Skip to content

Commit 0b53e88

Browse files
Issue GerryFerdinandus#15 Should give the user a warning when torrent file update failed.
If one of the torrent file write failed the variable SomeFilesAreReadOnly will be set. At the end of the files update cycle a warning text will be added if the variable SomeFilesAreReadOnly is set.
1 parent 0225684 commit 0b53e88

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

source/code/decodetorrent.pas

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,15 +543,14 @@ function TDecodeTorrent.SaveTorrent(const Filename: utf8string): boolean;
543543
str: utf8string;
544544
S: TFileStreamUTF8;
545545
begin
546-
Result := True;
547546
try
548547
//Encode it to string format
549548
str := '';
550549
TBEncoded.Encode(FBEncoded, str);
551550
//Write string to file. Support filename with unicode.
552551
S := TFileStreamUTF8.Create(FileName, fmCreate);
553552
try
554-
s.Write(Str[1], length(Str));
553+
Result := s.Write(Str[1], length(Str)) = length(Str);
555554
finally
556555
S.Free;
557556
end;

source/code/main.pas

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ procedure TFormTrackerModify.UpdateTorrent;
473473
var
474474
Reply, BoxStyle, i, CountTrackers: integer;
475475
PopUpMenuStr: string;
476-
SomeFilesAreReadOnly: Boolean;
476+
SomeFilesCannotBeWriten, SomeFilesAreReadOnly: boolean;
477477

478478
begin
479479
//Update all the torrent files.
@@ -483,6 +483,9 @@ procedure TFormTrackerModify.UpdateTorrent;
483483
//Undo all posible sort column used by the user. Sort it back to 'begin state'
484484
FControlerGridTorrentData.ReorderGrid;
485485

486+
//initial value is false, will be set to true if some file fails to write
487+
SomeFilesCannotBeWriten := False;
488+
486489
try
487490

488491
if not FConcoleMode then
@@ -615,8 +618,12 @@ procedure TFormTrackerModify.UpdateTorrent;
615618
FDecodePresentTorrent.Comment := FControlerGridTorrentData.ReadComment(i + 1);
616619

617620
//save the torrent file.
618-
FDecodePresentTorrent.SaveTorrent(FTorrentFileNameList[i]);
619-
end;
621+
if not FDecodePresentTorrent.SaveTorrent(FTorrentFileNameList[i]) then
622+
begin
623+
SomeFilesCannotBeWriten := True;
624+
end;
625+
626+
end;//for
620627

621628
//Create tracker.txt file
622629
SaveTrackerFinalListToFile;
@@ -670,7 +677,15 @@ procedure TFormTrackerModify.UpdateTorrent;
670677
if SomeFilesAreReadOnly then
671678
begin
672679
//add warning if read only files are detected.
673-
PopUpMenuStr := PopUpMenuStr + ' Warning: Some torrent files are not updated bacause they are READ-ONLY files.';
680+
PopUpMenuStr := PopUpMenuStr +
681+
' WARNING: Some torrent files are not updated bacause they are READ-ONLY files.';
682+
end;
683+
684+
if SomeFilesCannotBeWriten then
685+
begin
686+
//add warning if some files writen are failed. Someting is wrong with the disk.
687+
PopUpMenuStr := PopUpMenuStr +
688+
' WARNING: Some torrent files are not updated bacause they failed at write.';
674689
end;
675690

676691
//Show the MessageBox

0 commit comments

Comments
 (0)