diff --git a/AaxDecrypter/AaxcDownloadConverter.cs b/AaxDecrypter/AaxcDownloadConverter.cs index 72e1a4e2..cd3d8ff1 100644 --- a/AaxDecrypter/AaxcDownloadConverter.cs +++ b/AaxDecrypter/AaxcDownloadConverter.cs @@ -30,9 +30,9 @@ namespace AaxDecrypter bool Step1_CreateDir(); bool Step2_GetMetadata(); bool Step3_DownloadAndCombine(); - bool Step5_CreateCue(); - bool Step6_CreateNfo(); - bool Step7_Cleanup(); + bool Step4_CreateCue(); + bool Step5_CreateNfo(); + bool Step6_Cleanup(); } public class AaxcDownloadConverter : IAdvancedAaxcToM4bConverter { @@ -81,9 +81,9 @@ namespace AaxDecrypter ["Step 1: Create Dir"] = Step1_CreateDir, ["Step 2: Get Aaxc Metadata"] = Step2_GetMetadata, ["Step 3: Download Decrypted Audiobook"] = Step3_DownloadAndCombine, - ["Step 5: Create Cue"] = Step5_CreateCue, - ["Step 6: Create Nfo"] = Step6_CreateNfo, - ["Step 7: Cleanup"] = Step7_Cleanup, + ["Step 4: Create Cue"] = Step4_CreateCue, + ["Step 5: Create Nfo"] = Step5_CreateNfo, + ["Step 6: Cleanup"] = Step6_Cleanup, }; downloadLicense = dlLic; @@ -216,7 +216,7 @@ namespace AaxDecrypter DecryptProgressUpdate?.Invoke(this, (int)progressPercent); } - public bool Step5_CreateCue() + public bool Step4_CreateCue() { try { @@ -224,12 +224,12 @@ namespace AaxDecrypter } catch (Exception ex) { - Serilog.Log.Logger.Error(ex, $"{nameof(Step5_CreateCue)}. FAILED"); + Serilog.Log.Logger.Error(ex, $"{nameof(Step4_CreateCue)}. FAILED"); } return !isCanceled; } - public bool Step6_CreateNfo() + public bool Step5_CreateNfo() { try { @@ -237,12 +237,12 @@ namespace AaxDecrypter } catch (Exception ex) { - Serilog.Log.Logger.Error(ex, $"{nameof(Step6_CreateNfo)}. FAILED"); + Serilog.Log.Logger.Error(ex, $"{nameof(Step5_CreateNfo)}. FAILED"); } return !isCanceled; } - public bool Step7_Cleanup() + public bool Step6_Cleanup() { FileExt.SafeDelete(jsonDownloadState); FileExt.SafeDelete(tempFile); diff --git a/ApplicationServices/LibraryCommands.cs b/ApplicationServices/LibraryCommands.cs index 3ec19cc7..cc233231 100644 --- a/ApplicationServices/LibraryCommands.cs +++ b/ApplicationServices/LibraryCommands.cs @@ -35,7 +35,7 @@ namespace ApplicationServices } catch (AudibleApi.Authentication.LoginFailedException lfEx) { - lfEx.MoveResponseBodyFile(FileManager.Configuration.Instance.LibationFiles); + lfEx.SaveFiles(FileManager.Configuration.Instance.LibationFiles); // nuget Serilog.Exceptions would automatically log custom properties // However, it comes with a scary warning when used with EntityFrameworkCore which I'm not yet ready to implement: @@ -46,7 +46,7 @@ namespace ApplicationServices ResponseStatusCodeNumber = (int)lfEx.ResponseStatusCode, ResponseStatusCodeDesc = lfEx.ResponseStatusCode, lfEx.ResponseInputFields, - lfEx.ResponseBodyFilePath + lfEx.ResponseBodyFilePaths }); throw; } diff --git a/FileManager/PersistentDictionary.cs b/FileManager/PersistentDictionary.cs index 540fb94a..f828a35d 100644 --- a/FileManager/PersistentDictionary.cs +++ b/FileManager/PersistentDictionary.cs @@ -100,8 +100,13 @@ namespace FileManager lock (locker) { var jObject = readFile(); + var startContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); + jObject[propertyName] = newValue; - File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); + var endContents = JsonConvert.SerializeObject(jObject, Formatting.Indented); + + if (startContents != endContents) + File.WriteAllText(Filepath, endContents); } } @@ -112,10 +117,13 @@ namespace FileManager { var jObject = readFile(); var token = jObject.SelectToken(jsonPath); - var debug_oldValue = (string)token[propertyName]; + var oldValue = (string)token[propertyName]; - token[propertyName] = newValue; - File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); + if (oldValue != newValue) + { + token[propertyName] = newValue; + File.WriteAllText(Filepath, JsonConvert.SerializeObject(jObject, Formatting.Indented)); + } } } diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 21f7a1fa..7bd0fd03 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 5.1.8.2 + 5.1.9.1 diff --git a/LibationLauncher/Program.cs b/LibationLauncher/Program.cs index ec540a24..d41c1396 100644 --- a/LibationLauncher/Program.cs +++ b/LibationLauncher/Program.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Windows.Forms; using AudibleApi; using AudibleApi.Authorization; +using Dinah.Core.Logging; using FileManager; using InternalUtilities; using LibationWinForms; @@ -12,6 +13,7 @@ using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Serilog; +using Serilog.Events; namespace LibationLauncher { @@ -31,7 +33,6 @@ namespace LibationLauncher migrate_to_v4_0_0(); migrate_to_v5_0_0(); - ensureLoggingConfig(); ensureSerilogConfig(); configureLogging(); checkForUpdate(); @@ -155,7 +156,7 @@ namespace LibationLauncher // identity has likely been updated above. re-get contents var legacyContents = File.ReadAllText(AccountsSettingsFileLegacy30); - var identity = AudibleApi.Authorization.Identity.FromJson(legacyContents); + var identity = Identity.FromJson(legacyContents); if (!identity.IsValid) return null; @@ -257,42 +258,13 @@ namespace LibationLauncher } #endregion - private static string defaultLoggingLevel { get; } = "Information"; - private static void ensureLoggingConfig() - { - var config = Configuration.Instance; - - if (config.GetObject("Logging") != null) - return; - - // "Logging": { - // "LogLevel": { - // "Default": "Debug" - // } - // } - var loggingObj = new JObject - { - { - "LogLevel", new JObject { { "Default", defaultLoggingLevel } } - } - }; - config.SetObject("Logging", loggingObj); - } - - private static void ensureSerilogConfig() + private static void ensureSerilogConfig() { var config = Configuration.Instance; if (config.GetObject("Serilog") != null) return; - // default. for reference. output example: - // 2019-11-26 08:48:40.224 -05:00 [DBG] Begin Libation - var default_outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"; - // with class and method info. output example: - // 2019-11-26 08:48:40.224 -05:00 [DBG] (at LibationWinForms.Program.init()) Begin Libation - var code_outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] (at {Caller}) {Message:lj}{NewLine}{Exception}"; - // "Serilog": { // "MinimumLevel": "Information" // "WriteTo": [ @@ -312,7 +284,7 @@ namespace LibationLauncher // } var serilogObj = new JObject { - { "MinimumLevel", defaultLoggingLevel }, + { "MinimumLevel", "Information" }, { "WriteTo", new JArray { new JObject { {"Name", "Console" } }, @@ -325,7 +297,12 @@ namespace LibationLauncher // for this sink to work, a path must be provided. we override this below { "path", Path.Combine(Configuration.Instance.LibationFiles, "_Log.log") }, { "rollingInterval", "Month" }, - { "outputTemplate", code_outputTemplate } + // Serilog template formatting examples + // - default: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}" + // output example: 2019-11-26 08:48:40.224 -05:00 [DBG] Begin Libation + // - with class and method info: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] (at {Caller}) {Message:lj}{NewLine}{Exception}"; + // output example: 2019-11-26 08:48:40.224 -05:00 [DBG] (at LibationWinForms.Program.init()) Begin Libation + { "outputTemplate", "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] (at {Caller}) {Message:lj}{NewLine}{Exception}" } } } } @@ -439,12 +416,12 @@ namespace LibationLauncher { Version = BuildVersion.ToString(), - LogLevel_Verbose_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Verbose), - LogLevel_Debug_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Debug), - LogLevel_Information_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Information), - LogLevel_Warning_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Warning), - LogLevel_Error_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Error), - LogLevel_Fatal_Enabled = Serilog.Log.Logger.IsEnabled(Serilog.Events.LogEventLevel.Fatal), + LogLevel_Verbose_Enabled = Log.Logger.IsVerboseEnabled(), + LogLevel_Debug_Enabled = Log.Logger.IsDebugEnabled(), + LogLevel_Information_Enabled = Log.Logger.IsInformationEnabled(), + LogLevel_Warning_Enabled = Log.Logger.IsWarningEnabled(), + LogLevel_Error_Enabled = Log.Logger.IsErrorEnabled(), + LogLevel_Fatal_Enabled = Log.Logger.IsFatalEnabled(), config.LibationFiles, AudibleFileStorage.BooksDirectory, @@ -460,6 +437,20 @@ namespace LibationLauncher DecryptInProgressDir = AudibleFileStorage.DecryptInProgress, DecryptInProgressFiles = Directory.EnumerateFiles(AudibleFileStorage.DecryptInProgress).Count(), }); + + // when turning on debug (and especially Verbose) to share logs, some privacy settings may not be obscured + if (Log.Logger.IsVerboseEnabled()) + MessageBox.Show(@" +Warning: verbose logging is enabled. + +This should be used for debugging only. It creates many +more logs and debug files, neither of which are as +strictly anonomous. + +When you are finished debugging, it's highly recommended +to set your debug MinimumLevel to Information and restart +Libation. +".Trim(), "Verbose logging enabled", MessageBoxButtons.OK, MessageBoxIcon.Warning); } private static Version BuildVersion => System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;