mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-13 06:07:30 -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>
68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using ApplicationServices;
|
|
using Avalonia.Threading;
|
|
using DataLayer;
|
|
using LibationFileManager;
|
|
using LibationUiBase.Forms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LibationAvalonia.ViewModels;
|
|
|
|
partial class MainVM
|
|
{
|
|
public void Configure_Liberate() { }
|
|
|
|
/// <summary> This gets called by the "Begin Book and PDF Backups" menu item. </summary>
|
|
public async Task BackupAllBooks()
|
|
{
|
|
var books = await Task.Run(DbContexts.GetUnliberated_Flat_NoTracking);
|
|
await BackupAllBooksAsync(books);
|
|
}
|
|
|
|
/// <param name="notifyIfNothingQueued">False for the automatic post-scan download, which runs unattended.</param>
|
|
private async Task BackupAllBooksAsync(IEnumerable<LibraryBook> books, bool notifyIfNothingQueued = true)
|
|
{
|
|
try
|
|
{
|
|
var unliberated = books.UnLiberated().ToArray();
|
|
|
|
if (await ProcessQueue.QueueDownloadDecryptAsync(unliberated, notifyIfNothingQueued: notifyIfNothingQueued))
|
|
setQueueCollapseState(false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Serilog.Log.Logger.Error(ex, "An error occurred while backing up all library books");
|
|
}
|
|
}
|
|
|
|
/// <summary> This gets called by the "Begin PDF Only Backups" menu item. </summary>
|
|
public async Task BackupAllPdfs()
|
|
{
|
|
var books = await Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking());
|
|
if (await ProcessQueue.QueueDownloadPdfAsync(books))
|
|
setQueueCollapseState(false);
|
|
}
|
|
|
|
public async Task ConvertAllToMp3Async()
|
|
{
|
|
var result = await MessageBox.Show(MainWindow,
|
|
"This converts all m4b titles in your library to mp3 files. Original files are not deleted."
|
|
+ "\r\nFor large libraries this will take a long time and will take up more disk space."
|
|
+ "\r\n\r\nContinue?"
|
|
+ "\r\n\r\n(To always download titles as mp3 instead of m4b, go to Settings: Download my books as .MP3 files)",
|
|
"Convert all M4b => Mp3?",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
if (result == DialogResult.Yes && await ProcessQueue.QueueConvertToMp3Async(await Task.Run(() => DbContexts.GetLibrary_Flat_NoTracking())))
|
|
setQueueCollapseState(false);
|
|
}
|
|
|
|
private void setQueueCollapseState(bool collapsed)
|
|
{
|
|
QueueOpen = !collapsed;
|
|
Configuration.Instance.SetNonString(!collapsed, nameof(QueueOpen));
|
|
}
|
|
}
|