diff --git a/FileManager/PictureStorage.cs b/FileManager/PictureStorage.cs index 4ea1bcf2..64e3ccfa 100644 --- a/FileManager/PictureStorage.cs +++ b/FileManager/PictureStorage.cs @@ -7,6 +7,11 @@ using System.Net.Http; namespace FileManager { public enum PictureSize { _80x80 = 80, _300x300 = 300, _500x500 = 500 } + public class PictureCachedEventArgs : EventArgs + { + public PictureDefinition Definition { get; internal set; } + public byte[] Picture { get; internal set; } + } public struct PictureDefinition { public string PictureId { get; } @@ -38,7 +43,7 @@ namespace FileManager timer.Elapsed += (_, __) => timerDownload(); } - public static event EventHandler PictureCached; + public static event EventHandler PictureCached; private static Dictionary cache { get; } = new Dictionary(); public static (bool isDefault, byte[] bytes) GetPicture(PictureDefinition def) @@ -109,7 +114,7 @@ namespace FileManager saveFile(def, bytes); cache[def] = bytes; - PictureCached?.Invoke(nameof(PictureStorage), def.PictureId); + PictureCached?.Invoke(nameof(PictureStorage), new PictureCachedEventArgs { Definition = def, Picture = bytes }); } finally { diff --git a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs index c8c5ced0..16462100 100644 --- a/LibationWinForms/BookLiberation/ProcessorAutomationController.cs +++ b/LibationWinForms/BookLiberation/ProcessorAutomationController.cs @@ -285,10 +285,11 @@ namespace LibationWinForms.BookLiberation decryptDialog.SetAuthorNames(string.Join(", ", libraryBook.Book.Authors)); decryptDialog.SetNarratorNames(string.Join(", ", libraryBook.Book.NarratorNames)); decryptDialog.SetCoverImage( - WindowsDesktopUtilities.WinAudibleImageServer.GetImage( - libraryBook.Book.PictureId, - FileManager.PictureSize._80x80 - )); + 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 @@ -300,7 +301,12 @@ namespace LibationWinForms.BookLiberation 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))); + 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 diff --git a/LibationWinForms/GridEntry.cs b/LibationWinForms/GridEntry.cs index ae04e870..b173051a 100644 --- a/LibationWinForms/GridEntry.cs +++ b/LibationWinForms/GridEntry.cs @@ -28,18 +28,18 @@ namespace LibationWinForms public GridEntry(LibraryBook libraryBook) { LibraryBook = libraryBook; - _memberValues = CreateMemberValueDictionary(); //Get cover art. If it's default, subscribe to PictureCached - var picDef = new FileManager.PictureDefinition(Book.PictureId, FileManager.PictureSize._80x80); - (bool isDefault, byte[] picture) = FileManager.PictureStorage.GetPicture(picDef); + { + (bool isDefault, byte[] picture) = FileManager.PictureStorage.GetPicture(new FileManager.PictureDefinition(Book.PictureId, FileManager.PictureSize._80x80)); - if (isDefault) - FileManager.PictureStorage.PictureCached += PictureStorage_PictureCached; + if (isDefault) + FileManager.PictureStorage.PictureCached += PictureStorage_PictureCached; - //Mutable property. Set the field so PropertyChanged isn't fired. - _cover = ImageReader.ToImage(picture); + //Mutable property. Set the field so PropertyChanged isn't fired. + _cover = ImageReader.ToImage(picture); + } //Immutable properties { @@ -59,11 +59,11 @@ namespace LibationWinForms //DisplayTags and Liberate properties are live. } - private void PictureStorage_PictureCached(object sender, string pictureId) + private void PictureStorage_PictureCached(object sender, FileManager.PictureCachedEventArgs e) { - if (pictureId == Book.PictureId) + if (e.Definition.PictureId == Book.PictureId) { - Cover = WindowsDesktopUtilities.WinAudibleImageServer.GetImage(pictureId, FileManager.PictureSize._80x80); + Cover = ImageReader.ToImage(e.Picture); FileManager.PictureStorage.PictureCached -= PictureStorage_PictureCached; } }