From f7affe7840ed8519de979f540bb8c54df9dd2cb2 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 17:39:03 +0000 Subject: [PATCH 01/16] 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 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- i18n/en/Archive.resx | 46 ++++ i18n/en/Import.resx | 53 ++++ i18n/it/Archive.it.resx | 40 +++ i18n/it/Import.it.resx | 49 ++++ src/Titano.App/Archive/ArchiveFigures.cs | 168 ++++++++++++ src/Titano.App/Archive/ArchiveTree.cs | 130 ++++++++++ src/Titano.App/Archive/MaintenanceReports.cs | 93 +++++++ src/Titano.App/Archive/MassOperations.cs | 82 ++++++ src/Titano.App/Import/CardActions.cs | 62 +++++ src/Titano.App/Import/CardDevice.cs | 61 +++++ src/Titano.App/Import/CardPool.cs | 102 ++++++++ src/Titano.App/Import/ImportChoices.cs | 94 +++++++ src/Titano.App/Import/ImportDestinations.cs | 147 +++++++++++ src/Titano.App/Import/ImportPlans.cs | 205 +++++++++++++++ src/Titano.App/Import/ServerImportSink.cs | 51 ++++ .../Archive/ArchiveLogicTests.cs | 243 ++++++++++++++++++ .../Titano.App.Tests/Import/CardPoolTests.cs | 65 +++++ .../Import/ImportChoicesTests.cs | 69 +++++ .../Import/ImportFlowTests.cs | 139 ++++++++++ .../Import/ImportPlansTests.cs | 136 ++++++++++ .../Titano.App.Tests/Import/ImportTestData.cs | 76 ++++++ .../Import/ServerImportSinkTests.cs | 147 +++++++++++ 22 files changed, 2258 insertions(+) create mode 100644 src/Titano.App/Archive/ArchiveFigures.cs create mode 100644 src/Titano.App/Archive/ArchiveTree.cs create mode 100644 src/Titano.App/Archive/MaintenanceReports.cs create mode 100644 src/Titano.App/Archive/MassOperations.cs create mode 100644 src/Titano.App/Import/CardActions.cs create mode 100644 src/Titano.App/Import/CardDevice.cs create mode 100644 src/Titano.App/Import/CardPool.cs create mode 100644 src/Titano.App/Import/ImportChoices.cs create mode 100644 src/Titano.App/Import/ImportDestinations.cs create mode 100644 src/Titano.App/Import/ImportPlans.cs create mode 100644 src/Titano.App/Import/ServerImportSink.cs create mode 100644 tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs create mode 100644 tests/Titano.App.Tests/Import/CardPoolTests.cs create mode 100644 tests/Titano.App.Tests/Import/ImportChoicesTests.cs create mode 100644 tests/Titano.App.Tests/Import/ImportFlowTests.cs create mode 100644 tests/Titano.App.Tests/Import/ImportPlansTests.cs create mode 100644 tests/Titano.App.Tests/Import/ImportTestData.cs create mode 100644 tests/Titano.App.Tests/Import/ServerImportSinkTests.cs diff --git a/i18n/en/Archive.resx b/i18n/en/Archive.resx index a5952f47..3c1d2424 100644 --- a/i18n/en/Archive.resx +++ b/i18n/en/Archive.resx @@ -4,6 +4,16 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + {0} · {1} · {2}invariant + {0:N0} other + {0:N0} others + Other + {0} · {1} · {2}invariant + Unknown camera + {0} · {1} · {2}invariant + {0:N0} copy + {0:N0} copies + {0} · {1}invariant No archive yet Another Titano ({0}) is writing here. Try again shortly.long: error sentence The copy of {0} does not match the original.long: error sentence @@ -14,6 +24,20 @@ {0} changed after the plan was made.long: error sentence The card or folder {0} is no longer available.long: error sentence The archive changed after this plan was made.long: error sentence + Every sequence verified + Every sequence analysed + {0} missing · {1} damaged + {0:N0} duplicate frame + {0:N0} duplicate frames + No missing frames + No duplicate frames + {0:N0} sequence lacks proxies + {0:N0} sequences lack proxies + {0:N0} sequence not analysed + {0:N0} sequences not analysed + Every sequence has proxies + {0:N0} sequence unverified + {0:N0} sequences unverified Dry run: nothing was changed.long: job log line Not indexed: {0} ({1})long: job log line Changed: {0}long: job log line @@ -27,4 +51,26 @@ {0} folders, {1} indexed, {2} adopted, {3} removedlong: job log line Sequence not found: {0}long: job log line {0} photos checked, {1} intact, {2} hashed, {3} with problemslong: job log line + {0:N0} file missing + {0:N0} files missing + Not indexed yet + No sidecar in {0}long + {0:N0} photo not in sidecar + {0:N0} photos not in sidecar + {0} · {1}invariant + {0:N0} of {1:N0} changes + {0:N0} of {1:N0} change + Each tag has 1 to {0} characters.long + camera + cameras + {0:N0} format + {0:N0} formats + originals + {0} to analyse · {1} to verifylong + photo + photos + sequence + sequences + {0} – {1}invariant + Undated diff --git a/i18n/en/Import.resx b/i18n/en/Import.resx index 1dd4adb7..6443da66 100644 --- a/i18n/en/Import.resx +++ b/i18n/en/Import.resx @@ -4,5 +4,58 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Import again + Copy + Already in archive + Imported before + Formatting needs a complete import with verified copies.long + Only for a remembered card that is inserted.long + Check the card first: every file and its copy are hashed again.long + Some photos on the card have no verified copy; formatting would lose them.long + Only imports into this PC's archive can be checked against the card.long + Nothing from this card has been imported yet.long + No photo on the card matches a verified copy.long + copy {0} ({1}) + {0:N0} file + {0:N0} files + Session {0} · {1}long + Cannot read {0}: {1}long + {0} · not insertedlong + {0} #{1}invariant + {0} · {1} · {2} used + {0} · no DCIM · {1} free + serial {0} + Known card, not inserted + Drive without DCIM + Folder + Known card + New card Insert a card or pick a folder + {0:N0} kept + {0:N0} kept + {0} · {1}invariant + the archive copy differs + the archive copy is missing + verified + changed on the card + no longer on the card + {0:N0} verified on the card + {0:N0} verified on the card + about {0} + {0:N0} duplicate + {0:N0} duplicates + {0} free after import + {0:N0} imported before + {0:N0} imported before + {0:N0} session + {0:N0} sessions + {0} missing + No archive copy after the import; see the job log.long + Adds to · {0}long + {0} · {1}invariant + New · {0}long + Server + {0} · {1} → {2}invariant + Import {0:N0} photo + Import {0:N0} photos diff --git a/i18n/it/Archive.it.resx b/i18n/it/Archive.it.resx index 62523790..3c0c36a7 100644 --- a/i18n/it/Archive.it.resx +++ b/i18n/it/Archive.it.resx @@ -4,6 +4,12 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + {0:N0} altra + {0:N0} altre + Altro + Fotocamera ignota + {0:N0} copia + {0:N0} copie Nessun archivio Un altro Titano ({0}) sta scrivendo qui. Riprova tra poco. La copia di {0} non corrisponde all'originale. @@ -14,6 +20,20 @@ {0} è cambiato dopo la creazione del piano. La scheda o cartella {0} non è più disponibile. L'archivio è cambiato dopo la creazione del piano. + Tutte le sequenze verificate + Tutte le sequenze analizzate + {0} mancanti · {1} danneggiati + {0:N0} fotogramma doppio + {0:N0} fotogrammi doppi + Nessun fotogramma mancante + Nessun fotogramma doppio + {0:N0} sequenza senza proxy + {0:N0} sequenze senza proxy + {0:N0} sequenza non analizzata + {0:N0} sequenze non analizzate + Proxy pronti per tutte + {0:N0} sequenza non verificata + {0:N0} sequenze non verificate Prova: nulla è stato modificato. Non indicizzata: {0} ({1}) Modificato: {0} @@ -27,4 +47,24 @@ {0} cartelle, {1} indicizzate, {2} adottate, {3} rimosse Sequenza non trovata: {0} {0} foto controllate, {1} integre, {2} con impronta nuova, {3} con problemi + {0:N0} file mancante + {0:N0} file mancanti + Non ancora indicizzata + Nessun sidecar in {0} + {0:N0} foto fuori dal sidecar + {0:N0} foto fuori dal sidecar + {0:N0} di {1:N0} cambia + {0:N0} di {1:N0} cambiano + Ogni tag ha da 1 a {0} caratteri. + fotocamera + fotocamere + {0:N0} formato + {0:N0} formati + originali + {0} da analizzare · {1} da verificare + foto + foto + sequenza + sequenze + Senza data diff --git a/i18n/it/Import.it.resx b/i18n/it/Import.it.resx index 1d75e138..eec667fb 100644 --- a/i18n/it/Import.it.resx +++ b/i18n/it/Import.it.resx @@ -4,5 +4,54 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Importa di nuovo + Copia + Già in archivio + Già importata + Per formattare serve un'importazione completa con copie verificate. + Solo per una scheda nota e inserita. + Controlla prima la scheda: ogni file e la sua copia vengono verificati di nuovo. + Alcune foto della scheda non hanno una copia verificata: formattando andrebbero perse. + Solo le importazioni nell'archivio di questo PC si possono confrontare con la scheda. + Da questa scheda non è ancora stato importato nulla. + Nessuna foto della scheda corrisponde a una copia verificata. + copia {0} ({1}) + {0:N0} file + {0:N0} file + Sessione {0} · {1} + Impossibile leggere {0}: {1} + {0} · non inserita + {0} · {1} · {2} occupati + {0} · senza DCIM · {1} liberi + seriale {0} + Scheda nota, non inserita + Unità senza DCIM + Cartella + Scheda nota + Nuova scheda Inserisci una scheda o una cartella + {0:N0} conservata + {0:N0} conservate + la copia in archivio è diversa + manca la copia in archivio + verificata + modificata sulla scheda + non più sulla scheda + {0:N0} verificata sulla scheda + {0:N0} verificate sulla scheda + circa {0} + {0:N0} doppione + {0:N0} doppioni + {0} liberi dopo l'import + {0:N0} già importata + {0:N0} già importate + {0:N0} sessione + {0:N0} sessioni + mancano {0} + Nessuna copia in archivio dopo l'importazione: vedi il registro dell'attività. + Si aggiunge a · {0} + Nuova · {0} + Server + Importa {0:N0} foto + Importa {0:N0} foto diff --git a/src/Titano.App/Archive/ArchiveFigures.cs b/src/Titano.App/Archive/ArchiveFigures.cs new file mode 100644 index 00000000..b66e2872 --- /dev/null +++ b/src/Titano.App/Archive/ArchiveFigures.cs @@ -0,0 +1,168 @@ +using System.Globalization; +using Titano.App.Infrastructure; +using Titano.Core.Imaging; +using Titano.Core.Localization; +using Titano.Core.Naming; +using Titano.Data.Repositories; + +namespace Titano.App.Archiving; + +/// A bar of a chart: label, magnitude, the text after the bar and the hover text. +public sealed record BarValue(string Label, double Value, string ValueText, string ToolTip); + +/// A heatmap row (one year): photos per month, NaN for months still to come. +public sealed record HeatRow(string Label, IReadOnlyList Values, IReadOnlyList ToolTips); + +/// A figure tile of the Archive screen ("618,204" over "photos"). +public sealed record ArchiveTile(string Value, string Caption); + +public enum HealthAction +{ + None, + Verify, + Proxies, + Analyse, + Duplicates, + Orphans, +} + +/// One line of "Index health": ok or warning, what it found, and the fix it offers. +public sealed record HealthLine(bool IsOk, string Text, HealthAction Action); + +/// +/// Turns the index statistics into the Archive screen's figures (BRIEF §12.5, Archive.html): tiles, photos per month +/// (heatmap, year rows × 12 months), storage by year, the top cameras and formats by photos (the rest folded into one +/// bar), and the index health lines. +/// +public static class ArchiveFigures +{ + public const int TopCameras = 5; + public const int TopFormats = 6; + + public static IReadOnlyList Tiles(ArchiveStats stats) + { + var years = stats.ByYear.Select(y => y.Year).ToList(); + var range = years.Count == 0 ? "—" + : years.Min() == years.Max() ? Year(years.Min()) + : Loc.L("Archive.Tile.YearRange", Year(years.Min()), Year(years.Max())); + var cameras = stats.ByCamera.Count(c => !string.IsNullOrWhiteSpace(c.Model) || !string.IsNullOrWhiteSpace(c.Make)); + return + [ + new(Formatting.Count(stats.Photos), Loc.Plural("Archive.Tile.Photos", stats.Photos)), + new(Formatting.Count(stats.Sequences), Loc.Plural("Archive.Tile.Sequences", stats.Sequences)), + new(Formatting.Bytes(stats.Bytes), Loc.L("Archive.Tile.Originals")), + new(Formatting.Count(cameras), Loc.Plural("Archive.Tile.Cameras", cameras) + " · " + Loc.Plural("Archive.Tile.Formats", stats.ByFormat.Count)), + new(range, Loc.L("Archive.Tile.Pending", Formatting.Count(stats.Health.NotAnalyzed), Formatting.Count(stats.Health.Unverified))), + ]; + } + + /// Culture month initials for the heatmap columns ("J F M …", "G F M …"). + public static IReadOnlyList MonthLabels() => + [.. Loc.Culture.DateTimeFormat.AbbreviatedMonthNames.Take(12).Select(m => m.Length == 0 ? string.Empty : char.ToUpper(m[0], Loc.Culture).ToString())]; + + /// One row per year from the first to the last with photos, oldest first; months after are NaN. + public static IReadOnlyList PhotosPerMonth(ArchiveStats stats, DateTime today) + { + if (stats.ByMonth.Count == 0) return []; + var byKey = stats.ByMonth.ToDictionary(m => (m.Year, m.Month)); + var first = stats.ByMonth.Min(m => m.Year); + var last = System.Math.Max(stats.ByMonth.Max(m => m.Year), first); + var rows = new List(last - first + 1); + for (var year = first; year <= last; year++) + { + var values = new double[12]; + var tips = new string?[12]; + for (var month = 1; month <= 12; month++) + { + var future = year > today.Year || (year == today.Year && month > today.Month); + byKey.TryGetValue((year, month), out var bucket); + values[month - 1] = future ? double.NaN : bucket?.Photos ?? 0; + tips[month - 1] = future ? null : Loc.L("Archive.Chart.MonthTip", new DateTime(year, month, 1).ToString("Y", Loc.Culture), + Loc.Plural("Shell.Status.Photos", bucket?.Photos ?? 0), Loc.Plural("Shell.Status.Sequences", bucket?.Sequences ?? 0)); + } + rows.Add(new HeatRow(Year(year), values, tips)); + } + return rows; + } + + /// Bytes of originals per capture year, oldest first. + public static IReadOnlyList StorageByYear(ArchiveStats stats) => + [ + .. stats.ByYear.OrderBy(y => y.Year).Select(y => new BarValue(Year(y.Year), y.Bytes, Formatting.Bytes(y.Bytes), + Loc.L("Archive.Chart.YearTip", Year(y.Year), Formatting.Bytes(y.Bytes), Loc.Plural("Shell.Status.Sequences", y.Sequences)))), + ]; + + /// Photos per camera: the largest, then "n others". + public static IReadOnlyList ByCamera(ArchiveStats stats) + { + var cameras = stats.ByCamera + .GroupBy(c => PathTemplate.CameraName(c.Make, c.Model) is { Length: > 0 } name ? name : Loc.L("Archive.Chart.UnknownCamera"), StringComparer.Ordinal) + .Select(g => (Name: g.Key, Photos: g.Sum(c => c.Photos))) + .OrderByDescending(c => c.Photos).ThenBy(c => c.Name, StringComparer.CurrentCultureIgnoreCase) + .ToList(); + return Shares(cameras, TopCameras, rest => Loc.Plural("Archive.Chart.OtherCameras", rest), stats.Photos); + } + + /// Photos per file format: the largest, then "Other". + public static IReadOnlyList ByFormat(ArchiveStats stats) + { + var formats = stats.ByFormat + .GroupBy(f => FormatName(f.Format), StringComparer.Ordinal) + .Select(g => (Name: g.Key, Photos: g.Sum(f => f.Photos))) + .OrderByDescending(f => f.Photos).ThenBy(f => f.Name, StringComparer.Ordinal) + .ToList(); + return Shares(formats, TopFormats, _ => Loc.L("Archive.Chart.OtherFormats"), formats.Sum(f => f.Photos)); + } + + /// "CR2", "JPEG", "3FR": the format as photographers name it. + public static string FormatName(ImageFileFormat format) => format switch + { + ImageFileFormat.Unknown => Loc.L("Archive.Chart.OtherFormats"), + ImageFileFormat.ThreeFr => "3FR", + ImageFileFormat.JpegXl => "JXL", + ImageFileFormat.JpegXr => "JXR", + ImageFileFormat.WebP => "WebP", + _ => format.ToString().ToUpperInvariant(), + }; + + /// Index health (Archive.html): what needs attention, each with its fix. + public static IReadOnlyList Health(ArchiveStats stats, int withoutProxies) + { + var h = stats.Health; + var damaged = h.MissingFrames + h.CorruptFrames; + return + [ + h.Unverified == 0 + ? new HealthLine(true, Loc.L("Archive.Health.AllVerified"), HealthAction.None) + : new HealthLine(false, Loc.Plural("Archive.Health.Unverified", h.Unverified), HealthAction.Verify), + damaged == 0 + ? new HealthLine(true, Loc.L("Archive.Health.FramesOk"), HealthAction.None) + : new HealthLine(false, Loc.L("Archive.Health.Damaged", Formatting.Count(h.MissingFrames), Formatting.Count(h.CorruptFrames)), HealthAction.Orphans), + withoutProxies == 0 + ? new HealthLine(true, Loc.L("Archive.Health.ProxiesOk"), HealthAction.None) + : new HealthLine(false, Loc.Plural("Archive.Health.NoProxies", withoutProxies), HealthAction.Proxies), + h.NotAnalyzed == 0 + ? new HealthLine(true, Loc.L("Archive.Health.AnalysedOk"), HealthAction.None) + : new HealthLine(false, Loc.Plural("Archive.Health.NotAnalysed", h.NotAnalyzed), HealthAction.Analyse), + h.DuplicateFrames == 0 + ? new HealthLine(true, Loc.L("Archive.Health.NoDuplicates"), HealthAction.None) + : new HealthLine(false, Loc.Plural("Archive.Health.Duplicates", h.DuplicateFrames), HealthAction.Duplicates), + ]; + } + + private static IReadOnlyList Shares(List<(string Name, long Photos)> ranked, int top, Func restLabel, long total) + { + var bars = new List(top + 1); + foreach (var (name, photos) in ranked.Take(top)) bars.Add(Bar(name, photos, total)); + if (ranked.Count > top) bars.Add(Bar(restLabel(ranked.Count - top), ranked.Skip(top).Sum(c => c.Photos), total)); + return bars; + } + + private static BarValue Bar(string label, long photos, long total) + { + var share = Formatting.Percent(total > 0 ? photos / (double)total : 0); + return new BarValue(label, photos, share, Loc.L("Archive.Chart.ShareTip", label, Loc.Plural("Shell.Status.Photos", photos), share)); + } + + private static string Year(int year) => year.ToString(CultureInfo.InvariantCulture); +} diff --git a/src/Titano.App/Archive/ArchiveTree.cs b/src/Titano.App/Archive/ArchiveTree.cs new file mode 100644 index 00000000..23d287df --- /dev/null +++ b/src/Titano.App/Archive/ArchiveTree.cs @@ -0,0 +1,130 @@ +using System.Globalization; +using Titano.App.Infrastructure; +using Titano.Core.Archiving; +using Titano.Core.Localization; +using Titano.Core.Model; + +namespace Titano.App.Archiving; + +public enum TreeNodeKind +{ + Archive, + Year, + Sequence, +} + +/// A node of the archive tree: the archive, a capture year, or a sequence. +public sealed class ArchiveTreeNode +{ + private readonly List _children = []; + + internal ArchiveTreeNode(TreeNodeKind kind, string key, int depth) + { + Kind = kind; + Key = key; + Depth = depth; + } + + public TreeNodeKind Kind { get; } + + /// Stable across rebuilds: the archive id, the year, or the sequence id. + public string Key { get; } + + public int Depth { get; } + public required string Title { get; init; } + + /// "18 sequences · 2.1 TB", "3,600 photos · 72 GB". + public required string Detail { get; init; } + + public Sequence? Sequence { get; init; } + public bool IsExpanded { get; set; } + public IReadOnlyList Children => _children; + public bool HasChildren => _children.Count > 0; + + internal void Add(ArchiveTreeNode child) => _children.Add(child); + + /// The sequences this node stands for (itself, or all below it). + public IEnumerable Sequences() => Sequence is { } own ? [own] : _children.SelectMany(c => c.Sequences()); +} + +/// +/// The Archive screen's tree (BRIEF §12.5): the archive with its availability, its capture years (newest first) and +/// their sequences (newest first), flattened into the visible rows of a virtualised list. Undated sequences sit under +/// their own node after the years. +/// +public sealed class ArchiveTree +{ + private ArchiveTree(ArchiveTreeNode root, ArchiveAvailability availability) + { + Root = root; + Availability = availability; + } + + public ArchiveTreeNode Root { get; } + public ArchiveAvailability Availability { get; } + + public static ArchiveTree Build(Core.Model.Archive archive, ArchiveAvailability availability, IReadOnlyList sequences) + { + var root = new ArchiveTreeNode(TreeNodeKind.Archive, archive.Id.ToString("N"), 0) + { + Title = archive.Name, + Detail = Summary(sequences), + IsExpanded = true, + }; + foreach (var year in sequences.GroupBy(s => s.FirstCapture?.Year).OrderByDescending(g => g.Key ?? int.MinValue)) + { + var members = year.OrderByDescending(s => s.FirstCapture).ThenBy(s => s.DisplayTitle, StringComparer.CurrentCultureIgnoreCase).ToList(); + var node = new ArchiveTreeNode(TreeNodeKind.Year, year.Key?.ToString(CultureInfo.InvariantCulture) ?? "undated", 1) + { + Title = year.Key?.ToString(CultureInfo.InvariantCulture) ?? Loc.L("Archive.Tree.Undated"), + Detail = Summary(members), + }; + foreach (var s in members) + { + node.Add(new ArchiveTreeNode(TreeNodeKind.Sequence, s.Id.ToString("N"), 2) + { + Title = s.DisplayTitle, + Detail = Loc.Plural("Shell.Status.Photos", s.FrameCount) + " · " + Formatting.Bytes(s.TotalBytes), + Sequence = s, + }); + } + root.Add(node); + } + return new ArchiveTree(root, availability); + } + + /// Rows to show: every node whose ancestors are all expanded, depth first. + public IReadOnlyList Visible() + { + var rows = new List(); + void Walk(ArchiveTreeNode node) + { + rows.Add(node); + if (!node.IsExpanded) return; + foreach (var child in node.Children) Walk(child); + } + Walk(Root); + return rows; + } + + /// Expands the nodes whose keys are given (restoring the state after a refresh). + public void Expand(IReadOnlySet keys) + { + foreach (var year in Root.Children) year.IsExpanded = keys.Contains(year.Key); + } + + /// Keys of the expanded year nodes. + public IReadOnlySet ExpandedKeys() => Root.Children.Where(c => c.IsExpanded).Select(c => c.Key).ToHashSet(StringComparer.Ordinal); + + /// The set mass operations act on: the sequences of the selected nodes, each once; all of them when nothing is selected. + public static IReadOnlyList SetOf(ArchiveTree tree, IEnumerable selected) + { + var chosen = selected.ToList(); + var source = chosen.Count == 0 ? tree.Root.Sequences() : chosen.SelectMany(n => n.Sequences()); + var seen = new HashSet(); + return [.. source.Where(s => seen.Add(s.Id))]; + } + + private static string Summary(IReadOnlyCollection sequences) => + Loc.Plural("Shell.Status.Sequences", sequences.Count) + " · " + Formatting.Bytes(sequences.Sum(s => s.TotalBytes)); +} diff --git a/src/Titano.App/Archive/MaintenanceReports.cs b/src/Titano.App/Archive/MaintenanceReports.cs new file mode 100644 index 00000000..6a551755 --- /dev/null +++ b/src/Titano.App/Archive/MaintenanceReports.cs @@ -0,0 +1,93 @@ +using Titano.App.Infrastructure; +using Titano.App.Jobs; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Data.Archiving; +using Titano.Data.Repositories; + +namespace Titano.App.Archiving; + +/// A group of identical photos: the copies and where they are; the first one counts as the original. +public sealed record DuplicateRow(string Title, string Detail, IReadOnlyList Places, Guid SequenceId); + +/// What an orphan line is about, which decides its fix. +public enum OrphanKind +{ + /// Photos in a sequence folder that its sidecar does not list: fix = index them. + UnlistedFiles, + + /// Frames whose file is gone: fix = reconcile (flags them missing in sidecar and index). + MissingFiles, + + /// An index row whose folder has no sidecar any more: fix = remove the row (after confirmation). + MissingSequence, + + /// A folder with photos the index does not know yet: fix = scan. + NewFolder, +} + +/// One line of the orphans report and the target of its fix. +public sealed record OrphanRow(OrphanKind Kind, string Title, string Detail, Guid? SequenceId); + +/// A line of "Recent maintenance": date, operation and outcome. +public sealed record MaintenanceRow(Guid JobId, string DateText, string Text, string StateText, JobState State); + +/// +/// The Maintenance view's reports (BRIEF §12.5): duplicates across sequences, orphans with their safe fixes, and the +/// recent archive jobs. Nothing here deletes a file; the only removal is of index rows whose sidecar is gone. +/// +public static class MaintenanceReports +{ + /// Kinds of jobs listed under "Recent maintenance". + public static readonly IReadOnlyList MaintenanceKinds = [JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.Maintenance]; + + public static IReadOnlyList Duplicates(IReadOnlyList groups, IReadOnlyList locations) + { + var titles = locations.ToDictionary(l => l.Id, l => l.Title ?? l.Folder[(l.Folder.LastIndexOf('/') + 1)..]); + return + [ + .. groups.Where(g => g.Frames.Count > 1).Select(g => + { + var first = g.Frames[0]; + var name = first.RelativePath[(first.RelativePath.LastIndexOf('/') + 1)..]; + var places = g.Frames.Select(f => Loc.L("Archive.Duplicates.Place", titles.GetValueOrDefault(f.SequenceId, f.RelativePath), f.RelativePath)).ToList(); + return new DuplicateRow(name, Loc.Plural("Archive.Duplicates.Copies", g.Frames.Count), places, first.SequenceId); + }), + ]; + } + + public static IReadOnlyList Orphans(OrphanReport report, IReadOnlyList locations) + { + var byFolder = locations.ToDictionary(l => l.Folder, StringComparer.Ordinal); + var rows = new List(); + foreach (var s in report.Sequences) + { + byFolder.TryGetValue(s.Folder, out var location); + var title = location?.Title ?? s.Folder; + if (s.UnindexedFiles.Count > 0) + rows.Add(new OrphanRow(OrphanKind.UnlistedFiles, title, Loc.Plural("Archive.Orphans.Unlisted", s.UnindexedFiles.Count), location?.Id)); + if (s.MissingFiles.Count > 0) + rows.Add(new OrphanRow(OrphanKind.MissingFiles, title, Loc.Plural("Archive.Orphans.Missing", s.MissingFiles.Count), location?.Id)); + } + foreach (var missing in report.MissingSequences) + rows.Add(new OrphanRow(OrphanKind.MissingSequence, missing.Title ?? missing.Folder, Loc.L("Archive.Orphans.NoSidecar", missing.Folder), missing.Id)); + foreach (var folder in report.UnindexedFolders) + rows.Add(new OrphanRow(OrphanKind.NewFolder, folder.Length == 0 ? "/" : folder, Loc.L("Archive.Orphans.NewFolder"), null)); + return rows; + } + + public static IReadOnlyList Recent(IEnumerable jobs, int count) => + [ + .. jobs.OrderByDescending(j => j.Finished ?? j.Started ?? j.Created).Take(count).Select(j => + { + var when = j.Finished ?? j.Started ?? j.Created; + var text = string.IsNullOrWhiteSpace(j.TargetLabel) ? JobText.Kind(j.Kind) : Loc.L("Archive.Recent.Line", JobText.Kind(j.Kind), j.TargetLabel); + var state = j.State switch + { + JobState.Running when j.ProgressTotal > 0 => Formatting.Percent(j.ProgressDone / (double)j.ProgressTotal), + _ => Loc.L("Jobs.State." + j.State), + }; + return new MaintenanceRow(j.Id, Formatting.Date(when), text, state, j.State); + }), + ]; +} diff --git a/src/Titano.App/Archive/MassOperations.cs b/src/Titano.App/Archive/MassOperations.cs new file mode 100644 index 00000000..9f953f39 --- /dev/null +++ b/src/Titano.App/Archive/MassOperations.cs @@ -0,0 +1,82 @@ +using Titano.App.Settings; +using Titano.Core.Archiving; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Core.Naming; +using Titano.Data.Repositories; + +namespace Titano.App.Archiving; + +/// What a mass rename changes: the sequence titles (Rename) or the folder layout (Move). +public enum RenameMode +{ + Titles, + Folders, +} + +/// One line of the rename dry run: before → after. +public sealed record RenameRow(Guid SequenceId, string From, string To); + +/// +/// Mass rename and move of sequences (BRIEF §7, §12.5): the template is checked live, the engine's dry run +/// () is listed line by line, and applying makes exactly those changes. +/// +public static class MassRename +{ + /// The first problem of a template, localized; null when it can be used. + public static string? Validate(RenameMode mode, string? template) + { + if (string.IsNullOrWhiteSpace(template)) return Loc.L("Errors.Template.Empty", string.Empty, 1); + if (mode == RenameMode.Folders) return NamingPreview.Validate(template, isFolder: true); + var parsed = PathTemplate.Parse(template); + return parsed.Errors is [var error, ..] ? Loc.L("Errors.Template." + error.Code, error.Token ?? string.Empty, error.Position + 1) : null; + } + + /// The changes of a plan as rows: titles or folders, whichever the mode changes. + public static IReadOnlyList Rows(RenamePlan plan, RenameMode mode) => + [ + .. plan.Steps.Select(s => mode == RenameMode.Folders + ? new RenameRow(s.SequenceId, s.FromFolder, s.ToFolder) + : new RenameRow(s.SequenceId, s.FromTitle ?? string.Empty, s.ToTitle ?? string.Empty)), + ]; + + /// "12 of 36 sequences change". + public static string Summary(RenamePlan plan, int setSize) => Loc.Plural("Archive.Rename.Summary", plan.Steps.Count, setSize); +} + +/// Adding and removing tags on a set of sequences (BRIEF §12.5 Retag). +public static class Retag +{ + /// "sunset, harbour; Holy grail" → normalized, distinct tags; entries that cannot be tags are left out. + public static IReadOnlyList Parse(string? text) + { + var seen = new HashSet(StringComparer.OrdinalIgnoreCase); + return [.. Split(text).Where(IsValid).Select(TagRepository.Normalize).Where(seen.Add)]; + } + + /// The problem of a tag list as one sentence; null when every entry can be a tag. + public static string? Validate(string? text) => Split(text).All(IsValid) ? null : Loc.L("Archive.Retag.Invalid", TagRepository.MaxLength); + + private static IEnumerable Split(string? text) => + string.IsNullOrWhiteSpace(text) ? [] : text.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + private static bool IsValid(string tag) => tag.Length is > 0 and <= TagRepository.MaxLength && !tag.Any(char.IsControl); + + /// The new tag list of one sequence: removals first, then additions not already present. + public static IReadOnlyList Apply(IReadOnlyList current, IReadOnlyList add, IReadOnlyList remove) + { + var removed = new HashSet(remove, StringComparer.OrdinalIgnoreCase); + var result = current.Where(t => !removed.Contains(t)).ToList(); + var present = new HashSet(result, StringComparer.OrdinalIgnoreCase); + result.AddRange(add.Where(present.Add)); + return result; + } + + /// Only the sequences whose tags change, with their new tags (the dry run). + public static IReadOnlyList<(Sequence Sequence, IReadOnlyList Tags)> Changes(IEnumerable sequences, IReadOnlyList add, + IReadOnlyList remove) => + [ + .. sequences.Select(s => (Sequence: s, Tags: Apply(s.Tags, add, remove))) + .Where(c => !c.Tags.SequenceEqual(c.Sequence.Tags, StringComparer.Ordinal)), + ]; +} diff --git a/src/Titano.App/Import/CardActions.cs b/src/Titano.App/Import/CardActions.cs new file mode 100644 index 00000000..d4f9f8a5 --- /dev/null +++ b/src/Titano.App/Import/CardActions.cs @@ -0,0 +1,62 @@ +using Titano.App.Infrastructure; +using Titano.Core.Import; +using Titano.Core.Localization; + +namespace Titano.App.Import; + +/// +/// What may be done to the card after an import (BRIEF §0.2 rule 8, §12.4, §13). Deleting needs a recorded, +/// verified import into this PC's archive and a dry run that re-hashed every card file and its copy; formatting +/// needs, on top, a complete verified import and a dry run in which every photo still on the card is safe to delete. +/// Ejecting only needs a removable card. Each refusal comes with the sentence the button's tooltip shows. +/// +/// Photos on the card now (the scanner's count), for the format check. +public sealed record CardActions(ImportDestinationKind Destination, bool IsKnownCard, bool IsInserted, bool IsRemovable, ImportOutcome? Outcome, + ErasePlan? Erase, int CardPhotos) +{ + /// The dry run of "Delete imported" may start. + public bool CanCheck => CheckBlocker is null; + + public string? CheckBlocker => + Destination != ImportDestinationKind.Archive ? Loc.L("Import.Blocked.NotArchive") + : !IsKnownCard || !IsInserted ? Loc.L("Import.Blocked.NoCard") + : Outcome is not { Imported: > 0 } and not { Skipped: > 0 } ? Loc.L("Import.Blocked.NothingImported") + : null; + + public bool CanDelete => DeleteBlocker is null; + + public string? DeleteBlocker => + CheckBlocker ?? (Erase is null ? Loc.L("Import.Blocked.NoDryRun") : DeleteCount == 0 ? Loc.L("Import.Blocked.NothingVerified") : null); + + public bool CanFormat => FormatBlocker is null; + + public string? FormatBlocker => + DeleteBlocker + ?? (Outcome is not { IsComplete: true, Verified: true } ? Loc.L("Import.Blocked.Incomplete") + : KeptCount > 0 || DeleteCount < CardPhotos ? Loc.L("Import.Blocked.NotAllVerified") + : null); + + public bool CanEject => IsInserted && IsRemovable; + + public int DeleteCount => Erase?.ToDelete.Count() ?? 0; + + public long DeleteBytes => Erase?.ToDelete.Sum(i => i.Candidate.Size) ?? 0; + + public int KeptCount => Erase?.Items.Count(i => i.Verdict != EraseVerdict.Delete) ?? 0; + + /// "4,812 verified on the card · 96.2 GB · 2 kept": the dry run in one line; empty before it ran. + public string EraseText => Erase is null + ? string.Empty + : string.Join(" · ", new[] + { + Loc.Plural("Import.Erase.Verified", DeleteCount), + Formatting.Bytes(DeleteBytes), + KeptCount > 0 ? Loc.Plural("Import.Erase.Kept", KeptCount) : string.Empty, + }.Where(t => t.Length > 0)); + + /// Why each kept photo stays on the card ("IMG_0042.CR2 · the archive copy no longer matches"). + public IReadOnlyList KeptReasons => + Erase is null ? [] : [.. Erase.Items.Where(i => i.Verdict != EraseVerdict.Delete).Select(i => Loc.L("Import.Erase.Reason", i.Candidate.SourcePath, Verdict(i.Verdict)))]; + + public static string Verdict(EraseVerdict verdict) => Loc.L("Import.Erase.Verdict." + verdict); +} diff --git a/src/Titano.App/Import/CardDevice.cs b/src/Titano.App/Import/CardDevice.cs new file mode 100644 index 00000000..2aebdf71 --- /dev/null +++ b/src/Titano.App/Import/CardDevice.cs @@ -0,0 +1,61 @@ +using System.Globalization; +using Titano.Data.Archiving; + +namespace Titano.App.Import; + +/// +/// A volume the Import screen offers (BRIEF §12.4, §13): a removable volume, or any volume with a DCIM folder. +/// Card identity is {serial:X8}-{label}-{capacity}, stable across readers and drive letters. +/// +/// Root with trailing separator, e.g. E:\. +public sealed record CardDevice(string Root, string Label, uint SerialNumber, long TotalBytes, long FreeBytes, bool IsRemovable, bool HasDcim) +{ + public string Identity => string.Create(CultureInfo.InvariantCulture, $"{SerialNumber:X8}-{Label}-{TotalBytes}"); + + public long UsedBytes => System.Math.Max(0, TotalBytes - FreeBytes); + + public CardVolume ToVolume() => new(Identity, SerialNumber, Label.Length == 0 ? null : Label, TotalBytes); +} + +/// Outcome of a safe removal. +public enum EjectOutcome +{ + Ejected, + + /// Files on the card are still open; nothing changed. + InUse, + + /// Not a removable drive, or Windows refused. + Failed, +} + +/// Outcome of the operating system's format dialog (BRIEF §8.6). +public enum FormatOutcome +{ + Formatted, + Cancelled, + Failed, +} + +/// +/// Card detection and the two OS actions on a card (BRIEF §8.6, §13): safe removal and the Windows format dialog. +/// Events may arrive on any thread. +/// +public interface IDeviceMonitor : IDisposable +{ + event Action? Arrived; + + event Action? Removed; + + /// Candidate volumes present now. + IReadOnlyList Devices { get; } + + /// Starts watching (idempotent); the first snapshot raises no events. + void Start(); + + /// Locks, dismounts and ejects the volume; blocks for up to a few seconds. + EjectOutcome Eject(CardDevice device); + + /// Shows the Windows format dialog for the volume; call on the UI thread. + FormatOutcome Format(CardDevice device); +} diff --git a/src/Titano.App/Import/CardPool.cs b/src/Titano.App/Import/CardPool.cs new file mode 100644 index 00000000..1c0b13f3 --- /dev/null +++ b/src/Titano.App/Import/CardPool.cs @@ -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 +{ + /// A card with a DCIM tree, or a remembered card. + Card, + + /// A removable drive without DCIM: imported as a plain folder tree. + Drive, + + /// A folder picked with "Folder…". + Folder, +} + +/// +/// 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. is the card identity or the folder path. +/// +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; + + /// Where the photos are read from; null for a remembered card that is not inserted. + public string? Root => Device?.Root ?? FolderPath; + + /// "EOS R5 · card A", the volume label, or the drive. + 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; + + /// "E:\ · 128 GB · 96.2 GB used", "no DCIM · 1.8 TB free", "Canon EOS R5 · not inserted". + 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)), + }; + + /// "Known card", "New card", … for the state dot's tooltip. + 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", + }); + + /// "128 GB · serial 3F2A-9C11 · Canon EOS R5 #0431": the identity line of the profile header. + public string IdentityText + { + get + { + var parts = new List(); + 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); + } + } + + /// "3F2A-9C11", as Windows shows a volume serial. + 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); +} + +/// Builds the Devices list: inserted volumes first (in drive order), then remembered cards, then a picked folder. +public static class CardPool +{ + public static IReadOnlyList Build(IEnumerable devices, IEnumerable cards, string? folder) + { + var known = cards.ToDictionary(c => c.Identity, StringComparer.Ordinal); + var list = new List(); + 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; + } +} diff --git a/src/Titano.App/Import/ImportChoices.cs b/src/Titano.App/Import/ImportChoices.cs new file mode 100644 index 00000000..df2b009e --- /dev/null +++ b/src/Titano.App/Import/ImportChoices.cs @@ -0,0 +1,94 @@ +using Titano.Core.Import; +using Titano.Core.Naming; +using Titano.Data.Archiving; + +namespace Titano.App.Import; + +/// Where the photos go (BRIEF §12.4): this PC's archive, a plain folder, or the signed-in server. +public enum ImportDestinationKind +{ + Archive, + Folder, + Server, +} + +/// +/// The Import form (Import.html): scan, sessions, names, duplicates and after-import choices. Remembered per card as +/// its ; a session gap of 0 minutes in a profile means "do not split into sessions". +/// +public sealed record ImportChoices +{ + public ImportDestinationKind Destination { get; init; } = ImportDestinationKind.Archive; + public string? FolderPath { get; init; } + public bool IncludeSubfolders { get; init; } = true; + public bool SplitSessions { get; init; } = true; + public int GapMinutes { get; init; } = 45; + public int MinimumFrames { get; init; } = 8; + public bool VerifyCopies { get; init; } = true; + public string FolderTemplate { get; init; } = TemplateDefaults.Folder; + public string FileTemplate { get; init; } = TemplateDefaults.File; + public DuplicatePolicy Duplicates { get; init; } = DuplicatePolicy.Skip; + public AfterImport AfterImport { get; init; } = AfterImport.Keep; + public bool Eject { get; init; } = true; + public bool DeepAnalysis { get; init; } = true; + + /// A card's remembered choices. + public static ImportChoices FromProfile(CardProfile profile) => new() + { + IncludeSubfolders = profile.IncludeSubfolders, + SplitSessions = profile.SessionGapMinutes > 0, + GapMinutes = profile.SessionGapMinutes > 0 ? profile.SessionGapMinutes : new CardProfile().SessionGapMinutes, + MinimumFrames = profile.MinimumSessionFrames, + VerifyCopies = profile.VerifyCopies, + FolderTemplate = profile.FolderTemplate, + FileTemplate = profile.FileTemplate, + Duplicates = profile.Duplicates, + AfterImport = profile.AfterImport, + Eject = profile.Eject, + DeepAnalysis = profile.DeepAnalysis, + }; + + public CardProfile ToProfile() => new() + { + FolderTemplate = FolderTemplate, + FileTemplate = FileTemplate, + SessionGapMinutes = SplitSessions ? GapMinutes : 0, + MinimumSessionFrames = MinimumFrames, + IncludeSubfolders = IncludeSubfolders, + VerifyCopies = VerifyCopies, + Duplicates = Duplicates, + AfterImport = AfterImport, + Eject = Eject, + DeepAnalysis = DeepAnalysis, + }; + + /// Planner options; are the session titles typed in the plan, by session key. + public ImportOptions ToOptions(IReadOnlyDictionary? titles = null) => new() + { + FolderTemplate = FolderTemplate, + FileTemplate = FileTemplate, + // Without session splitting every camera body and format stays one session. + SessionGap = SplitSessions ? TimeSpan.FromMinutes(System.Math.Max(1, GapMinutes)) : TimeSpan.MaxValue, + MinimumSessionFrames = System.Math.Max(1, MinimumFrames), + IncludeSubfolders = IncludeSubfolders, + VerifyCopies = VerifyCopies, + Duplicates = Duplicates, + Titles = titles ?? new Dictionary(), + }; + + /// True when a choice changes which photos form which session or where they go, so the card must be planned again. + public bool NeedsNewPlan(ImportChoices previous) => + previous.Destination != Destination + || !string.Equals(previous.FolderPath, FolderPath, StringComparison.OrdinalIgnoreCase) + || previous.IncludeSubfolders != IncludeSubfolders + || previous.SplitSessions != SplitSessions + || (SplitSessions && previous.GapMinutes != GapMinutes) + || previous.MinimumFrames != MinimumFrames + || previous.FolderTemplate != FolderTemplate + || previous.FileTemplate != FileTemplate; + + /// Session titles feed the names only when a template uses {title}. + public bool TitlesChangeNames => UsesTitle(FolderTemplate) || UsesTitle(FileTemplate); + + private static bool UsesTitle(string template) => template.Contains("{title", StringComparison.OrdinalIgnoreCase); +} diff --git a/src/Titano.App/Import/ImportDestinations.cs b/src/Titano.App/Import/ImportDestinations.cs new file mode 100644 index 00000000..f97e9fc6 --- /dev/null +++ b/src/Titano.App/Import/ImportDestinations.cs @@ -0,0 +1,147 @@ +using Titano.Core.Import; +using Titano.Core.Model; +using Titano.Data.Archiving; + +namespace Titano.App.Import; + +/// Plans an import into one destination (BRIEF §12.4); nothing is written. +public interface IImportDestination +{ + ImportDestinationKind Kind { get; } + + /// Photos read so far. + Task PlanAsync(string sourceRoot, ImportOptions options, Guid? cardId, IProgress? progress, CancellationToken cancellationToken); +} + +/// This PC's archive: the planner knows the card's history, the archive's duplicates and its sequences. +public sealed class ArchiveDestination(ArchiveService archives, Archive archive) : IImportDestination +{ + public Archive Archive { get; } = archive; + + public ImportDestinationKind Kind => ImportDestinationKind.Archive; + + public Task PlanAsync(string sourceRoot, ImportOptions options, Guid? cardId, IProgress? progress, CancellationToken cancellationToken) => + archives.PlanImportAsync(Archive.Id, sourceRoot, options, cardId, progress, cancellationToken); +} + +/// +/// A plain folder or the server: nothing is indexed on this PC, so every photo is copied; a folder destination finds +/// identical files by name and hash while copying, the server by hash before any byte is sent. +/// +public sealed class UnindexedDestination(ImportDestinationKind kind, string root) : IImportDestination +{ + public ImportDestinationKind Kind { get; } = kind; + + /// The folder, or the local staging folder of server uploads. + public string Root { get; } = root; + + public Task PlanAsync(string sourceRoot, ImportOptions options, Guid? cardId, IProgress? progress, CancellationToken cancellationToken) + { + var problems = new List(); + var files = CardScanner.Find(sourceRoot, options.IncludeSubfolders, cancellationToken); + var photos = CardScanner.ReadMetadata(sourceRoot, files, problems, progress, cancellationToken); + return ImportPlanner.PlanAsync(sourceRoot, Root, photos, problems, options, NoIndex.Instance, cancellationToken); + } + + /// No history and no index; folders are reused so a repeated import lands next to the first one. + private sealed class NoIndex : IImportLookup + { + public static readonly NoIndex Instance = new(); + + public Task WasImportedAsync(CardFile file, CancellationToken cancellationToken) => Task.FromResult(false); + + public Task> FindCandidatesAsync(long size, DateTime capturedAt, CancellationToken cancellationToken) => + Task.FromResult>([]); + + public Task FindSessionFolderAsync(string sessionKey, CancellationToken cancellationToken) => Task.FromResult(null); + + public bool IsFolderTaken(string folder) => false; + } +} + +/// A failed photo of an import: where it is on the card and why. +public sealed record ImportFailure(string SourcePath, string Message); + +/// What an import did (BRIEF §12.4 verification result). +/// Copied and committed (verified by read-back when ). +/// Copied, but the destination already held the same content. +/// Not copied: imported before, or already in the archive. +public sealed record ImportOutcome(int Copied, int Duplicates, int Skipped, IReadOnlyList Failures, bool Verified) +{ + public bool IsComplete => Failures.Count == 0; + + /// Photos the destination now holds a verified copy of. + public int Imported => Copied + Duplicates; + + /// Totals of an executor run (folder or server destination). + public static ImportOutcome From(IEnumerable results, bool verified) + { + int copied = 0, duplicates = 0, skipped = 0; + var failures = new List(); + foreach (var r in results) + { + switch (r.Status) + { + case ImportItemStatus.Copied: + copied++; + break; + case ImportItemStatus.Duplicate: + duplicates++; + break; + case ImportItemStatus.Skipped: + skipped++; + break; + default: + failures.Add(new ImportFailure(r.Item.SourcePath, r.Error ?? string.Empty)); + break; + } + } + return new ImportOutcome(copied, duplicates, skipped, failures, verified); + } + + /// + /// After an archive import job: every planned copy must now be a frame of the archive (found by size and capture + /// time, the planner's own duplicate key); the copy was hashed and read back while the job ran. + /// + public static async Task CheckAsync(ImportPlan plan, bool verified, Func> isInArchive, + CancellationToken cancellationToken) + { + int copied = 0, skipped = 0; + var failures = new List(); + foreach (var item in plan.Items) + { + if (item.Action != ImportAction.Copy) + { + skipped++; + continue; + } + if (await isInArchive(item, cancellationToken).ConfigureAwait(false)) copied++; + else failures.Add(new ImportFailure(item.SourcePath, Core.Localization.Loc.L("Import.Result.NotCommitted"))); + } + return new ImportOutcome(copied, 0, skipped, failures, verified); + } +} + +/// +/// Runs a confirmed plan into a folder or the server on this PC (no job handler exists for those destinations): copies +/// with hashing and read-back, commits each batch to the sink and collects the per-file results. +/// +public static class LocalImport +{ + public static async Task RunAsync(ImportPlan plan, IImportSink sink, bool verify, IProgress? progress, + CancellationToken cancellationToken) + { + var results = new List(plan.FileCount); + await new ImportExecutor(plan, sink).RunAsync(0, verify, batch => + { + results.AddRange(batch.Results); + progress?.Report(batch.Progress); + return ValueTask.CompletedTask; + }, p => + { + progress?.Report(p); + return ValueTask.CompletedTask; + }, cancellationToken).ConfigureAwait(false); + return ImportOutcome.From(results, verify); + } +} diff --git a/src/Titano.App/Import/ImportPlans.cs b/src/Titano.App/Import/ImportPlans.cs new file mode 100644 index 00000000..74f81946 --- /dev/null +++ b/src/Titano.App/Import/ImportPlans.cs @@ -0,0 +1,205 @@ +using Titano.App.Infrastructure; +using Titano.Core.Archiving; +using Titano.Core.Import; +using Titano.Core.Localization; +using Titano.Core.Naming; + +namespace Titano.App.Import; + +/// Figures of a plan for the Plan panel header and the Import button (Import.html). +public sealed record PlanTotals(int Sessions, int Photos, int CopyCount, long CopyBytes, int Duplicates, int ImportedBefore, int Problems, + long? FreeAfter, TimeSpan Estimate) +{ + public bool HasEnoughSpace => FreeAfter is not < 0; + + /// "3 sessions · 4,812 photos · 96.2 GB · about 12 min". + public string Text => string.Join(" · ", + Loc.Plural("Import.Plan.Sessions", Sessions), + Loc.Plural("Shell.Status.Photos", Photos), + Formatting.Bytes(CopyBytes), + Loc.L("Import.Plan.About", Formatting.Duration(Estimate))); + + /// "0 duplicates" (already in the archive by hash). + public string DuplicatesText => Loc.Plural("Import.Plan.Duplicates", Duplicates); + + /// "12 imported before" (same file from this card), or empty. + public string ImportedBeforeText => ImportedBefore > 0 ? Loc.Plural("Import.Plan.ImportedBefore", ImportedBefore) : string.Empty; + + /// "2.1 TB free after import", "3.2 GB missing", or empty when the volume does not report its space. + public string SpaceText => FreeAfter switch + { + null => string.Empty, + < 0 => Loc.L("Import.Plan.SpaceMissing", Formatting.Bytes(-FreeAfter.Value)), + _ => Loc.L("Import.Plan.FreeAfter", Formatting.Bytes(FreeAfter.Value)), + }; + + /// "Import 4,812 photos". + public string ImportText => Loc.Plural("Import.Start", CopyCount); +} + +/// One row of the session table: what the planner grouped and where it goes. +/// Title the sequence gets when the user types none (its folder name). +/// The session starts a new sequence (false: it continues one imported before). +public sealed record PlanSessionRow(int Number, string SessionKey, string? Title, string DefaultTitle, string TimeText, string FramesText, + string SizeText, string CameraText, string TargetText, bool IsNew); + +public enum PlanRowKind +{ + Session, + File, +} + +/// A line of "Show plan": a session heading or one file and its destination. +public sealed record PlanDetailRow(PlanRowKind Kind, string Source, string Destination, string ActionText, string SizeText, bool IsSkipped); + +/// Everything "Show plan" lists: every file to its destination, the totals and the conflicts. +public sealed record PlanDetails(IReadOnlyList Rows, string TotalsText, IReadOnlyList Conflicts); + +/// +/// Turns an into what the Import screen shows (BRIEF §12.4 "Plan before touching disk") and +/// applies the choices that need no new scan of the card: the duplicate choice and session titles. +/// +public static class ImportPlans +{ + /// Planning speed assumption for the estimate: a UHS-I card read plus the read-back of the copy. + public const double BytesPerSecond = 80e6; + public const double VerifiedBytesPerSecond = 55e6; + + public static TimeSpan Estimate(long bytes, bool verify) => + TimeSpan.FromSeconds(System.Math.Ceiling(bytes / (verify ? VerifiedBytesPerSecond : BytesPerSecond))); + + public static PlanTotals Totals(ImportPlan plan, bool verify) => new( + plan.Sessions.Count, + plan.FileCount, + plan.CopyCount, + plan.CopyBytes, + plan.Items.Count(i => i.ExistingFrameId is not null), + plan.Items.Count(i => i.Action == ImportAction.SkipImported), + plan.Problems.Count, + plan.AvailableBytes is { } free ? free - plan.CopyBytes : null, + Estimate(plan.CopyBytes, verify)); + + /// + /// The plan with every photo already in the archive skipped or imported again, as the planner would have decided + /// (BRIEF §13: skip, or import again; never overwrite). + /// + public static ImportPlan WithDuplicates(ImportPlan plan, DuplicatePolicy policy) => plan with + { + Sessions = + [ + .. plan.Sessions.Select(s => s with + { + Items = + [ + .. s.Items.Select(i => i.ExistingFrameId is null || i.Action == ImportAction.SkipImported + ? i + : i with { Action = policy == DuplicatePolicy.Skip ? ImportAction.SkipInArchive : ImportAction.Copy }), + ], + }), + ], + }; + + /// The plan with the typed session titles (when no template uses {title}, so no name changes). + public static ImportPlan WithTitles(ImportPlan plan, IReadOnlyDictionary titles) => plan with + { + Sessions = [.. plan.Sessions.Select(s => s with { Title = titles.TryGetValue(s.SessionKey, out var t) && !string.IsNullOrWhiteSpace(t) ? t.Trim() : null })], + }; + + /// Folders of sequences already in the archive (a session there continues it). + public static IReadOnlyList Sessions(ImportPlan plan, ImportDestinationKind destination, IReadOnlySet existingFolders) => + [ + .. plan.Sessions.Select(s => + { + var isNew = !existingFolders.Contains(s.Folder); + var leaf = s.Folder[(s.Folder.LastIndexOf('/') + 1)..]; + var target = destination switch + { + ImportDestinationKind.Server => Loc.L("Import.Session.Server"), + ImportDestinationKind.Folder => s.Folder, + _ => Loc.L(isNew ? "Import.Session.New" : "Import.Session.Adds", s.Folder), + }; + return new PlanSessionRow(s.Number, s.SessionKey, s.Title, leaf, TimeText(s), FramesText(s), Formatting.Bytes(s.Items.Sum(i => i.Size)), + PathTemplate.CameraName(s.CameraMake, s.CameraModel), target, isNew); + }), + ]; + + /// "Show plan": every file and where it goes, with the conflicts the plan resolved or reports. + public static PlanDetails Details(ImportPlan plan, ImportDestinationKind destination, bool verify) + { + var rows = new List(plan.FileCount + plan.Sessions.Count); + foreach (var s in plan.Sessions) + { + var folder = DestinationFolder(s, destination); + rows.Add(new PlanDetailRow(PlanRowKind.Session, Loc.L("Import.Details.Session", s.Number, TimeText(s)), folder, + Loc.Plural("Shell.Status.Photos", s.Items.Count), Formatting.Bytes(s.Items.Sum(i => i.Size)), false)); + foreach (var item in s.Items) + { + rows.Add(new PlanDetailRow(PlanRowKind.File, item.SourcePath, folder + "/" + item.FileName, ActionText(item), + Formatting.Bytes(item.Size), item.Action != ImportAction.Copy)); + } + } + var totals = Totals(plan, verify); + var conflicts = new List(); + foreach (var problem in plan.Problems) conflicts.Add(Loc.L("Import.Details.Unreadable", problem.RelativePath, problem.Message)); + if (totals.Duplicates > 0) conflicts.Add(totals.DuplicatesText); + if (!totals.HasEnoughSpace) conflicts.Add(totals.SpaceText); + var text = string.Join(" · ", new[] + { + Loc.Plural("Import.Details.Files", plan.FileCount), + Loc.L("Import.Details.Copy", Formatting.Count(plan.CopyCount), Formatting.Bytes(plan.CopyBytes)), + totals.ImportedBeforeText, + totals.Duplicates > 0 ? totals.DuplicatesText : string.Empty, + }.Where(t => t.Length > 0)); + return new PlanDetails(rows, text, conflicts); + } + + /// The destination of a session as the user will find it: the archive's originals folder, the folder, or the server. + public static string DestinationFolder(PlannedSession session, ImportDestinationKind destination) => destination switch + { + ImportDestinationKind.Archive => session.Folder + "/" + ArchiveLayout.OriginalsFolder, + ImportDestinationKind.Server => Loc.L("Import.Session.Server"), + _ => session.Folder, + }; + + /// "→ 2026/2026-09-28 Canon EOS R5/2026-09-28_18-02-11_0001.CR2": the first file the plan copies. + public static string? FirstDestination(ImportPlan plan, ImportDestinationKind destination) + { + foreach (var s in plan.Sessions) + { + if (s.Items.FirstOrDefault(i => i.Action == ImportAction.Copy) is { } item) + return destination == ImportDestinationKind.Server ? item.FileName : s.Folder + "/" + item.FileName; + } + return null; + } + + private static string ActionText(PlannedItem item) => item.Action switch + { + ImportAction.SkipImported => Loc.L("Import.Action.ImportedBefore"), + ImportAction.SkipInArchive => Loc.L("Import.Action.Duplicate"), + _ when item.ExistingFrameId is not null => Loc.L("Import.Action.Again"), + _ => Loc.L("Import.Action.Copy"), + }; + + /// "28/09/2026 · 18:02 → 20:04". + private static string TimeText(PlannedSession s) => + Loc.L("Import.Session.Time", Formatting.Date(s.Start), s.Start.ToString("t", Loc.Culture), s.End.ToString("t", Loc.Culture)); + + /// "3,600 · 2 s": photos and the median interval between them. + private static string FramesText(PlannedSession s) + { + var interval = MedianInterval(s.Items); + var count = Formatting.Count(s.Items.Count); + return interval is { } median ? Loc.L("Import.Session.Frames", count, Formatting.Duration(median)) : count; + } + + internal static TimeSpan? MedianInterval(IReadOnlyList items) + { + if (items.Count < 2) return null; + var gaps = new List(items.Count - 1); + for (var i = 1; i < items.Count; i++) gaps.Add((items[i].CapturedAt - items[i - 1].CapturedAt).TotalSeconds); + gaps.Sort(); + var middle = gaps.Count / 2; + var seconds = gaps.Count % 2 == 1 ? gaps[middle] : (gaps[middle - 1] + gaps[middle]) / 2; + return TimeSpan.FromSeconds(System.Math.Max(0, seconds)); + } +} diff --git a/src/Titano.App/Import/ServerImportSink.cs b/src/Titano.App/Import/ServerImportSink.cs new file mode 100644 index 00000000..5100fb6d --- /dev/null +++ b/src/Titano.App/Import/ServerImportSink.cs @@ -0,0 +1,51 @@ +using System.IO; +using Titano.Core.Import; +using Titano.Protocol; +using Titano.Protocol.Client; + +namespace Titano.App.Import; + +/// +/// Import destination "Server" (BRIEF §12.4, §14.4): each verified copy staged on this PC is uploaded with the +/// protocol's resumable chunks and the hash computed while copying; the server checks that hash before it commits the +/// frame, and only then does the photo count as imported. Photos of one plan session share its session key, so the +/// server files them in one sequence — the same one when an interrupted import is started again. A typed session +/// title is set on that sequence once. +/// +public sealed class ServerImportSink(TitanoClient client, string stagingDirectory) : IImportSink +{ + private readonly HashSet _titled = []; + + public string StagingDirectory { get; } = stagingDirectory; + + public async Task> CommitAsync(PlannedSession session, IReadOnlyList files, CancellationToken cancellationToken) + { + var results = new List(files.Count); + foreach (var file in files) + { + // The server records the uploaded file name as the original name: upload the card's name, not the staging name. + var folder = Path.Combine(StagingDirectory, Path.GetFileNameWithoutExtension(file.StagedPath)); + var named = Path.Combine(folder, Path.GetFileName(file.Item.SourcePath)); + Directory.CreateDirectory(folder); + File.Move(file.StagedPath, named); + try + { + var committed = await client.UploadFileAsync(named, null, file.Item.CapturedAt, session.SessionKey, file.Sha256, null, cancellationToken) + .ConfigureAwait(false); + // An upload the server already held reports no position in a sequence. + var duplicate = committed is null || committed.Index < 0; + results.Add(new SinkCommit(committed?.FrameId, file.Item.FileName, duplicate)); + if (committed is { Index: >= 0 } && session.Title is { Length: > 0 } title && _titled.Add(committed.SequenceId)) + await client.UpdateSequenceAsync(committed.SequenceId, new UpdateSequenceRequest(title, null, null, null, null, null), cancellationToken) + .ConfigureAwait(false); + } + finally + { + // Our own staged copy; the original stays on the card. + File.Delete(named); + Directory.Delete(folder); + } + } + return results; + } +} diff --git a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs new file mode 100644 index 00000000..a5677d50 --- /dev/null +++ b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs @@ -0,0 +1,243 @@ +using System.Globalization; +using Titano.App.Archiving; +using Titano.Core.Archiving; +using Titano.Core.Imaging; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Data.Archiving; +using Titano.Data.Repositories; +using Titano.Testing; + +namespace Titano.App.Tests.Archiving; + +public sealed class ArchiveLogicTests +{ + private static readonly Core.Model.Archive Main = new() { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = "/archive" }; + + public ArchiveLogicTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + + private static Sequence Seq(string title, DateTime? first, int frames = 100, long bytes = 1_000_000, params string[] tags) => new() + { + Id = Guid.CreateVersion7(), + ArchiveId = Main.Id, + Title = title, + Folder = $"{first?.Year.ToString(CultureInfo.InvariantCulture) ?? "misc"}/{title}", + FirstCapture = first, + FrameCount = frames, + TotalBytes = bytes, + Tags = tags, + }; + + [Test] + public void TheTreeGroupsByYearNewestFirstWithUndatedLast() + { + var a = Seq("Harbour", new DateTime(2026, 9, 28), 3_600, 72_000_000_000); + var b = Seq("Comet", new DateTime(2026, 8, 13)); + var c = Seq("Stars", new DateTime(2025, 8, 2)); + var d = Seq("Scans", null); + var tree = ArchiveTree.Build(Main, ArchiveAvailability.Online, [c, d, b, a]); + + Assert.Equal("TitanoArchive", tree.Root.Title); + Assert.SequenceEqual(new[] { "2026", "2025", "Undated" }, tree.Root.Children.Select(n => n.Title)); + Assert.SequenceEqual(new[] { "Harbour", "Comet" }, tree.Root.Children[0].Children.Select(n => n.Title)); + Assert.Equal("3,600 photos · 72 GB", tree.Root.Children[0].Children[0].Detail); + Assert.Equal("2 sequences · 72 GB", tree.Root.Children[0].Detail); + + // Collapsed years show only themselves; expanding one reveals its sequences. + Assert.Equal(4, tree.Visible().Count); + tree.Root.Children[1].IsExpanded = true; + Assert.SequenceEqual(new[] { "TitanoArchive", "2026", "2025", "Stars", "Undated" }, tree.Visible().Select(n => n.Title)); + var expanded = tree.ExpandedKeys(); + var rebuilt = ArchiveTree.Build(Main, ArchiveAvailability.ReadOnly, [a, b, c, d]); + rebuilt.Expand(expanded); + Assert.Equal(5, rebuilt.Visible().Count); + Assert.Equal(ArchiveAvailability.ReadOnly, rebuilt.Availability); + } + + [Test] + public void TheMassOperationSetIsTheSelectionOrEverything() + { + var a = Seq("Harbour", new DateTime(2026, 9, 28)); + var b = Seq("Comet", new DateTime(2026, 8, 13)); + var c = Seq("Stars", new DateTime(2025, 8, 2)); + var tree = ArchiveTree.Build(Main, ArchiveAvailability.Online, [a, b, c]); + Assert.Equal(3, ArchiveTree.SetOf(tree, []).Count); + var year = tree.Root.Children[0]; + Assert.SequenceEqual(new[] { a.Id, b.Id }, ArchiveTree.SetOf(tree, [year]).Select(s => s.Id)); + // A year and one of its sequences count that sequence once. + Assert.Equal(2, ArchiveTree.SetOf(tree, [year, year.Children[1]]).Count); + Assert.Equal(3, ArchiveTree.SetOf(tree, [tree.Root]).Count); + } + + private static ArchiveStats Stats() => new( + Sequences: 12, + Photos: 10_000, + Bytes: 9_400_000_000_000, + ByYear: [new YearBucket(2026, 8, 6_000, 2_100_000_000_000), new YearBucket(2024, 4, 4_000, 1_400_000_000_000)], + ByMonth: [new MonthBucket(2024, 3, 2, 1_000), new MonthBucket(2026, 7, 5, 5_000), new MonthBucket(2026, 9, 1, 2_000)], + ByCamera: + [ + new CameraBucket("Canon", "Canon EOS R5", 4, 4_100, 0), + new CameraBucket("SONY", "ILCE-7M4", 2, 2_200, 0), + new CameraBucket("NIKON CORPORATION", "NIKON Z 8", 2, 1_400, 0), + new CameraBucket("GoPro", "HERO12 Black", 1, 900, 0), + new CameraBucket("Apple", "iPhone 16 Pro", 1, 600, 0), + new CameraBucket("DJI", "Osmo Action 5 Pro", 1, 500, 0), + new CameraBucket(null, null, 1, 300, 0), + ], + ByFormat: + [ + new FormatBucket(ImageFileFormat.Cr2, 3_800, 0), + new FormatBucket(ImageFileFormat.Arw, 2_100, 0), + new FormatBucket(ImageFileFormat.Jpeg, 2_000, 0), + new FormatBucket(ImageFileFormat.Nef, 1_400, 0), + new FormatBucket(ImageFileFormat.Dng, 400, 0), + new FormatBucket(ImageFileFormat.Heif, 200, 0), + new FormatBucket(ImageFileFormat.ThreeFr, 60, 0), + new FormatBucket(ImageFileFormat.Unknown, 40, 0), + ], + Health: new ArchiveHealth(Unverified: 3, WithWarnings: 1, WithErrors: 0, NotAnalyzed: 2, MissingFrames: 0, CorruptFrames: 0, DuplicateFrames: 5)); + + [Test] + public void ChartsAggregateYearsCamerasAndFormats() + { + var stats = Stats(); + var years = ArchiveFigures.StorageByYear(stats); + Assert.SequenceEqual(new[] { "2024", "2026" }, years.Select(b => b.Label)); + Assert.Equal("2.1 TB", years[1].ValueText); + + var cameras = ArchiveFigures.ByCamera(stats); + Assert.Equal(ArchiveFigures.TopCameras + 1, cameras.Count); + Assert.Equal("Canon EOS R5", cameras[0].Label); + Assert.Equal("41 %", cameras[0].ValueText); + Assert.Equal("SONY ILCE-7M4", cameras[1].Label); + Assert.Equal("Nikon Z 8", cameras[2].Label); + Assert.Equal("2 others", cameras[^1].Label); + Assert.Equal(800, cameras[^1].Value); + Assert.Equal(stats.Photos, (long)cameras.Sum(c => c.Value)); + + var formats = ArchiveFigures.ByFormat(stats); + Assert.SequenceEqual(new[] { "CR2", "ARW", "JPEG", "NEF", "DNG", "HEIF", "Other" }, formats.Select(f => f.Label)); + Assert.Equal(100, formats[^1].Value); + Assert.Equal("3FR", ArchiveFigures.FormatName(ImageFileFormat.ThreeFr)); + } + + [Test] + public void ThePhotosPerMonthHeatmapHasOneRowPerYearAndNoFuture() + { + var rows = ArchiveFigures.PhotosPerMonth(Stats(), new DateTime(2026, 10, 2)); + Assert.SequenceEqual(new[] { "2024", "2025", "2026" }, rows.Select(r => r.Label)); + Assert.Equal(1_000, rows[0].Values[2]); + Assert.Equal(0, rows[1].Values[5]); + Assert.Equal(5_000, rows[2].Values[6]); + Assert.Equal(0, rows[2].Values[9]); + Assert.True(double.IsNaN(rows[2].Values[10])); + Assert.Null(rows[2].ToolTips[11]); + Assert.Equal("July 2026 · 5,000 photos · 5 sequences", rows[2].ToolTips[6]); + Assert.Equal(12, ArchiveFigures.MonthLabels().Count); + Assert.Equal("J", ArchiveFigures.MonthLabels()[0]); + Assert.Empty(ArchiveFigures.PhotosPerMonth(Stats() with { ByMonth = [] }, DateTime.Today)); + } + + [Test] + public void TilesAndHealthSummariseTheIndex() + { + var tiles = ArchiveFigures.Tiles(Stats()); + Assert.Equal(5, tiles.Count); + Assert.Equal("10,000", tiles[0].Value); + Assert.Equal("9.4 TB", tiles[2].Value); + Assert.Equal("6", tiles[3].Value); + Assert.Equal("cameras · 8 formats", tiles[3].Caption); + Assert.Equal("2024 – 2026", tiles[4].Value); + + var health = ArchiveFigures.Health(Stats(), withoutProxies: 0); + Assert.Equal(HealthAction.Verify, health[0].Action); + Assert.False(health[0].IsOk); + Assert.Equal("3 sequences unverified", health[0].Text); + Assert.True(health[1].IsOk); + Assert.True(health[2].IsOk); + Assert.Equal(HealthAction.Analyse, health[3].Action); + Assert.Equal(HealthAction.Duplicates, health[4].Action); + } + + [Test] + public void RenameTemplatesAreCheckedAndThePlanListedByMode() + { + Assert.Null(MassRename.Validate(RenameMode.Titles, "{title} · {camera}")); + Assert.NotNull(MassRename.Validate(RenameMode.Titles, "{title")); + Assert.NotNull(MassRename.Validate(RenameMode.Titles, " ")); + Assert.Null(MassRename.Validate(RenameMode.Folders, "{year}/{date} {title}")); + Assert.NotNull(MassRename.Validate(RenameMode.Folders, "{nope}")); + + var a = Seq("Harbour", new DateTime(2026, 9, 28)); + var b = Seq("Comet", new DateTime(2026, 8, 13)); + var subjects = new[] { a, b }.Select(s => new RenameSubject(s.Id, s.Folder, s.Title, s.FirstCapture, "Canon", "Canon EOS R5", null)).ToList(); + var titles = RenamePlanner.Plan(Main.Id, subjects, null, "{title} · {camera}", subjects.Select(s => s.Folder), _ => false); + var rows = MassRename.Rows(titles, RenameMode.Titles); + Assert.Equal("Harbour", rows[0].From); + Assert.Equal("Harbour · Canon EOS R5", rows[0].To); + Assert.Equal("2 of 5 change", MassRename.Summary(titles, 5)); + + Assert.Empty(RenamePlanner.Plan(Main.Id, subjects, "{year}/{title}", null, subjects.Select(s => s.Folder), _ => false).Steps); + var folders = RenamePlanner.Plan(Main.Id, subjects, "{year}/{date} {title}", null, subjects.Select(s => s.Folder), _ => false); + var moves = MassRename.Rows(folders, RenameMode.Folders); + Assert.SequenceEqual(new[] { "2026/Harbour", "2026/Comet" }, moves.Select(r => r.From)); + Assert.SequenceEqual(new[] { "2026/2026-09-28 Harbour", "2026/2026-08-13 Comet" }, moves.Select(r => r.To)); + } + + [Test] + public void RetagAddsAndRemovesWithoutDuplicates() + { + Assert.SequenceEqual(new[] { "sunset", "harbour", "Holy grail" }, Retag.Parse(" sunset, harbour; Holy grail ,SUNSET")); + Assert.Empty(Retag.Parse(" ")); + Assert.Null(Retag.Validate("sunset, dusk")); + Assert.NotNull(Retag.Validate(new string('x', 65))); + Assert.Empty(Retag.Parse(new string('x', 65))); + Assert.SequenceEqual(new[] { "harbour", "dusk" }, Retag.Apply(["Sunset", "harbour"], ["dusk", "HARBOUR"], ["sunset"])); + var a = Seq("A", DateTime.Today, tags: ["sunset"]); + var b = Seq("B", DateTime.Today, tags: ["dusk"]); + var changes = Retag.Changes([a, b], ["dusk"], []); + Assert.Equal(a.Id, changes.Single().Sequence.Id); + Assert.SequenceEqual(new[] { "sunset", "dusk" }, changes.Single().Tags); + } + + [Test] + public void ReportsListDuplicatesOrphansAndRecentMaintenance() + { + var a = Seq("Harbour", new DateTime(2026, 9, 28)); + var b = Seq("Comet", new DateTime(2026, 8, 13)); + var locations = new[] { new SequenceLocation(a.Id, a.Folder, a.Title), new SequenceLocation(b.Id, b.Folder, null) }; + var groups = new[] + { + new DuplicateGroup("ab", [new DuplicateFrame("ab", Guid.NewGuid(), a.Id, 0, a.Folder + "/originals/IMG_1.CR2"), + new DuplicateFrame("ab", Guid.NewGuid(), b.Id, 4, b.Folder + "/originals/IMG_9.CR2")]), + new DuplicateGroup("cd", [new DuplicateFrame("cd", Guid.NewGuid(), a.Id, 1, a.Folder + "/originals/IMG_2.CR2")]), + }; + var duplicates = MaintenanceReports.Duplicates(groups, locations); + Assert.Equal("IMG_1.CR2", duplicates.Single().Title); + Assert.Equal("2 copies", duplicates.Single().Detail); + Assert.Equal(a.Id, duplicates.Single().SequenceId); + Assert.Contains("Comet", duplicates.Single().Places[1]); + + var report = new OrphanReport( + [new SequenceOrphans(a.Folder, ["IMG_7.CR2", "IMG_8.CR2"], [])], + [new SequenceLocation(Guid.NewGuid(), "2024/Gone", "Gone")], + ["2026/New shoot"]); + var orphans = MaintenanceReports.Orphans(report, locations); + Assert.SequenceEqual(new[] { OrphanKind.UnlistedFiles, OrphanKind.MissingSequence, OrphanKind.NewFolder }, orphans.Select(o => o.Kind)); + Assert.Equal("2 photos not in sidecar", orphans[0].Detail); + Assert.Equal(a.Id, orphans[0].SequenceId); + Assert.Null(orphans[2].SequenceId); + + var now = DateTimeOffset.UtcNow; + var jobs = new[] + { + new Job { Id = Guid.NewGuid(), Kind = JobKind.Verify, State = JobState.Running, ProgressDone = 71, ProgressTotal = 100, TargetLabel = "TitanoArchive", Created = now }, + new Job { Id = Guid.NewGuid(), Kind = JobKind.Scan, State = JobState.Done, Created = now.AddDays(-2), Finished = now.AddDays(-2) }, + }; + var recent = MaintenanceReports.Recent(jobs, 5); + Assert.Equal("Verify · TitanoArchive", recent[0].Text); + Assert.Equal("71 %", recent[0].StateText); + Assert.Equal(JobState.Done, recent[1].State); + } +} diff --git a/tests/Titano.App.Tests/Import/CardPoolTests.cs b/tests/Titano.App.Tests/Import/CardPoolTests.cs new file mode 100644 index 00000000..80dfd284 --- /dev/null +++ b/tests/Titano.App.Tests/Import/CardPoolTests.cs @@ -0,0 +1,65 @@ +using System.Globalization; +using Titano.App.Import; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Testing; + +namespace Titano.App.Tests.Import; + +public sealed class CardPoolTests +{ + private static readonly CardDevice CardA = new(@"F:\", "EOS_DIGITAL", 0x3F2A9C11, 128_000_000_000, 31_800_000_000, true, true); + private static readonly CardDevice GoPro = new(@"E:\", "GOPRO", 0x11112222, 64_000_000_000, 52_600_000_000, true, true); + private static readonly CardDevice Usb = new(@"G:\", "BACKUP", 0x99990000, 2_000_000_000_000, 1_800_000_000_000, true, false); + + public CardPoolTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + + private static MediaCard Known(CardDevice device, string nickname, DateTimeOffset seen) => new() + { + Id = Guid.CreateVersion7(), + Identity = device.Identity, + VolumeSerial = device.SerialNumber, + Label = device.Label, + Capacity = device.TotalBytes, + Nickname = nickname, + CameraMake = "Canon", + CameraModel = "Canon EOS R5", + CameraSerial = "0431", + LastSeen = seen, + }; + + [Test] + public void InsertedVolumesComeFirstThenRememberedCardsThenTheFolder() + { + var away = new CardDevice(@"H:\", "NIKON", 0x55556666, 64_000_000_000, 0, true, true); + var cards = new[] { Known(CardA, "EOS R5 · card A", DateTimeOffset.UtcNow), Known(away, "Z 8 card", DateTimeOffset.UtcNow.AddDays(-3)) }; + var pool = CardPool.Build([Usb, CardA, GoPro], cards, @"D:\Shoots\2026"); + + Assert.SequenceEqual(new[] { GoPro.Identity, CardA.Identity, Usb.Identity, away.Identity, @"D:\Shoots\2026" }, pool.Select(s => s.Key)); + Assert.Equal(SourceKind.Card, pool[0].Kind); + Assert.False(pool[0].IsKnown); + Assert.Equal("GOPRO", pool[0].Title); + Assert.Equal("New card", pool[0].StateText); + Assert.Equal("EOS R5 · card A", pool[1].Title); + Assert.Equal("Known card", pool[1].StateText); + Assert.Equal(@"F:\ · 128 GB · 96.2 GB used", pool[1].Subtitle); + Assert.Equal(@"F:\ · 128 GB · serial 3F2A-9C11 · Canon EOS R5 #0431", pool[1].IdentityText); + Assert.Equal(SourceKind.Drive, pool[2].Kind); + Assert.Equal(@"G:\ · no DCIM · 1.8 TB free", pool[2].Subtitle); + Assert.False(pool[3].IsInserted); + Assert.Null(pool[3].Root); + Assert.Equal("Canon EOS R5 · not inserted", pool[3].Subtitle); + Assert.Equal(SourceKind.Folder, pool[4].Kind); + Assert.Equal(@"D:\Shoots\2026", pool[4].Root); + } + + [Test] + public void AKnownCardWithoutDcimIsStillACard() + { + var pool = CardPool.Build([Usb], [Known(Usb, "Backup card", DateTimeOffset.UtcNow)], null); + Assert.Equal(SourceKind.Card, pool.Single().Kind); + Assert.Equal("3F2A-9C11", ImportSource.SerialText(0x3F2A9C11)); + Assert.Equal("3F2A9C11-EOS_DIGITAL-128000000000", CardA.Identity); + Assert.Equal("EOS_DIGITAL", CardA.ToVolume().Label); + } +} diff --git a/tests/Titano.App.Tests/Import/ImportChoicesTests.cs b/tests/Titano.App.Tests/Import/ImportChoicesTests.cs new file mode 100644 index 00000000..f8b2b030 --- /dev/null +++ b/tests/Titano.App.Tests/Import/ImportChoicesTests.cs @@ -0,0 +1,69 @@ +using Titano.App.Import; +using Titano.Core.Import; +using Titano.Data.Archiving; +using Titano.Testing; + +namespace Titano.App.Tests.Import; + +public sealed class ImportChoicesTests +{ + [Test] + public void ACardProfileRoundTripsThroughTheForm() + { + var profile = new CardProfile + { + FolderTemplate = "{year}/{title}", + FileTemplate = "{name}", + SessionGapMinutes = 30, + MinimumSessionFrames = 4, + IncludeSubfolders = false, + VerifyCopies = false, + Duplicates = DuplicatePolicy.ImportAgain, + AfterImport = AfterImport.DeleteImported, + Eject = false, + DeepAnalysis = false, + }; + var choices = ImportChoices.FromProfile(profile); + Assert.True(choices.SplitSessions); + Assert.Equal(30, choices.GapMinutes); + Assert.Equal(profile, choices.ToProfile()); + } + + [Test] + public void SessionsOffIsRememberedAsAZeroGapAndNeverSplits() + { + var off = new ImportChoices { SplitSessions = false, GapMinutes = 20 }; + Assert.Equal(0, off.ToProfile().SessionGapMinutes); + Assert.Equal(TimeSpan.MaxValue, off.ToOptions().SessionGap); + var back = ImportChoices.FromProfile(off.ToProfile()); + Assert.False(back.SplitSessions); + Assert.Equal(new CardProfile().SessionGapMinutes, back.GapMinutes); + Assert.Equal(TimeSpan.FromMinutes(20), (off with { SplitSessions = true }).ToOptions().SessionGap); + } + + [Test] + public void OptionsCarryTheFormAndTheTypedTitles() + { + var titles = new Dictionary { ["k"] = "Harbour" }; + var options = new ImportChoices { MinimumFrames = 0, Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false }.ToOptions(titles); + Assert.Equal(1, options.MinimumSessionFrames); + Assert.Equal(DuplicatePolicy.ImportAgain, options.Duplicates); + Assert.False(options.VerifyCopies); + Assert.Equal("Harbour", options.Titles["k"]); + } + + [Test] + public void OnlyGroupingAndNamingChoicesNeedANewPlan() + { + var a = new ImportChoices(); + Assert.False((a with { Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false, Eject = false, AfterImport = AfterImport.FormatCard }).NeedsNewPlan(a)); + Assert.False((a with { SplitSessions = false, GapMinutes = 5 }).NeedsNewPlan(a with { SplitSessions = false })); + Assert.True((a with { GapMinutes = 5 }).NeedsNewPlan(a)); + Assert.True((a with { MinimumFrames = 2 }).NeedsNewPlan(a)); + Assert.True((a with { FileTemplate = "{name}" }).NeedsNewPlan(a)); + Assert.True((a with { Destination = ImportDestinationKind.Folder }).NeedsNewPlan(a)); + Assert.True((a with { IncludeSubfolders = false }).NeedsNewPlan(a)); + Assert.False(a.TitlesChangeNames); + Assert.True((a with { FolderTemplate = "{year}/{Title:upper}" }).TitlesChangeNames); + } +} diff --git a/tests/Titano.App.Tests/Import/ImportFlowTests.cs b/tests/Titano.App.Tests/Import/ImportFlowTests.cs new file mode 100644 index 00000000..4b8eef2a --- /dev/null +++ b/tests/Titano.App.Tests/Import/ImportFlowTests.cs @@ -0,0 +1,139 @@ +using System.Globalization; +using System.IO; +using Titano.App.Import; +using Titano.Core.Import; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Data; +using Titano.Data.Archiving; +using Titano.Data.Jobs; +using Titano.Testing; +using static Titano.App.Tests.Import.ImportTestData; + +namespace Titano.App.Tests.Import; + +/// Card to archive and card to folder on real files and a real index, and the card-erase gate around them. +[Category("import")] +public sealed class ImportFlowTests(TestContext context) +{ + private static readonly CardVolume Volume = new("3F2A9C11-EOS_DIGITAL-127865454592", 0x3F2A9C11, "EOS_DIGITAL", 127_865_454_592); + + [Test] + public async Task AVerifiedArchiveImportUnlocksDeleteAndFormat() + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + await using var db = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory("db"), "titano.db")), context.Cancellation); + var archives = new ArchiveService(db, new ArchiveServiceOptions { Owner = "test" }); + var archive = await archives.AdoptAsync(context.CreateTempDirectory("archive"), "Main", context.Cancellation); + var card = Card(context.CreateTempDirectory("card"), 10, Start, Start.AddHours(3), Start.AddDays(1)); + var media = await archives.Imports.RegisterCardAsync(Volume, context.Cancellation); + var destination = new ArchiveDestination(archives, archive); + var choices = new ImportChoices(); + + var plan = await destination.PlanAsync(card, choices.ToOptions(), media.Id, null, context.Cancellation); + Assert.Equal(3, plan.Sessions.Count); + Assert.Equal(30, plan.CopyCount); + var before = new CardActions(ImportDestinationKind.Archive, true, true, true, null, null, plan.FileCount); + Assert.False(before.CanCheck, "no import, no erase"); + Assert.False(before.CanDelete); + Assert.False(before.CanFormat); + Assert.Equal(Loc.L("Import.Blocked.NothingImported"), before.CheckBlocker); + var unverified = await archives.PlanCardEraseAsync(archive.Id, media.Id, card, null, context.Cancellation); + Assert.Empty(unverified.ToDelete); + + await using (var engine = new JobEngine(db, archives.CreateJobHandlers(), + new JobEngineOptions { Workers = 1, WorkerId = "test", PollInterval = TimeSpan.FromMilliseconds(50), CheckpointInterval = TimeSpan.FromMilliseconds(50) })) + { + await engine.StartAsync(context.Cancellation); + var job = await engine.EnqueueAsync(ArchiveJobs.Import(archive, plan, media.Id, choices.VerifyCopies), cancellationToken: context.Cancellation); + await WaitDoneAsync(db, job.Id); + } + + var outcome = await ImportOutcome.CheckAsync(plan, choices.VerifyCopies, + async (item, ct) => (await db.Frames.FindBySizeAndCaptureAsync(archive.Id, item.Size, item.CapturedAt, ct)).Count > 0, context.Cancellation); + Assert.Equal(30, outcome.Copied); + Assert.True(outcome.IsComplete); + var afterImport = new CardActions(ImportDestinationKind.Archive, true, true, true, outcome, null, plan.FileCount); + Assert.True(afterImport.CanCheck); + Assert.False(afterImport.CanDelete, "the dry run must come first"); + Assert.Equal(Loc.L("Import.Blocked.NoDryRun"), afterImport.DeleteBlocker); + + var erase = await archives.PlanCardEraseAsync(archive.Id, media.Id, card, null, context.Cancellation); + var ready = afterImport with { Erase = erase }; + Assert.True(ready.CanDelete); + Assert.True(ready.CanFormat); + Assert.Equal(30, ready.DeleteCount); + Assert.Equal("30 verified on the card · " + Infrastructure.Formatting.Bytes(ready.DeleteBytes), ready.EraseText); + + // A photo added to the card after the import is not verified: formatting would lose it. + Assert.False((ready with { CardPhotos = 31 }).CanFormat); + Assert.False((ready with { Outcome = outcome with { Verified = false } }).CanFormat); + Assert.False((ready with { Destination = ImportDestinationKind.Folder }).CanDelete); + Assert.False((ready with { IsInserted = false }).CanDelete); + Assert.False((ready with { IsRemovable = false }).CanEject); + + var result = CardEraser.Execute(erase, context.Cancellation); + Assert.Equal(30, result.Deleted); + Assert.Empty(Directory.EnumerateFiles(Path.Combine(card, "DCIM", "100CANON"))); + } + + [Test] + public async Task AFolderImportCopiesWithoutAnIndexAndFindsItsOwnCopiesAgain() + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + var card = Card(context.CreateTempDirectory("card"), 8, Start, Start.AddHours(2)); + var target = context.CreateTempDirectory("folder"); + var destination = new UnindexedDestination(ImportDestinationKind.Folder, target); + var plan = await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation); + Assert.Equal(2, plan.Sessions.Count); + Assert.Equal(16, plan.CopyCount); + + var reports = new List(); + var outcome = await LocalImport.RunAsync(plan, new FolderImportSink(target), verify: true, new Progress(reports), context.Cancellation); + Assert.Equal(16, outcome.Copied); + Assert.True(outcome.IsComplete); + Assert.True(outcome.Verified); + Assert.NotEmpty(reports); + foreach (var s in plan.Sessions) + foreach (var item in s.Items) + Assert.FileExists(Path.Combine(target, s.Folder, item.FileName)); + + var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation), + new FolderImportSink(target), verify: true, null, context.Cancellation); + Assert.Equal(0, again.Copied); + Assert.Equal(16, again.Duplicates); + Assert.False(new CardActions(ImportDestinationKind.Folder, false, true, true, outcome, null, 16).CanCheck); + } + + [Test] + public async Task TheIndexCheckReportsPlannedCopiesThatNeverArrived() + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + var plan = Plan(null, null, Session(1, "f", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4), action: ImportAction.SkipImported))); + var outcome = await ImportOutcome.CheckAsync(plan, true, (item, _) => Task.FromResult(!item.SourcePath.EndsWith("0002.CR2", StringComparison.Ordinal)), + context.Cancellation); + Assert.Equal(1, outcome.Copied); + Assert.Equal(1, outcome.Skipped); + Assert.Equal("DCIM/100CANON/IMG_0002.CR2", outcome.Failures.Single().SourcePath); + Assert.False(outcome.IsComplete); + } + + private async Task WaitDoneAsync(TitanoDatabase db, Guid jobId) + { + var until = DateTime.UtcNow.AddSeconds(60); + while (DateTime.UtcNow < until) + { + var job = await db.Jobs.GetAsync(jobId, context.Cancellation); + if (job?.State == JobState.Done) return; + if (job?.State is JobState.Failed or JobState.Cancelled) Assert.Fail($"Import job ended {job.State}: {job.Error}\n{job.LogTail}"); + await Task.Delay(25, context.Cancellation); + } + Assert.Fail("The import job did not finish"); + } + + /// Collects reports synchronously (System.Progress posts to the thread pool). + private sealed class Progress(List into) : IProgress + { + public void Report(ImportProgress value) => into.Add(value); + } +} diff --git a/tests/Titano.App.Tests/Import/ImportPlansTests.cs b/tests/Titano.App.Tests/Import/ImportPlansTests.cs new file mode 100644 index 00000000..1703f05b --- /dev/null +++ b/tests/Titano.App.Tests/Import/ImportPlansTests.cs @@ -0,0 +1,136 @@ +using System.Globalization; +using Titano.App.Import; +using Titano.Core.Import; +using Titano.Core.Localization; +using Titano.Testing; +using static Titano.App.Tests.Import.ImportTestData; + +namespace Titano.App.Tests.Import; + +public sealed class ImportPlansTests +{ + public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + + private static ImportPlan ThreeSessions(long? available = 200_000_000) + { + var duplicate = Guid.CreateVersion7(); + return Plan(available, [new ImportProblem("DCIM/100CANON/IMG_0099.CR2", "Access denied")], + Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4)), Item(4, Start.AddSeconds(8))), + Session(2, "2026/2026-09-29 Canon EOS R5", Item(5, Start.AddDays(1)), Item(6, Start.AddDays(1).AddSeconds(120), action: ImportAction.SkipInArchive, existing: duplicate)), + Session(3, "2026/2026-09-30 Canon EOS R5", Item(7, Start.AddDays(2), action: ImportAction.SkipImported))); + } + + [Test] + public void TotalsCountWhatIsCopiedSkippedAndDuplicated() + { + var totals = ImportPlans.Totals(ThreeSessions(), verify: true); + Assert.Equal(3, totals.Sessions); + Assert.Equal(7, totals.Photos); + Assert.Equal(5, totals.CopyCount); + Assert.Equal(5 * 24_000_000L, totals.CopyBytes); + Assert.Equal(1, totals.Duplicates); + Assert.Equal(1, totals.ImportedBefore); + Assert.Equal(1, totals.Problems); + Assert.Equal(80_000_000L, totals.FreeAfter); + Assert.True(totals.HasEnoughSpace); + Assert.Equal(TimeSpan.FromSeconds(3), totals.Estimate); + Assert.Equal("3 sessions · 7 photos · 120 MB · about 3 s", totals.Text); + Assert.Equal("1 duplicate", totals.DuplicatesText); + Assert.Equal("Import 5 photos", totals.ImportText); + Assert.Equal("80 MB free after import", totals.SpaceText); + } + + [Test] + public void ASmallDestinationReportsTheMissingSpace() + { + var totals = ImportPlans.Totals(ThreeSessions(available: 100_000_000), verify: false); + Assert.False(totals.HasEnoughSpace); + Assert.Equal("20 MB missing", totals.SpaceText); + Assert.Equal(string.Empty, ImportPlans.Totals(ThreeSessions(available: null), verify: false).SpaceText); + Assert.Equal(TimeSpan.FromSeconds(2), ImportPlans.Totals(ThreeSessions(), verify: false).Estimate); + } + + [Test] + public void TheDuplicateChoiceFlipsOnlyPhotosAlreadyInTheArchive() + { + var plan = ThreeSessions(); + var again = ImportPlans.WithDuplicates(plan, DuplicatePolicy.ImportAgain); + Assert.Equal(6, again.CopyCount); + var duplicate = again.Sessions[1].Items[1]; + Assert.Equal(ImportAction.Copy, duplicate.Action); + Assert.NotNull(duplicate.ExistingFrameId); + Assert.Equal(ImportAction.SkipImported, again.Sessions[2].Items[0].Action); + + var skipped = ImportPlans.WithDuplicates(again, DuplicatePolicy.Skip); + Assert.Equal(ImportAction.SkipInArchive, skipped.Sessions[1].Items[1].Action); + Assert.Equal(plan.CopyCount, skipped.CopyCount); + Assert.Equal("Import again", ImportPlans.Details(again, ImportDestinationKind.Archive, true).Rows.Single(r => r.Source.EndsWith("0006.CR2", StringComparison.Ordinal)).ActionText); + } + + [Test] + public void TypedTitlesNameTheirSessions() + { + var plan = ThreeSessions(); + var titled = ImportPlans.WithTitles(plan, new Dictionary + { + [plan.Sessions[0].SessionKey] = " Harbour sunset ", + [plan.Sessions[1].SessionKey] = " ", + ["unknown"] = "ignored", + }); + Assert.Equal("Harbour sunset", titled.Sessions[0].Title); + Assert.Null(titled.Sessions[1].Title); + Assert.Null(titled.Sessions[2].Title); + Assert.SequenceEqual(plan.Items.Select(i => i.FileName), titled.Items.Select(i => i.FileName)); + } + + [Test] + public void SessionRowsShowTimesIntervalsAndWhereTheyGo() + { + var plan = ThreeSessions(); + var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet(["2026/2026-09-29 Canon EOS R5"], StringComparer.OrdinalIgnoreCase)); + Assert.Equal(3, rows.Count); + Assert.Equal("4 · 2 s", rows[0].FramesText); + Assert.Equal("2 · 2 min", rows[1].FramesText); + Assert.Equal("1", rows[2].FramesText); + Assert.True(rows[0].IsNew); + Assert.Equal("New · 2026/2026-09-28 Canon EOS R5", rows[0].TargetText); + Assert.False(rows[1].IsNew); + Assert.Equal("Adds to · 2026/2026-09-29 Canon EOS R5", rows[1].TargetText); + Assert.Equal("2026-09-28 Canon EOS R5", rows[0].DefaultTitle); + Assert.Equal("Canon EOS R5", rows[0].CameraText); + Assert.Equal("96 MB", rows[0].SizeText); + Assert.Contains("6:02", rows[0].TimeText); + Assert.Equal("Server", ImportPlans.Sessions(plan, ImportDestinationKind.Server, new HashSet())[0].TargetText); + } + + [Test] + public void ShowPlanListsEveryFileItsDestinationAndTheConflicts() + { + var plan = ThreeSessions(available: 100_000_000); + var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true); + Assert.Equal(plan.FileCount + plan.Sessions.Count, details.Rows.Count); + Assert.Equal(3, details.Rows.Count(r => r.Kind == PlanRowKind.Session)); + var first = details.Rows[1]; + Assert.Equal("DCIM/100CANON/IMG_0001.CR2", first.Source); + Assert.Equal("2026/2026-09-28 Canon EOS R5/originals/" + plan.Sessions[0].Items[0].FileName, first.Destination); + Assert.Equal("Copy", first.ActionText); + Assert.False(first.IsSkipped); + Assert.True(details.Rows.Single(r => r.Source.EndsWith("0007.CR2", StringComparison.Ordinal)).IsSkipped); + Assert.Equal(3, details.Conflicts.Count); + Assert.Contains("IMG_0099.CR2", details.Conflicts[0]); + Assert.Equal("7 files · copy 5 (120 MB) · 1 imported before · 1 duplicate", details.TotalsText); + + var folder = ImportPlans.Details(plan, ImportDestinationKind.Folder, verify: true); + Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, folder.Rows[1].Destination); + } + + [Test] + public void TheNamePreviewIsTheFirstCopiedFile() + { + var plan = ThreeSessions(); + Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestination(plan, ImportDestinationKind.Archive)); + Assert.Equal(plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestination(plan, ImportDestinationKind.Server)); + var nothing = ImportPlans.WithDuplicates(Plan(null, null, Session(1, "x", Item(1, Start, action: ImportAction.SkipImported))), DuplicatePolicy.Skip); + Assert.Null(ImportPlans.FirstDestination(nothing, ImportDestinationKind.Archive)); + } +} diff --git a/tests/Titano.App.Tests/Import/ImportTestData.cs b/tests/Titano.App.Tests/Import/ImportTestData.cs new file mode 100644 index 00000000..409e0d54 --- /dev/null +++ b/tests/Titano.App.Tests/Import/ImportTestData.cs @@ -0,0 +1,76 @@ +using System.IO; +using Titano.Core.Codecs.Jpeg; +using Titano.Core.Imaging; +using Titano.Core.Import; +using Titano.Core.Metadata; + +namespace Titano.App.Tests.Import; + +/// Synthetic cards (small JPEGs with Exif) and hand-made plans for the Import tests. +internal static class ImportTestData +{ + public static readonly DateTime Start = new(2026, 9, 28, 18, 2, 11); + + /// A real JPEG with Exif make, model, body serial and capture time; each seed gives distinct bytes. + public static byte[] Jpeg(DateTime captured, int seed) + { + using var image = new ImageBuffer(32, 24); + var random = new Random(seed); + for (var c = 0; c < 3; c++) + { + var plane = image.Plane(c); + var level = (float)random.NextDouble(); + for (var i = 0; i < plane.Length; i++) plane[i] = level * (0.5f + 0.5f * (i % 32) / 32f); + } + var exif = ExifWriter.BuildJpegApp1(new FrameMetadata { Make = "Canon", Model = "Canon EOS R5", BodySerial = "0431", CapturedAt = captured, Iso = 100 }); + return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 80, App1Segments = [exif[4..]] }); + } + + /// A card folder with DCIM/100CANON: one series per start time, photos 2 s apart. + public static string Card(string root, int perSession, params DateTime[] starts) + { + var folder = Path.Combine(root, "DCIM", "100CANON"); + Directory.CreateDirectory(folder); + var n = 1; + foreach (var start in starts) + { + for (var i = 0; i < perSession; i++, n++) + File.WriteAllBytes(Path.Combine(folder, $"IMG_{n:0000}.JPG"), Jpeg(start.AddSeconds(2 * i), n)); + } + return root; + } + + public static PlannedItem Item(int n, DateTime captured, long size = 24_000_000, ImportAction action = ImportAction.Copy, Guid? existing = null) => new() + { + SourcePath = $"DCIM/100CANON/IMG_{n:0000}.CR2", + Size = size, + ModifiedUtc = captured, + CapturedAt = captured, + FileName = $"{captured:yyyy-MM-dd_HH-mm-ss}_{n:0000}.CR2", + Action = action, + ExistingFrameId = existing, + }; + + public static PlannedSession Session(int number, string folder, params PlannedItem[] items) => new() + { + Number = number, + SessionKey = $"card-0000000{number}-key", + CameraMake = "Canon", + CameraModel = "Canon EOS R5", + Format = ImageFileFormat.Cr2, + Start = items[0].CapturedAt, + End = items[^1].CapturedAt, + Folder = folder, + Items = items, + }; + + public static ImportPlan Plan(long? available, IReadOnlyList? problems = null, params PlannedSession[] sessions) => new() + { + Id = Guid.CreateVersion7(), + SourceRoot = "/card", + DestinationRoot = "/archive", + Sessions = sessions, + Problems = problems ?? [], + AvailableBytes = available, + }; +} diff --git a/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs new file mode 100644 index 00000000..6513d850 --- /dev/null +++ b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs @@ -0,0 +1,147 @@ +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Json; +using System.Security.Cryptography; +using Titano.App.Import; +using Titano.Core.Import; +using Titano.Protocol; +using Titano.Protocol.Client; +using Titano.Testing; +using static Titano.App.Tests.Import.ImportTestData; + +namespace Titano.App.Tests.Import; + +/// The "Server" destination over the real protocol client against an in-memory upload endpoint. +[Category("import")] +public sealed class ServerImportSinkTests(TestContext context) +{ + [Test] + public async Task EveryPhotoIsUploadedInChunksUnderItsCardNameAndVerifiedByHash() + { + var card = Card(context.CreateTempDirectory("card"), 8, Start, Start.AddHours(2)); + var staging = context.CreateTempDirectory("staging"); + var server = new FakeUploadServer(chunkSize: 256); + using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" }; + var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation); + plan = plan with { Sessions = [plan.Sessions[0] with { Title = "Harbour sunset" }, .. plan.Sessions.Skip(1)] }; + + var outcome = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation); + + Assert.Equal(16, outcome.Copied); + Assert.True(outcome.IsComplete); + Assert.Equal(16, server.Committed.Count); + foreach (var item in plan.Items) + { + var bytes = File.ReadAllBytes(Path.Combine(card, item.SourcePath)); + var upload = server.Committed.Single(u => u.FileName == Path.GetFileName(item.SourcePath)); + Assert.BytesEqual(bytes, upload.Bytes); + Assert.Equal(Convert.ToHexStringLower(SHA256.HashData(bytes)), upload.Sha256); + Assert.True(upload.Chunks > 1, "files larger than a chunk travel in several chunks"); + } + Assert.SequenceEqual(plan.Sessions.Select(s => s.SessionKey).Order(StringComparer.Ordinal), + server.Committed.Select(u => u.SessionKey).Distinct().Order(StringComparer.Ordinal)); + Assert.Equal("Harbour sunset", server.Titles.Single().Value); + Assert.Empty(Directory.EnumerateFileSystemEntries(staging)); + } + + [Test] + public async Task PhotosTheServerAlreadyHoldsAreNotSentAgain() + { + var card = Card(context.CreateTempDirectory("card"), 8, Start); + var staging = context.CreateTempDirectory("staging"); + var server = new FakeUploadServer(chunkSize: 4096); + using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" }; + var destination = new UnindexedDestination(ImportDestinationKind.Server, staging); + var plan = await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation); + await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation); + var chunks = server.ChunkCount; + + var again = await LocalImport.RunAsync(plan, new ServerImportSink(client, staging), verify: true, null, context.Cancellation); + Assert.Equal(0, again.Copied); + Assert.Equal(8, again.Duplicates); + Assert.Equal(chunks, server.ChunkCount); + } + + [Test] + public async Task AHashTheServerRejectsStopsTheImport() + { + var card = Card(context.CreateTempDirectory("card"), 8, Start); + var staging = context.CreateTempDirectory("staging"); + var server = new FakeUploadServer(chunkSize: 4096) { Corrupt = true }; + using var client = new TitanoClient(new Uri("https://nas.local:8443/"), new CertificatePinning([]), "tests", server) { Token = "t" }; + var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation); + var error = await Assert.ThrowsAsync(() => LocalImport.RunAsync(plan, new ServerImportSink(client, staging), true, null, context.Cancellation)); + Assert.Equal(HttpStatusCode.UnprocessableEntity, error.Status); + Assert.Empty(server.Committed); + } + + /// Start, chunk and complete of BRIEF §14.4, plus the title update; the hash is checked at completion. + private sealed class FakeUploadServer(int chunkSize) : HttpMessageHandler + { + private readonly Dictionary _open = []; + private readonly Dictionary _sequences = new(StringComparer.Ordinal); + private readonly Dictionary _frames = new(StringComparer.Ordinal); + + public List Committed { get; } = []; + public Dictionary Titles { get; } = []; + public int ChunkCount { get; private set; } + + /// Flip a byte of every received chunk (a damaged transfer). + public bool Corrupt { get; init; } + + protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + var path = request.RequestUri!.AbsolutePath.Trim('/').Split('/'); + if (request.Method == HttpMethod.Post && path is ["api", "v1", "uploads"]) + { + var start = (await request.Content!.ReadFromJsonAsync(ProtocolJson.Default.StartUploadRequest, cancellationToken))!; + if (_frames.TryGetValue(start.Sha256, out var existing)) + return Json(new StartUploadResponse(null, chunkSize, [], true, existing), ProtocolJson.Default.StartUploadResponse); + var upload = new Upload(Guid.NewGuid(), start.FileName, start.Size, start.Sha256, start.SessionKey ?? "user"); + _open[upload.Id] = upload; + return Json(new StartUploadResponse(upload.Id, chunkSize, [], false, null), ProtocolJson.Default.StartUploadResponse); + } + if (request.Method == HttpMethod.Put && path is ["api", "v1", "uploads", var id, "chunks", var n]) + { + var upload = _open[Guid.Parse(id)]; + var bytes = await request.Content!.ReadAsByteArrayAsync(cancellationToken); + if (Corrupt) bytes[0] ^= 0xFF; + upload.Parts[int.Parse(n, System.Globalization.CultureInfo.InvariantCulture)] = bytes; + ChunkCount++; + return Json(new ChunkReceived(int.Parse(n, System.Globalization.CultureInfo.InvariantCulture), [.. upload.Parts.Keys]), ProtocolJson.Default.ChunkReceived); + } + if (request.Method == HttpMethod.Post && path is ["api", "v1", "uploads", var done, "complete"]) + { + var upload = _open[Guid.Parse(done)]; + if (Convert.ToHexStringLower(SHA256.HashData(upload.Bytes)) != upload.Sha256) + return Json(new ApiError("hash_mismatch", "Hash mismatch"), ProtocolJson.Default.ApiError, HttpStatusCode.UnprocessableEntity); + _open.Remove(upload.Id); + Committed.Add(upload); + var frame = Guid.NewGuid(); + _frames[upload.Sha256] = frame; + if (!_sequences.TryGetValue(upload.SessionKey, out var sequence)) _sequences[upload.SessionKey] = sequence = Guid.NewGuid(); + return Json(new CompleteUploadResponse(frame, sequence, Committed.Count(u => u.SessionKey == upload.SessionKey) - 1), + ProtocolJson.Default.CompleteUploadResponse); + } + if (request.Method == HttpMethod.Patch && path is ["api", "v1", "sequences", var sequenceId]) + { + var update = (await request.Content!.ReadFromJsonAsync(ProtocolJson.Default.UpdateSequenceRequest, cancellationToken))!; + Titles[Guid.Parse(sequenceId)] = update.Title!; + return Json(new SequenceDto(Guid.Parse(sequenceId), update.Title, update.Title!, "f", null, null, null, null, null, 0, null, 0, 0, 0, null, [], 0, null, + 1, 1, 0, null, DateTimeOffset.UtcNow), ProtocolJson.Default.SequenceDto); + } + return new HttpResponseMessage(HttpStatusCode.NotFound); + } + + private static HttpResponseMessage Json(T value, System.Text.Json.Serialization.Metadata.JsonTypeInfo type, HttpStatusCode status = HttpStatusCode.OK) => + new(status) { Content = JsonContent.Create(value, type) }; + + public sealed record Upload(Guid Id, string FileName, long Size, string Sha256, string SessionKey) + { + public SortedDictionary Parts { get; } = []; + public byte[] Bytes => [.. Parts.Values.SelectMany(p => p)]; + public int Chunks => Parts.Count; + } + } +} From a0e814885c9274a33c56002a4c1a705c1aeed807 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 22:20:10 +0000 Subject: [PATCH 02/16] 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- and archive- from a simulated card and sample reports; en and it resources for both screens. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- i18n/en/Archive.resx | 98 ++ i18n/en/Import.resx | 153 ++- i18n/en/Tooltips.resx | 111 ++ i18n/it/Archive.it.resx | 98 ++ i18n/it/Import.it.resx | 151 ++- i18n/it/Tooltips.it.resx | 111 ++ .../Archive/ArchiveDialogViewModels.cs | 289 +++++ .../Archive/ArchiveRowViewModels.cs | 73 ++ src/Titano.App/Archive/ArchiveScenes.cs | 39 + src/Titano.App/Archive/CurrentArchive.cs | 31 + src/Titano.App/Archive/SampleReports.cs | 40 + src/Titano.App/DesignTime/SampleData.cs | 8 + src/Titano.App/Import/CardPool.cs | 7 +- src/Titano.App/Import/ImportDestinations.cs | 9 +- .../Import/ImportResultViewModel.cs | 249 ++++ src/Titano.App/Import/ImportScenes.cs | 49 + .../Import/ImportSessionRowViewModel.cs | 21 + src/Titano.App/Import/SampleCards.cs | 173 +++ src/Titano.App/Infrastructure/AppServices.cs | 6 + src/Titano.App/Infrastructure/IAppDialogs.cs | 6 + .../Infrastructure/WindowsDeviceMonitor.cs | 74 ++ src/Titano.App/Sections/ArchiveView.xaml | 464 ++++++- src/Titano.App/Sections/ArchiveView.xaml.cs | 19 + src/Titano.App/Sections/ArchiveViewModel.cs | 618 +++++++++- src/Titano.App/Sections/ImportView.xaml | 522 +++++++- src/Titano.App/Sections/ImportView.xaml.cs | 20 + src/Titano.App/Sections/ImportViewModel.cs | 1078 ++++++++++++++++- src/Titano.App/Shell/ConfirmDialog.xaml | 5 + src/Titano.App/Shell/ConfirmDialog.xaml.cs | 7 + src/Titano.App/Shell/ScreenCapture.cs | 24 +- .../Titano.App.Tests/Import/CardPoolTests.cs | 6 +- 31 files changed, 4531 insertions(+), 28 deletions(-) create mode 100644 src/Titano.App/Archive/ArchiveDialogViewModels.cs create mode 100644 src/Titano.App/Archive/ArchiveRowViewModels.cs create mode 100644 src/Titano.App/Archive/ArchiveScenes.cs create mode 100644 src/Titano.App/Archive/CurrentArchive.cs create mode 100644 src/Titano.App/Archive/SampleReports.cs create mode 100644 src/Titano.App/Import/ImportResultViewModel.cs create mode 100644 src/Titano.App/Import/ImportScenes.cs create mode 100644 src/Titano.App/Import/ImportSessionRowViewModel.cs create mode 100644 src/Titano.App/Import/SampleCards.cs create mode 100644 src/Titano.App/Infrastructure/WindowsDeviceMonitor.cs diff --git a/i18n/en/Archive.resx b/i18n/en/Archive.resx index 3c1d2424..951c7220 100644 --- a/i18n/en/Archive.resx +++ b/i18n/en/Archive.resx @@ -4,16 +4,37 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + {0:N0} sequence changed + {0:N0} sequences changed + offline + online + read-only + The archive must be online and writable.long + By camera + By format {0} · {1} · {2}invariant + Photos per month {0:N0} other {0:N0} others Other {0} · {1} · {2}invariant + Storage by year Unknown camera {0} · {1} · {2}invariant + Keep row + Remove row + Remove {0} from the index?long + Its sidecar is gone. Only the index row is removed; no file is deleted.long + Cancel {0:N0} copy {0:N0} copies + Folder + {0:N0} group + {0:N0} groups + Mark copies + Open {0} · {1}invariant + Duplicates No archive yet Another Titano ({0}) is writing here. Try again shortly.long: error sentence The copy of {0} does not match the original.long: error sentence @@ -24,11 +45,19 @@ {0} changed after the plan was made.long: error sentence The card or folder {0} is no longer available.long: error sentence The archive changed after this plan was made.long: error sentence + None found + Find + Searching… Every sequence verified Every sequence analysed {0} missing · {1} damaged {0:N0} duplicate frame {0:N0} duplicate frames + Analyse + Show + Find + Build + Verify No missing frames No duplicate frames {0:N0} sequence lacks proxies @@ -36,8 +65,10 @@ {0:N0} sequence not analysed {0:N0} sequences not analysed Every sequence has proxies + Index health {0:N0} sequence unverified {0:N0} sequences unverified + Last scan {0} · {1}long Dry run: nothing was changed.long: job log line Not indexed: {0} ({1})long: job log line Changed: {0}long: job log line @@ -51,16 +82,71 @@ {0} folders, {1} indexed, {2} adopted, {3} removedlong: job log line Sequence not found: {0}long: job log line {0} photos checked, {1} intact, {2} hashed, {3} with problemslong: job log line + Dry run + Rebuild proxies + Relink moved archive… + Run maintenance + {0:N0} issue + {0:N0} issues + The orphan search stoppedlong + Reconcile + Remove row + Scan + Index + The fix did not completelong + Files missing + Row without sidecar + Folder not indexed + Photos not listed {0:N0} file missing {0:N0} files missing Not indexed yet No sidecar in {0}long + Orphans {0:N0} photo not in sidecar {0:N0} photos not in sidecar + Archive + Counting… + Rebuild index + Indexed now + Without sidecar + Folder + Sidecars + Rebuild + State + History {0} · {1}invariant + Recent maintenance + {0} relinkedlong + The archive could not be relinkedlong + Folder of the moved archive + Apply + {0} of {1} + Rename {0:N0} sequence + Rename {0:N0} sequences + Move {0:N0} sequence + Move {0:N0} sequences + Changes {0:N0} of {1:N0} changes {0:N0} of {1:N0} change + Template + Add tags + Apply + Tags of {0:N0} sequence + Tags of {0:N0} sequences Each tag has 1 to {0} characters.long + Remove tags + {0:N0} sequence · all + {0:N0} sequences · all + Analyse + Export CSV + Selected set + Move… + Proxies + Rename… + Retag… + Thumbnails + Verify camera cameras {0:N0} format @@ -72,5 +158,17 @@ sequence sequences {0} – {1}invariant + Adopt folder… + Archive + Duplicates + Maintenance + Orphans + Rebuild index… + Scan + Verify + Archive tree Undated + Maintenance + View + Overview diff --git a/i18n/en/Import.resx b/i18n/en/Import.resx index 6443da66..1b9a34e4 100644 --- a/i18n/en/Import.resx +++ b/i18n/en/Import.resx @@ -8,29 +8,79 @@ Copy Already in archive Imported before + Deep analysis + Delete imported + Eject + Format card + Keep card + Available once the card is remembered.long Formatting needs a complete import with verified copies.long + Create or adopt an archive first (Library or Settings).long Only for a remembered card that is inserted.long Check the card first: every file and its copy are hashed again.long + Wait for the plan of the card.long + Sign in to a Titano Server first.long Some photos on the card have no verified copy; formatting would lose them.long Only imports into this PC's archive can be checked against the card.long + Insert the card first.long + Only removable cards can be ejected.long Nothing from this card has been imported yet.long + Every photo is already imported or in the archive.long No photo on the card matches a verified copy.long + Not enough free space at the destination.long + Fix the name templates first.long + Delete + Delete {0:N0} photo from the card?long + Delete {0:N0} photos from the card?long + Each one was hashed again on the card and in the archive just now. Files changed since are kept.long + Forget + Forget {0}?long + Its nickname, settings and import history are removed. Photos on the card and in the archive stay.long + Format + Format {0}?long + {0:N0} photo was copied and verified. Formatting removes everything on the card.long + {0:N0} photos were copied and verified. Formatting removes everything on the card.long + Keep card + Keep + Type the card name to confirmlong + Archive + Choose folder + Folder + Folder path + Not connected + Server + Close + Action + Destination + On the card copy {0} ({1}) {0:N0} file {0:N0} files Session {0} · {1}long + Plan Cannot read {0}: {1}long {0} · not insertedlong {0} #{1}invariant - {0} · {1} · {2} used - {0} · no DCIM · {1} free + {0} · {1} used + last import {0} + no DCIM · {0} free serial {0} Known card, not inserted Drive without DCIM Folder Known card New card + Import automatically + Folder… + Refresh devices + Devices + Import again + Skip Insert a card or pick a folder + Checking {0:N0} photo + Checking {0:N0} photos + Delete {0:N0} photo… + Delete {0:N0} photos… {0:N0} kept {0:N0} kept {0} · {1}invariant @@ -41,6 +91,18 @@ no longer on the card {0:N0} verified on the card {0:N0} verified on the card + Retry + Import into folder + Import from folder + After import + Destination + Duplicates + Names + Scan + File template + Folder template + → {0}invariant + Template tokens about {0} {0:N0} duplicate {0:N0} duplicates @@ -49,13 +111,100 @@ {0:N0} imported before {0:N0} session {0:N0} sessions + Show plan {0} missing + Plan + Copy settings from + Edit + Forget card… + Card nickname + Rename + {0} of {1} + Cancel + {0} of {1} + Starting… + {0:N0} already there + {0:N0} already there + Check card + {0:N0} copied + {0:N0} copied + Eject + {0} · {1}invariant + Failed photos + Format card… + Open in Library + New import No archive copy after the import; see the job log.long + {0} copied · {1} failedlong + {0:N0} skipped + {0:N0} skipped + {0:N0} copied and verified + {0:N0} copied and verified + frames + gap + Session gap in minutes + min + Minimum frames per session + min + Sessions + Subfolders + Verify hashes Adds to · {0}long + adds + Camera + Frames · interval + Sequence + Session + Size {0} · {1}invariant New · {0}long + new Server {0} · {1} → {2}invariant Import {0:N0} photo Import {0:N0} photos + Import + Import cancelled + Choose a card or a folder.long + Insert this card to plan its import.long + The card could not be read: {0}long + Reading the card… + {0:N0} photo read + {0:N0} photos read + Importing with its saved settingslong + Cancel + The card check stoppedlong + Deleting from the card stoppedlong + {0:N0} photo deleted from the cardlong + {0:N0} photos deleted from the cardlong + {0} importedlong + {0} can be removedlong + {0} could not be ejectedlong + {0} is in use; close its files and retrylong + Format of {0} cancelledlong + {0} was not formattedlong + {0} formattedlong + Import + {0} insertedlong + Resume + The interrupted import can continuelong + Importing {0}long + Aperture + Camera name + Capture date + Day of the month + Original extension + Hour and minute + ISO + Lens + Month + Frame number + Original name + Frame number in session + Session number + Session start time + Shutter speed + Capture time + Sequence title + Capture year diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 7ca6cbe4..460744d5 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -12,9 +12,120 @@ Open the public releases page in the browser Every language but English is machine-translated; propose a better wording on the public issue tracker Titano uses no third-party code: everything beyond .NET and Windows is written in-house + Index an existing folder tree in place; nothing is moved or renamed + The archive folder cannot be reached; the index stays as last seen + The archive folder is reachable and writable + Readable but not writable: browse only + Photos per camera; the smallest are grouped + Close without changing anything · Esc + Hide the sequences of this year + Show the folder of the first copy in Explorer + Open the sequence of the first copy in the editor + Find identical photos across sequences by hash · reads the index only + Show the sequences of this year + Queue the light analysis of these sequences + Find the duplicate groups + Find files and rows that do not match + Queue proxy generation for these sequences + Re-hash the originals of these sequences + Folder template; the title token is the new title · checked as you type + Photos per file format + Nothing to fix + Needs attention; the button fixes it + Open the job history + Keep the index row + Last incremental scan: when it finished and how long it took + Leases, temporary files, thumbnail packs and duplicate flags; relink a moved archive + List what maintenance would change, without changing it + Rebuild every proxy of the archive · runs in the background + Clean stale leases and temporary files, compact thumbnail packs, mark duplicates · originals untouched + Index health, duplicates, orphans and recent maintenance + Flag every copy after the first so renders skip it · runs maintenance + Photos per month by first capture + Find photos not in a sidecar, frames without a file and folders not indexed · reads the archive + Mark the missing files in the sidecar and the index + Remove the index row; no file is deleted + Scan the archive to index this folder + Add these photos to the sequence's sidecar and index + Tree, figures and charts + Choose which archive to manage + Choose which archive to manage · {0} + Rebuild the index from the sidecars; falls back to a full metadata scan; never deletes originals + Queue the rebuild · the archive stays usable meanwhile + Choose the new folder of an archive you moved; its sequences follow + Make exactly these changes to folders, sidecars and index · resumes after a crash + Change the tags of these sequences in sidecars and index + Incremental scan: new, changed and removed files by modification time and size + The selected years and sequences; nothing selected means all + Run the deep analysis on every sequence in the set + Export the set as CSV: one row per sequence + Move the set into a new folder layout · dry run first + Generate or refresh proxies + Rename the titles of the set with a template · dry run first + Add or remove tags on the whole set + Generate or refresh thumbnails + Re-hash the originals of the set + Bytes of originals per capture year + Tags to add, separated by commas + Tags to remove, separated by commas + Title template; the title token is the current title · checked as you type + Re-hash every original and report bit rot · reads the whole archive Dismiss Open the folder with the log files Return to the advisor's value + Import photos already in the archive again; nothing is overwritten + Copy into this PC's archive with the naming templates · {0} + Start the import with this card's settings as soon as it is inserted; a toast lets you cancel + Stop copying; verified copies stay and the import can resume + Do not import this card now + Hash every imported file on the card and its archive copy again · reads both + Choose the destination folder + Close the plan + Resolved or reported by the plan before copying + Use another card's saved settings + Queue the deep analysis of every imported sequence (runs in the background) + Delete from the card only the photos verified just now; asks first + After the import, offer to delete only the files whose copy was verified + Photos already in the archive (same hash) + Rename this card, copy settings from another card, or forget it + Safely eject the card + Safely eject the card when done + The import stopped; verified copies were kept + File template; the extension is kept · checked as you type + Import from any folder on this PC or on the network + Copy into a folder of your choice; not indexed unless you adopt it later + Folder used when the destination is Folder + Folder template · checked as you type + Remove this card's nickname, settings and history; photos stay + Open the Windows format dialog after a typed confirmation + After the import, offer the Windows format dialog once every copy is verified + Open the Windows format dialog + Minutes without photos that start a new session + Photos imported from this card before (same name, size and time) + Leave the card untouched + Keep every photo on the card + Keep this card remembered + This photo stays on the card + Show the imported sequences in the Library + Groups smaller than this join the previous session + Plan this card again + Name of this card in Titano · Enter saves + Open Import with this card selected + Look again for cards and folders with a DCIM tree + Change the nickname of this card + Copies hashed while copying and read back from the destination + Continue the interrupted import where it stopped + Continue the import where it stopped + Stream the frames to the server; each one counts once the server confirms its hash + Sequence title · empty keeps the folder name · Enter saves + Split the card into sessions when the gap between two photos exceeds the limit + Show every file, where it goes and what the plan resolved + Leave photos already in the archive (same hash) on the card + Free space at the destination after the import; on a server, what your quota leaves + Copy with verification; the card is only touched after every hash matches · Ctrl+Enter + Look inside every subfolder of the source + Insert a token into the template used last + Hash while copying and read the destination back before the source is touched Stop this job; Retry continues later from its last checkpoint Hide finished jobs from the list; they stay in the history Every job diff --git a/i18n/it/Archive.it.resx b/i18n/it/Archive.it.resx index 3c0c36a7..8689b0be 100644 --- a/i18n/it/Archive.it.resx +++ b/i18n/it/Archive.it.resx @@ -4,12 +4,33 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + {0:N0} sequenza modificata + {0:N0} sequenze modificate + offline + online + sola lettura + L'archivio deve essere raggiungibile e scrivibile. + Per fotocamera + Per formato + Foto al mese {0:N0} altra {0:N0} altre Altro + Spazio per anno Fotocamera ignota + Mantieni riga + Rimuovi riga + Rimuovere {0} dall'indice? + Il suo sidecar non c'è più. Viene rimossa solo la riga dell'indice; nessun file viene eliminato. + Annulla {0:N0} copia {0:N0} copie + Cartella + {0:N0} gruppo + {0:N0} gruppi + Segna copie + Apri + Doppioni Nessun archivio Un altro Titano ({0}) sta scrivendo qui. Riprova tra poco. La copia di {0} non corrisponde all'originale. @@ -20,11 +41,19 @@ {0} è cambiato dopo la creazione del piano. La scheda o cartella {0} non è più disponibile. L'archivio è cambiato dopo la creazione del piano. + Nessuno trovato + Cerca + Ricerca… Tutte le sequenze verificate Tutte le sequenze analizzate {0} mancanti · {1} danneggiati {0:N0} fotogramma doppio {0:N0} fotogrammi doppi + Analizza + Mostra + Cerca + Crea + Verifica Nessun fotogramma mancante Nessun fotogramma doppio {0:N0} sequenza senza proxy @@ -32,8 +61,10 @@ {0:N0} sequenza non analizzata {0:N0} sequenze non analizzate Proxy pronti per tutte + Stato dell'indice {0:N0} sequenza non verificata {0:N0} sequenze non verificate + Ultima scansione {0} · {1} Prova: nulla è stato modificato. Non indicizzata: {0} ({1}) Modificato: {0} @@ -47,15 +78,70 @@ {0} cartelle, {1} indicizzate, {2} adottate, {3} rimosse Sequenza non trovata: {0} {0} foto controllate, {1} integre, {2} con impronta nuova, {3} con problemi + Simulazione + Ricrea proxy + Ricollega archivio spostato… + Esegui manutenzione + {0:N0} problema + {0:N0} problemi + Ricerca degli orfani interrotta + Riallinea + Rimuovi riga + Scansiona + Indicizza + La correzione non è stata completata + File mancanti + Riga senza sidecar + Cartella non indicizzata + Foto non elencate {0:N0} file mancante {0:N0} file mancanti Non ancora indicizzata Nessun sidecar in {0} + Orfani {0:N0} foto fuori dal sidecar {0:N0} foto fuori dal sidecar + Archivio + Conteggio… + Ricostruisci indice + Ora nell'indice + Senza sidecar + Cartella + Sidecar + Ricostruisci + Stato + Cronologia + Manutenzione recente + {0} ricollegato + Impossibile ricollegare l'archivio + Nuova cartella dell'archivio + Applica + {0} di {1} + Rinomina {0:N0} sequenza + Rinomina {0:N0} sequenze + Sposta {0:N0} sequenza + Sposta {0:N0} sequenze + Modifiche {0:N0} di {1:N0} cambia {0:N0} di {1:N0} cambiano + Modello + Aggiungi tag + Applica + Tag di {0:N0} sequenza + Tag di {0:N0} sequenze Ogni tag ha da 1 a {0} caratteri. + Rimuovi tag + {0:N0} sequenza · tutte + {0:N0} sequenze · tutte + Analizza + Esporta CSV + Insieme scelto + Sposta… + Proxy + Rinomina… + Tag… + Miniature + Verifica fotocamera fotocamere {0:N0} formato @@ -66,5 +152,17 @@ foto sequenza sequenze + Adotta cartella… + Archivio + Doppioni + Manutenzione + Orfani + Ricostruisci indice… + Scansiona + Verifica + Albero dell'archivio Senza data + Manutenzione + Vista + Panoramica diff --git a/i18n/it/Import.it.resx b/i18n/it/Import.it.resx index eec667fb..02ead40b 100644 --- a/i18n/it/Import.it.resx +++ b/i18n/it/Import.it.resx @@ -8,28 +8,78 @@ Copia Già in archivio Già importata + Analisi profonda + Elimina importate + Espelli + Formatta scheda + Mantieni scheda + Disponibile quando la scheda è memorizzata. Per formattare serve un'importazione completa con copie verificate. + Crea o adotta prima un archivio (Libreria o Impostazioni). Solo per una scheda nota e inserita. Controlla prima la scheda: ogni file e la sua copia vengono verificati di nuovo. + Attendi il piano della scheda. + Accedi prima a un Titano Server. Alcune foto della scheda non hanno una copia verificata: formattando andrebbero perse. Solo le importazioni nell'archivio di questo PC si possono confrontare con la scheda. + Inserisci prima la scheda. + Si possono espellere solo schede rimovibili. Da questa scheda non è ancora stato importato nulla. + Ogni foto è già importata o in archivio. Nessuna foto della scheda corrisponde a una copia verificata. + Spazio libero insufficiente nella destinazione. + Correggi prima i modelli dei nomi. + Elimina + Eliminare {0:N0} foto dalla scheda? + Eliminare {0:N0} foto dalla scheda? + Ognuna è stata appena verificata di nuovo sulla scheda e in archivio. I file modificati da allora vengono mantenuti. + Dimentica + Dimenticare {0}? + Soprannome, impostazioni e cronologia delle importazioni vengono rimossi. Le foto sulla scheda e in archivio restano. + Formatta + Formattare {0}? + {0:N0} foto è stata copiata e verificata. La formattazione cancella tutto il contenuto della scheda. + {0:N0} foto sono state copiate e verificate. La formattazione cancella tutto il contenuto della scheda. + Mantieni scheda + Mantieni + Scrivi il nome della scheda per confermare + Archivio + Scegli cartella + Cartella + Percorso cartella + Non connesso + Server + Chiudi + Azione + Destinazione + Sulla scheda copia {0} ({1}) {0:N0} file {0:N0} file Sessione {0} · {1} + Piano Impossibile leggere {0}: {1} {0} · non inserita - {0} · {1} · {2} occupati - {0} · senza DCIM · {1} liberi + {0} · {1} occupati + ultima importazione {0} + senza DCIM · {0} liberi seriale {0} Scheda nota, non inserita Unità senza DCIM Cartella Scheda nota Nuova scheda + Importa automaticamente + Cartella… + Aggiorna dispositivi + Dispositivi + Importa di nuovo + Salta Inserisci una scheda o una cartella + Verifica di {0:N0} foto + Verifica di {0:N0} foto + Elimina {0:N0} foto… + Elimina {0:N0} foto… {0:N0} conservata {0:N0} conservate la copia in archivio è diversa @@ -39,6 +89,17 @@ non più sulla scheda {0:N0} verificata sulla scheda {0:N0} verificate sulla scheda + Riprova + Importa nella cartella + Importa dalla cartella + Dopo l'importazione + Destinazione + Doppioni + Nomi + Scansione + Modello file + Modello cartella + Segnaposto circa {0} {0:N0} doppione {0:N0} doppioni @@ -47,11 +108,97 @@ {0:N0} già importate {0:N0} sessione {0:N0} sessioni + Mostra piano mancano {0} + Piano + Copia impostazioni da + Modifica + Dimentica scheda… + Nome della scheda + Rinomina + {0} di {1} + Annulla + {0} di {1} + Avvio… + {0:N0} già presente + {0:N0} già presenti + Controlla scheda + {0:N0} copiata + {0:N0} copiate + Espelli + Foto non riuscite + Formatta scheda… + Apri nella Libreria + Nuova importazione Nessuna copia in archivio dopo l'importazione: vedi il registro dell'attività. + {0} copiate · {1} non riuscite + {0:N0} saltata + {0:N0} saltate + {0:N0} copiata e verificata + {0:N0} copiate e verificate + fotogrammi + pausa + Pausa tra sessioni (min) + minimo + Minimo fotogrammi a sessione + min + Sessioni + Sottocartelle + Verifica hash Si aggiunge a · {0} + aggiunge + Fotocamera + Fotogrammi · intervallo + Sequenza + Sessione + Dimensione Nuova · {0} + nuova Server Importa {0:N0} foto Importa {0:N0} foto + Importa + Importazione annullata + Scegli una scheda o una cartella. + Inserisci questa scheda per pianificarne l'importazione. + Impossibile leggere la scheda: {0} + Lettura della scheda… + {0:N0} foto letta + {0:N0} foto lette + Importazione con le impostazioni salvate + Annulla + Controllo della scheda interrotto + Eliminazione dalla scheda interrotta + {0:N0} foto eliminata dalla scheda + {0:N0} foto eliminate dalla scheda + Importazione di {0} completata + {0} può essere rimossa + Impossibile espellere {0} + {0} è in uso: chiudi i suoi file e riprova + Formattazione di {0} annullata + {0} non è stata formattata + {0} formattata + Importa + {0} inserita + Riprendi + L'importazione interrotta può continuare + Importazione di {0} + Diaframma + Nome fotocamera + Data di scatto + Giorno del mese + Estensione originale + Ora e minuti + ISO + Obiettivo + Mese + Numero fotogramma + Nome originale + Numero nella sessione + Numero di sessione + Inizio della sessione + Tempo di posa + Ora di scatto + Titolo della sequenza + Anno di scatto diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index c81ad08f..ea3bf870 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -12,9 +12,120 @@ Apri la pagina pubblica delle versioni nel browser Tutte le lingue tranne l'inglese sono tradotte automaticamente; proponi una formulazione migliore nel tracker pubblico Titano non usa codice di terze parti: tutto ciò che va oltre .NET e Windows è scritto internamente + Indicizza sul posto una cartella esistente; nulla viene spostato o rinominato + La cartella dell'archivio non è raggiungibile; l'indice resta com'era + La cartella dell'archivio è raggiungibile e scrivibile + Leggibile ma non scrivibile: solo consultazione + Foto per fotocamera; le minori sono raggruppate + Chiudi senza modificare nulla · Esc + Nascondi le sequenze di quest'anno + Mostra in Esplora risorse la cartella della prima copia + Apri nell'editor la sequenza della prima copia + Trova foto identiche tra le sequenze tramite hash · legge solo l'indice + Mostra le sequenze di quest'anno + Metti in coda l'analisi rapida di queste sequenze + Trova i gruppi di doppioni + Trova file e righe che non corrispondono + Metti in coda la creazione dei proxy per queste sequenze + Ricalcola l'hash degli originali di queste sequenze + Modello della cartella; il segnaposto title è il nuovo titolo · controllato mentre scrivi + Foto per formato di file + Nulla da correggere + Richiede attenzione; il pulsante lo risolve + Apri la cronologia delle attività + Mantieni la riga dell'indice + Ultima scansione incrementale: quando è finita e quanto è durata + Lease, file temporanei, pacchetti di miniature e segni dei doppioni; ricollega un archivio spostato + Elenca cosa cambierebbe la manutenzione, senza cambiarlo + Ricrea tutti i proxy dell'archivio · in background + Pulisce lease scaduti e file temporanei, compatta le miniature, segna i doppioni · originali intatti + Stato dell'indice, doppioni, orfani e manutenzione recente + Segna ogni copia dopo la prima perché i render la saltino · esegue la manutenzione + Foto al mese per data del primo scatto + Trova foto fuori dai sidecar, fotogrammi senza file e cartelle non indicizzate · legge l'archivio + Segna i file mancanti nel sidecar e nell'indice + Rimuove la riga dell'indice; nessun file viene eliminato + Scansiona l'archivio per indicizzare questa cartella + Aggiunge queste foto al sidecar e all'indice della sequenza + Albero, cifre e grafici + Scegli quale archivio gestire + Scegli quale archivio gestire · {0} + Ricostruisce l'indice dai sidecar; se mancano legge i metadati; non elimina mai gli originali + Metti in coda la ricostruzione · l'archivio resta utilizzabile + Scegli la nuova cartella di un archivio spostato; le sequenze lo seguono + Applica esattamente queste modifiche a cartelle, sidecar e indice · riprende dopo un arresto + Cambia i tag di queste sequenze in sidecar e indice + Scansione incrementale: file nuovi, modificati e rimossi per data e dimensione + Anni e sequenze selezionati; senza selezione, tutte + Esegui l'analisi profonda su ogni sequenza dell'insieme + Esporta l'insieme in CSV: una riga per sequenza + Sposta l'insieme in una nuova struttura di cartelle · prima la prova + Crea o aggiorna i proxy + Rinomina i titoli dell'insieme con un modello · prima la prova + Aggiungi o rimuovi tag su tutto l'insieme + Crea o aggiorna le miniature + Ricalcola l'hash degli originali dell'insieme + Spazio degli originali per anno di scatto + Tag da aggiungere, separati da virgole + Tag da rimuovere, separati da virgole + Modello del titolo; il segnaposto title è il titolo attuale · controllato mentre scrivi + Ricalcola l'hash di ogni originale e segnala i danni · legge tutto l'archivio Chiudi Apri la cartella dei file di log Torna al valore consigliato + Importa di nuovo le foto già in archivio; nulla viene sovrascritto + Copia nell'archivio di questo PC con i modelli dei nomi · {0} + Avvia l'importazione con le impostazioni della scheda appena viene inserita; un avviso permette di annullare + Ferma la copia; le copie verificate restano e l'importazione può riprendere + Non importare ora questa scheda + Ricalcola l'hash di ogni file importato sulla scheda e della sua copia · legge entrambi + Scegli la cartella di destinazione + Chiudi il piano + Risolto o segnalato dal piano prima della copia + Usa le impostazioni salvate di un'altra scheda + Metti in coda l'analisi profonda di ogni sequenza importata (in background) + Elimina dalla scheda solo le foto appena verificate; chiede conferma + Dopo l'importazione, proponi di eliminare solo i file con copia verificata + Foto già in archivio (stesso hash) + Rinomina la scheda, copia le impostazioni da un'altra o dimenticala + Espelli la scheda in sicurezza + Espelli la scheda in sicurezza al termine + L'importazione si è fermata; le copie verificate sono state mantenute + Modello del file; l'estensione resta · controllato mentre scrivi + Importa da una cartella di questo PC o della rete + Copia in una cartella a scelta; non indicizzata finché non la adotti + Cartella usata quando la destinazione è Cartella + Modello della cartella · controllato mentre scrivi + Rimuovi soprannome, impostazioni e cronologia della scheda; le foto restano + Apri la formattazione di Windows dopo una conferma scritta + Dopo l'importazione, proponi la formattazione di Windows quando ogni copia è verificata + Apri la formattazione di Windows + Minuti senza foto che avviano una nuova sessione + Foto già importate da questa scheda (stesso nome, dimensione e data) + Lascia intatta la scheda + Mantieni tutte le foto sulla scheda + Mantieni la scheda in memoria + Questa foto resta sulla scheda + Mostra le sequenze importate nella Libreria + I gruppi più piccoli si uniscono alla sessione precedente + Pianifica di nuovo questa scheda + Nome della scheda in Titano · Invio salva + Apri Importa con questa scheda selezionata + Cerca di nuovo schede e cartelle con DCIM + Cambia il nome della scheda + Copie verificate con hash durante la copia e rilette dalla destinazione + Continua l'importazione interrotta da dove si è fermata + Continua l'importazione da dove si è fermata + Invia i fotogrammi al server; ognuno conta quando il server ne conferma l'hash + Titolo della sequenza · vuoto mantiene il nome della cartella · Invio salva + Dividi la scheda in sessioni quando la pausa tra due foto supera il limite + Mostra ogni file, dove andrà e cosa ha risolto il piano + Lascia sulla scheda le foto già in archivio (stesso hash) + Spazio libero nella destinazione dopo l'importazione; su un server, quanto resta della tua quota + Copia con verifica; la scheda si tocca solo dopo che ogni hash coincide · Ctrl+Invio + Cerca in ogni sottocartella della sorgente + Inserisci un segnaposto nell'ultimo modello usato + Calcola l'hash durante la copia e rileggi la destinazione prima di toccare la sorgente Ferma questa attività; Riprova la continua più tardi dall'ultimo punto di ripresa Nasconde le attività concluse dall'elenco; restano nella cronologia Tutte le attività diff --git a/src/Titano.App/Archive/ArchiveDialogViewModels.cs b/src/Titano.App/Archive/ArchiveDialogViewModels.cs new file mode 100644 index 00000000..fe43b98c --- /dev/null +++ b/src/Titano.App/Archive/ArchiveDialogViewModels.cs @@ -0,0 +1,289 @@ +using System.IO; +using System.Windows.Input; +using System.Windows.Threading; +using Titano.App.Infrastructure; +using Titano.App.Settings; +using Titano.Core.Archiving; +using Titano.Core.Diagnostics; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Data; +using Titano.Data.Archiving; +using Titano.Ui.Mvvm; + +namespace Titano.App.Archiving; + +/// An in-window dialog of the Archive screen: one primary action, one way out. +public abstract class ArchiveDialogViewModel(Action close) : LocalizedViewModel +{ + private bool _isBusy; + private string? _busyText; + + public ICommand CloseCommand { get; } = new RelayCommand(close); + + public bool IsBusy + { + get => _isBusy; + protected set + { + if (Set(ref _isBusy, value)) CommandManager.InvalidateRequerySuggested(); + } + } + + public string? BusyText { get => _busyText; protected set => Set(ref _busyText, value); } + + protected void Close() => CloseCommand.Execute(null); +} + +/// A fact of the rebuild dialog ("Sidecars · 412"). +public sealed record DialogFact(string Label, string Value); + +/// +/// "Rebuild index" (BRIEF §12.5): what the rebuild reads — the sidecars on disk, then a full metadata scan of folders +/// without one — next to what the index holds now. Originals are never touched; the rebuild runs as a job. +/// +public sealed class RebuildDialogViewModel : ArchiveDialogViewModel +{ + private readonly Func _rebuild; + private IReadOnlyList _facts; + + public RebuildDialogViewModel(Core.Model.Archive archive, ArchiveAvailability availability, int indexed, Func rebuild, Action close) + : base(close) + { + _rebuild = rebuild; + Archive = archive; + Availability = availability; + Indexed = indexed; + _facts = Facts(null); + RebuildCommand = new AsyncRelayCommand(RebuildAsync, () => !IsBusy && availability == ArchiveAvailability.Online); + } + + public Core.Model.Archive Archive { get; } + public ArchiveAvailability Availability { get; } + public int Indexed { get; } + + public IReadOnlyList FactRows { get => _facts; private set => Set(ref _facts, value); } + + public ICommand RebuildCommand { get; } + + public string RebuildToolTip => Availability == ArchiveAvailability.Online ? Loc.L("Tooltips.Archive.RebuildStart") : Loc.L("Archive.Blocked.NotOnline"); + + /// Counts sequence folders with and without a sidecar (a walk of the archive tree, off the UI thread). + public async Task CountAsync() + { + if (Availability == ArchiveAvailability.Offline) return; + BusyText = Loc.L("Archive.Rebuild.Counting"); + try + { + var root = Archive.RootPath; + var folders = await Task.Run(() => ArchiveScanner.FindSequenceFolders(new ArchivePaths(root))); + FactRows = Facts(folders); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) + { + Log.Warning("archive", "Counting sidecars failed", ex); + } + finally + { + BusyText = null; + } + } + + /// Shows counts computed elsewhere (capture). + public void ShowFolders(IReadOnlyList folders) => FactRows = Facts(folders); + + private IReadOnlyList Facts(IReadOnlyList? folders) + { + var waiting = Loc.L("Archive.Rebuild.Counting"); + return + [ + new(Loc.L("Archive.Rebuild.Archive"), Archive.Name), + new(Loc.L("Archive.Rebuild.Root"), Archive.RootPath), + new(Loc.L("Archive.Rebuild.State"), Loc.L("Archive.Availability." + Availability)), + new(Loc.L("Archive.Rebuild.Indexed"), Loc.Plural("Shell.Status.Sequences", Indexed)), + new(Loc.L("Archive.Rebuild.Sidecars"), folders is null ? waiting : Formatting.Count(folders.Count(f => f.Sidecar is not null))), + new(Loc.L("Archive.Rebuild.Metadata"), folders is null ? waiting : Formatting.Count(folders.Count(f => f.Sidecar is null))), + ]; + } + + private async Task RebuildAsync() + { + IsBusy = true; + try + { + await _rebuild(); + Close(); + } + finally + { + IsBusy = false; + } + } +} + +/// +/// Mass rename (titles) or move (folder layout) of a set (BRIEF §7, §12.5): the template is checked as it is typed, +/// the dry run lists every change, and Apply makes exactly those changes (journaled, so a crash resumes it). +/// +public sealed class RenameDialogViewModel : ArchiveDialogViewModel +{ + private readonly ArchiveService _archives; + private readonly Core.Model.Archive _archive; + private readonly IReadOnlyList _set; + private readonly Func _applied; + private readonly DispatcherTimer _delay = new() { Interval = TimeSpan.FromMilliseconds(400) }; + private RenamePlan? _plan; + private IReadOnlyList _rows = []; + private CancellationTokenSource? _planning; + + public RenameDialogViewModel(RenameMode mode, ArchiveService archives, Core.Model.Archive archive, IReadOnlyList set, Func applied, + Action close) + : base(close) + { + Mode = mode; + _archives = archives; + _archive = archive; + _set = set; + _applied = applied; + var initial = mode == RenameMode.Folders ? archive.FolderTemplate : "{title}"; + Template = new EditableField(initial, t => MassRename.Validate(mode, t), committed => _ = PlanAsync(), + () => Loc.L(mode == RenameMode.Folders ? "Tooltips.Archive.FolderTemplate" : "Tooltips.Archive.TitleTemplate")); + Template.PropertyChanged += (_, e) => + { + if (e.PropertyName != nameof(EditableField.Text)) return; + _delay.Stop(); + _delay.Start(); + }; + _delay.Tick += (_, _) => + { + _delay.Stop(); + _ = PlanAsync(); + }; + ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => !IsBusy && _plan is { Steps.Count: > 0 } && !Template.HasErrors); + } + + public RenameMode Mode { get; } + + public string Heading => Loc.Plural(Mode == RenameMode.Folders ? "Archive.Rename.MoveHeading" : "Archive.Rename.Heading", _set.Count); + + public EditableField Template { get; } + + public IReadOnlyList Rows { get => _rows; private set => Set(ref _rows, value); } + + public string SummaryText => _plan is null ? string.Empty : MassRename.Summary(_plan, _set.Count); + + public ICommand ApplyCommand { get; } + + /// The dry run of the current template (the engine's plan; nothing changes on disk). + public async Task PlanAsync() + { + _planning?.Cancel(); + _plan = null; + Rows = []; + OnPropertyChanged(nameof(SummaryText)); + if (Template.HasErrors) return; + var cts = _planning = new CancellationTokenSource(); + var template = Template.Text; + var ids = _set.Select(s => s.Id).ToList(); + try + { + var plan = await Task.Run(() => _archives.PlanRenameAsync(_archive.Id, ids, Mode == RenameMode.Folders ? template : null, + Mode == RenameMode.Titles ? template : null, cts.Token), cts.Token); + if (cts.IsCancellationRequested) return; + _plan = plan; + Rows = MassRename.Rows(plan, Mode); + OnPropertyChanged(nameof(SummaryText)); + CommandManager.InvalidateRequerySuggested(); + } + catch (OperationCanceledException) when (cts.IsCancellationRequested) + { + } + catch (Exception ex) when (ex is ArgumentException or DatabaseException or FormatException) + { + Log.Warning("archive", "Rename plan failed", ex); + BusyText = ex.Message; + } + } + + private async Task ApplyAsync() + { + if (_plan is not { } plan) return; + IsBusy = true; + var progress = new Progress(n => BusyText = Loc.L("Archive.Rename.Applying", Formatting.Count(n), Formatting.Count(plan.Steps.Count))); + try + { + await Task.Run(() => _archives.ApplyRenameAsync(plan, progress)); + await _applied(plan.Steps.Count); + Close(); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or StaleRenamePlanException or ArchiveOfflineException) + { + Log.Warning("archive", "Rename failed", ex); + BusyText = ex.Message; + } + finally + { + IsBusy = false; + } + } +} + +/// Add and remove tags on a set (BRIEF §12.5 Retag): the dry run counts the sequences that change. +public sealed class RetagDialogViewModel : ArchiveDialogViewModel +{ + private readonly ArchiveService _archives; + private readonly IReadOnlyList _set; + private readonly Func _applied; + + public RetagDialogViewModel(ArchiveService archives, IReadOnlyList set, Func applied, Action close) + : base(close) + { + _archives = archives; + _set = set; + _applied = applied; + Add = new EditableField(string.Empty, Retag.Validate, _ => OnPropertyChanged(nameof(SummaryText)), () => Loc.L("Tooltips.Archive.TagsAdd")); + Remove = new EditableField(string.Empty, Retag.Validate, _ => OnPropertyChanged(nameof(SummaryText)), () => Loc.L("Tooltips.Archive.TagsRemove")); + Add.PropertyChanged += (_, _) => OnPropertyChanged(nameof(SummaryText)); + Remove.PropertyChanged += (_, _) => OnPropertyChanged(nameof(SummaryText)); + ApplyCommand = new AsyncRelayCommand(ApplyAsync, () => !IsBusy && Changes().Count > 0); + } + + public string Heading => Loc.Plural("Archive.Retag.Heading", _set.Count); + + public EditableField Add { get; } + public EditableField Remove { get; } + + /// "12 of 36 change". + public string SummaryText => Loc.Plural("Archive.Rename.Summary", Changes().Count, _set.Count); + + public ICommand ApplyCommand { get; } + + private IReadOnlyList<(Sequence Sequence, IReadOnlyList Tags)> Changes() => + Add.HasErrors || Remove.HasErrors ? [] : Retag.Changes(_set, Retag.Parse(Add.Text), Retag.Parse(Remove.Text)); + + private async Task ApplyAsync() + { + var changes = Changes(); + IsBusy = true; + try + { + for (var i = 0; i < changes.Count; i++) + { + var (s, tags) = changes[i]; + BusyText = Loc.L("Archive.Rename.Applying", Formatting.Count(i + 1), Formatting.Count(changes.Count)); + await Task.Run(() => _archives.SetSequenceInfoAsync(s.Id, s.Title, tags, s.Rating, s.Notes)); + } + await _applied(changes.Count); + Close(); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException or ArchiveOfflineException) + { + Log.Warning("archive", "Retag failed", ex); + BusyText = ex.Message; + } + finally + { + IsBusy = false; + } + } +} diff --git a/src/Titano.App/Archive/ArchiveRowViewModels.cs b/src/Titano.App/Archive/ArchiveRowViewModels.cs new file mode 100644 index 00000000..b386232e --- /dev/null +++ b/src/Titano.App/Archive/ArchiveRowViewModels.cs @@ -0,0 +1,73 @@ +using System.Windows.Input; +using Titano.Core.Archiving; +using Titano.Core.Localization; +using Titano.Ui.Controls; +using Titano.Ui.Mvvm; + +namespace Titano.App.Archiving; + +/// A visible row of the archive tree: indentation, expander, title, figures and availability. +public sealed class ArchiveTreeRowViewModel(ArchiveTreeNode node, ArchiveAvailability availability, Action toggle) : ObservableObject +{ + public ArchiveTreeNode Node { get; } = node; + + public string Title => Node.Title; + public string Detail => Node.Detail; + + /// 16 px per level. + public System.Windows.Thickness IndentMargin => new(Node.Depth * 16, 0, 0, 0); + + public bool HasChildren => Node.HasChildren; + public bool IsExpanded => Node.IsExpanded; + public bool IsArchive => Node.Kind == TreeNodeKind.Archive; + public bool IsYear => Node.Kind == TreeNodeKind.Year; + + public string ToggleToolTip => Loc.L(Node.IsExpanded ? "Tooltips.Archive.Collapse" : "Tooltips.Archive.Expand"); + + public ICommand ToggleCommand { get; } = new RelayCommand(() => toggle(node)); + + /// The archive's availability (BRIEF §7: online, read-only, offline) on the archive row. + public StatusKind AvailabilityKind => availability switch + { + ArchiveAvailability.Online => StatusKind.Online, + ArchiveAvailability.ReadOnly => StatusKind.Warning, + _ => StatusKind.Offline, + }; + + public string AvailabilityText => Loc.L("Archive.Availability." + availability); + + public string AvailabilityToolTip => Loc.L("Tooltips.Archive.Availability." + availability); +} + +/// A line of "Index health" with its fix. +public sealed class HealthLineViewModel(HealthLine line, ICommand? fix) : ObservableObject +{ + public HealthLine Line { get; } = line; + public string Text => Line.Text; + public StatusKind Kind => Line.IsOk ? StatusKind.Done : StatusKind.Warning; + public string KindToolTip => Loc.L(Line.IsOk ? "Tooltips.Archive.HealthOk" : "Tooltips.Archive.HealthWarning"); + public bool HasFix => FixCommand is not null && Line.Action != HealthAction.None; + public ICommand? FixCommand { get; } = fix; + public string FixText => HasFix ? Loc.L("Archive.Health.Fix." + Line.Action) : string.Empty; + public string FixToolTip => HasFix ? Loc.L("Tooltips.Archive.Fix." + Line.Action) : string.Empty; +} + +/// A duplicate group with its safe actions: open the first copy's sequence, show its folder. +public sealed class DuplicateRowViewModel(DuplicateRow row, ICommand open, ICommand reveal) : ObservableObject +{ + public DuplicateRow Row { get; } = row; + public string Places => string.Join(" · ", Row.Places); + public ICommand OpenCommand { get; } = open; + public ICommand RevealCommand { get; } = reveal; +} + +/// An orphan line with its fix (index, reconcile, remove the row, scan). +public sealed class OrphanRowViewModel(OrphanRow row, ICommand fix) : ObservableObject +{ + public OrphanRow Row { get; } = row; + public StatusKind Kind => Row.Kind is OrphanKind.MissingFiles or OrphanKind.MissingSequence ? StatusKind.Warning : StatusKind.Queued; + public string KindText => Loc.L("Archive.Orphans.Kind." + Row.Kind); + public ICommand FixCommand { get; } = fix; + public string FixText => Loc.L("Archive.Orphans.Fix." + Row.Kind); + public string FixToolTip => Loc.L("Tooltips.Archive.Orphans." + Row.Kind); +} diff --git a/src/Titano.App/Archive/ArchiveScenes.cs b/src/Titano.App/Archive/ArchiveScenes.cs new file mode 100644 index 00000000..f9572fc8 --- /dev/null +++ b/src/Titano.App/Archive/ArchiveScenes.cs @@ -0,0 +1,39 @@ +using Titano.App.Shell; + +namespace Titano.App.Archiving; + +/// +/// The Archive views that --capture renders (archive-<view>-<theme>.png) and the screen smoke +/// tests check, on the sample archive: the tree with figures and charts, the maintenance view with its reports, and +/// the rebuild dialog. +/// +public static class ArchiveScenes +{ + public static readonly IReadOnlyList Views = ["overview", "maintenance", "rebuild"]; + + public static async Task ShowAsync(ShellViewModel shell, string view) + { + var archive = shell.Archive; + shell.Navigate(SectionKey.Archive); + archive.Dialog?.CloseCommand.Execute(null); + await archive.LoadAsync(); + var db = shell.Services.Database ?? throw new InvalidOperationException("The sample index is not open."); + var locations = archive.SelectedArchive is { } selected ? await db.Sequences.ListLocationsAsync(selected.Id) : []; + switch (view) + { + case "overview": + archive.ViewIndex = 0; + break; + case "maintenance": + archive.ViewIndex = 1; + archive.ShowReports(SampleReports.Duplicates(locations), SampleReports.Orphans(locations), locations); + break; + case "rebuild": + archive.ViewIndex = 0; + (await archive.OpenRebuildDialogAsync())?.ShowFolders(SampleReports.Folders(locations)); + break; + default: + throw new ArgumentOutOfRangeException(nameof(view), view, "Unknown Archive view."); + } + } +} diff --git a/src/Titano.App/Archive/CurrentArchive.cs b/src/Titano.App/Archive/CurrentArchive.cs new file mode 100644 index 00000000..b4357c93 --- /dev/null +++ b/src/Titano.App/Archive/CurrentArchive.cs @@ -0,0 +1,31 @@ +using System.IO; +using Titano.Data; + +namespace Titano.App.Archiving; + +/// The archive the Import and Archive screens work on: the one at the remembered root, else the first indexed. +public static class CurrentArchive +{ + public static Core.Model.Archive? Pick(IReadOnlyList archives, string? lastRoot) + { + if (archives.Count == 0) return null; + if (string.IsNullOrWhiteSpace(lastRoot)) return archives[0]; + var wanted = Normalize(lastRoot); + return archives.FirstOrDefault(a => string.Equals(Normalize(a.RootPath), wanted, StringComparison.OrdinalIgnoreCase)) ?? archives[0]; + } + + public static async Task FindAsync(TitanoDatabase db, string? lastRoot, CancellationToken cancellationToken = default) => + Pick(await db.Archives.ListAsync(cancellationToken).ConfigureAwait(false), lastRoot); + + private static string Normalize(string path) + { + try + { + return Path.TrimEndingDirectorySeparator(Path.GetFullPath(path)); + } + catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException) + { + return path; + } + } +} diff --git a/src/Titano.App/Archive/SampleReports.cs b/src/Titano.App/Archive/SampleReports.cs new file mode 100644 index 00000000..3aed3f79 --- /dev/null +++ b/src/Titano.App/Archive/SampleReports.cs @@ -0,0 +1,40 @@ +using Titano.Core.Archiving; +using Titano.Data.Archiving; +using Titano.Data.Repositories; + +namespace Titano.App.Archiving; + +/// +/// Capture and smoke-test data ONLY: maintenance reports and rebuild counts over the sample archive's sequences +/// (the sample index has no sidecars on disk, so the real searches would find nothing to show). +/// +public static class SampleReports +{ + private const string Sha = "9f2c41d07be8a6c3e15f0d2b84a97c6e3d1f50a28b9e7c4d6a0f3e2b1c8d9a47"; + + /// One photo stored twice: a frame of the first sequence copied into the second. + public static IReadOnlyList Duplicates(IReadOnlyList sequences) => + sequences.Count < 2 + ? [] + : + [ + new DuplicateGroup(Sha, + [ + new DuplicateFrame(Sha, Guid.CreateVersion7(), sequences[0].Id, 0, sequences[0].Folder + "/IMG_0001.CR2"), + new DuplicateFrame(Sha, Guid.CreateVersion7(), sequences[1].Id, 12, sequences[1].Folder + "/IMG_0001.CR2"), + ]), + ]; + + /// Two photos missing from a sidecar, a row whose sidecar is gone and a folder not indexed yet. + public static OrphanReport Orphans(IReadOnlyList sequences) => + sequences.Count < 4 + ? new OrphanReport([], [], []) + : new OrphanReport([new SequenceOrphans(sequences[2].Folder, ["IMG_0412.CR2", "IMG_0413.CR2"], [])], [sequences[3]], ["2024/2024-12-31 Unsorted"]); + + /// What the rebuild dialog counts: a sidecar in every sequence folder but the last two, read by metadata instead. + public static IReadOnlyList Folders(IReadOnlyList sequences) + { + var stamp = new FileStamp(4_096, DateTime.UtcNow); + return [.. sequences.Select((s, i) => new SequenceFolder(s.Folder, i < sequences.Count - 2 ? stamp : null, stamp))]; + } +} diff --git a/src/Titano.App/DesignTime/SampleData.cs b/src/Titano.App/DesignTime/SampleData.cs index 105b4f1a..e7a06635 100644 --- a/src/Titano.App/DesignTime/SampleData.cs +++ b/src/Titano.App/DesignTime/SampleData.cs @@ -1,9 +1,11 @@ using System.IO; using System.Net; using Titano.App.About; +using Titano.App.Import; using Titano.App.Infrastructure; using Titano.App.Server; using Titano.App.Settings; +using Titano.Core.Archiving; using Titano.Core.Codecs.Jpeg; using Titano.Core.Imaging; using Titano.Core.Model; @@ -38,6 +40,8 @@ public sealed class SampleData services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(), new PlainTokenProtector()); services.Encoders = new SampleEncoders(); services.CheckForUpdateAsync = _ => Task.FromResult(null); + services.Devices.Dispose(); + services.Devices = new SampleDeviceMonitor(); return new SampleData(services); } @@ -57,6 +61,9 @@ public sealed class SampleData Directory.CreateDirectory(root); var archive = new Archive { Id = Guid.CreateVersion7(), Name = "TitanoArchive", RootPath = root, Created = DateTimeOffset.UtcNow.AddYears(-2) }; await db.Archives.UpsertAsync(archive); + var paths = new ArchivePaths(root); + Directory.CreateDirectory(paths.MetaDirectory); + ManifestStore.WriteArchive(paths.ManifestPath, new ArchiveManifest { Id = archive.Id, Name = archive.Name, Created = archive.Created }); var sequences = Sequences(archive.Id).ToList(); foreach (var (sequence, colours, raw) in sequences) @@ -68,6 +75,7 @@ public sealed class SampleData await db.Sequences.SetTagsAsync(sequences[9].Sequence.Id, ["holy grail"]); foreach (var job in Jobs(sequences.Select(s => s.Sequence).ToList(), archive.Id)) await db.Jobs.EnqueueAsync(job); + await SampleCards.InsertAsync(db, (SampleDeviceMonitor)_services.Devices, _services.Environment.DataDirectory); settings.LastArchivePath = @"D:\TitanoArchive"; settings.ServerUrl = "https://nas.local:8443"; diff --git a/src/Titano.App/Import/CardPool.cs b/src/Titano.App/Import/CardPool.cs index 1c0b13f3..8882011f 100644 --- a/src/Titano.App/Import/CardPool.cs +++ b/src/Titano.App/Import/CardPool.cs @@ -36,12 +36,12 @@ public sealed record ImportSource(string Key, SourceKind Kind, CardDevice? Devic : Device is { Label.Length: > 0 } labelled ? labelled.Label : Device?.Root ?? FolderPath ?? Card?.Label ?? string.Empty; - /// "E:\ · 128 GB · 96.2 GB used", "no DCIM · 1.8 TB free", "Canon EOS R5 · not inserted". + /// "128 GB · 96.2 GB used", "no DCIM · 1.8 TB free", "Canon EOS R5 · not inserted". 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)), + 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)), }; @@ -61,7 +61,6 @@ public sealed record ImportSource(string Key, SourceKind Kind, CardDevice? Devic get { var parts = new List(); - 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; diff --git a/src/Titano.App/Import/ImportDestinations.cs b/src/Titano.App/Import/ImportDestinations.cs index f97e9fc6..a24f7a59 100644 --- a/src/Titano.App/Import/ImportDestinations.cs +++ b/src/Titano.App/Import/ImportDestinations.cs @@ -35,12 +35,17 @@ public sealed class UnindexedDestination(ImportDestinationKind kind, string root /// The folder, or the local staging folder of server uploads. public string Root { get; } = root; - public Task PlanAsync(string sourceRoot, ImportOptions options, Guid? cardId, IProgress? progress, CancellationToken cancellationToken) + /// Room left on the server (the user's quota); null when unlimited or unknown. A folder reports its volume's space. + public long? ServerSpace { get; init; } + + public async Task PlanAsync(string sourceRoot, ImportOptions options, Guid? cardId, IProgress? progress, CancellationToken cancellationToken) { var problems = new List(); var files = CardScanner.Find(sourceRoot, options.IncludeSubfolders, cancellationToken); var photos = CardScanner.ReadMetadata(sourceRoot, files, problems, progress, cancellationToken); - return ImportPlanner.PlanAsync(sourceRoot, Root, photos, problems, options, NoIndex.Instance, cancellationToken); + var plan = await ImportPlanner.PlanAsync(sourceRoot, Root, photos, problems, options, NoIndex.Instance, cancellationToken).ConfigureAwait(false); + // Staging only ever holds one batch; the space that matters for a server import is the quota. + return Kind == ImportDestinationKind.Server ? plan with { AvailableBytes = ServerSpace } : plan; } /// No history and no index; folders are reused so a repeated import lands next to the first one. diff --git a/src/Titano.App/Import/ImportResultViewModel.cs b/src/Titano.App/Import/ImportResultViewModel.cs new file mode 100644 index 00000000..42bde730 --- /dev/null +++ b/src/Titano.App/Import/ImportResultViewModel.cs @@ -0,0 +1,249 @@ +using System.IO; +using System.Windows.Input; +using Titano.App.Infrastructure; +using Titano.App.Shell; +using Titano.Core.Diagnostics; +using Titano.Core.Import; +using Titano.Core.Localization; +using Titano.Core.Model; +using Titano.Data; +using Titano.Data.Archiving; +using Titano.Ui.Controls; +using Titano.Ui.Mvvm; + +namespace Titano.App.Import; + +/// +/// The end of an import (BRIEF §12.4, §13): the verification result and the after-import actions — check the card +/// (dry run: every card file and its archive copy hashed again), delete the verified photos or format the card +/// (each after a confirmation, never by default), eject, open in the Library. decides +/// what is allowed and why not. +/// +public sealed class ImportResultViewModel : LocalizedViewModel +{ + private const int ListedFailures = 100; + + private readonly ShellViewModel _shell; + private readonly ImportPlan _plan; + private readonly ImportChoices _choices; + private readonly Core.Model.Archive? _archive; + private readonly MediaCard? _card; + private CardDevice? _device; + private CardActions _actions; + private bool _isBusy; + private string? _busyText; + + public ImportResultViewModel(ShellViewModel shell, ImportPlan plan, ImportOutcome outcome, ImportChoices choices, Core.Model.Archive? archive, + MediaCard? card, CardDevice? device) + { + _shell = shell; + _plan = plan; + _choices = choices; + _archive = archive; + _card = card; + _device = device; + Outcome = outcome; + _actions = new CardActions(choices.Destination, card is not null, device is not null, device?.IsRemovable == true, outcome, null, + plan.FileCount + plan.Problems.Count); + Failures = [.. outcome.Failures.Take(ListedFailures).Select(f => Loc.L("Import.Result.Failure", f.SourcePath, f.Message))]; + CheckCommand = new AsyncRelayCommand(CheckAsync, () => _actions.CanCheck && !_isBusy); + DeleteCommand = new AsyncRelayCommand(DeleteAsync, () => _actions.CanDelete && !_isBusy); + FormatCommand = new RelayCommand(Format, () => _actions.CanFormat && !_isBusy); + EjectCommand = new AsyncRelayCommand(EjectAsync, () => _actions.CanEject && !_isBusy); + OpenLibraryCommand = new AsyncRelayCommand(async () => + { + await _shell.Library.RefreshAsync(); + _shell.Navigate(SectionKey.Library); + }); + } + + public ImportOutcome Outcome { get; } + + public CardActions Actions + { + get => _actions; + private set + { + _actions = value; + OnAllPropertiesChanged(); + CommandManager.InvalidateRequerySuggested(); + } + } + + public ICommand CheckCommand { get; } + public ICommand DeleteCommand { get; } + public ICommand FormatCommand { get; } + public ICommand EjectCommand { get; } + public ICommand OpenLibraryCommand { get; } + + /// "4,812 copied and verified", "4,800 copied · 12 failed". + public string ResultText => Outcome.IsComplete + ? Loc.Plural(Outcome.Verified ? "Import.Result.Verified" : "Import.Result.Copied", Outcome.Imported) + : Loc.L("Import.Result.Partial", Formatting.Count(Outcome.Imported), Formatting.Count(Outcome.Failures.Count)); + + /// "12 skipped · 3 already there", or empty. + public string DetailText => string.Join(" · ", new[] + { + Outcome.Skipped > 0 ? Loc.Plural("Import.Result.Skipped", Outcome.Skipped) : string.Empty, + Outcome.Duplicates > 0 ? Loc.Plural("Import.Result.AlreadyThere", Outcome.Duplicates) : string.Empty, + }.Where(t => t.Length > 0)); + + public bool IsComplete => Outcome.IsComplete; + + public StatusKind ResultKind => Outcome.IsComplete ? StatusKind.Done : StatusKind.Warning; + + public IReadOnlyList Failures { get; } + + public bool HasFailures => Failures.Count > 0; + + /// The profile chose "Delete imported": the dry run and the delete button are offered. + public bool OffersDelete => _choices.AfterImport == AfterImport.DeleteImported; + + /// The profile chose "Format card". + public bool OffersFormat => _choices.AfterImport == AfterImport.FormatCard; + + public bool OffersCheck => OffersDelete || OffersFormat; + + public bool IsBusy + { + get => _isBusy; + private set + { + if (Set(ref _isBusy, value)) CommandManager.InvalidateRequerySuggested(); + } + } + + /// "Checking 1,240 photos" while the dry run hashes. + public string? BusyText { get => _busyText; private set => Set(ref _busyText, value); } + + public string EraseText => _actions.EraseText; + + public IReadOnlyList KeptReasons => _actions.KeptReasons; + + public string CheckToolTip => _actions.CheckBlocker ?? Loc.L("Tooltips.Import.Check"); + + /// "Delete 4,812 photos…". + public string DeleteText => Loc.Plural("Import.Erase.Delete", _actions.DeleteCount); + + public string DeleteToolTip => _actions.DeleteBlocker ?? Loc.L("Tooltips.Import.Delete"); + + public string FormatToolTip => _actions.FormatBlocker ?? Loc.L("Tooltips.Import.Format"); + + public string EjectToolTip => _actions.CanEject ? Loc.L("Tooltips.Import.Eject") : Loc.L("Import.Blocked.NotRemovable"); + + /// The card left or came back (Devices list); actions follow. + public void SetDevice(CardDevice? device) + { + _device = device; + Actions = _actions with { IsInserted = device is not null, IsRemovable = device?.IsRemovable == true }; + } + + /// Shows a dry run computed elsewhere (capture, tests). + public void ShowErase(ErasePlan erase, int cardPhotos) => Actions = _actions with { Erase = erase, CardPhotos = cardPhotos }; + + /// Ejects when the profile asks for it and nothing more is to be done on the card. + public async Task AutoEjectAsync() + { + if (_choices.Eject && _choices.AfterImport == AfterImport.Keep && Outcome.IsComplete && _actions.CanEject) await EjectAsync(); + } + + private async Task CheckAsync() + { + if (_shell.Services.Archives is not { } archives || _archive is null || _card is null || _device is null) return; + var root = _device.Root; + IsBusy = true; + try + { + var progress = new Progress(n => BusyText = Loc.Plural("Import.Erase.Checking", n)); + var (erase, photos) = await Task.Run(async () => + { + var plan = await archives.PlanCardEraseAsync(_archive.Id, _card.Id, root, progress).ConfigureAwait(false); + return (plan, CardScanner.Find(root, includeSubfolders: true).Count); + }); + ShowErase(erase, photos); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException) + { + Log.Warning("import", "Card check failed", ex); + _shell.Notify(Loc.L("Import.Toast.CheckFailed"), ex.Message); + } + finally + { + BusyText = null; + IsBusy = false; + } + } + + private async Task DeleteAsync() + { + if (_actions.Erase is not { } erase) return; + var confirmed = _shell.Services.Dialogs.Confirm(new ConfirmRequest + { + Heading = Loc.Plural("Import.Confirm.DeleteHeading", _actions.DeleteCount), + Message = Loc.L("Import.Confirm.DeleteMessage"), + SafeText = Loc.L("Import.Confirm.Keep"), + SafeToolTip = Loc.L("Tooltips.Import.KeepCard"), + ActionText = Loc.L("Import.Confirm.Delete"), + ActionToolTip = Loc.L("Tooltips.Import.Delete"), + IsDestructive = true, + }); + if (!confirmed) return; + IsBusy = true; + try + { + var result = await Task.Run(() => CardEraser.Execute(erase)); + _shell.Notify(Loc.Plural("Import.Toast.Deleted", result.Deleted), + result.Kept.Count > 0 ? Loc.Plural("Import.Erase.Kept", result.Kept.Count) : null); + // The card changed: a new dry run is needed before anything else is deleted. + Actions = _actions with { Erase = null }; + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) + { + Log.Warning("import", "Deleting imported photos failed", ex); + _shell.Notify(Loc.L("Import.Toast.DeleteFailed"), ex.Message); + } + finally + { + IsBusy = false; + } + if (_choices.Eject && _actions.CanEject) await EjectAsync(); + } + + private void Format() + { + if (_device is not { } device) return; + var name = _card?.Nickname ?? device.Label; + var confirmed = _shell.Services.Dialogs.Confirm(new ConfirmRequest + { + Heading = Loc.L("Import.Confirm.FormatHeading", name), + Message = Loc.Plural("Import.Confirm.FormatMessage", _actions.DeleteCount), + SafeText = Loc.L("Import.Confirm.Keep"), + SafeToolTip = Loc.L("Tooltips.Import.KeepCard"), + ActionText = Loc.L("Import.Confirm.Format"), + ActionToolTip = Loc.L("Tooltips.Import.FormatConfirm"), + IsDestructive = true, + TypedConfirmation = name, + TypedPrompt = Loc.L("Import.Confirm.TypeName"), + }); + if (!confirmed) return; + var outcome = _shell.Services.Devices.Format(device); + if (outcome == FormatOutcome.Formatted) Actions = _actions with { Erase = null }; + if (outcome != FormatOutcome.Cancelled) _shell.Notify(Loc.L("Import.Toast.Format." + outcome, name)); + } + + private async Task EjectAsync() + { + if (_device is not { } device) return; + IsBusy = true; + try + { + var outcome = await Task.Run(() => _shell.Services.Devices.Eject(device)); + _shell.Notify(Loc.L("Import.Toast.Eject." + outcome, _card?.Nickname ?? device.Label)); + if (outcome == EjectOutcome.Ejected) SetDevice(null); + } + finally + { + IsBusy = false; + } + } +} diff --git a/src/Titano.App/Import/ImportScenes.cs b/src/Titano.App/Import/ImportScenes.cs new file mode 100644 index 00000000..c4bd9741 --- /dev/null +++ b/src/Titano.App/Import/ImportScenes.cs @@ -0,0 +1,49 @@ +using Titano.App.Shell; + +namespace Titano.App.Import; + +/// +/// The Import states that --capture renders (import-<state>-<theme>.png) and the screen smoke +/// tests check, on the card of : the card just inserted with its plan and sessions (and the +/// insertion toast), "Show plan", and the verification result with the after-import actions. +/// +public static class ImportScenes +{ + public static readonly IReadOnlyList States = ["plan", "showplan", "done"]; + + public static async Task ShowAsync(ShellViewModel shell, string state) + { + var import = shell.Import; + shell.Navigate(SectionKey.Import); + switch (state) + { + case "plan": + var card = SampleCards.Card(shell.Services.Environment.DataDirectory); + if (import.Result is not null) import.NewImportCommand.Execute(null); + import.CloseDetailsCommand.Execute(null); + await import.RefreshSourcesAsync(); + import.SelectSource(card.Identity); + import.KeepCard = true; + await import.WaitForPlanAsync(); + if (import.Sessions.Count > 0) + { + var sunset = import.Sessions[^1].Title; + sunset.Text = "Harbour sunset"; + sunset.Commit(); + } + await import.CardInsertedAsync(card); + break; + case "showplan": + import.ShowPlanCommand.Execute(null); + break; + case "done": + import.CloseDetailsCommand.Execute(null); + import.DeleteImported = true; + var plan = import.Plan ?? throw new InvalidOperationException("The sample card has no plan."); + import.ShowResult(SampleCards.Outcome(plan)).ShowErase(SampleCards.Erase(plan), plan.FileCount); + break; + default: + throw new ArgumentOutOfRangeException(nameof(state), state, "Unknown Import state."); + } + } +} diff --git a/src/Titano.App/Import/ImportSessionRowViewModel.cs b/src/Titano.App/Import/ImportSessionRowViewModel.cs new file mode 100644 index 00000000..cb533025 --- /dev/null +++ b/src/Titano.App/Import/ImportSessionRowViewModel.cs @@ -0,0 +1,21 @@ +using Titano.App.Settings; +using Titano.Core.Localization; +using Titano.Ui.Mvvm; + +namespace Titano.App.Import; + +/// A session of the plan with its editable title (the sequence title; empty keeps the folder name). +public sealed class ImportSessionRowViewModel : ObservableObject +{ + public ImportSessionRowViewModel(PlanSessionRow row, Action titleChanged) + { + Row = row; + Title = new EditableField(row.Title ?? string.Empty, _ => null, text => titleChanged(row.SessionKey, text), () => Loc.L("Tooltips.Import.SessionTitle")); + } + + public PlanSessionRow Row { get; } + + public EditableField Title { get; } + + public string Placeholder => Row.DefaultTitle; +} diff --git a/src/Titano.App/Import/SampleCards.cs b/src/Titano.App/Import/SampleCards.cs new file mode 100644 index 00000000..d514eb96 --- /dev/null +++ b/src/Titano.App/Import/SampleCards.cs @@ -0,0 +1,173 @@ +using System.IO; +using Titano.Core.Archiving; +using Titano.Core.Codecs.Jpeg; +using Titano.Core.Imaging; +using Titano.Core.Import; +using Titano.Core.Metadata; +using Titano.Core.Model; +using Titano.Data; +using Titano.Data.Repositories; + +namespace Titano.App.Import; + +/// +/// Capture and smoke-test data ONLY (--capture, never the user's data): a simulated Canon EOS R5 card in the +/// capture folder — a night, a dawn and a sunset session of small JPEGs with Exif — remembered as "EOS R5 · card A", +/// a second remembered card that is not inserted, a USB drive without DCIM, and the import result shown afterwards. +/// +public static class SampleCards +{ + private const uint Serial = 0x3F2A9C11; + private static readonly DateTimeOffset LastImport = new(2026, 9, 21, 19, 40, 0, TimeSpan.Zero); + + /// Night, dawn and sunset: start, photos, seconds between photos. + private static readonly (DateTime Start, int Photos, int Interval)[] Sessions = + [ + (new DateTime(2026, 9, 26, 21, 10, 0), 10, 120), + (new DateTime(2026, 9, 27, 5, 41, 0), 16, 4), + (new DateTime(2026, 9, 28, 18, 2, 11), 24, 2), + ]; + + /// The inserted card: its root is a folder of the capture environment. + public static CardDevice Card(string dataDirectory) => + new(Path.Combine(dataDirectory, "card") + Path.DirectorySeparatorChar, "EOS_DIGITAL", Serial, 127_865_454_592, 31_665_454_592, IsRemovable: true, + HasDcim: true); + + /// Writes the card's photos, remembers both cards (the inserted one with its last import) and inserts the card and a USB drive. + public static async Task InsertAsync(TitanoDatabase db, SampleDeviceMonitor devices, string dataDirectory) + { + var card = Card(dataDirectory); + WritePhotos(card.Root); + var known = new MediaCard + { + Id = Guid.CreateVersion7(), + Identity = card.Identity, + VolumeSerial = card.SerialNumber, + Label = card.Label, + Capacity = card.TotalBytes, + Nickname = "EOS R5 · card A", + CameraMake = "Canon", + CameraModel = "Canon EOS R5", + CameraSerial = "0431", + FirstSeen = LastImport.AddMonths(-7), + LastSeen = DateTimeOffset.UtcNow, + }; + await db.MediaCards.UpsertAsync(known); + await db.MediaCards.RecordImportsAsync([new ImportRecord(known.Id, new ImportKey("DCIM/100CANON/IMG_9001.CR2", 24_000_000, LastImport), null, null, null, + LastImport)]); + await db.MediaCards.UpsertAsync(new MediaCard + { + Id = Guid.CreateVersion7(), + Identity = "7C1D0E42-GOPRO-63864569856", + VolumeSerial = 0x7C1D0E42, + Label = "GOPRO", + Capacity = 63_864_569_856, + Nickname = "GoPro 12", + CameraMake = "GoPro", + CameraModel = "HERO12 Black", + FirstSeen = LastImport.AddMonths(-3), + LastSeen = LastImport.AddDays(-6), + }); + devices.Insert(card); + devices.Insert(new CardDevice(@"F:\", "USB DRIVE", 0x51E02B44, 2_000_398_934_016, 1_800_000_000_000, IsRemovable: true, HasDcim: false)); + } + + /// What the import of reports: every planned copy committed and read back. + public static ImportOutcome Outcome(ImportPlan plan) => new(plan.CopyCount, 0, plan.FileCount - plan.CopyCount, [], Verified: true); + + /// The dry run of "Delete imported" after that import: every copy matches except the last photo, touched since. + public static ErasePlan Erase(ImportPlan plan) + { + var copied = plan.Sessions.SelectMany(s => s.Items.Where(i => i.Action == ImportAction.Copy).Select(i => (Session: s, Item: i))).ToList(); + return new ErasePlan(plan.SourceRoot, + [ + .. copied.Select((c, n) => new EraseItem( + new EraseCandidate(c.Item.SourcePath, c.Item.Size, string.Empty, + Path.Combine(plan.DestinationRoot, c.Session.Folder, ArchiveLayout.OriginalsFolder, c.Item.FileName)), + n == copied.Count - 1 ? EraseVerdict.SourceChanged : EraseVerdict.Delete, c.Item.ModifiedUtc)), + ]); + } + + private static void WritePhotos(string root) + { + var folder = Path.Combine(root, "DCIM", "100CANON"); + if (Directory.Exists(folder)) return; + Directory.CreateDirectory(folder); + var n = 1; + foreach (var (start, photos, interval) in Sessions) + { + for (var i = 0; i < photos; i++, n++) + { + var captured = start.AddSeconds(i * interval); + var path = Path.Combine(folder, $"IMG_{n:0000}.JPG"); + File.WriteAllBytes(path, Photo(captured, n)); + File.SetLastWriteTime(path, captured); + } + } + } + + /// A small sky gradient with grain (distinct bytes per photo) and the camera's Exif. + private static byte[] Photo(DateTime captured, int seed) + { + const int Width = 96, Height = 64; + using var image = new ImageBuffer(Width, Height, 3, clear: false); + var random = new Random(seed); + var dusk = captured.Hour is >= 18 or < 6 ? 0.15f : 0.6f; + for (var y = 0; y < Height; y++) + { + for (var x = 0; x < Width; x++) + { + var sky = dusk * (1 - y / (float)Height) + 0.05f; + var grain = (float)random.NextDouble() * 0.04f; + image.Plane(0)[y * Width + x] = sky * 1.2f + grain; + image.Plane(1)[y * Width + x] = sky * 0.8f + grain; + image.Plane(2)[y * Width + x] = sky * 0.6f + grain; + } + } + var exif = ExifWriter.BuildJpegApp1(new FrameMetadata + { + Make = "Canon", + Model = "Canon EOS R5", + BodySerial = "0431", + CapturedAt = captured, + Iso = 100, + ExposureTime = 1.0 / 250, + FNumber = 8, + }); + return JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 85, App1Segments = [exif[4..]] }); + } +} + +/// The capture's device monitor: lists the sample volumes; it raises no events and never ejects or formats. +public sealed class SampleDeviceMonitor : IDeviceMonitor +{ + private readonly List _devices = []; + + public event Action? Arrived + { + add { } + remove { } + } + + public event Action? Removed + { + add { } + remove { } + } + + public IReadOnlyList Devices => [.. _devices]; + + public void Insert(CardDevice device) => _devices.Add(device); + + public void Start() + { + } + + public EjectOutcome Eject(CardDevice device) => EjectOutcome.Failed; + + public FormatOutcome Format(CardDevice device) => FormatOutcome.Cancelled; + + public void Dispose() + { + } +} diff --git a/src/Titano.App/Infrastructure/AppServices.cs b/src/Titano.App/Infrastructure/AppServices.cs index 5ed5098f..5fb742a9 100644 --- a/src/Titano.App/Infrastructure/AppServices.cs +++ b/src/Titano.App/Infrastructure/AppServices.cs @@ -3,6 +3,7 @@ using System.IO; using System.Net.Http; using System.Reflection; using Titano.App.About; +using Titano.App.Import; using Titano.App.Jobs; using Titano.App.Library; using Titano.App.Server; @@ -86,6 +87,9 @@ public sealed class AppServices : IAsyncDisposable public IEncoderInventory Encoders { get; set; } + /// Card detection, eject and format (BRIEF §13); started with the index, replaced by a fake in capture. + public IDeviceMonitor Devices { get; set; } = new WindowsDeviceMonitor(); + /// Latest public release (GitHub Releases API of the releases repository, BRIEF §18). public Func> CheckForUpdateAsync { get; set; } @@ -155,6 +159,7 @@ public sealed class AppServices : IAsyncDisposable } await StartJobsAsync(Database, startEngine: true, ct); Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems); + Devices.Start(); if (Settings.LastArchivePath is { Length: > 0 } root) _polling = PollAsync(root, _stopping.Token); } @@ -177,6 +182,7 @@ public sealed class AppServices : IAsyncDisposable (Jobs as IDisposable)?.Dispose(); if (Engine is not null) await Engine.DisposeAsync(); Thumbnails?.Dispose(); + Devices.Dispose(); Server.Dispose(); if (Database is not null) await Database.DisposeAsync(); } diff --git a/src/Titano.App/Infrastructure/IAppDialogs.cs b/src/Titano.App/Infrastructure/IAppDialogs.cs index 892964e2..e6fbc7d4 100644 --- a/src/Titano.App/Infrastructure/IAppDialogs.cs +++ b/src/Titano.App/Infrastructure/IAppDialogs.cs @@ -17,6 +17,12 @@ public sealed record ConfirmRequest /// Warning-outlined action (never a primary) for data-destroying choices. public bool IsDestructive { get; init; } + + /// Text the user must type before the action enables (formatting a card: its name); null asks no typing. + public string? TypedConfirmation { get; init; } + + /// Label of the typing field ("Type the card name to confirm"). + public string? TypedPrompt { get; init; } } /// Modal questions and OS pickers the view models ask for (BRIEF §12.1: modals only for confirmations and login). diff --git a/src/Titano.App/Infrastructure/WindowsDeviceMonitor.cs b/src/Titano.App/Infrastructure/WindowsDeviceMonitor.cs new file mode 100644 index 00000000..6b6a0a04 --- /dev/null +++ b/src/Titano.App/Infrastructure/WindowsDeviceMonitor.cs @@ -0,0 +1,74 @@ +using System.ComponentModel; +using System.Windows; +using System.Windows.Interop; +using Titano.App.Import; +using Titano.Core.Diagnostics; +using Titano.Core.Windows.Devices; + +namespace Titano.App.Infrastructure; + +/// +/// Card detection on this PC (BRIEF §13): (WM_DEVICECHANGE plus a 3-second poll), +/// safe removal through and formatting only through the Windows format dialog +/// (, BRIEF §8.6). +/// +public sealed class WindowsDeviceMonitor : IDeviceMonitor +{ + private RemovableVolumeWatcher? _watcher; + + public event Action? Arrived; + + public event Action? Removed; + + public IReadOnlyList Devices => _watcher is { } watcher ? [.. watcher.Volumes.Select(Map)] : []; + + public void Start() + { + if (_watcher is not null) return; + var watcher = new RemovableVolumeWatcher(); + watcher.VolumeArrived += (_, e) => Arrived?.Invoke(Map(e.Volume)); + watcher.VolumeRemoved += (_, e) => Removed?.Invoke(Map(e.Volume)); + try + { + watcher.Start(); + _watcher = watcher; + } + catch (Win32Exception ex) + { + // Without the watcher cards are still listed by "Folder…"; nothing else depends on it. + Log.Warning("devices", "Card detection is unavailable", ex); + watcher.Dispose(); + } + } + + public EjectOutcome Eject(CardDevice device) => VolumeEjector.Eject(device.Root[0]) switch + { + EjectResult.Ejected => EjectOutcome.Ejected, + EjectResult.InUse => EjectOutcome.InUse, + _ => EjectOutcome.Failed, + }; + + public FormatOutcome Format(CardDevice device) + { + var owner = Application.Current?.MainWindow is { } window ? new WindowInteropHelper(window).Handle : 0; + try + { + return FormatDialog.Show(owner, device.Root[0]) switch + { + FormatDialogResult.Formatted => FormatOutcome.Formatted, + FormatDialogResult.Cancelled => FormatOutcome.Cancelled, + _ => FormatOutcome.Failed, + }; + } + catch (Exception ex) when (ex is ArgumentException or InvalidOperationException) + { + Log.Warning("devices", $"The format dialog cannot open for {device.Root}", ex); + return FormatOutcome.Failed; + } + } + + public void Dispose() => _watcher?.Dispose(); + + private static CardDevice Map(VolumeInfo v) => + new(v.RootPath, v.Label, v.SerialNumber, v.TotalBytes, v.FreeBytes, v.DriveType == VolumeDriveType.Removable, v.HasDcim); +} diff --git a/src/Titano.App/Sections/ArchiveView.xaml b/src/Titano.App/Sections/ArchiveView.xaml index 1141aff3..8a8753e8 100644 --- a/src/Titano.App/Sections/ArchiveView.xaml +++ b/src/Titano.App/Sections/ArchiveView.xaml @@ -2,8 +2,466 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="clr-namespace:Titano.Ui.Controls;assembly=Titano.Ui" - xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui"> - - + xmlns:v="clr-namespace:Titano.Ui.Visuals;assembly=Titano.Ui" + xmlns:l="clr-namespace:Titano.Ui.Localization;assembly=Titano.Ui" + xmlns:ar="clr-namespace:Titano.App.Archiving" + xmlns:shell="clr-namespace:Titano.App.Shell"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs index a5677d50..a305524a 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs @@ -240,4 +240,26 @@ public sealed class ArchiveLogicTests Assert.Equal("71 %", recent[0].StateText); Assert.Equal(JobState.Done, recent[1].State); } + + [Test] + public void TheScreensWorkOnTheRememberedArchiveElseTheFirst() + { + var other = Main with { Id = Guid.CreateVersion7(), Name = "Travel", RootPath = "/media/travel" }; + Assert.Null(CurrentArchive.Pick([], "/archive")); + Assert.Equal(other.Id, CurrentArchive.Pick([Main, other], "/media/travel/")!.Id); + Assert.Equal(Main.Id, CurrentArchive.Pick([Main, other], "/elsewhere")!.Id); + Assert.Equal(Main.Id, CurrentArchive.Pick([Main, other], null)!.Id); + } + + [Test] + public void TheSampleReportsFillEveryKindOfReportRow() + { + var locations = Enumerable.Range(1, 6).Select(i => new SequenceLocation(Guid.CreateVersion7(), $"2026/Shoot {i}", $"Shoot {i}")).ToList(); + Assert.Equal("2 copies", MaintenanceReports.Duplicates(SampleReports.Duplicates(locations), locations).Single().Detail); + Assert.SequenceEqual(new[] { OrphanKind.UnlistedFiles, OrphanKind.MissingSequence, OrphanKind.NewFolder }, + MaintenanceReports.Orphans(SampleReports.Orphans(locations), locations).Select(o => o.Kind)); + var folders = SampleReports.Folders(locations); + Assert.Equal(4, folders.Count(f => f.Sidecar is not null)); + Assert.Equal(2, folders.Count(f => f.Sidecar is null)); + } } diff --git a/tests/Titano.App.Tests/Import/SampleCardsTests.cs b/tests/Titano.App.Tests/Import/SampleCardsTests.cs new file mode 100644 index 00000000..3c91e2a6 --- /dev/null +++ b/tests/Titano.App.Tests/Import/SampleCardsTests.cs @@ -0,0 +1,49 @@ +using System.Globalization; +using System.IO; +using Titano.App.Import; +using Titano.Core.Localization; +using Titano.Data; +using Titano.Data.Archiving; +using Titano.Testing; + +namespace Titano.App.Tests.Import; + +/// The simulated card behind the Import captures plans like a real one and gates the after-import actions. +[Category("import")] +public sealed class SampleCardsTests(TestContext context) +{ + [Test] + public async Task TheSampleCardPlansThreeSessionsAndAllowsOnlyAVerifiedDelete() + { + Loc.SetCulture(CultureInfo.GetCultureInfo("en")); + await using var db = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory("db"), "titano.db")), context.Cancellation); + var archives = new ArchiveService(db, new ArchiveServiceOptions { Owner = "test" }); + var archive = await archives.AdoptAsync(context.CreateTempDirectory("archive"), "Main", context.Cancellation); + var devices = new SampleDeviceMonitor(); + await SampleCards.InsertAsync(db, devices, context.CreateTempDirectory("data")); + + var pool = CardPool.Build(devices.Devices, await db.MediaCards.ListAsync(context.Cancellation), null); + Assert.SequenceEqual(new[] { SourceKind.Card, SourceKind.Drive, SourceKind.Card }, pool.Select(s => s.Kind)); + Assert.Equal("EOS R5 · card A", pool[0].Title); + Assert.Equal("128 GB · serial 3F2A-9C11 · Canon EOS R5 #0431", pool[0].IdentityText); + Assert.Equal("GoPro 12", pool[2].Title); + Assert.False(pool[2].IsInserted); + var card = pool[0].Card!; + Assert.Equal(new DateTimeOffset(2026, 9, 21, 19, 40, 0, TimeSpan.Zero), (await db.MediaCards.ListImportsAsync(card.Id, 1, context.Cancellation))[0].ImportedAt); + + var plan = await new ArchiveDestination(archives, archive).PlanAsync(pool[0].Root!, new ImportChoices().ToOptions(), card.Id, null, context.Cancellation); + Assert.Equal(3, plan.Sessions.Count); + Assert.SequenceEqual(new[] { 10, 16, 24 }, plan.Sessions.Select(s => s.Items.Count)); + Assert.Equal(50, plan.CopyCount); + Assert.Equal("Canon EOS R5", plan.Sessions[0].CameraModel); + + var outcome = SampleCards.Outcome(plan); + var before = new CardActions(ImportDestinationKind.Archive, true, true, true, outcome, null, plan.FileCount); + Assert.False(before.CanDelete, "no dry run yet"); + var actions = before with { Erase = SampleCards.Erase(plan) }; + Assert.True(actions.CanDelete); + Assert.Equal(49, actions.DeleteCount); + Assert.Equal(1, actions.KeptCount); + Assert.False(actions.CanFormat, "a kept photo would be lost by formatting"); + } +} diff --git a/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs index 6513d850..8827eb3d 100644 --- a/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs +++ b/tests/Titano.App.Tests/Import/ServerImportSinkTests.cs @@ -76,6 +76,22 @@ public sealed class ServerImportSinkTests(TestContext context) Assert.Empty(server.Committed); } + [Test] + public async Task TheQuotaIsTheRoomOfAServerImport() + { + var card = Card(context.CreateTempDirectory("card"), 8, Start); + var staging = context.CreateTempDirectory("staging"); + var plan = await new UnindexedDestination(ImportDestinationKind.Server, staging) { ServerSpace = 1_000 } + .PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation); + Assert.Equal(1_000L, plan.AvailableBytes); + Assert.False(ImportPlans.Totals(plan, verify: true).HasEnoughSpace, "eight photos do not fit in 1 KB of quota"); + + var unlimited = await new UnindexedDestination(ImportDestinationKind.Server, staging).PlanAsync(card, new ImportChoices().ToOptions(), null, null, + context.Cancellation); + Assert.Null(unlimited.AvailableBytes); + Assert.True(ImportPlans.Totals(unlimited, verify: true).HasEnoughSpace); + } + /// Start, chunk and complete of BRIEF §14.4, plus the title update; the hash is checked at completion. private sealed class FakeUploadServer(int chunkSize) : HttpMessageHandler { From d4f7396ac27083e74dfdb91d1742d1f64695f3ba Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 22:29:33 +0000 Subject: [PATCH 05/16] fix(app): an import keeps its result and resume when its card leaves and returns Re-listing the devices no longer re-plans the card of a running, failed or finished import, so a removed card can resume its job after re-insertion and the verification result stays after ejecting. The source list and profile edits are locked while an import runs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.App/Sections/ImportView.xaml | 2 +- src/Titano.App/Sections/ImportViewModel.cs | 25 ++++++++++--------- .../Import/ImportFlowTests.cs | 5 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Titano.App/Sections/ImportView.xaml b/src/Titano.App/Sections/ImportView.xaml index a014265b..064a7f44 100644 --- a/src/Titano.App/Sections/ImportView.xaml +++ b/src/Titano.App/Sections/ImportView.xaml @@ -97,7 +97,7 @@ VerticalContentAlignment="Top"> - + diff --git a/src/Titano.App/Sections/ImportViewModel.cs b/src/Titano.App/Sections/ImportViewModel.cs index 471a453c..28855312 100644 --- a/src/Titano.App/Sections/ImportViewModel.cs +++ b/src/Titano.App/Sections/ImportViewModel.cs @@ -113,8 +113,8 @@ public sealed class ImportViewModel : SectionViewModel field.Text += token.Text; field.Commit(); }); - RenameCommand = new RelayCommand(() => IsRenaming = true, () => _selected?.Card is not null); - ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => _selected?.Card is not null); + RenameCommand = new RelayCommand(() => IsRenaming = true, () => CanEditProfile); + ForgetCommand = new AsyncRelayCommand(ForgetCardAsync, () => CanEditProfile); ShowPlanCommand = new RelayCommand(() => Details = _plan is null ? null : ImportPlans.Details(_plan, _choices.Destination, _choices.VerifyCopies), () => _plan is not null); CloseDetailsCommand = new RelayCommand(() => Details = null); @@ -128,7 +128,7 @@ public sealed class ImportViewModel : SectionViewModel RetryCommand = new AsyncRelayCommand(RetryAsync, () => _phase == ImportPhase.Failed); shell.Services.Devices.Arrived += device => Dispatch(() => _ = CardInsertedAsync(device)); - shell.Services.Devices.Removed += device => Dispatch(() => _ = OnRemovedAsync(device)); + shell.Services.Devices.Removed += removed => Dispatch(() => _ = OnRemovedAsync()); shell.Services.Server.PropertyChanged += (_, _) => Dispatch(() => OnPropertyChanged(string.Empty)); } @@ -193,7 +193,8 @@ public sealed class ImportViewModel : SectionViewModel public EditableField Nickname { get; } - public bool CanEditProfile => _selected?.Card is not null; + /// A remembered card's profile can be edited, except while its import runs. + public bool CanEditProfile => _selected?.Card is not null && _phase != ImportPhase.Running; public IReadOnlyList OtherCards => [ @@ -479,14 +480,18 @@ public sealed class ImportViewModel : SectionViewModel var key = _selected?.Key; var pool = Rebuild(); var again = pool.FirstOrDefault(s => s.Key == key) ?? pool.FirstOrDefault(s => s.IsInserted && s.Kind == SourceKind.Card); - if (!Equals(again, _selected)) + // The card of a running, failed or finished import may leave and come back: its import, result and resume stay. + var keepsImport = again is not null && again.Key == key && _phase is ImportPhase.Running or ImportPhase.Failed or ImportPhase.Done; + if (Equals(again, _selected) || keepsImport) { _selected = again; - OnSourceChanged(); + _result?.SetDevice(again?.Device); + OnPropertyChanged(string.Empty); } else { - OnPropertyChanged(string.Empty); + _selected = again; + OnSourceChanged(); } } @@ -1058,11 +1063,7 @@ public sealed class ImportViewModel : SectionViewModel if (_phase == ImportPhase.Running && _jobSourceKey == identity) await CancelAsync(); } - private async Task OnRemovedAsync(CardDevice device) - { - await RefreshSourcesAsync(); - _result?.SetDevice(Services.Devices.Devices.FirstOrDefault(d => d.Identity == _selected?.Device?.Identity)); - } + private Task OnRemovedAsync() => RefreshSourcesAsync(); private static void Dispatch(Action action) { diff --git a/tests/Titano.App.Tests/Import/ImportFlowTests.cs b/tests/Titano.App.Tests/Import/ImportFlowTests.cs index 4b8eef2a..1dd8fbec 100644 --- a/tests/Titano.App.Tests/Import/ImportFlowTests.cs +++ b/tests/Titano.App.Tests/Import/ImportFlowTests.cs @@ -94,9 +94,8 @@ public sealed class ImportFlowTests(TestContext context) Assert.True(outcome.IsComplete); Assert.True(outcome.Verified); Assert.NotEmpty(reports); - foreach (var s in plan.Sessions) - foreach (var item in s.Items) - Assert.FileExists(Path.Combine(target, s.Folder, item.FileName)); + foreach (var (folder, name) in plan.Sessions.SelectMany(s => s.Items.Select(i => (s.Folder, i.FileName)))) + Assert.FileExists(Path.Combine(target, folder, name)); var again = await LocalImport.RunAsync(await destination.PlanAsync(card, new ImportChoices().ToOptions(), null, null, context.Cancellation), new FolderImportSink(target), verify: true, null, context.Cancellation); From 55469ae08698aa9f3eb08d0447d3715e4067538b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Oct 2026 22:31:27 +0000 Subject: [PATCH 06/16] fix(app): archive tooltips say why a command is disabled; the rename dialog stops planning when closed Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.App/Archive/ArchiveDialogViewModels.cs | 7 +++++++ src/Titano.App/Sections/ArchiveView.xaml | 14 +++++++------- src/Titano.App/Sections/ArchiveViewModel.cs | 10 ++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Titano.App/Archive/ArchiveDialogViewModels.cs b/src/Titano.App/Archive/ArchiveDialogViewModels.cs index fe43b98c..8415a930 100644 --- a/src/Titano.App/Archive/ArchiveDialogViewModels.cs +++ b/src/Titano.App/Archive/ArchiveDialogViewModels.cs @@ -174,6 +174,13 @@ public sealed class RenameDialogViewModel : ArchiveDialogViewModel public ICommand ApplyCommand { get; } + public override void Dispose() + { + _delay.Stop(); + _planning?.Cancel(); + base.Dispose(); + } + /// The dry run of the current template (the engine's plan; nothing changes on disk). public async Task PlanAsync() { diff --git a/src/Titano.App/Sections/ArchiveView.xaml b/src/Titano.App/Sections/ArchiveView.xaml index 8a8753e8..ddf723ce 100644 --- a/src/Titano.App/Sections/ArchiveView.xaml +++ b/src/Titano.App/Sections/ArchiveView.xaml @@ -163,12 +163,12 @@ ToolTip="{Binding ArchiveToolTip}" AutomationProperties.Name="{l:Loc Archive.Toolbar.Archive}" Margin="0,0,8,8" /> - - @@ -201,12 +199,12 @@ - - - - + + + + - + @@ -501,7 +499,7 @@ - + diff --git a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs index a305524a..9db10c3f 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveLogicTests.cs @@ -1,5 +1,6 @@ using System.Globalization; using Titano.App.Archiving; +using Titano.App.Library; using Titano.Core.Archiving; using Titano.Core.Imaging; using Titano.Core.Localization; @@ -98,6 +99,34 @@ public sealed class ArchiveLogicTests ], Health: new ArchiveHealth(Unverified: 3, WithWarnings: 1, WithErrors: 0, NotAnalyzed: 2, MissingFrames: 0, CorruptFrames: 0, DuplicateFrames: 5)); + [Test] + public void TheSetFilterNarrowsByCameraStatusAndTag() + { + var canon = Seq("Harbour", new DateTime(2026, 9, 28), tags: "sunset") with + { + CameraMake = "Canon", + CameraModel = "Canon EOS R5", + Status = SequenceStatus.AnalyzedLight | SequenceStatus.ProxiesBuilt, + }; + var sony = Seq("Comet", new DateTime(2026, 8, 13), tags: "night") with { CameraMake = "SONY", CameraModel = "ILCE-7M4" }; + var unknown = Seq("Old", null); + + Assert.True(new ArchiveSetFilter().IsEmpty); + Assert.True(new ArchiveSetFilter().Matches(unknown), "no filter keeps everything"); + var byCamera = new ArchiveSetFilter(Camera: ArchiveSetFilter.CameraOf(canon)); + Assert.True(byCamera.Matches(canon)); + Assert.False(byCamera.Matches(sony)); + Assert.Equal(Loc.L("Archive.Chart.UnknownCamera"), ArchiveSetFilter.CameraOf(unknown)); + Assert.True(new ArchiveSetFilter(Status: StatusFilter.NotAnalysed).Matches(sony)); + Assert.False(new ArchiveSetFilter(Status: StatusFilter.NotAnalysed).Matches(canon)); + Assert.True(new ArchiveSetFilter(Status: StatusFilter.Proxies).Matches(canon)); + Assert.True(new ArchiveSetFilter(Tag: "SUNSET").Matches(canon), "tags compare without case"); + Assert.False(new ArchiveSetFilter(Tag: "sunset").Matches(sony)); + Assert.Equal(ArchiveSetFilter.CameraOf(canon) + " · Not analysed · sunset", + new ArchiveSetFilter(ArchiveSetFilter.CameraOf(canon), StatusFilter.NotAnalysed, "sunset").Describe()); + Assert.Equal(string.Empty, new ArchiveSetFilter().Describe()); + } + [Test] public void ChartsAggregateYearsCamerasAndFormats() { From 2d6756a1e120885aa2e1b54db534e34d29d58ae2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 10:51:13 +0000 Subject: [PATCH 14/16] fix(app): the shell disposes the Import and Archive screens They cancel planning, imports and searches and detach their job events. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.App/Shell/ShellViewModel.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Titano.App/Shell/ShellViewModel.cs b/src/Titano.App/Shell/ShellViewModel.cs index 8dccfe76..0f0d7727 100644 --- a/src/Titano.App/Shell/ShellViewModel.cs +++ b/src/Titano.App/Shell/ShellViewModel.cs @@ -246,6 +246,8 @@ public sealed class ShellViewModel : LocalizedViewModel { Jobs.Dispose(); Library.Dispose(); + Import.Dispose(); + Archive.Dispose(); Server.Dispose(); Settings.Dispose(); About.Dispose(); From 0e79763e90cb4ad53b0220ec684615cd1730dd2d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 10:51:13 +0000 Subject: [PATCH 15/16] test(app): smoke tests check real button states, every new capture state and the kept tree selection Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- .../Archive/ArchiveScreenSmokeTests.cs | 34 ++++++++++- .../Import/ImportScreenSmokeTests.cs | 60 +++++++++++++++++-- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs index a56b4132..0074623c 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs @@ -1,3 +1,5 @@ +using System.Windows.Controls; +using System.Windows.Input; using Titano.App.Archiving; using Titano.App.Sections; using Titano.App.Tests.Windows; @@ -8,7 +10,7 @@ namespace Titano.App.Tests.Archiving; /// /// Every Archive view of --capture () on the sample archive, rendered in both themes -/// in the real main window, with what each view must show. +/// in the real main window, with what each view must show — and the buttons really enabled, not only their commands. /// [WindowsOnly] [Serial] @@ -35,6 +37,18 @@ public sealed class ArchiveScreenSmokeTests Assert.NotEmpty(archive.FormatBars); Assert.True(archive.ScanCommand.CanExecute(null), "an online archive can be scanned"); await app.ExpectAsync("archive-overview"); + Assert.True(ButtonFor(app, archive.ScanCommand).IsEnabled, "the Scan button is enabled once the archive is read"); + Assert.True(ButtonFor(app, archive.AnalyseSetCommand).IsEnabled, "mass operations are enabled on the whole archive"); + + // Expanding another year keeps the selection: the set stays what the user chose. + var year = archive.TreeRows[1]; + var tree = app.FindAll().Single(l => l.Name == "Tree"); + tree.SelectedItems.Add(year); + var chosen = archive.SetText; + archive.Toggle(archive.TreeRows.Last(r => r.IsYear)); + Assert.Equal(chosen, archive.SetText, "opening a year does not change the set"); + Assert.True(tree.SelectedItems.Cast().Any(r => r.Node.Key == year.Node.Key), "the list shows the same selection"); + tree.SelectedItems.Clear(); await ArchiveScenes.ShowAsync(app.Shell, "maintenance"); Assert.True(archive.IsMaintenance); @@ -46,6 +60,24 @@ public sealed class ArchiveScreenSmokeTests await ArchiveScenes.ShowAsync(app.Shell, "rebuild"); var rebuild = Assert.NotNull(archive.Dialog as RebuildDialogViewModel); Assert.True(rebuild.RebuildCommand.CanExecute(null)); + Assert.False(archive.IsContentEnabled, "the screen behind a dialog takes no input"); await app.ExpectAsync("archive-rebuild"); + + await ArchiveScenes.ShowAsync(app.Shell, "move"); + var move = Assert.NotNull(archive.Dialog as RenameDialogViewModel); + Assert.NotEmpty(move.Rows, "the dry run lists the folders that change"); + await app.ExpectAsync("archive-move"); + Assert.True(ButtonFor(app, move.ApplyCommand).IsEnabled, "Apply follows the dry run"); + + move.CloseCommand.Execute(null); + archive.RetagSetCommand.Execute(null); + var retag = Assert.NotNull(archive.Dialog as RetagDialogViewModel); + retag.Add.Text = "sunset"; + await app.ExpectAsync("archive-retag"); + Assert.True(ButtonFor(app, retag.ApplyCommand).IsEnabled, "Apply follows the typed tags"); + retag.CloseCommand.Execute(null); }); + + private static Button ButtonFor(ScreenSmokeTests.SampleApp app, ICommand command) => + Assert.NotNull(app.FindAll