Ignore:
Timestamp:
Feb 27, 2018, 6:11:44 PM (6 years ago)
Author:
chronos
Message:
  • Added: Partial support for color theming.
  • Added: Allow to edit contact properties in the list of all.
File:
1 edited

Legend:

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

    r1 r15  
    2828    unfDNSDomainName = 11);
    2929
     30  TFilterMethodMethod = function (FileName: string): Boolean of object;
    3031var
    3132  ExceptionHandler: TExceptionEvent;
     
    6364procedure OpenWebPage(URL: string);
    6465procedure OpenFileInShell(FileName: string);
    65 procedure ExecuteProgram(CommandLine: string);
     66procedure ExecuteProgram(Executable: string; Parameters: array of string);
    6667procedure FreeThenNil(var Obj);
    6768function RemoveQuotes(Text: string): string;
     
    7071function GetDirCount(Dir: string): Integer;
    7172function MergeArray(A, B: array of string): TArrayOfString;
     73function LoadFileToStr(const FileName: TFileName): AnsiString;
     74procedure SearchFiles(AList: TStrings; Dir: string;
     75  FilterMethod: TFilterMethodMethod);
    7276
    7377
     
    111115  Path := IncludeTrailingPathDelimiter(APath);
    112116
    113   Find := FindFirst(UTF8Decode(Path + AFileSpec), faAnyFile xor faDirectory, SearchRec);
     117  Find := FindFirst(Path + AFileSpec, faAnyFile xor faDirectory, SearchRec);
    114118  while Find = 0 do begin
    115     DeleteFile(Path + UTF8Encode(SearchRec.Name));
     119    DeleteFile(Path + SearchRec.Name);
    116120
    117121    Find := SysUtils.FindNext(SearchRec);
     
    428432end;
    429433
    430 procedure ExecuteProgram(CommandLine: string);
     434procedure ExecuteProgram(Executable: string; Parameters: array of string);
    431435var
    432436  Process: TProcess;
     437  I: Integer;
    433438begin
    434439  try
    435440    Process := TProcess.Create(nil);
    436     Process.CommandLine := CommandLine;
     441    Process.Executable := Executable;
     442    for I := 0 to Length(Parameters) - 1 do
     443      Process.Parameters.Add(Parameters[I]);
    437444    Process.Options := [poNoConsole];
    438445    Process.Execute;
     
    455462procedure OpenFileInShell(FileName: string);
    456463begin
    457   ExecuteProgram('cmd.exe /c start "' + FileName + '"');
     464  ExecuteProgram('cmd.exe', ['/c', 'start', FileName]);
    458465end;
    459466
     
    492499end;
    493500
     501function LoadFileToStr(const FileName: TFileName): AnsiString;
     502var
     503  FileStream: TFileStream;
     504  Read: Integer;
     505begin
     506  Result := '';
     507  FileStream := TFileStream.Create(FileName, fmOpenRead);
     508  try
     509    if FileStream.Size > 0 then begin
     510      SetLength(Result, FileStream.Size);
     511      Read := FileStream.Read(Pointer(Result)^, FileStream.Size);
     512      SetLength(Result, Read);
     513    end;
     514  finally
     515    FileStream.Free;
     516  end;
     517end;
     518
     519function DefaultSearchFilter(const FileName: string): Boolean;
     520begin
     521  Result := True;
     522end;
     523
     524procedure SearchFiles(AList: TStrings; Dir: string;
     525  FilterMethod: TFilterMethodMethod);
     526var
     527  SR: TSearchRec;
     528begin
     529  Dir := IncludeTrailingPathDelimiter(Dir);
     530  if FindFirst(Dir + '*', faAnyFile, SR) = 0 then
     531    try
     532      repeat
     533        if (SR.Name = '.') or (SR.Name = '..') or not FilterMethod(SR.Name) then Continue;
     534        AList.Add(Dir + SR.Name);
     535        if (SR.Attr and faDirectory) <> 0 then
     536          SearchFiles(AList, Dir + SR.Name, FilterMethod);
     537      until FindNext(SR) <> 0;
     538    finally
     539      FindClose(SR);
     540    end;
     541end;
    494542
    495543
Note: See TracChangeset for help on using the changeset viewer.