feat(app): import and archive manager logic (plans, card pool, card gate, server sink, tree, charts, reports)

Plain classes behind the Import and Archive screens: plan totals, session
rows and the Show plan listing; duplicate and title choices without a new
scan; folder and server destinations with the protocol client's chunked,
hash-verified uploads; the after-import gate that allows deleting or
formatting a card only after a verified archive import and a dry run; the
archive tree, chart aggregation, mass rename/retag and maintenance reports.

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 17:39:03 +00:00
1 parent 7d95536096
commit f7affe7840
22 files changed
+2258

No files matched your search

+102
View File
@@ -0,0 +1,102 @@
using System.Globalization;
using Titano.App.Infrastructure;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Core.Naming;
namespace Titano.App.Import;
public enum SourceKind
{
/// <summary>A card with a DCIM tree, or a remembered card.</summary>
Card,
/// <summary>A removable drive without DCIM: imported as a plain folder tree.</summary>
Drive,
/// <summary>A folder picked with "Folder…".</summary>
Folder,
}
/// <summary>
/// One entry of the Devices list (BRIEF §12.4, §13 card pool): an inserted volume joined with its remembered card, a
/// remembered card that is not inserted, or a picked folder. <see cref="Key"/> is the card identity or the folder path.
/// </summary>
public sealed record ImportSource(string Key, SourceKind Kind, CardDevice? Device, MediaCard? Card, string? FolderPath)
{
public bool IsInserted => Device is not null || FolderPath is not null;
public bool IsKnown => Card is not null;
/// <summary>Where the photos are read from; null for a remembered card that is not inserted.</summary>
public string? Root => Device?.Root ?? FolderPath;
/// <summary>"EOS R5 · card A", the volume label, or the drive.</summary>
public string Title => Card?.Nickname is { Length: > 0 } nickname ? nickname
: Device is { Label.Length: > 0 } labelled ? labelled.Label
: Device?.Root ?? FolderPath ?? Card?.Label ?? string.Empty;
/// <summary>"E:\ · 128 GB · 96.2 GB used", "no DCIM · 1.8 TB free", "Canon EOS R5 · not inserted".</summary>
public string Subtitle => Kind switch
{
SourceKind.Folder => FolderPath ?? string.Empty,
SourceKind.Drive => Loc.L("Import.Device.NoDcim", Device!.Root, Formatting.Bytes(Device.FreeBytes)),
_ when Device is not null => Loc.L("Import.Device.Card", Device.Root, Formatting.Bytes(Device.TotalBytes), Formatting.Bytes(Device.UsedBytes)),
_ => Loc.L("Import.Device.Away", CameraText(Card) is { Length: > 0 } camera ? camera : Formatting.Bytes(Card!.Capacity)),
};
/// <summary>"Known card", "New card", … for the state dot's tooltip.</summary>
public string StateText => Loc.L(Kind switch
{
SourceKind.Folder => "Import.Device.State.Folder",
SourceKind.Drive => "Import.Device.State.Drive",
_ when !IsInserted => "Import.Device.State.Away",
_ when IsKnown => "Import.Device.State.Known",
_ => "Import.Device.State.New",
});
/// <summary>"128 GB · serial 3F2A-9C11 · Canon EOS R5 #0431": the identity line of the profile header.</summary>
public string IdentityText
{
get
{
var parts = new List<string>();
if (Device is not null) parts.Add(Device.Root);
var capacity = Device?.TotalBytes ?? Card?.Capacity ?? 0;
if (capacity > 0) parts.Add(Formatting.Bytes(capacity));
var serial = Device?.SerialNumber ?? Card?.VolumeSerial;
if (serial is { } s && Kind != SourceKind.Folder) parts.Add(Loc.L("Import.Device.Serial", SerialText(s)));
if (CameraText(Card) is { Length: > 0 } camera) parts.Add(Card?.CameraSerial is { Length: > 0 } body ? Loc.L("Import.Device.Body", camera, body) : camera);
return string.Join(" · ", parts);
}
}
/// <summary>"3F2A-9C11", as Windows shows a volume serial.</summary>
public static string SerialText(uint serial)
{
var hex = serial.ToString("X8", CultureInfo.InvariantCulture);
return hex[..4] + "-" + hex[4..];
}
private static string CameraText(MediaCard? card) => card is null ? string.Empty : PathTemplate.CameraName(card.CameraMake, card.CameraModel);
}
/// <summary>Builds the Devices list: inserted volumes first (in drive order), then remembered cards, then a picked folder.</summary>
public static class CardPool
{
public static IReadOnlyList<ImportSource> Build(IEnumerable<CardDevice> devices, IEnumerable<MediaCard> cards, string? folder)
{
var known = cards.ToDictionary(c => c.Identity, StringComparer.Ordinal);
var list = new List<ImportSource>();
foreach (var device in devices.OrderBy(d => d.Root, StringComparer.OrdinalIgnoreCase))
{
known.Remove(device.Identity, out var card);
var kind = device.HasDcim || card is not null ? SourceKind.Card : SourceKind.Drive;
list.Add(new ImportSource(device.Identity, kind, device, card, null));
}
foreach (var card in known.Values.OrderByDescending(c => c.LastSeen))
list.Add(new ImportSource(card.Identity, SourceKind.Card, null, card, null));
if (folder is not null) list.Add(new ImportSource(folder, SourceKind.Folder, null, null, folder));
return list;
}
}