[go: up one dir, main page]

Menu

[fa4ba5]: / Directories.pas  Maximize  Restore  History

Download this file

79 lines (62 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{$INCLUDE switches}
unit Directories;
interface
var
HomeDir, DataDir: string;
function LocalizedFilePath(path: string): string;
implementation
uses
ShlObj,Windows,SysUtils;
function GetSpecialDirectory(const CSIDL: integer): string;
var
RecPath: PChar;
begin
RecPath:=StrAlloc(MAX_PATH);
try
FillChar(RecPath^, MAX_PATH, 0);
if SHGetSpecialFolderPath(0, RecPath, CSIDL, false) then
result:=RecPath
else result:='';
finally
StrDispose(RecPath);
end
end;
function DirectoryExists(path: string): boolean;
var
f: TSearchRec;
begin
result:=FindFirst(path,faDirectory,f)=0;
end;
function LocalizedFilePath(path: string): string;
begin
result:=DataDir+'Localization\'+path;
if not FileExists(result) then
result:=HomeDir+path
end;
var
AppDataDir: string;
src,dst: TSearchRec;
initialization
HomeDir:=ExtractFilePath(ParamStr(0));
AppDataDir:=GetSpecialDirectory(CSIDL_APPDATA);
if AppDataDir='' then
DataDir:=HomeDir
else
begin
if not DirectoryExists(AppDataDir+'\C-evo') then
CreateDir(AppDataDir+'\C-evo');
DataDir:=AppDataDir+'\C-evo\';
end;
if not DirectoryExists(DataDir+'Saved') then
CreateDir(DataDir+'Saved');
if not DirectoryExists(DataDir+'Maps') then
CreateDir(DataDir+'Maps');
// copy appdata if not done yet
if FindFirst(HomeDir+'AppData\Saved\*.cevo',$21,src)=0 then
repeat
if (FindFirst(DataDir+'Saved\'+src.Name,$21,dst)<>0)
or (dst.Time<src.Time) then
CopyFile(PChar(HomeDir+'AppData\Saved\'+src.Name),
PChar(DataDir+'Saved\'+src.Name),false);
until FindNext(src)<>0;
end.