From 3a48479435603169aa1d72586906ef68c1112766 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Sat, 7 Jan 2023 18:41:34 -0700 Subject: [PATCH] Typos and formatting --- Source/AppScaffolding/LibationScaffolding.cs | 2 +- Source/AppScaffolding/UpgradeProperties.cs | 34 +++--- Source/FileLiberator/DownloadOptions.cs | 103 +++++++++--------- Source/FileManager/PersistentDictionary.cs | 36 +++--- .../Views/MainWindow.ScanAuto.cs | 2 - .../Configuration.Logging.cs | 6 +- .../Configuration.PropertyChange.cs | 2 +- 7 files changed, 92 insertions(+), 93 deletions(-) diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs index 84ec6fe4..629fbfce 100644 --- a/Source/AppScaffolding/LibationScaffolding.cs +++ b/Source/AppScaffolding/LibationScaffolding.cs @@ -357,7 +357,7 @@ namespace AppScaffolding public static UpgradeProperties GetLatestRelease() { // timed out - (var latest, var zip) = getLatestRelease(TimeSpan.FromSeconds(10000)); + (var latest, var zip) = getLatestRelease(TimeSpan.FromSeconds(10)); if (latest is null || zip is null) return null; diff --git a/Source/AppScaffolding/UpgradeProperties.cs b/Source/AppScaffolding/UpgradeProperties.cs index d3a040f2..506255b2 100644 --- a/Source/AppScaffolding/UpgradeProperties.cs +++ b/Source/AppScaffolding/UpgradeProperties.cs @@ -3,32 +3,32 @@ using System.Text.RegularExpressions; namespace AppScaffolding { - public record UpgradeProperties - { - private static readonly Regex linkstripper = new Regex(@"\[(.*)\]\(.*\)"); + public record UpgradeProperties + { + private static readonly Regex linkstripper = new Regex(@"\[(.*)\]\(.*\)"); public string ZipUrl { get; } - public string HtmlUrl { get; } - public string ZipName { get; } - public Version LatestRelease { get; } + public string HtmlUrl { get; } + public string ZipName { get; } + public Version LatestRelease { get; } public string Notes { get; } - public UpgradeProperties(string zipUrl, string htmlUrl, string zipName, Version latestRelease, string notes) - { - ZipName = zipName; - HtmlUrl = htmlUrl; - ZipUrl = zipUrl; - LatestRelease = latestRelease; - Notes = stripMarkdownLinks(notes); - } - private string stripMarkdownLinks(string body) - { + public UpgradeProperties(string zipUrl, string htmlUrl, string zipName, Version latestRelease, string notes) + { + ZipName = zipName; + HtmlUrl = htmlUrl; + ZipUrl = zipUrl; + LatestRelease = latestRelease; + Notes = stripMarkdownLinks(notes); + } + private string stripMarkdownLinks(string body) + { body = body.Replace(@"\", ""); var matches = linkstripper.Matches(body); foreach (Match match in matches) body = body.Replace(match.Groups[0].Value, match.Groups[1].Value); - return body; + return body; } } } diff --git a/Source/FileLiberator/DownloadOptions.cs b/Source/FileLiberator/DownloadOptions.cs index 98bdbb33..7520ed15 100644 --- a/Source/FileLiberator/DownloadOptions.cs +++ b/Source/FileLiberator/DownloadOptions.cs @@ -11,80 +11,81 @@ using ApplicationServices; namespace FileLiberator { - public class DownloadOptions : IDownloadOptions, IDisposable - { - public event EventHandler DownloadSpeedChanged; + public class DownloadOptions : IDownloadOptions, IDisposable + { + public event EventHandler DownloadSpeedChanged; public LibraryBook LibraryBook { get; } - public LibraryBookDto LibraryBookDto { get; } - public string DownloadUrl { get; } - public string UserAgent { get; } - public string AudibleKey { get; init; } - public string AudibleIV { get; init; } - public AaxDecrypter.OutputFormat OutputFormat { get; init; } - public bool TrimOutputToChapterLength { get; init; } - public bool RetainEncryptedFile { get; init; } - public bool StripUnabridged { get; init; } - public bool CreateCueSheet { get; init; } - public bool DownloadClipsBookmarks { get; init; } - public long DownloadSpeedBps { get; init; } + public LibraryBookDto LibraryBookDto { get; } + public string DownloadUrl { get; } + public string UserAgent { get; } + public string AudibleKey { get; init; } + public string AudibleIV { get; init; } + public AaxDecrypter.OutputFormat OutputFormat { get; init; } + public bool TrimOutputToChapterLength { get; init; } + public bool RetainEncryptedFile { get; init; } + public bool StripUnabridged { get; init; } + public bool CreateCueSheet { get; init; } + public bool DownloadClipsBookmarks { get; init; } + public long DownloadSpeedBps { get; init; } public ChapterInfo ChapterInfo { get; init; } - public bool FixupFile { get; init; } - public NAudio.Lame.LameConfig LameConfig { get; init; } - public bool Downsample { get; init; } - public bool MatchSourceBitrate { get; init; } - public ReplacementCharacters ReplacementCharacters => Configuration.Instance.ReplacementCharacters; + public bool FixupFile { get; init; } + public NAudio.Lame.LameConfig LameConfig { get; init; } + public bool Downsample { get; init; } + public bool MatchSourceBitrate { get; init; } + public ReplacementCharacters ReplacementCharacters => Configuration.Instance.ReplacementCharacters; - public string GetMultipartFileName(MultiConvertFileProperties props) - => Templates.ChapterFile.GetFilename(LibraryBookDto, props); + public string GetMultipartFileName(MultiConvertFileProperties props) + => Templates.ChapterFile.GetFilename(LibraryBookDto, props); - public string GetMultipartTitleName(MultiConvertFileProperties props) - => Templates.ChapterTitle.GetTitle(LibraryBookDto, props); + public string GetMultipartTitleName(MultiConvertFileProperties props) + => Templates.ChapterTitle.GetTitle(LibraryBookDto, props); - public async Task SaveClipsAndBookmarks(string fileName) - { - if (DownloadClipsBookmarks) - { - var format = Configuration.Instance.ClipsBookmarksFileFormat; + public async Task SaveClipsAndBookmarks(string fileName) + { + if (DownloadClipsBookmarks) + { + var format = Configuration.Instance.ClipsBookmarksFileFormat; var formatExtension = format.ToString().ToLowerInvariant(); - var filePath = Path.ChangeExtension(fileName, formatExtension); + var filePath = Path.ChangeExtension(fileName, formatExtension); - var api = await LibraryBook.GetApiAsync(); - var records = await api.GetRecordsAsync(LibraryBook.Book.AudibleProductId); + var api = await LibraryBook.GetApiAsync(); + var records = await api.GetRecordsAsync(LibraryBook.Book.AudibleProductId); - switch(format) - { - case Configuration.ClipBookmarkFormat.CSV: - RecordExporter.ToCsv(filePath, records); - break; - case Configuration.ClipBookmarkFormat.Xlsx: + switch(format) + { + case Configuration.ClipBookmarkFormat.CSV: + RecordExporter.ToCsv(filePath, records); + break; + case Configuration.ClipBookmarkFormat.Xlsx: RecordExporter.ToXlsx(filePath, records); break; - case Configuration.ClipBookmarkFormat.Json: + case Configuration.ClipBookmarkFormat.Json: RecordExporter.ToJson(filePath, LibraryBook, records); break; } - return filePath; - } - return string.Empty; - } + return filePath; + } + return string.Empty; + } private readonly IDisposable cancellation; public void Dispose() => cancellation?.Dispose(); public DownloadOptions(LibraryBook libraryBook, string downloadUrl, string userAgent) { - LibraryBook = ArgumentValidator.EnsureNotNull(libraryBook, nameof(libraryBook)); - DownloadUrl = ArgumentValidator.EnsureNotNullOrEmpty(downloadUrl, nameof(downloadUrl)); - UserAgent = ArgumentValidator.EnsureNotNullOrEmpty(userAgent, nameof(userAgent)); - // no null/empty check for key/iv. unencrypted files do not have them + LibraryBook = ArgumentValidator.EnsureNotNull(libraryBook, nameof(libraryBook)); + DownloadUrl = ArgumentValidator.EnsureNotNullOrEmpty(downloadUrl, nameof(downloadUrl)); + UserAgent = ArgumentValidator.EnsureNotNullOrEmpty(userAgent, nameof(userAgent)); + // no null/empty check for key/iv. unencrypted files do not have them LibraryBookDto = LibraryBook.ToDto(); - cancellation = Configuration.Instance - .ObservePropertyChanged( - nameof(Configuration.DownloadSpeedLimit), - newVal => DownloadSpeedChanged?.Invoke(this, newVal)); + cancellation = + Configuration.Instance + .ObservePropertyChanged( + nameof(Configuration.DownloadSpeedLimit), + newVal => DownloadSpeedChanged?.Invoke(this, newVal)); } } } diff --git a/Source/FileManager/PersistentDictionary.cs b/Source/FileManager/PersistentDictionary.cs index 8e8ee518..315bcd36 100644 --- a/Source/FileManager/PersistentDictionary.cs +++ b/Source/FileManager/PersistentDictionary.cs @@ -46,28 +46,28 @@ namespace FileManager return stringCache[propertyName]; } - public T GetNonString(string propertyName) - { - var obj = GetObject(propertyName); + public T GetNonString(string propertyName) + { + var obj = GetObject(propertyName); - if (obj is null) return default; + if (obj is null) return default; if (obj.GetType().IsAssignableTo(typeof(T))) return (T)obj; - if (obj is JObject jObject) return jObject.ToObject(); - if (obj is JValue jValue) - { - if (jValue.Type == JTokenType.String && typeof(T).IsAssignableTo(typeof(Enum))) - { - return - Enum.TryParse(typeof(T), jValue.Value(), out var enumVal) - ? (T)enumVal - : Enum.GetValues(typeof(T)).Cast().First(); - } - return jValue.Value(); - } + if (obj is JObject jObject) return jObject.ToObject(); + if (obj is JValue jValue) + { + if (jValue.Type == JTokenType.String && typeof(T).IsAssignableTo(typeof(Enum))) + { + return + Enum.TryParse(typeof(T), jValue.Value(), out var enumVal) + ? (T)enumVal + : Enum.GetValues(typeof(T)).Cast().First(); + } + return jValue.Value(); + } throw new InvalidCastException($"{obj.GetType()} is not convertible to {typeof(T)}"); - } + } - public object GetObject(string propertyName) + public object GetObject(string propertyName) { if (!objectCache.ContainsKey(propertyName)) { diff --git a/Source/LibationAvalonia/Views/MainWindow.ScanAuto.cs b/Source/LibationAvalonia/Views/MainWindow.ScanAuto.cs index cf3f5bba..422872e4 100644 --- a/Source/LibationAvalonia/Views/MainWindow.ScanAuto.cs +++ b/Source/LibationAvalonia/Views/MainWindow.ScanAuto.cs @@ -5,7 +5,6 @@ using Dinah.Core; using LibationFileManager; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; namespace LibationAvalonia.Views @@ -14,7 +13,6 @@ namespace LibationAvalonia.Views public partial class MainWindow { private InterruptableTimer autoScanTimer; - private IDisposable cancellation; private void Configure_ScanAuto() { diff --git a/Source/LibationFileManager/Configuration.Logging.cs b/Source/LibationFileManager/Configuration.Logging.cs index f5f9037d..3a7dcee4 100644 --- a/Source/LibationFileManager/Configuration.Logging.cs +++ b/Source/LibationFileManager/Configuration.Logging.cs @@ -36,7 +36,7 @@ namespace LibationFileManager } set { - OnPropertyChanging(nameof(LogLevel), LogLevel, value); + OnPropertyChanging(nameof(LogLevel), LogLevel, value); var valueWasChanged = persistentDictionary.SetWithJsonPath("Serilog", "MinimumLevel", value.ToString()); if (!valueWasChanged) { @@ -46,9 +46,9 @@ namespace LibationFileManager configuration.Reload(); - OnPropertyChanged(nameof(LogLevel), value); + OnPropertyChanged(nameof(LogLevel), value); - Log.Logger.Information("Updated LogLevel MinimumLevel. {@DebugInfo}", new + Log.Logger.Information("Updated LogLevel MinimumLevel. {@DebugInfo}", new { LogLevel_Verbose_Enabled = Log.Logger.IsVerboseEnabled(), LogLevel_Debug_Enabled = Log.Logger.IsDebugEnabled(), diff --git a/Source/LibationFileManager/Configuration.PropertyChange.cs b/Source/LibationFileManager/Configuration.PropertyChange.cs index ff47f0c9..f384fa3f 100644 --- a/Source/LibationFileManager/Configuration.PropertyChange.cs +++ b/Source/LibationFileManager/Configuration.PropertyChange.cs @@ -7,7 +7,7 @@ namespace LibationFileManager /* * Use this type in the getter for any Dictionary settings, * and be sure to clone it before returning. This allows Configuration to - * accurately detect if an of the Dictionary's elements have changed. + * accurately detect if any of the Dictionary's elements have changed. */ private class EquatableDictionary : Dictionary {