From 2e5360f0bae90337934e249135b3e1f24a24d9b3 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 21 Aug 2020 11:50:11 -0400 Subject: [PATCH] Libation 4.0 prep: purge global static config Configuration.LocaleCountryCode --- .../UNTESTED/LibraryCommands.cs | 18 ++++++--- FileManager/UNTESTED/Configuration.cs | 6 --- LibationLauncher/LibationLauncher.csproj | 2 +- LibationLauncher/UNTESTED/Program.cs | 22 +++++------ .../Dialogs/SettingsDialog.Designer.cs | 38 ++----------------- .../UNTESTED/Dialogs/SettingsDialog.cs | 22 +---------- .../Dialogs/SettingsDialog.Designer.cs | 38 ++----------------- 7 files changed, 32 insertions(+), 114 deletions(-) diff --git a/ApplicationServices/UNTESTED/LibraryCommands.cs b/ApplicationServices/UNTESTED/LibraryCommands.cs index 96817369..c2c8d562 100644 --- a/ApplicationServices/UNTESTED/LibraryCommands.cs +++ b/ApplicationServices/UNTESTED/LibraryCommands.cs @@ -4,6 +4,7 @@ using AudibleApi; using DataLayer; using DtoImporterService; using InternalUtilities; +using Serilog; namespace ApplicationServices { @@ -15,24 +16,31 @@ namespace ApplicationServices { var account = AudibleApiStorage.TEST_GetFirstAccount(); + Log.Logger.Information("ImportLibraryAsync. {@DebugInfo}", new + { + account.AccountName, + account.AccountId, + LocaleName = account.Locale.Name, + }); + var items = await AudibleApiActions.GetAllLibraryItemsAsync(account, callback); var totalCount = items.Count; - Serilog.Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); + Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); using var context = DbContexts.GetContext(); var libraryImporter = new LibraryImporter(context, account); var newCount = await Task.Run(() => libraryImporter.Import(items)); context.SaveChanges(); - Serilog.Log.Logger.Information($"Import: New count {newCount}"); + Log.Logger.Information($"Import: New count {newCount}"); await Task.Run(() => SearchEngineCommands.FullReIndex()); - Serilog.Log.Logger.Information("FullReIndex: success"); + Log.Logger.Information("FullReIndex: success"); return (totalCount, newCount); } catch (Exception ex) { - Serilog.Log.Logger.Error(ex, "Error importing library"); + Log.Logger.Error(ex, "Error importing library"); throw; } } @@ -52,7 +60,7 @@ namespace ApplicationServices } catch (Exception ex) { - Serilog.Log.Logger.Error(ex, "Error updating tags"); + Log.Logger.Error(ex, "Error updating tags"); throw; } } diff --git a/FileManager/UNTESTED/Configuration.cs b/FileManager/UNTESTED/Configuration.cs index aa179724..e92fc4fd 100644 --- a/FileManager/UNTESTED/Configuration.cs +++ b/FileManager/UNTESTED/Configuration.cs @@ -90,12 +90,6 @@ namespace FileManager set => persistentDictionary.Set(nameof(DecryptInProgressEnum), value); } - public string LocaleCountryCode - { - get => persistentDictionary.GetString(nameof(LocaleCountryCode)); - set => persistentDictionary.Set(nameof(LocaleCountryCode), value); - } - // note: any potential file manager static ctors can't compensate if storage dir is changed at run time via settings. this is partly bad architecture. but the side effect is desirable. if changing LibationFiles location: restart app // singleton stuff diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 901e37cb..ce209911 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.186 + 3.1.12.194 diff --git a/LibationLauncher/UNTESTED/Program.cs b/LibationLauncher/UNTESTED/Program.cs index a373810d..666c908d 100644 --- a/LibationLauncher/UNTESTED/Program.cs +++ b/LibationLauncher/UNTESTED/Program.cs @@ -42,7 +42,6 @@ namespace LibationLauncher { static bool configSetupIsComplete(Configuration config) => config.FilesExist - && !string.IsNullOrWhiteSpace(config.LocaleCountryCode) && !string.IsNullOrWhiteSpace(config.DownloadsInProgressEnum) && !string.IsNullOrWhiteSpace(config.DecryptInProgressEnum); @@ -56,7 +55,6 @@ namespace LibationLauncher setupDialog.NoQuestionsBtn_Click += (_, __) => { config.DecryptKey ??= ""; - config.LocaleCountryCode ??= "us"; config.DownloadsInProgressEnum ??= "WinTemp"; config.DecryptInProgressEnum ??= "WinTemp"; config.Books ??= Configuration.AppDir; @@ -142,7 +140,7 @@ namespace LibationLauncher var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var jObj = JObject.Parse(settingsContents); var jLocale = jObj.Property("LocaleCountryCode"); - var localeName = jLocale.Value(); + var localeName = jLocale.Value.Value(); var locale = Localization.Get(localeName); var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult(); @@ -187,23 +185,22 @@ namespace LibationLauncher if (!File.Exists(Configuration.Instance.SettingsFilePath)) return; -// don't delete old settings until new values are used -// remember to remove these from Configuration.cs -return; - // use JObject to remove decrypt key and locale from Settings.json var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var jObj = JObject.Parse(settingsContents); - var resave = false; - - var jDecryptKey = jObj.Property("DecryptKey"); var jLocale = jObj.Property("LocaleCountryCode"); - jDecryptKey?.Remove(); +//// don't delete old setting until new value is used +//// remember to remove these from Configuration.cs +//var jDecryptKey = jObj.Property("DecryptKey"); + +//jDecryptKey?.Remove(); jLocale?.Remove(); - if (jDecryptKey != null || jLocale != null) + if ( +//jDecryptKey != null || + jLocale != null) { var newContents = jObj.ToString(Formatting.Indented); File.WriteAllText(Configuration.Instance.SettingsFilePath, newContents); @@ -385,7 +382,6 @@ return; { Version = BuildVersion.ToString(), - AudibleLocale = config.LocaleCountryCode, config.LibationFiles, AudibleFileStorage.BooksDirectory, diff --git a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs index 1bf09658..c71b13aa 100644 --- a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs @@ -45,8 +45,6 @@ this.decryptInProgressDescLbl = new System.Windows.Forms.Label(); this.saveBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); - this.audibleLocaleLbl = new System.Windows.Forms.Label(); - this.audibleLocaleCb = new System.Windows.Forms.ComboBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.downloadsInProgressGb.SuspendLayout(); this.decryptInProgressGb.SuspendLayout(); @@ -206,7 +204,7 @@ // saveBtn // this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.saveBtn.Location = new System.Drawing.Point(612, 404); + this.saveBtn.Location = new System.Drawing.Point(612, 367); this.saveBtn.Name = "saveBtn"; this.saveBtn.Size = new System.Drawing.Size(75, 23); this.saveBtn.TabIndex = 7; @@ -218,7 +216,7 @@ // this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelBtn.Location = new System.Drawing.Point(713, 404); + this.cancelBtn.Location = new System.Drawing.Point(713, 367); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(75, 23); this.cancelBtn.TabIndex = 8; @@ -226,30 +224,6 @@ this.cancelBtn.UseVisualStyleBackColor = true; this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); // - // audibleLocaleLbl - // - this.audibleLocaleLbl.AutoSize = true; - this.audibleLocaleLbl.Location = new System.Drawing.Point(12, 56); - this.audibleLocaleLbl.Name = "audibleLocaleLbl"; - this.audibleLocaleLbl.Size = new System.Drawing.Size(77, 13); - this.audibleLocaleLbl.TabIndex = 4; - this.audibleLocaleLbl.Text = "Audible Locale"; - // - // audibleLocaleCb - // - this.audibleLocaleCb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.audibleLocaleCb.FormattingEnabled = true; - this.audibleLocaleCb.Items.AddRange(new object[] { - "us", - "uk", - "germany", - "france", - "canada"}); - this.audibleLocaleCb.Location = new System.Drawing.Point(95, 53); - this.audibleLocaleCb.Name = "audibleLocaleCb"; - this.audibleLocaleCb.Size = new System.Drawing.Size(53, 21); - this.audibleLocaleCb.TabIndex = 5; - // // groupBox1 // this.groupBox1.Controls.Add(this.decryptKeyTb); @@ -257,7 +231,7 @@ this.groupBox1.Controls.Add(this.decryptKeyDescLbl); this.groupBox1.Controls.Add(this.downloadsInProgressGb); this.groupBox1.Controls.Add(this.decryptInProgressGb); - this.groupBox1.Location = new System.Drawing.Point(15, 90); + this.groupBox1.Location = new System.Drawing.Point(15, 53); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(773, 308); this.groupBox1.TabIndex = 6; @@ -270,10 +244,8 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelBtn; - this.ClientSize = new System.Drawing.Size(800, 439); + this.ClientSize = new System.Drawing.Size(800, 402); this.Controls.Add(this.groupBox1); - this.Controls.Add(this.audibleLocaleCb); - this.Controls.Add(this.audibleLocaleLbl); this.Controls.Add(this.cancelBtn); this.Controls.Add(this.saveBtn); this.Controls.Add(this.booksLocationDescLbl); @@ -314,8 +286,6 @@ private System.Windows.Forms.RadioButton decryptInProgressWinTempRb; private System.Windows.Forms.Button saveBtn; private System.Windows.Forms.Button cancelBtn; - private System.Windows.Forms.Label audibleLocaleLbl; - private System.Windows.Forms.ComboBox audibleLocaleCb; private System.Windows.Forms.GroupBox groupBox1; } } \ No newline at end of file diff --git a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs index 43968ad6..51031485 100644 --- a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs @@ -38,11 +38,6 @@ namespace LibationWinForms.Dialogs ? config.Books : Path.GetDirectoryName(Exe.FileLocationOnDisk); - this.audibleLocaleCb.Text - = !string.IsNullOrWhiteSpace(config.LocaleCountryCode) - ? config.LocaleCountryCode - : "us"; - switch (config.DownloadsInProgressEnum) { case "LibationFiles": @@ -78,22 +73,7 @@ namespace LibationWinForms.Dialogs private void saveBtn_Click(object sender, EventArgs e) { - var origLocale = config.LocaleCountryCode; - var newLocale = this.audibleLocaleCb.Text; - - if (origLocale == newLocale) - { - config.DecryptKey = this.decryptKeyTb.Text; - } - else - { - // when changing locale: - // - delete decrypt key - // - clear/delete identity tokens file - config.LocaleCountryCode = newLocale; - config.DecryptKey = ""; - File.Delete(AudibleApiStorage.AccountsSettingsFile); - } + config.DecryptKey = this.decryptKeyTb.Text; config.DownloadsInProgressEnum = downloadsInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp"; config.DecryptInProgressEnum = decryptInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp"; diff --git a/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs b/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs index 2c74f3e2..d80ba682 100644 --- a/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs +++ b/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs @@ -45,8 +45,6 @@ this.decryptInProgressDescLbl = new System.Windows.Forms.Label(); this.saveBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); - this.audibleLocaleLbl = new System.Windows.Forms.Label(); - this.audibleLocaleCb = new System.Windows.Forms.ComboBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.downloadsInProgressGb.SuspendLayout(); this.decryptInProgressGb.SuspendLayout(); @@ -205,7 +203,7 @@ // saveBtn // this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.saveBtn.Location = new System.Drawing.Point(612, 404); + this.saveBtn.Location = new System.Drawing.Point(612, 367); this.saveBtn.Name = "saveBtn"; this.saveBtn.Size = new System.Drawing.Size(75, 23); this.saveBtn.TabIndex = 7; @@ -216,37 +214,13 @@ // this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelBtn.Location = new System.Drawing.Point(713, 404); + this.cancelBtn.Location = new System.Drawing.Point(713, 367); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(75, 23); this.cancelBtn.TabIndex = 8; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; // - // audibleLocaleLbl - // - this.audibleLocaleLbl.AutoSize = true; - this.audibleLocaleLbl.Location = new System.Drawing.Point(12, 56); - this.audibleLocaleLbl.Name = "audibleLocaleLbl"; - this.audibleLocaleLbl.Size = new System.Drawing.Size(77, 13); - this.audibleLocaleLbl.TabIndex = 4; - this.audibleLocaleLbl.Text = "Audible Locale"; - // - // audibleLocaleCb - // - this.audibleLocaleCb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.audibleLocaleCb.FormattingEnabled = true; - this.audibleLocaleCb.Items.AddRange(new object[] { - "us", - "uk", - "germany", - "france", - "canada"}); - this.audibleLocaleCb.Location = new System.Drawing.Point(95, 53); - this.audibleLocaleCb.Name = "audibleLocaleCb"; - this.audibleLocaleCb.Size = new System.Drawing.Size(53, 21); - this.audibleLocaleCb.TabIndex = 5; - // // groupBox1 // this.groupBox1.Controls.Add(this.decryptKeyTb); @@ -254,7 +228,7 @@ this.groupBox1.Controls.Add(this.decryptKeyDescLbl); this.groupBox1.Controls.Add(this.downloadsInProgressGb); this.groupBox1.Controls.Add(this.decryptInProgressGb); - this.groupBox1.Location = new System.Drawing.Point(15, 90); + this.groupBox1.Location = new System.Drawing.Point(15, 53); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(773, 308); this.groupBox1.TabIndex = 6; @@ -267,10 +241,8 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelBtn; - this.ClientSize = new System.Drawing.Size(800, 439); + this.ClientSize = new System.Drawing.Size(800, 402); this.Controls.Add(this.groupBox1); - this.Controls.Add(this.audibleLocaleCb); - this.Controls.Add(this.audibleLocaleLbl); this.Controls.Add(this.cancelBtn); this.Controls.Add(this.saveBtn); this.Controls.Add(this.booksLocationDescLbl); @@ -310,8 +282,6 @@ private System.Windows.Forms.RadioButton decryptInProgressWinTempRb; private System.Windows.Forms.Button saveBtn; private System.Windows.Forms.Button cancelBtn; - private System.Windows.Forms.Label audibleLocaleLbl; - private System.Windows.Forms.ComboBox audibleLocaleCb; private System.Windows.Forms.GroupBox groupBox1; } } \ No newline at end of file