Changeset 16
- Timestamp:
- Jan 8, 2017, 10:29:20 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Directories.pas
r9 r16 12 12 13 13 uses 14 ShlObj,LCLIntf, LCLType, LMessages, SysUtils, FileUtil;14 LCLIntf, LCLType, LMessages, SysUtils, FileUtil; 15 15 16 function GetSpecialDirectory(const CSIDL: integer): string;17 16 var 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; 31 19 32 20 function DirectoryExists(path: string): boolean; … … 44 32 end; 45 33 46 var 47 AppDataDir: string; 48 src, dst: TSearchRec; 34 procedure Init; 35 begin 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; 49 61 50 62 initialization 51 63 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; 64 Init; 76 65 77 66 end.
Note:
See TracChangeset
for help on using the changeset viewer.