Skip to content

Commit 280ed4d

Browse files
Add command line parameter: -Ux
Via command line parameter -Ux 5 diferent trackers list order can be selected. See enduser/readme.txt file for more info.
1 parent 0ad280f commit 280ed4d

File tree

2 files changed

+153
-15
lines changed

2 files changed

+153
-15
lines changed

enduser/readme.txt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ If you do not want to use it this way, then just remove both the files 'add_trac
33

44
These '.txt' files must be place in the same directory as the program.
55

6+
--------------------
67

78
Console mode:
89
Start program with a parameter to torrent file or dir
@@ -11,8 +12,9 @@ trackereditor.exe "C:\dir\torrent"
1112
What tracker will be added/removed depend the content of the add_trackers.txt and remove_trackers.txt files.
1213

1314
--------------------
15+
1416
Additional Files: Trackers file and log file
15-
These 3 files can be optionaly present in the same dir as the trackereditor excutable file.
17+
These 3 files can be optionally present in the same dir as the trackereditor executable file.
1618
'add_trackers.txt' and 'remove_trackers.txt' are used in 'hidden console' mode and normal 'windows mode'
1719

1820

@@ -23,21 +25,19 @@ List of all the trackers that must added.
2325
remove_trackers.txt
2426
List of all the trackers that must removed
2527
note: if the file is empty then all trackers from the present torrent will be REMOVED.
26-
note: if the file is not present then no trackers will be automatickly removed.
27-
28+
note: if the file is not present then no trackers will be automatic removed.
2829

2930

3031
log.txt is only created in console mode.
31-
Show the in console mode the succes/failure of the torrent update.
32+
Show the in console mode the success/failure of the torrent update.
3233
First line status: 'OK' or 'ERROR: xxxxxxx' xxxxxxx = error description
3334
Second line files count: '1'
3435
Third line tracker count: 23
3536
Second and third line info are only valid if the first line is 'OK'
3637

3738
--------------------
3839

39-
40-
3 posible use case scenario in updating torrent file.
40+
3 possible use case scenario in updating torrent file.
4141
Add tracker and/or remove tracker
4242

4343
Add new tracker + keep tracker inside torrent
@@ -61,6 +61,30 @@ no new tracker + remove some or all tracker inside torrent.
6161
Empty remove_trackers.txt file to remove all trackers from the present torrent.
6262
This will create torrent files with out any tracker. (DHT torrent)
6363

64+
--------------------
65+
66+
Updated torrent file trackers list order with '-Ux' parameter.
67+
This is optional parameter. The default setting is -U4. The same as previous software version.
68+
69+
trackereditor.exe "C:\dir\torrent" -U0
70+
71+
Console parameter: -U0
72+
Insert new trackers list BEFORE, the original trackers list inside the torrent file.
73+
And remove possible duplicated trackers from the ORIGINAL trackers list.
74+
75+
Console parameter: -U1
76+
Insert new trackers list BEFORE, the original trackers list inside the torrent file.
77+
And remove possible duplicated trackers from the NEW trackers list.
78+
79+
Console parameter: -U2
80+
Append new trackers list AFTER, the original trackers list inside the torrent file.
81+
And remove possible duplicated trackers from the ORIGINAL trackers list.
82+
83+
Console parameter: -U3
84+
Append new trackers list AFTER, the original trackers list inside the torrent file.
85+
And remove possible duplicated trackers from the NEW trackers list.
6486

87+
Console parameter: -U4
88+
Sort the trackers list by name.
6589

6690

source/main.pas

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,32 @@ interface
4343

4444
//Updated torrent file trackers list order.
4545
TTrackerListOrder = (
46-
tloInsertNewBeforeAndKeepOriginalIntact,
46+
47+
// Console parameter: -U0
48+
// Insert new trackers list BEFORE, the original trackers list inside the torrent file.
49+
// And remove possible duplicated trackers from the ORIGINAL trackers list.
4750
tloInsertNewBeforeAndKeepNewIntact,
48-
tloAppendNewAfterAndKeepOriginalIntact,
51+
52+
// Console parameter: -U1
53+
// Insert new trackers list BEFORE, the original trackers list inside the torrent file.
54+
// And remove possible duplicated trackers from the NEW trackers list.
55+
tloInsertNewBeforeAndKeepOriginalIntact,
56+
57+
// Console parameter: -U2
58+
// Append new trackers list AFTER, the original trackers list inside the torrent file.
59+
// And remove possible duplicated trackers from the ORIGINAL trackers list.
4960
tloAppendNewAfterAndKeepNewIntact,
50-
tloSort);
61+
62+
// Console parameter: -U3
63+
// Append new trackers list AFTER, the original trackers list inside the torrent file.
64+
// And remove possible duplicated trackers from the NEW trackers list.
65+
tloAppendNewAfterAndKeepOriginalIntact,
66+
67+
// Console parameter: -U4
68+
// Sort the trackers list by name.
69+
tloSort
70+
);
71+
5172

5273

5374
{ TFormTrackerModify }
@@ -179,6 +200,8 @@ TFormTrackerModify = class(TForm)
179200
procedure MenuItemTorrentFilesTreeSyncWithPopupMenu;
180201
procedure SaveTrackerFinalListToFile;
181202
procedure ConsoleMode;
203+
function ConsoleModeDecodeParameter(out FileNameOrDirStr: UTF8String): boolean;
204+
function DecodeConsoleUpdateParameter(ConsoleUpdateParameter: UTF8String): boolean;
182205
procedure UpdateViewRemoveTracker;
183206

184207

@@ -675,8 +698,8 @@ procedure TFormTrackerModify.ConsoleMode;
675698
AssignFile(FLogFile, ExtractFilePath(Application.ExeName) + LOG_FILE_NAME);
676699
ReWrite(FLogFile);
677700

