-
Notifications
You must be signed in to change notification settings - Fork 13
/
SCCopyForm.pas
1234 lines (1059 loc) · 35 KB
/
SCCopyForm.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
This file is part of SuperCopier2.
SuperCopier2 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.
SuperCopier2 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 SCCopyForm;
{$MODE Delphi}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Forms,
Dialogs, StdCtrls, ComCtrls, Controls,
ExtCtrls, Spin, Menus, SCFilelist,ScBaseList,ShellApi,
SCCommon, SCProgessBar, {ScSystray,}
SCFileNameLabel, Buttons, ToolWin, ScPopupButton,SCLocEngine,Themes,
ScTrackBar;
const
WIDTH_DPI_MULTIPLIER=408/96;
FOLDED_HEIGHT_DPI_MULTIPLIER=145/96;
UNFOLDED_HEIGHT_DPI_MULTIPLIER=409/96;
type
TLvFileListAction=procedure(FileList:TFileList;Item:TListItem);
{ TCopyForm }
TCopyForm = class(TForm)
llAll: TLabel;
llSpeed: TLabel;
llFromTitle: TLabel;
llToTitle: TLabel;
pcPages: TPageControl;
tsCopyList: TTabSheet;
tsErrors: TTabSheet;
tsOptions: TTabSheet;
lvFileList: TListView;
lvErrorList: TListView;
pmFileContext: TPopupMenu;
miTop: TMenuItem;
miUp: TMenuItem;
miDown: TMenuItem;
miBottom: TMenuItem;
miRemove: TMenuItem;
miSelectAll: TMenuItem;
miInvert: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
pmNewFiles: TPopupMenu;
miChooseDest: TMenuItem;
miDefaultDest: TMenuItem;
miCancel: TMenuItem;
N3: TMenuItem;
odCopyList: TOpenDialog;
sdCopyList: TSaveDialog;
miChooseSetDefault: TMenuItem;
gbSpeedLimit: TGroupBox;
chSpeedLimit: TCheckBox;
llCustomSpeedLimit: TLabel;
gbCollisions: TGroupBox;
llCollisions: TLabel;
cbCollisions: TComboBox;
gbCopyErrors: TGroupBox;
llCopyErrors: TLabel;
cbCopyError: TComboBox;
gbCopyEnd: TGroupBox;
llCopyEnd: TLabel;
cbCopyEnd: TComboBox;
sdErrorLog: TSaveDialog;
btSaveDefaultCfg: TButton;
odFileAdd: TOpenDialog;
pmFileAdd: TPopupMenu;
miAddFiles: TMenuItem;
miAddFolder: TMenuItem;
ggFile: TSCProgessBar;
ggAll: TSCProgessBar;
Systray: TTrayIcon; //ScSystray;
tiSystray: TTimer;
llTo: TSCFileNameLabel;
llFrom: TSCFileNameLabel;
btFileTop: TSpeedButton;
btFileUp: TSpeedButton;
btFileDown: TSpeedButton;
btFileBottom: TSpeedButton;
btFileAdd: TSpeedButton;
btFileRemove: TSpeedButton;
btFileSave: TSpeedButton;
btFileLoad: TSpeedButton;
btErrorClear: TSpeedButton;
btErrorSaveLog: TSpeedButton;
btCancel: TScPopupButton;
btSkip: TScPopupButton;
btPause: TScPopupButton;
btResume: TScPopupButton;
btUnfold: TScPopupButton;
btFold: TScPopupButton;
pmSystray: TPopupMenu;
miStCancel: TMenuItem;
miStPause: TMenuItem;
miStResume: TMenuItem;
llFile: TSCFileNameLabel;
N4: TMenuItem;
miSort: TMenuItem;
miBySrcFullPath: TMenuItem;
miByDestFullPath: TMenuItem;
miBySize: TMenuItem;
miBySrcName: TMenuItem;
miBySrcExt: TMenuItem;
tbSpeedLimit: TScTrackBar;
edCustomSpeedLimit: TEdit;
llSpeedLimit: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure chSpeedLimitClick(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure lvFileListData(Sender: TObject; Item: TListItem);
procedure btErrorClearClick(Sender: TObject);
procedure btFileRemoveClick(Sender: TObject);
procedure miSelectAllClick(Sender: TObject);
procedure miInvertClick(Sender: TObject);
procedure btFileUpClick(Sender: TObject);
procedure btFileDownClick(Sender: TObject);
procedure btFileTopClick(Sender: TObject);
procedure btFileBottomClick(Sender: TObject);
procedure miDefaultDestClick(Sender: TObject);
procedure miChooseDestClick(Sender: TObject);
procedure miCancelClick(Sender: TObject);
procedure btFileSaveClick(Sender: TObject);
procedure btFileLoadClick(Sender: TObject);
procedure miChooseSetDefaultClick(
Sender: TObject);
procedure cbCopyEndChange(Sender: TObject);
procedure edCustomSpeedLimitKeyPress(Sender: TObject; var Key: Char);
procedure cbCollisionsChange(Sender: TObject);
procedure cbCopyErrorChange(Sender: TObject);
procedure btErrorSaveLogClick(Sender: TObject);
procedure pcPagesChange(Sender: TObject);
procedure btSaveDefaultCfgClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btFileAddClick(Sender: TObject);
procedure miAddFilesClick(Sender: TObject);
procedure miAddFolderClick(Sender: TObject);
procedure SystrayMouseDown(Sender: TObject);
procedure tiSystrayTimer(Sender: TObject);
procedure btCancelClick(Sender: TObject; ItemIndex: Integer);
procedure btSkipClick(Sender: TObject; ItemIndex: Integer);
procedure btPauseClick(Sender: TObject; ItemIndex: Integer);
procedure btUnfoldClick(Sender: TObject; ItemIndex: Integer);
procedure miStPauseClick(Sender: TObject);
procedure miStCancelClick(Sender: TObject);
procedure lvFileListColumnClick(Sender: TObject; Column: TListColumn);
procedure miBySrcFullPathClick(Sender: TObject);
procedure miBySrcNameClick(Sender: TObject);
procedure miByDestFullPathClick(Sender: TObject);
procedure miBySizeClick(Sender: TObject);
procedure miBySrcExtClick(Sender: TObject);
procedure tbSpeedLimitChange(Sender: TObject);
procedure edCustomSpeedLimitChange(Sender: TObject);
private
{ Dйclarations privйes }
SystrayBmp:TBitmap;
NewBaseList:TBaseList;
FState:TCopyWindowState;
FConfigData:TCopyWindowConfigData;
FUnfolded:Boolean;
FMinimized:Boolean;
FMinimizedToTray:Boolean;
procedure ProcessLvFileListAction(Action:TLvFileListAction;SelectedOnly:Boolean;BackwardScan:Boolean=True);
procedure OpenNewFilesMenu;
procedure SortFileList(Mode:TFileListSortMode);
procedure OnDropFiles_(var Msg:TMessage);// message WM_DROPFILES;
procedure OnWindowPosChanged(var Msg:TMessage); message WM_ACTIVATE;
procedure OnSysCommand(var Msg:TMessage); message WM_SYSCOMMAND;
procedure SetState(Value:TCopyWindowState);
procedure SetConfigData(Value:TCopyWindowConfigData);
procedure SetUnfolded(Value:Boolean);
procedure SetMinimized(Value:Boolean);
public
{ Dйclarations publiques }
Paused,SkipPending,CancelPending:Boolean;
CopyThread:TThread; // dйclarй en tant que TThread pour йviter la rйfйrence circulaire
UnfoldedHeight,NonClientHeight:Integer;
NotificationTargetForm:TForm;
property State:TCopyWindowState read FState write SetState;
property ConfigData:TCopyWindowConfigData read FConfigData write SetConfigData;
property Unfolded:Boolean read FUnfolded write SetUnfolded;
property Minimized:Boolean read FMinimized write SetMinimized;
property MinimizedToTray:Boolean read FMinimizedToTray;
procedure SaveCopyErrorLog(FileName:WideString);
end;
var
CopyForm: TCopyForm;
implementation
uses DateUtils,SCLocStrings,SCCopyThread, SCCopier,SCWin32,SCConfig, StrUtils,
SCMainForm, ImgList;
var DestIndex:Integer;
{$R *.lfm}
//******************************************************************************
// MoveSelectionInfo: passe les infos de sйlection et de focus d'un item а un autre
//******************************************************************************
procedure MoveSelectionInfo(Item:TListItem;DestIndex:Integer);
var Focused:Boolean;
Destination:TListItem;
begin
Focused:=Item.Focused;
Item.Selected:=False;
Destination:=Item.Owner.Item[DestIndex];
Destination.Selected:=True;
Destination.Focused:=Focused;
end;
//******************************************************************************
//******************************************************************************
// Actions sur lvFileList
//******************************************************************************
//******************************************************************************
procedure RemoveAction(Filelist:TFileList;Item:TListItem);
begin
Filelist.Delete(Item.Index+1,True);
end;
procedure SelectAction(Filelist:TFileList;Item:TListItem);
begin
Item.Selected:=True;
end;
procedure InvertAction(Filelist:TFileList;Item:TListItem);
begin
Item.Selected:=not Item.Selected;
end;
procedure MoveUpAction(Filelist:TFileList;Item:TListItem);
begin
if Item.Index>0 then
begin
Filelist.Move(Item.Index+1,Item.Index-1+1);
MoveSelectionInfo(Item,Item.Index-1);
end;
end;
procedure MoveDownAction(Filelist:TFileList;Item:TListItem);
begin
if Item.Index<Filelist.Count-2 then
begin
Filelist.Move(Item.Index+1,Item.Index+1+1);
MoveSelectionInfo(Item,Item.Index+1);
end;
end;
procedure MoveTopAction(Filelist:TFileList;Item:TListItem);
begin
Filelist.Move(Item.Index+1,DestIndex+1);
MoveSelectionInfo(Item,DestIndex);
Inc(DestIndex);
end;
procedure MoveBottomAction(Filelist:TFileList;Item:TListItem);
begin
Filelist.Move(Item.Index+1,DestIndex+1);
MoveSelectionInfo(Item,DestIndex);
Dec(DestIndex);
end;
//******************************************************************************
// ProcessLvFileListAction : exйcute une action sur les йlйments de lvFileList
//******************************************************************************
procedure TCopyForm.ProcessLvFileListAction(Action:TLvFileListAction;SelectedOnly:Boolean;BackwardScan:Boolean=True);
var i:Integer;
begin
Assert(Assigned(Action),'No action to do');
try
with TCopyThread(CopyThread).LockCopier do
begin
Screen.Cursor:=crHourGlass;
if SelectedOnly then
begin
if (lvFileList.SelCount=1) and (lvFileList.Selected <> nil) and (lvFileList.Selected.Index>1) then
begin
Action(FileList,lvFileList.Selected);
end
else
begin
if lvFileList.SelCount>0 then
begin
if BackwardScan then
begin
for i:=lvFileList.Items.Count-1 downto 0 do
if lvFileList.Items[i].Selected then Action(FileList,lvFileList.Items[i]);
end
else
begin
for i:=0 to lvFileList.Items.Count-1 do
if lvFileList.Items[i].Selected then Action(FileList,lvFileList.Items[i]);
end;
end;
end;
end
else
begin
if BackwardScan then
begin
for i:=lvFileList.Items.Count-1 downto 0 do
Action(FileList,lvFileList.Items[i]);
end
else
begin
for i:=0 to lvFileList.Items.Count-1 do
Action(FileList,lvFileList.Items[i]);
end;
end;
//maj info
TCopyThread(CopyThread).UpdateCopyWindow;
//maj listview
lvFileList.Invalidate;
lvFileList.Items.Count:=FileList.Count-1;
end;
finally
Screen.Cursor:=crDefault;
TCopyThread(CopyThread).UnlockCopier
end;
end;
//******************************************************************************
// OpenNewFilesMenu : open le menu permettant de choisir la destination
//******************************************************************************
procedure TCopyForm.OpenNewFilesMenu;
begin
// On ouvre le menu pour le choix de l'action
miDefaultDest.Enabled:=TCopyThread(CopyThread).DefaultDir<>'?';
miDefaultDest.Caption:=LeftStr(miDefaultDest.Caption,Pos('(',miDefaultDest.Caption))+TCopyThread(CopyThread).DefaultDir+')';
pmNewFiles.Popup(Mouse.CursorPos.X,Mouse.CursorPos.Y);
end;
//******************************************************************************
// SetState : appelйe quand la thread fait changer la fenкtre d'йtat
//******************************************************************************
procedure TCopyForm.SetState(Value:TCopyWindowState);
begin
FState:=Value;
case FState of
cwsWaiting,
cwsRecursing,
cwsCopyEnd:
begin
btPause.Enabled:=True;
btResume.Enabled:=True;
btSkip.Enabled:=False;
btCancel.Enabled:=True;
end;
cwsCopying:
begin
btPause.Enabled:=True;
btResume.Enabled:=True;
btSkip.Enabled:=True;
btCancel.Enabled:=True;
end;
cwsPaused:
begin
btPause.Enabled:=True;
btResume.Enabled:=True;
btCancel.Enabled:=True;
end;
cwsCancelling,
cwsWaitingActionResult:
begin
btPause.Enabled:=False;
btResume.Enabled:=False;
btSkip.Enabled:=False;
btCancel.Enabled:=False;
end;
end;
// menu systray
miStPause.Enabled:=btPause.Enabled;
miStResume.Enabled:=btResume.Enabled;
miStCancel.Enabled:=btCancel.Enabled;
end;
//******************************************************************************
// SetConfigData : appelйe quand la thread change la config de la fenкtre
//******************************************************************************
procedure TCopyForm.SetConfigData(Value:TCopyWindowConfigData);
begin
FConfigData:=Value;
with FConfigData do
begin
cbCopyEnd.ItemIndex:=Integer(CopyEndAction);
chSpeedLimit.Checked:=ThrottleEnabled;
edCustomSpeedLimit.Text:=IntToStr(ThrottleSpeedLimit);
tbSpeedLimit.Position:=SpeedLimitToIndex(ThrottleSpeedLimit);
cbCollisions.ItemIndex:=Integer(CollisionAction);
cbCopyError.ItemIndex:=Integer(CopyErrorAction);
end;
end;
//******************************************************************************
// SetUnfolded : change les paramкtres de la fenкtre pour passer en mode dйveloppй ou non
//******************************************************************************
procedure TCopyForm.SetUnfolded(Value:Boolean);
var NewClientHeight:Integer;
begin
FUnfolded:=Value;
if FUnfolded then
begin
NewClientHeight:=Round(UNFOLDED_HEIGHT_DPI_MULTIPLIER*PixelsPerInch);
Constraints.MinHeight:=NewClientHeight+NonClientHeight;
Constraints.MaxHeight:=0;
ClientHeight:=UnfoldedHeight;
btUnfold.Visible:=False;
btFold.Visible:=True;
end
else
begin
UnfoldedHeight:=ClientHeight;
NewClientHeight:=Round(FOLDED_HEIGHT_DPI_MULTIPLIER*PixelsPerInch);
Constraints.MinHeight:=NewClientHeight+NonClientHeight;
Constraints.MaxHeight:=NewClientHeight+NonClientHeight;
ClientHeight:=NewClientHeight;
btUnfold.Visible:=True;
btFold.Visible:=False;
end;
end;
//******************************************************************************
// SetMinimized : permets de minimiser la fenкtre dans la taskbar/le systray selon la config
//******************************************************************************
procedure TCopyForm.SetMinimized(Value:Boolean);
begin
FMinimized:=Value;
FMinimizedToTray:=False;
if FMinimized then
begin
if Config.Values.MinimizeToTray then
begin
WindowState:=wsMinimized;
FMinimizedToTray:=True;
Visible:=False;
tiSystray.Enabled:=True;
Systray.Visible:=True;
tiSystrayTimer(nil);
end
else
begin
//HACK: en utilisant WindowState, toutes les fenкtres de copies sont rйduites
// j'utilise donc direct l'API
SetForegroundWindow(Handle);
ShowWindow(Handle,SW_SHOWMINIMIZED);
if not Visible then Visible:=True;
end;
end
else
begin
WindowState:=wsNormal;
Visible:=True;
Systray.Visible:=False;
tiSystray.Enabled:=False;
// si une form est en attente aprиs une notification, l'afficher
if Assigned(NotificationTargetForm) then NotificationTargetForm.Visible:=True;
NotificationTargetForm:=nil;
end;
end;
//******************************************************************************
// SaveCopyErrorLog : йcrit le log des erreurs dans un fichier
//******************************************************************************
procedure TCopyForm.SaveCopyErrorLog(FileName:WideString);
var Log:TStringList;
FS:TFileStream;
i:integer;
begin
Log:=TStringList.Create;
try
try
// entete
Log.Add(Format('*** %s: %s ***',[DateToStr(Date),TCopyThread(CopyThread).DisplayName]));
// liste des erreurs
for i:=0 to lvErrorList.Items.Count-1 do
with lvErrorList.Items[i] do
begin
Log.Add(Format('%s %s %s : %s',[Caption,SubItems[0],SubItems[1],SubItems[2]]));
end;
// on s'assure que le rep du log existe
ForceDirectories(ExtractFilePath(FileName));
// on crйe le fichier si il n'existe pas et on l'ouvre si il existe
if FileExists(FileName) then
FS:=TFileStream.Create(FileName,fmOpenReadWrite)
else
FS:=TFileStream.Create(FileName,fmCreate);
try
// on se place a la fin du fichier
FS.Seek(0,soEnd);
Log.SaveToStream(FS);
finally
FS.Free;
end;
finally
Log.Free;
end;
except
on E:Exception do SCWin32.MessageBox(Handle,E.Message,Caption,MB_ICONERROR);
end;
end;
//******************************************************************************
// SortFileList : tri de la liste de fichiers
//******************************************************************************
procedure TCopyForm.SortFileList(Mode: TFileListSortMode);
begin
with TCopyThread(CopyThread).LockCopier do
try
if FileList.SortMode=Mode then
FileList.SortReverse:=not FileList.SortReverse
else
FileList.SortReverse:=False;
FileList.SortMode:=Mode;
FileList.Sort;
//maj listview
lvFileList.Invalidate;
lvFileList.Items.Count:=FileList.Count-1;
finally
TCopyThread(CopyThread).UnlockCopier
end;
end;
procedure TCopyForm.FormCreate(Sender: TObject);
var ExStyle:Cardinal;
begin
LocEngine.TranslateForm(Self);
//HACK: correction d'un bug de taille de police sous NT4
if (Win32Platform=VER_PLATFORM_WIN32_NT) and (Win32MajorVersion=4) and (PixelsPerInch=96) then
PixelsPerInch:=Round(PixelsPerInch*Width/(WIDTH_DPI_MULTIPLIER*96));
//HACK: ne pas mettre directement la fenкtre en resizeable pour que
// la gestion des grandes polices puisse la redimentionner
BorderStyle:=bsSizeable;
//HACK: fix temporaire pour les pb de scintillement des barres de progression
// avec les thиmes activйs
DoubleBuffered:=ThemeServices.ThemesEnabled;
// init variables
NonClientHeight:=Height-ClientHeight;
UnfoldedHeight:=Round(UNFOLDED_HEIGHT_DPI_MULTIPLIER*PixelsPerInch);
Constraints.MinWidth:=Round(WIDTH_DPI_MULTIPLIER*PixelsPerInch);
CancelPending:=False;
SkipPending:=False;
Paused:=False;
State:=cwsWaiting;
NotificationTargetForm:=nil;
NewBaseList:=nil;
// charger la config par dйfaut
ConfigData:=Config.Values.DefaultCopyWindowConfig;
// chargement taille/position
if Config.Values.CopyWindowSaveSize then
begin
Width:=Config.Values.CopyWindowWidth;
UnfoldedHeight:=Config.Values.CopyWindowHeight;
Unfolded:=Config.Values.CopyWindowUnfolded;
end
else
begin
Unfolded:=False;
end;
if Config.Values.CopyWindowSavePosition then
begin
Position:=poDesigned;
Top:=Config.Values.CopyWindowTop;
Left:=Config.Values.CopyWindowLeft;
end;
// chargement apparence des progress
with Config.Values do
begin
ggFile.FontTxt.Color:=ProgressTextColor;
ggFile.FontProgress.Color:=ProgressTextColor;
ggFile.FontTxtColor:=ProgressOutlineColor;
ggFile.FontProgressColor:=ProgressOutlineColor;
ggFile.FrontColor1:=ProgressForegroundColor1;
ggFile.FrontColor2:=ProgressForegroundColor2;
ggFile.BackColor1:=ProgressBackgroundColor1;
ggFile.BackColor2:=ProgressBackgroundColor2;
ggFile.BorderColor:=ProgressBorderColor;
ggAll.FontTxt.Color:=ProgressTextColor;
ggAll.FontProgress.Color:=ProgressTextColor;
ggAll.FontTxtColor:=ProgressOutlineColor;
ggAll.FontProgressColor:=ProgressOutlineColor;
ggAll.FrontColor1:=ProgressForegroundColor1;
ggAll.FrontColor2:=ProgressForegroundColor2;
ggAll.BackColor1:=ProgressBackgroundColor1;
ggAll.BackColor2:=ProgressBackgroundColor2;
ggAll.BorderColor:=ProgressBorderColor;
end;
// chargement des glyphs des boutons
with MainForm.ilGlobal do
begin
GetBitmap(12,btFileTop.Glyph);
GetBitmap(10,btFileUp.Glyph);
GetBitmap(11,btFileDown.Glyph);
GetBitmap(13,btFileBottom.Glyph);
GetBitmap(14,btFileAdd.Glyph);
GetBitmap(15,btFileRemove.Glyph);
GetBitmap(17,btFileLoad.Glyph);
GetBitmap(16,btFileSave.Glyph);
GetBitmap(18,btErrorClear.Glyph);
GetBitmap(16,btErrorSaveLog.Glyph);
end;
// si on ne minimise pas dans le systray, afficher un tab dans la
// barre des tвches sinon passer la form en always on top
if not Config.Values.MinimizeToTray then
begin
ExStyle:=GetWindowLong(Handle,GWL_EXSTYLE);
SetWindowLong(Handle,GWL_EXSTYLE,ExStyle or WS_EX_APPWINDOW);
end
else
begin
FormStyle:=fsStayOnTop;
end;
// init du bitmap qui servira pour le systray
SystrayBmp:=TBitmap.Create;
with SystrayBmp do
begin
PixelFormat:=pf24bit;
Width:=16;
Height:=16;
Canvas.Brush.Color:=clBlack;
Canvas.FillRect(Canvas.ClipRect);
Canvas.Font.Size:=9;
Canvas.Font.Name:='Arial';
Canvas.Font.Color:=clWhite;
end;
tiSystray.Enabled:=True;
// accepter le drag & drop
//DragAcceptFiles(lvFileList.Handle,True);
pcPages.ActivePage:=tsCopyList;
if Config.Values.CopyWindowStartMinimized then Minimized:=True;
end;
procedure TCopyForm.btSaveDefaultCfgClick(Sender: TObject);
begin
Config.Values.DefaultCopyWindowConfig:=ConfigData;
end;
procedure TCopyForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
btCancelClick(nil,0);
CanClose:=False;
end;
procedure TCopyForm.FormDestroy(Sender: TObject);
begin
// sauvegarde taille/position
if Config.Values.CopyWindowSaveSize then
begin
Config.Values.CopyWindowWidth:=Width;
if Unfolded then
Config.Values.CopyWindowHeight:=Height
else
Config.Values.CopyWindowHeight:=UnfoldedHeight;
Config.Values.CopyWindowUnfolded:=Unfolded;
end;
if Config.Values.CopyWindowSavePosition then
begin
Config.Values.CopyWindowTop:=Top;
Config.Values.CopyWindowLeft:=Left;
end;
// libйration
SystrayBmp.Free;
end;
procedure TCopyForm.pcPagesChange(Sender: TObject);
begin
if pcPages.ActivePage=tsErrors then tsErrors.Show;
end;
procedure TCopyForm.lvFileListData(Sender: TObject; Item: TListItem);
begin
try
with TCopyThread(CopyThread).LockCopier,TListItem(Item) do
begin
if Index<FileList.Count-1 then
with FileList[Item.Index+1] do
begin
Caption:=SrcFullName;
SubItems.Add(SizeToString(SrcSize,Config.Values.SizeUnit));
SubItems.Add(Directory.Destpath);
end;
end;
finally
TCopyThread(CopyThread).UnlockCopier
end;
end;
procedure TCopyForm.btErrorClearClick(Sender: TObject);
begin
lvErrorList.Clear;
end;
procedure TCopyForm.btErrorSaveLogClick(Sender: TObject);
begin
FixParentBugs;
sdErrorLog.InitialDir:=TCopyThread(CopyThread).DefaultDir;
sdErrorLog.FileName:=ExtractFileName(Config.Values.ErrorLogFileName);
if sdErrorLog.Execute then
try
Screen.Cursor:=crHourGlass;
SaveCopyErrorLog(sdErrorLog.FileName);
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TCopyForm.btFileRemoveClick(Sender: TObject);
begin
ProcessLvFileListAction(RemoveAction,True);
end;
procedure TCopyForm.miSelectAllClick(Sender: TObject);
begin
ProcessLvFileListAction(SelectAction,False);
end;
procedure TCopyForm.miInvertClick(Sender: TObject);
begin
ProcessLvFileListAction(InvertAction,False);
end;
procedure TCopyForm.btFileUpClick(Sender: TObject);
begin
ProcessLvFileListAction(MoveUpAction,True,False);
end;
procedure TCopyForm.btFileDownClick(Sender: TObject);
begin
ProcessLvFileListAction(MoveDownAction,True);
end;
procedure TCopyForm.btFileTopClick(Sender: TObject);
begin
DestIndex:=0;
ProcessLvFileListAction(MoveTopAction,True,False);
end;
procedure TCopyForm.btFileBottomClick(Sender: TObject);
begin
DestIndex:=lvFileList.Items.Count-1;
ProcessLvFileListAction(MoveBottomAction,True);
end;
procedure TCopyForm.btFileAddClick(Sender: TObject);
begin
pmFileAdd.Popup(Mouse.CursorPos.X,Mouse.CursorPos.Y);
end;
procedure TCopyForm.btFileSaveClick(Sender: TObject);
var FS:TFileStream;
begin
FixParentBugs;
if sdCopyList.Execute then
begin
try
Screen.Cursor:=crHourGlass;
with TCopyThread(CopyThread).LockCopier do
begin
FS:=TFileStream.Create(sdCopyList.FileName,fmCreate);
try
SaveToStream(FS);
finally
FS.Free;
end;
end;
finally
TCopyThread(CopyThread).UnlockCopier;
Screen.Cursor:=crDefault;
end;
end;
end;
procedure TCopyForm.btFileLoadClick(Sender: TObject);
var FS:TFileStream;
begin
FixParentBugs;
if odCopyList.Execute then
begin
try
Screen.Cursor:=crHourGlass;
with TCopyThread(CopyThread).LockCopier do
begin
FS:=TFileStream.Create(odCopyList.FileName,fmOpenRead);
try
LoadFromStream(FS);
finally
FS.Free;
end;
//maj info
TCopyThread(CopyThread).UpdateCopyWindow;
//maj listview
lvFileList.Invalidate;
lvFileList.Items.Count:=FileList.Count-1;
end;
finally
TCopyThread(CopyThread).UnlockCopier;
Screen.Cursor:=crDefault;
end;
end;
end;
procedure TCopyForm.miDefaultDestClick(Sender: TObject);
begin
TCopyThread(CopyThread).AddBaseList(NewBaseList,amDefaultDir);
NewBaseList:=nil;
end;
procedure TCopyForm.miChooseDestClick(Sender: TObject);
begin
TCopyThread(CopyThread).AddBaseList(NewBaseList,amPromptForDest);
NewBaseList:=nil;
end;
procedure TCopyForm.miChooseSetDefaultClick(
Sender: TObject);
begin
TCopyThread(CopyThread).AddBaseList(NewBaseList,amPromptForDestAndSetDefault);
NewBaseList:=nil;
end;
procedure TCopyForm.miCancelClick(Sender: TObject);
begin
// on libиre la baselist vu qu'elle ne vas pas кtre traitйe
NewBaseList.Free;
NewBaseList:=nil;
end;
procedure TCopyForm.cbCopyEndChange(Sender: TObject);
begin
FConfigData.CopyEndAction:=TCopyWindowCopyEndAction(cbCopyEnd.ItemIndex);
end;
procedure TCopyForm.chSpeedLimitClick(Sender: TObject);
begin
tbSpeedLimit.Enabled:=chSpeedLimit.Checked;
edCustomSpeedLimit.Enabled:=chSpeedLimit.Checked;
llCustomSpeedLimit.Enabled:=chSpeedLimit.Checked;
llSpeedLimit.Enabled:=chSpeedLimit.Checked;
FConfigData.ThrottleEnabled:=chSpeedLimit.Checked;
end;
procedure TCopyForm.FormDropFiles(Sender: TObject; const FileNames: array of String);
var
i:integer;
BaseItem:TBaseItem;
begin
try
Screen.Cursor:=crHourGlass;
if Assigned(NewBaseList) then
begin
NewBaseList.Free;
NewBaseList := nil;
end;
// on construit la BaseList
if Length(FileNames) = 0 then exit;
NewBaseList:=TBaseList.Create;
for i:=0 to Length(FileNames)-1 do
begin
BaseItem:=TBaseItem.Create;
BaseItem.SrcName:=FileNames[i];
BaseItem.IsDirectory:=DirectoryExists(FileNames[i]);
NewBaseList.Add(BaseItem);
end;
OpenNewFilesMenu;
finally
Screen.Cursor:=crDefault;
end;
end;
procedure TCopyForm.edCustomSpeedLimitChange(Sender: TObject);
begin
FConfigData.ThrottleSpeedLimit:=StrToIntDef(edCustomSpeedLimit.Text,-1);
end;
procedure TCopyForm.edCustomSpeedLimitKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9']) and (Key>#31) then Key:=#0; // autoriser seulement les chiffres et les caractиres de contrфle
end;
procedure TCopyForm.tbSpeedLimitChange(Sender: TObject);
var IsCustom:Boolean;
begin
IsCustom:=tbSpeedLimit.Position=0;
edCustomSpeedLimit.Visible:=IsCustom;
llCustomSpeedLimit.Visible:=IsCustom;
llSpeedLimit.Visible:=not IsCustom;
if not IsCustom then
begin
FConfigData.ThrottleSpeedLimit:=IndexToSpeedLimit(tbSpeedLimit.Position);
llSpeedLimit.Caption:=SizeToString(FConfigData.ThrottleSpeedLimit*1024);
end
else
edCustomSpeedLimitChange(nil);
end;
procedure TCopyForm.cbCollisionsChange(Sender: TObject);
begin
FConfigData.CollisionAction:=TCollisionAction(cbCollisions.ItemIndex);
end;
procedure TCopyForm.cbCopyErrorChange(Sender: TObject);
begin
FConfigData.CopyErrorAction:=TCopyErrorAction(cbCopyError.ItemIndex);
end;
procedure TCopyForm.miAddFilesClick(Sender: TObject);
var i:integer;
BaseItem:TBaseItem;
begin
FixParentBugs;
if odFileAdd.Execute then
begin
if Assigned(NewBaseList) then NewBaseList.Free;
NewBaseList:=TBaseList.Create;