Skip to content

Commit 1715174

Browse files
create function CheckForAnnounce()
The check was done in two places. Now it is move to one function. Also clean up some code.
1 parent 35da8b0 commit 1715174

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

source/code/main.pas

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ TFormTrackerModify = class(TForm)
157157
// is the present torrent file being process
158158
FDecodePresentTorrent: TDecodeTorrent;
159159

160+
FDragAndDropStartUp, // user have start the program via Drag And Drop
160161
FConsoleMode, //user have start the program in console mode
161162
FFilePresentBanByUserList//There is a file 'remove_trackers.txt' detected
162163
: boolean;
@@ -165,7 +166,7 @@ TFormTrackerModify = class(TForm)
165166
FLogFile, FTrackerFile: TextFile;
166167
FProcessTimeStart, FProcessTimeTotal: TDateTime;
167168
FControlerGridTorrentData: TControlerGridTorrentData;
168-
169+
function CheckForAnnounce(const TrackerURL: UTF8String): boolean;
169170
procedure AppendTrackersToMemoNewTrackers(TrackerList: TStringList);
170171
procedure ShowUserErrorMessage(const ErrorText: string; const FormText: string = '');
171172
function TrackerWithURLAndAnnounce(const TrackerURL: UTF8String): boolean;
@@ -177,7 +178,7 @@ TFormTrackerModify = class(TForm)
177178
procedure ViewUpdateFormCaption;
178179
procedure ClearAllTorrentFilesNameAndTrackerInside;
179180
procedure SaveTrackerFinalListToFile;
180-
procedure ConsoleMode;
181+
procedure ConsoleModeOrDragAndDropStartupMode;
181182
procedure UpdateViewRemoveTracker;
182183
function ReloadAllTorrentAndRefreshView: boolean;
183184
function AddTorrentFileList(TorrentFileNameStringList: TStringList): boolean;
@@ -189,8 +190,9 @@ TFormTrackerModify = class(TForm)
189190
procedure ShowTrackerInsideFileList;
190191

191192
procedure CheckedOnOffAllTrackers(Value: boolean);
192-
function CopyUserInputNewTrackersToList: boolean;
193-
procedure LoadTrackersTextFileAddTrackers;
193+
function CopyUserInputNewTrackersToList(Temporary_SkipAnnounceCheck: boolean =
194+
False): boolean;
195+
procedure LoadTrackersTextFileAddTrackers(Temporary_SkipAnnounceCheck: boolean);
194196
procedure LoadTrackersTextFileRemoveTrackers;
195197
public
196198
{ public declarations }
@@ -223,11 +225,6 @@ implementation
223225

224226
procedure TFormTrackerModify.FormCreate(Sender: TObject);
225227
begin
226-
227-
//Update some captions
228-
Caption := FORM_CAPTION;
229-
GroupBoxPresentTracker.Caption := GROUPBOX_PRESENT_TRACKERS_CAPTION;
230-
231228
//Create controler for StringGridTorrentData
232229
FControlerGridTorrentData := TControlerGridTorrentData.Create(StringGridTorrentData);
233230

@@ -295,9 +292,10 @@ procedure TFormTrackerModify.FormCreate(Sender: TObject);
295292
//there must be two command line or more for a console mode.
296293
//one is for drag and drop via shortcut in windows mode.
297294
FConsoleMode := ParamCount >= 2;
295+
FDragAndDropStartUp := ParamCount = 1;
298296

299297
//Show the default trackers
300-
LoadTrackersTextFileAddTrackers;
298+
LoadTrackersTextFileAddTrackers(True);
301299

302300
//Load the unwanted trackers list.
303301
LoadTrackersTextFileRemoveTrackers;
@@ -309,9 +307,15 @@ procedure TFormTrackerModify.FormCreate(Sender: TObject);
309307
//or in windows mode via shortcut with drag/drop ( = 1)
310308
if ParamCount > 0 then
311309
begin
312-
ConsoleMode;
310+
ConsoleModeOrDragAndDropStartupMode;
313311
end;
314312

313+
//There should be no more exception made for the drag and drop
314+
FDragAndDropStartUp := False;
315+
316+
//Update some captions
317+
ViewUpdateFormCaption;
318+
GroupBoxPresentTracker.Caption := GROUPBOX_PRESENT_TRACKERS_CAPTION;
315319
end;
316320

