-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
6783 lines (6299 loc) · 200 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, Graphics, Dialogs, ComCtrls, Menus, ActnList,
httpsend, StdCtrls, fpjson, jsonparser, ExtCtrls, rpc, syncobjs, variants, varlist, IpResolver,
zipper, ResTranslator, VarGrid, StrUtils, LCLProc, Grids, BaseForm, utils, AddTorrent;
const
AppName = 'Transmission Remote GUI';
AppVersion = '5.0.1';
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...';
sSecs = '%ds';
sMins = '%dm';
sHours = '%dh';
sDays = '%dd';
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';
type
{ 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;
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;
acInfoPane: TAction;
acStatusBar: TAction;
acCopyPath: TAction;
acRename: TAction;
acTrackerGrouping: TAction;
acUpdateBlocklist: TAction;
acUpdateGeoIP: TAction;
acTorrentProps: TAction;
acVerifyTorrent: TAction;
ActionList: TActionList;
ApplicationProperties: TApplicationProperties;
edSearch: TEdit;
imgSearch: TImage;
imgFlags: TImageList;
ImageList16: TImageList;
FilterTimer: TTimer;
MenuItem100: TMenuItem;
MenuItem68: TMenuItem;
MenuItem93: TMenuItem;
MenuItem94: TMenuItem;
MenuItem95: TMenuItem;
MenuItem96: TMenuItem;
MenuItem97: TMenuItem;
MenuItem98: TMenuItem;
MenuItem99: TMenuItem;
panDetailsWait: TPanel;
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;
miDonate: 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 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 acMoveTorrentExecute(Sender: TObject);
procedure acNewConnectionExecute(Sender: TObject);
procedure acOpenContainingFolderExecute(Sender: TObject);
procedure acOpenFileExecute(Sender: TObject);
procedure acOptionsExecute(Sender: TObject);
procedure acDisconnectExecute(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 acStopAllTorrentsExecute(Sender: TObject);
procedure acStopTorrentExecute(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 FormActivate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
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 miDonateClick(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 TorrentsListTimerTimer(Sender: TObject);
procedure pmFilesPopup(Sender: TObject);
procedure pmTorrentsPopup(Sender: TObject);
procedure TrayIconDblClick(Sender: TObject);
procedure VSplitterChangeBounds(Sender: TObject);
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;
{$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): 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): boolean;
function GetSelectedTorrents: variant;
procedure FillDownloadDirs(CB: TComboBox; const CurFolderParam: string);
procedure SaveDownloadDirs(CB: TComboBox; const CurFolderParam: string);
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;
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);
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);
end;
function CheckAppParams: boolean;
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;
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;
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;
// Status images
imgDown = 9;
imgSeed = 10;
imgDownError = 11;
imgSeedError = 12;
imgError = 13;
imgDone = 14;
imgStopped = 29;
imgDownQueue = 16;
imgSeedQueue = 17;
imgAll = 19;
imgActive = 20;
StatusFiltersCount = 7;
TorrentFieldsMap: array[idxName..idxSeedingTime] of string =
('', 'totalSize', '', 'status', 'peersSendingToUs,seeders',
'peersGettingFromUs,leechers', '', '', 'eta', 'uploadRatio',
'downloadedEver', 'uploadedEver', '', '', 'addedDate', 'doneDate', 'activityDate', '', 'bandwidthPriority',
'', '', 'queuePosition', 'secondsSeeding');
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, types, 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;
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;
function AddToChannel(Clr: TColor; Value: integer; Position: byte): TColor;
var i: integer;
begin
i:=(Clr shr (Position*8)) and $FF;
i:=i + Value;
if i < 0 then i:=0;
if i > $FF then i:=$FF;
Result:=Clr and (not (Cardinal($FF) shl (Position*8))) or (Cardinal(i) shl (Position*8));
end;
function AddToColor(Color: TColor; R, G, B: integer): TColor;
begin
Result:=ColorToRGB(Color);
Result:=AddToChannel(Result, R, 0);
Result:=AddToChannel(Result, G, 1);
Result:=AddToChannel(Result, B, 2);
end;
function GetLikeColor(Color: TColor; Delta: integer): TColor;
var i, j: integer;
begin
Result:=ColorToRGB(Color);
j:=Result and $FF; //red
i:=(Result shr 8) and $FF; // green
if i > j then
j:=i;
i:=((Result shr 16) and $FF) shr 1; // blue
if i > j then
j:=i;
if j < $80 then
i:=(($80 - j) div $20 + 1)*Delta
else
i:=Delta;
if (i + j > 255) or (i + j < 0) then
i:=-Delta;
Result:=AddToColor(Result, i, i, i);
end;
function LocateFile(const FileName: string; const Paths: array of string): string;
var
i: integer;
begin
for i:=Low(Paths) to High(Paths) do begin
Result:=IncludeTrailingPathDelimiter(Paths[i]) + FileName;
if FileExistsUTF8(Result) then
exit;
end;
Result:='';
end;
procedure OnTranslate(Sender: TResTranslator; const ResourceName: AnsiString; var Accept: boolean);
const
IgnoreUnits: array[0..12] of string =
('fpjson','jsonparser','jsonscanner','lclstrconsts','math',
'rtlconsts','sysconst','variants','zbase','zipper','zstream',
'xmlcfg', 'registry');
IgnoreControls: array[0..3] of string =
('AboutForm.txAuthor', 'MainForm.miLn', 'ConnOptionsForm.cbUseSocks5', 'ConnOptionsForm.tabConnection');
var
i: integer;
begin
Accept := not AnsiMatchText(Copy2Symb(ResourceName, '.'), IgnoreUnits)
or AnsiStartsText('lclstrconsts.rsMb', ResourceName) //<-- dialog buttons
or AnsiStartsText('lclstrconsts.rsMt', ResourceName); //<-- dialog message
if Accept then
for i:=Low(IgnoreControls) to High(IgnoreControls) do
if AnsiStartsText(IgnoreControls[i], ResourceName) then begin
Accept:=False;
exit;
end;
if Accept and (Copy(ResourceName, Length(ResourceName) - 8, MaxInt) = '.Category') then
Accept:=False;
end;
var
FHomeDir: string;
FIPCFileName: string;
FRunFileName: string;
function IsProtocolSupported(const url: string): boolean;
const
Protocols: array [1..3] of string =
('http:', 'https:', 'magnet:');
var
i: integer;
s: string;
begin
s:=AnsiLowerCase(url);
for i:=Low(Protocols) to High(Protocols) do
if Copy(s, 1, Length(Protocols[i])) = Protocols[i] then begin
Result:=True;
exit;
end;
Result:=False;
end;
procedure AddTorrentFile(const FileName: string);
var
h: System.THandle;
t: TDateTime;
s: string;
begin
if not IsProtocolSupported(FileName) and not FileExistsUTF8(FileName) then
exit;
t:=Now;
repeat
if FileExistsUTF8(FIPCFileName) then
h:=FileOpenUTF8(FIPCFileName, fmOpenWrite or fmShareDenyRead or fmShareDenyWrite)
else
h:=FileCreateUTF8(FIPCFileName);
if h <> System.THandle(-1) then begin
s:=FileName + LineEnding;
FileSeek(h, 0, soFromEnd);
FileWrite(h, s[1], Length(s));
FileClose(h);
break;
end;
Sleep(20);
until Now - t >= 3/SecsPerDay;
end;
procedure LoadTranslation;
begin
FTranslationFileName := Ini.ReadString('Interface', 'TranslationFile', '');
if FTranslationFileName <> '-' then
if (FTranslationFileName = '') or not IsTranslationFileValid(DefaultLangDir + FTranslationFileName) then
FTranslationLanguage := LoadDefaultTranslationFile(@OnTranslate)
else
FTranslationLanguage := LoadTranslationFile(DefaultLangDir + FTranslationFileName, @OnTranslate);
if FTranslationLanguage = '' then
FTranslationLanguage := 'English'
end;
function CheckAppParams: boolean;
var
i: integer;
s: string;
h: System.THandle;
pid: SizeUInt;
{$ifdef linux}
proc: TProcess;
sr: TSearchRec;
hLib: TLibHandle;
{$endif linux}
begin
Application.Title:=AppName;
{$ifdef linux}
IsUnity:=CompareText(GetEnvironmentVariable('XDG_CURRENT_DESKTOP'), 'unity') = 0;
if GetEnvironmentVariable('LIBOVERLAY_SCROLLBAR') <> '0' then begin
i:=FindFirstUTF8('/usr/lib/liboverlay-scrollbar*', faAnyFile, sr);
FindClose(sr);
hLib:=LoadLibrary('liboverlay-scrollbar.so');