forked from AlexTuduran/Locator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUPersistency.pas
205 lines (167 loc) · 5.15 KB
/
UPersistency.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
unit UPersistency;
(******************************************************************************
* Description: System persistency services *
* Author: Alexandru Tuduran *
* Contact: [email protected] *
( *****************************************************************************)
interface
{$warn UNIT_PLATFORM OFF}
{$warn SYMBOL_PLATFORM OFF}
uses
Forms,
SysUtils,
IniFiles;
function Pers_Gen_Get_Cfg_Page_Index: Integer;
procedure Pers_Gen_Set_Cfg_Page_Index(Value: Integer);
function Pers_Gen_Get_WndX: Integer;
procedure Pers_Gen_Set_WndX(Value: Integer);
function Pers_Gen_Get_WndY: Integer;
procedure Pers_Gen_Set_WndY(Value: Integer);
function Pers_Gen_Get_WndW: Integer;
procedure Pers_Gen_Set_WndW(Value: Integer);
function Pers_Gen_Get_WndH: Integer;
procedure Pers_Gen_Set_WndH(Value: Integer);
function Pers_Gen_Get_Open_Path_App: String;
procedure Pers_Gen_Set_Open_Path_App(Value: String);
function Pers_Gen_Get_Show_Op_Fail_Warns: Boolean;
procedure Pers_Gen_Set_Show_Op_Fail_Warns(Value: Boolean);
function Pers_OpenWith_Get_Num_Apps: Integer;
procedure Pers_OpenWith_Set_Num_Apps(Value: Integer);
function Pers_OpenWith_Get_App(Index: Integer): String;
procedure Pers_OpenWith_Set_App(Index: Integer; Value: String);
implementation
const
INI_GEN_SECTION = 'General';
INI_OW_SECTION = 'OpenWith';
{ Generic routines }
function Get_App_Path: String;
begin
Result := ExtractFilePath(Application.ExeName);
end;
function Get_Cfg_File: TIniFile;
begin
Result := TIniFile.Create(Get_App_Path + 'settings.cfg');
end;
procedure Write_Integer(Section: String; Ident: String; Value: Integer);
begin
with Get_Cfg_File do
begin
WriteInteger(Section, Ident, Value);
Free;
end;
end;
function Read_Integer(Section: String; Ident: String; Default: Integer): Integer;
begin
with Get_Cfg_File do
begin
Result := ReadInteger(Section, Ident, Default);
Free;
end;
end;
procedure Write_Boolean(Section: String; Ident: String; Value: Boolean);
begin
with Get_Cfg_File do
begin
WriteBool(Section, Ident, Value);
Free;
end;
end;
function Read_Boolean(Section: String; Ident: String; Default: Boolean): Boolean;
begin
with Get_Cfg_File do
begin
Result := ReadBool(Section, Ident, Default);
Free;
end;
end;
procedure Write_String(Section: String; Ident: String; Value: String);
begin
with Get_Cfg_File do
begin
WriteString(Section, Ident, Value);
Free;
end;
end;
function Read_String(Section: String; Ident: String; Default: String): String;
begin
with Get_Cfg_File do
begin
Result := ReadString(Section, Ident, Default);
Free;
end;
end;
{ Specialized routines - general }
function Pers_Gen_Get_Cfg_Page_Index: Integer;
begin
Result := Read_Integer(INI_GEN_SECTION, 'Cfg_Page_Index', 0);
end;
procedure Pers_Gen_Set_Cfg_Page_Index(Value: Integer);
begin
Write_Integer(INI_GEN_SECTION, 'Cfg_Page_Index', Value);
end;
function Pers_Gen_Get_WndX: Integer;
begin
Result := Read_Integer(INI_GEN_SECTION, 'Wnd_X', -1);
end;
procedure Pers_Gen_Set_WndX(Value: Integer);
begin
Write_Integer(INI_GEN_SECTION, 'Wnd_X', Value);
end;
function Pers_Gen_Get_WndY: Integer;
begin
Result := Read_Integer(INI_GEN_SECTION, 'Wnd_Y', -1);
end;
procedure Pers_Gen_Set_WndY(Value: Integer);
begin
Write_Integer(INI_GEN_SECTION, 'Wnd_Y', Value);
end;
function Pers_Gen_Get_WndW: Integer;
begin
Result := Read_Integer(INI_GEN_SECTION, 'Wnd_W', -1);
end;
procedure Pers_Gen_Set_WndW(Value: Integer);
begin
Write_Integer(INI_GEN_SECTION, 'Wnd_W', Value);
end;
function Pers_Gen_Get_WndH: Integer;
begin
Result := Read_Integer(INI_GEN_SECTION, 'Wnd_H', -1);
end;
procedure Pers_Gen_Set_WndH(Value: Integer);
begin
Write_Integer(INI_GEN_SECTION, 'Wnd_H', Value);
end;
function Pers_Gen_Get_Show_Op_Fail_Warns: Boolean;
begin
Result := Read_Boolean(INI_GEN_SECTION, 'Show_Op_Fail_Warns', True);
end;
procedure Pers_Gen_Set_Show_Op_Fail_Warns(Value: Boolean);
begin
Write_Boolean(INI_GEN_SECTION, 'Show_Op_Fail_Warns', Value);
end;
{ Specialized routines - open with }
function Pers_Gen_Get_Open_Path_App: String;
begin
Result := Read_String(INI_GEN_SECTION, 'Open_Path_App', '');
end;
procedure Pers_Gen_Set_Open_Path_App(Value: String);
begin
Write_String(INI_GEN_SECTION, 'Open_Path_App', Value);
end;
function Pers_OpenWith_Get_Num_Apps: Integer;
begin
Result := Read_Integer(INI_OW_SECTION, 'Num_Open_With_Apps', 0);
end;
procedure Pers_OpenWith_Set_Num_Apps(Value: Integer);
begin
Write_Integer(INI_OW_SECTION, 'Num_Open_With_Apps', Value);
end;
function Pers_OpenWith_Get_App(Index: Integer): String;
begin
Result := Read_String(INI_OW_SECTION, Format('Open_With_App_%d', [Index]), '');
end;
procedure Pers_OpenWith_Set_App(Index: Integer; Value: String);
begin
Write_String(INI_OW_SECTION, Format('Open_With_App_%d', [Index]), Value);
end;
end.