-
Notifications
You must be signed in to change notification settings - Fork 5
/
settings.pas
212 lines (181 loc) · 5.41 KB
/
settings.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
206
207
208
209
210
211
212
unit settings;
interface
uses
Classes, SysUtils, Rest.Json, Generics.Collections, Registry;
type
TAppTrigger = class
private
fExecutable: string;
fClassName: string;
fCaption: string;
fPartialCaption: Boolean;
fEnabled: Boolean;
fBrightness: Integer;
fContrast: Integer;
fFullScreenOnly: Boolean;
public
constructor Create(const aExecutable, aClassName, aCaption: string);
destructor Destroy(); override;
published
property Executable: string read fExecutable write fExecutable;
property ClassName: string read fClassName write fClassName;
property Caption: string read fCaption write fCaption;
property PartialCaption: Boolean read fPartialCaption write fPartialCaption;
property Enabled: Boolean read fEnabled write fEnabled;
property Brightness: Integer read fBrightness write fBrightness;
property Contrast: Integer read fContrast write fContrast;
end;
TAppTriggers = class
private
fDefault: Extended;
fItems: TArray<TAppTrigger>;
public
destructor Destroy; override;
procedure Append(aItem: TAppTrigger);
procedure Remove(aIndex: Integer);
function Count: Integer;
published
property default: Extended read fDefault write fDefault;
property Items: TArray<TAppTrigger> read fItems write fItems;
end;
TSettings = class(TObject)
private
fAppTriggers: TAppTriggers;
fAutoRun: Boolean;
fHotKey: string;
fOverlayHotkey: string;
fDefBrightness: Integer;
fDefContrast: Integer;
fDefVibrance: Integer;
fDefGamma: Integer; // single monitor only
fFullBrightness: Integer;
fFullContrast: Integer;
fFullVibrance: Integer;
fFullGamma: Integer;
fFullSettings: Boolean; // single monitor only
fOverlayOpacity: Integer;
procedure SetAutorun(aEnable: Boolean);
public
constructor Create;
destructor Destroy; override;
published
property Autorun: Boolean read fAutoRun write SetAutorun;
property HotKey: string read fHotKey write fHotKey;
property OverlayHotkey: string read fOverlayHotkey write fOverlayHotkey;
property DefaultBrightness: Integer read fDefBrightness write fDefBrightness;
property DefaultContrast: Integer read fDefContrast write fDefContrast;
property DefaultVibrance: Integer read fDefVibrance write fDefVibrance;
property DefaultGamma: Integer read fDefGamma write fDefGamma;
property FullscreenBrightness: Integer read fFullBrightness write fFullBrightness;
property FullscreenContrast: Integer read fFullContrast write fFullContrast;
property FullscreenVibrance: Integer read fFullVibrance write fFullVibrance;
property FullscreenGamma: Integer read fFullGamma write fFullGamma;
property FullscreenSettingsOn: Boolean read fFullSettings write fFullSettings;
property OverlayOpacity: Integer read fOverlayOpacity write fOverlayOpacity;
end;
TSettingsHandler = class(TObject)
public
class function LoadSettings(fSettings: String = ''): TSettings;
class procedure SaveSettings(aSettings: TSettings; fSettings: String = '');
end;
implementation
{ TSettingsHandler }
class function TSettingsHandler.LoadSettings(fSettings: String): TSettings;
var
strings: TStrings;
begin
strings := TStringList.Create;
try
if fSettings = '' then
fSettings := ExtractFilePath(ParamStr(0)) + 'settings.json';
if FileExists(fSettings) then
begin
strings.LoadFromFile(fSettings);
Result := TJson.JsonToObject<TSettings>(strings.Text);
end
else
begin
Result := TSettings.Create;
end;
finally
strings.Free;
end;
end;
class procedure TSettingsHandler.SaveSettings(aSettings: TSettings;
fSettings: String);
var
strings: TStrings;
json: String;
begin
if fSettings = '' then
fSettings := ExtractFilePath(ParamStr(0)) + 'settings.json';
strings := TStringList.Create;
try
json := TJson.ObjectToJsonString(aSettings);
strings.Add(json);
strings.SaveToFile(fSettings);
finally
strings.Free;
end;
end;
{ TSettings }
constructor TSettings.Create;
begin
inherited; // invoke inherit
fAppTriggers := TAppTriggers.Create;
end;
destructor TSettings.Destroy;
begin
fAppTriggers.Free;
inherited;
end;
procedure TSettings.SetAutorun(aEnable: Boolean);
begin
end;
{ TAppTrigger }
constructor TAppTrigger.Create(const aExecutable, aClassName, aCaption: string);
begin
fExecutable := aExecutable;
fClassName := aClassName;
fCaption := aCaption;
fEnabled := True;
fPartialCaption := False;
fContrast := 0;
fBrightness := 0;
fFullScreenOnly := False;
end;
destructor TAppTrigger.Destroy;
begin
inherited;
end;
{ TAppTriggers }
procedure TAppTriggers.Append(aItem: TAppTrigger);
begin
SetLength(fItems, Length(fItems) + 1);
fItems[High(fItems)] := aItem;
end;
function TAppTriggers.Count: Integer;
begin
Result := Length(fItems);
end;
destructor TAppTriggers.Destroy;
var
vItem: TAppTrigger;
begin
for vItem in fItems do
vItem.Free;
inherited;
end;
procedure TAppTriggers.Remove(aIndex: Integer);
var
I: Integer;
begin
if (Count > 0) and (aIndex < Count) then
begin
fItems[aIndex].Free;
for I := aIndex + 1 to Count - 1 do
fItems[I - 1] := fItems[I];
SetLength(fItems, Count - 1);
end;
end;
end.