From ede8397f13164eb3d21c388247b08821eded064b Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sat, 21 Aug 2021 18:15:39 -0600 Subject: [PATCH] Needed to add check for actual file since Audio_Exists is now an application state. --- FileLiberator/DownloadDecryptBook.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index e0d960ef..4acf9681 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -47,13 +47,15 @@ namespace FileLiberator return new StatusHandler { "Decrypt failed" }; // moves files and returns dest dir - _ = moveFilesToBooksDir(libraryBook.Book, outputAudioFilename); + var moveResults = MoveFilesToBooksDir(libraryBook.Book, outputAudioFilename); - if (!libraryBook.Book.Audio_Exists) + if (!moveResults.movedAudioFile) return new StatusHandler { "Cannot find final audio file after decryption" }; - // only need to update if success. if failure, it will remain at 0 == NotLiberated - ApplicationServices.LibraryCommands.UpdateBook(libraryBook, LiberatedStatus.Liberated); + // need to update before Audio_Exists will return true + ApplicationServices.LibraryCommands.UpdateBook(libraryBook.Book, LiberatedStatus.Liberated); + + return new StatusHandler(); } @@ -146,7 +148,7 @@ namespace FileLiberator NarratorsDiscovered?.Invoke(this, e.Narrator ?? "[unknown]"); } - private static string moveFilesToBooksDir(Book product, string outputAudioFilename) + private static (string destinationDir, bool movedAudioFile) MoveFilesToBooksDir(Book product, string outputAudioFilename) { // create final directory. move each file into it. MOVE AUDIO FILE LAST // new dir: safetitle_limit50char + " [" + productId + "]" @@ -161,6 +163,7 @@ namespace FileLiberator // audio filename: safetitle_limit50char + " [" + productId + "]." + audio_ext var audioFileName = FileUtility.GetValidFilename(destinationDir, product.Title, musicFileExt, product.AudibleProductId); + bool movedAudioFile = false; foreach (var f in sortedFiles) { var dest @@ -173,11 +176,14 @@ namespace FileLiberator Cue.UpdateFileName(f, audioFileName); File.Move(f.FullName, dest); + + movedAudioFile |= AudibleFileStorage.Audio.IsFileTypeMatch(f); + } AudibleFileStorage.Audio.Refresh(); - return destinationDir; + return (destinationDir, movedAudioFile); } private static List getProductFilesSorted(Book product, string outputAudioFilename)