[go: up one dir, main page]

Menu

[r19]: / source / onguard3.pas  Maximize  Restore  History

Download this file

374 lines (331 with data), 11.7 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
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
(* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is TurboPower OnGuard
*
* The Initial Developer of the Original Code is
* TurboPower Software
*
* Portions created by the Initial Developer are Copyright (C) 1996-2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** *)
{*********************************************************}
{* ONGUARD3.PAS 1.15 *}
{* Copyright (c) 1996-02 TurboPower Software Co *}
{* All rights reserved. *}
{*********************************************************}
{$I onguard.inc}
unit onguard3;
{-Key selection and maintenance}
interface
uses
{$IFDEF Win16} WinTypes, WinProcs, {$ENDIF}
{$IFDEF Win32} Windows, {$ENDIF}
{$IFDEF MSWINDOWS}
SysUtils, Messages, Classes, Graphics, Controls, Clipbrd, IniFiles,
StdCtrls, Buttons, Forms, Dialogs,
{$ENDIF}
{$IFDEF UseOgFMX}
System.SysUtils, System.Types, System.UITypes, System.Classes, System.IniFiles,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects,
FMX.ExtCtrls, FMX.ListBox, FMX.Layouts, FMX.Edit, FMX.Platform,
Fmx.StdCtrls, FMX.Header, FMX.Graphics,
{$ENDIF}
ogconst,
ogutil,
onguard,
onguard1,
onguard4;
type
TKeyMaintFrm = class(TForm)
ProductsGb: TGroupBox;
ProductsLb: TListBox;
AddBtn: TButton;
DeleteBtn: TButton;
EditBtn: TButton;
{$IFNDEF UseOgFMX}
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
OpenBtn: TBitBtn;
{$ENDIF}
{$IFDEF UseOgFMX}
OKBtn: TButton;
CancelBtn: TButton;
OpenBtn: TButton;
{$ENDIF}
OpenDialog1: TOpenDialog;
FileNameGb: TGroupBox;
FileNameEd: TEdit;
OpenFileSb: TSpeedButton;
GroupBox1: TGroupBox;
BlockKeyEd: TEdit;
BytesKeyEd: TEdit;
CopyBlockKeySb: TSpeedButton;
CopyByteKeySb: TSpeedButton;
KeyPasteSb: TSpeedButton;
SpeedButton1: TSpeedButton;
procedure AddBtnClick(Sender: TObject);
procedure EditBtnClick(Sender: TObject);
procedure DeleteBtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InfoChanged(Sender: TObject);
procedure KeyCopySbClick(Sender: TObject);
procedure OpenFileSbClick(Sender: TObject);
procedure OpenBtnClick(Sender: TObject);
procedure ProductsLbDblClick(Sender: TObject);
procedure CopyByteKeySbClick(Sender: TObject);
procedure KeyPasteSbClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
function GetListBoxItemIndex : integer; {!!.07}
private
{ Private declarations }
FKey : TKey;
FKeyType : TKeyType;
function GetKeyFileName : string;
procedure SetKeyFileName(Value : string);
public
{ Public declarations }
procedure SetKey(Value : TKey); {!!.08}
procedure GetKey(var Value : TKey); {!!.08}
property KeyFileName : string
read GetKeyFileName
write SetKeyFileName;
property KeyType : TKeyType
read FKeyType
write FKeyType;
end;
implementation
{$IFDEF MSWINDOWS}{$R *.DFM}{$ENDIF}
{$IFDEF UseOgFMX}{$R *.FMX}{$ENDIF}
{!! This function is required to get round a bug in Delphi 4} {!!.07}
function TKeyMaintFrm.GetListBoxItemIndex : integer; {!!.07}
begin {!!.07}
if (ProductsLB.Items.Count = 0) then {!!.07}
Result := -1 {!!.07}
else {!!.07}
{Result := SendMessage(ProductsLB.Handle, LB_GETCURSEL, 0, 0);} {!!.07}
{Note: The above doesn't work - cannot delete item 0} {!!.07}
{ This works but looks odd in D4 so still a bug} {!!.07}
Result := ProductsLB.ItemIndex; {!!.07}
end; {!!.07}
procedure TKeyMaintFrm.FormCreate(Sender: TObject);
begin
InfoChanged(Sender);
end;
procedure TKeyMaintFrm.InfoChanged(Sender: TObject);
var
I : Integer;
IniFile : TIniFile;
begin
OpenBtn.Enabled := Length(FileNameEd.Text) > 0;
FillChar(FKey, SizeOf(FKey), 0);
if Length(KeyFileName) > 0 then begin
IniFile := TIniFile.Create(KeyFileName);
try
I := GetListBoxItemIndex; {!!.07}
ProductsLb.Items.BeginUpdate;
try
ProductsLb.Items.Clear;
IniFile.ReadSection(OgKeySection, ProductsLb.Items);
if I < ProductsLb.Items.Count then
ProductsLb.ItemIndex := I {!!.07}
else begin {!!.07}
ProductsLb.ItemIndex := pred(ProductsLb.Items.Count); {!!.07}
I := GetListBoxItemIndex; {!!.07}
end; {!!.07}
if (I > -1) then begin {!!.07}
EditBtn.Enabled := True; {!!.07}
DeleteBtn.Enabled := True; {!!.07}
BlockKeyEd.Text := IniFile.ReadString(OgKeySection,
ProductsLb.Items[I], ''); {!!.07}
HexToBuffer(BlockKeyEd.Text, FKey, SizeOf(FKey));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
BytesKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
if HexStringIsZero(BlockKeyEd.Text)then
BlockKeyEd.Text := '';
if HexStringIsZero(BytesKeyEd.Text)then
BytesKeyEd.Text := '';
end else begin {!!.07}
EditBtn.Enabled := False; {!!.07}
DeleteBtn.Enabled := False; {!!.07}
end; {!!.07}
finally
ProductsLb.Items.EndUpdate;
end;
finally
IniFile.Free;
end;
end else
ProductsLb.Items.Clear;
OKBtn.Enabled := HexToBuffer(BlockKeyEd.Text, FKey, SizeOf(FKey));
end;
procedure TKeyMaintFrm.AddBtnClick(Sender: TObject);
var
F : TEditProductFrm;
IniFile : TIniFile;
begin
F := TEditProductFrm.Create(Self);
try
F.SetKey(FKey);
F.KeyType := FKeyType;
{$IFDEF MSWINDOWS}
F.ShowHint := ShowHint;
{$ENDIF}
if F.ShowModal = mrOK then begin
IniFile := TIniFile.Create(KeyFileName);
try
IniFile.WriteString(OgKeySection, F.ProductEd.Text, F.KeyEd.Text);
finally
IniFile.Free;
end;
F.GetKey(FKey);
FKeyType := F.KeyType;
end;
finally
F.Free;
end;
InfoChanged(Self);
end;
procedure TKeyMaintFrm.EditBtnClick(Sender: TObject);
var
F : TEditProductFrm;
IniFile : TIniFile;
begin
F := TEditProductFrm.Create(Self);
try
F.SetKey(FKey);
F.KeyType := FKeyType;
{$IFDEF MSWINDOWS}
F.ShowHint := ShowHint;
{$ENDIF}
IniFile := TIniFile.Create(KeyFileName);
try
F.ProductEd.Text := ProductsLb.Items[GetListBoxItemIndex]; {!!.07}
F.KeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
if F.ShowModal = mrOK then
IniFile.WriteString(OgKeySection, F.ProductEd.Text, F.KeyEd.Text);
finally
IniFile.Free;
end;
finally
F.Free;
end;
InfoChanged(Self);
end;
procedure TKeyMaintFrm.DeleteBtnClick(Sender: TObject);
var
IniFile : TIniFile;
I : Integer;
{$IFDEF Win16}
Buf1 : array[0..255] of Char;
Buf2 : array[0..255] of Char;
{$ENDIF}
begin
I := GetListBoxItemIndex; {!!.07}
if (I > -1) then {!!.07}
if MessageDlg({$IFNDEF NoOgSrMgr}StrRes[SCDeleteQuery]{$ELSE}SCDeleteQuery{$ENDIF},
{$IFDEF UseOgFMX}TMsgDlgType.{$ENDIF}mtConfirmation,
{$IFDEF UseOgFMX}mbYesNo{$ELSE}[mbYes, mbNo]{$ENDIF}, 0) = mrYes then begin
{$IFDEF MSWINDOWS}
{$IFNDEF Win16}
IniFile := TIniFile.Create(KeyFileName);
try
IniFile.DeleteKey(OgKeySection, ProductsLb.Items[I]); {!!.07}
finally
IniFile.Free;
end;
{$ELSE}
StrPLCopy(Buf1, ProductsLb.Items[I], 255); {!!.07}
StrPLCopy(Buf2, KeyFileName, 255);
WritePrivateProfileString(OgKeySection, Buf1, nil, Buf2);
{$ENDIF}
{$ENDIF}
BlockKeyEd.Text := '';
BytesKeyEd.Text := '';
InfoChanged(Self);
end;
end;
procedure TKeyMaintFrm.KeyCopySbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
OldSelStart := BlockKeyEd.SelStart;
BlockKeyEd.SelStart := 0;
BlockKeyEd.SelLength := MaxInt;
BlockKeyEd.CopyToClipboard;
BlockKeyEd.SelStart := OldSelStart;
BlockKeyEd.SelLength := 0;
end;
procedure TKeyMaintFrm.CopyByteKeySbClick(Sender: TObject);
var
OldSelStart: Integer;
begin
OldSelStart := BytesKeyEd.SelStart;
BytesKeyEd.SelStart := 0;
BytesKeyEd.SelLength := MaxInt;
BytesKeyEd.CopyToClipboard;
BytesKeyEd.SelStart := OldSelStart;
BytesKeyEd.SelLength := 0;
end;
procedure TKeyMaintFrm.OpenFileSbClick(Sender: TObject);begin
OpenDialog1.FileName := FileNameEd.Text;
if OpenDialog1.Execute then begin
FileNameEd.Text := OpenDialog1.FileName;
InfoChanged(Sender);
end;
end;
function TKeyMaintFrm.GetKeyFileName : string;
begin
Result := FileNameEd.Text;
end;
procedure TKeyMaintFrm.SetKeyFileName(Value : string);
begin
FileNameEd.Text := Value;
InfoChanged(Self);
end;
procedure TKeyMaintFrm.OpenBtnClick(Sender: TObject);
begin
OpenDialog1.FileName := FileNameEd.Text;
FileNameEd.Text := OpenDialog1.FileName;
InfoChanged(Sender);
end;
procedure TKeyMaintFrm.ProductsLbDblClick(Sender: TObject);
begin
ModalResult := mrOK;
end;
procedure TKeyMaintFrm.KeyPasteSbClick(Sender: TObject);
begin
BlockKeyEd.PasteFromClipboard;
HexToBuffer(BlockKeyEd.Text, FKey, SizeOf(FKey));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
BytesKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
end;
procedure TKeyMaintFrm.SpeedButton1Click(Sender: TObject);
begin
BytesKeyEd.PasteFromClipboard;
HexToBuffer(BytesKeyEd.Text, FKey, SizeOf(FKey));
BytesKeyEd.Text := BufferToHexBytes(FKey, SizeOf(FKey));
BlockKeyEd.Text := BufferToHex(FKey, SizeOf(FKey));
end;
procedure TKeyMaintFrm.GetKey(var Value : TKey); {!!.08}
begin
Value := FKey;
end;
procedure TKeyMaintFrm.SetKey(Value : TKey); {!!.08}
begin
FKey := Value;
end;
end.