Ignore:
Timestamp:
Nov 25, 2017, 12:27:33 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Improved New game window.
  • Modified: Used newer version of Common and CoolTranslator packages.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33backup
        44tunneler.exe
         5tunneler.dbg
         6tunneler.lps
        57heaptrclog.trc
        6 tunneler.lps
         8Components/Common/Languages/*.mo
         9Components/CoolTranslator/Demo/lib
  • trunk/Components/Common/UCommon.pas

    r31 r34  
    66
    77uses
    8   {$IFDEF Windows}Windows,{$ENDIF}
     8  {$ifdef Windows}Windows,{$endif}
     9  {$ifdef Linux}baseunix,{$endif}
    910  Classes, SysUtils, StrUtils, Dialogs, Process, LCLIntf,
    1011  FileUtil; //, ShFolder, ShellAPI;
     
    4849function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    4950function SplitString(var Text: string; Count: Word): string;
     51function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer;
    5052function GetBit(Variable: QWord; Index: Byte): Boolean;
     53procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean); overload;
    5154procedure SetBit(var Variable: QWord; Index: Byte; State: Boolean); overload;
    5255procedure SetBit(var Variable: Cardinal; Index: Byte; State: Boolean); overload;
     
    6265procedure ExecuteProgram(CommandLine: string);
    6366procedure FreeThenNil(var Obj);
     67function RemoveQuotes(Text: string): string;
     68function ComputerName: string;
     69function OccurenceOfChar(What: Char; Where: string): Integer;
     70function GetDirCount(Dir: string): Integer;
     71function MergeArray(A, B: array of string): TArrayOfString;
     72function LoadFileToStr(const FileName: TFileName): AnsiString;
    6473
    6574
     
    105114  Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);
    106115  while Find = 0 do begin
    107     DeleteFileUTF8(Path + UTF8Encode(SearchRec.Name));
     116    DeleteFile(Path + UTF8Encode(SearchRec.Name));
    108117
    109118    Find := SysUtils.FindNext(SearchRec);
     
    284293  L: LongWord;
    285294begin
    286 
    287295  L := MAX_USERNAME_LENGTH + 2;
    288296  SetLength(Result, L);
     
    299307  end;
    300308end;
    301 
     309{$endif}
     310
     311function ComputerName: string;
     312{$ifdef mswindows}
     313const
     314 INFO_BUFFER_SIZE = 32767;
     315var
     316  Buffer : array[0..INFO_BUFFER_SIZE] of WideChar;
     317  Ret : DWORD;
     318begin
     319  Ret := INFO_BUFFER_SIZE;
     320  If (GetComputerNameW(@Buffer[0],Ret)) then begin
     321    Result := UTF8Encode(WideString(Buffer));
     322  end
     323  else begin
     324    Result := 'ERROR_NO_COMPUTERNAME_RETURNED';
     325  end;
     326end;
     327{$endif}
     328{$ifdef unix}
     329var
     330  Name: UtsName;
     331begin
     332  fpuname(Name);
     333  Result := Name.Nodename;
     334end;
     335{$endif}
     336
     337{$ifdef windows}
    302338function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    303339const
     
    336372end;
    337373
     374function GetBitCount(Variable: QWord; MaxIndex: Integer): Integer;
     375var
     376  I: Integer;
     377begin
     378  Result := 0;
     379  for I := 0 to MaxIndex - 1 do
     380    if ((Variable shr I) and 1) = 1 then Inc(Result);
     381end;
     382
    338383function GetBit(Variable:QWord;Index:Byte):Boolean;
    339384begin
     
    341386end;
    342387
     388procedure SetBit(var Variable: Int64; Index: Byte; State: Boolean);
     389begin
     390  Variable := (Variable and ((1 shl Index) xor High(QWord))) or (Int64(State) shl Index);
     391end;
     392
    343393procedure SetBit(var Variable:QWord;Index:Byte;State:Boolean); overload;
    344394begin
    345   Variable := (Variable and ((1 shl Index) xor QWord($ffffffffffffffff))) or (QWord(State) shl Index);
     395  Variable := (Variable and ((1 shl Index) xor High(QWord))) or (QWord(State) shl Index);
    346396end;
    347397
    348398procedure SetBit(var Variable:Cardinal;Index:Byte;State:Boolean); overload;
    349399begin
    350   Variable := (Variable and ((1 shl Index) xor Cardinal($ffffffff))) or (Cardinal(State) shl Index);
     400  Variable := (Variable and ((1 shl Index) xor High(Cardinal))) or (Cardinal(State) shl Index);
    351401end;
    352402
    353403procedure SetBit(var Variable:Word;Index:Byte;State:Boolean); overload;
    354404begin
    355   Variable := (Variable and ((1 shl Index) xor Word($ffff))) or (Word(State) shl Index);
     405  Variable := (Variable and ((1 shl Index) xor High(Word))) or (Word(State) shl Index);
    356406end;
    357407
     
    400450
    401451procedure OpenWebPage(URL: string);
    402 var
    403   Process: TProcess;
    404   Browser, Params: string;
    405452begin
    406453  OpenURL(URL);
    407   {try
    408     Process := TProcess.Create(nil);
    409     Browser := '';
    410     //FindDefaultBrowser(Browser, Params);
    411     //Process.Executable := Browser;
    412     //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
    413     Process.CommandLine := 'cmd.exe /c start ' + URL;
    414     Process.Options := [poNoConsole];
    415     Process.Execute;
     454end;
     455
     456procedure OpenFileInShell(FileName: string);
     457begin
     458  ExecuteProgram('cmd.exe /c start "' + FileName + '"');
     459end;
     460
     461function RemoveQuotes(Text: string): string;
     462begin
     463  Result := Text;
     464  if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then
     465    Result := Copy(Text, 2, Length(Text) - 2);
     466end;
     467
     468function OccurenceOfChar(What: Char; Where: string): Integer;
     469var
     470  I: Integer;
     471begin
     472  Result := 0;
     473  for I := 1 to Length(Where) do
     474    if Where[I] = What then Inc(Result);
     475end;
     476
     477function GetDirCount(Dir: string): Integer;
     478begin
     479  Result := OccurenceOfChar(DirectorySeparator, Dir);
     480  if Copy(Dir, Length(Dir), 1) = DirectorySeparator then
     481    Dec(Result);
     482end;
     483
     484function MergeArray(A, B: array of string): TArrayOfString;
     485var
     486  I: Integer;
     487begin
     488  SetLength(Result, Length(A) + Length(B));
     489  for I := 0 to Length(A) - 1 do
     490    Result[I] := A[I];
     491  for I := 0 to Length(B) - 1 do
     492    Result[Length(A) + I] := B[I];
     493end;
     494
     495function LoadFileToStr(const FileName: TFileName): AnsiString;
     496var
     497  FileStream: TFileStream;
     498  Read: Integer;
     499begin
     500  Result := '';
     501  FileStream := TFileStream.Create(FileName, fmOpenRead);
     502  try
     503    if FileStream.Size > 0 then begin
     504      SetLength(Result, FileStream.Size);
     505      Read := FileStream.Read(Pointer(Result)^, FileStream.Size);
     506      SetLength(Result, Read);
     507    end;
    416508  finally
    417     Process.Free;
    418   end;}
    419 end;
    420 
    421 procedure OpenFileInShell(FileName: string);
    422 begin
    423   ExecuteProgram('cmd.exe /c start "' + FileName + '"');
    424 end;
     509    FileStream.Free;
     510  end;
     511end;
     512
     513
    425514
    426515initialization
Note: See TracChangeset for help on using the changeset viewer.