1 | {$INCLUDE switches}
|
---|
2 | unit Directories;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | var
|
---|
7 | HomeDir, DataDir: string;
|
---|
8 |
|
---|
9 | function LocalizedFilePath(path: string): string;
|
---|
10 |
|
---|
11 | implementation
|
---|
12 |
|
---|
13 | uses
|
---|
14 | ShlObj, Windows, SysUtils;
|
---|
15 |
|
---|
16 | function GetSpecialDirectory(const CSIDL: integer): string;
|
---|
17 | 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;
|
---|
31 |
|
---|
32 | function DirectoryExists(path: string): boolean;
|
---|
33 | var
|
---|
34 | f: TSearchRec;
|
---|
35 | begin
|
---|
36 | result := FindFirst(path, faDirectory, f) = 0;
|
---|
37 | end;
|
---|
38 |
|
---|
39 | function LocalizedFilePath(path: string): string;
|
---|
40 | begin
|
---|
41 | result := DataDir + 'Localization\' + path;
|
---|
42 | if not FileExists(result) then
|
---|
43 | result := HomeDir + path
|
---|
44 | end;
|
---|
45 |
|
---|
46 | var
|
---|
47 | AppDataDir: string;
|
---|
48 | src, dst: TSearchRec;
|
---|
49 |
|
---|
50 | initialization
|
---|
51 |
|
---|
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;
|
---|
76 |
|
---|
77 | end.
|
---|