diff --git a/src/Chronos.App/Archive/ArchiveScenes.cs b/src/Chronos.App/Archive/ArchiveScenes.cs index 203a9055..16bbcd1f 100644 --- a/src/Chronos.App/Archive/ArchiveScenes.cs +++ b/src/Chronos.App/Archive/ArchiveScenes.cs @@ -20,6 +20,8 @@ public static class ArchiveScenes 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) : []; + // What the Reorganize view wrote leaves with it, so the sample's sizes stay the same for the views after it. + RemoveSampleFiles(); switch (view) { case "overview": @@ -35,6 +37,9 @@ public static class ArchiveScenes break; case "reorganize": archive.ViewIndex = 0; + // The dry run reads each sequence's sidecar, which the sample index has none of: without them every + // sequence would show "cannot be read" and Apply would stay off. + if (archive.SelectedArchive is { } reorganized) await WriteSampleSidecarsAsync(db, reorganized.RootPath, locations); await archive.OpenReorganizeDialogAsync(); if (archive.Dialog is ReorganizeDialogViewModel reorganize) { @@ -60,4 +65,60 @@ public static class ArchiveScenes throw new ArgumentOutOfRangeException(nameof(view), view, "Unknown Archive view."); } } + + /// + /// A minimal sidecar for each sample sequence that has none yet: its id, title and camera, and one small stand-in photo in + /// its originals taken at its first capture, which the templates' dates and file names come from. + /// + private static async Task WriteSampleSidecarsAsync(Data.ChronosDatabase db, string root, IReadOnlyList locations) + { + // A file is recorded before it is written, so one half written goes too. + var paths = new Core.Archiving.ArchivePaths(root); + byte[] photo = [0xFF, 0xD8, 0xFF, 0xD9]; + var sha256 = Convert.ToHexStringLower(System.Security.Cryptography.SHA256.HashData(photo)); + foreach (var location in locations) + { + var folder = paths.Sequence(location.Folder); + if (System.IO.File.Exists(folder.ManifestPath) || await db.Sequences.GetAsync(location.Id) is not { } sequence) continue; + System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(folder.ManifestPath)!); + const string file = Core.Archiving.ArchiveLayout.OriginalsFolder + "/IMG_0001.JPG"; + var frames = new List(); + if (sequence.FirstCapture is { } first) + { + var onDisk = System.IO.Path.Combine(folder.Folder, file); + System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(onDisk)!); + SampleFiles.Add(onDisk); + System.IO.File.WriteAllBytes(onDisk, photo); + frames.Add(new Core.Archiving.SidecarFrame { Id = Guid.CreateVersion7(), File = file, Size = photo.Length, Sha256 = sha256, CapturedAt = first }); + } + SampleFiles.Add(folder.ManifestPath); + Core.Archiving.ManifestStore.WriteSequence(folder.ManifestPath, new Core.Archiving.SequenceManifest + { + Id = sequence.Id, + Title = sequence.Title, + Camera = new Core.Archiving.SidecarCamera { Make = sequence.CameraMake, Model = sequence.CameraModel }, + Frames = frames, + }); + } + } + + /// The files wrote that are still on disk. + private static readonly List SampleFiles = []; + + /// Deletes the files the Reorganize view wrote for its dry run. + private static void RemoveSampleFiles() + { + foreach (var path in SampleFiles) + { + try + { + System.IO.File.Delete(path); + } + catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException) + { + Core.Diagnostics.Log.Warning("capture", $"{path} of the sample stays", ex); + } + } + SampleFiles.Clear(); + } } diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml index 665a6299..fedbf7c2 100644 --- a/src/Chronos.App/Sections/SettingsView.xaml +++ b/src/Chronos.App/Sections/SettingsView.xaml @@ -694,7 +694,7 @@ - + diff --git a/tests/Chronos.App.Tests/Archive/ArchiveScreenSmokeTests.cs b/tests/Chronos.App.Tests/Archive/ArchiveScreenSmokeTests.cs index 9549daff..7ded9a3b 100644 --- a/tests/Chronos.App.Tests/Archive/ArchiveScreenSmokeTests.cs +++ b/tests/Chronos.App.Tests/Archive/ArchiveScreenSmokeTests.cs @@ -100,7 +100,7 @@ public sealed class ArchiveScreenSmokeTests Assert.NotEmpty(reorganize.Rows, "the dry run lists the sequences that change"); Assert.Null(reorganize.ErrorText); await app.ExpectAsync("archive-reorganize"); - Assert.True(ButtonFor(app, reorganize.ApplyCommand).IsEnabled, "Apply follows the dry run"); + Assert.True(ButtonFor(app, reorganize.ApplyCommand).IsEnabled, "Apply follows the dry run: " + reorganize.ApplyToolTip); Assert.True(ButtonFor(app, reorganize.CloseCommand).IsDefault, "Enter takes the safe way out"); foreach (var box in app.FindAll().Where(c => c.IsVisible)) Assert.NotNull(box.ToolTip, "every template switch says what it does"); AssertNoErrorShown(app); @@ -149,7 +149,7 @@ public sealed class ArchiveScreenSmokeTests // The dialogs' templates exist once they are laid out: render first, then look inside. await ArchiveScenes.ShowAsync(app.Shell, "rebuild"); await app.ExpectAsync("archive-rebuild-ar"); - Assert.Equal(FlowDirection.LeftToRight, TextFor(app, archive.SelectedArchive!.RootPath).FlowDirection, "the archive folder reads left to right"); + Assert.Equal(FlowDirection.LeftToRight, TextFor(app, AppEnvironment.Shown(archive.SelectedArchive!.RootPath)).FlowDirection, "the archive folder reads left to right"); await ArchiveScenes.ShowAsync(app.Shell, "reorganize"); var reorganize = Assert.NotNull(archive.Dialog as ReorganizeDialogViewModel); @@ -299,7 +299,14 @@ public sealed class ArchiveScreenSmokeTests UiLanguage.Apply(language); window.UpdateLayout(); await window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle); + // A language switch builds the tree's rows again; they may arrive a few layout passes later. var years = TreeItems(app).Where(i => ((ArchiveTreeRowViewModel)i.DataContext).IsYear).ToList(); + for (var until = DateTime.UtcNow.AddSeconds(TestTiming.Budget(5)); years.Count == 0 && DateTime.UtcNow < until;) + { + await Task.Delay(50); + window.UpdateLayout(); + years = TreeItems(app).Where(i => ((ArchiveTreeRowViewModel)i.DataContext).IsYear).ToList(); + } Assert.True(years.Count > 0, $"{language}: year rows show"); foreach (var item in years) { diff --git a/tests/Chronos.App.Tests/Server/ServerScreenSmokeTests.cs b/tests/Chronos.App.Tests/Server/ServerScreenSmokeTests.cs index b9a3b754..4030a189 100644 --- a/tests/Chronos.App.Tests/Server/ServerScreenSmokeTests.cs +++ b/tests/Chronos.App.Tests/Server/ServerScreenSmokeTests.cs @@ -50,7 +50,8 @@ public sealed class ServerScreenSmokeTests var sunrise = Row(table, "Sunrise over Superga"); Assert.Equal(SyncStatus.ProxiesOnly, sunrise.Entry.Status); Assert.Equal(Loc.L("Server.Sync.Proxies"), sunrise.LocalText); - Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals], Actions(sunrise)); + // A server without projects: open with proxies; the workspace is offered, disabled with the reason (phase 5b). + Assert.SequenceEqual([SyncAction.OpenWithProxies, SyncAction.DownloadOriginals, SyncAction.OpenInWorkspace], Actions(sunrise)); Assert.SequenceEqual([SyncAction.Upload], Actions(Row(table, "Clouds over the Langhe"))); var conflict = Row(table, "Holy grail ยท Monviso"); Assert.Equal(StatusKind.Warning, conflict.StateKind); diff --git a/tests/Chronos.App.Tests/Windows/ScreenSmokeTests.cs b/tests/Chronos.App.Tests/Windows/ScreenSmokeTests.cs index 6fe83476..014e9b79 100644 --- a/tests/Chronos.App.Tests/Windows/ScreenSmokeTests.cs +++ b/tests/Chronos.App.Tests/Windows/ScreenSmokeTests.cs @@ -83,7 +83,7 @@ public sealed class ScreenSmokeTests Assert.Equal(0, shell.Library.SelectionCount); shell.Navigate(SectionKey.Jobs); - Assert.Equal(9, shell.Jobs.Rows.Count); + Assert.Equal(10, shell.Jobs.Rows.Count, string.Join(" | ", shell.Jobs.Rows.Select(r => r.AccessibleName))); Assert.True(shell.IsJobActive, "running jobs show in the job bar"); shell.Jobs.Rows[0].IsExpanded = true; await app.ExpectAsync("jobs"); diff --git a/tests/visual/baselines/archive-reorganize-dark.png b/tests/visual/baselines/archive-reorganize-dark.png index c83a4084..bc4d7a8b 100644 Binary files a/tests/visual/baselines/archive-reorganize-dark.png and b/tests/visual/baselines/archive-reorganize-dark.png differ diff --git a/tests/visual/baselines/archive-reorganize-light.png b/tests/visual/baselines/archive-reorganize-light.png index f62de147..3c05f770 100644 Binary files a/tests/visual/baselines/archive-reorganize-light.png and b/tests/visual/baselines/archive-reorganize-light.png differ