Files
Chronos/src/Titano.App/Import/CardPool.cs
T
Claude a0e814885c feat(app): Import and Archive manager screens with capture scenes and resources
Import (cards and folders): the card pool with remembered profiles and the
nickname field for new cards, the form (destination, scan, sessions, names
with live preview and tokens, duplicates, after-import choices), the plan
panel with editable session titles, Show plan, the archive import job or
the folder/server run with progress, the verification result and the
after-import actions (dry run, delete, format through the Windows dialog,
eject, open in Library), card-insertion toasts, automatic import into the
archive and resume after re-insertion. Deep analysis after import is queued
with ProcessingJobs at background priority.

Archive manager: archive picker, tree with availability, figure tiles and
charts, mass operations on the selected set, scan/rebuild (dialog)/verify/
duplicates/orphans/adopt/maintenance as jobs, and the maintenance view with
index health, recent runs and the duplicate and orphan reports with safe
fixes.

--capture renders import-<state> and archive-<view> from a simulated card
and sample reports; en and it resources for both screens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 22:20:10 +00:00

102 lines
4.6 KiB
C#

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>"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", Formatting.Bytes(Device!.FreeBytes)),
_ when Device is not null => Loc.L("Import.Device.Card", 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>();
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;
}
}