Skip to content

Commit a2e51de

Browse files
fix: broken drag/drop to desktop link
This is a regression in 1.33.beta serie cc16aed
1 parent 22959a3 commit a2e51de

File tree

1 file changed

+82
-36
lines changed

1 file changed

+82
-36
lines changed

source/code/main.pas

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ TFormTrackerModify = class(TForm)
140140
// is the present torrent file being process
141141
FDecodePresentTorrent: TDecodeTorrent;
142142

143-
FConcoleMode, //user have start the program in console mode
143+
FConsoleMode, //user have start the program in console mode
144144
FFilePresentBanByUserList//There is a file 'remove_trackers.txt' detected
145145
: boolean;
146146

@@ -218,6 +218,11 @@ implementation
218218
procedure TFormTrackerModify.FormCreate(Sender: TObject);
219219
begin
220220

221+
//Update some captions
222+
Caption := FORM_CAPTION;
223+
GroupBoxTorrentContents.Caption := TORRENT_FILES_CONTENTS_FORM_CAPTION;
224+
GroupBoxPresentTracker.Caption := GROUPBOX_PRESENT_TRACKERS_CAPTION;
225+
221226
//Create controler for StringGridTorrentData
222227
FControlerGridTorrentData := TControlerGridTorrentData.Create(StringGridTorrentData);
223228

@@ -260,7 +265,6 @@ procedure TFormTrackerModify.FormCreate(Sender: TObject);
260265
//must NOT be sorted. Must keep the original order intact.
261266
FTrackerList.TrackerFinalList.Sorted := False;
262267

263-
264268
//Decoding class for torrent.
265269
FDecodePresentTorrent := TDecodeTorrent.Create;
266270

@@ -273,25 +277,24 @@ procedure TFormTrackerModify.FormCreate(Sender: TObject);
273277
Width := Constraints.MinWidth;
274278
Height := Constraints.MinHeight;
275279

276-
//there must be one command line or more for a console mode.
277-
FConcoleMode := ParamCount > 0;
280+
//there must be two command line or more for a console mode.
281+
//one is for drag and drop via shortcut in windows mode.
282+
FConsoleMode := ParamCount >= 2;
278283

279284
//Show the default trackers
280285
LoadTrackersTextFileAddTrackers;
281286

282287
//Load the unwanted trackers list.
283288
LoadTrackersTextFileRemoveTrackers;
284289

285-
//Start program in console mode
286-
if FConcoleMode then
290+
//Start program in console mode ( >= 2)
291+
//or in windows mode via shortcut with drag/drom ( = 1)
292+
if ParamCount > 0 then
287293
begin
288294
ConsoleMode;
289295
end;
290296

291-
//Update some captions
292-
Caption := FORM_CAPTION;
293-
GroupBoxTorrentContents.Caption := TORRENT_FILES_CONTENTS_FORM_CAPTION;
294-
GroupBoxPresentTracker.Caption := GROUPBOX_PRESENT_TRACKERS_CAPTION;
297+
295298

296299
end;
297300

@@ -567,7 +570,7 @@ procedure TFormTrackerModify.UpdateTorrent;
567570

568571
try
569572

570-
if not FConcoleMode then
573+
if not FConsoleMode then
571574
begin
572575
//Warn user before updating the torrent
573576
BoxStyle := MB_ICONWARNING + MB_OKCANCEL;
@@ -584,7 +587,7 @@ procedure TFormTrackerModify.UpdateTorrent;
584587
//Must have some torrent selected
585588
if (FTrackerList.TorrentFileNameList.Count = 0) then
586589
begin
587-
if FConcoleMode then
590+
if FConsoleMode then
588591
begin
589592
FTrackerList.LogStringList.Add('ERROR: No torrent file selected');
590593
end
@@ -616,7 +619,7 @@ procedure TFormTrackerModify.UpdateTorrent;
616619
CountTrackers := FTrackerList.TrackerFinalList.Count;
617620

