forked from Ravie/quice
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MeConnectForm.pas
377 lines (349 loc) · 10.8 KB
/
MeConnectForm.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
unit MeConnectForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, TypInfo, ZConnection;
type
TMeConnectForm = class(TForm)
btConnect: TButton;
btCancel: TButton;
btDetails: TButton;
gbAdvanced: TGroupBox;
btClear: TButton;
gbConnect: TGroupBox;
edUsername: TEdit;
lbUsername: TLabel;
lbPassword: TLabel;
edPassword: TEdit;
edServer: TComboBox;
lbServer: TLabel;
lbPort: TLabel;
edPort: TEdit;
edmDatabase: TComboBox;
lbmDatabase: TLabel;
cbSavePassword: TCheckBox;
Image1: TImage;
lbCharSet: TLabel;
edCharSet: TEdit;
edcDatabase: TComboBox;
lbcDatabase: TLabel;
edsDatabase: TComboBox;
edrDatabase: TComboBox;
lbrDatabase: TLabel;
lbsDatabase: TLabel;
procedure btConnectClick(Sender: TObject);
procedure edServerDropDown(Sender: TObject);
procedure GetDataBases(Sender: TObject);
procedure edExit(Sender: TObject);
procedure btDetailsClick(Sender: TObject);
procedure btClearClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edServerChange(Sender: TObject);
private
FListGot : boolean;
procedure SaveSettings;
procedure LoadSettings;
procedure SavePassword;
procedure LoadPassword;
procedure GetServerList(Items: TStrings);
protected
procedure DoInit;
procedure DoConnect;
end;
implementation
uses MainUnit, MyDataModule, Functions, Registry;
{$R *.dfm}
procedure TMeConnectForm.DoInit;
begin
FListGot := false;
if (edUsername.Text <> '') and (edPassword.Text = '') then
ActiveControl := edPassword;
LoadSettings;
if cbSavePassword.Checked then begin
LoadPassword;
end;
end;
procedure TMeConnectForm.DoConnect;
begin
edExit(nil);
MainForm.CharDBName := edcDatabase.Text;
MainForm.RealmDBName := edrDatabase.Text;
MainForm.ScriptDBName := edsDatabase.Text;
if Trim(edCharSet.Text) <> '' then
MainForm.MyMangosConnection.ClientCodepage := edCharSet.Text;
try
if MainForm.MyMangosConnection.Connected then
MainForm.MyMangosConnection.Disconnect;
MainForm.MyMangosConnection.Connect;
ModalResult := mrOk;
except
ModalResult := mrNone;
raise;
end;
end;
procedure TMeConnectForm.btConnectClick(Sender: TObject);
begin
if dmMain.DBCDir = '' then
dmMain.DBCDir := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) + 'DBFilesClient';
SaveSettings;
DoConnect;
if cbSavePassword.Checked then begin
SavePassword;
end;
end;
procedure TMeConnectForm.edServerDropDown(Sender: TObject);
var
OldCursor: TCursor;
begin
if FListGot then
Exit;
FListGot := True;
OldCursor := Screen.Cursor;
Screen.Cursor := crSQLWait;
try
GetServerList(edServer.Items);
finally
Screen.Cursor := OldCursor;
end;
end;
procedure TMeConnectForm.GetServerList(Items: TStrings);
begin
with TRegistry.Create do
try
RootKey:= HKEY_CURRENT_USER;
if OpenKey('Software\'+SoftwareCompany+'\' + Trim(ProgramName) + '\servers', false) then
GetKeyNames(Items);
finally
Free;
end;
end;
procedure TMeConnectForm.GetDataBases(Sender: TObject);
var
OldCursor: TCursor;
WasConnected: Boolean;
begin
edmDatabase.Items.Clear;
edcDatabase.Items.Clear;
edrDatabase.Items.Clear;
edsDatabase.Items.Clear;
OldCursor := Screen.Cursor;
Screen.Cursor := crSQLWait;
try
WasConnected := MainForm.MyMangosConnection.Connected;
if not WasConnected then
MainForm.MyMangosConnection.Connect;
MainForm.MyMangosConnection.GetCatalogNames(edmDatabase.Items);
edcDatabase.Items.AddStrings(edmDatabase.Items);
edrDatabase.Items.AddStrings(edmDatabase.Items);
edsDatabase.Items.AddStrings(edmDatabase.Items);
if not WasConnected then
MainForm.MyMangosConnection.Disconnect;
finally
Screen.Cursor := OldCursor;
end;
end;
procedure TMeConnectForm.edExit(Sender: TObject);
begin
try
MainForm.MyMangosConnection.Password := edPassword.Text;
MainForm.MyMangosConnection.HostName := edServer.Text;
MainForm.MyMangosConnection.User := edUsername.Text;
MainForm.MyMangosConnection.Database := edmDatabase.Text;
MainForm.MyMangosConnection.Port := StrToIntDef(edPort.Text, 3306);
except
ActiveControl := Sender as TWinControl;
raise;
end;
end;
procedure TMeConnectForm.LoadPassword;
begin
try
edPassword.Text:=ReadFromRegistry(CurrentUser, '', 'Password', tpString);
except
edPassword.Text:='';
end;
end;
procedure TMeConnectForm.SavePassword;
begin
WriteToRegistry(CurrentUser, '', 'Password', tpString, edPassword.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'Password', tpString, edPassword.Text);
end;
procedure TMeConnectForm.LoadSettings;
begin
try
cbSavePassword.Checked:=ReadFromRegistry(CurrentUser, '', 'SavePass', tpBool);
except
cbSavePassword.Checked:=false;
end;
try
edServer.Text:=ReadFromRegistry(CurrentUser, '', 'Server', tpString);
except
edServer.Clear;
end;
try
edUsername.Text:=ReadFromRegistry(CurrentUser, '', 'Username', tpString);
except
edUsername.Clear;
end;
try
edPort.Text:=ReadFromRegistry(CurrentUser, '', 'Port', tpString);
except
edPort.Clear;
end;
try
edCharSet.Text:=ReadFromRegistry(CurrentUser, '', 'Charset', tpString);
except
edCharSet.Clear;
end;
end;
procedure TMeConnectForm.SaveSettings;
begin
WriteToRegistry(CurrentUser, '', 'SavePass', tpBool, cbSavePassword.Checked);
WriteToRegistry(CurrentUser, '', 'Server', tpString, edServer.Text);
WriteToRegistry(CurrentUser, '', 'Username', tpString, edUsername.Text);
WriteToRegistry(CurrentUser, '', 'cDatabase', tpString, edcDatabase.Text);
WriteToRegistry(CurrentUser, '', 'mDatabase', tpString, edmDatabase.Text);
WriteToRegistry(CurrentUser, '', 'rDatabase', tpString, edrDatabase.Text);
WriteToRegistry(CurrentUser, '', 'sDatabase', tpString, edsDatabase.Text);
WriteToRegistry(CurrentUser, '', 'Port', tpString, edPort.Text);
WriteToRegistry(CurrentUser, '', 'Charset', tpString, edCharSet.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'SavePass', tpBool, cbSavePassword.Checked);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'Username', tpString, edUsername.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'mDatabase', tpString, edmDatabase.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'cDatabase', tpString, edcDatabase.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'rDatabase', tpString, edrDatabase.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'sDatabase', tpString, edsDatabase.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'Port', tpString, edPort.Text);
WriteToRegistry(CurrentUser, 'servers\' + edServer.Text, 'Charset', tpString, edCharSet.Text);
end;
procedure TMeConnectForm.btDetailsClick(Sender: TObject);
const
mH = 80;
begin
if pos('>>', btDetails.Caption)>0 then
begin
ClientHeight:=ClientHeight+gbAdvanced.Height+10;
btDetails.Caption:=dmMain.Text[77]; //'<< Details';
gbAdvanced.Visible:=true;
end
else
begin
ClientHeight:=ClientHeight-gbAdvanced.Height-10;
btDetails.Caption:=dmMain.Text[78]; //'Details >>';
gbAdvanced.Visible:=false;
end;
end;
procedure TMeConnectForm.btClearClick(Sender: TObject);
begin
edUsername.Clear;
edPassword.Clear;
edServer.Clear;
edPort.Clear;
edmDatabase.Clear;
edcDatabase.Clear;
edrDatabase.Clear;
edsDatabase.Clear;
edCharSet.Clear;
end;
procedure TMeConnectForm.FormCreate(Sender: TObject);
var
Major, Minor, Release, Build: Word;
begin
ClientHeight:=292;
DoInit;
if GetFileVersion(Application.ExeName, Major, Minor, Release, Build) then
Caption := Format('Quice %d.%d.%d.%d',[Major, Minor, Release, Build])
else
Caption := 'Quice';
dmMain.Translate.CreateDefaultTranslation(TForm(Self));
end;
procedure TMeConnectForm.FormShow(Sender: TObject);
var
Major, Minor, Release, Build: Word;
mDBname, cDBname, rDBname, sDBname: string;
AC: TWinControl;
begin
dmMain.Translate.TranslateForm(TForm(Self));
if GetFileVersion(Application.ExeName, Major, Minor, Release, Build) then
Caption := Format('Quice %d.%d.%d.%d',[Major, Minor, Release, Build])
else
Caption := 'Quice';
mDBname:=ReadFromRegistry(CurrentUser, '', 'mDatabase', tpString);
cDBname:=ReadFromRegistry(CurrentUser, '', 'cDatabase', tpString);
rDBname:=ReadFromRegistry(CurrentUser, '', 'rDatabase', tpString);
sDBname:=ReadFromRegistry(CurrentUser, '', 'sDatabase', tpString);
edExit(Sender);
try
GetDataBases(Sender);
if mDBname<>'' then
edmDatabase.ItemIndex:=edmDatabase.Items.IndexOf(mDBName);
if cDBname<>'' then
edcDatabase.ItemIndex:=edcDatabase.Items.IndexOf(cDBName);
if rDBname<>'' then
edrDatabase.ItemIndex:=edrDatabase.Items.IndexOf(rDBName);
if sDBname<>'' then
edsDatabase.ItemIndex:=edsDatabase.Items.IndexOf(sDBName);
except
if edmDatabase.Text='' then
edmDatabase.Text:=mDBName;
if edcDatabase.Text='' then
edcDatabase.Text:=cDBName;
if edrDatabase.Text='' then
edrDatabase.Text:=rDBName;
if edsDatabase.Text='' then
edsDatabase.Text:=sDBName;
end;
AC := edServer;
if edServer.Text <> '' then AC := edPort;
if edPort.Text <> '' then AC := edUsername;
if edUsername.Text <> '' then AC := edPassword;
if edPassword.Text <> '' then AC := btConnect;
FocusControl(AC);
end;
procedure TMeConnectForm.edServerChange(Sender: TObject);
begin
try
cbSavePassword.Checked:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'SavePass', tpBool);
except
cbSavePassword.Checked:=false;
end;
if cbSavePassword.Checked then
try
edPassword.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'Password', tpString);
except
edPassword.Text:='';
end;
try
edUsername.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'Username', tpString);
except
edUsername.Clear;
end;
try
edmDatabase.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'mDatabase', tpString);
except
end;
try
edcDatabase.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'cDatabase', tpString);
except
end;
try
edrDatabase.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'rDatabase', tpString);
except
end;
try
edsDatabase.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'sDatabase', tpString);
except
end;
try
edPort.Text:=ReadFromRegistry(CurrentUser, 'servers\' + edServer.Text, 'Port', tpString);
except
edPort.Clear;
end;
try
edCharSet.Text:=ReadFromRegistry(CurrentUser,'servers\' + edServer.Text, 'Charset', tpString);
except
edCharSet.Clear;
end;
end;
end.