source: branches/delphi/Directories.pas

Last change on this file was 6, checked in by chronos, 7 years ago
  • Modified: Formated all project source files using Delphi formatter as original indentation and other formatting was really bad.
File size: 1.7 KB
Line 
1{$INCLUDE switches}
2unit Directories;
3
4interface
5
6var
7 HomeDir, DataDir: string;
8
9function LocalizedFilePath(path: string): string;
10
11implementation
12
13uses
14 ShlObj, Windows, SysUtils;
15
16function GetSpecialDirectory(const CSIDL: integer): string;
17var
18 RecPath: PChar;
19begin
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
30end;
31
32function DirectoryExists(path: string): boolean;
33var
34 f: TSearchRec;
35begin
36 result := FindFirst(path, faDirectory, f) = 0;
37end;
38
39function LocalizedFilePath(path: string): string;
40begin
41 result := DataDir + 'Localization\' + path;
42 if not FileExists(result) then
43 result := HomeDir + path
44end;
45
46var
47 AppDataDir: string;
48 src, dst: TSearchRec;
49
50initialization
51
52HomeDir := ExtractFilePath(ParamStr(0));
53
54AppDataDir := GetSpecialDirectory(CSIDL_APPDATA);
55if AppDataDir = '' then
56 DataDir := HomeDir
57else
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');
67
68// copy appdata if not done yet
69if 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;
76
77end.
Note: See TracBrowser for help on using the repository browser.