Handle and notify users of invalid account settings file
This commit is contained in:
parent
b36e110b49
commit
ac036f65f1
4 changed files with 161 additions and 13 deletions
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ApplicationServices;
|
||||
using AudibleUtilities;
|
||||
using Dinah.Core.WindowsDesktop.Drawing;
|
||||
using FileManager;
|
||||
using LibationFileManager;
|
||||
using LibationUiBase;
|
||||
|
||||
|
|
@ -13,9 +11,11 @@ namespace LibationWinForms
|
|||
public partial class Form1
|
||||
{
|
||||
private void Configure_NonUI()
|
||||
{
|
||||
// init default/placeholder cover art
|
||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
{
|
||||
AudibleApiStorage.LoadError += AudibleApiStorage_LoadError;
|
||||
|
||||
// init default/placeholder cover art
|
||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
||||
PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format));
|
||||
PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format));
|
||||
|
|
@ -35,6 +35,55 @@ namespace LibationWinForms
|
|||
if ((libraryStats.booksNoProgress + libraryStats.pdfsNotDownloaded) > 0)
|
||||
beginBookBackupsToolStripMenuItem_Click();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AudibleApiStorage_LoadError(object sender, AccountSettingsLoadErrorEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
//Backup AccountSettings.json and create a new, empty file.
|
||||
var backupFile =
|
||||
FileUtility.SaferMoveToValidPath(
|
||||
e.SettingsFilePath,
|
||||
e.SettingsFilePath,
|
||||
ReplacementCharacters.Barebones,
|
||||
"bak");
|
||||
|
||||
AudibleApiStorage.EnsureAccountsSettingsFileExists();
|
||||
e.Handled = true;
|
||||
|
||||
showAccountSettingsRecoveredMessage(backupFile);
|
||||
}
|
||||
catch
|
||||
{
|
||||
showAccountSettingsUnrecoveredMessage();
|
||||
}
|
||||
|
||||
void showAccountSettingsRecoveredMessage(LongPath backupFile)
|
||||
=> MessageBox.Show(this, $"""
|
||||
Libation could not load your account settings, so it had created a new, empty account settings file.
|
||||
|
||||
You will need to re-add you Audible account(s) before scanning or downloading.
|
||||
|
||||
The old account settings file has been archived at '{backupFile.PathWithoutPrefix}'
|
||||
|
||||
{e.GetException().ToString()}
|
||||
""",
|
||||
"Error Loading Account Settings",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Warning);
|
||||
|
||||
void showAccountSettingsUnrecoveredMessage()
|
||||
=> MessageBox.Show(this, $"""
|
||||
Libation could not load your account settings. The file may be corrupted, but Libation is unable to delete it.
|
||||
|
||||
Please move or delete the account settings file '{e.SettingsFilePath}'
|
||||
|
||||
{e.GetException().ToString()}
|
||||
""",
|
||||
"Error Loading Account Settings",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue