From dd8b0783a9328c1fbf2c714911e88d9b0e4fa143 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 10 May 2022 20:43:07 -0600 Subject: [PATCH] Address comments --- Source/FileLiberator/DownloadDecryptBook.cs | 4 +-- Source/LibationWinForms/grid/ImageDisplay.cs | 26 +++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index bea2e358..0717ddc4 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -295,7 +295,7 @@ namespace FileLiberator (libraryBook.Book.PictureLarge, PictureSize.Native); var picBytes = PictureStorage.GetPictureSynchronously(new PictureDefinition(picId, size)); - + if (picBytes.Length > 0) File.WriteAllBytes(coverPath, picBytes); } @@ -303,7 +303,7 @@ namespace FileLiberator { //Failure to download cover art should not be //considered a failure to download the book - Serilog.Log.Logger.Error(ex.Message); + Serilog.Log.Logger.Error(ex, $"Error downloading cover art of {libraryBook.Book.AudibleProductId} to {coverPath} catalog product."); } } diff --git a/Source/LibationWinForms/grid/ImageDisplay.cs b/Source/LibationWinForms/grid/ImageDisplay.cs index 09fa2481..53f75987 100644 --- a/Source/LibationWinForms/grid/ImageDisplay.cs +++ b/Source/LibationWinForms/grid/ImageDisplay.cs @@ -13,10 +13,18 @@ namespace LibationWinForms public string BookSaveDirectory { get; set; } public byte[] CoverPicture { get => _coverBytes; set => pictureBox1.Image = Dinah.Core.Drawing.ImageReader.ToImage(_coverBytes = value); } - - private byte[] _coverBytes; + + public ImageDisplay() + { + InitializeComponent(); + lastWidth = Width; + lastHeight = Height; + } + + #region Make the form's aspect ratio always match the picture's aspect ratio. + private bool detectedResizeDirection = false; private bool resizingWidth = false; private bool resizingHeight = false; @@ -27,14 +35,6 @@ namespace LibationWinForms private int formExtraHeight; private double pictureAR = 1; - - public ImageDisplay() - { - InitializeComponent(); - lastWidth = Width; - lastHeight = Height; - } - protected override void OnResizeBegin(EventArgs e) { detectedResizeDirection = false; @@ -87,6 +87,8 @@ namespace LibationWinForms return (int)((height - formExtraHeight) * pictureAR) + formExtraWidth; } + #endregion + private void ImageDisplay_Shown(object sender, EventArgs e) { formExtraWidth = Width - pictureBox1.Width; @@ -110,8 +112,8 @@ namespace LibationWinForms } catch (Exception ex) { - Serilog.Log.Logger.Error(ex.Message); - MessageBox.Show(this, $"An error was encountered while trying to save the picture\r\n\r\n{ex.Message}", "Sailed to save picture", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); + Serilog.Log.Logger.Error(ex, $"Failed to save picture to {saveFileDialog.FileName}"); + MessageBox.Show(this, $"An error was encountered while trying to save the picture\r\n\r\n{ex.Message}", "Failed to save picture", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }