mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-13 14:17:15 -04:00
The multi-book branch of QueueDownloadDecryptAsync returned false with no log entry and no message whenever UnLiberated() came back empty, so a request Libation understood and declined looked exactly like a dead button. Callers that pre-filter with UnLiberated() land here with an empty list, which is the common way to hit it. Classify each title that cannot be queued and report the breakdown: already downloaded, previously failed, absent from the last scan, or a series parent with no audio of its own. Log it either way; show it only when a person is waiting, so the automatic post-scan download stays silent. Fixes #1940 Co-authored-by: rmcrackan <rmcrackan@gmail.com>
108 lines
3.6 KiB
C#
108 lines
3.6 KiB
C#
using ApplicationServices;
|
|
using AudibleUtilities;
|
|
using Dinah.Core.Threading;
|
|
using Dinah.Core.WindowsDesktop.Drawing;
|
|
using FileManager;
|
|
using LibationFileManager;
|
|
using LibationUiBase;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LibationWinForms;
|
|
|
|
public partial class Form1
|
|
{
|
|
private void Configure_NonUI()
|
|
{
|
|
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));
|
|
PictureStorage.SetDefaultImage(PictureSize.Native, Properties.Resources.default_cover_500x500.ToBytes(format));
|
|
|
|
BaseUtil.SetLoadImageDelegate(WinFormsUtil.TryLoadImageOrDefault);
|
|
BaseUtil.SetIsDarkModeDelegate(() => Application.IsDarkModeEnabled);
|
|
|
|
// wire-up event to automatically download after scan.
|
|
// winforms only. this should NOT be allowed in cli
|
|
updateCountsBw.RunWorkerCompleted += (_, e) => tryAutoDownloadAfterCounts(e);
|
|
}
|
|
|
|
private void tryAutoDownloadAfterCounts(System.ComponentModel.RunWorkerCompletedEventArgs e)
|
|
{
|
|
// Guard e.Cancelled/e.Error before reading e.Result: e.Result rethrows a faulted count,
|
|
// which here (a RunWorkerCompleted handler) would become an unhandled exception.
|
|
if (!Configuration.Instance.AutoDownloadEpisodes || e.Cancelled || e.Error is not null)
|
|
return;
|
|
|
|
if (e.Result is not LibraryCommands.LibraryStats libraryStats)
|
|
return;
|
|
|
|
if (libraryStats.PendingBooks + libraryStats.pdfsNotDownloaded <= 0)
|
|
return;
|
|
|
|
// RunWorkerCompleted has no SynchronizationContext; queue items require the UI thread.
|
|
this.UIThreadAsync(() => _ = BackupAllBooksAsync(libraryStats.LibraryBooks, notifyIfNothingQueued: false));
|
|
}
|
|
|
|
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,
|
|
Configuration.Instance.ReplacementCharacters,
|
|
"bak");
|
|
|
|
AudibleApiStorage.EnsureAccountsSettingsFileExists();
|
|
e.Handled = true;
|
|
|
|
showAccountSettingsRecoveredMessage(backupFile);
|
|
}
|
|
catch
|
|
{
|
|
showAccountSettingsUnrecoveredMessage();
|
|
}
|
|
|
|
void showAccountSettingsRecoveredMessage(LongPath backupFile)
|
|
{
|
|
var ex = e.GetException();
|
|
var body = AccountSettingsDecryptFailure.TryFindInTree(ex, out _)
|
|
? AccountSettingsDecryptFailure.GetRecoveredDialogBody(ex, backupFile.PathWithoutPrefix)
|
|
: $"""
|
|
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}'
|
|
|
|
{ex}
|
|
""";
|
|
|
|
MessageBox.Show(
|
|
this,
|
|
body,
|
|
AccountSettingsDecryptFailure.LoadErrorCaption,
|
|
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);
|
|
}
|
|
}
|