forked from transmission-remote-gui/transgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
7850 lines (7257 loc) · 242 KB
/
main.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 Transmission Remote GUI.
Copyright (c) 2008-2014 by Yury Sidorov.
Transmission Remote GUI 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.
Transmission Remote GUI 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.
You should have received a copy of the GNU General Public License
along with Transmission Remote GUI; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*************************************************************************************}
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, zstream, LResources, Forms, Controls,
{$ifdef windows}
windows, ShellApi,
{$else}
lclintf,
{$endif windows}
Graphics, Dialogs, ComCtrls, Menus, ActnList, LCLVersion,
httpsend, StdCtrls, fpjson, jsonparser, ExtCtrls, rpc, syncobjs, variants, varlist, IpResolver,
zipper, ResTranslator, VarGrid, StrUtils, LCLProc, Grids, BaseForm, utils, AddTorrent, Types, LazFileUtils, LazUTF8, StringToVK;
const
AppName = 'Transmission Remote GUI';
AppVersion = '5.15.3';
resourcestring
sAll = 'All torrents';
sWaiting = 'Waiting';
sVerifying = 'Verifying';
sDownloading = 'Downloading';
sSeeding = 'Seeding';
sFinished = 'Finished';
sStopped = 'Stopped';
sUnknown = 'Unknown';
sCompleted = 'Completed';
sConnected = 'connected';
sActive = 'Active';
sInactive = 'Inactive';
sErrorState = 'Error';
sUpdating = 'Updating...';
sFinishedDownload = '''%s'' has finished downloading';
sDownloadComplete = 'Download complete';
sUpdateComplete = 'Update complete.';
sTorrentVerification = 'Torrent verification may take a long time.' + LineEnding + 'Are you sure to start verification of torrent ''%s''?';
sTorrentsVerification = 'Torrents verification may take a long time.' + LineEnding + 'Are you sure to start verification of %d torrents?';
sReconnect = 'Reconnect in %d seconds.';
sDisconnected = 'Disconnected';
sConnectingToDaemon = 'Connecting to daemon...';
sLanguagePathFile = 'Language pathfile';
sLanguagePath = 'Language path';
sLanguageList = 'Language list';
sSecs = '%ds';
sMins = '%dm';
sHours = '%dh';
sDays = '%dd';
sMonths = '%dmo';
sYears = '%dy';
sDownloadingSeeding = '%s%s%d downloading, %d seeding%s%s, %s';
sDownSpeed = 'D: %s/s';
sUpSpeed = 'U: %s/s';
SFreeSpace = 'Free: %s';
sNoPathMapping = 'Unable to find path mapping.'+LineEnding+'Use the application''s options to setup path mappings.';
sGeoIPConfirm = 'Geo IP database is needed to resolve country by IP address.' + LineEnding + 'Download this database now?';
sFlagArchiveConfirm = 'Flag images archive is needed to display country flags.' + LineEnding + 'Download this archive now?';
sInSwarm = 'in swarm';
sHashfails = '%s (%d hashfails)';
sDone = '%s (%s done)';
sHave = '%d x %s (have %d)';
sUnableExtractFlag = 'Unable to extract flag image.';
sTrackerWorking = 'Working';
sTrackerUpdating = 'Updating';
sRestartRequired = 'You need to restart the application to apply changes.';
sRemoveTorrentData = 'Are you sure to remove torrent ''%s'' and all associated DATA?';
sRemoveTorrentDataMulti = 'Are you sure to remove %d selected torrents and all their associated DATA?';
sRemoveTorrent = 'Are you sure to remove torrent ''%s''?';
sRemoveTorrentMulti = 'Are you sure to remove %d selected torrents?';
sUnableGetFilesList = 'Unable to get files list';
sTrackerError = 'Tracker';
sSkip = 'skip';
sLow = 'low';
sNormal = 'normal';
sHigh = 'high';
sByte = 'b';
sKByte = 'KB';
sMByte = 'MB';
sGByte = 'GB';
sTByte = 'TB';
sPerSecond = '/s';
sOf = 'of';
sNoTracker = 'No tracker';
sTorrents = 'Torrents';
sBlocklistUpdateComplete = 'The block list has been updated successfully.' + LineEnding + 'The list entries count: %d.';
sSeveralTorrents = '%d torrents';
sUnableToExecute = 'Unable to execute "%s".';
sSSLLoadError = 'Unable to load OpenSSL library files: %s and %s';
SRemoveTracker = 'Are you sure to remove tracker ''%s''?';
SUnlimited = 'Unlimited';
SAverage = 'average';
SCheckNewVersion = 'Do you wish to enable automatic checking for a new version of %s?';
SDuplicateTorrent = 'Torrent already exists in the list';
SUpdateTrackers = 'Update trackers for the existing torrent?';
SDownloadingTorrent = 'Downloading torrent file...';
SConnectTo = 'Connect to %s';
SEnterPassword = 'Please enter a password to connect to %s:';
SDownloaded = 'Downloaded';
SUploaded = 'Uploaded';
SFilesAdded = 'Files added';
SActiveTime = 'Active time';
STotalSize = 'Total: %s';
sTotalSizeToDownload = 'Selected: %s';
sTotalDownloaded = 'Done: %s';
sTotalRemain = 'Remaining: %s';
sUserMenu = 'User Menu';
sBiDiDefault = 'Default';
sBiDiLeftRight = 'Left->Right';
sBiDiRightLeft = 'Right->Left';
sBiDiRightLeftNoAlign = 'Right->Left (No Align)';
sBiDiRightLeftReadOnly = 'Right->Left (Reading Only)';
type
// for torrent folder
FolderData = class
public
Hit: integer;
Ext: string;
Txt: string;
Lst: TDate;
end;
{ TProgressImage }
TProgressImage = class(TGraphicControl)
private
FBmp: TBitmap;
FBorderColor: TColor;
FEndIndex: integer;
FImageIndex: integer;
FImages: TImageList;
FStartIndex: integer;
FTimer: TTimer;
function GetFrameDelay: integer;
procedure SetBorderColor(const AValue: TColor);
procedure SetEndIndex(const AValue: integer);
procedure SetFrameDelay(const AValue: integer);
procedure SetImageIndex(const AValue: integer);
procedure SetImages(const AValue: TImageList);
procedure SetStartIndex(const AValue: integer);
procedure UpdateIndex;
procedure DoTimer(Sender: TObject);
protected
procedure Paint; override;
procedure VisibleChanged; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Images: TImageList read FImages write SetImages;
property ImageIndex: integer read FImageIndex write SetImageIndex;
property StartIndex: integer read FStartIndex write SetStartIndex;
property EndIndex: integer read FEndIndex write SetEndIndex;
property FrameDelay: integer read GetFrameDelay write SetFrameDelay;
property BorderColor: TColor read FBorderColor write SetBorderColor;
end;
{ TMainForm }
TMainForm = class(TBaseForm)
acConnect: TAction;
acAddTorrent: TAction;
acExport: TAction;
acImport: TAction;
acStopTorrent: TAction;
acRemoveTorrent: TAction;
acStartTorrent: TAction;
acSetHighPriority: TAction;
acSetNormalPriority: TAction;
acSetLowPriority: TAction;
acSetNotDownload: TAction;
acOptions: TAction;
acDaemonOptions: TAction;
acStartAllTorrents: TAction;
acStopAllTorrents: TAction;
acExit: TAction;
acResolveHost: TAction;
acResolveCountry: TAction;
acShowCountryFlag: TAction;
acSetupColumns: TAction;
acRemoveTorrentAndData: TAction;
acOpenFile: TAction;
acOpenContainingFolder: TAction;
acAddLink: TAction;
acReannounceTorrent: TAction;
acMoveTorrent: TAction;
acSelectAll: TAction;
acShowApp: TAction;
acHideApp: TAction;
acAddTracker: TAction;
acEditTracker: TAction;
acDelTracker: TAction;
acConnOptions: TAction;
acNewConnection: TAction;
acDisconnect: TAction;
acAltSpeed: TAction;
acForceStartTorrent: TAction;
acQMoveTop: TAction;
acQMoveUp: TAction;
acQMoveDown: TAction;
acQMoveBottom: TAction;
acCheckNewVersion: TAction;
acFolderGrouping: TAction;
acAdvEditTrackers: TAction;
acFilterPane: TAction;
acMenuShow : TAction;
acBigToolbar: TAction;
ImageList32: TImageList;
MenuItem103: TMenuItem;
MenuShow: TAction;
ActionList1: TActionList;
acToolbarShow : TAction;
acInfoPane: TAction;
acStatusBar: TAction;
acCopyPath: TAction;
acRename: TAction;
acStatusBarSizes: TAction;
acTrackerGrouping: TAction;
acUpdateBlocklist: TAction;
acUpdateGeoIP: TAction;
acTorrentProps: TAction;
acVerifyTorrent: TAction;
ActionList: TActionList;
ApplicationProperties: TApplicationProperties;
MenuItem501: TMenuItem;
MenuItem502: TMenuItem;
SearchToolbar: TToolBar;
tbSearchCancel: TToolButton;
LocalWatchTimer: TTimer;
txMagLabel: TLabel;
txMagnetLink: TEdit;
MenuItem101: TMenuItem;
MenuItem102: TMenuItem;
edSearch: TEdit;
imgSearch: TImage;
imgFlags: TImageList;
ImageList16: TImageList;
FilterTimer: TTimer;
MenuItem100: TMenuItem;
MenuItem122: TMenuItem;
MenuItem1888: TMenuItem;
MenuItem1889: TMenuItem;
MenuItem1890: TMenuItem;
MenuItem68: TMenuItem;
MenuItem93: TMenuItem;
MenuItem94: TMenuItem;
MenuItem95: TMenuItem;
MenuItem96: TMenuItem;
MenuItem97: TMenuItem;
MenuItem98: TMenuItem;
MenuItem99: TMenuItem;
miExport: TMenuItem;
miImport: TMenuItem;
OpenDialog1: TOpenDialog;
panDetailsWait: TPanel;
SaveDialog1: TSaveDialog;
ToolButton5: TToolButton;
txGlobalStats: TLabel;
lvFilter: TVarGrid;
lvTrackers: TVarGrid;
MenuItem25: TMenuItem;
MenuItem34: TMenuItem;
MenuItem35: TMenuItem;
MenuItem40: TMenuItem;
MenuItem41: TMenuItem;
MenuItem43: TMenuItem;
MenuItem63: TMenuItem;
MenuItem64: TMenuItem;
MenuItem77: TMenuItem;
MenuItem78: TMenuItem;
MenuItem79: TMenuItem;
MenuItem80: TMenuItem;
MenuItem81: TMenuItem;
MenuItem82: TMenuItem;
MenuItem83: TMenuItem;
MenuItem84: TMenuItem;
MenuItem85: TMenuItem;
MenuItem86: TMenuItem;
MenuItem87: TMenuItem;
MenuItem88: TMenuItem;
MenuItem89: TMenuItem;
MenuItem90: TMenuItem;
MenuItem91: TMenuItem;
MenuItem92: TMenuItem;
miView: TMenuItem;
goDevelopmentSite: TMenuItem;
miHomePage: TMenuItem;
pmiQueue: TMenuItem;
miQueue: TMenuItem;
pmFilter: TPopupMenu;
sepTrackers: TMenuItem;
MenuItem65: TMenuItem;
MenuItem66: TMenuItem;
MenuItem67: TMenuItem;
MenuItem69: TMenuItem;
MenuItem70: TMenuItem;
MenuItem72: TMenuItem;
MenuItem76: TMenuItem;
pmiUpSpeedLimit: TMenuItem;
pmiDownSpeedLimit: TMenuItem;
pmDownSpeeds: TPopupMenu;
pmUpSpeeds: TPopupMenu;
sepCon2: TMenuItem;
MenuItem71: TMenuItem;
sepCon1: TMenuItem;
MenuItem73: TMenuItem;
MenuItem74: TMenuItem;
MenuItem75: TMenuItem;
pmSepOpen2: TMenuItem;
MenuItem42: TMenuItem;
pmSepOpen1: TMenuItem;
MenuItem44: TMenuItem;
MenuItem45: TMenuItem;
MenuItem46: TMenuItem;
MenuItem47: TMenuItem;
MenuItem48: TMenuItem;
MenuItem49: TMenuItem;
MenuItem50: TMenuItem;
MenuItem51: TMenuItem;
MenuItem52: TMenuItem;
MenuItem53: TMenuItem;
MenuItem54: TMenuItem;
MenuItem55: TMenuItem;
MenuItem56: TMenuItem;
MenuItem58: TMenuItem;
MenuItem59: TMenuItem;
MenuItem60: TMenuItem;
MenuItem61: TMenuItem;
MenuItem62: TMenuItem;
miPriority: TMenuItem;
pmiPriority: TMenuItem;
MenuItem57: TMenuItem;
pbDownloaded: TPaintBox;
pmTrackers: TPopupMenu;
pmConnections: TPopupMenu;
tabStats: TTabSheet;
tabTrackers: TTabSheet;
tbConnect: TToolButton;
tbtAltSpeed: TToolButton;
sepAltSpeed: TToolButton;
sepQueue: TToolButton;
tbQMoveUp: TToolButton;
tbQMoveDown: TToolButton;
ToolButton9: TToolButton;
txConnErrorLabel: TLabel;
panSearch: TPanel;
panFilter: TPanel;
panReconnectFrame: TShape;
txReconnectSecs: TLabel;
txConnError: TLabel;
MenuItem38: TMenuItem;
MenuItem39: TMenuItem;
panReconnect: TPanel;
txLastActive: TLabel;
txLastActiveLabel: TLabel;
txTracker: TLabel;
txTrackerLabel: TLabel;
txCompletedOn: TLabel;
txCompletedOnLabel: TLabel;
txAddedOn: TLabel;
txAddedOnLabel: TLabel;
MenuItem19: TMenuItem;
MenuItem20: TMenuItem;
MenuItem21: TMenuItem;
MenuItem22: TMenuItem;
MenuItem23: TMenuItem;
MenuItem24: TMenuItem;
miTSep1: TMenuItem;
MenuItem26: TMenuItem;
MenuItem27: TMenuItem;
MenuItem28: TMenuItem;
MenuItem29: TMenuItem;
MenuItem30: TMenuItem;
MenuItem31: TMenuItem;
MenuItem32: TMenuItem;
MenuItem33: TMenuItem;
MenuItem36: TMenuItem;
MenuItem37: TMenuItem;
miAbout: TMenuItem;
miHelp: TMenuItem;
panTop: TPanel;
pmTray: TPopupMenu;
HSplitter: TSplitter;
pmPeers: TPopupMenu;
TrayIcon: TTrayIcon;
txCreated: TLabel;
txCreatedLabel: TLabel;
txTorrentHeader: TPanel;
txTorrentName: TLabel;
txTorrentNameLabel: TLabel;
txDownProgress: TLabel;
txDownProgressLabel: TLabel;
panProgress: TPanel;
txMaxPeers: TLabel;
txMaxPeersLabel: TLabel;
txPeers: TLabel;
txPeersLabel: TLabel;
txSeeds: TLabel;
txSeedsLabel: TLabel;
txDummy2: TLabel;
txTrackerUpdate: TLabel;
txDummy1: TLabel;
txRemaining: TLabel;
txRemainingLabel: TLabel;
txStatus: TLabel;
txStatusLabel: TLabel;
txRatio: TLabel;
txRatioLabel: TLabel;
txDownLimit: TLabel;
txDownLimitLabel: TLabel;
txTrackerUpdateLabel: TLabel;
txTransferHeader: TPanel;
txUpSpeed: TLabel;
txUpLimit: TLabel;
txUpSpeedLabel: TLabel;
txDownSpeed: TLabel;
txDownSpeedLabel: TLabel;
txUploaded: TLabel;
txUploadedLabel: TLabel;
txDownloaded: TLabel;
txDownloadedLabel: TLabel;
txUpLimitLabel: TLabel;
txWasted: TLabel;
txWastedLabel: TLabel;
miCopyLabel: TMenuItem;
pmLabels: TPopupMenu;
txError: TLabel;
txErrorLabel: TLabel;
MenuItem17: TMenuItem;
MenuItem18: TMenuItem;
miTools: TMenuItem;
TickTimer: TTimer;
MainToolBar: TToolBar;
panTransfer: TPanel;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
tbStopTorrent: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
txComment: TLabel;
txCommentLabel: TLabel;
txHash: TLabel;
txHashLabel: TLabel;
panGeneralInfo: TPanel;
lvFiles: TVarGrid;
lvPeers: TVarGrid;
MainMenu: TMainMenu;
MenuItem1: TMenuItem;
MenuItem10: TMenuItem;
MenuItem11: TMenuItem;
MenuItem12: TMenuItem;
MenuItem13: TMenuItem;
MenuItem14: TMenuItem;
MenuItem15: TMenuItem;
MenuItem16: TMenuItem;
MenuItem2: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
MenuItem5: TMenuItem;
MenuItem6: TMenuItem;
MenuItem7: TMenuItem;
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
miConnect: TMenuItem;
miExit: TMenuItem;
miTorrent: TMenuItem;
OpenTorrentDlg: TOpenDialog;
PageInfo: TPageControl;
pmTorrents: TPopupMenu;
pmFiles: TPopupMenu;
sbGenInfo: TScrollBox;
txPieces: TLabel;
txPiecesLabel: TLabel;
txTotalSize: TLabel;
txTotalSizeLabel: TLabel;
gTorrents: TVarGrid;
gStats: TVarGrid;
VSplitter: TSplitter;
StatusBar: TStatusBar;
tabPeers: TTabSheet;
tabGeneral: TTabSheet;
TorrentsListTimer: TTimer;
tabFiles: TTabSheet;
procedure acAddLinkExecute(Sender: TObject);
procedure acAddTorrentExecute(Sender: TObject);
procedure acAddTrackerExecute(Sender: TObject);
procedure acAdvEditTrackersExecute(Sender: TObject);
procedure acAltSpeedExecute(Sender: TObject);
procedure acBigToolbarExecute(Sender: TObject);
procedure acCheckNewVersionExecute(Sender: TObject);
procedure acConnectExecute(Sender: TObject);
procedure acConnOptionsExecute(Sender: TObject);
procedure acCopyPathExecute(Sender: TObject);
procedure acDelTrackerExecute(Sender: TObject);
procedure acEditTrackerExecute(Sender: TObject);
procedure acFilterPaneExecute(Sender: TObject);
procedure acFolderGroupingExecute(Sender: TObject);
procedure acForceStartTorrentExecute(Sender: TObject);
procedure acHideAppExecute(Sender: TObject);
procedure acInfoPaneExecute(Sender: TObject);
procedure acMenuShowExecute(Sender: TObject);
procedure acMoveTorrentExecute(Sender: TObject);
procedure acNewConnectionExecute(Sender: TObject);
procedure acOpenContainingFolderExecute(Sender: TObject);
procedure acOpenFileExecute(Sender: TObject);
procedure acOptionsExecute(Sender: TObject);
procedure acDisconnectExecute(Sender: TObject);
procedure acExportExecute(Sender: TObject);
procedure acImportExecute(Sender: TObject);
procedure acExitExecute(Sender: TObject);
procedure acDaemonOptionsExecute(Sender: TObject);
procedure acQMoveBottomExecute(Sender: TObject);
procedure acQMoveDownExecute(Sender: TObject);
procedure acQMoveTopExecute(Sender: TObject);
procedure acQMoveUpExecute(Sender: TObject);
procedure acReannounceTorrentExecute(Sender: TObject);
procedure acRemoveTorrentAndDataExecute(Sender: TObject);
procedure acRemoveTorrentExecute(Sender: TObject);
procedure acRenameExecute(Sender: TObject);
procedure acResolveCountryExecute(Sender: TObject);
procedure acResolveHostExecute(Sender: TObject);
procedure acSelectAllExecute(Sender: TObject);
procedure acSetHighPriorityExecute(Sender: TObject);
procedure acSetLowPriorityExecute(Sender: TObject);
procedure acSetNormalPriorityExecute(Sender: TObject);
procedure acSetNotDownloadExecute(Sender: TObject);
procedure acSetupColumnsExecute(Sender: TObject);
procedure acShowAppExecute(Sender: TObject);
procedure acShowCountryFlagExecute(Sender: TObject);
procedure acStartAllTorrentsExecute(Sender: TObject);
procedure acStartTorrentExecute(Sender: TObject);
procedure acStatusBarExecute(Sender: TObject);
procedure acStatusBarSizesExecute(Sender: TObject);
procedure acStopAllTorrentsExecute(Sender: TObject);
procedure acStopTorrentExecute(Sender: TObject);
procedure gTorrentsMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure gTorrentsMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure LocalWatchTimerTimer(Sender: TObject);
procedure lvFilesMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MenuShowExecute(Sender: TObject);
procedure acToolbarShowExecute(Sender: TObject);
procedure acTorrentPropsExecute(Sender: TObject);
procedure acTrackerGroupingExecute(Sender: TObject);
procedure acUpdateBlocklistExecute(Sender: TObject);
procedure acUpdateGeoIPExecute(Sender: TObject);
procedure acVerifyTorrentExecute(Sender: TObject);
procedure ApplicationPropertiesEndSession(Sender: TObject);
procedure ApplicationPropertiesException(Sender: TObject; E: Exception);
procedure ApplicationPropertiesIdle(Sender: TObject; var Done: Boolean);
procedure ApplicationPropertiesMinimize(Sender: TObject);
procedure ApplicationPropertiesRestore(Sender: TObject);
procedure edSearchChange(Sender: TObject);
procedure edSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState );
procedure FormActivate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormWindowStateChange(Sender: TObject);
procedure gTorrentsCellAttributes(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; var CellAttribs: TCellAttributes);
procedure gTorrentsClick(Sender: TObject);
procedure gTorrentsDblClick(Sender: TObject);
procedure gTorrentsDrawCell(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; const R: TRect; var ADefaultDrawing: boolean);
procedure gTorrentsEditorHide(Sender: TObject);
procedure gTorrentsEditorShow(Sender: TObject);
procedure gTorrentsQuickSearch(Sender: TVarGrid; var SearchText: string; var ARow: integer);
procedure gTorrentsResize(Sender: TObject);
procedure gTorrentsSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string);
procedure gTorrentsSortColumn(Sender: TVarGrid; var ASortCol: integer);
procedure HSplitterChangeBounds(Sender: TObject);
procedure lvFilesDblClick(Sender: TObject);
procedure lvFilesEditorHide(Sender: TObject);
procedure lvFilesEditorShow(Sender: TObject);
procedure lvFilesSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string);
procedure lvFilterCellAttributes(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; var CellAttribs: TCellAttributes);
procedure lvFilterClick(Sender: TObject);
procedure lvFilterDrawCell(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; const R: TRect; var ADefaultDrawing: boolean);
procedure lvPeersCellAttributes(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; var CellAttribs: TCellAttributes);
procedure lvTrackersCellAttributes(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; var CellAttribs: TCellAttributes);
procedure lvTrackersDblClick(Sender: TObject);
procedure lvTrackersKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure goDevelopmentSiteClick(Sender: TObject);
procedure MainToolBarContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
procedure MenuItem101Click(Sender: TObject);
procedure miHomePageClick(Sender: TObject);
procedure PageInfoResize(Sender: TObject);
procedure panReconnectResize(Sender: TObject);
procedure pbDownloadedPaint(Sender: TObject);
procedure StatusBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure TickTimerTimer(Sender: TObject);
procedure FilterTimerTimer(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure lvFilterResize(Sender: TObject);
procedure miAboutClick(Sender: TObject);
procedure miCopyLabelClick(Sender: TObject);
procedure PageInfoChange(Sender: TObject);
procedure tbSearchCancelClick(Sender: TObject);
procedure TorrentsListTimerTimer(Sender: TObject);
procedure pmFilesPopup(Sender: TObject);
procedure pmTorrentsPopup(Sender: TObject);
procedure TrayIconDblClick(Sender: TObject);
procedure VSplitterChangeBounds(Sender: TObject);
function CorrectPath (path: string): string; // PETROV
private
FStarted: boolean;
FTorrents: TVarList;
FFiles: TVarList;
FTrackers: TStringList;
FResolver: TIpResolver;
FUnZip: TUnZipper;
FReconnectWaitStart: TDateTime;
FReconnectTimeOut: integer;
FTorrentProgress: TBitmap;
FLastPieces: string;
FLastPieceCount: integer;
FLastDone: double;
FCurConn: string;
FPathMap: TStringList;
FLastFilerIndex: integer;
FFilterChanged: boolean;
FCurDownSpeedLimit: integer;
FCurUpSpeedLimit: integer;
FFlagsPath: string;
FAddingTorrent: integer;
FPendingTorrents: TStringList;
FLinksFromClipboard: boolean;
FLastClipboardLink: string;
FLinuxOpenDoc: integer;
FFromNow: boolean;
FWatchLocalFolder: string;
FWatchDestinationFolder: string;
FWatchDownloading: boolean;
FRow: integer;
FCol: integer;
{$ifdef windows}
FFileManagerDefault: string;
FFileManagerDefaultParam: string;
FGlobalHotkey: string;
fGlobalHotkeyMod: string;
FUserDefinedMenuEx: string;
FUserDefinedMenuParam: string;
{$endif windows}
{$ifdef LCLcarbon}
FFormActive: boolean;
{$endif LCLcarbon}
FSlowResponse: TProgressImage;
FDetailsWait: TProgressImage;
FDetailsWaitStart: TDateTime;
FMainFormShown: boolean;
FFilesTree: TFilesTree;
FFilesCapt: string;
FCalcAvg: boolean;
FPasswords: TStringList;
procedure UpdateUI;
procedure UpdateUIRpcVersion(RpcVersion: integer);
function DoConnect: boolean;
procedure DoCreateOutZipStream(Sender: TObject; var AStream: TStream; AItem: TFullZipFileEntry);
procedure DoDisconnect;
procedure DoOpenFlagsZip(Sender: TObject; var AStream: TStream);
procedure TorrentProps(PageNo: integer);
procedure ShowConnOptions(NewConnection: boolean);
procedure SaveColumns(LV: TVarGrid; const AName: string; FullInfo: boolean = True);
procedure LoadColumns(LV: TVarGrid; const AName: string; FullInfo: boolean = True);
function GetTorrentError(t: TJSONObject; Status: integer): string;
function SecondsToString(j: integer): string;
function DoAddTorrent(const FileName: Utf8String): boolean;
procedure UpdateTray;
procedure HideApp;
procedure ShowApp;
procedure DownloadFinished(const TorrentName: string);
function GetFlagImage(const CountryCode: string): integer;
procedure BeforeCloseApp;
function GetGeoIpDatabase: string;
function GetFlagsArchive: string;
function DownloadGeoIpDatabase(AUpdate: boolean): boolean;
procedure TorrentColumnsChanged;
function EtaToString(ETA: integer): string;
function GetTorrentStatus(TorrentIdx: integer): string;
function GetSeedsText(Seeds, SeedsTotal: integer): string;
function GetPeersText(Peers, PeersTotal, Leechers: integer): string;
function RatioToString(Ratio: double): string;
function TorrentDateTimeToString(d: Int64; FromNow:Boolean = false): string;
procedure DoRefresh(All: boolean = False);
function GetFilesCommonPath(files: TJSONArray): string;
procedure InternalRemoveTorrent(const Msg, MsgMulti: string; RemoveLocalData: boolean);
function IncludeProperTrailingPathDelimiter(const s: string): string;
procedure UrlLabelClick(Sender: TObject);
procedure CenterReconnectWindow;
procedure ProcessPieces(const Pieces: string; PieceCount: integer; const Done: double);
function ExecRemoteFile(const FileName: string; SelectFile: boolean; Userdef: boolean= false): boolean;
function GetSelectedTorrents: variant;
function GetDisplayedTorrents: variant;
procedure FillDownloadDirs(CB: TComboBox; const CurFolderParam: string);
procedure SaveDownloadDirs(CB: TComboBox; const CurFolderParam: string);
procedure DeleteDirs(CB: TComboBox; maxdel : Integer);
procedure SetRefreshInterval;
procedure AddTracker(EditMode: boolean);
procedure UpdateConnections;
procedure DoConnectToHost(Sender: TObject);
procedure FillSpeedsMenu;
procedure DoSetDownloadSpeed(Sender: TObject);
procedure DoSetUploadSpeed(Sender: TObject);
procedure SetSpeedLimit(const Dir: string; Speed: integer);
function FixSeparators(const p: string): string;
function MapRemoteToLocal(const RemotePath: string): string;
procedure CheckAddTorrents;
procedure CheckClipboardLink;
procedure CenterDetailsWait;
procedure ReadLocalFolderWatch;
function GetPageInfoType(pg: TTabSheet): TAdvInfoType;
procedure DetailsUpdated;
function RenameTorrent(TorrentId: integer; const OldPath, NewName: string): boolean;
procedure FilesTreeStateChanged(Sender: TObject);
function SelectTorrent(TorrentId, TimeOut: integer): integer;
procedure OpenCurrentTorrent(OpenFolderOnly: boolean; UserDef: boolean=false);
public
procedure FillTorrentsList(list: TJSONArray);
procedure FillPeersList(list: TJSONArray);
procedure FillFilesList(ATorrentId: integer; list, priorities, wanted: TJSONArray; const DownloadDir: WideString);
procedure FillGeneralInfo(t: TJSONObject);
procedure FillTrackersList(TrackersData: TJSONObject);
procedure FillSessionInfo(s: TJSONObject);
procedure FillStatistics(s: TJSONObject);
procedure CheckStatus(Fatal: boolean = True);
function TorrentAction(const TorrentIds: variant; const AAction: string; args: TJSONObject = nil): boolean;
function SetFilePriority(TorrentId: integer; const Files: array of integer; const APriority: string): boolean;
function SetCurrentFilePriority(const APriority: string): boolean;
procedure SetTorrentPriority(APriority: integer);
procedure ClearDetailsInfo(Skip: TAdvInfoType = aiNone);
function SelectRemoteFolder(const CurFolder, DialogTitle: string): string;
procedure ConnectionSettingsChanged(const ActiveConnection: string; ForceReconnect: boolean);
procedure StatusBarSizes;
end;
function ExcludeInvalidChar (path: string): string; // PETROV
function GetBiDi: TBiDiMode;
function CheckAppParams: boolean;
procedure LoadTranslation;
function GetHumanSize(sz: double; RoundTo: integer = 0; const EmptyStr: string = '-'): string;
function PriorityToStr(p: integer; var ImageIndex: integer): string;
procedure DrawProgressCell(Sender: TVarGrid; ACol, ARow, ADataCol: integer; AState: TGridDrawState; const ACellRect: TRect);
var
MainForm: TMainForm;
RpcObj: TRpc;
FTranslationFileName: string;
FTranslationLanguage: string;
FAlterColor: TColor;
IsUnity: boolean;
Ini: TIniFileUtf8;
FHomeDir: string;
{$ifdef windows}
PrevWndProc: windows.WNDPROC;
HotKeyID: Integer;
{$endif windows}
const
// Torrents list
idxName = 0;
idxSize = 1;
idxDone = 2;
idxStatus = 3;
idxSeeds = 4;
idxPeers = 5;
idxDownSpeed = 6;
idxUpSpeed = 7;
idxETA = 8;
idxRatio = 9;
idxDownloaded = 10;
idxUploaded = 11;
idxTracker = 12;
idxTrackerStatus = 13;
idxAddedOn = 14;
idxCompletedOn = 15;
idxLastActive = 16;
idxPath = 17;
idxPriority = 18;
idxSizeToDowload = 19;
idxTorrentId = 20;
idxQueuePos = 21;
idxSeedingTime = 22;
idxSizeLeft = 23;
idxTag = -1;
idxSeedsTotal = -2;
idxLeechersTotal = -3;
idxStateImg = -4;
idxDeleted = -5;
idxDownSpeedHistory = -6;
idxUpSpeedHistory = -7;
TorrentsExtraColumns = 7;
// Peers list
idxPeerHost = 0;
idxPeerPort = 1;
idxPeerCountry = 2;
idxPeerClient = 3;
idxPeerFlags = 4;
idxPeerDone = 5;
idxPeerUpSpeed = 6;
idxPeerDownSpeed = 7;
idxPeerTag = -1;
idxPeerIP = -2;
idxPeerCountryImage = -3;
PeersExtraColumns = 3;
// Trackers list
idxTrackersListName = 0;
idxTrackersListStatus = 1;
idxTrackersListUpdateIn = 2;
idxTrackersListSeeds = 3;
idxTrackerTag = -1;
idxTrackerID = -2;
TrackersExtraColumns = 2;
// Filter idices
fltAll = 0;
fltDown = 1;
fltDone = 2;
fltActive = 3;
fltInactive = 4;
fltStopped = 5;
fltError = 6;
fltWaiting = 7;
// Status images
imgDown = 9;
imgSeed = 10;
imgDownError = 11;
imgSeedError = 12;
imgError = 13;
imgDone = 14;
imgStopped = 29;
imgDownQueue = 16;
imgSeedQueue = 17;
imgAll = 19;
imgActive = 20;
imgInactive = 15;
imgWaiting = 42;
StatusFiltersCount = 8;
TorrentFieldsMap: array[idxName..idxSizeLeft] of string =
('', 'totalSize', '', 'status', 'peersSendingToUs,seeders',
'peersGettingFromUs,leechers', '', '', 'eta', 'uploadRatio',
'downloadedEver', 'uploadedEver', '', '', 'addedDate', 'doneDate', 'activityDate', '', 'bandwidthPriority',
'', '', 'queuePosition', 'secondsSeeding', 'leftUntilDone');
FinishedQueue = 1000000;
TR_PRI_SKIP = -1000; // psedudo priority
TR_PRI_LOW = -1;
TR_PRI_NORMAL = 0;
TR_PRI_HIGH = 1;
implementation
uses
{$ifdef linux}
process, dynlibs,
{$endif linux}
{$ifdef darwin}
urllistenerosx,
{$endif darwin}
synacode, ConnOptions, clipbrd, DateUtils, TorrProps, DaemonOptions, About,
ToolWin, download, ColSetup, AddLink, MoveTorrent, ssl_openssl_lib, AddTracker, lcltype,
Options, ButtonPanel, BEncode, synautil;
const
TR_STATUS_CHECK_WAIT_1 = ( 1 shl 0 ); // Waiting in queue to check files
TR_STATUS_CHECK_1 = ( 1 shl 1 ); // Checking files
TR_STATUS_DOWNLOAD_1 = ( 1 shl 2 ); // Downloading
TR_STATUS_SEED_1 = ( 1 shl 3 ); // Seeding
TR_STATUS_STOPPED_1 = ( 1 shl 4 ); // Torrent is stopped
TR_STATUS_STOPPED_2 = 0; // Torrent is stopped
TR_STATUS_CHECK_WAIT_2 = 1; // Queued to check files
TR_STATUS_CHECK_2 = 2; // Checking files
TR_STATUS_DOWNLOAD_WAIT_2 = 3; // Queued to download
TR_STATUS_DOWNLOAD_2 = 4; // Downloading
TR_STATUS_SEED_WAIT_2 = 5; // Queued to seed
TR_STATUS_SEED_2 = 6; // Seeding
TR_STATUS_FINISHED = $100; // Torrent is finished (pseudo status)
TR_SPEEDLIMIT_GLOBAL = 0; // only follow the overall speed limit
TR_SPEEDLIMIT_SINGLE = 1; // only follow the per-torrent limit
TR_SPEEDLIMIT_UNLIMITED = 2; // no limits at all
SpeedHistorySize = 20;
const
SizeNames: array[1..5] of string = (sByte, sKByte, sMByte, sGByte, sTByte);
var
TR_STATUS_STOPPED, TR_STATUS_CHECK_WAIT, TR_STATUS_CHECK, TR_STATUS_DOWNLOAD_WAIT, TR_STATUS_DOWNLOAD, TR_STATUS_SEED_WAIT, TR_STATUS_SEED: integer;
{$ifdef windows}
function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
begin
if (uMsg=WM_HOTKEY) and (WParam=HotKeyID) then
begin
if (MainForm.Visible = false) or (MainForm.WindowState = wsMinimized) then
MainForm.ShowApp
else
MainForm.HideApp;
end;
result:=CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam);
end;
{$endif windows}
function IsHash(Hash: String): boolean;
var i: integer;
begin
Result := false;
if Hash = '' then exit;
if Length(Hash) = 32 then // possible base32 encoded hash
try
Hash:=StrToHex(Base32Decode(UpperCase(Hash)));
except
exit;
end;
if Length(Hash) <> 40 then exit;
Result := true;
for i := 1 to 40 do if not (Hash[i] in ['a' .. 'f', 'A'..'F', '0'..'9']) then Result := false;
end;
procedure TMainForm.ReadLocalFolderWatch;
var
sr: TSearchRec;
begin
if FPendingTorrents.Count = 0 then
begin
if FindFirstUTF8(FWatchLocalFolder+'*.torrent',faAnyFile,sr)=0 then
repeat
FPendingTorrents.Add(FWatchLocalFolder+sr.Name);
until FindNextUTF8(sr)<>0;
FindCloseUTF8(sr);
end;
end;
function GetHumanSize(sz: double; RoundTo: integer; const EmptyStr: string): string;
var
i: integer;
begin
if sz < 0 then begin
Result:=EmptyStr;
exit;
end;
i:=Low(SizeNames);
if RoundTo > 0 then begin
Inc(i);
sz:=sz/1024;
end;
while i <= High(SizeNames) do begin
if sz < 1024 then
break;
sz:=sz/1024;
Inc(i);
end;
if (RoundTo = 0) and (i > 3) then
RoundTo:=i - 2;
Result:=Format('%.' + IntToStr(RoundTo) + 'f %s', [sz, SizeNames[i]]);
end;