-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsmanager.pas
More file actions
286 lines (244 loc) · 10.4 KB
/
settingsmanager.pas
File metadata and controls
286 lines (244 loc) · 10.4 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
unit Settingsmanager;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, ExtCtrls;
type
{ TSettingsmanager }
TSettingsmanager = class(TObject)
private
FConfigurationFile, FDefaultLanguage, FBaseFolder: String;
FSslDllLocation_F1, FSslDllLocation_F2, FSQLiteDllLocation : String;
FActivateLogging, FAppendLogFile, FDisplayHelpText : Boolean;
FSetActiveBackGround, FTreeViewHotTrack : Boolean;
FFileCopyCount, FFileCopyCurrent : Integer;
procedure ReadSettings;
procedure GetConfigurationFileLocation;
property ConfigurationFile : String Read FConfigurationFile Write FConfigurationFile;
property BaseFolder : String Read FBaseFolder Write FBaseFolder;
public
constructor Create; overload;
destructor Destroy; override;
procedure SaveSettings;
procedure StoreFormState(aForm: TForm);
procedure RestoreFormState(aForm: TForm);
function CheckFormIsEntireVisible(Rect: TRect): TRect;
procedure StoreSplitterPos(aSplitter: TSplitter);
procedure RestoreSplitterPos(aSplitter: TSplitter);
// Configure form
property ActivateLogging : Boolean Read FActivateLogging Write FActivateLogging default True;
property AppendLogFile : Boolean Read FAppendLogFile Write FAppendLogFile default True;
property SslDllLocation_file1 : String Read FSslDllLocation_F1 Write FSslDllLocation_F1;
property SslDllLocation_file2 : String Read FSslDllLocation_F2 Write FSslDllLocation_F2;
property SQLiteDllLocation : String Read FSQLiteDllLocation Write FSQLiteDllLocation;
property DefaultLanguage : String Read FDefaultLanguage Write FDefaultLanguage;
property SetActiveBackGround : Boolean Read FSetActiveBackGround Write FSetActiveBackGround;
property FileCopyCount : Integer Read FFileCopyCount Write FFileCopyCount;
property FileCopyCurrent : Integer Read FFileCopyCurrent Write FFileCopyCurrent;
property SetTreeViewHotTrack : Boolean Read FTreeViewHotTrack Write FTreeViewHotTrack default False;
property DisplayHelpText : Boolean Read FDisplayHelpText Write FDisplayHelpText default False;
end;
implementation
uses Settings, IniFiles, Form_Main;
{ TSettingsmanager }
{%region constructor - destructor}
constructor TSettingsmanager.Create;
begin
inherited;
BaseFolder := ExtractFilePath(Application.ExeName);
GetConfigurationFileLocation;
ReadSettings;
end;
destructor TSettingsmanager.Destroy;
begin
// ..
inherited Destroy;
end;
{%endregion constructor - destructor}
procedure TSettingsmanager.GetConfigurationFileLocation;
var
UserName : string;
begin
UserName := StringReplace(GetEnvironmentVariable('USERNAME') , ' ', '_', [rfIgnoreCase, rfReplaceAll]) + '_';
ConfigurationFile := BaseFolder + Settings.SettingsFolder + PathDelim + UserName + Settings.ConfigurationFile;
end;
procedure TSettingsmanager.ReadSettings;
begin
With TIniFile.Create(ConfigurationFile) do
try
// Form_Configure
if ReadInteger('Configure', 'ActivateLogging', 1) = 1 then begin
ActivateLogging := True;
end
else begin
ActivateLogging := False;
end;
if ReadInteger('Configure', 'AppendLogFile', 1) = 1 then begin
AppendLogFile := True;
end
else begin
AppendLogFile := False;
end;
SslDllLocation_file1 := ReadString('Configure', 'SslDllLocation_1', BaseFolder + 'libeay32.dll');
SslDllLocation_file2 := ReadString('Configure', 'SslDllLocation_2', BaseFolder + 'ssleay32.dll');
SQLiteDllLocation := ReadString('Configure', 'SQLiteDllLocation', BaseFolder + 'sqlite3.dll');
if ReadBool('Configure', 'SetActiveBackGround', True) then begin
SetActiveBackGround := True;
end
else begin
SetActiveBackGround := False;
end;
FileCopyCount := ReadInteger('Configure', 'FileCopyCount', 10);
FileCopyCurrent := ReadInteger('Configure', 'FileCopyCurrent', 0);
if ReadInteger('Configure', 'TreeViewHotTrack', 0) = 0 then begin
SetTreeViewHotTrack := False;
end
else begin
SetTreeViewHotTrack := True;
end;
if ReadInteger('Configure', 'DisplayHelpText', 0) = 0 then begin
DisplayHelpText := False;
end
else begin
DisplayHelpText := True;
end;
DefaultLanguage := ReadString('Configure', 'DefaultLanguage', 'en');
finally
Free;
end;
end;
procedure TSettingsmanager.SaveSettings;
begin
With TIniFile.Create(ConfigurationFile) do
try
WriteString('Application', 'Name', Settings.ApplicationName);
WriteString('Application', 'Version', Settings.Version);
WriteString('Application', 'Database version', Settings.DataBaseVersion);
WriteString('Application', 'Build Date' , Settings.BuildDate);
WriteBool('Configure', 'ActivateLogging', ActivateLogging);
WriteBool('Configure', 'AppendLogFile', AppendLogFile);
WriteString('Configure', 'SslDllLocation_1', SslDllLocation_file1);
WriteString('Configure', 'SslDllLocation_2', SslDllLocation_file2);
WriteString( 'Configure', 'SQLiteDllLocation', SQLiteDllLocation);
WriteBool('Configure', 'SetActiveBackGround', SetActiveBackGround);
WriteInteger('Configure', 'FileCopyCount', FileCopyCount);
WriteInteger('Configure', 'FileCopyCurrent', FileCopyCurrent);
WriteBool('Configure', 'TreeViewHotTrack', SetTreeViewHotTrack);
WriteBool('Configure', 'DisplayHelpText', DisplayHelpText);
WriteString('Configure', 'DefaultLanguage', DefaultLanguage);
finally
Free;
end;
end;
procedure TSettingsmanager.StoreFormState(aForm: TForm);
begin
With TIniFile.Create(ConfigurationFile) do
try
try
writeinteger('Position', aForm.Name + '_Windowstate', integer(aForm.WindowState));
WriteInteger('Position', aForm.Name + '_Left', aForm.Left);
WriteInteger('Position', aForm.Name + '_Top', aForm.Top);
WriteInteger('Position', aForm.Name + '_Width', aForm.Width);
WriteInteger('Position', aForm.Name + '_Height', aForm.Height);
WriteInteger('Position', aForm.Name + '_RestoredLeft', aForm.RestoredLeft);
WriteInteger('Position', aForm.Name + '_RestoredTop', aForm.RestoredTop);
WriteInteger('Position', aForm.Name + '_RestoredWidth', aForm.RestoredWidth);
WriteInteger('Position', aForm.Name + '_RestoredHeight', aForm.RestoredHeight);
FrmMain.Logging.WriteToLogInfo('Opslaan schermpositie van scherm: ' + ' (' + aForm.Name + ').' );
finally
Free;
end;
Except
FrmMain.Logging.WriteToLogError('Opslaan schermpositie van scherm: ' + aForm.Name + ' is mislukt.' );
end;
end;
procedure TSettingsmanager.RestoreFormState(aForm: TForm);
var
LastWindowState: TWindowState;
begin
With TIniFile.Create(ConfigurationFile) do
try
try
LastWindowState := TWindowState(ReadInteger('Position', aForm.Name + '_WindowState', Integer(aForm.WindowState)));
if LastWindowState = wsMaximized then
begin
aForm.WindowState := wsNormal;
aForm.BoundsRect := Bounds(
ReadInteger('Position', aForm.Name + '_RestoredLeft', aForm.RestoredLeft),
ReadInteger('Position', aForm.Name + '_RestoredTop', aForm.RestoredTop),
ReadInteger('Position', aForm.Name + '_RestoredWidth', aForm.RestoredWidth),
ReadInteger('Position', aForm.Name + '_RestoredHeight', aForm.RestoredHeight));
aForm.WindowState := wsMaximized;
end
else
begin
aForm.WindowState := wsNormal;
aForm.BoundsRect := Bounds(
ReadInteger('Position', aForm.Name + '_Left', aForm.Left),
ReadInteger('Position', aForm.Name + '_Top', aForm.Top),
ReadInteger('Position', aForm.Name + '_Width', aForm.Width),
ReadInteger('Position', aForm.Name + '_Height', aForm.Height));
aForm.BoundsRect := CheckFormIsEntireVisible(aForm.BoundsRect);
end;
FrmMain.Logging.WriteToLogInfo('Ophalen schermpositie van scherm: ' + aForm.Name + ' is gereed.' );
finally
Free;
end;
Except
FrmMain.Logging.WriteToLogError('Ophalen schermpositie van scherm: ' + aForm.Name + ' is mislukt.');
end;
end;
function TSettingsmanager.CheckFormIsEntireVisible(Rect: TRect): TRect;
var
Width: Integer;
Height: Integer;
begin
Result := Rect;
Width := Rect.Right - Rect.Left;
Height := Rect.Bottom - Rect.Top;
if Result.Left < (Screen.DesktopLeft) then begin
Result.Left := Screen.DesktopLeft;
Result.Right := Screen.DesktopLeft + Width;
end;
if Result.Right > (Screen.DesktopLeft + Screen.DesktopWidth) then begin
Result.Left := Screen.DesktopLeft + Screen.DesktopWidth - Width;
Result.Right := Screen.DesktopLeft + Screen.DesktopWidth;
end;
if Result.Top < Screen.DesktopTop then begin
Result.Top := Screen.DesktopTop;
Result.Bottom := Screen.DesktopTop + Height;
end;
if Result.Bottom > (Screen.DesktopTop + Screen.DesktopHeight) then begin
Result.Top := Screen.DesktopTop + Screen.DesktopHeight - Height;
Result.Bottom := Screen.DesktopTop + Screen.DesktopHeight;
end;
end;
procedure TSettingsmanager.StoreSplitterPos(aSplitter: TSplitter);
begin
With TIniFile.Create(ConfigurationFile) do
try
try
writeinteger('Position', aSplitter.Name + '_Left', aSplitter.Left);
writeinteger('Position', aSplitter.Name + '_Top', aSplitter.Top);
finally
Free;
end;
Except
FrmMain.Logging.WriteToLogError('Opslaan splitter van splitter: ' + aSplitter.Name + ' is mislukt.' );
end;
end;
procedure TSettingsmanager.RestoreSplitterPos(aSplitter: TSplitter);
begin
With TIniFile.Create(ConfigurationFile) do
try
try
aSplitter.Left := ReadInteger('Position', aSplitter.Name + '_Left', aSplitter.Left);
aSplitter.Top := ReadInteger('Position', aSplitter.Name + '_Top', aSplitter.Top);
finally
Free;
end;
Except
FrmMain.Logging.WriteToLogError('Ophalen positie van splitter: ' + aSplitter.Name + ' is mislukt.');
end;
end;
end.