fix(app): import gates, partial results and plan editing after review

- a card that leaves needs a new check; formatting re-lists the card and refuses
  one that changed since its check; files that are not photos are named in the
  format confirmation
- an import never stays stuck in Running; Retry never resumes an older job
- server imports list refused files and keep what was uploaded when stopped
- the archive result matches each copy to its job's record and shows the job's
  own error per file
- refreshing devices keeps typed titles and choices; titles lock while copying
- three destination names, merge and split of sessions, camera profiles shared
  by the cards of a camera, photo counts and a new-card toast
- disabled controls say why; keyboard focus follows the nickname field and
  Show plan (Esc closes it); label column fits longer languages
- capture states for insertion, running, failed and a new card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:44:22 +00:00
1 parent 5aa5edab57
commit 29c82eba5c
27 files changed
+1286 -285

No files matched your search

+67 -19
View File
@@ -17,11 +17,13 @@ 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. <see cref="CardActions"/> decides
/// what is allowed and why not.
/// what is allowed and why not; a card that leaves needs a new check, and formatting refuses a card that changed
/// since its check.
/// </summary>
public sealed class ImportResultViewModel : LocalizedViewModel
{
private const int ListedFailures = 100;
private const int ListedOther = 8;
private readonly ShellViewModel _shell;
private readonly ImportPlan _plan;
@@ -43,12 +45,11 @@ public sealed class ImportResultViewModel : LocalizedViewModel
_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);
_actions = new CardActions(choices.Destination, card is not null, device is not null, device?.IsRemovable == true, outcome, null, null);
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);
FormatCommand = new AsyncRelayCommand(FormatAsync, () => _actions.CanFormat && !_isBusy);
EjectCommand = new AsyncRelayCommand(EjectAsync, () => _actions.CanEject && !_isBusy);
OpenLibraryCommand = new AsyncRelayCommand(async () =>
{
@@ -122,8 +123,8 @@ public sealed class ImportResultViewModel : LocalizedViewModel
public string CheckToolTip => _actions.CheckBlocker ?? Loc.L("Tooltips.Import.Check");
/// <summary>"Delete 4,812 photos…".</summary>
public string DeleteText => Loc.Plural("Import.Erase.Delete", _actions.DeleteCount);
/// <summary>"Delete 4,812 photos…" once the card was checked; "Delete photos…" before.</summary>
public string DeleteText => _actions.Erase is null ? Loc.L("Import.Erase.DeletePlain") : Loc.Plural("Import.Erase.Delete", _actions.DeleteCount);
public string DeleteToolTip => _actions.DeleteBlocker ?? Loc.L("Tooltips.Import.Delete");
@@ -131,15 +132,25 @@ public sealed class ImportResultViewModel : LocalizedViewModel
public string EjectToolTip => _actions.CanEject ? Loc.L("Tooltips.Import.Eject") : Loc.L("Import.Blocked.NotRemovable");
/// <summary>The card left or came back (Devices list); actions follow.</summary>
/// <summary>
/// The card is listed again, left, or came back (Devices list); actions follow. A card that left may come back
/// changed (photos shot meanwhile), so its dry run no longer counts: a new check is needed.
/// </summary>
public void SetDevice(CardDevice? device)
{
var same = device is not null && _device is not null && device.Identity == _device.Identity && device.Root == _device.Root;
_device = device;
Actions = _actions with { IsInserted = device is not null, IsRemovable = device?.IsRemovable == true };
Actions = _actions with
{
IsInserted = device is not null,
IsRemovable = device?.IsRemovable == true,
Erase = same ? _actions.Erase : null,
Card = same ? _actions.Card : null,
};
}
/// <summary>Shows a dry run computed elsewhere (capture, tests).</summary>
public void ShowErase(ErasePlan erase, int cardPhotos) => Actions = _actions with { Erase = erase, CardPhotos = cardPhotos };
public void ShowErase(ErasePlan erase, CardSnapshot card) => Actions = _actions with { Erase = erase, Card = card };
/// <summary>Ejects when the profile asks for it and nothing more is to be done on the card.</summary>
public async Task AutoEjectAsync()
@@ -150,17 +161,18 @@ public sealed class ImportResultViewModel : LocalizedViewModel
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;
var device = _device;
IsBusy = true;
try
{
var progress = new Progress<int>(n => BusyText = Loc.Plural("Import.Erase.Checking", n));
var (erase, photos) = await Task.Run(async () =>
var (erase, snapshot) = 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);
// Listed before hashing: formatting later compares the card with this list.
var card = CardSnapshot.Take(device.Root, device.Identity);
return (await archives.PlanCardEraseAsync(_archive.Id, _card.Id, device.Root, progress).ConfigureAwait(false), card);
});
ShowErase(erase, photos);
if (_device == device) ShowErase(erase, snapshot);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException)
{
@@ -195,7 +207,7 @@ public sealed class ImportResultViewModel : LocalizedViewModel
_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 };
Actions = _actions with { Erase = null, Card = null };
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
@@ -209,14 +221,19 @@ public sealed class ImportResultViewModel : LocalizedViewModel
if (_choices.Eject && _actions.CanEject) await EjectAsync();
}
private void Format()
private async Task FormatAsync()
{
if (_device is not { } device) return;
if (_device is not { } device || _actions.Card is not { } checkedCard) return;
var name = _card?.Nickname ?? device.Label;
var notImported = _actions.NotImported;
var confirmed = _shell.Services.Dialogs.Confirm(new ConfirmRequest
{
Heading = Loc.L("Import.Confirm.FormatHeading", name),
Message = Loc.Plural("Import.Confirm.FormatMessage", _actions.DeleteCount),
Message = notImported.Count == 0
? Loc.Plural("Import.Confirm.FormatMessage", _actions.DeleteCount)
: Loc.Plural("Import.Confirm.FormatMessage", _actions.DeleteCount) + " " + Loc.Plural("Import.Confirm.FormatOther", notImported.Count),
Detail = notImported.Count == 0 ? null : OtherFilesDetail(notImported),
DetailToolTip = Loc.L("Tooltips.Import.NotImported"),
SafeText = Loc.L("Import.Confirm.Keep"),
SafeToolTip = Loc.L("Tooltips.Import.KeepCard"),
ActionText = Loc.L("Import.Confirm.Format"),
@@ -226,11 +243,42 @@ public sealed class ImportResultViewModel : LocalizedViewModel
TypedPrompt = Loc.L("Import.Confirm.TypeName"),
});
if (!confirmed) return;
// Right before formatting: the same card, holding exactly what was checked (BRIEF §0.2 rule 8).
IsBusy = true;
bool unchanged;
try
{
var present = _shell.Services.Devices.Devices.FirstOrDefault(d => d.Identity == device.Identity && d.Root == device.Root);
unchanged = present is not null && checkedCard.IsUnchanged(await Task.Run(() => CardSnapshot.Take(present.Root, present.Identity)));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
Log.Warning("import", "The card could not be listed before formatting", ex);
unchanged = false;
}
finally
{
IsBusy = false;
}
if (!unchanged)
{
Actions = _actions with { Erase = null, Card = null };
_shell.Notify(Loc.L("Import.Toast.CardChanged", name), Loc.L("Import.Blocked.NoDryRun"));
return;
}
var outcome = _shell.Services.Devices.Format(device);
if (outcome == FormatOutcome.Formatted) Actions = _actions with { Erase = null };
if (outcome == FormatOutcome.Formatted) Actions = _actions with { Erase = null, Card = null };
if (outcome != FormatOutcome.Cancelled) _shell.Notify(Loc.L("Import.Toast.Format." + outcome, name));
}
/// <summary>The first files that were never imported, one per line.</summary>
private static string OtherFilesDetail(IReadOnlyList<string> files)
{
var shown = files.Take(ListedOther).ToList();
if (files.Count > ListedOther) shown.Add("…");
return string.Join(Environment.NewLine, shown);
}
private async Task EjectAsync()
{
if (_device is not { } device) return;