This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.pas
More file actions
142 lines (128 loc) · 3.63 KB
/
Config.pas
File metadata and controls
142 lines (128 loc) · 3.63 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
unit Config;
interface
uses
Classes, Forms, SysUtils, IniFiles, SyncObjs;
type
TConfig = class(TObject)
private
FLock: TCriticalSection;
public
FPort: string;
FFolder: string;
FFolderOrg: string;
FIconize: boolean;
FUser: string;
FPassword: string;
FAdminIp: string;
FBackDates: integer;
FAcceptGateway: boolean;
FDebugLog: integer;
FLocalOnly: boolean;
FP2PPathWinny: string;
FP2PPathRingoch: string;
procedure Load;
procedure Save;
function LoadTemplate(FileName: string): string;
constructor Create;
destructor Destroy; override;
end;
var
CrescentVersion: string = '0.0.22.1';
ReportVersion: string = '0.0.22';
ShingetsuVersion: string = '0.1';
FConfig: TConfig;
FTerminateFlag: boolean = false;
implementation
const
INI_NET_SECT: string = 'NET';
constructor TConfig.Create;
begin
inherited;
FLock := TCriticalSection.Create;
end;
destructor TConfig.Destroy;
begin
FLock.Free;
inherited;
end;
procedure TConfig.Load;
var
iniPath: string;
ini: TMemIniFile;
begin
FLock.Enter;
iniPath := ChangeFileExt(Application.ExeName, '.ini');
ini := TMemIniFile.Create(iniPath);
FPort := ini.ReadString(INI_NET_SECT, 'Port', '8000');
FIconize := ini.ReadBool(INI_NET_SECT, 'Iconize', false);
FFolderOrg := ini.ReadString(INI_NET_SECT, 'CrescentFolder', '');
FUser := ini.ReadString(INI_NET_SECT, 'User', '');
FPassword := ini.ReadString(INI_NET_SECT, 'Password', '');
FAdminIp := ini.ReadString(INI_NET_SECT, 'AdminIp', '127.0.0.1');
FBackDates := ini.ReadInteger(INI_NET_SECT, 'BackDates', 10);
FAcceptGateway := ini.ReadBool(INI_NET_SECT, 'AcceptGateway', true);
FDebugLog := ini.ReadInteger(INI_NET_SECT, 'DebugLog', 0);
FLocalOnly := ini.ReadBool(INI_NET_SECT, 'LocalOnly', false);
FP2PPathWinny := ini.ReadString(INI_NET_SECT, 'P2PPathWinny', 'localhost:7744');
FP2PPathRingoch := ini.ReadString(INI_NET_SECT, 'P2PPathRingoch', 'localhost:60000');
FFolder := FFolderOrg;
if (FUser = '') or (FPassword = '') then begin
FUser := 'default';
FPassword := IntToStr(Random(20000000000));
end;
if FAdminIp = '' then begin
FAdminIp := '127.0.0.1';
end;
if FFolder = '' then begin
FFolder := ExtractFilePath(Application.ExeName);
end;
if FFolder[Length(FFolder)] = '\' then begin
FFolder := Copy(FFolder, 1, Length(FFolder) - 1);
end;
ini.Free;
FLock.Leave;
end;
procedure TConfig.Save;
var
iniPath: string;
ini: TMemIniFile;
begin
FLock.Enter;
iniPath := ChangeFileExt(Application.ExeName, '.ini');
ini := TMemIniFile.Create(iniPath);
ini.WriteString(INI_NET_SECT, 'Port', FPort);
ini.WriteBool(INI_NET_SECT, 'Iconize', FIconize);
ini.WriteString(INI_NET_SECT, 'CrescentFolder', FFolderOrg);
ini.WriteString(INI_NET_SECT, 'User', FUser);
ini.WriteString(INI_NET_SECT, 'Password', FPassword);
ini.WriteString(INI_NET_SECT, 'AdminIp', FAdminIp);
ini.WriteInteger(INI_NET_SECT, 'BackDates', FBackDates);
ini.WriteBool(INI_NET_SECT, 'AcceptGateway', FAcceptGateway);
ini.WriteInteger(INI_NET_SECT, 'DebugLog', FDebugLog);
ini.WriteBool(INI_NET_SECT, 'LocalOnly', FLocalOnly);
ini.WriteString(INI_NET_SECT, 'P2PPathWinny', FP2PPathWinny);
ini.WriteString(INI_NET_SECT, 'P2PPathRingoch', FP2PPathRingoch);
ini.UpdateFile;
ini.Free;
FLock.Leave;
end;
function TConfig.LoadTemplate(FileName: string): string;
var
f: TFileStream;
n: integer;
begin
result := '';
try
f := TFileStream.Create(FFolder + '\file\' + FileName, fmOpenRead);
try
n := f.Size;
SetLength(result, n);
f.Read(result[1], n);
finally
f.Free;
end;
except
result := '';
end;
end;
end.