From 2afcaebb78673f186109bb4d0414b824ff64d476 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sun, 8 May 2022 16:31:24 -0600 Subject: [PATCH] Prevent same bok being decrypted more than once at a time --- .../BookLiberation/ProcessorAutomationController.cs | 7 ++++--- LibationWinForms/grid/ProductsGrid.cs | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index 064b012e..adb40eff 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -50,12 +50,12 @@ namespace LibationWinForms.BookLiberation public static class ProcessorAutomationController { - public static async Task BackupSingleBookAsync(LibraryBook libraryBook) + public static async Task BackupSingleBookAsync(LibraryBook libraryBook, Action onCompleteAction = null) { Serilog.Log.Logger.Information($"Begin {nameof(BackupSingleBookAsync)} {{@DebugInfo}}", new { libraryBook?.Book?.AudibleProductId }); var logMe = LogMe.RegisterForm(); - var backupBook = CreateBackupBook(logMe); + var backupBook = CreateBackupBook(logMe, onCompleteAction); // continue even if libraryBook is null. we'll display even that in the processing box await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync(); @@ -96,13 +96,14 @@ namespace LibationWinForms.BookLiberation await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync(); } - private static Processable CreateBackupBook(LogMe logMe) + private static Processable CreateBackupBook(LogMe logMe, Action onCompleteAction = null) { var downloadPdf = CreateProcessable(logMe); //Chain pdf download on DownloadDecryptBook.Completed async void onDownloadDecryptBookCompleted(object sender, LibraryBook e) { + onCompleteAction?.Invoke(e); await downloadPdf.TryProcessAsync(e); } diff --git a/LibationWinForms/grid/ProductsGrid.cs b/LibationWinForms/grid/ProductsGrid.cs index 7f933bad..821220b3 100644 --- a/LibationWinForms/grid/ProductsGrid.cs +++ b/LibationWinForms/grid/ProductsGrid.cs @@ -29,6 +29,7 @@ namespace LibationWinForms public partial class ProductsGrid : UserControl { + private static List bookConversionInProgress = new(); public event EventHandler VisibleCountChanged; // alias @@ -88,8 +89,14 @@ namespace LibationWinForms return; } + //don't try to decrypt the same book at the same time. + if (bookConversionInProgress.Contains(libraryBook.Book.AudibleProductId)) + return; + + bookConversionInProgress.Add(libraryBook.Book.AudibleProductId); + // else: liberate - await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook); + await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook, b => bookConversionInProgress.Remove(b.Book.AudibleProductId)); } private static void Details_Click(GridEntry liveGridEntry)