Libation 4.0 prep: purge global static config Configuration.LocaleCountryCode

This commit is contained in:
Robert McRackan 2020-08-21 11:50:11 -04:00
parent 258775ff3f
commit 2e5360f0ba
7 changed files with 32 additions and 114 deletions

View File

@ -4,6 +4,7 @@ using AudibleApi;
using DataLayer; using DataLayer;
using DtoImporterService; using DtoImporterService;
using InternalUtilities; using InternalUtilities;
using Serilog;
namespace ApplicationServices namespace ApplicationServices
{ {
@ -15,24 +16,31 @@ namespace ApplicationServices
{ {
var account = AudibleApiStorage.TEST_GetFirstAccount(); 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 items = await AudibleApiActions.GetAllLibraryItemsAsync(account, callback);
var totalCount = items.Count; var totalCount = items.Count;
Serilog.Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}");
using var context = DbContexts.GetContext(); using var context = DbContexts.GetContext();
var libraryImporter = new LibraryImporter(context, account); var libraryImporter = new LibraryImporter(context, account);
var newCount = await Task.Run(() => libraryImporter.Import(items)); var newCount = await Task.Run(() => libraryImporter.Import(items));
context.SaveChanges(); context.SaveChanges();
Serilog.Log.Logger.Information($"Import: New count {newCount}"); Log.Logger.Information($"Import: New count {newCount}");
await Task.Run(() => SearchEngineCommands.FullReIndex()); await Task.Run(() => SearchEngineCommands.FullReIndex());
Serilog.Log.Logger.Information("FullReIndex: success"); Log.Logger.Information("FullReIndex: success");
return (totalCount, newCount); return (totalCount, newCount);
} }
catch (Exception ex) catch (Exception ex)
{ {
Serilog.Log.Logger.Error(ex, "Error importing library"); Log.Logger.Error(ex, "Error importing library");
throw; throw;
} }
} }
@ -52,7 +60,7 @@ namespace ApplicationServices
} }
catch (Exception ex) catch (Exception ex)
{ {
Serilog.Log.Logger.Error(ex, "Error updating tags"); Log.Logger.Error(ex, "Error updating tags");
throw; throw;
} }
} }

View File

