From dd3b032b21714a1bf4fbca155ad2072b7a288d0b Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Tue, 25 Aug 2020 15:58:56 -0400 Subject: [PATCH] Fix account persistence edge case --- InternalUtilities/Account.cs | 2 ++ InternalUtilities/AccountsSettings.cs | 4 +++- LibationLauncher/LibationLauncher.csproj | 2 +- LibationWinForms/UNTESTED/Form1.cs | 27 ++++++++++++++++++------ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/InternalUtilities/Account.cs b/InternalUtilities/Account.cs index c42cf989..e1afc9ab 100644 --- a/InternalUtilities/Account.cs +++ b/InternalUtilities/Account.cs @@ -91,5 +91,7 @@ namespace InternalUtilities ArgumentValidator.EnsureNotNullOrWhiteSpace(accountId, nameof(accountId)); AccountId = accountId.Trim(); } + + public override string ToString() => $"{AccountId} - {Locale?.Name ?? "[empty]"}"; } } diff --git a/InternalUtilities/AccountsSettings.cs b/InternalUtilities/AccountsSettings.cs index 2d57d640..d1614be0 100644 --- a/InternalUtilities/AccountsSettings.cs +++ b/InternalUtilities/AccountsSettings.cs @@ -113,7 +113,9 @@ namespace InternalUtilities return false; account.Updated -= update; - return _accounts_backing.Remove(account); + var result = _accounts_backing.Remove(account); + update_no_validate(); + return result; } private void validate(Account account) diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 58915c2e..cce0b2e6 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.271 + 3.1.12.279 diff --git a/LibationWinForms/UNTESTED/Form1.cs b/LibationWinForms/UNTESTED/Form1.cs index 4049045c..561e6f97 100644 --- a/LibationWinForms/UNTESTED/Form1.cs +++ b/LibationWinForms/UNTESTED/Form1.cs @@ -8,6 +8,7 @@ using Dinah.Core; using Dinah.Core.Drawing; using Dinah.Core.Windows.Forms; using FileManager; +using InternalUtilities; using LibationWinForms.Dialogs; namespace LibationWinForms @@ -42,6 +43,8 @@ namespace LibationWinForms PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format)); PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format)); + setImportMenu(); + setVisibleCount(null, 0); reloadGrid(); @@ -55,8 +58,8 @@ namespace LibationWinForms setBackupCounts(null, null); } - #region reload grid - bool isProcessingGridSelect = false; + #region reload grid + bool isProcessingGridSelect = false; private void reloadGrid() { // suppressed filter while init'ing UI @@ -223,10 +226,19 @@ namespace LibationWinForms doFilter(lastGoodFilter); } } - #endregion + #endregion - #region index menu - private void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e) + #region Import menu + private void setImportMenu() + { + var hasMultipleAccounts = AudibleApiStorage.GetPersistentAccountsSettings().Accounts.Count > 1; + + scanLibraryToolStripMenuItem.Visible = !hasMultipleAccounts; + scanLibraryOfAllAccountsToolStripMenuItem.Visible = hasMultipleAccounts; + scanLibraryOfSomeAccountsToolStripMenuItem.Visible = hasMultipleAccounts; + } + + private void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new IndexLibraryDialog(); dialog.ShowDialog(); @@ -309,7 +321,10 @@ private void scanLibraryOfSomeAccountsToolStripMenuItem_Click(object sender, Eve #region settings menu private void accountsToolStripMenuItem_Click(object sender, EventArgs e) -=> new AccountsDialog().ShowDialog(); + { + new AccountsDialog().ShowDialog(); + setImportMenu(); + } private void basicSettingsToolStripMenuItem_Click(object sender, EventArgs e) => new SettingsDialog().ShowDialog();