Skip to content

Commit

Permalink
Issue #15 Should give the user a warning when torrent file update fai…
Browse files Browse the repository at this point in the history
…led.

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.
  • Loading branch information
GerryFerdinandus committed Feb 12, 2016
1 parent 0225684 commit 0b53e88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions source/code/decodetorrent.pas
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,14 @@ function TDecodeTorrent.SaveTorrent(const Filename: utf8string): boolean;
str: utf8string;
S: TFileStreamUTF8;
begin
Result := True;
try
//Encode it to string format
str := '';
TBEncoded.Encode(FBEncoded, str);
//Write string to file. Support filename with unicode.
S := TFileStreamUTF8.Create(FileName, fmCreate);
try
s.Write(Str[1], length(Str));
Result := s.Write(Str[1], length(Str)) = length(Str);
finally
S.Free;
end;
Expand Down
23 changes: 19 additions & 4 deletions source/code/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ procedure TFormTrackerModify.UpdateTorrent;
var
Reply, BoxStyle, i, CountTrackers: integer;
PopUpMenuStr: string;
SomeFilesAreReadOnly: Boolean;
SomeFilesCannotBeWriten, SomeFilesAreReadOnly: boolean;

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

//initial value is false, will be set to true if some file fails to write
SomeFilesCannotBeWriten := False;

try

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

//save the torrent file.
FDecodePresentTorrent.SaveTorrent(FTorrentFileNameList[i]);
end;
if not FDecodePresentTorrent.SaveTorrent(FTorrentFileNameList[i]) then
begin
SomeFilesCannotBeWriten := True;
end;

end;//for

//Create tracker.txt file
SaveTrackerFinalListToFile;
Expand Down Expand Up @@ -670,7 +677,15 @@ procedure TFormTrackerModify.UpdateTorrent;
if SomeFilesAreReadOnly then
begin
//add warning if read only files are detected.
PopUpMenuStr := PopUpMenuStr + ' Warning: Some torrent files are not updated bacause they are READ-ONLY files.';
PopUpMenuStr := PopUpMenuStr +
' WARNING: Some torrent files are not updated bacause they are READ-ONLY files.';
end;

if SomeFilesCannotBeWriten then
begin
//add warning if some files writen are failed. Someting is wrong with the disk.
PopUpMenuStr := PopUpMenuStr +
' WARNING: Some torrent files are not updated bacause they failed at write.';
end;

//Show the MessageBox
Expand Down

0 comments on commit 0b53e88

Please sign in to comment.