-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitConfig.pas
240 lines (211 loc) · 5.64 KB
/
UnitConfig.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
unit UnitConfig;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, IniFiles, ExtCtrls, ShellApi;
type
TFormConfig = class(TForm)
GroupBox1: TGroupBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn4: TBitBtn;
GroupBox2: TGroupBox;
ListBox1: TListBox;
Label5: TLabel;
Edit4: TEdit;
Edit3: TEdit;
BitBtn3: TBitBtn;
Label3: TLabel;
Edit7: TEdit;
BitBtn5: TBitBtn;
Edit5: TEdit;
Edit6: TEdit;
BitBtn6: TBitBtn;
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit8: TEdit;
CheckBox1: TCheckBox;
Button1: TButton;
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
Started: Boolean;
Closing: Boolean;
procedure Carregar;
procedure CarregarConfig(ConfigFile: string);
function Salvar: boolean;
procedure SalvarConfig;
procedure Cancelar;
{ Private declarations }
public
{ Public declarations }
end;
var
FormConfig: TFormConfig;
implementation
{$R *.dfm}
procedure TFormConfig.CarregarConfig(ConfigFile: string);
var
Ini: TIniFile;
LS: TStrings;
I: Integer;
begin
ini := TIniFile.Create(ConfigFile);
try
Edit1.Text := ini.readstring('irc', 'host', '200.142.160.127');
Edit2.Text := IntToStr(ini.ReadInteger('irc', 'port', 8000));
Edit3.Text := ini.readstring('irc', 'nick', '');
Edit4.Text := ini.readstring('irc', 'password', 'sesc');
Edit5.Text := ini.readstring('irc', 'altnick', '');
Edit6.Text := ini.readstring('irc', 'username', 'Alterar');
Edit7.Text := ini.readstring('irc', 'realname', Edit6.Text);
Edit8.Text := ini.readstring('irc', 'channel', 'ip-sesc');
Ini.ReadSection('Usuarios', ListBox1.Items);
if Listbox1.Items.Count = 0 then
begin
LS:= TStringList.Create;
Randomize;
for i := 0 to 9 do
LS.Add(Format('Antena%2.2d',[i+1]));
while LS.count>0 do
begin
I := Random(LS.Count);
Listbox1.Items.Add(LS[I]);
LS.Delete(I);
end;
end;
finally
Ini.Free();
end;
end;
procedure TFormConfig.SalvarConfig();
var
Ini: TMemIniFile;
i: Integer;
begin
Ini := TMemIniFile.Create(ExtractFilePath(ParamStr(0)) + '\config.ini');
try
Ini.WriteString('irc', 'host', Edit1.Text);
Ini.WriteString('irc', 'port', Edit2.Text);
Ini.WriteString('irc', 'nick', Edit3.Text);
Ini.WriteString('irc', 'password', Edit4.Text);
Ini.WriteString('irc', 'altnick', Edit5.Text);
Ini.WriteString('irc', 'username', Edit6.Text);
Ini.WriteString('irc', 'realname', Edit7.Text);
Ini.WriteString('irc', 'channel', Edit8.Text);
for i := 0 to ListBox1.Items.Count - 1 do
Ini.WriteString('Usuarios', ListBox1.Items[i], '');
Ini.UpdateFile();
finally
Ini.Free();
end;
end;
function TFormConfig.Salvar(): boolean;
begin
Result := False;
if Length(Edit7.Text)<5 then
begin
ShowMessage('O usuário deve conter mais que 4 letras');
Exit;
end
else
begin
Result := true;
SalvarConfig();
end;
end;
procedure TFormConfig.Carregar();
begin
CarregarConfig(ExtractFilePath(ParamStr(0)) + '\config.ini');
end;
procedure TFormConfig.BitBtn4Click(Sender: TObject);
begin
Carregar();
end;
procedure TFormConfig.BitBtn1Click(Sender: TObject);
begin
if Salvar() then
ModalResult := mrOk;
end;
procedure TFormConfig.FormCreate(Sender: TObject);
begin
Closing := False;
Started := False;
Carregar();
Started := True;
end;
procedure TFormConfig.BitBtn6Click(Sender: TObject);
begin
CarregarConfig('');
end;
procedure TFormConfig.BitBtn5Click(Sender: TObject);
begin
ListBox1.DeleteSelected();
BitBtn5.Enabled := False;
end;
procedure TFormConfig.Edit1Change(Sender: TObject);
begin
if Started then
BitBtn4.Enabled := True;
end;
procedure TFormConfig.ListBox1Click(Sender: TObject);
var
i: integer;
begin
for i:= 0 to ListBox1.Items.Count-1 do
begin
BitBtn5.Enabled := ListBox1.Selected[i];
if BitBtn5.Enabled then
Break;
end;
end;
procedure TFormConfig.BitBtn3Click(Sender: TObject);
var
newUser: string;
begin
newUser := InputBox('Novo Usuario', 'Usuario', '');
if newUser <> '' then
ListBox1.Items.Add(newUser);
end;
procedure TFormConfig.CheckBox1Click(Sender: TObject);
begin
Panel1.Enabled := CheckBox1.Checked;
end;
procedure TFormConfig.BitBtn2Click(Sender: TObject);
begin
Cancelar();
end;
procedure TFormConfig.Cancelar;
begin
//teve ateração?
if not BitBtn4.Enabled then
ModalResult := mrCancel
else
//confirma se descarta
if MessageDlg('Descarta alterações e fecha?',
mtConfirmation, [mbYes, mbNo], 0)=mrYes then
ModalResult := mrCancel
else
Exit;
end;
procedure TFormConfig.Button1Click(Sender: TObject);
begin
if FileExists('manual.mht') then
ShellExecute(Application.Handle, nil,'manual.mht', nil, nil, SW_SHOWNORMAL)
else
ShowMessage('Arquivo "manual.mht" não encontrado!');
end;
end.