Typos and formatting

This commit is contained in:
Michael Bucari-Tovo 2023-01-07 18:41:34 -07:00
parent cab8555ab5
commit 3a48479435
7 changed files with 92 additions and 93 deletions

View File

@ -357,7 +357,7 @@ namespace AppScaffolding
public static UpgradeProperties GetLatestRelease() public static UpgradeProperties GetLatestRelease()
{ {
// timed out // 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) if (latest is null || zip is null)
return null; return null;

View File

@ -3,32 +3,32 @@ using System.Text.RegularExpressions;
namespace AppScaffolding namespace AppScaffolding
{ {
public record UpgradeProperties public record UpgradeProperties
{ {
private static readonly Regex linkstripper = new Regex(@"\[(.*)\]\(.*\)"); private static readonly Regex linkstripper = new Regex(@"\[(.*)\]\(.*\)");
public string ZipUrl { get; } public string ZipUrl { get; }
public string HtmlUrl { get; } public string HtmlUrl { get; }
public string ZipName { get; } public string ZipName { get; }
public Version LatestRelease { get; } public Version LatestRelease { get; }
public string Notes { get; } public string Notes { get; }
public UpgradeProperties(string zipUrl, string htmlUrl, string zipName, Version latestRelease, string notes) public UpgradeProperties(string zipUrl, string htmlUrl, string zipName, Version latestRelease, string notes)
{ {
ZipName = zipName; ZipName = zipName;
HtmlUrl = htmlUrl; HtmlUrl = htmlUrl;
ZipUrl = zipUrl; ZipUrl = zipUrl;
LatestRelease = latestRelease; LatestRelease = latestRelease;
Notes = stripMarkdownLinks(notes); Notes = stripMarkdownLinks(notes);
} }
private string stripMarkdownLinks(string body) private string stripMarkdownLinks(string body)
{ {
body = body.Replace(@"\", ""); body = body.Replace(@"\", "");
var matches = linkstripper.Matches(body); var matches = linkstripper.Matches(body);
foreach (Match match in matches) foreach (Match match in matches)
body = body.Replace(match.Groups[0].Value, match.Groups[1].Value); body = body.Replace(match.Groups[0].Value, match.Groups[1].Value);
return body; return body;
} }
} }
} }

View File

@ -11,80 +11,81 @@ using ApplicationServices;
namespace FileLiberator namespace FileLiberator
{ {
public class DownloadOptions : IDownloadOptions, IDisposable public class DownloadOptions : IDownloadOptions, IDisposable
{ {
public event EventHandler<long> DownloadSpeedChanged; public event EventHandler<long> DownloadSpeedChanged;
public LibraryBook LibraryBook { get; } public LibraryBook LibraryBook { get; }
public LibraryBookDto LibraryBookDto { get; } public LibraryBookDto LibraryBookDto { get; }
public string DownloadUrl { get; } public string DownloadUrl { get; }
public string UserAgent { get; } public string UserAgent { get; }
public string AudibleKey { get; init; } public string AudibleKey { get; init; }
public string AudibleIV { get; init; } public string AudibleIV { get; init; }
public AaxDecrypter.OutputFormat OutputFormat { get; init; } public AaxDecrypter.OutputFormat OutputFormat { get; init; }
public bool TrimOutputToChapterLength { get; init; } public bool TrimOutputToChapterLength { get; init; }
public bool RetainEncryptedFile { get; init; } public bool RetainEncryptedFile { get; init; }
public bool StripUnabridged { get; init; } public bool StripUnabridged { get; init; }
public bool CreateCueSheet { get; init; } public bool CreateCueSheet { get; init; }
public bool DownloadClipsBookmarks { get; init; } public bool DownloadClipsBookmarks { get; init; }
public long DownloadSpeedBps { get; init; } public long DownloadSpeedBps { get; init; }
public ChapterInfo ChapterInfo { get; init; } public ChapterInfo ChapterInfo { get; init; }
public bool FixupFile { get; init; } public bool FixupFile { get; init; }
public NAudio.Lame.LameConfig LameConfig { get; init; } public NAudio.Lame.LameConfig LameConfig { get; init; }
public bool Downsample { get; init; } public bool Downsample { get; init; }
public bool MatchSourceBitrate { get; init; } public bool MatchSourceBitrate { get; init; }
public ReplacementCharacters ReplacementCharacters => Configuration.Instance.ReplacementCharacters; public ReplacementCharacters ReplacementCharacters => Configuration.Instance.ReplacementCharacters;
public string GetMultipartFileName(MultiConvertFileProperties props) public string GetMultipartFileName(MultiConvertFileProperties props)
=> Templates.ChapterFile.GetFilename(LibraryBookDto, props); => Templates.ChapterFile.GetFilename(LibraryBookDto, props);
public string GetMultipartTitleName(MultiConvertFileProperties props) public string GetMultipartTitleName(MultiConvertFileProperties props)
=> Templates.ChapterTitle.GetTitle(LibraryBookDto, props); => Templates.ChapterTitle.GetTitle(LibraryBookDto, props);
public async Task<string> SaveClipsAndBookmarks(string fileName) public async Task<string> SaveClipsAndBookmarks(string fileName)
{ {
if (DownloadClipsBookmarks) if (DownloadClipsBookmarks)
{ {
var format = Configuration.Instance.ClipsBookmarksFileFormat; var format = Configuration.Instance.ClipsBookmarksFileFormat;
var formatExtension = format.ToString().ToLowerInvariant(); var formatExtension = format.ToString().ToLowerInvariant();
var filePath = Path.ChangeExtension(fileName, formatExtension); var filePath = Path.ChangeExtension(fileName, formatExtension);
var api = await LibraryBook.GetApiAsync(); var api = await LibraryBook.GetApiAsync();
var records = await api.GetRecordsAsync(LibraryBook.Book.AudibleProductId); var records = await api.GetRecordsAsync(LibraryBook.Book.AudibleProductId);
switch(format) switch(format)
{ {
case Configuration.ClipBookmarkFormat.CSV: case Configuration.ClipBookmarkFormat.CSV:
RecordExporter.ToCsv(filePath, records); RecordExporter.ToCsv(filePath, records);
break; break;
case Configuration.ClipBookmarkFormat.Xlsx: case Configuration.ClipBookmarkFormat.Xlsx:
RecordExporter.ToXlsx(filePath, records); RecordExporter.ToXlsx(filePath, records);
break; break;
case Configuration.ClipBookmarkFormat.Json: case Configuration.ClipBookmarkFormat.Json:
RecordExporter.ToJson(filePath, LibraryBook, records); RecordExporter.ToJson(filePath, LibraryBook, records);
break; break;
} }
return filePath; return filePath;
} }
return string.Empty; return string.Empty;
} }
private readonly IDisposable cancellation; private readonly IDisposable cancellation;
public void Dispose() => cancellation?.Dispose(); public void Dispose() => cancellation?.Dispose();
public DownloadOptions(LibraryBook libraryBook, string downloadUrl, string userAgent) public DownloadOptions(LibraryBook libraryBook, string downloadUrl, string userAgent)
{ {
LibraryBook = ArgumentValidator.EnsureNotNull(libraryBook, nameof(libraryBook)); LibraryBook = ArgumentValidator.EnsureNotNull(libraryBook, nameof(libraryBook));
DownloadUrl = ArgumentValidator.EnsureNotNullOrEmpty(downloadUrl, nameof(downloadUrl)); DownloadUrl = ArgumentValidator.EnsureNotNullOrEmpty(downloadUrl, nameof(downloadUrl));
UserAgent = ArgumentValidator.EnsureNotNullOrEmpty(userAgent, nameof(userAgent)); UserAgent = ArgumentValidator.EnsureNotNullOrEmpty(userAgent, nameof(userAgent));
// no null/empty check for key/iv. unencrypted files do not have them // no null/empty check for key/iv. unencrypted files do not have them
LibraryBookDto = LibraryBook.ToDto(); LibraryBookDto = LibraryBook.ToDto();
cancellation = Configuration.Instance cancellation =
.ObservePropertyChanged<long>( Configuration.Instance
nameof(Configuration.DownloadSpeedLimit), .ObservePropertyChanged<long>(
newVal => DownloadSpeedChanged?.Invoke(this, newVal)); nameof(Configuration.DownloadSpeedLimit),
newVal => DownloadSpeedChanged?.Invoke(this, newVal));
} }
} }
} }

View File

@ -46,28 +46,28 @@ namespace FileManager
return stringCache[propertyName]; return stringCache[propertyName];
} }
public T GetNonString<T>(string propertyName) public T GetNonString<T>(string propertyName)
{ {
var obj = GetObject(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.GetType().IsAssignableTo(typeof(T))) return (T)obj;
if (obj is JObject jObject) return jObject.ToObject<T>(); if (obj is JObject jObject) return jObject.ToObject<T>();
if (obj is JValue jValue) if (obj is JValue jValue)
{ {
if (jValue.Type == JTokenType.String && typeof(T).IsAssignableTo(typeof(Enum))) if (jValue.Type == JTokenType.String && typeof(T).IsAssignableTo(typeof(Enum)))
{ {
return return
Enum.TryParse(typeof(T), jValue.Value<string>(), out var enumVal) Enum.TryParse(typeof(T), jValue.Value<string>(), out var enumVal)
? (T)enumVal ? (T)enumVal
: Enum.GetValues(typeof(T)).Cast<T>().First(); : Enum.GetValues(typeof(T)).Cast<T>().First();
} }
return jValue.Value<T>(); return jValue.Value<T>();
} }
throw new InvalidCastException($"{obj.GetType()} is not convertible to {typeof(T)}"); 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)) if (!objectCache.ContainsKey(propertyName))
{ {

View File

@ -5,7 +5,6 @@ using Dinah.Core;
using LibationFileManager; using LibationFileManager;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
namespace LibationAvalonia.Views namespace LibationAvalonia.Views
@ -14,7 +13,6 @@ namespace LibationAvalonia.Views
public partial class MainWindow public partial class MainWindow
{ {
private InterruptableTimer autoScanTimer; private InterruptableTimer autoScanTimer;
private IDisposable cancellation;
private void Configure_ScanAuto() private void Configure_ScanAuto()
{ {

View File

@ -36,7 +36,7 @@ namespace LibationFileManager
} }
set set
{ {
OnPropertyChanging(nameof(LogLevel), LogLevel, value); OnPropertyChanging(nameof(LogLevel), LogLevel, value);
var valueWasChanged = persistentDictionary.SetWithJsonPath("Serilog", "MinimumLevel", value.ToString()); var valueWasChanged = persistentDictionary.SetWithJsonPath("Serilog", "MinimumLevel", value.ToString());
if (!valueWasChanged) if (!valueWasChanged)
{ {
@ -46,9 +46,9 @@ namespace LibationFileManager
configuration.Reload(); 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_Verbose_Enabled = Log.Logger.IsVerboseEnabled(),
LogLevel_Debug_Enabled = Log.Logger.IsDebugEnabled(), LogLevel_Debug_Enabled = Log.Logger.IsDebugEnabled(),

View File

@ -7,7 +7,7 @@ namespace LibationFileManager
/* /*
* Use this type in the getter for any Dictionary<TKey, TValue> settings, * Use this type in the getter for any Dictionary<TKey, TValue> settings,
* and be sure to clone it before returning. This allows Configuration to * 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<TKey, TValue> : Dictionary<TKey, TValue> private class EquatableDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{ {