Skip to content

Commit

Permalink
Fix crash on cover art delete
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Oct 3, 2024
1 parent f719b75 commit 85768e9
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/Models/CodexCollection.cs
Original file line number Diff line number Diff line change
@@ -563,8 +563,16 @@ public void DeleteCodex(Codex toDelete)
AllCodices.Remove(toDelete);

//Delete CoverArt & Thumbnail
File.Delete(toDelete.CoverArt);
File.Delete(toDelete.Thumbnail);
try
{
File.Delete(toDelete.CoverArt);
File.Delete(toDelete.Thumbnail);
}
catch
{
//deleting the thumbnail could fail because of many reasons,
//not a big deal as it will just get overwritten when a new codex gets the freed id
}
Logger.Info($"Removed {toDelete.Title} from {DirectoryName}");
}

16 changes: 12 additions & 4 deletions src/ViewModels/ChooseMetaDataViewModel.cs
Original file line number Diff line number Diff line change
@@ -67,10 +67,18 @@ public override Task Finish()
CodicesWithChoices[i].Item1.RefreshThumbnail();
}
//delete temp cover if it exists
if (CodicesWithChoices[i].Item2.CoverArt?.EndsWith(".tmp.png") == true)
File.Delete(CodicesWithChoices[i].Item2.CoverArt);
if (CodicesWithChoices[i].Item2.Thumbnail?.EndsWith(".tmp.png") == true)
File.Delete(CodicesWithChoices[i].Item2.Thumbnail);
try
{
if (CodicesWithChoices[i].Item2.CoverArt?.EndsWith(".tmp.png") == true)
File.Delete(CodicesWithChoices[i].Item2.CoverArt);
if (CodicesWithChoices[i].Item2.Thumbnail?.EndsWith(".tmp.png") == true)
File.Delete(CodicesWithChoices[i].Item2.Thumbnail);
}
catch (Exception ex)
{
//no big deal if this fails
Logger.Warn("Failed to clean up temporary files", ex);
}

//Set image paths back so that copy operation after this doesn't change them to the temp files
_codicesWithMadeChoices[i].SetImagePaths(MainViewModel.CollectionVM.CurrentCollection);

0 comments on commit 85768e9

Please sign in to comment.