678-
//Get the first parameter.
679-
FileNameOrDirStr := UTF8Trim(ParamStr(1));
701+
//Get the console parameters.
702+
ConsoleModeDecodeParameter(FileNameOrDirStr);
680703

681704
//If FLogStringList empty then there is no error.
682705
if FLogStringList.Text = '' then
@@ -694,7 +717,6 @@ procedure TFormTrackerModify.ConsoleMode;
694717
//Some tracker must be removed. Console and windows mode.
695718
UpdateViewRemoveTracker;
696719
//update torrent
697-
FTrackerListOrderForUpdatedTorrent := tloSort;
698720
UpdateTorrent;
699721
end;
700722
end
@@ -715,7 +737,6 @@ procedure TFormTrackerModify.ConsoleMode;
715737
//Some tracker must be removed. Console and windows mode.
716738
UpdateViewRemoveTracker;
717739
//update torrent
718-
FTrackerListOrderForUpdatedTorrent := tloSort;
719740
UpdateTorrent;
720741
finally
721742
StringList.Free;
@@ -743,6 +764,100 @@ procedure TFormTrackerModify.ConsoleMode;
743764
end;
744765

745766

767+
function TFormTrackerModify.ConsoleModeDecodeParameter(
768+
out FileNameOrDirStr: UTF8String): boolean;
769+
begin
770+
{
771+
Console mode can be started with 2 parameter
772+
Update methode: -U0 , -U1, -U2, -U3, -U4
773+
String with a link to folder or to torrent file. 'C:\dir'
774+
775+
}
776+
777+
case Paramcount of
778+
0:
779+
begin
780+
FLogStringList.Add('ERROR: There are no parameter detected.');
781+
Result := False;
782+
exit;
783+
end;
784+
1:
785+
begin
786+
//one parameter. Must be a link.
787+
FileNameOrDirStr := UTF8Trim(ParamStr(1));
788+
//Keep the same behaviour as the previeus software version.
789+
FTrackerListOrderForUpdatedTorrent := tloSort;
790+
Result := True;
791+
end;
792+
2:
793+
begin
794+
//Two parameters. The user can select the update methode.
795+
//Check for '-U' contruction as first parameter
796+
if (Pos('-U', ParamStr(1)) = 1) then
797+
begin
798+
//Update parameter is the first parameter
799+
Result := DecodeConsoleUpdateParameter(ParamStr(1));
800+
FileNameOrDirStr := UTF8Trim(ParamStr(2));
801+
end
802+
else
803+
begin
804+
//Update parameter is the second parameter
805+
Result := DecodeConsoleUpdateParameter(ParamStr(2));
806+
FileNameOrDirStr := UTF8Trim(ParamStr(1));
807+
end;
808+
809+
end;
810+
else
811+
begin
812+
FLogStringList.Add('ERROR: There can only be maximum of 2 parameter. Not: ' +
813+
IntToStr(ParamCount));
814+
Result := False;
815+
exit;
816+
end;
817+
818+
end;
819+
end;
820+
821+
function TFormTrackerModify.DecodeConsoleUpdateParameter(
822+
ConsoleUpdateParameter: UTF8String): boolean;
823+
var
824+
i: integer;
825+
begin
826+
//Decode the '-Ux' x is number [0..4]
827+
828+
//verify string content.
829+
Result := (Pos('-U', ConsoleUpdateParameter) = 1) and
830+
(length(ConsoleUpdateParameter) = 3);
831+
832+
if Result then
833+
begin
834+
//get the number
835+
Result := TryStrToInt(ConsoleUpdateParameter[3], i);
836+
if Result then
837+
begin
838+
//decode number [0..4]
839+
case i of
840+
0: FTrackerListOrderForUpdatedTorrent := tloInsertNewBeforeAndKeepNewIntact;
841+
1: FTrackerListOrderForUpdatedTorrent := tloInsertNewBeforeAndKeepOriginalIntact;
842+
2: FTrackerListOrderForUpdatedTorrent := tloAppendNewAfterAndKeepNewIntact;
843+
3: FTrackerListOrderForUpdatedTorrent := tloAppendNewAfterAndKeepOriginalIntact;
844+
4: FTrackerListOrderForUpdatedTorrent := tloSort;
845+
else
846+
begin
847+
//the number is out of range.
848+
Result := False;
849+
end;
850+
end;
851+
end;
852+
end;
853+
854+
if not Result then
855+
begin
856+
FLogStringList.Add('ERROR: can not decode update parameter -U : ' +
857+
ConsoleUpdateParameter);
858+
end;
859+
end;
860+
746861
procedure TFormTrackerModify.UpdateViewRemoveTracker;
747862
var
748863
TrackerStr: UTF8String;
@@ -923,7 +1038,7 @@ procedure TFormTrackerModify.CombineFiveTrackerListToOne(
9231038
//Begin with an empty list
9241039
FTrackerFinalList.Clear;
9251040

926-
if FTrackerListOrderForUpdatedTorrent <> tloSort then
1041+
if TrackerListOrder <> tloSort then
9271042
begin
9281043

9291044
//Read the trackers inside the torrent file
@@ -1236,7 +1351,6 @@ procedure TFormTrackerModify.MenuUpdateTorrentAddAfterRemoveOriginalClick(
12361351

12371352
procedure TFormTrackerModify.MenuUpdateTorrentAddBeforeRemoveNewClick(Sender: TObject);
12381353

1239-
12401354
begin
12411355
//User have selected to add new tracker.
12421356
FTrackerListOrderForUpdatedTorrent := tloInsertNewBeforeAndKeepOriginalIntact;

0 commit comments

Comments
 (0)