Ignore:
Timestamp:
Dec 10, 2016, 11:01:49 PM (8 years ago)
Author:
chronos
Message:
  • Added: Files for required package CoolTranslator.
  • Modified: Updated Common package files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UCommon.pas

    r12 r40  
    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;
     
    6566procedure FreeThenNil(var Obj);
    6667function 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;
    6772function LoadFileToStr(const FileName: TFileName): AnsiString;
    6873
     
    288293  L: LongWord;
    289294begin
    290 
    291295  L := MAX_USERNAME_LENGTH + 2;
    292296  SetLength(Result, L);
     
    303307  end;
    304308end;
    305 
     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}
    306338function LoggedOnUserNameEx(Format: TUserNameFormat): string;
    307339const
     
    418450
    419451procedure OpenWebPage(URL: string);
    420 var
    421   Process: TProcess;
    422   Browser, Params: string;
    423452begin
    424453  OpenURL(URL);
    425   {try
    426     Process := TProcess.Create(nil);
    427     Browser := '';
    428     //FindDefaultBrowser(Browser, Params);
    429     //Process.Executable := Browser;
    430     //Process.Parameters.Add(Format(Params, [ApplicationInfo.HomePage]);
    431     Process.CommandLine := 'cmd.exe /c start ' + URL;
    432     Process.Options := [poNoConsole];
    433     Process.Execute;
    434   finally
    435     Process.Free;
    436   end;}
    437454end;
    438455
     
    447464  if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then
    448465    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];
    449493end;
    450494
     
    467511end;
    468512
     513
     514
    469515initialization
    470516
Note: See TracChangeset for help on using the changeset viewer.