-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfig.pas
More file actions
265 lines (245 loc) · 7.66 KB
/
Copy pathConfig.pas
File metadata and controls
265 lines (245 loc) · 7.66 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
unit Config;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Registry, StdCtrls, JvDialogs, XPMan, MMSystem, Buttons, ImgList,
ComCtrls;
type
TConfRecord = record
PlaySound: Boolean;
SoundFile: string;
MinAPM: Single;
PosX, PosY: Integer;
EnableLiveAPM: Boolean;
DispAllAPMs: Boolean;
GameClockX, GameClockY: Integer;
EnableGameClock: Boolean;
LocalClockX, LocalClockY: Integer;
EnableLocalClock: Boolean;
end;
TConfigDialog = class(TForm)
btnSave: TButton;
XPManifest1: TXPManifest;
dlgOpen: TJvOpenDialog;
btnResetDefaults: TButton;
pcConfigBox: TPageControl;
tsAlert: TTabSheet;
cbPlaySound: TCheckBox;
lblMinAPM: TLabel;
edMinAPM: TEdit;
edAlertSndFile: TEdit;
btnAlertPreview: TButton;
btnBrowse: TButton;
lblAlertSndFile: TLabel;
tsLiveAPM: TTabSheet;
lblLiveAPMX: TLabel;
lblLiveAPMY: TLabel;
edLiveAPMX: TEdit;
edLiveAPMY: TEdit;
cbEnableLiveAPM: TCheckBox;
cbDispAllAPMs: TCheckBox;
tsGameClock: TTabSheet;
lblGameClockX: TLabel;
edGameClockX: TEdit;
lblGameClockY: TLabel;
edGameClockY: TEdit;
cbEnableGameClock: TCheckBox;
tsLocalClock: TTabSheet;
cbEnableLocalClock: TCheckBox;
lblLocalClockX: TLabel;
edLocalClockX: TEdit;
lblLocalClockY: TLabel;
edLocalClockY: TEdit;
procedure btnBrowseClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure btnResetDefaultsClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SetupConfForm(ConfRecord: TConfRecord);
end;
procedure LoadAPMConf(var ConfRecord: TConfRecord; UseDefaults: Boolean = False);
procedure SaveAPMConf(ConfRecord: TConfRecord);
function GetSCDir: string;
function GetPluginDir: string;
var
ConfigDialog: TConfigDialog;
implementation
{$R *.dfm}
function GetSCDir: string;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
Result := '';
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SOFTWARE\Blizzard Entertainment\Starcraft', False) then
Result := Reg.ReadString('InstallPath');
finally
Reg.CloseKey;
Reg.Free;
end;
end;
function GetPluginDir: string;
var
buf: array[0..MAX_PATH] of char;
begin
GetModuleFileName(HInstance, buf, SizeOf(buf));
Result := ExtractFilePath(buf);
end;
procedure LoadAPMConf(var ConfRecord: TConfRecord; UseDefaults: Boolean = False);
var
Reg: TRegistry;
begin
with ConfRecord do
begin
PlaySound := True;
SoundFile := GetPluginDir + 'alert.wav';
MinAPM := 60.5;
PosX := 4;
PosY := 2;
EnableLiveAPM := True;
DispAllAPMs := True;
GameClockX := 286;
GameClockY := 2;
EnableGameClock := True;
LocalClockX := 14;
LocalClockY := 284;
EnableLocalClock := True;
end;
if UseDefaults then exit;
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('SOFTWARE\BWProgrammers\APMAlert', False) then
begin
if Reg.ValueExists('PlaySound') then
ConfRecord.PlaySound := Reg.ReadBool('PlaySound');
if Reg.ValueExists('SoundFile') then
ConfRecord.SoundFile := Reg.ReadString('SoundFile');
if Reg.ValueExists('MinAPM') then
ConfRecord.MinAPM := Reg.ReadFloat('MinAPM');
if Reg.ValueExists('PosX') then
ConfRecord.PosX := Reg.ReadInteger('PosX');
if Reg.ValueExists('PosY') then
ConfRecord.PosY := Reg.ReadInteger('PosY');
if Reg.ValueExists('EnableLiveAPM') then
ConfRecord.EnableLiveAPM := Reg.ReadBool('EnableLiveAPM');
if Reg.ValueExists('DispAllAPMs') then
ConfRecord.DispAllAPMs := Reg.ReadBool('DispAllAPMs');
if Reg.ValueExists('GameClockX') then
ConfRecord.GameClockX := Reg.ReadInteger('GameClockX');
if Reg.ValueExists('GameClockY') then
ConfRecord.GameClockY := Reg.ReadInteger('GameClockY');
if Reg.ValueExists('EnableGameClock') then
ConfRecord.EnableGameClock := Reg.ReadBool('EnableGameClock');
if Reg.ValueExists('LocalClockX') then
ConfRecord.LocalClockX := Reg.ReadInteger('LocalClockX');
if Reg.ValueExists('LocalClockY') then
ConfRecord.LocalClockY := Reg.ReadInteger('LocalClockY');
if Reg.ValueExists('EnableLocalClock') then
ConfRecord.EnableLocalClock := Reg.ReadBool('EnableLocalClock');
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;
procedure SaveAPMConf(ConfRecord: TConfRecord);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('SOFTWARE\BWProgrammers\APMAlert', True) then
begin
Reg.WriteBool('PlaySound', ConfRecord.PlaySound);
Reg.WriteString('SoundFile',ConfRecord.SoundFile);
Reg.WriteFloat('MinAPM',ConfRecord.MinAPM);
Reg.WriteInteger('PosX',ConfRecord.PosX);
Reg.WriteInteger('PosY',ConfRecord.PosY);
Reg.WriteBool('EnableLiveAPM',ConfRecord.EnableLiveAPM);
Reg.WriteBool('DispAllAPMs',ConfRecord.DispAllAPMs);
Reg.WriteInteger('GameClockX',ConfRecord.GameClockX);
Reg.WriteInteger('GameClockY',ConfRecord.GameClockY);
Reg.WriteBool('EnableGameClock',ConfRecord.EnableGameClock);
Reg.WriteInteger('LocalClockX',ConfRecord.LocalClockX);
Reg.WriteInteger('LocalClockY',ConfRecord.LocalClockY);
Reg.WriteBool('EnableLocalClock',ConfRecord.EnableLocalClock);
end;
finally
Reg.Free;
end;
end;
procedure TConfigDialog.btnBrowseClick(Sender: TObject);
begin
if dlgOpen.Execute then
begin
edAlertSndFile.Text := dlgOpen.FileName;
end;
end;
procedure TConfigDialog.btnResetDefaultsClick(Sender: TObject);
var
ConfRecord: TConfRecord;
begin
LoadAPMConf(ConfRecord, True);
SetupConfForm(ConfRecord);
end;
procedure TConfigDialog.btnSaveClick(Sender: TObject);
var
ConfRecord: TConfRecord;
begin
with ConfRecord do
begin
PlaySound := cbPlaySound.Checked;
SoundFile := edAlertSndFile.Text;
MinAPM := StrToFloat(edMinAPM.Text);
PosX := StrToInt(edLiveAPMX.Text);
PosY := StrToInt(edLiveAPMY.Text);
EnableLiveAPM := cbEnableLiveAPM.Checked;
DispAllAPMs := cbDispAllAPMs.Checked;
GameClockX := StrToInt(edGameClockX.Text);
GameClockY := StrToInt(edGameClockY.Text);
EnableGameClock := cbEnableGameClock.Checked;
LocalClockX := StrToInt(edLocalClockX.Text);
LocalClockY := StrToInt(edLocalClockY.Text);
EnableLocalClock := cbEnableLocalClock.Checked;
end;
SaveAPMConf(ConfRecord);
Self.Close;
end;
procedure TConfigDialog.SetupConfForm(ConfRecord: TConfRecord);
begin
cbPlaySound.Checked := ConfRecord.PlaySound;
edAlertSndFile.Text := ConfRecord.SoundFile;
edMinAPM.Text := FloatToStr(ConfRecord.MinAPM);
edLiveAPMX.Text := IntToStr(ConfRecord.PosX);
edLiveAPMY.Text := IntToStr(ConfRecord.PosY);
cbEnableLiveAPM.Checked := ConfRecord.EnableLiveAPM;
cbDispAllAPMs.Checked := ConfRecord.DispAllAPMs;
edGameClockX.Text := IntToStr(ConfRecord.GameClockX);
edGameClockY.Text := IntToStr(ConfRecord.GameClockY);
cbEnableGameClock.Checked := ConfRecord.EnableGameClock;
edLocalClockX.Text := IntToStr(ConfRecord.LocalClockX);
edLocalClockY.Text := IntToStr(ConfRecord.LocalClockY);
cbEnableLocalClock.Checked := ConfRecord.EnableLocalClock;
end;
procedure TConfigDialog.FormCreate(Sender: TObject);
var
ConfRecord: TConfRecord;
begin
pcConfigBox.TabIndex := 0;
dlgOpen.InitialDir := GetSCDir;
LoadAPMConf(ConfRecord);
SetupConfForm(ConfRecord);
end;
procedure TConfigDialog.BitBtn1Click(Sender: TObject);
begin
sndPlaySound(PChar(edAlertSndFile.Text), SND_ASYNC);
end;
end.