From 0045cf05efb9bb4cc522f5321a189f5217224d3a Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 11 Aug 2021 18:08:38 -0600 Subject: [PATCH] Redesign DookLiberation control flow. --- AaxDecrypter/AaxcDownloadConverter.cs | 24 +- FileLiberator/BackupBook.cs | 23 +- FileLiberator/ConvertToMp3.cs | 49 +- FileLiberator/DownloadDecryptBook.cs | 44 +- FileLiberator/DownloadFile.cs | 19 +- FileLiberator/DownloadableBase.cs | 16 +- .../{IDecryptable.cs => IAudioDecodable.cs} | 9 +- FileLiberator/IDownloadable.cs | 12 - FileLiberator/IDownloadableProcessable.cs | 4 - FileLiberator/IStreamProcessable.cs | 5 + FileLiberator/IStreamable.cs | 13 + FileManager/PictureStorage.cs | 2 +- LibationLauncher/LibationLauncher.csproj | 2 +- LibationLauncher/Program.cs | 3 + .../BookLiberation/AudioConvertForm.cs | 28 + ...ner.cs => AudioDecodeBaseForm.Designer.cs} | 2 +- .../BookLiberation/AudioDecodeBaseForm.cs | 129 ++++ ...ryptForm.resx => AudioDecodeBaseForm.resx} | 0 .../BookLiberation/AudioDecryptForm.cs | 24 + .../BookLiberation/DecryptForm.cs | 55 -- .../BookLiberation/DownloadForm.cs | 24 +- .../BookLiberation/PdfDownloadForm.cs | 16 + .../BookLiberation/ProcessBaseForm.cs | 45 ++ .../ProcessorAutomationController.cs | 306 ++------- .../BookLiberation/StreamBaseForm.cs | 52 ++ LibationWinForms/Form1.Designer.cs | 625 +++++++++--------- LibationWinForms/Form1.cs | 9 + LibationWinForms/Form1.resx | 3 +- 28 files changed, 817 insertions(+), 726 deletions(-) rename FileLiberator/{IDecryptable.cs => IAudioDecodable.cs} (56%) delete mode 100644 FileLiberator/IDownloadable.cs delete mode 100644 FileLiberator/IDownloadableProcessable.cs create mode 100644 FileLiberator/IStreamProcessable.cs create mode 100644 FileLiberator/IStreamable.cs create mode 100644 LibationWinForms/BookLiberation/AudioConvertForm.cs rename LibationWinForms/BookLiberation/{DecryptForm.Designer.cs => AudioDecodeBaseForm.Designer.cs} (99%) create mode 100644 LibationWinForms/BookLiberation/AudioDecodeBaseForm.cs rename LibationWinForms/BookLiberation/{DecryptForm.resx => AudioDecodeBaseForm.resx} (100%) create mode 100644 LibationWinForms/BookLiberation/AudioDecryptForm.cs delete mode 100644 LibationWinForms/BookLiberation/DecryptForm.cs create mode 100644 LibationWinForms/BookLiberation/PdfDownloadForm.cs create mode 100644 LibationWinForms/BookLiberation/ProcessBaseForm.cs create mode 100644 LibationWinForms/BookLiberation/StreamBaseForm.cs diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index efbbda4a..86794123 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -1,6 +1,7 @@ using AAXClean; using Dinah.Core; using Dinah.Core.IO; +using Dinah.Core.Net.Http; using Dinah.Core.StepRunner; using System; using System.IO; @@ -12,8 +13,9 @@ namespace AaxDecrypter { public event EventHandler RetrievedTags; public event EventHandler RetrievedCoverArt; - public event EventHandler DecryptProgressUpdate; + public event EventHandler DecryptProgressUpdate; public event EventHandler DecryptTimeRemaining; + public string AppName { get; set; } = nameof(AaxcDownloadConverter); private string outputFileName { get; } @@ -132,7 +134,14 @@ namespace AaxDecrypter public bool Step2_DownloadAndCombine() { - DecryptProgressUpdate?.Invoke(this, 0); + var zeroProgress = new DownloadProgress + { + BytesReceived = 0, + ProgressPercentage = 0, + TotalBytesToReceive = nfsPersister.NetworkFileStream.Length + }; + + DecryptProgressUpdate?.Invoke(this, zeroProgress); if (File.Exists(outputFileName)) FileExt.SafeDelete(outputFileName); @@ -151,7 +160,7 @@ namespace AaxDecrypter nfsPersister.Dispose(); - DecryptProgressUpdate?.Invoke(this, 0); + DecryptProgressUpdate?.Invoke(this, zeroProgress); return decryptionResult == ConversionResult.NoErrorsDetected && !isCanceled; } @@ -167,7 +176,13 @@ namespace AaxDecrypter double progressPercent = 100 * e.ProcessPosition.TotalSeconds / duration.TotalSeconds; - DecryptProgressUpdate?.Invoke(this, (int)progressPercent); + DecryptProgressUpdate?.Invoke(this, + new DownloadProgress + { + ProgressPercentage = progressPercent, + BytesReceived = (long)(nfsPersister.NetworkFileStream.Length * progressPercent), + TotalBytesToReceive = nfsPersister.NetworkFileStream.Length + }); } public bool Step3_CreateCue() @@ -209,6 +224,7 @@ namespace AaxDecrypter { isCanceled = true; aaxFile?.Cancel(); + aaxFile?.Dispose(); } } } diff --git a/FileLiberator/BackupBook.cs b/FileLiberator/BackupBook.cs index 718e0e7f..c7050b4c 100644 --- a/FileLiberator/BackupBook.cs +++ b/FileLiberator/BackupBook.cs @@ -2,7 +2,6 @@ using System.Threading.Tasks; using DataLayer; using Dinah.Core.ErrorHandling; -using FileManager; namespace FileLiberator { @@ -20,10 +19,16 @@ namespace FileLiberator public event EventHandler StatusUpdate; public event EventHandler Completed; - public DownloadDecryptBook DownloadDecryptBook { get; } = new DownloadDecryptBook(); - public DownloadPdf DownloadPdf { get; } = new DownloadPdf(); + public DownloadDecryptBook DownloadDecryptBook { get; } + public DownloadPdf DownloadPdf { get; } - public bool Validate(LibraryBook libraryBook) + public BackupBook(DownloadDecryptBook downloadDecryptBook, DownloadPdf downloadPdf) + { + DownloadDecryptBook = downloadDecryptBook; + DownloadPdf = downloadPdf; + } + + public bool Validate(LibraryBook libraryBook) => !ApplicationServices.TransitionalFileLocator.Audio_Exists(libraryBook.Book); // do NOT use ConfigureAwait(false) on ProcessAsync() @@ -35,16 +40,16 @@ namespace FileLiberator try { { - var statusHandler = await DownloadDecryptBook.TryProcessAsync(libraryBook); - if (statusHandler.HasErrors) + var statusHandler = await DownloadDecryptBook.TryProcessAsync(libraryBook); + if (statusHandler.HasErrors) return statusHandler; } - { - var statusHandler = await DownloadPdf.TryProcessAsync(libraryBook); + { + var statusHandler = await DownloadPdf.TryProcessAsync(libraryBook); if (statusHandler.HasErrors) return statusHandler; - } + } return new StatusHandler(); } diff --git a/FileLiberator/ConvertToMp3.cs b/FileLiberator/ConvertToMp3.cs index 92eddcfa..6b514837 100644 --- a/FileLiberator/ConvertToMp3.cs +++ b/FileLiberator/ConvertToMp3.cs @@ -3,6 +3,7 @@ using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; using Dinah.Core.IO; +using Dinah.Core.Net.Http; using FileManager; using System; using System.IO; @@ -11,25 +12,26 @@ using System.Threading.Tasks; namespace FileLiberator { - public class ConvertToMp3 : IDecryptable + public class ConvertToMp3 : IAudioDecodable { - public event EventHandler DecryptBegin; - public event EventHandler TitleDiscovered; - public event EventHandler AuthorsDiscovered; - public event EventHandler NarratorsDiscovered; - public event EventHandler CoverImageFilepathDiscovered; - public event EventHandler UpdateProgress; - public event EventHandler UpdateRemainingTime; - public event EventHandler DecryptCompleted; - public event EventHandler Begin; - public event EventHandler Completed; - - public event EventHandler StatusUpdate; - public event EventHandler> RequestCoverArt; private Mp4File m4bBook; - private string Mp3FileName(string m4bPath) => m4bPath is null ? string.Empty : PathLib.ReplaceExtension(m4bPath, ".mp3"); + public event EventHandler StreamingTimeRemaining; + public event EventHandler> RequestCoverArt; + public event EventHandler TitleDiscovered; + public event EventHandler AuthorsDiscovered; + public event EventHandler NarratorsDiscovered; + public event EventHandler CoverImageFilepathDiscovered; + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingCompleted; + public event EventHandler Begin; + public event EventHandler StatusUpdate; + public event EventHandler Completed; + + private long fileSize; + private string Mp3FileName(string m4bPath) => m4bPath is null ? string.Empty : PathLib.ReplaceExtension(m4bPath, ".mp3"); public void Cancel() => m4bBook?.Cancel(); @@ -43,15 +45,16 @@ namespace FileLiberator { Begin?.Invoke(this, libraryBook); - DecryptBegin?.Invoke(this, $"Begin converting {libraryBook} to mp3"); + StreamingBegin?.Invoke(this, $"Begin converting {libraryBook} to mp3"); try { var m4bPath = ApplicationServices.TransitionalFileLocator.Audio_GetPath(libraryBook.Book); - m4bBook = new Mp4File(m4bPath, FileAccess.Read); m4bBook.ConversionProgressUpdate += M4bBook_ConversionProgressUpdate; + fileSize = m4bBook.InputStream.Length; + TitleDiscovered?.Invoke(this, m4bBook.AppleTags.Title); AuthorsDiscovered?.Invoke(this, m4bBook.AppleTags.FirstAuthor); NarratorsDiscovered?.Invoke(this, m4bBook.AppleTags.Narrator); @@ -76,7 +79,7 @@ namespace FileLiberator } finally { - DecryptCompleted?.Invoke(this, $"Completed converting to mp3: {libraryBook.Book.Title}"); + StreamingCompleted?.Invoke(this, $"Completed converting to mp3: {libraryBook.Book.Title}"); Completed?.Invoke(this, libraryBook); } } @@ -88,11 +91,17 @@ namespace FileLiberator double estTimeRemaining = remainingSecsToProcess / e.ProcessSpeed; if (double.IsNormal(estTimeRemaining)) - UpdateRemainingTime?.Invoke(this, TimeSpan.FromSeconds(estTimeRemaining)); + StreamingTimeRemaining?.Invoke(this, TimeSpan.FromSeconds(estTimeRemaining)); double progressPercent = 100 * e.ProcessPosition.TotalSeconds / duration.TotalSeconds; - UpdateProgress?.Invoke(this, (int)progressPercent); + StreamingProgressChanged?.Invoke(this, + new DownloadProgress + { + ProgressPercentage = progressPercent, + BytesReceived = (long)(fileSize * progressPercent), + TotalBytesToReceive = fileSize + }); } } } diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index a2b961c6..8565a1da 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -8,27 +8,30 @@ using AudibleApi; using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; +using Dinah.Core.Net.Http; using FileManager; namespace FileLiberator { - public class DownloadDecryptBook : IDecryptable + public class DownloadDecryptBook : IAudioDecodable { - public event EventHandler> RequestCoverArt; - public event EventHandler Begin; - public event EventHandler DecryptBegin; - public event EventHandler TitleDiscovered; - public event EventHandler AuthorsDiscovered; - public event EventHandler NarratorsDiscovered; - public event EventHandler CoverImageFilepathDiscovered; - public event EventHandler UpdateProgress; - public event EventHandler UpdateRemainingTime; - public event EventHandler DecryptCompleted; - public event EventHandler Completed; - public event EventHandler StatusUpdate; - private AaxcDownloadConverter aaxcDownloader; - public async Task ProcessAsync(LibraryBook libraryBook) + private AaxcDownloadConverter aaxcDownloader; + + public event EventHandler StreamingTimeRemaining; + public event EventHandler> RequestCoverArt; + public event EventHandler TitleDiscovered; + public event EventHandler AuthorsDiscovered; + public event EventHandler NarratorsDiscovered; + public event EventHandler CoverImageFilepathDiscovered; + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingCompleted; + public event EventHandler Begin; + public event EventHandler StatusUpdate; + public event EventHandler Completed; + + public async Task ProcessAsync(LibraryBook libraryBook) { Begin?.Invoke(this, libraryBook); @@ -63,7 +66,7 @@ namespace FileLiberator private async Task aaxToM4bConverterDecryptAsync(string cacheDir, string destinationDir, LibraryBook libraryBook) { - DecryptBegin?.Invoke(this, $"Begin decrypting {libraryBook}"); + StreamingBegin?.Invoke(this, $"Begin decrypting {libraryBook}"); try { @@ -103,8 +106,8 @@ namespace FileLiberator aaxcDownloader = new AaxcDownloadConverter(outFileName, cacheDir, aaxcDecryptDlLic, format) { AppName = "Libation" }; - aaxcDownloader.DecryptProgressUpdate += (s, progress) => UpdateProgress?.Invoke(this, progress); - aaxcDownloader.DecryptTimeRemaining += (s, remaining) => UpdateRemainingTime?.Invoke(this, remaining); + aaxcDownloader.DecryptProgressUpdate += (s, progress) => StreamingProgressChanged?.Invoke(this, progress); + aaxcDownloader.DecryptTimeRemaining += (s, remaining) => StreamingTimeRemaining?.Invoke(this, remaining); aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; aaxcDownloader.RetrievedTags += aaxcDownloader_RetrievedTags; @@ -119,11 +122,12 @@ namespace FileLiberator } finally { - DecryptCompleted?.Invoke(this, $"Completed downloading and decrypting {libraryBook.Book.Title}"); + StreamingCompleted?.Invoke(this, $"Completed downloading and decrypting {libraryBook.Book.Title}"); } } - private void AaxcDownloader_RetrievedCoverArt(object sender, byte[] e) + + private void AaxcDownloader_RetrievedCoverArt(object sender, byte[] e) { if (e is null && Configuration.Instance.AllowLibationFixup) { diff --git a/FileLiberator/DownloadFile.cs b/FileLiberator/DownloadFile.cs index 13f38479..d4735420 100644 --- a/FileLiberator/DownloadFile.cs +++ b/FileLiberator/DownloadFile.cs @@ -6,20 +6,21 @@ using Dinah.Core.Net.Http; namespace FileLiberator { // currently only used to download the .zip flies for upgrade - public class DownloadFile : IDownloadable + public class DownloadFile : IStreamable { - public event EventHandler DownloadBegin; - public event EventHandler DownloadProgressChanged; - public event EventHandler DownloadCompleted; + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingCompleted; + public event EventHandler StreamingTimeRemaining; public async Task PerformDownloadFileAsync(string downloadUrl, string proposedDownloadFilePath) { var client = new HttpClient(); var progress = new Progress(); - progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e); + progress.ProgressChanged += OnProgressChanged; - DownloadBegin?.Invoke(this, proposedDownloadFilePath); + StreamingBegin?.Invoke(this, proposedDownloadFilePath); try { @@ -28,8 +29,12 @@ namespace FileLiberator } finally { - DownloadCompleted?.Invoke(this, proposedDownloadFilePath); + StreamingCompleted?.Invoke(this, proposedDownloadFilePath); } } + private void OnProgressChanged(object sender, DownloadProgress e) + { + StreamingProgressChanged?.Invoke(this, e); + } } } diff --git a/FileLiberator/DownloadableBase.cs b/FileLiberator/DownloadableBase.cs index da78a8a6..9156e626 100644 --- a/FileLiberator/DownloadableBase.cs +++ b/FileLiberator/DownloadableBase.cs @@ -6,16 +6,18 @@ using Dinah.Core.Net.Http; namespace FileLiberator { - public abstract class DownloadableBase : IDownloadableProcessable + public abstract class DownloadableBase : IStreamProcessable { public event EventHandler Begin; public event EventHandler Completed; - public event EventHandler DownloadBegin; - public event EventHandler DownloadProgressChanged; - public event EventHandler DownloadCompleted; + public event EventHandler StreamingBegin; + public event EventHandler StreamingProgressChanged; + public event EventHandler StreamingCompleted; public event EventHandler StatusUpdate; + public event EventHandler StreamingTimeRemaining; + protected void Invoke_StatusUpdate(string message) => StatusUpdate?.Invoke(this, message); public abstract bool Validate(LibraryBook libraryBook); @@ -44,9 +46,9 @@ namespace FileLiberator protected async Task PerformDownloadAsync(string proposedDownloadFilePath, Func, Task> func) { var progress = new Progress(); - progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e); + progress.ProgressChanged += (_, e) => StreamingProgressChanged?.Invoke(this, e); - DownloadBegin?.Invoke(this, proposedDownloadFilePath); + StreamingBegin?.Invoke(this, proposedDownloadFilePath); try { @@ -57,7 +59,7 @@ namespace FileLiberator } finally { - DownloadCompleted?.Invoke(this, proposedDownloadFilePath); + StreamingCompleted?.Invoke(this, proposedDownloadFilePath); } } } diff --git a/FileLiberator/IDecryptable.cs b/FileLiberator/IAudioDecodable.cs similarity index 56% rename from FileLiberator/IDecryptable.cs rename to FileLiberator/IAudioDecodable.cs index 568c3624..8eaab624 100644 --- a/FileLiberator/IDecryptable.cs +++ b/FileLiberator/IAudioDecodable.cs @@ -1,20 +1,17 @@ -using System; +using Dinah.Core.Net.Http; +using System; namespace FileLiberator { - public interface IDecryptable : IProcessable + public interface IAudioDecodable : IStreamProcessable { - event EventHandler DecryptBegin; event EventHandler> RequestCoverArt; event EventHandler TitleDiscovered; event EventHandler AuthorsDiscovered; event EventHandler NarratorsDiscovered; event EventHandler CoverImageFilepathDiscovered; - event EventHandler UpdateProgress; - event EventHandler UpdateRemainingTime; - event EventHandler DecryptCompleted; void Cancel(); } } diff --git a/FileLiberator/IDownloadable.cs b/FileLiberator/IDownloadable.cs deleted file mode 100644 index 782d96ee..00000000 --- a/FileLiberator/IDownloadable.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using Dinah.Core.Net.Http; - -namespace FileLiberator -{ - public interface IDownloadable - { - event EventHandler DownloadBegin; - event EventHandler DownloadProgressChanged; - event EventHandler DownloadCompleted; - } -} diff --git a/FileLiberator/IDownloadableProcessable.cs b/FileLiberator/IDownloadableProcessable.cs deleted file mode 100644 index 6c8b41de..00000000 --- a/FileLiberator/IDownloadableProcessable.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FileLiberator -{ - public interface IDownloadableProcessable : IDownloadable, IProcessable { } -} diff --git a/FileLiberator/IStreamProcessable.cs b/FileLiberator/IStreamProcessable.cs new file mode 100644 index 00000000..360663ab --- /dev/null +++ b/FileLiberator/IStreamProcessable.cs @@ -0,0 +1,5 @@ + +namespace FileLiberator +{ + public interface IStreamProcessable : IStreamable, IProcessable { } +} diff --git a/FileLiberator/IStreamable.cs b/FileLiberator/IStreamable.cs new file mode 100644 index 00000000..94049a7a --- /dev/null +++ b/FileLiberator/IStreamable.cs @@ -0,0 +1,13 @@ +using System; +using Dinah.Core.Net.Http; + +namespace FileLiberator +{ + public interface IStreamable + { + event EventHandler StreamingBegin; + event EventHandler StreamingProgressChanged; + event EventHandler StreamingTimeRemaining; + event EventHandler StreamingCompleted; + } +} diff --git a/FileManager/PictureStorage.cs b/FileManager/PictureStorage.cs index 64e3ccfa..4fdd894b 100644 --- a/FileManager/PictureStorage.cs +++ b/FileManager/PictureStorage.cs @@ -125,7 +125,7 @@ namespace FileManager private static HttpClient imageDownloadClient { get; } = new HttpClient(); private static byte[] downloadBytes(PictureDefinition def) { - var sz = ((int)def.Size).ToString(); + var sz = (int)def.Size; return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result; } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 66f1127c..ca7b53f8 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.4.9.158 + 5.4.9.200 diff --git a/LibationLauncher/Program.cs b/LibationLauncher/Program.cs index 0786e414..0184b1a7 100644 --- a/LibationLauncher/Program.cs +++ b/LibationLauncher/Program.cs @@ -63,6 +63,9 @@ namespace LibationLauncher #if !DEBUG checkForUpdate(config); #endif + LibationWinForms.BookLiberation.ProcessorAutomationController.DownloadFile( + "https://github.com/rmcrackan/Libation/releases/download/v5.4.9/Libation.5.4.9.zip", + @"C:\Users\mbuca\Downloads\libation test dl.zip"); Application.Run(new Form1()); } diff --git a/LibationWinForms/BookLiberation/AudioConvertForm.cs b/LibationWinForms/BookLiberation/AudioConvertForm.cs new file mode 100644 index 00000000..0dde6860 --- /dev/null +++ b/LibationWinForms/BookLiberation/AudioConvertForm.cs @@ -0,0 +1,28 @@ +using DataLayer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibationWinForms.BookLiberation +{ + class AudioConvertForm : AudioDecodeBaseForm + { + #region AudioDecodeBaseForm overrides + public override string DecodeActionName => "Converting"; + #endregion + + #region IProcessable event handler overrides + public override void OnBegin(object sender, LibraryBook libraryBook) + { + InfoLogAction($"Convert Step, Begin: {libraryBook.Book}"); + + base.OnBegin(sender, libraryBook); + } + public override void OnCompleted(object sender, LibraryBook libraryBook) + => InfoLogAction($"Convert Step, Completed: {libraryBook.Book}{Environment.NewLine}"); + + #endregion + } +} diff --git a/LibationWinForms/BookLiberation/DecryptForm.Designer.cs b/LibationWinForms/BookLiberation/AudioDecodeBaseForm.Designer.cs similarity index 99% rename from LibationWinForms/BookLiberation/DecryptForm.Designer.cs rename to LibationWinForms/BookLiberation/AudioDecodeBaseForm.Designer.cs index e279b1ec..d38e4bbb 100644 --- a/LibationWinForms/BookLiberation/DecryptForm.Designer.cs +++ b/LibationWinForms/BookLiberation/AudioDecodeBaseForm.Designer.cs @@ -1,6 +1,6 @@ namespace LibationWinForms.BookLiberation { - partial class DecryptForm + partial class AudioDecodeBaseForm { /// /// Required designer variable. diff --git a/LibationWinForms/BookLiberation/AudioDecodeBaseForm.cs b/LibationWinForms/BookLiberation/AudioDecodeBaseForm.cs new file mode 100644 index 00000000..3354460a --- /dev/null +++ b/LibationWinForms/BookLiberation/AudioDecodeBaseForm.cs @@ -0,0 +1,129 @@ +using DataLayer; +using Dinah.Core.Net.Http; +using Dinah.Core.Windows.Forms; +using FileLiberator; +using System; + +namespace LibationWinForms.BookLiberation +{ + public partial class AudioDecodeBaseForm : ProcessBaseForm + { + public virtual string DecodeActionName { get; } = "Decoding"; + public AudioDecodeBaseForm() => InitializeComponent(); + + private Func GetCoverArtDelegate; + + // book info + private string title; + private string authorNames; + private string narratorNames; + + public override void SetProcessable(IStreamable streamProcessable, Action infoLog) + { + base.SetProcessable(streamProcessable, infoLog); + + if (Streamable is not null && Streamable is IAudioDecodable audioDecodable) + { + OnUnsubscribeAll(this, EventArgs.Empty); + + audioDecodable.RequestCoverArt += OnRequestCoverArt; + audioDecodable.TitleDiscovered += OnTitleDiscovered; + audioDecodable.AuthorsDiscovered += OnAuthorsDiscovered; + audioDecodable.NarratorsDiscovered += OnNarratorsDiscovered; + audioDecodable.CoverImageFilepathDiscovered += OnCoverImageFilepathDiscovered; + + Disposed += OnUnsubscribeAll; + } + } + private void OnUnsubscribeAll(object sender, EventArgs e) + { + Disposed -= OnUnsubscribeAll; + if (Streamable is not null && Streamable is IAudioDecodable audioDecodable) + { + audioDecodable.RequestCoverArt -= OnRequestCoverArt; + audioDecodable.TitleDiscovered -= OnTitleDiscovered; + audioDecodable.AuthorsDiscovered -= OnAuthorsDiscovered; + audioDecodable.NarratorsDiscovered -= OnNarratorsDiscovered; + audioDecodable.CoverImageFilepathDiscovered -= OnCoverImageFilepathDiscovered; + + audioDecodable.Cancel(); + } + } + + #region IProcessable event handler overrides + public override void OnBegin(object sender, LibraryBook libraryBook) + { + GetCoverArtDelegate = () => FileManager.PictureStorage.GetPictureSynchronously( + new FileManager.PictureDefinition( + libraryBook.Book.PictureId, + FileManager.PictureSize._500x500)); + + //Set default values from library + OnTitleDiscovered(null, libraryBook.Book.Title); + OnAuthorsDiscovered(null, string.Join(", ", libraryBook.Book.Authors)); + OnNarratorsDiscovered(null, string.Join(", ", libraryBook.Book.NarratorNames)); + OnCoverImageFilepathDiscovered(null, + FileManager.PictureStorage.GetPictureSynchronously( + new FileManager.PictureDefinition( + libraryBook.Book.PictureId, + FileManager.PictureSize._80x80))); + } + #endregion + + #region IStreamable event handler overrides + + public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) + { + if (!downloadProgress.ProgressPercentage.HasValue) + return; + + if (downloadProgress.ProgressPercentage == 0) + updateRemainingTime(0); + else + progressBar1.UIThread(() => progressBar1.Value = (int)downloadProgress.ProgressPercentage); + } + + public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) + => updateRemainingTime((int)timeRemaining.TotalSeconds); + + #endregion + + #region IAudioDecodable event handlers + + public virtual void OnRequestCoverArt(object sender, Action setCoverArtDelegate) + => setCoverArtDelegate(GetCoverArtDelegate?.Invoke()); + + public virtual void OnTitleDiscovered(object sender, string title) + { + this.UIThread(() => this.Text = DecodeActionName + " " + title); + this.title = title; + updateBookInfo(); + } + + public virtual void OnAuthorsDiscovered(object sender, string authors) + { + authorNames = authors; + updateBookInfo(); + } + + public virtual void OnNarratorsDiscovered(object sender, string narrators) + { + narratorNames = narrators; + updateBookInfo(); + } + + public virtual void OnCoverImageFilepathDiscovered(object sender, byte[] coverArt) + => pictureBox1.UIThread(() => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(coverArt)); + + #endregion + + + // thread-safe UI updates + private void updateBookInfo() + => bookInfoLbl.UIThread(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"); + + private void updateRemainingTime(int remaining) + => remainingTimeLbl.UIThread(() => remainingTimeLbl.Text = $"ETA:\r\n{remaining} sec"); + + } +} diff --git a/LibationWinForms/BookLiberation/DecryptForm.resx b/LibationWinForms/BookLiberation/AudioDecodeBaseForm.resx similarity index 100% rename from LibationWinForms/BookLiberation/DecryptForm.resx rename to LibationWinForms/BookLiberation/AudioDecodeBaseForm.resx diff --git a/LibationWinForms/BookLiberation/AudioDecryptForm.cs b/LibationWinForms/BookLiberation/AudioDecryptForm.cs new file mode 100644 index 00000000..45b6b5c8 --- /dev/null +++ b/LibationWinForms/BookLiberation/AudioDecryptForm.cs @@ -0,0 +1,24 @@ +using DataLayer; +using System; + +namespace LibationWinForms.BookLiberation +{ + class AudioDecryptForm : AudioDecodeBaseForm + { + #region AudioDecodeBaseForm overrides + public override string DecodeActionName => "Decrypting"; + #endregion + + #region IProcessable event handler overrides + public override void OnBegin(object sender, LibraryBook libraryBook) + { + InfoLogAction($"Download & Decrypt Step, Begin: {libraryBook.Book}"); + + base.OnBegin(sender, libraryBook); + } + public override void OnCompleted(object sender, LibraryBook libraryBook) + => InfoLogAction($"Download & Decrypt Step, Completed: {libraryBook.Book}{Environment.NewLine}"); + + #endregion + } +} diff --git a/LibationWinForms/BookLiberation/DecryptForm.cs b/LibationWinForms/BookLiberation/DecryptForm.cs deleted file mode 100644 index d39089e7..00000000 --- a/LibationWinForms/BookLiberation/DecryptForm.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Dinah.Core.Windows.Forms; -using System; -using System.Linq; -using System.Windows.Forms; - -namespace LibationWinForms.BookLiberation -{ - public partial class DecryptForm : Form - { - public DecryptForm() => InitializeComponent(); - - // book info - private string title; - private string authorNames; - private string narratorNames; - - public void SetTitle(string actionName, string title) - { - this.UIThread(() => this.Text = actionName + " " + title); - this.title = title; - updateBookInfo(); - } - public void SetAuthorNames(string authorNames) - { - this.authorNames = authorNames; - updateBookInfo(); - } - public void SetNarratorNames(string narratorNames) - { - this.narratorNames = narratorNames; - updateBookInfo(); - } - - // thread-safe UI updates - private void updateBookInfo() - => bookInfoLbl.UIThread(() => bookInfoLbl.Text = $"{title}\r\nBy {authorNames}\r\nNarrated by {narratorNames}"); - - public void SetCoverImage(System.Drawing.Image coverImage) - => pictureBox1.UIThread(() => pictureBox1.Image = coverImage); - - public void UpdateProgress(int percentage) - { - if (percentage == 0) - updateRemainingTime(0); - else - progressBar1.UIThread(() => progressBar1.Value = percentage); - } - - public void UpdateRemainingTime(TimeSpan remaining) - => updateRemainingTime((int)remaining.TotalSeconds); - - private void updateRemainingTime(int remaining) - => remainingTimeLbl.UIThread(() => remainingTimeLbl.Text = $"ETA:\r\n{remaining} sec"); - } -} diff --git a/LibationWinForms/BookLiberation/DownloadForm.cs b/LibationWinForms/BookLiberation/DownloadForm.cs index 7a260a05..563a68fd 100644 --- a/LibationWinForms/BookLiberation/DownloadForm.cs +++ b/LibationWinForms/BookLiberation/DownloadForm.cs @@ -1,11 +1,13 @@ -using Dinah.Core.Windows.Forms; +using DataLayer; +using Dinah.Core.Net.Http; +using Dinah.Core.Windows.Forms; using System; using System.Linq; using System.Windows.Forms; namespace LibationWinForms.BookLiberation { - public partial class DownloadForm : Form + public partial class DownloadForm : ProcessBaseForm { public DownloadForm() { @@ -15,23 +17,27 @@ namespace LibationWinForms.BookLiberation filenameLbl.Text = ""; } - // thread-safe UI updates - public void UpdateFilename(string title) => filenameLbl.UIThread(() => filenameLbl.Text = title); - - public void DownloadProgressChanged(long BytesReceived, long? TotalBytesToReceive) + #region IStreamable event handler overrides + public override void OnStreamingBegin(object sender, string beginString) + { + filenameLbl.UIThread(() => filenameLbl.Text = beginString); + base.OnStreamingBegin(sender, beginString); + } + public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { // this won't happen with download file. it will happen with download string - if (!TotalBytesToReceive.HasValue || TotalBytesToReceive.Value <= 0) + if (!downloadProgress.TotalBytesToReceive.HasValue || downloadProgress.TotalBytesToReceive.Value <= 0) return; - progressLbl.UIThread(() => progressLbl.Text = $"{BytesReceived:#,##0} of {TotalBytesToReceive.Value:#,##0}"); + progressLbl.UIThread(() => progressLbl.Text = $"{downloadProgress.BytesReceived:#,##0} of {downloadProgress.TotalBytesToReceive.Value:#,##0}"); - var d = double.Parse(BytesReceived.ToString()) / double.Parse(TotalBytesToReceive.Value.ToString()) * 100.0; + var d = double.Parse(downloadProgress.BytesReceived.ToString()) / double.Parse(downloadProgress.TotalBytesToReceive.Value.ToString()) * 100.0; var i = int.Parse(Math.Truncate(d).ToString()); progressBar1.UIThread(() => progressBar1.Value = i); lastDownloadProgress = DateTime.Now; } + #endregion #region timer private Timer timer { get; } = new Timer { Interval = 1000 }; diff --git a/LibationWinForms/BookLiberation/PdfDownloadForm.cs b/LibationWinForms/BookLiberation/PdfDownloadForm.cs new file mode 100644 index 00000000..870871e9 --- /dev/null +++ b/LibationWinForms/BookLiberation/PdfDownloadForm.cs @@ -0,0 +1,16 @@ +using DataLayer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibationWinForms.BookLiberation +{ + internal class PdfDownloadForm : DownloadForm + { + public override void OnBegin(object sender, LibraryBook libraryBook) => InfoLogAction($"PDF Step, Begin: {libraryBook.Book}"); + public override void OnCompleted(object sender, LibraryBook libraryBook) => InfoLogAction($"PDF Step, Completed: {libraryBook.Book}"); + + } +} diff --git a/LibationWinForms/BookLiberation/ProcessBaseForm.cs b/LibationWinForms/BookLiberation/ProcessBaseForm.cs new file mode 100644 index 00000000..acd8b6bd --- /dev/null +++ b/LibationWinForms/BookLiberation/ProcessBaseForm.cs @@ -0,0 +1,45 @@ +using DataLayer; +using Dinah.Core.Net.Http; +using FileLiberator; +using System; +using System.Windows.Forms; + +namespace LibationWinForms.BookLiberation +{ + public class ProcessBaseForm : StreamBaseForm + { + protected Action InfoLogAction { get; private set; } + public virtual void SetProcessable(IStreamable streamable, Action infoLog) + { + InfoLogAction = infoLog; + SetStreamable(streamable); + + if (Streamable is not null && Streamable is IProcessable processable) + { + OnUnsubscribeAll(this, EventArgs.Empty); + + processable.Begin += OnBegin; + processable.Completed += OnCompleted; + processable.StatusUpdate += OnStatusUpdate; + Disposed += OnUnsubscribeAll; + } + } + + private void OnUnsubscribeAll(object sender, EventArgs e) + { + Disposed -= OnUnsubscribeAll; + if (Streamable is not null && Streamable is IProcessable processable) + { + processable.Begin -= OnBegin; + processable.Completed -= OnCompleted; + processable.StatusUpdate -= OnStatusUpdate; + } + } + + #region IProcessable event handlers + public virtual void OnBegin(object sender, LibraryBook libraryBook) => InfoLogAction($"Begin: {libraryBook.Book}"); + public virtual void OnStatusUpdate(object sender, string statusUpdate) => InfoLogAction("- " + statusUpdate); + public virtual void OnCompleted(object sender, LibraryBook libraryBook) => InfoLogAction($"Completed: {libraryBook.Book}{Environment.NewLine}"); + #endregion + } +} diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index 16462100..8cbc11ba 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -55,153 +55,65 @@ namespace LibationWinForms.BookLiberation { Serilog.Log.Logger.Information("Begin backup single {@DebugInfo}", new { libraryBook?.Book?.AudibleProductId }); - var backupBook = getWiredUpBackupBook(completedAction); - - (Action unsubscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook); + LogMe logMe = LogMe.RegisterForm(); + var backupBook = CreateBackupBook(completedAction, logMe); // continue even if libraryBook is null. we'll display even that in the processing box await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync(); - - unsubscribeEvents(); } public static async Task BackupAllBooksAsync(EventHandler completedAction = null) { Serilog.Log.Logger.Information("Begin " + nameof(BackupAllBooksAsync)); - var backupBook = getWiredUpBackupBook(completedAction); var automatedBackupsForm = new AutomatedBackupsForm(); + LogMe logMe = LogMe.RegisterForm(automatedBackupsForm); - (Action unsubscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook, automatedBackupsForm); + var backupBook = CreateBackupBook(completedAction, logMe); await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync(); - unsubscribeEvents(); } public static async Task ConvertAllBooksAsync() { Serilog.Log.Logger.Information("Begin " + nameof(ConvertAllBooksAsync)); - var convertBook = new ConvertToMp3(); - convertBook.Begin += (_, l) => wireUpEvents(convertBook, l, "Converting"); - var automatedBackupsForm = new AutomatedBackupsForm(); + LogMe logMe = LogMe.RegisterForm(automatedBackupsForm); - var logMe = LogMe.RegisterForm(automatedBackupsForm); - - void statusUpdate(object _, string str) => logMe.Info("- " + str); - void convertBookBegin(object _, LibraryBook libraryBook) => logMe.Info($"Convert Step, Begin: {libraryBook.Book}"); - void convertBookCompleted(object _, LibraryBook libraryBook) => logMe.Info($"Convert Step, Completed: {libraryBook.Book}{Environment.NewLine}"); - convertBook.Begin += convertBookBegin; - convertBook.StatusUpdate += statusUpdate; - convertBook.Completed += convertBookCompleted; + var convertBook = CreateStreamableProcessable(null, logMe); await new BackupLoop(logMe, convertBook, automatedBackupsForm).RunBackupAsync(); - - convertBook.Begin -= convertBookBegin; - convertBook.StatusUpdate -= statusUpdate; - convertBook.Completed -= convertBookCompleted; } - private static BackupBook getWiredUpBackupBook(EventHandler completedAction) + private static BackupBook CreateBackupBook(EventHandler completedAction, LogMe logMe) { - var backupBook = new BackupBook(); - - backupBook.DownloadDecryptBook.Begin += (_, l) => wireUpEvents(backupBook.DownloadDecryptBook, l); - backupBook.DownloadPdf.Begin += (_, __) => wireUpEvents(backupBook.DownloadPdf); - - if (completedAction != null) - { - backupBook.DownloadDecryptBook.Completed += completedAction; - backupBook.DownloadPdf.Completed += completedAction; - } - - return backupBook; - } - - private static (Action unsubscribeEvents, LogMe) attachToBackupsForm(BackupBook backupBook, AutomatedBackupsForm automatedBackupsForm = null) - { - #region create logger - var logMe = LogMe.RegisterForm(automatedBackupsForm); - #endregion - - #region define how model actions will affect form behavior - void statusUpdate(object _, string str) => logMe.Info("- " + str); - void decryptBookBegin(object _, LibraryBook libraryBook) => logMe.Info($"Decrypt Step, Begin: {libraryBook.Book}"); - // extra line after book is completely finished - void decryptBookCompleted(object _, LibraryBook libraryBook) => logMe.Info($"Decrypt Step, Completed: {libraryBook.Book}{Environment.NewLine}"); - void downloadPdfBegin(object _, LibraryBook libraryBook) => logMe.Info($"PDF Step, Begin: {libraryBook.Book}"); - // extra line after book is completely finished - void downloadPdfCompleted(object _, LibraryBook libraryBook) => logMe.Info($"PDF Step, Completed: {libraryBook.Book}{Environment.NewLine}"); - #endregion - - #region subscribe new form to model's events - backupBook.DownloadDecryptBook.Begin += decryptBookBegin; - backupBook.DownloadDecryptBook.StatusUpdate += statusUpdate; - backupBook.DownloadDecryptBook.Completed += decryptBookCompleted; - backupBook.DownloadPdf.Begin += downloadPdfBegin; - backupBook.DownloadPdf.StatusUpdate += statusUpdate; - backupBook.DownloadPdf.Completed += downloadPdfCompleted; - #endregion - - #region when form closes, unsubscribe from model's events - // unsubscribe so disposed forms aren't still trying to receive notifications - Action unsubscribe = () => - { - backupBook.DownloadDecryptBook.Begin -= decryptBookBegin; - backupBook.DownloadDecryptBook.StatusUpdate -= statusUpdate; - backupBook.DownloadDecryptBook.Completed -= decryptBookCompleted; - backupBook.DownloadPdf.Begin -= downloadPdfBegin; - backupBook.DownloadPdf.StatusUpdate -= statusUpdate; - backupBook.DownloadPdf.Completed -= downloadPdfCompleted; - }; - #endregion - - return (unsubscribe, logMe); + var downloadPdf = CreateStreamableProcessable(completedAction, logMe); + var downloadDecryptBook = CreateStreamableProcessable(completedAction, logMe); + return new BackupBook(downloadDecryptBook, downloadPdf); } public static async Task BackupAllPdfsAsync(EventHandler completedAction = null) { Serilog.Log.Logger.Information("Begin " + nameof(BackupAllPdfsAsync)); - var downloadPdf = getWiredUpDownloadPdf(completedAction); + var automatedBackupsForm = new AutomatedBackupsForm(); + LogMe logMe = LogMe.RegisterForm(automatedBackupsForm); + + var downloadPdf = CreateStreamableProcessable(completedAction, logMe); - (AutomatedBackupsForm automatedBackupsForm, LogMe logMe) = attachToBackupsForm(downloadPdf); await new BackupLoop(logMe, downloadPdf, automatedBackupsForm).RunBackupAsync(); } - private static DownloadPdf getWiredUpDownloadPdf(EventHandler completedAction) - { - var downloadPdf = new DownloadPdf(); - - downloadPdf.Begin += (_, __) => wireUpEvents(downloadPdf); - - if (completedAction != null) - downloadPdf.Completed += completedAction; - - return downloadPdf; - } - public static void DownloadFile(string url, string destination, bool showDownloadCompletedDialog = false) { - var downloadDialog = new DownloadForm(); - downloadDialog.UpdateFilename(destination); - downloadDialog.Show(); - new System.Threading.Thread(() => { - var downloadFile = new DownloadFile(); + (DownloadFile downloadFile, DownloadForm downloadForm) = CreateStreamable(); - downloadFile.DownloadProgressChanged += (_, progress) => downloadDialog.UIThread(() => - downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive) - ); - downloadFile.DownloadCompleted += (_, __) => downloadDialog.UIThread(() => - { - downloadDialog.Close(); - if (showDownloadCompletedDialog) - MessageBox.Show("File downloaded"); - }); + if (showDownloadCompletedDialog) + downloadFile.StreamingCompleted += (_, __) => MessageBox.Show("File downloaded"); downloadFile.PerformDownloadFileAsync(url, destination).GetAwaiter().GetResult(); }) @@ -209,171 +121,41 @@ namespace LibationWinForms.BookLiberation .Start(); } - // subscribed to Begin event because a new form should be created+processed+closed on each iteration - private static void wireUpEvents(IDownloadableProcessable downloadable) + /// + /// Create a new and which creates a new on IProcessable.Begin. + /// + /// The derrived type to create. + /// The derrived form to create on Begin + /// An additional event handler to handle .Completed + /// A new of type + private static TStrProc CreateStreamableProcessable(EventHandler completedAction = null, LogMe logMe = null) + where TForm : ProcessBaseForm, new() + where TStrProc : IStreamProcessable, new() { - #region create form - var downloadDialog = new DownloadForm(); - #endregion + var strProc = new TStrProc(); - // extra complexity for wiring up download form: - // case 1: download is needed - // dialog created. subscribe to events - // downloadable.DownloadBegin fires. shows dialog - // downloadable.DownloadCompleted fires. closes dialog. which fires FormClosing, FormClosed, Disposed - // Disposed unsubscribe from events - // case 2: download is not needed - // dialog created. subscribe to events - // dialog is never shown nor closed - // downloadable.Completed fires. disposes dialog and unsubscribes from events - - #region define how model actions will affect form behavior - void downloadBegin(object _, string str) + strProc.Begin += (sender, libraryBook) => { - downloadDialog.UpdateFilename(str); - downloadDialog.Show(); - } - - // close form on DOWNLOAD completed, not final Completed. Else for BackupBook this form won't close until DECRYPT is also complete - void fileDownloadCompleted(object _, string __) => downloadDialog.Close(); - - void downloadProgressChanged(object _, Dinah.Core.Net.Http.DownloadProgress progress) - => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive); - - void unsubscribe(object _ = null, EventArgs __ = null) - { - downloadable.DownloadBegin -= downloadBegin; - downloadable.DownloadCompleted -= fileDownloadCompleted; - downloadable.DownloadProgressChanged -= downloadProgressChanged; - downloadable.Completed -= dialogDispose; - } - - // unless we dispose, if the form is created but un-used/never-shown then weird UI stuff can happen - // also, since event unsubscribe occurs on FormClosing and an unused form is never closed, then the events will never be unsubscribed - void dialogDispose(object _, object __) - { - if (!downloadDialog.IsDisposed) - downloadDialog.Dispose(); - } - #endregion - - #region subscribe new form to model's events - downloadable.DownloadBegin += downloadBegin; - downloadable.DownloadCompleted += fileDownloadCompleted; - downloadable.DownloadProgressChanged += downloadProgressChanged; - downloadable.Completed += dialogDispose; - #endregion - - #region when form closes, unsubscribe from model's events - // unsubscribe so disposed forms aren't still trying to receive notifications - // FormClosing is more UI safe but won't fire unless the form is shown and closed - // if form was shown, Disposed will fire for FormClosing, FormClosed, and Disposed - // if not shown, it will still fire for Disposed - downloadDialog.Disposed += unsubscribe; - #endregion - } - - // subscribed to Begin event because a new form should be created+processed+closed on each iteration - private static void wireUpEvents(IDecryptable decryptBook, LibraryBook libraryBook, string actionName = "Decrypting") - { - #region create form - var decryptDialog = new DecryptForm(); - #endregion - - #region Set initially displayed book properties from library info. - decryptDialog.SetTitle(actionName, libraryBook.Book.Title); - decryptDialog.SetAuthorNames(string.Join(", ", libraryBook.Book.Authors)); - decryptDialog.SetNarratorNames(string.Join(", ", libraryBook.Book.NarratorNames)); - decryptDialog.SetCoverImage( - Dinah.Core.Drawing.ImageReader.ToImage( - FileManager.PictureStorage.GetPictureSynchronously( - new FileManager.PictureDefinition( - libraryBook.Book.PictureId, - FileManager.PictureSize._80x80)))); - #endregion - - #region define how model actions will affect form behavior - void decryptBegin(object _, string __) => decryptDialog.Show(); - void titleDiscovered(object _, string title) => decryptDialog.SetTitle(actionName, title); - void authorsDiscovered(object _, string authors) => decryptDialog.SetAuthorNames(authors); - void narratorsDiscovered(object _, string narrators) => decryptDialog.SetNarratorNames(narrators); - void coverImageFilepathDiscovered(object _, byte[] coverBytes) => decryptDialog.SetCoverImage(Dinah.Core.Drawing.ImageReader.ToImage(coverBytes)); - void updateProgress(object _, int percentage) => decryptDialog.UpdateProgress(percentage); - void updateRemainingTime(object _, TimeSpan remaining) => decryptDialog.UpdateRemainingTime(remaining); - void decryptCompleted(object _, string __) => decryptDialog.Close(); - void requestCoverArt(object _, Action setCoverArtDelegate) - => setCoverArtDelegate( - FileManager.PictureStorage.GetPictureSynchronously( - new FileManager.PictureDefinition( - libraryBook.Book.PictureId, - FileManager.PictureSize._500x500))); - #endregion - - #region subscribe new form to model's events - decryptBook.DecryptBegin += decryptBegin; - - decryptBook.TitleDiscovered += titleDiscovered; - decryptBook.AuthorsDiscovered += authorsDiscovered; - decryptBook.NarratorsDiscovered += narratorsDiscovered; - decryptBook.CoverImageFilepathDiscovered += coverImageFilepathDiscovered; - decryptBook.UpdateProgress += updateProgress; - decryptBook.UpdateRemainingTime += updateRemainingTime; - decryptBook.RequestCoverArt += requestCoverArt; - - decryptBook.DecryptCompleted += decryptCompleted; - #endregion - - #region when form closes, unsubscribe from model's events - // unsubscribe so disposed forms aren't still trying to receive notifications - decryptDialog.FormClosing += (_, __) => - { - decryptBook.DecryptBegin -= decryptBegin; - - decryptBook.TitleDiscovered -= titleDiscovered; - decryptBook.AuthorsDiscovered -= authorsDiscovered; - decryptBook.NarratorsDiscovered -= narratorsDiscovered; - decryptBook.CoverImageFilepathDiscovered -= coverImageFilepathDiscovered; - decryptBook.UpdateProgress -= updateProgress; - decryptBook.UpdateRemainingTime -= updateRemainingTime; - decryptBook.RequestCoverArt -= requestCoverArt; - - decryptBook.DecryptCompleted -= decryptCompleted; - decryptBook.Cancel(); + var processForm = new TForm(); + processForm.SetProcessable(strProc, logMe.Info); + processForm.OnBegin(sender, libraryBook); }; - #endregion + + if (completedAction != null) + strProc.Completed += completedAction; + + return strProc; } - - private static (AutomatedBackupsForm, LogMe) attachToBackupsForm(IDownloadableProcessable downloadable) + private static (TStrProc, TForm) CreateStreamable(EventHandler completedAction = null) + where TForm : StreamBaseForm, new() + where TStrProc : IStreamable, new() { - #region create form and logger - var automatedBackupsForm = new AutomatedBackupsForm(); - var logMe = LogMe.RegisterForm(automatedBackupsForm); - #endregion + var strProc = new TStrProc(); - #region define how model actions will affect form behavior - void begin(object _, LibraryBook libraryBook) => logMe.Info($"Begin: {libraryBook.Book}"); - void statusUpdate(object _, string str) => logMe.Info("- " + str); - // extra line after book is completely finished - void completed(object _, LibraryBook libraryBook) => logMe.Info($"Completed: {libraryBook.Book}{Environment.NewLine}"); - #endregion + var streamForm = new TForm(); + streamForm.SetStreamable(strProc); - #region subscribe new form to model's events - downloadable.Begin += begin; - downloadable.StatusUpdate += statusUpdate; - downloadable.Completed += completed; - #endregion - - #region when form closes, unsubscribe from model's events - // unsubscribe so disposed forms aren't still trying to receive notifications - automatedBackupsForm.FormClosing += (_, __) => - { - downloadable.Begin -= begin; - downloadable.StatusUpdate -= statusUpdate; - downloadable.Completed -= completed; - }; - #endregion - - return (automatedBackupsForm, logMe); + return (strProc, streamForm); } } diff --git a/LibationWinForms/BookLiberation/StreamBaseForm.cs b/LibationWinForms/BookLiberation/StreamBaseForm.cs new file mode 100644 index 00000000..f6907131 --- /dev/null +++ b/LibationWinForms/BookLiberation/StreamBaseForm.cs @@ -0,0 +1,52 @@ +using Dinah.Core.Net.Http; +using FileLiberator; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LibationWinForms.BookLiberation +{ + public class StreamBaseForm : Form + { + protected IStreamable Streamable { get; private set; } + public void SetStreamable(IStreamable streamable) + { + Streamable = streamable; + + if (Streamable is null) return; + + OnUnsubscribeAll(this, EventArgs.Empty); + + Streamable.StreamingBegin += OnStreamingBegin; + Streamable.StreamingCompleted += OnStreamingCompleted; + Streamable.StreamingProgressChanged += OnStreamingProgressChanged; + Streamable.StreamingTimeRemaining += OnStreamingTimeRemaining; + + Disposed += OnUnsubscribeAll; + } + + private void OnUnsubscribeAll(object sender, EventArgs e) + { + Disposed -= OnUnsubscribeAll; + + Streamable.StreamingBegin -= OnStreamingBegin; + Streamable.StreamingCompleted -= OnStreamingCompleted; + Streamable.StreamingProgressChanged -= OnStreamingProgressChanged; + Streamable.StreamingTimeRemaining -= OnStreamingTimeRemaining; + } + + #region IStreamable event handlers + public virtual void OnStreamingBegin(object sender, string beginString) => Show(); + public virtual void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) { } + public virtual void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) { } + public virtual void OnStreamingCompleted(object sender, string completedString) + { + Close(); + Dispose(); + } + #endregion + } +} diff --git a/LibationWinForms/Form1.Designer.cs b/LibationWinForms/Form1.Designer.cs index 3762f817..ad89b4ef 100644 --- a/LibationWinForms/Form1.Designer.cs +++ b/LibationWinForms/Form1.Designer.cs @@ -28,339 +28,351 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); - this.gridPanel = new System.Windows.Forms.Panel(); - this.filterHelpBtn = new System.Windows.Forms.Button(); - this.filterBtn = new System.Windows.Forms.Button(); - this.filterSearchTb = new System.Windows.Forms.TextBox(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.noAccountsYetAddAccountToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.scanLibraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.scanLibraryOfAllAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.scanLibraryOfSomeAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeLibraryBooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeAllAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.removeSomeAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.liberateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.beginBookBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.beginPdfBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.convertAllM4bToMp3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.exportLibraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.quickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.firstFilterIsDefaultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.editQuickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.visibleCountLbl = new System.Windows.Forms.ToolStripStatusLabel(); - this.springLbl = new System.Windows.Forms.ToolStripStatusLabel(); - this.backupsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel(); - this.pdfsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel(); - this.addFilterBtn = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // gridPanel - // - this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.gridPanel = new System.Windows.Forms.Panel(); + this.filterHelpBtn = new System.Windows.Forms.Button(); + this.filterBtn = new System.Windows.Forms.Button(); + this.filterSearchTb = new System.Windows.Forms.TextBox(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.noAccountsYetAddAccountToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.scanLibraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.scanLibraryOfAllAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.scanLibraryOfSomeAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeLibraryBooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeAllAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeSomeAccountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.liberateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.beginBookBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.beginPdfBackupsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.convertAllM4bToMp3ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportLibraryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.quickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.firstFilterIsDefaultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.editQuickFiltersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.accountsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.basicSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.visibleCountLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.springLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.backupsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.pdfsCountsLbl = new System.Windows.Forms.ToolStripStatusLabel(); + this.addFilterBtn = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // gridPanel + // + this.gridPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.gridPanel.Location = new System.Drawing.Point(14, 65); - this.gridPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.gridPanel.Name = "gridPanel"; - this.gridPanel.Size = new System.Drawing.Size(979, 445); - this.gridPanel.TabIndex = 5; - // - // filterHelpBtn - // - this.filterHelpBtn.Location = new System.Drawing.Point(14, 31); - this.filterHelpBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.filterHelpBtn.Name = "filterHelpBtn"; - this.filterHelpBtn.Size = new System.Drawing.Size(26, 27); - this.filterHelpBtn.TabIndex = 3; - this.filterHelpBtn.Text = "?"; - this.filterHelpBtn.UseVisualStyleBackColor = true; - this.filterHelpBtn.Click += new System.EventHandler(this.filterHelpBtn_Click); - // - // filterBtn - // - this.filterBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.filterBtn.Location = new System.Drawing.Point(905, 31); - this.filterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.filterBtn.Name = "filterBtn"; - this.filterBtn.Size = new System.Drawing.Size(88, 27); - this.filterBtn.TabIndex = 2; - this.filterBtn.Text = "Filter"; - this.filterBtn.UseVisualStyleBackColor = true; - this.filterBtn.Click += new System.EventHandler(this.filterBtn_Click); - // - // filterSearchTb - // - this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.gridPanel.Location = new System.Drawing.Point(14, 65); + this.gridPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.gridPanel.Name = "gridPanel"; + this.gridPanel.Size = new System.Drawing.Size(979, 445); + this.gridPanel.TabIndex = 5; + // + // filterHelpBtn + // + this.filterHelpBtn.Location = new System.Drawing.Point(14, 31); + this.filterHelpBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.filterHelpBtn.Name = "filterHelpBtn"; + this.filterHelpBtn.Size = new System.Drawing.Size(26, 27); + this.filterHelpBtn.TabIndex = 3; + this.filterHelpBtn.Text = "?"; + this.filterHelpBtn.UseVisualStyleBackColor = true; + this.filterHelpBtn.Click += new System.EventHandler(this.filterHelpBtn_Click); + // + // filterBtn + // + this.filterBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.filterBtn.Location = new System.Drawing.Point(905, 31); + this.filterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.filterBtn.Name = "filterBtn"; + this.filterBtn.Size = new System.Drawing.Size(88, 27); + this.filterBtn.TabIndex = 2; + this.filterBtn.Text = "Filter"; + this.filterBtn.UseVisualStyleBackColor = true; + this.filterBtn.Click += new System.EventHandler(this.filterBtn_Click); + // + // filterSearchTb + // + this.filterSearchTb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.filterSearchTb.Location = new System.Drawing.Point(217, 33); - this.filterSearchTb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.filterSearchTb.Name = "filterSearchTb"; - this.filterSearchTb.Size = new System.Drawing.Size(681, 23); - this.filterSearchTb.TabIndex = 1; - this.filterSearchTb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.filterSearchTb_KeyPress); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.filterSearchTb.Location = new System.Drawing.Point(217, 33); + this.filterSearchTb.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.filterSearchTb.Name = "filterSearchTb"; + this.filterSearchTb.Size = new System.Drawing.Size(681, 23); + this.filterSearchTb.TabIndex = 1; + this.filterSearchTb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.filterSearchTb_KeyPress); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.importToolStripMenuItem, this.liberateToolStripMenuItem, this.exportToolStripMenuItem, this.quickFiltersToolStripMenuItem, this.settingsToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); - this.menuStrip1.Size = new System.Drawing.Size(1007, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // importToolStripMenuItem - // - this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); + this.menuStrip1.Size = new System.Drawing.Size(1007, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // importToolStripMenuItem + // + this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.noAccountsYetAddAccountToolStripMenuItem, this.scanLibraryToolStripMenuItem, this.scanLibraryOfAllAccountsToolStripMenuItem, this.scanLibraryOfSomeAccountsToolStripMenuItem, this.removeLibraryBooksToolStripMenuItem}); - this.importToolStripMenuItem.Name = "importToolStripMenuItem"; - this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20); - this.importToolStripMenuItem.Text = "&Import"; - // - // noAccountsYetAddAccountToolStripMenuItem - // - this.noAccountsYetAddAccountToolStripMenuItem.Name = "noAccountsYetAddAccountToolStripMenuItem"; - this.noAccountsYetAddAccountToolStripMenuItem.Size = new System.Drawing.Size(247, 22); - this.noAccountsYetAddAccountToolStripMenuItem.Text = "No accounts yet. A&dd Account..."; - this.noAccountsYetAddAccountToolStripMenuItem.Click += new System.EventHandler(this.noAccountsYetAddAccountToolStripMenuItem_Click); - // - // scanLibraryToolStripMenuItem - // - this.scanLibraryToolStripMenuItem.Name = "scanLibraryToolStripMenuItem"; - this.scanLibraryToolStripMenuItem.Size = new System.Drawing.Size(247, 22); - this.scanLibraryToolStripMenuItem.Text = "Scan &Library"; - this.scanLibraryToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryToolStripMenuItem_Click); - // - // scanLibraryOfAllAccountsToolStripMenuItem - // - this.scanLibraryOfAllAccountsToolStripMenuItem.Name = "scanLibraryOfAllAccountsToolStripMenuItem"; - this.scanLibraryOfAllAccountsToolStripMenuItem.Size = new System.Drawing.Size(247, 22); - this.scanLibraryOfAllAccountsToolStripMenuItem.Text = "Scan Library of &All Accounts"; - this.scanLibraryOfAllAccountsToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryOfAllAccountsToolStripMenuItem_Click); - // - // scanLibraryOfSomeAccountsToolStripMenuItem - // - this.scanLibraryOfSomeAccountsToolStripMenuItem.Name = "scanLibraryOfSomeAccountsToolStripMenuItem"; - this.scanLibraryOfSomeAccountsToolStripMenuItem.Size = new System.Drawing.Size(247, 22); - this.scanLibraryOfSomeAccountsToolStripMenuItem.Text = "Scan Library of &Some Accounts..."; - this.scanLibraryOfSomeAccountsToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryOfSomeAccountsToolStripMenuItem_Click); - // - // removeLibraryBooksToolStripMenuItem - // - this.removeLibraryBooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.importToolStripMenuItem.Name = "importToolStripMenuItem"; + this.importToolStripMenuItem.Size = new System.Drawing.Size(55, 20); + this.importToolStripMenuItem.Text = "&Import"; + // + // noAccountsYetAddAccountToolStripMenuItem + // + this.noAccountsYetAddAccountToolStripMenuItem.Name = "noAccountsYetAddAccountToolStripMenuItem"; + this.noAccountsYetAddAccountToolStripMenuItem.Size = new System.Drawing.Size(247, 22); + this.noAccountsYetAddAccountToolStripMenuItem.Text = "No accounts yet. A&dd Account..."; + this.noAccountsYetAddAccountToolStripMenuItem.Click += new System.EventHandler(this.noAccountsYetAddAccountToolStripMenuItem_Click); + // + // scanLibraryToolStripMenuItem + // + this.scanLibraryToolStripMenuItem.Name = "scanLibraryToolStripMenuItem"; + this.scanLibraryToolStripMenuItem.Size = new System.Drawing.Size(247, 22); + this.scanLibraryToolStripMenuItem.Text = "Scan &Library"; + this.scanLibraryToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryToolStripMenuItem_Click); + // + // scanLibraryOfAllAccountsToolStripMenuItem + // + this.scanLibraryOfAllAccountsToolStripMenuItem.Name = "scanLibraryOfAllAccountsToolStripMenuItem"; + this.scanLibraryOfAllAccountsToolStripMenuItem.Size = new System.Drawing.Size(247, 22); + this.scanLibraryOfAllAccountsToolStripMenuItem.Text = "Scan Library of &All Accounts"; + this.scanLibraryOfAllAccountsToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryOfAllAccountsToolStripMenuItem_Click); + // + // scanLibraryOfSomeAccountsToolStripMenuItem + // + this.scanLibraryOfSomeAccountsToolStripMenuItem.Name = "scanLibraryOfSomeAccountsToolStripMenuItem"; + this.scanLibraryOfSomeAccountsToolStripMenuItem.Size = new System.Drawing.Size(247, 22); + this.scanLibraryOfSomeAccountsToolStripMenuItem.Text = "Scan Library of &Some Accounts..."; + this.scanLibraryOfSomeAccountsToolStripMenuItem.Click += new System.EventHandler(this.scanLibraryOfSomeAccountsToolStripMenuItem_Click); + // + // removeLibraryBooksToolStripMenuItem + // + this.removeLibraryBooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.removeAllAccountsToolStripMenuItem, this.removeSomeAccountsToolStripMenuItem}); - this.removeLibraryBooksToolStripMenuItem.Name = "removeLibraryBooksToolStripMenuItem"; - this.removeLibraryBooksToolStripMenuItem.Size = new System.Drawing.Size(247, 22); - this.removeLibraryBooksToolStripMenuItem.Text = "Remove Library Books"; - // - // removeAllAccountsToolStripMenuItem - // - this.removeAllAccountsToolStripMenuItem.Name = "removeAllAccountsToolStripMenuItem"; - this.removeAllAccountsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.removeAllAccountsToolStripMenuItem.Text = "All Accounts"; - this.removeAllAccountsToolStripMenuItem.Click += new System.EventHandler(this.removeAllAccountsToolStripMenuItem_Click); - // - // removeSomeAccountsToolStripMenuItem - // - this.removeSomeAccountsToolStripMenuItem.Name = "removeSomeAccountsToolStripMenuItem"; - this.removeSomeAccountsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.removeSomeAccountsToolStripMenuItem.Text = "Some Accounts"; - this.removeSomeAccountsToolStripMenuItem.Click += new System.EventHandler(this.removeSomeAccountsToolStripMenuItem_Click); - // - // liberateToolStripMenuItem - // - this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.removeLibraryBooksToolStripMenuItem.Name = "removeLibraryBooksToolStripMenuItem"; + this.removeLibraryBooksToolStripMenuItem.Size = new System.Drawing.Size(247, 22); + this.removeLibraryBooksToolStripMenuItem.Text = "Remove Library Books"; + // + // removeAllAccountsToolStripMenuItem + // + this.removeAllAccountsToolStripMenuItem.Name = "removeAllAccountsToolStripMenuItem"; + this.removeAllAccountsToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.removeAllAccountsToolStripMenuItem.Text = "All Accounts"; + this.removeAllAccountsToolStripMenuItem.Click += new System.EventHandler(this.removeAllAccountsToolStripMenuItem_Click); + // + // removeSomeAccountsToolStripMenuItem + // + this.removeSomeAccountsToolStripMenuItem.Name = "removeSomeAccountsToolStripMenuItem"; + this.removeSomeAccountsToolStripMenuItem.Size = new System.Drawing.Size(157, 22); + this.removeSomeAccountsToolStripMenuItem.Text = "Some Accounts"; + this.removeSomeAccountsToolStripMenuItem.Click += new System.EventHandler(this.removeSomeAccountsToolStripMenuItem_Click); + // + // liberateToolStripMenuItem + // + this.liberateToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.beginBookBackupsToolStripMenuItem, this.beginPdfBackupsToolStripMenuItem, this.convertAllM4bToMp3ToolStripMenuItem}); - this.liberateToolStripMenuItem.Name = "liberateToolStripMenuItem"; - this.liberateToolStripMenuItem.Size = new System.Drawing.Size(61, 20); - this.liberateToolStripMenuItem.Text = "&Liberate"; - // - // beginBookBackupsToolStripMenuItem - // - this.beginBookBackupsToolStripMenuItem.Name = "beginBookBackupsToolStripMenuItem"; - this.beginBookBackupsToolStripMenuItem.Size = new System.Drawing.Size(284, 22); - this.beginBookBackupsToolStripMenuItem.Text = "Begin &Book and PDF Backups: {0}"; - this.beginBookBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginBookBackupsToolStripMenuItem_Click); - // - // beginPdfBackupsToolStripMenuItem - // - this.beginPdfBackupsToolStripMenuItem.Name = "beginPdfBackupsToolStripMenuItem"; - this.beginPdfBackupsToolStripMenuItem.Size = new System.Drawing.Size(284, 22); - this.beginPdfBackupsToolStripMenuItem.Text = "Begin &PDF Only Backups: {0}"; - this.beginPdfBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginPdfBackupsToolStripMenuItem_Click); - // - // convertAllM4bToMp3ToolStripMenuItem - // - this.convertAllM4bToMp3ToolStripMenuItem.Name = "convertAllM4bToMp3ToolStripMenuItem"; - this.convertAllM4bToMp3ToolStripMenuItem.Size = new System.Drawing.Size(284, 22); - this.convertAllM4bToMp3ToolStripMenuItem.Text = "Convert all M4b to Mp3 [Long-running]"; - this.convertAllM4bToMp3ToolStripMenuItem.Visible = false; - this.convertAllM4bToMp3ToolStripMenuItem.Click += new System.EventHandler(this.convertAllM4bToMp3ToolStripMenuItem_Click); - // - // exportToolStripMenuItem - // - this.exportToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.liberateToolStripMenuItem.Name = "liberateToolStripMenuItem"; + this.liberateToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.liberateToolStripMenuItem.Text = "&Liberate"; + // + // beginBookBackupsToolStripMenuItem + // + this.beginBookBackupsToolStripMenuItem.Name = "beginBookBackupsToolStripMenuItem"; + this.beginBookBackupsToolStripMenuItem.Size = new System.Drawing.Size(284, 22); + this.beginBookBackupsToolStripMenuItem.Text = "Begin &Book and PDF Backups: {0}"; + this.beginBookBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginBookBackupsToolStripMenuItem_Click); + // + // beginPdfBackupsToolStripMenuItem + // + this.beginPdfBackupsToolStripMenuItem.Name = "beginPdfBackupsToolStripMenuItem"; + this.beginPdfBackupsToolStripMenuItem.Size = new System.Drawing.Size(284, 22); + this.beginPdfBackupsToolStripMenuItem.Text = "Begin &PDF Only Backups: {0}"; + this.beginPdfBackupsToolStripMenuItem.Click += new System.EventHandler(this.beginPdfBackupsToolStripMenuItem_Click); + // + // convertAllM4bToMp3ToolStripMenuItem + // + this.convertAllM4bToMp3ToolStripMenuItem.Name = "convertAllM4bToMp3ToolStripMenuItem"; + this.convertAllM4bToMp3ToolStripMenuItem.Size = new System.Drawing.Size(284, 22); + this.convertAllM4bToMp3ToolStripMenuItem.Text = "Convert all M4b to Mp3 [Long-running]"; + this.convertAllM4bToMp3ToolStripMenuItem.Visible = false; + this.convertAllM4bToMp3ToolStripMenuItem.Click += new System.EventHandler(this.convertAllM4bToMp3ToolStripMenuItem_Click); + // + // exportToolStripMenuItem + // + this.exportToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exportLibraryToolStripMenuItem}); - this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; - this.exportToolStripMenuItem.Size = new System.Drawing.Size(53, 20); - this.exportToolStripMenuItem.Text = "E&xport"; - // - // exportLibraryToolStripMenuItem - // - this.exportLibraryToolStripMenuItem.Name = "exportLibraryToolStripMenuItem"; - this.exportLibraryToolStripMenuItem.Size = new System.Drawing.Size(156, 22); - this.exportLibraryToolStripMenuItem.Text = "E&xport Library..."; - this.exportLibraryToolStripMenuItem.Click += new System.EventHandler(this.exportLibraryToolStripMenuItem_Click); - // - // quickFiltersToolStripMenuItem - // - this.quickFiltersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; + this.exportToolStripMenuItem.Size = new System.Drawing.Size(53, 20); + this.exportToolStripMenuItem.Text = "E&xport"; + // + // exportLibraryToolStripMenuItem + // + this.exportLibraryToolStripMenuItem.Name = "exportLibraryToolStripMenuItem"; + this.exportLibraryToolStripMenuItem.Size = new System.Drawing.Size(156, 22); + this.exportLibraryToolStripMenuItem.Text = "E&xport Library..."; + this.exportLibraryToolStripMenuItem.Click += new System.EventHandler(this.exportLibraryToolStripMenuItem_Click); + // + // quickFiltersToolStripMenuItem + // + this.quickFiltersToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.firstFilterIsDefaultToolStripMenuItem, this.editQuickFiltersToolStripMenuItem, this.toolStripSeparator1}); - this.quickFiltersToolStripMenuItem.Name = "quickFiltersToolStripMenuItem"; - this.quickFiltersToolStripMenuItem.Size = new System.Drawing.Size(84, 20); - this.quickFiltersToolStripMenuItem.Text = "Quick &Filters"; - // - // firstFilterIsDefaultToolStripMenuItem - // - this.firstFilterIsDefaultToolStripMenuItem.Name = "firstFilterIsDefaultToolStripMenuItem"; - this.firstFilterIsDefaultToolStripMenuItem.Size = new System.Drawing.Size(256, 22); - this.firstFilterIsDefaultToolStripMenuItem.Text = "Start Libation with 1st filter &Default"; - this.firstFilterIsDefaultToolStripMenuItem.Click += new System.EventHandler(this.FirstFilterIsDefaultToolStripMenuItem_Click); - // - // editQuickFiltersToolStripMenuItem - // - this.editQuickFiltersToolStripMenuItem.Name = "editQuickFiltersToolStripMenuItem"; - this.editQuickFiltersToolStripMenuItem.Size = new System.Drawing.Size(256, 22); - this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters..."; - this.editQuickFiltersToolStripMenuItem.Click += new System.EventHandler(this.EditQuickFiltersToolStripMenuItem_Click); - // - // toolStripSeparator1 - // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(253, 6); - // - // settingsToolStripMenuItem - // - this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.quickFiltersToolStripMenuItem.Name = "quickFiltersToolStripMenuItem"; + this.quickFiltersToolStripMenuItem.Size = new System.Drawing.Size(84, 20); + this.quickFiltersToolStripMenuItem.Text = "Quick &Filters"; + // + // firstFilterIsDefaultToolStripMenuItem + // + this.firstFilterIsDefaultToolStripMenuItem.Name = "firstFilterIsDefaultToolStripMenuItem"; + this.firstFilterIsDefaultToolStripMenuItem.Size = new System.Drawing.Size(256, 22); + this.firstFilterIsDefaultToolStripMenuItem.Text = "Start Libation with 1st filter &Default"; + this.firstFilterIsDefaultToolStripMenuItem.Click += new System.EventHandler(this.FirstFilterIsDefaultToolStripMenuItem_Click); + // + // editQuickFiltersToolStripMenuItem + // + this.editQuickFiltersToolStripMenuItem.Name = "editQuickFiltersToolStripMenuItem"; + this.editQuickFiltersToolStripMenuItem.Size = new System.Drawing.Size(256, 22); + this.editQuickFiltersToolStripMenuItem.Text = "&Edit quick filters..."; + this.editQuickFiltersToolStripMenuItem.Click += new System.EventHandler(this.EditQuickFiltersToolStripMenuItem_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(253, 6); + // + // settingsToolStripMenuItem + // + this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.accountsToolStripMenuItem, this.basicSettingsToolStripMenuItem}); - this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; - this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); - this.settingsToolStripMenuItem.Text = "&Settings"; - // - // accountsToolStripMenuItem - // - this.accountsToolStripMenuItem.Name = "accountsToolStripMenuItem"; - this.accountsToolStripMenuItem.Size = new System.Drawing.Size(133, 22); - this.accountsToolStripMenuItem.Text = "&Accounts..."; - this.accountsToolStripMenuItem.Click += new System.EventHandler(this.accountsToolStripMenuItem_Click); - // - // basicSettingsToolStripMenuItem - // - this.basicSettingsToolStripMenuItem.Name = "basicSettingsToolStripMenuItem"; - this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(133, 22); - this.basicSettingsToolStripMenuItem.Text = "&Settings..."; - this.basicSettingsToolStripMenuItem.Click += new System.EventHandler(this.basicSettingsToolStripMenuItem_Click); - // - // statusStrip1 - // - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.settingsToolStripMenuItem.Text = "&Settings"; + // + // accountsToolStripMenuItem + // + this.accountsToolStripMenuItem.Name = "accountsToolStripMenuItem"; + this.accountsToolStripMenuItem.Size = new System.Drawing.Size(133, 22); + this.accountsToolStripMenuItem.Text = "&Accounts..."; + this.accountsToolStripMenuItem.Click += new System.EventHandler(this.accountsToolStripMenuItem_Click); + // + // basicSettingsToolStripMenuItem + // + this.basicSettingsToolStripMenuItem.Name = "basicSettingsToolStripMenuItem"; + this.basicSettingsToolStripMenuItem.Size = new System.Drawing.Size(133, 22); + this.basicSettingsToolStripMenuItem.Text = "&Settings..."; + this.basicSettingsToolStripMenuItem.Click += new System.EventHandler(this.basicSettingsToolStripMenuItem_Click); + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.visibleCountLbl, this.springLbl, this.backupsCountsLbl, this.pdfsCountsLbl}); - this.statusStrip1.Location = new System.Drawing.Point(0, 517); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); - this.statusStrip1.Size = new System.Drawing.Size(1007, 22); - this.statusStrip1.TabIndex = 6; - this.statusStrip1.Text = "statusStrip1"; - // - // visibleCountLbl - // - this.visibleCountLbl.Name = "visibleCountLbl"; - this.visibleCountLbl.Size = new System.Drawing.Size(61, 17); - this.visibleCountLbl.Text = "Visible: {0}"; - // - // springLbl - // - this.springLbl.Name = "springLbl"; - this.springLbl.Size = new System.Drawing.Size(375, 17); - this.springLbl.Spring = true; - // - // backupsCountsLbl - // - this.backupsCountsLbl.Name = "backupsCountsLbl"; - this.backupsCountsLbl.Size = new System.Drawing.Size(336, 17); - this.backupsCountsLbl.Text = "BACKUPS: No progress: {0} Encrypted: {1} Fully backed up: {2}"; - // - // pdfsCountsLbl - // - this.pdfsCountsLbl.Name = "pdfsCountsLbl"; - this.pdfsCountsLbl.Size = new System.Drawing.Size(218, 17); - this.pdfsCountsLbl.Text = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}"; - // - // addFilterBtn - // - this.addFilterBtn.Location = new System.Drawing.Point(47, 31); - this.addFilterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.addFilterBtn.Name = "addFilterBtn"; - this.addFilterBtn.Size = new System.Drawing.Size(163, 27); - this.addFilterBtn.TabIndex = 4; - this.addFilterBtn.Text = "Add To Quick Filters"; - this.addFilterBtn.UseVisualStyleBackColor = true; - this.addFilterBtn.Click += new System.EventHandler(this.AddFilterBtn_Click); - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1007, 539); - this.Controls.Add(this.filterBtn); - this.Controls.Add(this.addFilterBtn); - this.Controls.Add(this.filterSearchTb); - this.Controls.Add(this.filterHelpBtn); - this.Controls.Add(this.statusStrip1); - this.Controls.Add(this.gridPanel); - this.Controls.Add(this.menuStrip1); - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MainMenuStrip = this.menuStrip1; - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.Name = "Form1"; - this.Text = "Libation: Liberate your Library"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); - this.Load += new System.EventHandler(this.Form1_Load); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); + this.statusStrip1.Location = new System.Drawing.Point(0, 517); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); + this.statusStrip1.Size = new System.Drawing.Size(1007, 22); + this.statusStrip1.TabIndex = 6; + this.statusStrip1.Text = "statusStrip1"; + // + // visibleCountLbl + // + this.visibleCountLbl.Name = "visibleCountLbl"; + this.visibleCountLbl.Size = new System.Drawing.Size(61, 17); + this.visibleCountLbl.Text = "Visible: {0}"; + // + // springLbl + // + this.springLbl.Name = "springLbl"; + this.springLbl.Size = new System.Drawing.Size(375, 17); + this.springLbl.Spring = true; + // + // backupsCountsLbl + // + this.backupsCountsLbl.Name = "backupsCountsLbl"; + this.backupsCountsLbl.Size = new System.Drawing.Size(336, 17); + this.backupsCountsLbl.Text = "BACKUPS: No progress: {0} Encrypted: {1} Fully backed up: {2}"; + // + // pdfsCountsLbl + // + this.pdfsCountsLbl.Name = "pdfsCountsLbl"; + this.pdfsCountsLbl.Size = new System.Drawing.Size(218, 17); + this.pdfsCountsLbl.Text = "| PDFs: NOT d/l\'ed: {0} Downloaded: {1}"; + // + // addFilterBtn + // + this.addFilterBtn.Location = new System.Drawing.Point(47, 31); + this.addFilterBtn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.addFilterBtn.Name = "addFilterBtn"; + this.addFilterBtn.Size = new System.Drawing.Size(163, 27); + this.addFilterBtn.TabIndex = 4; + this.addFilterBtn.Text = "Add To Quick Filters"; + this.addFilterBtn.UseVisualStyleBackColor = true; + this.addFilterBtn.Click += new System.EventHandler(this.AddFilterBtn_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(648, 0); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(123, 70); + this.button1.TabIndex = 0; + this.button1.Text = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1007, 539); + this.Controls.Add(this.button1); + this.Controls.Add(this.filterBtn); + this.Controls.Add(this.addFilterBtn); + this.Controls.Add(this.filterSearchTb); + this.Controls.Add(this.filterHelpBtn); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.gridPanel); + this.Controls.Add(this.menuStrip1); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "Form1"; + this.Text = "Libation: Liberate your Library"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -398,5 +410,6 @@ private System.Windows.Forms.ToolStripMenuItem removeLibraryBooksToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem removeAllAccountsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem removeSomeAccountsToolStripMenuItem; - } + private System.Windows.Forms.Button button1; + } } diff --git a/LibationWinForms/Form1.cs b/LibationWinForms/Form1.cs index 6f9223d3..e9e0c350 100644 --- a/LibationWinForms/Form1.cs +++ b/LibationWinForms/Form1.cs @@ -63,6 +63,7 @@ namespace LibationWinForms // also applies filter. ONLY call AFTER loading grid loadInitialQuickFilterState(); + } private void Form1_FormClosing(object sender, FormClosingEventArgs e) @@ -494,5 +495,13 @@ namespace LibationWinForms private void basicSettingsToolStripMenuItem_Click(object sender, EventArgs e) => new SettingsDialog().ShowDialog(); #endregion + + private void button1_Click(object sender, EventArgs e) + { + + BookLiberation.ProcessorAutomationController.DownloadFile( + "https://github.com/rmcrackan/Libation/releases/download/v5.4.9/Libation.5.4.9.zip", + @"C:\Users\mbuca\Downloads\libation test dl.zip"); + } } } diff --git a/LibationWinForms/Form1.resx b/LibationWinForms/Form1.resx index 0f6fc673..64da6d15 100644 --- a/LibationWinForms/Form1.resx +++ b/LibationWinForms/Form1.resx @@ -1,5 +1,4 @@ - - +