Changeset 16


Ignore:
Timestamp:
Jan 8, 2017, 10:29:20 AM (8 years ago)
Author:
chronos
Message:
  • Fixed: Do not use shlobj unit as it uses Windows API.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Directories.pas

    r9 r16  
    1212
    1313uses
    14   ShlObj, LCLIntf, LCLType, LMessages, SysUtils, FileUtil;
     14  LCLIntf, LCLType, LMessages, SysUtils, FileUtil;
    1515
    16 function GetSpecialDirectory(const CSIDL: integer): string;
    1716var
    18   RecPath: PChar;
    19 begin
    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);
    29   end
    30 end;
     17  AppDataDir: string;
     18  src, dst: TSearchRec;
    3119
    3220function DirectoryExists(path: string): boolean;
     
    4432end;
    4533
    46 var
    47   AppDataDir: string;
    48   src, dst: TSearchRec;
     34procedure Init;
     35begin
     36  HomeDir := ExtractFilePath(ParamStr(0));
     37
     38  AppDataDir := GetAppConfigDir(False);
     39  if AppDataDir = '' then
     40    DataDir := HomeDir
     41  else
     42  begin
     43    if not DirectoryExists(AppDataDir) then
     44      CreateDir(AppDataDir);
     45    DataDir := AppDataDir;
     46  end;
     47  if not DirectoryExists(DataDir + 'Saved') then
     48    CreateDir(DataDir + 'Saved');
     49  if not DirectoryExists(DataDir + 'Maps') then
     50    CreateDir(DataDir + 'Maps');
     51
     52  // Copy appdata if not done yet
     53  if FindFirst(HomeDir + 'AppData\Saved\*.cevo', $21, src) = 0 then
     54    repeat
     55      if (FindFirst(DataDir + 'Saved\' + src.Name, $21, dst) <> 0) or
     56        (dst.Time < src.Time) then
     57        CopyFile(PChar(HomeDir + 'AppData\Saved\' + src.Name),
     58          PChar(DataDir + 'Saved\' + src.Name), false);
     59    until FindNext(src) <> 0;
     60  end;
    4961
    5062initialization
    5163
    52 HomeDir := ExtractFilePath(ParamStr(0));
    53 
    54 AppDataDir := GetSpecialDirectory(CSIDL_APPDATA);
    55 if AppDataDir = '' then
    56   DataDir := HomeDir
    57 else
    58 begin
    59   if not DirectoryExists(AppDataDir + '\C-evo') then
    60     CreateDir(AppDataDir + '\C-evo');
    61   DataDir := AppDataDir + '\C-evo\';
    62 end;
    63 if not DirectoryExists(DataDir + 'Saved') then
    64   CreateDir(DataDir + 'Saved');
    65 if not DirectoryExists(DataDir + 'Maps') then
    66   CreateDir(DataDir + 'Maps');
    67 
    68 // copy appdata if not done yet
    69 if FindFirst(HomeDir + 'AppData\Saved\*.cevo', $21, src) = 0 then
    70   repeat
    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;
     64Init;
    7665
    7766end.
Note: See TracChangeset for help on using the changeset viewer.