1 | {$INCLUDE Switches.inc}
|
---|
2 | unit Directories;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | var
|
---|
7 | HomeDir, DataDir: string;
|
---|
8 | LocaleCode: string;
|
---|
9 |
|
---|
10 | function LocalizedFilePath(const Path: string): string;
|
---|
11 |
|
---|
12 |
|
---|
13 | implementation
|
---|
14 |
|
---|
15 | uses
|
---|
16 | LCLIntf, LCLType, SysUtils, FileUtil;
|
---|
17 |
|
---|
18 | var
|
---|
19 | AppDataDir: string;
|
---|
20 | src, dst: TSearchRec;
|
---|
21 |
|
---|
22 | function DirectoryExists(path: string): boolean;
|
---|
23 | var
|
---|
24 | f: TSearchRec;
|
---|
25 | begin
|
---|
26 | result := FindFirst(path, faDirectory, f) = 0;
|
---|
27 | end;
|
---|
28 |
|
---|
29 | function LocalizedFilePath(const Path: string): string;
|
---|
30 | begin
|
---|
31 | if LocaleCode <> '' then begin
|
---|
32 | Result := HomeDir + 'Localization' + DirectorySeparator + LocaleCode + DirectorySeparator + Path;
|
---|
33 | if not FileExists(Result) then
|
---|
34 | Result := HomeDir + Path;
|
---|
35 | end else Result := HomeDir + Path;
|
---|
36 | end;
|
---|
37 |
|
---|
38 | procedure InitUnit;
|
---|
39 | begin
|
---|
40 | LocaleCode := '';
|
---|
41 | HomeDir := ExtractFilePath(ParamStr(0));
|
---|
42 |
|
---|
43 | AppDataDir := GetAppConfigDir(False);
|
---|
44 | if AppDataDir = '' then
|
---|
45 | DataDir := HomeDir
|
---|
46 | else
|
---|
47 | begin
|
---|
48 | if not DirectoryExists(AppDataDir) then
|
---|
49 | CreateDir(AppDataDir);
|
---|
50 | DataDir := AppDataDir;
|
---|
51 | end;
|
---|
52 | if not DirectoryExists(DataDir + 'Saved') then
|
---|
53 | CreateDir(DataDir + 'Saved');
|
---|
54 | if not DirectoryExists(DataDir + 'Maps') then
|
---|
55 | CreateDir(DataDir + 'Maps');
|
---|
56 |
|
---|
57 | // Copy appdata if not done yet
|
---|
58 | if FindFirst(HomeDir + 'AppData' + DirectorySeparator + 'Saved' + DirectorySeparator + '*.cevo', $21, src) = 0 then
|
---|
59 | repeat
|
---|
60 | if (FindFirst(DataDir + 'Saved' + DirectorySeparator + src.Name, $21, dst) <> 0) or
|
---|
61 | (dst.Time < src.Time) then
|
---|
62 | CopyFile(PChar(HomeDir + 'AppData' + DirectorySeparator + 'Saved' + DirectorySeparator + src.Name),
|
---|
63 | PChar(DataDir + 'Saved' + DirectorySeparator + src.Name), false);
|
---|
64 | until FindNext(src) <> 0;
|
---|
65 | end;
|
---|
66 |
|
---|
67 | initialization
|
---|
68 |
|
---|
69 | InitUnit;
|
---|
70 |
|
---|
71 | end.
|
---|