feat(import): import a whole folder as one sequence per format
Owner review 2, R9: Import › Folder… gains a "Group" choice for picked folders: Sessions (as before) or Whole folder. A whole folder, with its subfolders when Subfolders is on, becomes one sequence per file format; camera bodies and pauses are ignored, while RAW+JPEG of the same shots stays two sequences so no frame is ever doubled. Only the user's splits break it, and Merge joins a split part back. The planner implements it (ImportOptions.Grouping, Core, Linux-tested): the session key is "folder-" plus a hash of this PC's name, the full path and the format, so an interrupted or repeated import continues the same sequence; the default title is the folder's name. The plan shows one row per format with the format and the number of cameras. Cards and drives always import by sessions; the choice is not part of a card profile and a folder starts on Sessions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5209579631
commit
445dfd41a3
14 files changed
+419
-26
No files matched your search
@@ -34,6 +34,7 @@
|
||||
<data name="Import.Blocked.NothingVerified" xml:space="preserve"><value>No photo on the card matches a verified copy.</value><comment>long</comment></data>
|
||||
<data name="Import.Blocked.Space" xml:space="preserve"><value>Not enough free space at the destination.</value><comment>long</comment></data>
|
||||
<data name="Import.Blocked.Template" xml:space="preserve"><value>Fix the name templates first.</value><comment>long</comment></data>
|
||||
<data name="Import.Blocked.WholeFolder" xml:space="preserve"><value>The whole folder is one sequence per format.</value><comment>long</comment></data>
|
||||
<data name="Import.Confirm.Delete" xml:space="preserve"><value>Delete</value></data>
|
||||
<data name="Import.Confirm.DeleteHeading.one" xml:space="preserve"><value>Delete {0:N0} photo from the card?</value><comment>long</comment></data>
|
||||
<data name="Import.Confirm.DeleteHeading.other" xml:space="preserve"><value>Delete {0:N0} photos from the card?</value><comment>long</comment></data>
|
||||
@@ -118,9 +119,12 @@
|
||||
<data name="Import.Failed.SourceGone" xml:space="preserve"><value>{0} is no longer available.</value><comment>long</comment></data>
|
||||
<data name="Import.Folder.PickDestination" xml:space="preserve"><value>Import into folder</value></data>
|
||||
<data name="Import.Folder.PickSource" xml:space="preserve"><value>Import from folder</value></data>
|
||||
<data name="Import.Group.Sessions" xml:space="preserve"><value>Sessions</value></data>
|
||||
<data name="Import.Group.WholeFolder" xml:space="preserve"><value>Whole folder</value></data>
|
||||
<data name="Import.Label.After" xml:space="preserve"><value>After import</value></data>
|
||||
<data name="Import.Label.Destination" xml:space="preserve"><value>Destination</value></data>
|
||||
<data name="Import.Label.Duplicates" xml:space="preserve"><value>Duplicates</value></data>
|
||||
<data name="Import.Label.Group" xml:space="preserve"><value>Group</value></data>
|
||||
<data name="Import.Label.Names" xml:space="preserve"><value>Names</value></data>
|
||||
<data name="Import.Label.Scan" xml:space="preserve"><value>Scan</value></data>
|
||||
<data name="Import.Names.File" xml:space="preserve"><value>File template</value></data>
|
||||
@@ -176,6 +180,8 @@
|
||||
<data name="Import.Scan.Verify" xml:space="preserve"><value>Verify hashes</value></data>
|
||||
<data name="Import.Session.Adds" xml:space="preserve"><value>Adds to · {0}</value><comment>long</comment></data>
|
||||
<data name="Import.Session.AddsShort" xml:space="preserve"><value>adds</value></data>
|
||||
<data name="Import.Session.Cameras.one" xml:space="preserve"><value>{0:N0} camera</value></data>
|
||||
<data name="Import.Session.Cameras.other" xml:space="preserve"><value>{0:N0} cameras</value></data>
|
||||
<data name="Import.Session.Column.Camera" xml:space="preserve"><value>Camera</value></data>
|
||||
<data name="Import.Session.Column.Frames" xml:space="preserve"><value>Frames · interval</value></data>
|
||||
<data name="Import.Session.Column.Sequence" xml:space="preserve"><value>Sequence</value></data>
|
||||
|
||||
@@ -303,6 +303,7 @@
|
||||
<data name="Tooltips.Import.FormatChoice" xml:space="preserve"><value>After the import, offer the Windows format dialog once every copy is verified</value></data>
|
||||
<data name="Tooltips.Import.FormatConfirm" xml:space="preserve"><value>Open the Windows format dialog</value></data>
|
||||
<data name="Tooltips.Import.Gap" xml:space="preserve"><value>Minutes without photos that start a new session</value></data>
|
||||
<data name="Tooltips.Import.GroupSessions" xml:space="preserve"><value>Split the folder into sessions by camera, format and pauses, as for a card</value></data>
|
||||
<data name="Tooltips.Import.ImportedBefore" xml:space="preserve"><value>Photos imported from this card before (same name, size and time)</value></data>
|
||||
<data name="Tooltips.Import.Keep" xml:space="preserve"><value>Leave the card untouched</value></data>
|
||||
<data name="Tooltips.Import.KeepCard" xml:space="preserve"><value>Keep every photo on the card</value></data>
|
||||
@@ -331,6 +332,7 @@
|
||||
<data name="Tooltips.Import.Subfolders" xml:space="preserve"><value>Look inside every subfolder of the source</value></data>
|
||||
<data name="Tooltips.Import.Tokens" xml:space="preserve"><value>Insert a token into the template used last</value></data>
|
||||
<data name="Tooltips.Import.Verify" xml:space="preserve"><value>Hash while copying and read the destination back before the source is touched</value></data>
|
||||
<data name="Tooltips.Import.WholeFolder" xml:space="preserve"><value>One sequence per file format for the whole folder, subfolders included when scanned; cameras and pauses are ignored</value></data>
|
||||
<data name="Tooltips.Jobs.Cancel" xml:space="preserve"><value>Stop this job; Retry continues later from its last checkpoint</value></data>
|
||||
<data name="Tooltips.Jobs.ClearDone" xml:space="preserve"><value>Hide finished jobs from the list; they stay in the history</value></data>
|
||||
<data name="Tooltips.Jobs.Filter.All" xml:space="preserve"><value>Every job</value></data>
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
<data name="Import.Blocked.NothingVerified" xml:space="preserve"><value>Nessuna foto della scheda corrisponde a una copia verificata.</value></data>
|
||||
<data name="Import.Blocked.Space" xml:space="preserve"><value>Spazio libero insufficiente nella destinazione.</value></data>
|
||||
<data name="Import.Blocked.Template" xml:space="preserve"><value>Correggi prima i modelli dei nomi.</value></data>
|
||||
<data name="Import.Blocked.WholeFolder" xml:space="preserve"><value>La cartella intera è una sequenza per formato.</value></data>
|
||||
<data name="Import.Confirm.Delete" xml:space="preserve"><value>Elimina</value></data>
|
||||
<data name="Import.Confirm.DeleteHeading.one" xml:space="preserve"><value>Eliminare {0:N0} foto dalla scheda?</value></data>
|
||||
<data name="Import.Confirm.DeleteHeading.other" xml:space="preserve"><value>Eliminare {0:N0} foto dalla scheda?</value></data>
|
||||
@@ -116,9 +117,12 @@
|
||||
<data name="Import.Failed.SourceGone" xml:space="preserve"><value>{0} non è più disponibile.</value></data>
|
||||
<data name="Import.Folder.PickDestination" xml:space="preserve"><value>Importa nella cartella</value></data>
|
||||
<data name="Import.Folder.PickSource" xml:space="preserve"><value>Importa dalla cartella</value></data>
|
||||
<data name="Import.Group.Sessions" xml:space="preserve"><value>Sessioni</value></data>
|
||||
<data name="Import.Group.WholeFolder" xml:space="preserve"><value>Cartella intera</value></data>
|
||||
<data name="Import.Label.After" xml:space="preserve"><value>Dopo l'importazione</value></data>
|
||||
<data name="Import.Label.Destination" xml:space="preserve"><value>Destinazione</value></data>
|
||||
<data name="Import.Label.Duplicates" xml:space="preserve"><value>Doppioni</value></data>
|
||||
<data name="Import.Label.Group" xml:space="preserve"><value>Raggruppa</value></data>
|
||||
<data name="Import.Label.Names" xml:space="preserve"><value>Nomi</value></data>
|
||||
<data name="Import.Label.Scan" xml:space="preserve"><value>Scansione</value></data>
|
||||
<data name="Import.Names.File" xml:space="preserve"><value>Modello file</value></data>
|
||||
@@ -172,6 +176,8 @@
|
||||
<data name="Import.Scan.Verify" xml:space="preserve"><value>Verifica hash</value></data>
|
||||
<data name="Import.Session.Adds" xml:space="preserve"><value>Si aggiunge a · {0}</value></data>
|
||||
<data name="Import.Session.AddsShort" xml:space="preserve"><value>esistente</value></data>
|
||||
<data name="Import.Session.Cameras.one" xml:space="preserve"><value>{0:N0} fotocamera</value></data>
|
||||
<data name="Import.Session.Cameras.other" xml:space="preserve"><value>{0:N0} fotocamere</value></data>
|
||||
<data name="Import.Session.Column.Camera" xml:space="preserve"><value>Fotocamera</value></data>
|
||||
<data name="Import.Session.Column.Frames" xml:space="preserve"><value>Fotogrammi · intervallo</value></data>
|
||||
<data name="Import.Session.Column.Sequence" xml:space="preserve"><value>Sequenza</value></data>
|
||||
|
||||
@@ -302,6 +302,7 @@
|
||||
<data name="Tooltips.Import.FormatChoice" xml:space="preserve"><value>Dopo l'importazione, proponi la formattazione di Windows quando ogni copia è verificata</value></data>
|
||||
<data name="Tooltips.Import.FormatConfirm" xml:space="preserve"><value>Apri la formattazione di Windows</value></data>
|
||||
<data name="Tooltips.Import.Gap" xml:space="preserve"><value>Minuti senza foto che avviano una nuova sessione</value></data>
|
||||
<data name="Tooltips.Import.GroupSessions" xml:space="preserve"><value>Dividi la cartella in sessioni per fotocamera, formato e pause, come per una scheda</value></data>
|
||||
<data name="Tooltips.Import.ImportedBefore" xml:space="preserve"><value>Foto già importate da questa scheda (stesso nome, dimensione e data)</value></data>
|
||||
<data name="Tooltips.Import.Keep" xml:space="preserve"><value>Lascia intatta la scheda</value></data>
|
||||
<data name="Tooltips.Import.KeepCard" xml:space="preserve"><value>Mantieni tutte le foto sulla scheda</value></data>
|
||||
@@ -330,6 +331,7 @@
|
||||
<data name="Tooltips.Import.Subfolders" xml:space="preserve"><value>Cerca in ogni sottocartella della sorgente</value></data>
|
||||
<data name="Tooltips.Import.Tokens" xml:space="preserve"><value>Inserisci un segnaposto nell'ultimo modello usato</value></data>
|
||||
<data name="Tooltips.Import.Verify" xml:space="preserve"><value>Calcola l'hash durante la copia e rileggi la destinazione prima di toccare la sorgente</value></data>
|
||||
<data name="Tooltips.Import.WholeFolder" xml:space="preserve"><value>Una sequenza per formato di file per l'intera cartella, sottocartelle comprese se incluse; fotocamere e pause sono ignorate</value></data>
|
||||
<data name="Tooltips.Jobs.Cancel" xml:space="preserve"><value>Ferma questa attività; Riprova la continua più tardi dall'ultimo punto di ripresa</value></data>
|
||||
<data name="Tooltips.Jobs.ClearDone" xml:space="preserve"><value>Nasconde le attività concluse dall'elenco; restano nella cronologia</value></data>
|
||||
<data name="Tooltips.Jobs.Filter.All" xml:space="preserve"><value>Tutte le attività</value></data>
|
||||
|
||||
@@ -15,13 +15,18 @@ public enum ImportDestinationKind
|
||||
|
||||
/// <summary>
|
||||
/// The Import form (Import.html): scan, sessions, names, duplicates and after-import choices. Remembered per card as
|
||||
/// its <see cref="CardProfile"/>; a session gap of 0 minutes in a profile means "do not split into sessions".
|
||||
/// its <see cref="CardProfile"/>; a session gap of 0 minutes in a profile means "do not split into sessions". The
|
||||
/// grouping is not in a profile: a card always imports by sessions, and a picked folder starts with them.
|
||||
/// </summary>
|
||||
public sealed record ImportChoices
|
||||
{
|
||||
public ImportDestinationKind Destination { get; init; } = ImportDestinationKind.Archive;
|
||||
public string? FolderPath { get; init; }
|
||||
public bool IncludeSubfolders { get; init; } = true;
|
||||
|
||||
/// <summary>"Group" (a picked folder only): its sessions, or the whole folder as one sequence per format.</summary>
|
||||
public ImportGrouping Grouping { get; init; } = ImportGrouping.Sessions;
|
||||
|
||||
public bool SplitSessions { get; init; } = true;
|
||||
public int GapMinutes { get; init; } = 45;
|
||||
public int MinimumFrames { get; init; } = 8;
|
||||
@@ -78,6 +83,7 @@ public sealed record ImportChoices
|
||||
IncludeSubfolders = IncludeSubfolders,
|
||||
VerifyCopies = VerifyCopies,
|
||||
Duplicates = Duplicates,
|
||||
Grouping = Grouping,
|
||||
Titles = titles ?? new Dictionary<string, string>(),
|
||||
SplitBefore = splits ?? new HashSet<string>(),
|
||||
MergeAt = merges ?? new HashSet<string>(),
|
||||
@@ -88,6 +94,7 @@ public sealed record ImportChoices
|
||||
previous.Destination != Destination
|
||||
|| (Destination == ImportDestinationKind.Folder && !string.Equals(previous.FolderPath, FolderPath, StringComparison.OrdinalIgnoreCase))
|
||||
|| previous.IncludeSubfolders != IncludeSubfolders
|
||||
|| previous.Grouping != Grouping
|
||||
|| previous.SplitSessions != SplitSessions
|
||||
|| (SplitSessions && previous.GapMinutes != GapMinutes)
|
||||
|| previous.MinimumFrames != MinimumFrames
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
@@ -40,7 +41,8 @@ public sealed record PlanTotals(int Sessions, int Photos, int CopyCount, long Co
|
||||
}
|
||||
|
||||
/// <summary>One row of the session table: what the planner grouped and where it goes.</summary>
|
||||
/// <param name="DefaultTitle">Title the sequence gets when the user types none (its folder name).</param>
|
||||
/// <param name="Title">The title the user typed; null when none.</param>
|
||||
/// <param name="DefaultTitle">Title the sequence gets when the user types none (a whole folder's name, else its folder name).</param>
|
||||
/// <param name="IsNew">The session starts a new sequence (false: it continues one imported before).</param>
|
||||
/// <param name="FirstPath">Card path of the session's first photo (where a merge joins it to the previous session).</param>
|
||||
/// <param name="MergesInto">Number of the earlier session of the same camera and format it can merge into; null for none.</param>
|
||||
@@ -116,10 +118,19 @@ public static class ImportPlans
|
||||
],
|
||||
};
|
||||
|
||||
/// <summary>The plan with the typed session titles (when no template uses <c>{title}</c>, so no name changes).</summary>
|
||||
/// <summary>
|
||||
/// The plan with the typed session titles (when no template uses <c>{title}</c>, so no name changes); a session
|
||||
/// without one keeps its default title (a whole folder's name).
|
||||
/// </summary>
|
||||
public static ImportPlan WithTitles(ImportPlan plan, IReadOnlyDictionary<string, string> titles) => plan with
|
||||
{
|
||||
Sessions = [.. plan.Sessions.Select(s => s with { Title = titles.TryGetValue(s.SessionKey, out var t) && !string.IsNullOrWhiteSpace(t) ? t.Trim() : null })],
|
||||
Sessions =
|
||||
[
|
||||
.. plan.Sessions.Select(s => s with
|
||||
{
|
||||
Title = titles.TryGetValue(s.SessionKey, out var t) && !string.IsNullOrWhiteSpace(t) ? t.Trim() : s.DefaultTitle,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
/// <param name="existingFolders">Folders of sequences already in the archive (a session there continues it).</param>
|
||||
@@ -135,20 +146,35 @@ public static class ImportPlans
|
||||
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, s.Items.Count > 0 ? s.Items[0].SourcePath : string.Empty,
|
||||
// The field shows a typed title only; the default (a whole folder's name, else the folder's) is its placeholder.
|
||||
var typed = s.Title is { } title && title != s.DefaultTitle ? title : null;
|
||||
return new PlanSessionRow(s.Number, s.SessionKey, typed, s.DefaultTitle ?? leaf, TimeText(s), FramesText(s),
|
||||
Formatting.Bytes(s.Items.Sum(i => i.Size)), CameraText(plan, s), target, isNew, s.Items.Count > 0 ? s.Items[0].SourcePath : string.Empty,
|
||||
MergeTarget(plan, s)?.Number);
|
||||
}),
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// "Canon EOS R5"; for a whole folder, one row per format, the format too and how many bodies took the photos:
|
||||
/// "Canon EOS R5 · CR3", "2 cameras · JPEG".
|
||||
/// </summary>
|
||||
private static string CameraText(ImportPlan plan, PlannedSession s)
|
||||
{
|
||||
var camera = PathTemplate.CameraName(s.CameraMake, s.CameraModel);
|
||||
if (plan.Grouping != ImportGrouping.WholeFolder) return camera;
|
||||
var bodies = s.Cameras > 1 ? Loc.Plural("Import.Session.Cameras", s.Cameras) : camera;
|
||||
return string.Join(Loc.Separator, new[] { bodies, FormatNames.Of(s.Format) }.Where(t => t.Length > 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The session <paramref name="session"/> joins when the user merges it (BRIEF §13): the one before it of the same
|
||||
/// camera body and format, whose last photo precedes its first; sessions of other cameras or formats never merge.
|
||||
/// A whole folder's parts (split by the user) join the part before them of the same format, whatever the camera.
|
||||
/// </summary>
|
||||
public static PlannedSession? MergeTarget(ImportPlan plan, PlannedSession session) =>
|
||||
plan.Sessions.TakeWhile(s => !ReferenceEquals(s, session))
|
||||
.LastOrDefault(s => s.CameraMake == session.CameraMake && s.CameraModel == session.CameraModel && s.CameraSerial == session.CameraSerial
|
||||
&& s.Format == session.Format);
|
||||
.LastOrDefault(s => s.Format == session.Format && (plan.Grouping == ImportGrouping.WholeFolder
|
||||
|| (s.CameraMake == session.CameraMake && s.CameraModel == session.CameraModel && s.CameraSerial == session.CameraSerial)));
|
||||
|
||||
/// <summary>"Show plan": every file and where it goes, with the conflicts the plan resolved or reports.</summary>
|
||||
public static PlanDetails Details(ImportPlan plan, ImportDestinationKind destination, bool verify)
|
||||
|
||||
@@ -355,17 +355,27 @@
|
||||
</WrapPanel>
|
||||
</HeaderedContentControl>
|
||||
|
||||
<!-- A picked folder only: its sessions, or the whole folder as one sequence per format. -->
|
||||
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Group}"
|
||||
Visibility="{Binding CanGroupFolder, Converter={StaticResource BoolToVisibility}}">
|
||||
<WrapPanel>
|
||||
<RadioButton Content="{l:Loc Import.Group.Sessions}" IsChecked="{Binding GroupBySessions}" ToolTip="{l:Loc Tooltips.Import.GroupSessions}" />
|
||||
<RadioButton Content="{l:Loc Import.Group.WholeFolder}" IsChecked="{Binding GroupWholeFolder}" ToolTip="{l:Loc Tooltips.Import.WholeFolder}" />
|
||||
</WrapPanel>
|
||||
</HeaderedContentControl>
|
||||
|
||||
<HeaderedContentControl Style="{StaticResource Import.Row}" Header="{l:Loc Import.Label.Scan}">
|
||||
<WrapPanel>
|
||||
<CheckBox Content="{l:Loc Import.Scan.Subfolders}" IsChecked="{Binding IncludeSubfolders}" ToolTip="{l:Loc Tooltips.Import.Subfolders}" />
|
||||
<CheckBox Content="{l:Loc Import.Scan.Sessions}" IsChecked="{Binding SplitSessions}" ToolTip="{l:Loc Tooltips.Import.Sessions}" />
|
||||
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding SplitSessions}">
|
||||
<CheckBox Content="{l:Loc Import.Scan.Sessions}" IsChecked="{Binding SplitSessions}" IsEnabled="{Binding SessionsApply}"
|
||||
ToolTip="{Binding SessionsToolTip}" />
|
||||
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding GapApplies}">
|
||||
<TextBlock Text="{l:Loc Import.Scan.Gap}" Style="{StaticResource Text.Unit}" />
|
||||
<TextBox x:Name="GapBox" Style="{StaticResource TextBox.Small}" Text="{Binding GapMinutes.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
|
||||
shell:EditBehavior.Field="{Binding GapMinutes}" ToolTip="{Binding GapMinutes.ToolTip}" AutomationProperties.Name="{l:Loc Import.Scan.GapName}" />
|
||||
<TextBlock Text="{l:Loc Import.Scan.Minutes}" Style="{StaticResource Text.Unit}" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}">
|
||||
<StackPanel Orientation="Horizontal" Style="{StaticResource Import.Choice}" IsEnabled="{Binding SessionsApply}">
|
||||
<TextBlock Text="{l:Loc Import.Scan.Minimum}" Style="{StaticResource Text.Unit}" />
|
||||
<TextBox Style="{StaticResource TextBox.Small}" Text="{Binding MinimumFrames.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
|
||||
shell:EditBehavior.Field="{Binding MinimumFrames}" ToolTip="{Binding MinimumFrames.ToolTip}" AutomationProperties.Name="{l:Loc Import.Scan.MinimumName}" />
|
||||
|
||||
@@ -120,8 +120,10 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
// The path is checked only while Folder is the destination; typing one chooses Folder, as "…" does.
|
||||
FolderPath = new EditableField(string.Empty, text => IsFolderDestination ? ArchiveLocations.Validate(text) : null,
|
||||
text => Choices = _choices with { FolderPath = text, Destination = ImportDestinationKind.Folder }, () => Loc.L("Tooltips.Import.FolderPath"));
|
||||
GapMinutes = NumberField(1, 24 * 60, () => _choices.GapMinutes, n => Choices = _choices with { GapMinutes = n }, "Tooltips.Import.Gap");
|
||||
MinimumFrames = NumberField(1, 1000, () => _choices.MinimumFrames, n => Choices = _choices with { MinimumFrames = n }, "Tooltips.Import.MinimumFrames");
|
||||
GapMinutes = NumberField(1, 24 * 60, () => _choices.GapMinutes, n => Choices = _choices with { GapMinutes = n },
|
||||
() => SessionToolTip("Tooltips.Import.Gap"));
|
||||
MinimumFrames = NumberField(1, 1000, () => _choices.MinimumFrames, n => Choices = _choices with { MinimumFrames = n },
|
||||
() => SessionToolTip("Tooltips.Import.MinimumFrames"));
|
||||
FolderTemplate = new EditableField(_choices.FolderTemplate, t => NamingPreview.Validate(t, isFolder: true),
|
||||
t => Choices = _choices with { FolderTemplate = t }, () => Loc.L("Tooltips.Import.FolderTemplate"));
|
||||
FileTemplate = new EditableField(_choices.FileTemplate, t => NamingPreview.Validate(t, isFolder: false),
|
||||
@@ -264,6 +266,11 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
if (previous == value) return;
|
||||
_choices = value;
|
||||
if (value.Destination != previous.Destination) FolderPath.Refresh();
|
||||
if (value.Grouping != previous.Grouping)
|
||||
{
|
||||
GapMinutes.Refresh();
|
||||
MinimumFrames.Refresh();
|
||||
}
|
||||
OnPropertyChanged(string.Empty);
|
||||
if (value.NeedsNewPlan(previous) || (value.TitlesChangeNames != previous.TitlesChangeNames && _titles.Count > 0)) SchedulePlan();
|
||||
else ApplyPlan();
|
||||
@@ -320,6 +327,37 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
set => Choices = _choices with { IncludeSubfolders = value };
|
||||
}
|
||||
|
||||
/// <summary>"Group" is offered for a picked folder only (BRIEF §12.4): a card or a drive always splits into sessions.</summary>
|
||||
public bool CanGroupFolder => _selected?.Kind == SourceKind.Folder;
|
||||
|
||||
public bool GroupBySessions
|
||||
{
|
||||
get => !IsWholeFolder;
|
||||
set
|
||||
{
|
||||
if (value) SetGrouping(ImportGrouping.Sessions);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The picked folder is one sequence per format: camera bodies and pauses are ignored.</summary>
|
||||
public bool GroupWholeFolder
|
||||
{
|
||||
get => IsWholeFolder;
|
||||
set
|
||||
{
|
||||
if (value && CanGroupFolder) SetGrouping(ImportGrouping.WholeFolder);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsWholeFolder => CanGroupFolder && _choices.Grouping == ImportGrouping.WholeFolder;
|
||||
|
||||
/// <summary>Sessions, their gap and their minimum do not apply to a whole folder.</summary>
|
||||
public bool SessionsApply => !IsWholeFolder;
|
||||
|
||||
public bool GapApplies => SessionsApply && _choices.SplitSessions;
|
||||
|
||||
public string SessionsToolTip => SessionToolTip("Tooltips.Import.Sessions");
|
||||
|
||||
public bool SplitSessions
|
||||
{
|
||||
get => _choices.SplitSessions;
|
||||
@@ -340,6 +378,18 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
public IReadOnlyList<TokenItem> Tokens { get; }
|
||||
public ICommand InsertTokenCommand { get; }
|
||||
|
||||
private void SetGrouping(ImportGrouping grouping)
|
||||
{
|
||||
if (_choices.Grouping == grouping) return;
|
||||
// Splits and merges were made on the other grouping's sessions.
|
||||
_splits.Clear();
|
||||
_merges.Clear();
|
||||
Choices = _choices with { Grouping = grouping };
|
||||
}
|
||||
|
||||
/// <summary>A session control's tooltip, or why it does not apply to a whole folder.</summary>
|
||||
private string SessionToolTip(string key) => IsWholeFolder ? Loc.L("Import.Blocked.WholeFolder") : Loc.L(key);
|
||||
|
||||
/// <summary>The view tells which template field the "{ }" menu writes into.</summary>
|
||||
public void SetActiveTemplate(bool folder) => _activeTemplateIsFolder = folder;
|
||||
|
||||
@@ -966,7 +1016,8 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
{
|
||||
if (!cts.IsCancellationRequested) SetStatus(ImportPhase.Planning, Loc.Plural("Import.Status.ReadingCount", n));
|
||||
});
|
||||
var options = _choices.ToOptions(_titles, _splits, _merges);
|
||||
// A card or a drive is always planned by sessions, whatever a folder chose before.
|
||||
var options = _choices.ToOptions(_titles, _splits, _merges) with { Grouping = IsWholeFolder ? ImportGrouping.WholeFolder : ImportGrouping.Sessions };
|
||||
var cardId = _selected.Kind == SourceKind.Card ? await RegisteredCardIdAsync() : null;
|
||||
try
|
||||
{
|
||||
@@ -1456,11 +1507,11 @@ public sealed class ImportViewModel : SectionViewModel
|
||||
else dispatcher.BeginInvoke(action);
|
||||
}
|
||||
|
||||
private static EditableField NumberField(int min, int max, Func<int> current, Action<int> commit, string toolTipKey) =>
|
||||
private static EditableField NumberField(int min, int max, Func<int> current, Action<int> commit, Func<string> toolTip) =>
|
||||
new(current().ToString(Loc.Culture),
|
||||
text => int.TryParse(text.Trim(), NumberStyles.Integer, Loc.Culture, out var n) && n >= min && n <= max
|
||||
? null
|
||||
: Loc.L("Errors.Number.Range", min.ToString("N0", Loc.Culture), max.ToString("N0", Loc.Culture)),
|
||||
text => commit(int.Parse(text.Trim(), NumberStyles.Integer, Loc.Culture)),
|
||||
() => Loc.L(toolTipKey));
|
||||
toolTip);
|
||||
}
|
||||
@@ -14,6 +14,19 @@ public enum DuplicatePolicy
|
||||
ImportAgain,
|
||||
}
|
||||
|
||||
/// <summary>How the planner turns the photos of a source into sequences (BRIEF §12.4, §13).</summary>
|
||||
public enum ImportGrouping
|
||||
{
|
||||
/// <summary>One session per camera body and file format, split where the pause between two photos exceeds the gap.</summary>
|
||||
Sessions,
|
||||
|
||||
/// <summary>
|
||||
/// The whole source (a folder picked on this PC) is one sequence per file format: camera bodies and pauses are
|
||||
/// ignored. RAW+JPEG of the same shots stays two sequences, so no frame is ever doubled.
|
||||
/// </summary>
|
||||
WholeFolder,
|
||||
}
|
||||
|
||||
/// <summary>Card import settings (BRIEF §12.4, §13); the defaults are the brief's.</summary>
|
||||
public sealed record ImportOptions
|
||||
{
|
||||
@@ -25,6 +38,9 @@ public sealed record ImportOptions
|
||||
public bool VerifyCopies { get; init; } = true;
|
||||
public DuplicatePolicy Duplicates { get; init; } = DuplicatePolicy.Skip;
|
||||
|
||||
/// <summary>Sessions, or the whole source as one sequence per format (the session gap and minimum then do not apply).</summary>
|
||||
public ImportGrouping Grouping { get; init; } = ImportGrouping.Sessions;
|
||||
|
||||
/// <summary>Card paths where the user split a session (a new session starts at that photo).</summary>
|
||||
public IReadOnlySet<string> SplitBefore { get; init; } = new HashSet<string>();
|
||||
|
||||
@@ -65,7 +81,10 @@ public sealed record PlannedItem
|
||||
public string? Sha256 { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>A session of the plan: one camera body and file format, one sequence in the archive.</summary>
|
||||
/// <summary>
|
||||
/// A session of the plan: one camera body and file format (a whole folder: one file format), one sequence in the
|
||||
/// archive. Its camera is the one of its first photo.
|
||||
/// </summary>
|
||||
public sealed record PlannedSession
|
||||
{
|
||||
/// <summary>1-based, in order of start time across the import.</summary>
|
||||
@@ -78,6 +97,10 @@ public sealed record PlannedSession
|
||||
public string? CameraMake { get; init; }
|
||||
public string? CameraModel { get; init; }
|
||||
public string? CameraSerial { get; init; }
|
||||
|
||||
/// <summary>Camera bodies among its photos: 1 for a session, possibly more for a whole folder.</summary>
|
||||
public int Cameras { get; init; } = 1;
|
||||
|
||||
public ImageFileFormat Format { get; init; }
|
||||
public DateTime Start { get; init; }
|
||||
public DateTime End { get; init; }
|
||||
@@ -86,6 +109,13 @@ public sealed record PlannedSession
|
||||
public required string Folder { get; init; }
|
||||
|
||||
public string? Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The title when the user types none: the source folder's name for a whole folder; null names the sequence
|
||||
/// after its destination folder.
|
||||
/// </summary>
|
||||
public string? DefaultTitle { get; init; }
|
||||
|
||||
public IReadOnlyList<PlannedItem> Items { get; init; } = [];
|
||||
}
|
||||
|
||||
@@ -99,6 +129,10 @@ public sealed record ImportPlan
|
||||
public required string SourceRoot { get; init; }
|
||||
public required string DestinationRoot { get; init; }
|
||||
public DateTimeOffset Created { get; init; }
|
||||
|
||||
/// <summary>How the photos were grouped into <see cref="Sessions"/>.</summary>
|
||||
public ImportGrouping Grouping { get; init; }
|
||||
|
||||
public IReadOnlyList<PlannedSession> Sessions { get; init; } = [];
|
||||
public IReadOnlyList<ImportProblem> Problems { get; init; } = [];
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Naming;
|
||||
|
||||
namespace Chronos.Core.Import;
|
||||
@@ -33,16 +34,29 @@ public static class ImportPlanner
|
||||
{
|
||||
var folderTemplate = PathTemplate.Parse(options.FolderTemplate);
|
||||
var fileTemplate = PathTemplate.Parse(options.FileTemplate);
|
||||
var wholeFolder = options.Grouping == ImportGrouping.WholeFolder;
|
||||
var folderName = wholeFolder ? FolderName(sourceRoot) : null;
|
||||
var drafts = new List<(string Key, List<CardPhoto> Photos)>();
|
||||
foreach (var body in photos.GroupBy(BodyKey, StringComparer.Ordinal))
|
||||
// A whole folder groups by file format alone, never by camera body: RAW+JPEG of the same shots must stay two
|
||||
// sequences, or each frame would appear twice in one.
|
||||
Func<CardPhoto, string> groupKey = wholeFolder ? FormatKey : BodyKey;
|
||||
foreach (var group in photos.GroupBy(groupKey, StringComparer.Ordinal))
|
||||
{
|
||||
var ordered = body.OrderBy(p => p.CaptureTime).ThenBy(p => p.File.RelativePath, StringComparer.Ordinal).ToList();
|
||||
var ranges = SessionSplitter.Split(ordered.ConvertAll(p => p.CaptureTime), options.SessionGap, options.MinimumSessionFrames,
|
||||
i => options.SplitBefore.Contains(ordered[i].File.RelativePath) ? true : options.MergeAt.Contains(ordered[i].File.RelativePath) ? false : null);
|
||||
foreach (var range in ranges)
|
||||
var ordered = group.OrderBy(p => p.CaptureTime).ThenBy(p => p.File.RelativePath, StringComparer.Ordinal).ToList();
|
||||
var times = ordered.ConvertAll(p => p.CaptureTime);
|
||||
bool? UserBreak(int i) =>
|
||||
options.SplitBefore.Contains(ordered[i].File.RelativePath) ? true : options.MergeAt.Contains(ordered[i].File.RelativePath) ? false : null;
|
||||
// Only the user's splits break a whole folder: no pause starts a session and no group is too small to stand.
|
||||
var ranges = wholeFolder
|
||||
? SessionSplitter.Split(times, TimeSpan.MaxValue, 1, UserBreak)
|
||||
: SessionSplitter.Split(times, options.SessionGap, options.MinimumSessionFrames, UserBreak);
|
||||
for (var r = 0; r < ranges.Count; r++)
|
||||
{
|
||||
var members = ordered.GetRange(range.Start, range.Count);
|
||||
drafts.Add((SessionKey(body.Key, members[0].CaptureTime), members));
|
||||
var members = ordered.GetRange(ranges[r].Start, ranges[r].Count);
|
||||
var key = wholeFolder
|
||||
? FolderKey(sourceRoot, members[0].Metadata.Format, r == 0 ? null : members[0].CaptureTime)
|
||||
: SessionKey(group.Key, members[0].CaptureTime);
|
||||
drafts.Add((key, members));
|
||||
}
|
||||
}
|
||||
drafts.Sort((a, b) => a.Photos[0].CaptureTime.CompareTo(b.Photos[0].CaptureTime) is var c and not 0 ? c : string.CompareOrdinal(a.Key, b.Key));
|
||||
@@ -53,7 +67,7 @@ public static class ImportPlanner
|
||||
{
|
||||
var (key, members) = drafts[s];
|
||||
var first = members[0];
|
||||
options.Titles.TryGetValue(key, out var title);
|
||||
var title = options.Titles.GetValueOrDefault(key) ?? folderName;
|
||||
var context = Context(first, first.CaptureTime, s + 1, 1, title);
|
||||
var folder = await lookup.FindSessionFolderAsync(key, cancellationToken).ConfigureAwait(false)
|
||||
?? UniqueFolder(folderTemplate.ExpandFolder(context), claimedFolders, lookup);
|
||||
@@ -74,11 +88,13 @@ public static class ImportPlanner
|
||||
CameraMake = first.Metadata.Make,
|
||||
CameraModel = first.Metadata.Model,
|
||||
CameraSerial = first.Metadata.BodySerial,
|
||||
Cameras = CountCameras(members),
|
||||
Format = first.Metadata.Format,
|
||||
Start = first.CaptureTime,
|
||||
End = members[^1].CaptureTime,
|
||||
Folder = folder,
|
||||
Title = title,
|
||||
DefaultTitle = folderName,
|
||||
Items = items,
|
||||
});
|
||||
}
|
||||
@@ -88,6 +104,7 @@ public static class ImportPlanner
|
||||
SourceRoot = Path.GetFullPath(sourceRoot),
|
||||
DestinationRoot = Path.GetFullPath(destinationRoot),
|
||||
Created = DateTimeOffset.UtcNow,
|
||||
Grouping = options.Grouping,
|
||||
Sessions = sessions,
|
||||
Problems = problems,
|
||||
AvailableBytes = FreeSpace(destinationRoot),
|
||||
@@ -139,12 +156,41 @@ public static class ImportPlanner
|
||||
};
|
||||
|
||||
/// <summary>Camera body and file format: RAW+JPEG shooting yields two sequences instead of doubled frames.</summary>
|
||||
private static string BodyKey(CardPhoto p) => $"{p.Metadata.Make}|{p.Metadata.Model}|{p.Metadata.BodySerial}|{p.Metadata.Format}";
|
||||
private static string BodyKey(CardPhoto p) => $"{CameraKey(p)}|{p.Metadata.Format}";
|
||||
|
||||
private static string CameraKey(CardPhoto p) => $"{p.Metadata.Make}|{p.Metadata.Model}|{p.Metadata.BodySerial}";
|
||||
|
||||
/// <summary>Camera bodies that took the photos; a photo without a camera in its metadata is no body of its own.</summary>
|
||||
private static int CountCameras(List<CardPhoto> photos) =>
|
||||
System.Math.Max(1, photos.Where(p => p.Metadata.Model is not null).Select(CameraKey).Distinct(StringComparer.Ordinal).Count());
|
||||
|
||||
/// <summary>File format alone (a whole folder): RAW+JPEG still yields two sequences instead of doubled frames.</summary>
|
||||
private static string FormatKey(CardPhoto p) => p.Metadata.Format.ToString();
|
||||
|
||||
private static string SessionKey(string bodyKey, DateTime start) =>
|
||||
"card-" + Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(bodyKey)))[..8] + "-"
|
||||
+ start.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// The key of a whole folder's sequence: the same folder of this PC and the same format always give the same key,
|
||||
/// so an interrupted import resumes into its sequence and a later import of the folder adds to it. A part the user
|
||||
/// split off also carries the time of its first photo.
|
||||
/// </summary>
|
||||
internal static string FolderKey(string sourceRoot, ImageFileFormat format, DateTime? splitAt = null)
|
||||
{
|
||||
var path = Path.TrimEndingDirectorySeparator(Path.GetFullPath(sourceRoot));
|
||||
// Windows compares paths without case: D:\Trip and d:\trip are one folder.
|
||||
if (OperatingSystem.IsWindows()) path = path.ToUpperInvariant();
|
||||
// The same path on another PC is another folder: a server files every client's uploads by these keys.
|
||||
var identity = $"{Environment.MachineName.ToUpperInvariant()}|{path}|{format}";
|
||||
var key = "folder-" + Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(identity)))[..16];
|
||||
return splitAt is { } start ? key + "-" + start.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture) : key;
|
||||
}
|
||||
|
||||
/// <summary>The picked folder's own name, the default title of a whole folder; null for a drive root.</summary>
|
||||
private static string? FolderName(string sourceRoot) =>
|
||||
Path.GetFileName(Path.TrimEndingDirectorySeparator(Path.GetFullPath(sourceRoot))) is { Length: > 0 } name ? name : null;
|
||||
|
||||
private static string UniqueFolder(string folder, HashSet<string> claimed, IImportLookup lookup)
|
||||
{
|
||||
if (folder.Length == 0) folder = "Import";
|
||||
|
||||
@@ -94,6 +94,16 @@ public sealed class ImportChoicesTests
|
||||
Assert.SequenceEqual([fresh.Id], joined.Without(own.Id).Cards);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheGroupingTravelsToThePlannerButNeverIntoACardProfile()
|
||||
{
|
||||
var whole = new ImportChoices { Grouping = ImportGrouping.WholeFolder };
|
||||
Assert.Equal(ImportGrouping.WholeFolder, whole.ToOptions().Grouping);
|
||||
Assert.Equal(ImportGrouping.Sessions, new ImportChoices().ToOptions().Grouping, "a source starts with its sessions");
|
||||
Assert.True(whole.NeedsNewPlan(new ImportChoices()), "the grouping changes which photos form which sequence");
|
||||
Assert.Equal(ImportGrouping.Sessions, ImportChoices.FromProfile(whole.ToProfile()).Grouping, "a card always imports by sessions");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SplitsAndMergesTravelToThePlanner()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Import;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Testing;
|
||||
@@ -175,6 +176,51 @@ public sealed class ImportPlansTests
|
||||
Assert.Equal(1, split[2].MergesInto, "the earlier session of the same body, skipping the other camera");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWholeFolderRowShowsItsFormatAndCamerasWithTheFolderNameAsDefaultTitle()
|
||||
{
|
||||
var jpeg = Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddHours(5))) with
|
||||
{
|
||||
SessionKey = "folder-jpeg",
|
||||
Format = ImageFileFormat.Jpeg,
|
||||
Cameras = 2,
|
||||
Title = "Etna",
|
||||
DefaultTitle = "Etna",
|
||||
};
|
||||
var raw = Session(2, "2026/2026-09-28 Canon EOS R5 (2)", Item(3, Start), Item(4, Start.AddHours(5))) with
|
||||
{
|
||||
SessionKey = "folder-raw",
|
||||
Title = "Etna",
|
||||
DefaultTitle = "Etna",
|
||||
};
|
||||
var plan = Plan(null, null, jpeg, raw) with { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>());
|
||||
Assert.Equal("2 cameras · JPEG", rows[0].CameraText);
|
||||
Assert.Equal("Canon EOS R5 · CR2", rows[1].CameraText);
|
||||
Assert.Null(rows[0].Title, "the folder's name is the placeholder, not typed text");
|
||||
Assert.Equal("Etna", rows[0].DefaultTitle);
|
||||
Assert.Null(rows[1].MergesInto, "another format never merges");
|
||||
var bySessions = ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>());
|
||||
Assert.Equal("Canon EOS R5", bySessions[1].CameraText);
|
||||
|
||||
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string> { ["folder-jpeg"] = "Etna at night" });
|
||||
Assert.Equal("Etna at night", titled.Sessions[0].Title);
|
||||
Assert.Equal("Etna", titled.Sessions[1].Title, "a sequence without a typed title keeps the folder's name");
|
||||
Assert.Equal("Etna at night", ImportPlans.Sessions(titled, ImportDestinationKind.Archive, new HashSet<string>())[0].Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWholeFolderPartMergesBackIntoThePartBeforeItOfTheSameFormatWhateverItsCamera()
|
||||
{
|
||||
var first = Session(1, "2026/Etna", Item(1, Start));
|
||||
var second = Session(2, "2026/Etna (2)", Item(2, Start.AddHours(1))) with { CameraMake = "Nikon", CameraModel = "NIKON Z 8" };
|
||||
var plan = Plan(null, null, first, second) with { Grouping = ImportGrouping.WholeFolder };
|
||||
Assert.Equal(1, ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto);
|
||||
Assert.Null(ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto,
|
||||
"sessions of another camera never merge");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowPlanOffersASplitOnEveryPhotoButTheFirstOfItsSession()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Metadata;
|
||||
using Chronos.Core.Tests.Archiving;
|
||||
using Chronos.Testing;
|
||||
using static Chronos.Core.Tests.Import.ImportTestKit;
|
||||
@@ -163,6 +165,118 @@ public sealed class ImportPlannerTests(TestContext context)
|
||||
Assert.SequenceEqual([5, 5, 10], split.Sessions.Select(s => s.Items.Count));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderIsOneSequenceWhateverTheCameraBodiesAndPauses()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna eruption");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval, prefix: "CAN_");
|
||||
TestPhotos.WriteSeries(folder, Start.AddHours(3), 10, Interval, firstSeed: 20, prefix: "CAN_", firstNumber: 11);
|
||||
TestPhotos.WriteSeries(folder, Start.AddSeconds(5), 3, Interval, firstSeed: 40, prefix: "NIK_", make: "NIKON CORPORATION", model: "NIKON Z 8");
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
Assert.Equal(3, (await PlanAsync(folder, destination)).Sessions.Count, "by sessions: two Canon sessions and the Nikon");
|
||||
|
||||
var plan = await PlanAsync(folder, destination, new ImportOptions { Grouping = ImportGrouping.WholeFolder, FolderTemplate = "{year}/{title}" });
|
||||
Assert.Equal(ImportGrouping.WholeFolder, plan.Grouping);
|
||||
var session = plan.Sessions.Single();
|
||||
Assert.Equal(23, session.Items.Count);
|
||||
Assert.Equal(2, session.Cameras);
|
||||
Assert.Equal("Etna eruption", session.Title, "the folder's name is the default title");
|
||||
Assert.Equal("Etna eruption", session.DefaultTitle);
|
||||
Assert.Equal("2026/Etna eruption", session.Folder);
|
||||
Assert.SequenceEqual(session.Items.OrderBy(i => i.CapturedAt).Select(i => i.SourcePath), session.Items.Select(i => i.SourcePath),
|
||||
"both bodies in capture order");
|
||||
Assert.Equal("2026-09-28_21-01-30_0023.JPG", session.Items[^1].FileName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderOfRawAndJpegIsTwoSequencesSoNoFrameIsDoubled()
|
||||
{
|
||||
var photos = new List<CardPhoto>();
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
// An hour between shots: far beyond the session gap, ignored for a whole folder.
|
||||
var at = Start.AddHours(i);
|
||||
photos.Add(Photo($"IMG_{i:0000}.JPG", at, ImageFileFormat.Jpeg));
|
||||
photos.Add(Photo($"IMG_{i:0000}.CR3", at, ImageFileFormat.Cr3));
|
||||
}
|
||||
var plan = await ImportPlanner.PlanAsync(context.CreateTempDirectory("raw+jpeg"), context.CreateTempDirectory("archive"), photos, [],
|
||||
new ImportOptions { Grouping = ImportGrouping.WholeFolder }, new FakeLookup());
|
||||
|
||||
Assert.Equal(2, plan.Sessions.Count, "one sequence per format");
|
||||
Assert.SequenceEqual([ImageFileFormat.Jpeg, ImageFileFormat.Cr3], plan.Sessions.Select(s => s.Format).OrderBy(f => f));
|
||||
foreach (var session in plan.Sessions)
|
||||
{
|
||||
Assert.Equal(6, session.Items.Count);
|
||||
Assert.Equal(1, session.Items.Select(i => Path.GetExtension(i.SourcePath)).Distinct().Count(), "one format per sequence");
|
||||
}
|
||||
Assert.Equal(12, plan.Items.Select(i => i.SourcePath).Distinct().Count(), "every photo is planned once");
|
||||
Assert.NotEqual(plan.Sessions[0].SessionKey, plan.Sessions[1].SessionKey);
|
||||
Assert.NotEqual(plan.Sessions[0].Folder, plan.Sessions[1].Folder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderTakesItsSubfoldersOnlyWhenAsked()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Construction");
|
||||
TestPhotos.WriteSeries(folder, Start, 4, Interval);
|
||||
TestPhotos.WriteSeries(Path.Combine(folder, "week 2"), Start.AddDays(7), 4, Interval, firstSeed: 50, firstNumber: 5);
|
||||
TestPhotos.WriteSeries(Path.Combine(folder, "week 2", "monday"), Start.AddDays(8), 4, Interval, firstSeed: 70, firstNumber: 9);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var all = (await PlanAsync(folder, destination, whole)).Sessions.Single();
|
||||
Assert.Equal(12, all.Items.Count);
|
||||
Assert.Equal("week 2/monday/IMG_0012.JPG", all.Items[^1].SourcePath);
|
||||
var top = (await PlanAsync(folder, destination, whole with { IncludeSubfolders = false })).Sessions.Single();
|
||||
Assert.Equal(4, top.Items.Count);
|
||||
Assert.Equal(all.SessionKey, top.SessionKey, "the same folder's sequence, whatever is scanned in it");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderKeepsItsKeySoAnInterruptedImportResumesIntoItsSequence()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
var first = (await PlanAsync(folder, destination, whole)).Sessions.Single();
|
||||
Assert.True(first.SessionKey.StartsWith("folder-", StringComparison.Ordinal), first.SessionKey);
|
||||
Assert.Equal(first.SessionKey, ImportPlanner.FolderKey(folder + Path.DirectorySeparatorChar, ImageFileFormat.Jpeg),
|
||||
"a trailing separator names the same folder");
|
||||
Assert.NotEqual(first.SessionKey, ImportPlanner.FolderKey(folder, ImageFileFormat.Cr3));
|
||||
Assert.NotEqual(first.SessionKey, ImportPlanner.FolderKey(Path.Combine(folder, "other"), ImageFileFormat.Jpeg));
|
||||
|
||||
// Photos added later, earlier ones too, keep the folder's key.
|
||||
TestPhotos.WriteSeries(folder, Start.AddDays(-1), 2, Interval, firstSeed: 90, prefix: "OLD_");
|
||||
Assert.Equal(first.SessionKey, (await PlanAsync(folder, destination, whole)).Sessions.Single().SessionKey);
|
||||
|
||||
var lookup = new FakeLookup();
|
||||
lookup.SessionFolders[first.SessionKey] = "2026/Etna";
|
||||
Assert.Equal("2026/Etna", (await PlanAsync(folder, destination, whole, lookup)).Sessions.Single().Folder, "the sequence of the interrupted import");
|
||||
|
||||
var typed = whole with { Titles = new Dictionary<string, string> { [first.SessionKey] = "Etna at night" } };
|
||||
var titled = (await PlanAsync(folder, destination, typed)).Sessions.Single();
|
||||
Assert.Equal("Etna at night", titled.Title);
|
||||
Assert.Equal("Etna", titled.DefaultTitle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderSplitsOnlyWhereTheUserSplitsIt()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Harbour");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var split = new ImportOptions { Grouping = ImportGrouping.WholeFolder, SplitBefore = new HashSet<string> { "IMG_0009.JPG" } };
|
||||
|
||||
var plan = await PlanAsync(folder, destination, split);
|
||||
Assert.SequenceEqual([8, 2], plan.Sessions.Select(s => s.Items.Count), "a part the user split off stays, however short");
|
||||
Assert.Equal(ImportPlanner.FolderKey(folder, ImageFileFormat.Jpeg), plan.Sessions[0].SessionKey);
|
||||
Assert.NotEqual(plan.Sessions[0].SessionKey, plan.Sessions[1].SessionKey);
|
||||
Assert.Equal(plan.Sessions[1].SessionKey, (await PlanAsync(folder, destination, split)).Sessions[1].SessionKey);
|
||||
var merged = split with { SplitBefore = new HashSet<string>(), MergeAt = new HashSet<string> { "IMG_0009.JPG" } };
|
||||
Assert.Equal(10, (await PlanAsync(folder, destination, merged)).Sessions.Single().Items.Count, "merging the part back undoes the split");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoWithoutExifIsPlannedAtItsFileTime()
|
||||
{
|
||||
@@ -177,4 +291,8 @@ public sealed class ImportPlannerTests(TestContext context)
|
||||
// No camera identity: it forms its own body group rather than joining the Canon session.
|
||||
Assert.SequenceEqual([8, 1], plan.Sessions.Select(s => s.Items.Count));
|
||||
}
|
||||
|
||||
/// <summary>A photo as the scanner reads it, without a file behind it (the planner hashes only duplicate candidates).</summary>
|
||||
private static CardPhoto Photo(string path, DateTime captured, ImageFileFormat format) => new(new CardFile(path, 1_000, captured),
|
||||
new FrameMetadata { Format = format, Make = "Canon", Model = "Canon EOS R5", BodySerial = "0431", CapturedAt = captured });
|
||||
}
|
||||
@@ -105,6 +105,35 @@ public sealed class ImportServiceTests(TestContext context)
|
||||
Assert.Equal(20, (await FramesAsync(fx, plan.Sessions.Single())).Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderBecomesOneSequenceNamedAfterItThatALaterImportAddsTo()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna eruption");
|
||||
Photos.WriteSeries(folder, Start, 5);
|
||||
Photos.WriteSeries(folder, Start.AddHours(4), 5, firstSeed: 20, prefix: "NIK_", make: "NIKON CORPORATION", model: "NIKON Z 8");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var plan = await fx.Service.PlanImportAsync(fx.Archive.Id, folder, whole, null, null, fx.Ct);
|
||||
var session = plan.Sessions.Single();
|
||||
await RunAsync(fx, plan);
|
||||
var id = await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Id, session.SessionKey);
|
||||
Assert.Equal("Etna eruption", (await fx.Db.Sequences.GetAsync(id!.Value))!.Title);
|
||||
Assert.Equal(10, (await FramesAsync(fx, session)).Count);
|
||||
|
||||
// Photos added to the folder later join the same sequence; those imported before are found in the archive.
|
||||
Photos.WriteSeries(folder, Start.AddDays(1), 3, firstSeed: 40, prefix: "LATE_");
|
||||
var later = await fx.Service.PlanImportAsync(fx.Archive.Id, folder, whole, null, null, fx.Ct);
|
||||
Assert.Equal(session.SessionKey, later.Sessions.Single().SessionKey);
|
||||
Assert.Equal(session.Folder, later.Sessions.Single().Folder);
|
||||
Assert.Equal(3, later.CopyCount);
|
||||
await RunAsync(fx, later);
|
||||
Assert.Equal(13, (await FramesAsync(fx, session)).Count);
|
||||
|
||||
static Task<ImportProgress> RunAsync(ArchiveFixture fx, ImportPlan plan) => fx.Service.Imports.ExecuteAsync(
|
||||
new ImportJobParameters(fx.Archive.Id, plan, null, true, null), Guid.NewGuid(), 0, _ => ValueTask.CompletedTask, null, fx.Ct);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ErasingTheCardDeletesOnlyVerifiedImports()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user