@ -90,12 +90,6 @@ namespace FileManager
set => persistentDictionary.Set(nameof(DecryptInProgressEnum), value); 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 // 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 // singleton stuff

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> --> <!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.186</Version> <Version>3.1.12.194</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -42,7 +42,6 @@ namespace LibationLauncher
{ {
static bool configSetupIsComplete(Configuration config) static bool configSetupIsComplete(Configuration config)
=> config.FilesExist => config.FilesExist
&& !string.IsNullOrWhiteSpace(config.LocaleCountryCode)
&& !string.IsNullOrWhiteSpace(config.DownloadsInProgressEnum) && !string.IsNullOrWhiteSpace(config.DownloadsInProgressEnum)
&& !string.IsNullOrWhiteSpace(config.DecryptInProgressEnum); && !string.IsNullOrWhiteSpace(config.DecryptInProgressEnum);
@ -56,7 +55,6 @@ namespace LibationLauncher
setupDialog.NoQuestionsBtn_Click += (_, __) => setupDialog.NoQuestionsBtn_Click += (_, __) =>
{ {
config.DecryptKey ??= ""; config.DecryptKey ??= "";
config.LocaleCountryCode ??= "us";
config.DownloadsInProgressEnum ??= "WinTemp"; config.DownloadsInProgressEnum ??= "WinTemp";
config.DecryptInProgressEnum ??= "WinTemp"; config.DecryptInProgressEnum ??= "WinTemp";
config.Books ??= Configuration.AppDir; config.Books ??= Configuration.AppDir;
@ -142,7 +140,7 @@ namespace LibationLauncher
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
var jObj = JObject.Parse(settingsContents); var jObj = JObject.Parse(settingsContents);
var jLocale = jObj.Property("LocaleCountryCode"); var jLocale = jObj.Property("LocaleCountryCode");
var localeName = jLocale.Value<string>(); var localeName = jLocale.Value.Value<string>();
var locale = Localization.Get(localeName); var locale = Localization.Get(localeName);
var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult(); var api = EzApiCreator.GetApiAsync(locale, AccountsSettingsFileLegacy30).GetAwaiter().GetResult();
@ -187,23 +185,22 @@ namespace LibationLauncher
if (!File.Exists(Configuration.Instance.SettingsFilePath)) if (!File.Exists(Configuration.Instance.SettingsFilePath))
return; 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 // use JObject to remove decrypt key and locale from Settings.json
var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath); var settingsContents = File.ReadAllText(Configuration.Instance.SettingsFilePath);
var jObj = JObject.Parse(settingsContents); var jObj = JObject.Parse(settingsContents);
var resave = false;
var jDecryptKey = jObj.Property("DecryptKey");
var jLocale = jObj.Property("LocaleCountryCode"); 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(); jLocale?.Remove();
if (jDecryptKey != null || jLocale != null) if (
//jDecryptKey != null ||
jLocale != null)
{ {
var newContents = jObj.ToString(Formatting.Indented); var newContents = jObj.ToString(Formatting.Indented);
File.WriteAllText(Configuration.Instance.SettingsFilePath, newContents); File.WriteAllText(Configuration.Instance.SettingsFilePath, newContents);
@ -385,7 +382,6 @@ return;
{ {
Version = BuildVersion.ToString(), Version = BuildVersion.ToString(),
AudibleLocale = config.LocaleCountryCode,
config.LibationFiles, config.LibationFiles,
AudibleFileStorage.BooksDirectory, AudibleFileStorage.BooksDirectory,

View File

@ -45,8 +45,6 @@
this.decryptInProgressDescLbl = new System.Windows.Forms.Label(); this.decryptInProgressDescLbl = new System.Windows.Forms.Label();
this.saveBtn = new System.Windows.Forms.Button(); this.saveBtn = new System.Windows.Forms.Button();
this.cancelBtn = 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.groupBox1 = new System.Windows.Forms.GroupBox();
this.downloadsInProgressGb.SuspendLayout(); this.downloadsInProgressGb.SuspendLayout();
this.decryptInProgressGb.SuspendLayout(); this.decryptInProgressGb.SuspendLayout();
@ -206,7 +204,7 @@
// saveBtn // saveBtn
// //
this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Name = "saveBtn";
this.saveBtn.Size = new System.Drawing.Size(75, 23); this.saveBtn.Size = new System.Drawing.Size(75, 23);
this.saveBtn.TabIndex = 7; 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.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.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.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(75, 23); this.cancelBtn.Size = new System.Drawing.Size(75, 23);
this.cancelBtn.TabIndex = 8; this.cancelBtn.TabIndex = 8;
@ -226,30 +224,6 @@
this.cancelBtn.UseVisualStyleBackColor = true; this.cancelBtn.UseVisualStyleBackColor = true;
this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); 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 // groupBox1
// //
this.groupBox1.Controls.Add(this.decryptKeyTb); this.groupBox1.Controls.Add(this.decryptKeyTb);
@ -257,7 +231,7 @@
this.groupBox1.Controls.Add(this.decryptKeyDescLbl); this.groupBox1.Controls.Add(this.decryptKeyDescLbl);
this.groupBox1.Controls.Add(this.downloadsInProgressGb); this.groupBox1.Controls.Add(this.downloadsInProgressGb);
this.groupBox1.Controls.Add(this.decryptInProgressGb); 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.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(773, 308); this.groupBox1.Size = new System.Drawing.Size(773, 308);
this.groupBox1.TabIndex = 6; this.groupBox1.TabIndex = 6;
@ -270,10 +244,8 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelBtn; 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.groupBox1);
this.Controls.Add(this.audibleLocaleCb);
this.Controls.Add(this.audibleLocaleLbl);
this.Controls.Add(this.cancelBtn); this.Controls.Add(this.cancelBtn);
this.Controls.Add(this.saveBtn); this.Controls.Add(this.saveBtn);
this.Controls.Add(this.booksLocationDescLbl); this.Controls.Add(this.booksLocationDescLbl);
@ -314,8 +286,6 @@
private System.Windows.Forms.RadioButton decryptInProgressWinTempRb; private System.Windows.Forms.RadioButton decryptInProgressWinTempRb;
private System.Windows.Forms.Button saveBtn; private System.Windows.Forms.Button saveBtn;
private System.Windows.Forms.Button cancelBtn; private System.Windows.Forms.Button cancelBtn;
private System.Windows.Forms.Label audibleLocaleLbl;
private System.Windows.Forms.ComboBox audibleLocaleCb;
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
} }
} }

View File

@ -38,11 +38,6 @@ namespace LibationWinForms.Dialogs
? config.Books ? config.Books
: Path.GetDirectoryName(Exe.FileLocationOnDisk); : Path.GetDirectoryName(Exe.FileLocationOnDisk);
this.audibleLocaleCb.Text
= !string.IsNullOrWhiteSpace(config.LocaleCountryCode)
? config.LocaleCountryCode
: "us";
switch (config.DownloadsInProgressEnum) switch (config.DownloadsInProgressEnum)
{ {
case "LibationFiles": case "LibationFiles":
@ -78,22 +73,7 @@ namespace LibationWinForms.Dialogs
private void saveBtn_Click(object sender, EventArgs e) private void saveBtn_Click(object sender, EventArgs e)
{ {
var origLocale = config.LocaleCountryCode; config.DecryptKey = this.decryptKeyTb.Text;
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.DownloadsInProgressEnum = downloadsInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp"; config.DownloadsInProgressEnum = downloadsInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp";
config.DecryptInProgressEnum = decryptInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp"; config.DecryptInProgressEnum = decryptInProgressLibationFilesRb.Checked ? "LibationFiles" : "WinTemp";

View File

@ -45,8 +45,6 @@
this.decryptInProgressDescLbl = new System.Windows.Forms.Label(); this.decryptInProgressDescLbl = new System.Windows.Forms.Label();
this.saveBtn = new System.Windows.Forms.Button(); this.saveBtn = new System.Windows.Forms.Button();
this.cancelBtn = 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.groupBox1 = new System.Windows.Forms.GroupBox();
this.downloadsInProgressGb.SuspendLayout(); this.downloadsInProgressGb.SuspendLayout();
this.decryptInProgressGb.SuspendLayout(); this.decryptInProgressGb.SuspendLayout();
@ -205,7 +203,7 @@
// saveBtn // saveBtn
// //
this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Name = "saveBtn";
this.saveBtn.Size = new System.Drawing.Size(75, 23); this.saveBtn.Size = new System.Drawing.Size(75, 23);
this.saveBtn.TabIndex = 7; 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.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.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.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(75, 23); this.cancelBtn.Size = new System.Drawing.Size(75, 23);
this.cancelBtn.TabIndex = 8; this.cancelBtn.TabIndex = 8;
this.cancelBtn.Text = "Cancel"; this.cancelBtn.Text = "Cancel";
this.cancelBtn.UseVisualStyleBackColor = true; 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 // groupBox1
// //
this.groupBox1.Controls.Add(this.decryptKeyTb); this.groupBox1.Controls.Add(this.decryptKeyTb);
@ -254,7 +228,7 @@
this.groupBox1.Controls.Add(this.decryptKeyDescLbl); this.groupBox1.Controls.Add(this.decryptKeyDescLbl);
this.groupBox1.Controls.Add(this.downloadsInProgressGb); this.groupBox1.Controls.Add(this.downloadsInProgressGb);
this.groupBox1.Controls.Add(this.decryptInProgressGb); 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.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(773, 308); this.groupBox1.Size = new System.Drawing.Size(773, 308);
this.groupBox1.TabIndex = 6; this.groupBox1.TabIndex = 6;
@ -267,10 +241,8 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelBtn; 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.groupBox1);
this.Controls.Add(this.audibleLocaleCb);
this.Controls.Add(this.audibleLocaleLbl);
this.Controls.Add(this.cancelBtn); this.Controls.Add(this.cancelBtn);
this.Controls.Add(this.saveBtn); this.Controls.Add(this.saveBtn);
this.Controls.Add(this.booksLocationDescLbl); this.Controls.Add(this.booksLocationDescLbl);
@ -310,8 +282,6 @@
private System.Windows.Forms.RadioButton decryptInProgressWinTempRb; private System.Windows.Forms.RadioButton decryptInProgressWinTempRb;
private System.Windows.Forms.Button saveBtn; private System.Windows.Forms.Button saveBtn;
private System.Windows.Forms.Button cancelBtn; private System.Windows.Forms.Button cancelBtn;
private System.Windows.Forms.Label audibleLocaleLbl;
private System.Windows.Forms.ComboBox audibleLocaleCb;
private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox1;
} }
} }