@@ -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;
743764end ;
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+
746861procedure TFormTrackerModify.UpdateViewRemoveTracker ;
747862var
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
12371352procedure TFormTrackerModify.MenuUpdateTorrentAddBeforeRemoveNewClick (Sender: TObject);
12381353
1239-
12401354begin
12411355 // User have selected to add new tracker.
12421356 FTrackerListOrderForUpdatedTorrent := tloInsertNewBeforeAndKeepOriginalIntact;
0 commit comments