feat(app): connect the archive engine to the desktop client

The client builds the archive service on its index (WIC, then managed
decoders), registers its scan, rebuild, verify, import, thumbnail, proxy
and maintenance handlers, reopens the last archive at start and rescans
it every 10 minutes. Welcome and Library create or adopt archives
through it and queue a full scan; a failure shows a toast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 12:49:15 +00:00
1 parent 6ac27413a7
commit 9fd7ac0d36
6 files changed
+115 -45

No files matched your search

+41 -20
View File
@@ -1,12 +1,11 @@
using System.IO;
using Titano.Core.Diagnostics;
using Titano.Data.Archiving;
namespace Titano.App.Infrastructure;
/// <summary>
/// First-run archive choices (BRIEF §12.1): create a local archive or adopt an existing folder tree. The
/// integrator replaces <see cref="LocalArchiveSetup"/> with an implementation backed by the archive engine (folder
/// layout, index, adopt job); see <see cref="AppServices"/>.
/// First-run and Library archive choices (BRIEF §12.1): create a local archive or adopt an existing folder tree.
/// </summary>
public interface IArchiveSetup
{
@@ -17,27 +16,49 @@ public interface IArchiveSetup
Task AdoptAsync(string folder, CancellationToken cancellationToken = default);
}
/// <summary>Until the archive engine is connected: remembers the chosen root in the settings and nothing else.</summary>
public sealed class LocalArchiveSetup(AppSettings settings, Action save) : IArchiveSetup
/// <summary>
/// Creates or adopts the archive through the archive engine (originals stay where they are), remembers it as the
/// archive to open at start and queues a full scan that indexes its sequences.
/// </summary>
public sealed class EngineArchiveSetup(AppServices services) : IArchiveSetup
{
public Task CreateAsync(string root, CancellationToken cancellationToken = default)
{
Remember(root);
Log.Info("archive", $"Local archive root set to {root}");
return Task.CompletedTask;
}
public Task CreateAsync(string root, CancellationToken cancellationToken = default) => OpenAsync(root, cancellationToken);
public Task AdoptAsync(string folder, CancellationToken cancellationToken = default)
{
Remember(folder);
Log.Info("archive", $"Adopted folder recorded: {folder}");
return Task.CompletedTask;
}
public Task AdoptAsync(string folder, CancellationToken cancellationToken = default) => OpenAsync(folder, cancellationToken);
private void Remember(string path)
private async Task OpenAsync(string path, CancellationToken cancellationToken)
{
settings.LastArchivePath = Path.GetFullPath(path);
save();
var archives = services.Archives ?? throw new InvalidOperationException("The index is not open.", services.OpenError);
var root = Path.GetFullPath(path);
var archive = await Task.Run(async () =>
{
Directory.CreateDirectory(root);
return await archives.AdoptAsync(root, null, cancellationToken).ConfigureAwait(false);
}, cancellationToken);
services.Settings.LastArchivePath = root;
services.SaveSettings();
await services.QueueScanAsync(archive, full: true, cancellationToken);
Log.Info("archive", $"Archive {archive.Name} ready at {root}");
}
}
/// <summary>Runs an archive action from the UI; a failure becomes a toast instead of an unhandled exception.</summary>
public static class ArchiveActions
{
public static async Task<bool> TryAsync(Shell.ShellViewModel shell, Func<IArchiveSetup, Task> action)
{
try
{
await action(shell.Services.ArchiveSetup);
return true;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException or InvalidDataException
or Data.DatabaseException)
{
Log.Error("archive", "Archive action failed", ex);
shell.Notify(Core.Localization.Loc.L("Errors.Archive.Open"), ex.Message);
return false;
}
}
}