Changeset 6 for trunk/Directories.pas
- Timestamp:
- Jan 7, 2017, 11:32:14 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Directories.pas
r2 r6 1 1 {$INCLUDE switches} 2 3 2 unit Directories; 4 3 … … 6 5 7 6 var 8 HomeDir, DataDir: string;7 HomeDir, DataDir: string; 9 8 10 9 function LocalizedFilePath(path: string): string; 11 12 10 13 11 implementation 14 12 15 13 uses 16 ShlObj,Windows,SysUtils;14 ShlObj, Windows, SysUtils; 17 15 18 16 function GetSpecialDirectory(const CSIDL: integer): string; 19 17 var 20 RecPath: PChar;18 RecPath: PChar; 21 19 begin 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); 30 29 end 31 30 end; … … 33 32 function DirectoryExists(path: string): boolean; 34 33 var 35 f: TSearchRec;34 f: TSearchRec; 36 35 begin 37 result:=FindFirst(path,faDirectory,f)=0;36 result := FindFirst(path, faDirectory, f) = 0; 38 37 end; 39 38 40 39 function LocalizedFilePath(path: string): string; 41 40 begin 42 result:=DataDir+'Localization\'+path;43 if not FileExists(result) then44 result:=HomeDir+path41 result := DataDir + 'Localization\' + path; 42 if not FileExists(result) then 43 result := HomeDir + path 45 44 end; 46 45 47 48 46 var 49 AppDataDir: string;50 src,dst: TSearchRec;47 AppDataDir: string; 48 src, dst: TSearchRec; 51 49 52 50 initialization 53 HomeDir:=ExtractFilePath(ParamStr(0));54 51 52 HomeDir := ExtractFilePath(ParamStr(0)); 55 53 56 AppDataDir :=GetSpecialDirectory(CSIDL_APPDATA);57 if AppDataDir ='' then58 DataDir :=HomeDir54 AppDataDir := GetSpecialDirectory(CSIDL_APPDATA); 55 if AppDataDir = '' then 56 DataDir := HomeDir 59 57 else 60 61 if not DirectoryExists(AppDataDir +'\C-evo') then62 CreateDir(AppDataDir +'\C-evo');63 DataDir :=AppDataDir+'\C-evo\';64 65 if not DirectoryExists(DataDir +'Saved') then66 CreateDir(DataDir +'Saved');67 if not DirectoryExists(DataDir +'Maps') then68 CreateDir(DataDir +'Maps');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'); 69 67 70 68 // copy appdata if not done yet 71 if FindFirst(HomeDir +'AppData\Saved\*.cevo',$21,src)=0 then69 if FindFirst(HomeDir + 'AppData\Saved\*.cevo', $21, src) = 0 then 72 70 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 78 77 end.
Note:
See TracChangeset
for help on using the changeset viewer.