317321
procedure TFormTrackerModify.CheckBoxSkipAnnounceCheckChange(Sender: TObject);
@@ -490,6 +494,12 @@ procedure TFormTrackerModify.MenuItemOnlineCheckDownloadNewTrackonClick(
490494
end;
491495
end;
492496

497+
function TFormTrackerModify.CheckForAnnounce(const TrackerURL: UTF8String): boolean;
498+
begin
499+
Result := (not FTrackerList.SkipAnnounceCheck) and
500+
(not WebTorrentTrackerURL(TrackerURL)) and (not FDragAndDropStartUp);
501+
end;
502+
493503
procedure TFormTrackerModify.ShowUserErrorMessage(const ErrorText: string;
494504
const FormText: string);
495505
begin
@@ -511,19 +521,12 @@ procedure TFormTrackerModify.ShowUserErrorMessage(const ErrorText: string;
511521

512522
function TFormTrackerModify.TrackerWithURLAndAnnounce(
513523
const TrackerURL: UTF8String): boolean;
514-
var
515-
CheckForAnnounce: boolean;
516524
begin
517525
//Validate the begin of the URL
518526
Result := ValidTrackerURL(TrackerURL);
519527
if Result then
520528
begin
521-
// Normaly there is an announce present in the URL
522-
// But not for WebTorrent and Private trackers
523-
CheckForAnnounce := (not FTrackerList.SkipAnnounceCheck) and
524-
(not WebTorrentTrackerURL(TrackerURL));
525-
526-
if CheckForAnnounce then
529+
if CheckForAnnounce(TrackerURL) then
527530
begin
528531
Result := TrackerURLWithAnnounce(TrackerURL);
529532
end;
@@ -860,19 +863,19 @@ procedure TFormTrackerModify.SaveTrackerFinalListToFile;
860863
CloseFile(FTrackerFile);
861864
end;
862865

863-
procedure TFormTrackerModify.ConsoleMode;
866+
procedure TFormTrackerModify.ConsoleModeOrDragAndDropStartupMode;
864867
var
865868
FileNameOrDirStr: UTF8String;
866869
StringList: TStringList;
867870
MustExitWithErrorCode: boolean;
868871
begin
869872
// There are two options
870873
//-
871-
// One parameter only
872-
// This is the first tracker-editor version with only 'sort' trackers list.
874+
// One parameter only. Program startup via DragAndDrop
873875
// The first parameter[1] is path to file or dir.
876+
874877
//-
875-
// Two parameter version
878+
// Two parameter version. Always console mode.
876879
// This is later version where there is more selection about the tracker list.
877880

878881
//Will be set to True when error occure.
@@ -1096,10 +1099,10 @@ procedure TFormTrackerModify.CheckedOnOffAllTrackers(Value: boolean);
10961099
end;
10971100

10981101

1099-
function TFormTrackerModify.CopyUserInputNewTrackersToList: boolean;
1102+
function TFormTrackerModify.CopyUserInputNewTrackersToList(
1103+
Temporary_SkipAnnounceCheck: boolean): boolean;
11001104
var
11011105
TrackerStrLoop, TrackerStr, ErrorStr: UTF8String;
1102-
CheckForAnnounce: boolean;
11031106
begin
11041107
{
11051108
Called after 'update torrent' is selected.
@@ -1121,9 +1124,7 @@ function TFormTrackerModify.CopyUserInputNewTrackersToList: boolean;
11211124
Result := ValidTrackerURL(TrackerStr);
11221125
if Result then
11231126
begin
1124-
CheckForAnnounce := (not FTrackerList.SkipAnnounceCheck) and
1125-
(not WebTorrentTrackerURL(TrackerStr));
1126-
if CheckForAnnounce then
1127+
if CheckForAnnounce(TrackerStr) and (not Temporary_SkipAnnounceCheck) then
11271128
begin
11281129
Result := TrackerURLWithAnnounce(TrackerStr);
11291130
if not Result then
@@ -1198,7 +1199,8 @@ procedure TFormTrackerModify.UpdateTrackerInsideFileList;
11981199

11991200
end;
12001201

1201-
procedure TFormTrackerModify.LoadTrackersTextFileAddTrackers;
1202+
procedure TFormTrackerModify.LoadTrackersTextFileAddTrackers(
1203+
Temporary_SkipAnnounceCheck: boolean);
12021204
var
12031205
i: integer;
12041206
begin
@@ -1217,7 +1219,7 @@ procedure TFormTrackerModify.LoadTrackersTextFileAddTrackers;
12171219
end;
12181220

12191221
//Check for error in tracker list
1220-
if not CopyUserInputNewTrackersToList then
1222+
if not CopyUserInputNewTrackersToList(Temporary_SkipAnnounceCheck) then
12211223
begin
12221224
MemoNewTrackers.Lines.Clear;
12231225
end;

0 commit comments

Comments
 (0)