From 8098564926c8f1f4376363cba020c2bc43011e94 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Wed, 6 Oct 2021 08:23:07 -0600 Subject: [PATCH] Better naming. --- AppScaffolding/AppScaffolding.csproj | 2 +- FileLiberator/DownloadDecryptBook.cs | 25 ++++++++-------- .../TruncatedDataGridViewTextBoxColumn.cs | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 LibationWinForms/TruncatedDataGridViewTextBoxColumn.cs diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index afc57dae..4413fc22 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net5.0 - 6.2.1.0 + 6.2.1.6 diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 86178c68..85e03bb8 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -14,7 +14,7 @@ namespace FileLiberator { public class DownloadDecryptBook : AudioDecodable { - private AudiobookDownloadBase aaxcDownloader; + private AudiobookDownloadBase abDownloader; public override async Task ProcessAsync(LibraryBook libraryBook) { @@ -84,18 +84,19 @@ namespace FileLiberator var outFileName = Path.Combine(destinationDir, $"{PathLib.ToPathSafeString(libraryBook.Book.Title)} [{libraryBook.Book.AudibleProductId}].{outputFormat.ToString().ToLower()}"); - aaxcDownloader = contentLic.DrmType == AudibleApi.Common.DrmType.Adrm - ? new AaxcDownloadConverter(outFileName, cacheDir, audiobookDlLic, outputFormat, Configuration.Instance.SplitFilesByChapter) { AppName = "Libation" } + abDownloader = contentLic.DrmType == AudibleApi.Common.DrmType.Adrm + ? new AaxcDownloadConverter(outFileName, cacheDir, audiobookDlLic, outputFormat, Configuration.Instance.SplitFilesByChapter) : new UnencryptedAudiobookDownloader(outFileName, cacheDir, audiobookDlLic); - aaxcDownloader.DecryptProgressUpdate += (s, progress) => OnStreamingProgressChanged(progress); - aaxcDownloader.DecryptTimeRemaining += (s, remaining) => OnStreamingTimeRemaining(remaining); - aaxcDownloader.RetrievedTitle += (s, title) => OnTitleDiscovered(title); - aaxcDownloader.RetrievedAuthors += (s, authors) => OnAuthorsDiscovered(authors); - aaxcDownloader.RetrievedNarrators += (s, narrators) => OnNarratorsDiscovered(narrators); - aaxcDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; + abDownloader.AppName = "Libation"; + abDownloader.DecryptProgressUpdate += (s, progress) => OnStreamingProgressChanged(progress); + abDownloader.DecryptTimeRemaining += (s, remaining) => OnStreamingTimeRemaining(remaining); + abDownloader.RetrievedTitle += (s, title) => OnTitleDiscovered(title); + abDownloader.RetrievedAuthors += (s, authors) => OnAuthorsDiscovered(authors); + abDownloader.RetrievedNarrators += (s, narrators) => OnNarratorsDiscovered(narrators); + abDownloader.RetrievedCoverArt += AaxcDownloader_RetrievedCoverArt; // REAL WORK DONE HERE - var success = await Task.Run(() => aaxcDownloader.Run()); + var success = await Task.Run(abDownloader.Run); // decrypt failed if (!success) @@ -113,7 +114,7 @@ namespace FileLiberator { if (e is null && Configuration.Instance.AllowLibationFixup) { - OnRequestCoverArt(aaxcDownloader.SetCoverArt); + OnRequestCoverArt(abDownloader.SetCoverArt); } if (e is not null) @@ -204,7 +205,7 @@ namespace FileLiberator public override void Cancel() { - aaxcDownloader?.Cancel(); + abDownloader?.Cancel(); } } } diff --git a/LibationWinForms/TruncatedDataGridViewTextBoxColumn.cs b/LibationWinForms/TruncatedDataGridViewTextBoxColumn.cs new file mode 100644 index 00000000..a462e6e9 --- /dev/null +++ b/LibationWinForms/TruncatedDataGridViewTextBoxColumn.cs @@ -0,0 +1,29 @@ +using System.ComponentModel; +using System.Windows.Forms; + +namespace LibationWinForms +{ + public class TruncatedDataGridViewTextBoxColumn : DataGridViewTextBoxColumn + { + public TruncatedDataGridViewTextBoxColumn() + { + CellTemplate = new TruncatedDataGridViewTextBoxCell(); + } + } + + internal class TruncatedDataGridViewTextBoxCell : DataGridViewTextBoxCell + { + private const int MAX_DISPLAY_CHARS = 63; + private string truncatedString; + + protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) + { + if (value is null || value is not string valueStr) + return value; + + truncatedString ??= valueStr.Length < MAX_DISPLAY_CHARS ? valueStr : valueStr.Substring(0, MAX_DISPLAY_CHARS - 1) + "…"; + + return truncatedString; + } + } +}