From be84fb317e52e7d9720773b5c2bea6d1d4111eb2 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 21 Aug 2020 22:01:23 -0400 Subject: [PATCH] DecryptKey: static => account instance --- FileLiberator/UNTESTED/DecryptBook.cs | 14 +++++--- FileManager/UNTESTED/Configuration.cs | 7 ---- .../UNTESTED/AudibleApiStorage.cs | 5 ++- LibationLauncher/LibationLauncher.csproj | 2 +- LibationLauncher/UNTESTED/Program.cs | 17 +++------- .../Dialogs/SettingsDialog.Designer.cs | 34 ------------------- .../UNTESTED/Dialogs/SettingsDialog.cs | 4 --- .../Dialogs/SettingsDialog.Designer.cs | 34 ------------------- 8 files changed, 20 insertions(+), 97 deletions(-) diff --git a/FileLiberator/UNTESTED/DecryptBook.cs b/FileLiberator/UNTESTED/DecryptBook.cs index 3a306b80..f392ff19 100644 --- a/FileLiberator/UNTESTED/DecryptBook.cs +++ b/FileLiberator/UNTESTED/DecryptBook.cs @@ -8,6 +8,7 @@ using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; using FileManager; +using InternalUtilities; namespace FileLiberator { @@ -56,7 +57,12 @@ namespace FileLiberator return new StatusHandler { "Cannot find decrypt. Final audio file already exists" }; var proposedOutputFile = Path.Combine(AudibleFileStorage.DecryptInProgress, $"[{libraryBook.Book.AudibleProductId}].m4b"); - var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename); + + var account = AudibleApiStorage + .GetAccounts() + .GetAccount(libraryBook.Account, libraryBook.Book.Locale); + + var outputAudioFilename = await aaxToM4bConverterDecrypt(proposedOutputFile, aaxFilename, account); // decrypt failed if (outputAudioFilename == null) @@ -78,13 +84,13 @@ namespace FileLiberator } } - private async Task aaxToM4bConverterDecrypt(string proposedOutputFile, string aaxFilename) + private async Task aaxToM4bConverterDecrypt(string proposedOutputFile, string aaxFilename, Account account) { DecryptBegin?.Invoke(this, $"Begin decrypting {aaxFilename}"); try { - var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, Configuration.Instance.DecryptKey); + var converter = await AaxToM4bConverter.CreateAsync(aaxFilename, account.DecryptKey); converter.AppName = "Libation"; TitleDiscovered?.Invoke(this, converter.tags.title); @@ -103,7 +109,7 @@ namespace FileLiberator if (!success) return null; - Configuration.Instance.DecryptKey = converter.decryptKey; + account.DecryptKey = converter.decryptKey; return converter.outputFileName; } diff --git a/FileManager/UNTESTED/Configuration.cs b/FileManager/UNTESTED/Configuration.cs index e92fc4fd..7710dc58 100644 --- a/FileManager/UNTESTED/Configuration.cs +++ b/FileManager/UNTESTED/Configuration.cs @@ -43,13 +43,6 @@ namespace FileManager public string SettingsFilePath => Path.Combine(LibationFiles, "Settings.json"); - [Description("Your user-specific key used to decrypt your audible files (*.aax) into audio files you can use anywhere (*.m4b). Leave alone in most cases")] - public string DecryptKey - { - get => persistentDictionary.GetString(nameof(DecryptKey)); - set => persistentDictionary.Set(nameof(DecryptKey), value); - } - [Description("Location for book storage. Includes destination of newly liberated books")] public string Books { diff --git a/InternalUtilities/UNTESTED/AudibleApiStorage.cs b/InternalUtilities/UNTESTED/AudibleApiStorage.cs index b58d2eb5..2c3f0d71 100644 --- a/InternalUtilities/UNTESTED/AudibleApiStorage.cs +++ b/InternalUtilities/UNTESTED/AudibleApiStorage.cs @@ -24,7 +24,10 @@ namespace InternalUtilities => TEST_GetFirstAccount().GetIdentityTokensJsonPath(); // convenience for for tests and demos. don't use in production Libation public static Account TEST_GetFirstAccount() - => new AccountsPersister(AccountsSettingsFile).Accounts.GetAll().FirstOrDefault(); + => GetAccounts().GetAll().FirstOrDefault(); + + public static Accounts GetAccounts() + => new AccountsPersister(AccountsSettingsFile).Accounts; public static string GetIdentityTokensJsonPath(this Account account) => GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name); diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index e7adc0f0..23e18e62 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.214 + 3.1.12.218 diff --git a/LibationLauncher/UNTESTED/Program.cs b/LibationLauncher/UNTESTED/Program.cs index 8c3a6aa2..e9e08e45 100644 --- a/LibationLauncher/UNTESTED/Program.cs +++ b/LibationLauncher/UNTESTED/Program.cs @@ -54,7 +54,6 @@ namespace LibationLauncher var setupDialog = new SetupDialog(); setupDialog.NoQuestionsBtn_Click += (_, __) => { - config.DecryptKey ??= ""; config.DownloadsInProgressEnum ??= "WinTemp"; config.DecryptInProgressEnum ??= "WinTemp"; config.Books ??= Configuration.AppDir; @@ -155,7 +154,6 @@ namespace LibationLauncher if (!identity.IsValid) return null; - var accountsPersist = new AccountsPersister(AudibleApiStorage.AccountsSettingsFile); var account = new Account(email) { AccountName = $"{email} - {locale.Name}", @@ -163,7 +161,7 @@ namespace LibationLauncher }; // saves to new file - accountsPersist.Accounts.Add(account); + AudibleApiStorage.GetAccounts().Add(account); return account; } @@ -191,17 +189,12 @@ namespace LibationLauncher var jObj = JObject.Parse(settingsContents); var jLocale = jObj.Property("LocaleCountryCode"); - -//// don't delete old setting until new value is used -//// remember to remove these from Configuration.cs -//var jDecryptKey = jObj.Property("DecryptKey"); - -//jDecryptKey?.Remove(); + 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); diff --git a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs index c71b13aa..256bb85f 100644 --- a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.Designer.cs @@ -28,12 +28,9 @@ /// private void InitializeComponent() { - this.decryptKeyLbl = new System.Windows.Forms.Label(); - this.decryptKeyTb = new System.Windows.Forms.TextBox(); this.booksLocationLbl = new System.Windows.Forms.Label(); this.booksLocationTb = new System.Windows.Forms.TextBox(); this.booksLocationSearchBtn = new System.Windows.Forms.Button(); - this.decryptKeyDescLbl = new System.Windows.Forms.Label(); this.booksLocationDescLbl = new System.Windows.Forms.Label(); this.downloadsInProgressGb = new System.Windows.Forms.GroupBox(); this.downloadsInProgressLibationFilesRb = new System.Windows.Forms.RadioButton(); @@ -51,22 +48,6 @@ this.groupBox1.SuspendLayout(); this.SuspendLayout(); // - // decryptKeyLbl - // - this.decryptKeyLbl.AutoSize = true; - this.decryptKeyLbl.Location = new System.Drawing.Point(6, 22); - this.decryptKeyLbl.Name = "decryptKeyLbl"; - this.decryptKeyLbl.Size = new System.Drawing.Size(64, 13); - this.decryptKeyLbl.TabIndex = 0; - this.decryptKeyLbl.Text = "Decrypt key"; - // - // decryptKeyTb - // - this.decryptKeyTb.Location = new System.Drawing.Point(76, 19); - this.decryptKeyTb.Name = "decryptKeyTb"; - this.decryptKeyTb.Size = new System.Drawing.Size(100, 20); - this.decryptKeyTb.TabIndex = 1; - // // booksLocationLbl // this.booksLocationLbl.AutoSize = true; @@ -93,15 +74,6 @@ this.booksLocationSearchBtn.UseVisualStyleBackColor = true; this.booksLocationSearchBtn.Click += new System.EventHandler(this.booksLocationSearchBtn_Click); // - // decryptKeyDescLbl - // - this.decryptKeyDescLbl.AutoSize = true; - this.decryptKeyDescLbl.Location = new System.Drawing.Point(73, 42); - this.decryptKeyDescLbl.Name = "decryptKeyDescLbl"; - this.decryptKeyDescLbl.Size = new System.Drawing.Size(36, 13); - this.decryptKeyDescLbl.TabIndex = 2; - this.decryptKeyDescLbl.Text = "[desc]"; - // // booksLocationDescLbl // this.booksLocationDescLbl.AutoSize = true; @@ -226,9 +198,6 @@ // // groupBox1 // - this.groupBox1.Controls.Add(this.decryptKeyTb); - this.groupBox1.Controls.Add(this.decryptKeyLbl); - 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, 53); @@ -269,12 +238,9 @@ } #endregion - private System.Windows.Forms.Label decryptKeyLbl; - private System.Windows.Forms.TextBox decryptKeyTb; private System.Windows.Forms.Label booksLocationLbl; private System.Windows.Forms.TextBox booksLocationTb; private System.Windows.Forms.Button booksLocationSearchBtn; - private System.Windows.Forms.Label decryptKeyDescLbl; private System.Windows.Forms.Label booksLocationDescLbl; private System.Windows.Forms.GroupBox downloadsInProgressGb; private System.Windows.Forms.Label downloadsInProgressDescLbl; diff --git a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs index 51031485..16dd1fe7 100644 --- a/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/SettingsDialog.cs @@ -19,8 +19,6 @@ namespace LibationWinForms.Dialogs private void SettingsDialog_Load(object sender, EventArgs e) { - this.decryptKeyTb.Text = config.DecryptKey; - this.decryptKeyDescLbl.Text = desc(nameof(config.DecryptKey)); this.booksLocationDescLbl.Text = desc(nameof(config.Books)); this.downloadsInProgressDescLbl.Text = desc(nameof(config.DownloadsInProgressEnum)); this.decryptInProgressDescLbl.Text = desc(nameof(config.DecryptInProgressEnum)); @@ -73,8 +71,6 @@ namespace LibationWinForms.Dialogs private void saveBtn_Click(object sender, EventArgs e) { - 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 d80ba682..e9159a28 100644 --- a/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs +++ b/WinFormsDesigner/Dialogs/SettingsDialog.Designer.cs @@ -28,12 +28,9 @@ /// private void InitializeComponent() { - this.decryptKeyLbl = new System.Windows.Forms.Label(); - this.decryptKeyTb = new System.Windows.Forms.TextBox(); this.booksLocationLbl = new System.Windows.Forms.Label(); this.booksLocationTb = new System.Windows.Forms.TextBox(); this.booksLocationSearchBtn = new System.Windows.Forms.Button(); - this.decryptKeyDescLbl = new System.Windows.Forms.Label(); this.booksLocationDescLbl = new System.Windows.Forms.Label(); this.downloadsInProgressGb = new System.Windows.Forms.GroupBox(); this.downloadsInProgressLibationFilesRb = new System.Windows.Forms.RadioButton(); @@ -51,22 +48,6 @@ this.groupBox1.SuspendLayout(); this.SuspendLayout(); // - // decryptKeyLbl - // - this.decryptKeyLbl.AutoSize = true; - this.decryptKeyLbl.Location = new System.Drawing.Point(6, 22); - this.decryptKeyLbl.Name = "decryptKeyLbl"; - this.decryptKeyLbl.Size = new System.Drawing.Size(64, 13); - this.decryptKeyLbl.TabIndex = 0; - this.decryptKeyLbl.Text = "Decrypt key"; - // - // decryptKeyTb - // - this.decryptKeyTb.Location = new System.Drawing.Point(76, 19); - this.decryptKeyTb.Name = "decryptKeyTb"; - this.decryptKeyTb.Size = new System.Drawing.Size(100, 20); - this.decryptKeyTb.TabIndex = 1; - // // booksLocationLbl // this.booksLocationLbl.AutoSize = true; @@ -92,15 +73,6 @@ this.booksLocationSearchBtn.Text = "..."; this.booksLocationSearchBtn.UseVisualStyleBackColor = true; // - // decryptKeyDescLbl - // - this.decryptKeyDescLbl.AutoSize = true; - this.decryptKeyDescLbl.Location = new System.Drawing.Point(73, 42); - this.decryptKeyDescLbl.Name = "decryptKeyDescLbl"; - this.decryptKeyDescLbl.Size = new System.Drawing.Size(36, 13); - this.decryptKeyDescLbl.TabIndex = 2; - this.decryptKeyDescLbl.Text = "[desc]"; - // // booksLocationDescLbl // this.booksLocationDescLbl.AutoSize = true; @@ -223,9 +195,6 @@ // // groupBox1 // - this.groupBox1.Controls.Add(this.decryptKeyTb); - this.groupBox1.Controls.Add(this.decryptKeyLbl); - 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, 53); @@ -265,12 +234,9 @@ } #endregion - private System.Windows.Forms.Label decryptKeyLbl; - private System.Windows.Forms.TextBox decryptKeyTb; private System.Windows.Forms.Label booksLocationLbl; private System.Windows.Forms.TextBox booksLocationTb; private System.Windows.Forms.Button booksLocationSearchBtn; - private System.Windows.Forms.Label decryptKeyDescLbl; private System.Windows.Forms.Label booksLocationDescLbl; private System.Windows.Forms.GroupBox downloadsInProgressGb; private System.Windows.Forms.Label downloadsInProgressDescLbl;