-
Notifications
You must be signed in to change notification settings - Fork 1
/
UIniOptions.pas
110 lines (92 loc) · 2.93 KB
/
UIniOptions.pas
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
unit UIniOptions;
interface
uses
Classes, SysUtils, IniFiles, Forms, Windows;
const
csIniMainSection = 'Main';
{ Section: Main }
csIniMainDataDir = 'DataDir';
csIniMainPatternFile = 'PatternFile';
csIniMainDictionaryFile = 'DictionaryFile';
csIniMainMokassarDictionaryFile = 'MokassarDictionaryFile';
csIniMainPatternCount = 'PatternCount';
type
TIniOptions = class(TObject)
private
{ Section: Main }
FMainDataDir: string;
FMainPatternFile: string;
FMainDictionaryFile: string;
FMainMokassarDictionaryFile: string;
FMainPatternCount: Integer;
public
procedure LoadSettings(Ini: TIniFile);
procedure SaveSettings(Ini: TIniFile);
procedure LoadFromFile(const FileName: string);
procedure SaveToFile(const FileName: string);
{ Section: Main }
property MainDataDir: string read FMainDataDir write FMainDataDir;
property MainPatternCount: Integer read FMainPatternCount write FMainPatternCount;
property MainPatternFile: string read FMainPatternFile write FMainPatternFile;
property MainDictionaryFile: string read FMainDictionaryFile write FMainDictionaryFile;
property MainMokassarDictionaryFile: string read FMainMokassarDictionaryFile
write FMainMokassarDictionaryFile;
end;
var
IniOptions: TIniOptions = nil;
implementation
procedure TIniOptions.LoadSettings(Ini: TIniFile);
begin
if Ini <> nil then
begin
{ Section: Main }
FMainPatternCount := Ini.ReadInteger(csIniMainSection, csIniMainPatternCount, -1);
FMainDataDir := Ini.ReadString(csIniMainSection, csIniMainDataDir, 'Data\');
FMainPatternFile := Ini.ReadString(csIniMainSection, csIniMainPatternFile, 'Patterns.txt');
FMainDictionaryFile := Ini.ReadString(csIniMainSection, csIniMainDictionaryFile, 'fa2.txt');
FMainMokassarDictionaryFile := Ini.ReadString(csIniMainSection, csIniMainMokassarDictionaryFile,
'MokassarDic.txt');
end;
end;
procedure TIniOptions.SaveSettings(Ini: TIniFile);
begin
if Ini <> nil then
begin
{ Section: Main }
Ini.WriteInteger(csIniMainSection, csIniMainPatternCount, FMainPatternCount);
Ini.WriteString(csIniMainSection, csIniMainDataDir, FMainDataDir);
Ini.WriteString(csIniMainSection, csIniMainPatternFile, FMainPatternFile);
Ini.WriteString(csIniMainSection, csIniMainDictionaryFile, FMainDictionaryFile);
Ini.WriteString(csIniMainSection, csIniMainMokassarDictionaryFile, FMainMokassarDictionaryFile);
end;
end;
procedure TIniOptions.LoadFromFile(const FileName: string);
var
Ini: TIniFile;
begin
if FileExists(FileName) then
begin
Ini := TIniFile.Create(FileName);
try
LoadSettings(Ini);
finally
Ini.Free;
end;
end;
end;
procedure TIniOptions.SaveToFile(const FileName: string);
var
Ini: TIniFile;
begin
Ini := TIniFile.Create(FileName);
try
SaveSettings(Ini);
finally
Ini.Free;
end;
end;
initialization
IniOptions := TIniOptions.Create;
finalization
IniOptions.Free;
end.