Changeset 6 for trunk/Directories.pas


Ignore:
Timestamp:
Jan 7, 2017, 11:32:14 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Directories.pas

    r2 r6  
    11{$INCLUDE switches}
    2 
    32unit Directories;
    43
     
    65
    76var
    8 HomeDir, DataDir: string;
     7  HomeDir, DataDir: string;
    98
    109function LocalizedFilePath(path: string): string;
    11 
    1210
    1311implementation
    1412
    1513uses
    16 ShlObj,Windows,SysUtils;
     14  ShlObj, Windows, SysUtils;
    1715
    1816function GetSpecialDirectory(const CSIDL: integer): string;
    1917var
    20 RecPath: PChar;
     18  RecPath: PChar;
    2119begin
    22 RecPath:=StrAlloc(MAX_PATH);
    23 try
    24   FillChar(RecPath^, MAX_PATH, 0);
    25   if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) then
    26     result:=RecPath
    27   else result:='';
    28 finally
    29   StrDispose(RecPath);
     20  RecPath := StrAlloc(MAX_PATH);
     21  try
     22    FillChar(RecPath^, MAX_PATH, 0);
     23    if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) then
     24      result := RecPath
     25    else
     26      result := '';
     27  finally
     28    StrDispose(RecPath);
    3029  end
    3130end;
     
    3332function DirectoryExists(path: string): boolean;
    3433var
    35 f: TSearchRec;
     34  f: TSearchRec;
    3635begin
    37 result:=FindFirst(path,faDirectory,f)=0;
     36  result := FindFirst(path, faDirectory, f) = 0;
    3837end;
    3938
    4039function LocalizedFilePath(path: string): string;
    4140begin
    42 result:=DataDir+'Localization\'+path;
    43 if not FileExists(result) then
    44   result:=HomeDir+path
     41  result := DataDir + 'Localization\' + path;
     42  if not FileExists(result) then
     43    result := HomeDir + path
    4544end;
    4645
    47 
    4846var
    49 AppDataDir: string;
    50 src,dst: TSearchRec;
     47  AppDataDir: string;
     48  src, dst: TSearchRec;
    5149
    5250initialization
    53 HomeDir:=ExtractFilePath(ParamStr(0));
    5451
     52HomeDir := ExtractFilePath(ParamStr(0));
    5553
    56 AppDataDir:=GetSpecialDirectory(CSIDL_APPDATA);
    57 if AppDataDir='' then
    58   DataDir:=HomeDir
     54AppDataDir := GetSpecialDirectory(CSIDL_APPDATA);
     55if AppDataDir = '' then
     56  DataDir := HomeDir
    5957else
    60   begin
    61   if not DirectoryExists(AppDataDir+'\C-evo') then
    62     CreateDir(AppDataDir+'\C-evo');
    63   DataDir:=AppDataDir+'\C-evo\';
    64   end;
    65 if not DirectoryExists(DataDir+'Saved') then
    66   CreateDir(DataDir+'Saved');
    67 if not DirectoryExists(DataDir+'Maps') then
    68   CreateDir(DataDir+'Maps');
     58begin
     59  if not DirectoryExists(AppDataDir + '\C-evo') then
     60    CreateDir(AppDataDir + '\C-evo');
     61  DataDir := AppDataDir + '\C-evo\';
     62end;
     63if not DirectoryExists(DataDir + 'Saved') then
     64  CreateDir(DataDir + 'Saved');
     65if not DirectoryExists(DataDir + 'Maps') then
     66  CreateDir(DataDir + 'Maps');
    6967
    7068// copy appdata if not done yet
    71 if FindFirst(HomeDir+'AppData\Saved\*.cevo',$21,src)=0 then
     69if FindFirst(HomeDir + 'AppData\Saved\*.cevo', $21, src) = 0 then
    7270  repeat
    73     if (FindFirst(DataDir+'Saved\'+src.Name,$21,dst)<>0)
    74       or (dst.Time<src.Time) then
    75       CopyFile(PChar(HomeDir+'AppData\Saved\'+src.Name),
    76         PChar(DataDir+'Saved\'+src.Name),false);
    77   until FindNext(src)<>0;
     71    if (FindFirst(DataDir + 'Saved\' + src.Name, $21, dst) <> 0) or
     72      (dst.Time < src.Time) then
     73      CopyFile(PChar(HomeDir + 'AppData\Saved\' + src.Name),
     74        PChar(DataDir + 'Saved\' + src.Name), false);
     75  until FindNext(src) <> 0;
     76
    7877end.
Note: See TracChangeset for help on using the changeset viewer.