Skip to content

Commit ff5c2e4

Browse files
feature: add extra tabpage for private torrent
This is for: Ignore /announce for private tracker [Issue GerryFerdinandus#31] Add private tracker source tag [Issue GerryFerdinandus#35] Todo: unit test
1 parent c7f97c8 commit ff5c2e4

File tree

9 files changed

+386
-73
lines changed

9 files changed

+386
-73
lines changed

source/code/controler_treeview_torrent_data.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ procedure Tcontroler_treeview_torrent_data.AddOneTorrentFileDecoded(
355355
begin
356356
FTreeViewFileContents.Items.AddChild(TreeNodeInfo, 'Private: no');
357357
end;
358+
// some private torrent have info:source
359+
if DecodeTorrent.InfoSource <> '' then
360+
begin
361+
FTreeViewFileContents.Items.AddChild(TreeNodeInfo, 'Source: ' +
362+
DecodeTorrent.InfoSource);
363+
end;
358364

359365
//All the files count inside the torrent must be added to FTotalFileInsideTorrent
360366
Inc(FTotalFileInsideTorrent, DecodeTorrent.InfoFilesCount);

source/code/controlergridtorrentdata.pas

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ TControlerGridTorrentData = class
5151
FCreatedBy, //4
5252
FComment, //5
5353
FPrivateTorrent, //6
54-
FPieceLength, //7
55-
FTotaSize, //8
56-
FIndexOrder //9
54+
FInfoSource, //7
55+
FPieceLength, //8
56+
FTotaSize, //9
57+
FIndexOrder //10
5758
: TGridColumn;
5859

5960
FRowIsMovedNeedUpdate: boolean;
@@ -71,9 +72,10 @@ TControlerGridTorrentData = class
7172
CreatedBy, //4
7273
Comment, //5
7374
PrivateTorrent, //6
74-
PieceLength, //7
75-
TotaSize, //8
76-
IndexOrder //9
75+
InfoSource, //7
76+
PieceLength, //8
77+
TotaSize, //9
78+
IndexOrder //10
7779
: UTF8String;
7880

7981
procedure ClearAllImageIndex;
@@ -88,7 +90,7 @@ implementation
8890

8991
{ TControlerGridTorrentData }
9092
const
91-
COLUMN_COUNT = 10;
93+
COLUMN_COUNT = 11;
9294

9395
procedure TControlerGridTorrentData.StringGridTorrentDataColRowMoved(Sender: TObject;
9496
IsColumn: boolean; sIndex, tIndex: integer);
@@ -156,6 +158,7 @@ procedure TControlerGridTorrentData.AppendRow;
156158
WriteCell(FCreatedBy, CreatedBy);
157159
WriteCell(FComment, Comment);
158160
WriteCell(FPrivateTorrent, PrivateTorrent);
161+
WriteCell(FInfoSource, InfoSource);
159162
WriteCell(FPieceLength, PieceLength);
160163
WriteCell(FTotaSize, TotaSize);
161164
WriteCell(FIndexOrder, IndexOrder);
@@ -203,9 +206,10 @@ constructor TControlerGridTorrentData.Create(StringGridTorrentData: TStringGrid)
203206
AddColumn(FCreatedBy, 4);
204207
AddColumn(FComment, 5);
205208
AddColumn(FPrivateTorrent, 6);
206-
AddColumn(FPieceLength, 7);
207-
AddColumn(FTotaSize, 8);
208-
AddColumn(FIndexOrder, 9);
209+
AddColumn(FInfoSource, 7);
210+
AddColumn(FPieceLength, 8);
211+
AddColumn(FTotaSize, 9);
212+
AddColumn(FIndexOrder, 10);
209213

210214
//Fillin the tag value
211215
UpdateColumnTag;

source/code/decodetorrent.pas

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ TDecodeTorrent = class
6868
FCreatedBy: utf8string;
6969
FCreatedDate: TDateTime;
7070
FComment: utf8string;
71+
FInfoSource: utf8string;
7172
FName: utf8string;
7273
FPieceLenght: int64;
7374
FPrivateTorrent: boolean;
@@ -83,6 +84,7 @@ TDecodeTorrent = class
8384
function GetName: utf8string;
8485
function GetPieceLenght: int64;
8586
function GetPrivateTorrent: boolean;
87+
function GetInfoSource: utf8string;
8688
procedure SetComment(const AValue: utf8string);
8789
public
8890
//All the trackers inside this torrent file
@@ -117,6 +119,11 @@ TDecodeTorrent = class
117119
procedure RemovePrivateTorrentFlag;
118120
procedure AddPrivateTorrentFlag;
119121

122+
//info.source
123+
property InfoSource: utf8string read FInfoSource;
124+
procedure InfoSourceRemove;
125+
procedure InfoSourceAdd(const Value: utf8string);
126+
120127
//info.files
121128
function InfoFilesCount: integer;
122129
function InfoFilesNameIndex(index: integer): utf8string;
@@ -405,7 +412,7 @@ function TDecodeTorrent.DecodeTorrent: boolean;
405412
FName := GetName;
406413
FPieceLenght := GetPieceLenght;
407414
FPrivateTorrent := GetPrivateTorrent;
408-
415+
FInfoSource := GetInfoSource;
409416
except
410417
end;
411418
end;
@@ -441,9 +448,22 @@ function TDecodeTorrent.GetPrivateTorrent: boolean;
441448
end;
442449
end;
443450

451+
function TDecodeTorrent.GetInfoSource: utf8string;
452+
var
453+
TempBEncoded: TBEncoded;
454+
begin
455+
Result := '';
456+
try
457+
{find 'source' }
458+
TempBEncoded := FBEncoded_Info.ListData.FindElement('source');
459+
if assigned(TempBEncoded) then
460+
Result := TempBEncoded.StringData;
461+
except
462+
end;
463+
end;
464+
444465
procedure TDecodeTorrent.SetComment(const AValue: utf8string);
445466
var
446-
// Encoded: TBEncoded;
447467
Data: TBEncodedData;
448468
begin
449469
if FComment = AValue then
@@ -477,7 +497,6 @@ procedure TDecodeTorrent.SetComment(const AValue: utf8string);
477497

478498
end;
479499

480-
481500
{
482501
try
483502
Encoded := TBEncoded.Create;
@@ -499,7 +518,7 @@ procedure TDecodeTorrent.RemovePrivateTorrentFlag;
499518
except
500519
end;
501520
//read databack again
502-
GetPrivateTorrent;
521+
FPrivateTorrent := GetPrivateTorrent;
503522
end;
504523

505524
procedure TDecodeTorrent.AddPrivateTorrentFlag;
@@ -519,7 +538,36 @@ procedure TDecodeTorrent.AddPrivateTorrentFlag;
519538
except
520539
end;
521540
//read databack again
522-
GetPrivateTorrent;
541+
FPrivateTorrent := GetPrivateTorrent;
542+
end;
543+
544+
procedure TDecodeTorrent.InfoSourceRemove;
545+
begin
546+
try
547+
FBEncoded_Info.ListData.RemoveElement('source');
548+
except
549+
end;
550+
//read databack again
551+
FInfoSource := GetInfoSource;
552+
end;
553+
554+
procedure TDecodeTorrent.InfoSourceAdd(const Value: utf8string);
555+
var
556+
Encoded: TBEncoded;
557+
Data: TBEncodedData;
558+
begin//remove the old one and create a new one
559+
InfoSourceRemove;
560+
try
561+
Encoded := TBEncoded.Create;
562+
Encoded.Format := befString;
563+
Encoded.StringData := Value;
564+
Data := TBEncodedData.Create(Encoded);
565+
Data.Header := 'source';
566+
FBEncoded_Info.ListData.Add(Data);
567+
FBEncoded_Info.ListData.Sort(@sort_);//text must be in alfabetical order.
568+
except
569+
end;
570+
FInfoSource := GetInfoSource;
523571
end;
524572

525573
procedure TDecodeTorrent.RemoveAnnounce;

source/code/main.lfm

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
object FormTrackerModify: TFormTrackerModify
2-
Left = 1398
2+
Left = 429
33
Height = 607
4-
Top = 448
4+
Top = 183
55
Width = 1179
66
AllowDropFiles = True
77
Caption = 'Bittorrent Tracker Editor'
@@ -144,7 +144,7 @@ object FormTrackerModify: TFormTrackerModify
144144
Top = 0
145145
Width = 1171
146146
Align = alClient
147-
ColCount = 10
147+
ColCount = 11
148148
ColumnClickSorts = True
149149
Columns = <
150150
item
@@ -182,6 +182,10 @@ object FormTrackerModify: TFormTrackerModify
182182
Title.Caption = 'Private'
183183
Width = 50
184184
end
185+
item
186+
Title.Caption = 'Source'
187+
Width = 64
188+
end
185189
item
186190
Alignment = taRightJustify
187191
ReadOnly = True
@@ -215,6 +219,7 @@ object FormTrackerModify: TFormTrackerModify
215219
145
216220
160
217221
50
222+
64
218223
100
219224
100
220225
0
@@ -224,6 +229,68 @@ object FormTrackerModify: TFormTrackerModify
224229
object TabSheetTorrentsContents: TTabSheet
225230
Caption = 'Files/Trackers/Info'
226231
end
232+
object TabSheetPrivateTrackers: TTabSheet
233+
Caption = 'Private Trackers'
234+
ClientHeight = 561
235+
ClientWidth = 1171
236+
object GroupBoxItemsForPrivateTrackers: TGroupBox
237+
Left = 0
238+
Height = 176
239+
Hint = 'Private trackers URL may not end with /announce'
240+
Top = 8
241+
Width = 288
242+
Caption = 'Items for private trackers'
243+
ClientHeight = 158
244+
ClientWidth = 284
245+
TabOrder = 0
246+
object CheckBoxSkipAnnounceCheck: TCheckBox
247+
Left = 16
248+
Height = 19
249+
Top = 0
250+
Width = 221
251+
Caption = 'Skip Announce Check in the URL (-SAC)'
252+
OnChange = CheckBoxSkipAnnounceCheckChange
253+
ParentShowHint = False
254+
ShowHint = True
255+
TabOrder = 0
256+
end
257+
object GroupBoxInfoSource: TGroupBox
258+
Left = 16
259+
Height = 120
260+
Top = 32
261+
Width = 264
262+
Caption = 'Warning: This will change the torrent info HASH'
263+
ClientHeight = 102
264+
ClientWidth = 260
265+
TabOrder = 1
266+
object CheckBoxRemoveAllSourceTag: TCheckBox
267+
Left = 8
268+
Height = 19
269+
Top = 8
270+
Width = 132
271+
Caption = 'Remove all source tag'
272+
OnChange = CheckBoxRemoveAllSourceTagChange
273+
TabOrder = 0
274+
end
275+
object LabeledEditInfoSource: TLabeledEdit
276+
Left = 8
277+
Height = 21
278+
Hint = 'Keep empty if you do not want to add or change anything.'
279+
Top = 56
280+
Width = 221
281+
EditLabel.Height = 13
282+
EditLabel.Width = 221
283+
EditLabel.Caption = 'Add/Change source tag value: (-SOURCE)'
284+
EditLabel.ParentColor = False
285+
ParentShowHint = False
286+
ShowHint = True
287+
TabOrder = 1
288+
TabStop = False
289+
OnEditingDone = LabeledEditInfoSourceEditingDone
290+
end
291+
end
292+
end
293+
end
227294
end
228295
object SelectDirectoryDialog1: TSelectDirectoryDialog
229296
Title = 'Select a directory with torrent files inside.'

0 commit comments

Comments
 (0)