forked from geraldholdsworth/DiscImageManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWordEditorUnit.pas
269 lines (243 loc) · 8.86 KB
/
PWordEditorUnit.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
unit PWordEditorUnit;
{
Copyright (C) 2018-2023 Gerald Holdsworth [email protected]
This source is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public Licence as published by the Free
Software Foundation; either version 3 of the Licence, or (at your option)
any later version.
This code is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more
details.
A copy of the GNU General Public Licence is available on the World Wide Web
at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1335, USA.
}
{$mode objfpc}{$H+}
interface
uses
Classes,SysUtils,Forms,Controls,Graphics,Dialogs,ExtCtrls,StdCtrls,Buttons,
GJHCustomComponents,DiscImage;
type
{ TPwordEditorForm }
TPwordEditorForm = class(TForm)
AccountsPanel: TPanel;
HeaderPanel: TPanel;
AccountsScroll: TScrollBox;
ControlsPanel: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
btnAdd: TSpeedButton;
UsernamesHdr: TPanel;
PasswordsHdr: TPanel;
SystemHdr: TPanel;
LockedHdr: TPanel;
BootOptionHdr: TPanel;
OKButton,
CancelButton: TGJHButton;
procedure btnAddClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormShow(Sender: TObject);
function CreateNewEntry: Integer;
function CreateEditField(column: TPanel;maxlen,len: Integer): TEdit;
function CreateTickBox(column: TPanel;len: Integer): TGJHTickBox;
function CreateDropDown(column: TPanel;len: Integer): TComboBox;
procedure OKButtonClick(Sender: TObject);
private
Usernames: array of TEdit;
Passwords: array of TEdit;
System : array of TGJHTickBox;
Locked : array of TGJHTickBox;
BootOpts : array of TComboBox;
FreeSpc : array of TEdit;
public
UserAccounts: TUserAccounts;
end;
var
PwordEditorForm: TPwordEditorForm;
implementation
{$R *.lfm}
uses MainUnit;
{ TPwordEditorForm }
{------------------------------------------------------------------------------}
//Set the form up prior to opening it
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.FormShow(Sender: TObject);
var
index,
ctrl : Integer;
begin
//Is there anything to show?
if Length(UserAccounts)>0 then
for index:=0 to Length(UserAccounts)-1 do
begin
//Create a new entry and make a note of the reference
ctrl:=CreateNewEntry;
//Fill in the fields
Usernames[ctrl].Text :=UserAccounts[index].Username;
Passwords[ctrl].Text :=UserAccounts[index].Password;
System[ctrl].Ticked :=UserAccounts[index].System;
Locked[ctrl].Ticked :=UserAccounts[index].Locked;
BootOpts[ctrl].ItemIndex:=UserAccounts[index].BootOption;
FreeSpc[ctrl].Text :=IntToHex(UserAccounts[index].FreeSpace,8);
end;
end;
{------------------------------------------------------------------------------}
//Hide the form and delete all the dynamic components
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.FormHide(Sender: TObject);
var
len: Integer;
begin
//Continue while there are some components left
while Length(Usernames)>0 do
begin
//Take a note of the reference of the last one
len:=Length(Usernames)-1;
//Free up the components
Usernames[len].Free;
Passwords[len].Free;
System[len].Free;
Locked[len].Free;
BootOpts[len].Free;
FreeSpc[len].Free;
//Reduce the array lengths
SetLength(Usernames,len);
SetLength(Passwords,len);
SetLength(System,len);
SetLength(Locked,len);
SetLength(BootOpts,len);
SetLength(FreeSpc,len);
end;
btnAdd.Top:=0;
end;
{------------------------------------------------------------------------------}
//Texturise the form
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.FormPaint(Sender: TObject);
begin
MainForm.FileInfoPanelPaint(Sender);
end;
{------------------------------------------------------------------------------}
//Adds a new entry
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.btnAddClick(Sender: TObject);
begin
CreateNewEntry;
end;
{------------------------------------------------------------------------------}
//Create the form
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.FormCreate(Sender: TObject);
var
ratio : Real;
begin
ratio:=PixelsPerInch/DesignTimePPI;
OKButton:=MainForm.CreateButton(ControlsPanel as TControl,'OK',True,0,
Round(8*ratio),mrOK);
OKButton.Left:=ControlsPanel.ClientWidth-OKButton.Width-Round(8*ratio);
OKButton.OnClick:=@OKButtonClick;
CancelButton:=MainForm.CreateButton(ControlsPanel as TControl,'Cancel',False,
0,Round(12*ratio),mrCancel);
CancelButton.Left:=OKButton.Left-Round(8*ratio)-CancelButton.Width;
ControlsPanel.Height:=OKButton.Top+OKButton.Height+Round(8*ratio);
end;
{------------------------------------------------------------------------------}
//Create a new entry, including creating the components
{------------------------------------------------------------------------------}
function TPwordEditorForm.CreateNewEntry: Integer;
begin
//Take a note of the reference for the last one
Result:=Length(Usernames);
//Username
SetLength(Usernames,Result+1);
Usernames[Result]:=CreateEditField(UsernamesHdr,20,Result);
//Password
SetLength(Passwords,Result+1);
Passwords[Result]:=CreateEditField(PasswordsHdr,10,Result);
//Is it a system account?
SetLength(System,Result+1);
System[Result]:=CreateTickBox(SystemHdr,Result);
//Is it locked?
SetLength(Locked,Result+1);
Locked[Result]:=CreateTickBox(LockedHdr,Result);
//Boot option
SetLength(BootOpts,Result+1);
BootOpts[Result]:=CreateDropDown(BootOptionHdr,Result);
//Free space
SetLength(FreeSpc,Result+1);
FreeSpc[Result]:=CreateEditField(UsernamesHdr,8,Result);
FreeSpc[Result].Visible:=False; //This is hidden
//Move the add button
btnAdd.Top:=Usernames[Result].Top+Usernames[Result].Height;
end;
{------------------------------------------------------------------------------}
//Create a TEdit
{------------------------------------------------------------------------------}
function TPwordEditorForm.CreateEditField(column: TPanel;maxlen,len: Integer): TEdit;
begin
Result:=TEdit.Create(AccountsScroll);
Result.Parent:=AccountsScroll;
Result.Left:=column.Left;
Result.Width:=column.Width;
Result.Height:=22;
Result.Top:=(2+column.Height)*len;
Result.MaxLength:=maxlen;
end;
{------------------------------------------------------------------------------}
//Create a TCheckBox
{------------------------------------------------------------------------------}
function TPwordEditorForm.CreateTickBox(column: TPanel;len: Integer): TGJHTickBox;
begin
Result:=TGJHTickBox.Create(AccountsScroll);
Result.Parent:=AccountsScroll;
Result.Left:=column.Left+(column.Width-18)div 2;
Result.Top:=2+(2+column.Height)*len;
Result.Caption:='';
end;
{------------------------------------------------------------------------------}
//Create a TComboBox
{------------------------------------------------------------------------------}
function TPwordEditorForm.CreateDropDown(column: TPanel;len: Integer): TComboBox;
begin
Result:=TComboBox.Create(AccountsScroll);
Result.Parent:=AccountsScroll;
Result.Left:=column.Left;
Result.Top:=(2+column.Height)*len;
Result.Width:=column.Width;
Result.Items.AddCommaText('None,Load,Run,Execute');
Result.ItemIndex:=0;
Result.Style:=csDropDownList;
end;
{------------------------------------------------------------------------------}
//Gather the entries
{------------------------------------------------------------------------------}
procedure TPwordEditorForm.OKButtonClick(Sender: TObject);
var
index: Integer;
begin
//Reset the accounts to none
SetLength(UserAccounts,0);
//If there are any fields, go through them
if Length(Usernames)>0 then
for index:=0 to Length(Usernames)-1 do
if Usernames[index].Text<>'' then //If the username is blank, skip it
begin
//Increase the accounts array by one
SetLength(UserAccounts,Length(UserAccounts)+1);
//Populate it
UserAccounts[Length(UserAccounts)-1].Username :=Usernames[index].Text;
UserAccounts[Length(UserAccounts)-1].Password :=Passwords[index].Text;
UserAccounts[Length(UserAccounts)-1].System :=System[index].Ticked;
UserAccounts[Length(UserAccounts)-1].Locked :=Locked[index].Ticked;
UserAccounts[Length(UserAccounts)-1].BootOption:=BootOpts[index].ItemIndex;
UserAccounts[Length(UserAccounts)-1].FreeSpace :=StrToIntDef('$'+FreeSpc[index].Text,0);
end;
end;
end.