618621
//In console mode we can ignore this warning
619-
if not FConcoleMode and (CountTrackers = 0) then
622+
if not FConsoleMode and (CountTrackers = 0) then
620623
begin //Torrent without a tracker is posible. But is this what the user realy want? a DHT torrent.
621624
BoxStyle := MB_ICONWARNING + MB_OKCANCEL;
622625
Reply := Application.MessageBox(
@@ -727,7 +730,7 @@ procedure TFormTrackerModify.UpdateTorrent;
727730
end;
728731

729732

730-
if FConcoleMode then
733+
if FConsoleMode then
731734
begin
732735
//When succesfull the log file shows, 3 lines,
733736
// OK + Count torrent files + Count Trackers
@@ -849,11 +852,15 @@ procedure TFormTrackerModify.ConsoleMode;
849852

850853
//Will be set to True when error occure.
851854
MustExitWithErrorCode := False;
855+
ViewUpdateBegin;
852856

853857
try
854-
//Create the log file. The old one will be overwritten
855-
AssignFile(FLogFile, ExtractFilePath(Application.ExeName) + FILE_NAME_CONSOLE_LOG);
856-
ReWrite(FLogFile);
858+
if FConsoleMode then
859+
begin
860+
//Create the log file. The old one will be overwritten
861+
AssignFile(FLogFile, ExtractFilePath(Application.ExeName) + FILE_NAME_CONSOLE_LOG);
862+
ReWrite(FLogFile);
863+
end;
857864

858865
//Get the startup command lime parameters.
859866
if ConsoleModeDecodeParameter(FileNameOrDirStr, FTrackerList) then
@@ -868,9 +875,19 @@ procedure TFormTrackerModify.ConsoleMode;
868875
ShowTrackerInsideFileList;
869876
//Some tracker must be removed. Console and windows mode.
870877
UpdateViewRemoveTracker;
871-
//update torrent
872-
UpdateTorrent;
878+
879+
if FConsoleMode then
880+
begin
881+
//update torrent
882+
UpdateTorrent;
883+
end;
884+
885+
end
886+
else
887+
begin
888+
//failed to load the torrent via folders
873889
end;
890+
874891
end
875892
else //a single torrent file is selected?
876893
begin
@@ -888,48 +905,77 @@ procedure TFormTrackerModify.ConsoleMode;
888905
ShowTrackerInsideFileList;
889906
//Some tracker must be removed. Console and windows mode.
890907
UpdateViewRemoveTracker;
891-
//update torrent
892-
UpdateTorrent;
908+
909+
if FConsoleMode then
910+
begin
911+
//update torrent
912+
UpdateTorrent;
913+
end;
914+
915+
end
916+
else
917+
begin
918+
//failed to load one torrent
893919
end;
894920

921+
895922
finally
896923
StringList.Free;
897924
end;
898925
end
899926
else
900927
begin //Error. this is not a torrent file
901-
FTrackerList.LogStringList.Add('ERROR: No torrent file selected.');
928+
929+
if FConsoleMode then
930+
begin
931+
FTrackerList.LogStringList.Add('ERROR: No torrent file selected.');
932+
end
933+
else
934+
begin
935+
936+
end;
937+
938+
902939
end;
903940
end;
904941
end;
905942

906-
//Write to log file. And close the file.
907-
WriteLn(FLogFile, FTrackerList.LogStringList.Text);
908-
CloseFile(FLogFile);
909-
910-
//check if log data is success full
911-
//if (no data) or (not CONSOLE_SUCCESS_STATUS) then error
912-
MustExitWithErrorCode := FTrackerList.LogStringList.Count = 0;
913-
if not MustExitWithErrorCode then
943+
if FConsoleMode then
914944
begin
915-
MustExitWithErrorCode := FTrackerList.LogStringList[0] <> CONSOLE_SUCCESS_STATUS;
945+
//Write to log file. And close the file.
946+
WriteLn(FLogFile, FTrackerList.LogStringList.Text);
947+
CloseFile(FLogFile);
948+
949+
//check if log data is success full
950+
//if (no data) or (not CONSOLE_SUCCESS_STATUS) then error
951+
MustExitWithErrorCode := FTrackerList.LogStringList.Count = 0;
952+
if not MustExitWithErrorCode then
953+
begin
954+
MustExitWithErrorCode := FTrackerList.LogStringList[0] <> CONSOLE_SUCCESS_STATUS;
955+
end;
916956
end;
917957

958+
918959
except
919960
//Shutdown the console program.
920961
//This is needed or else the program will keep running forever.
921962
//exit with error code
922963
MustExitWithErrorCode := True;
923964
end;
924965

966+
ViewUpdateEnd;
967+
925968
if MustExitWithErrorCode then
926969
begin
927970
//exit with error code
928971
System.ExitCode := 1;
929972
end;
930973

931-
//Always shutdown the program when in console mode.
932-
Application.terminate;
974+
if FConsoleMode then
975+
begin
976+
//Always shutdown the program when in console mode.
977+
Application.terminate;
978+
end;
933979
end;
934980

935981

@@ -1093,7 +1139,7 @@ function TFormTrackerModify.CopyUserInputNewTrackersToList: boolean;
10931139
else
10941140
begin
10951141
//There is error. Show the error.
1096-
if FConcoleMode then
1142+
if FConsoleMode then
10971143
begin
10981144
FTrackerList.LogStringList.Add(ErrorStr);
10991145
end
@@ -1490,7 +1536,7 @@ procedure TFormTrackerModify.FormDropFiles(Sender: TObject;
14901536
procedure TFormTrackerModify.FormShow(Sender: TObject);
14911537
begin
14921538
//In console mode do not show the program.
1493-
if FConcoleMode then
1539+
if FConsoleMode then
14941540
Visible := False;
14951541
end;
14961542

@@ -1529,7 +1575,7 @@ function TFormTrackerModify.AddTorrentFileList(TorrentFileNameStringList:
15291575
//Cancel everything.
15301576
FTrackerList.TorrentFileNameList.Clear;
15311577
FTrackerList.TrackerFromInsideTorrentFilesList.Clear;
1532-
if FConcoleMode then
1578+
if FConsoleMode then
15331579
begin
15341580
FTrackerList.LogStringList.Add('Error: Can not read torrent. ' +
15351581
TorrentFileNameStr);

0 commit comments

Comments
 (0)