diff --git a/src/Chronos.App/Archive/ArchiveDialogViewModels.cs b/src/Chronos.App/Archive/ArchiveDialogViewModels.cs index a5fa4e11..95770e96 100644 --- a/src/Chronos.App/Archive/ArchiveDialogViewModels.cs +++ b/src/Chronos.App/Archive/ArchiveDialogViewModels.cs @@ -128,7 +128,7 @@ public sealed class RebuildDialogViewModel : ArchiveDialogViewModel Archive = archive; Availability = availability; Indexed = indexed; - _facts = Facts(null, availability == ArchiveAvailability.Offline ? Loc.L("Archive.Error.Offline", Formatting.LeftToRight(archive.RootPath)) : null); + _facts = Facts(null, availability == ArchiveAvailability.Offline ? Loc.L("Archive.Error.Offline", Formatting.LeftToRight(AppEnvironment.Shown(archive.RootPath))) : null); RebuildCommand = new AsyncRelayCommand(RebuildAsync, () => !IsBusy && availability == ArchiveAvailability.Online); } @@ -181,7 +181,7 @@ public sealed class RebuildDialogViewModel : ArchiveDialogViewModel return [ new(Loc.L("Archive.Rebuild.Archive"), Archive.Name), - new(Loc.L("Archive.Rebuild.Root"), Archive.RootPath, IsPath: true), + new(Loc.L("Archive.Rebuild.Root"), AppEnvironment.Shown(Archive.RootPath), IsPath: true), new(Loc.L("Archive.Rebuild.State"), Loc.L("Archive.Availability." + Availability)), new(Loc.L("Archive.Rebuild.Indexed"), Loc.Plural("Shell.Status.Sequences", Indexed)), Count(Loc.L("Archive.Rebuild.Sidecars"), f => f.Sidecar is not null), diff --git a/src/Chronos.App/Infrastructure/AppEnvironment.cs b/src/Chronos.App/Infrastructure/AppEnvironment.cs index 6ba3e5ef..d97520bf 100644 --- a/src/Chronos.App/Infrastructure/AppEnvironment.cs +++ b/src/Chronos.App/Infrastructure/AppEnvironment.cs @@ -57,9 +57,68 @@ public sealed class AppEnvironment return new(paths.DataRoot, paths.IsPortable, isCapture: false, paths.SyncedFolder, paths.PortableSyncRoot, paths.EarlierPortableData); } + /// + /// The data folder a capture shows in place of its temporary one (): the default data folder of a + /// sample user, so the screenshots show no path of the machine (its temporary folder, its user name). + /// + public const string SampleDataDirectory = @"C:\Users\Studio\AppData\Local\Chronos"; + + /// The folder a capture shows for its sample archive (archive in its data folder), as the sample settings name it. + public const string SampleArchiveDirectory = @"D:\ChronosArchive"; + + /// The temporary data folder of the capture this process runs (the last one made); null outside a capture. + private static string? _captureData; + /// A fresh temporary data folder for screenshots and smoke tests; delete it with . - public static AppEnvironment ForCapture() => - new(Path.Combine(Path.GetTempPath(), "chronos-capture-" + Guid.CreateVersion7().ToString("N")), portable: false, isCapture: true); + public static AppEnvironment ForCapture() + { + var environment = new AppEnvironment(Path.Combine(Path.GetTempPath(), "chronos-capture-" + Guid.CreateVersion7().ToString("N")), portable: false, isCapture: true); + _captureData = environment.DataDirectory; + return environment; + } + + /// + /// A path as the screens show it: one under a capture's temporary data folder as under + /// (its sample archive as ), so the screenshots show nothing of the machine; any + /// other as it is. Only for text on screen: a path typed there goes through . + /// + public static string Shown(string path) => Shown(path, _captureData); + + /// A path typed or shown on screen as the one it stands for: undone, so a capture never writes outside its temporary folder. + public static string Actual(string shown) => Actual(shown, _captureData); + + /// for the capture whose data folder is (none: the path as it is). + internal static string Shown(string path, string? captureData) + { + foreach (var (actual, shown) in CaptureFolders(captureData)) + { + if (Swap(path, actual, shown) is { } swapped) return swapped; + } + return path; + } + + /// for the capture whose data folder is . + internal static string Actual(string shown, string? captureData) + { + foreach (var (actual, sample) in CaptureFolders(captureData)) + { + if (Swap(shown, sample, actual) is { } swapped) return swapped; + } + return shown; + } + + /// A capture's folders and what the screens show for each, the more specific first. + private static (string Actual, string Shown)[] CaptureFolders(string? captureData) => + captureData is null ? [] : [(Path.Combine(captureData, "archive"), SampleArchiveDirectory), (captureData, SampleDataDirectory)]; + + /// with its root replaced by ; null when it is not under it. + private static string? Swap(string path, string from, string to) + { + if (string.IsNullOrEmpty(path)) return null; + var root = from.TrimEnd(Path.DirectorySeparatorChar); + if (path.TrimEnd(Path.DirectorySeparatorChar).Equals(root, StringComparison.OrdinalIgnoreCase)) return to; + return path.StartsWith(root + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) ? to + path[root.Length..] : null; + } /// Removes the temporary data folder of a capture environment (never a real one). public void DeleteCaptureData() diff --git a/src/Chronos.App/Sections/ServerView.xaml b/src/Chronos.App/Sections/ServerView.xaml index 6aae169a..8fc9283e 100644 --- a/src/Chronos.App/Sections/ServerView.xaml +++ b/src/Chronos.App/Sections/ServerView.xaml @@ -214,7 +214,7 @@ ToolTipService.ShowOnDisabled="True" Height="30" Margin="10,0,0,0" /> - @@ -223,7 +223,7 @@ - + @@ -247,7 +247,7 @@ - + diff --git a/src/Chronos.App/Sections/SettingsViewModel.cs b/src/Chronos.App/Sections/SettingsViewModel.cs index fb3c9cad..83ccf08c 100644 --- a/src/Chronos.App/Sections/SettingsViewModel.cs +++ b/src/Chronos.App/Sections/SettingsViewModel.cs @@ -169,12 +169,13 @@ public sealed class SettingsViewModel : SectionViewModel Logs = new LogSettingsRows(_s, Save); // ---- Workspace ---- - WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => Shell.Services.Workspace.Root, OpenWorkspaceFolder, ChangeWorkspaceFolderAsync); + WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => AppEnvironment.Shown(Shell.Services.Workspace.Root), OpenWorkspaceFolder, ChangeWorkspaceFolderAsync); // ---- Storage ---- - CacheFolder = new EditableField(CacheStore.Folder(shell.Services.Environment, _s), v => ArchiveLocations.Validate(v), v => + // A capture shows its folders under a sample data folder; what is typed is taken back to the folder it stands for. + CacheFolder = new EditableField(AppEnvironment.Shown(CacheStore.Folder(shell.Services.Environment, _s)), v => ArchiveLocations.Validate(AppEnvironment.Actual(v)), v => { - var full = Path.GetFullPath(v); + var full = Path.GetFullPath(AppEnvironment.Actual(v)); _s.CacheFolder = full.Equals(Shell.Services.Environment.CacheDirectory, StringComparison.OrdinalIgnoreCase) ? null : full; Save(); _ = UpdateCacheUsageAsync(); @@ -222,8 +223,8 @@ public sealed class SettingsViewModel : SectionViewModel RedetectCommand = new AsyncRelayCommand(DetectEncodersAsync, () => !_isDetecting && !_isTesting); SelfTestCommand = new AsyncRelayCommand(SelfTestAsync, () => !_isDetecting && !_isTesting && Encoders.Any(e => e.Row.CanSelfTest)); ClearCacheCommand = new AsyncRelayCommand(ClearCacheAsync); - OpenDataFolderCommand = new RelayCommand(() => ShellActions.Reveal(DataFolder)); - OpenLogsCommand = new RelayCommand(() => ShellActions.Reveal(LogsFolder)); + OpenDataFolderCommand = new RelayCommand(() => ShellActions.Reveal(Shell.Services.Environment.DataDirectory)); + OpenLogsCommand = new RelayCommand(() => ShellActions.Reveal(Shell.Services.Environment.LogDirectory)); ExportDiagnosticsCommand = new AsyncRelayCommand(ExportDiagnosticsAsync); BackupDatabaseCommand = new AsyncRelayCommand(BackupDatabaseAsync, () => Shell.Services.Database is not null); RedetectFormatsCommand = new AsyncRelayCommand(() => DetectFormatsAsync(refresh: true), () => !_isDetectingFormats); @@ -785,8 +786,8 @@ public sealed class SettingsViewModel : SectionViewModel // ---------------- Advanced ---------------- - public string DataFolder => Shell.Services.Environment.DataDirectory; - public string LogsFolder => Shell.Services.Environment.LogDirectory; + public string DataFolder => AppEnvironment.Shown(Shell.Services.Environment.DataDirectory); + public string LogsFolder => AppEnvironment.Shown(Shell.Services.Environment.LogDirectory); public string PortableText => Loc.L(Shell.Services.Environment.IsPortable ? "Settings.Advanced.PortableOn" : "Settings.Advanced.PortableOff"); /// Level, retention, size limits and rotation of the log files, and the diagnostics bundle's share of each. @@ -877,10 +878,10 @@ public sealed class SettingsViewModel : SectionViewModel var environment = Shell.Services.Environment; if (environment.SyncedFolder is not null) Shell.Notify(Loc.L("Settings.Advanced.DataInOneDrive"), Formatting.LeftToRight(DataFolder), Loc.L("Common.Open"), - Loc.L("Tooltips.Settings.DataInOneDrive"), () => ShellActions.Reveal(DataFolder), isError: true); + Loc.L("Tooltips.Settings.DataInOneDrive"), () => ShellActions.Reveal(Shell.Services.Environment.DataDirectory), isError: true); else if (environment.PortableSyncRoot is not null) Shell.Notify(Loc.L("Settings.Advanced.DataOutsideOneDrive"), Formatting.LeftToRight(DataFolder), Loc.L("Common.Open"), - Loc.L("Tooltips.Settings.OpenDataFolder"), () => ShellActions.Reveal(DataFolder)); + Loc.L("Tooltips.Settings.OpenDataFolder"), () => ShellActions.Reveal(Shell.Services.Environment.DataDirectory)); if (environment.EarlierPortableData is { } earlier) Shell.Notify(Loc.L("Settings.Advanced.EarlierData"), Formatting.LeftToRight(earlier), Loc.L("Common.Open"), Loc.L("Tooltips.Settings.EarlierData"), () => ShellActions.Reveal(earlier)); @@ -1338,7 +1339,7 @@ public sealed class SettingsViewModel : SectionViewModel { Heading = Loc.L("Settings.Storage.ClearTitle"), Message = Loc.L("Settings.Storage.ClearMessage"), - Detail = Formatting.LeftToRight(folder), + Detail = Formatting.LeftToRight(AppEnvironment.Shown(folder)), DetailToolTip = Loc.L("Tooltips.Settings.CacheFolder"), SafeText = Loc.L("Settings.Storage.Keep"), SafeToolTip = Loc.L("Tooltips.Settings.KeepCache"), @@ -1553,7 +1554,7 @@ public sealed class SettingsViewModel : SectionViewModel _s.CacheFolder = null; _s.ThumbnailMemoryItems = defaults.ThumbnailMemoryItems; _s.CacheLimitGb = defaults.CacheLimitGb; - CacheFolder.Load(CacheStore.Folder(Shell.Services.Environment, _s)); + CacheFolder.Load(AppEnvironment.Shown(CacheStore.Folder(Shell.Services.Environment, _s))); ThumbnailMemory.Load(_s.ThumbnailMemoryItems.ToString(CultureInfo.CurrentCulture)); CacheLimit.Load(_s.CacheLimitGb.ToString(CultureInfo.CurrentCulture)); if (Shell.Services.Thumbnails is { } thumbs) thumbs.Capacity = _s.ThumbnailMemoryItems; @@ -1670,7 +1671,7 @@ public sealed class SettingsViewModel : SectionViewModel LoadImportFields(); LoadAnalysisFields(); Parallelism.Load(EffectiveParallelism.ToString(CultureInfo.CurrentCulture)); - CacheFolder.Load(CacheStore.Folder(Shell.Services.Environment, _s)); + CacheFolder.Load(AppEnvironment.Shown(CacheStore.Folder(Shell.Services.Environment, _s))); ThumbnailMemory.Load(_s.ThumbnailMemoryItems.ToString(CultureInfo.CurrentCulture)); CacheLimit.Load(_s.CacheLimitGb.ToString(CultureInfo.CurrentCulture)); if (Shell.Services.Thumbnails is { } thumbs) thumbs.Capacity = _s.ThumbnailMemoryItems; diff --git a/tests/Chronos.App.Tests/Infrastructure/AppEnvironmentTests.cs b/tests/Chronos.App.Tests/Infrastructure/AppEnvironmentTests.cs index c900ea4e..013c1476 100644 --- a/tests/Chronos.App.Tests/Infrastructure/AppEnvironmentTests.cs +++ b/tests/Chronos.App.Tests/Infrastructure/AppEnvironmentTests.cs @@ -61,6 +61,26 @@ public sealed class AppEnvironmentTests(TestContext context) Assert.Null(AppEnvironment.From(AppPaths.Resolve(app, local, [oneDrive])).EarlierPortableData); } + [Test] + public void ACaptureShowsSamplePathsAndTakesWhatIsTypedBackToItsOwnFolder() + { + // Whatever the machine's temporary folder and user name, the screenshots show the same paths. + var data = Path.Combine(context.CreateTempDirectory("temp"), "chronos-capture-0123"); + Assert.Equal(AppEnvironment.SampleDataDirectory, AppEnvironment.Shown(data, data)); + Assert.Equal(Path.Combine(AppEnvironment.SampleDataDirectory, "cache"), AppEnvironment.Shown(Path.Combine(data, "cache"), data)); + Assert.Equal(@"D:\ChronosArchive\2026\Harbour", AppEnvironment.Shown(Path.Combine(data, "archive", "2026", "Harbour"), data)); + // A path elsewhere, or one that only starts with the same letters, is shown as it is; outside a capture every path is. + Assert.Equal(data + "-other", AppEnvironment.Shown(data + "-other", data)); + Assert.Equal(@"E:\Photos", AppEnvironment.Shown(@"E:\Photos", data)); + Assert.Equal(Path.Combine(data, "cache"), AppEnvironment.Shown(Path.Combine(data, "cache"), null)); + + // What is typed over a shown path goes to the capture's own folder, never to the sample user's. + Assert.Equal(Path.Combine(data, "cache", "big"), AppEnvironment.Actual(Path.Combine(AppEnvironment.SampleDataDirectory, "cache", "big"), data)); + Assert.Equal(Path.Combine(data, "archive"), AppEnvironment.Actual(AppEnvironment.SampleArchiveDirectory, data)); + Assert.Equal(@"E:\Cache", AppEnvironment.Actual(@"E:\Cache", data)); + Assert.Equal(AppEnvironment.SampleDataDirectory, AppEnvironment.Actual(AppEnvironment.SampleDataDirectory, null)); + } + [Test] public void AUserFolderOneDriveSynchronisesIsReportedNotHidden() { diff --git a/tests/visual/baselines/README.md b/tests/visual/baselines/README.md index e333768d..6bc4b4ff 100644 --- a/tests/visual/baselines/README.md +++ b/tests/visual/baselines/README.md @@ -24,7 +24,11 @@ dotnet run --project src/Chronos.Tools -- screenshots diff out/screenshots --out The capture runs on sample data whose clock stands at `SampleData.Now` (2026-10-02 10:18 UTC), in English with English formats and with animations off, so the same code draws the same pixels on any day. What the screens measure on the machine is shown as fixed sample values while the clock is frozen (`AppClock`): free space (1.2 TB), the -server's response time (12 ms) and the time and duration of the last sync comparison. Two things still come from the +server's response time (12 ms) and the time and duration of the last sync comparison. The capture's data folder is a +new one in the machine's temporary folder, but the screens show it as a sample user's (`C:\Users\Studio\AppData\Local\Chronos`, +its sample archive as `D:\ChronosArchive`: `AppEnvironment.Shown`), so neither the temporary folder nor the user name +reaches a picture; a path typed over a shown one goes back to the temporary folder (`AppEnvironment.Actual`), so the +capture writes nowhere else. Two captures made with different `TEMP` folders are identical. Two things still come from the machine: the time zone (times are shown in local time; the baselines are made in the development PC's, Europe/Rome, which the Windows runner must share) and the fonts and scaling of Windows itself. diff --git a/tests/visual/baselines/archive-rebuild-dark.png b/tests/visual/baselines/archive-rebuild-dark.png index f2fc2d5e..0555d702 100644 Binary files a/tests/visual/baselines/archive-rebuild-dark.png and b/tests/visual/baselines/archive-rebuild-dark.png differ diff --git a/tests/visual/baselines/archive-rebuild-light.png b/tests/visual/baselines/archive-rebuild-light.png index cd9e46cd..55b85018 100644 Binary files a/tests/visual/baselines/archive-rebuild-light.png and b/tests/visual/baselines/archive-rebuild-light.png differ diff --git a/tests/visual/baselines/server-conflict-dark.png b/tests/visual/baselines/server-conflict-dark.png index d951770f..df2c77d4 100644 Binary files a/tests/visual/baselines/server-conflict-dark.png and b/tests/visual/baselines/server-conflict-dark.png differ diff --git a/tests/visual/baselines/server-conflict-light.png b/tests/visual/baselines/server-conflict-light.png index 019b1f95..386780a3 100644 Binary files a/tests/visual/baselines/server-conflict-light.png and b/tests/visual/baselines/server-conflict-light.png differ diff --git a/tests/visual/baselines/server-dark.png b/tests/visual/baselines/server-dark.png index 5229b2df..1f08268d 100644 Binary files a/tests/visual/baselines/server-dark.png and b/tests/visual/baselines/server-dark.png differ diff --git a/tests/visual/baselines/server-light.png b/tests/visual/baselines/server-light.png index 4311acf3..99a6e522 100644 Binary files a/tests/visual/baselines/server-light.png and b/tests/visual/baselines/server-light.png differ diff --git a/tests/visual/baselines/server-signedout-dark.png b/tests/visual/baselines/server-signedout-dark.png index e7d28d79..aae2eff4 100644 Binary files a/tests/visual/baselines/server-signedout-dark.png and b/tests/visual/baselines/server-signedout-dark.png differ diff --git a/tests/visual/baselines/server-signedout-light.png b/tests/visual/baselines/server-signedout-light.png index afe004a6..00e1d834 100644 Binary files a/tests/visual/baselines/server-signedout-light.png and b/tests/visual/baselines/server-signedout-light.png differ diff --git a/tests/visual/baselines/server-sync-dark.png b/tests/visual/baselines/server-sync-dark.png index c0d898ec..802bf8c6 100644 Binary files a/tests/visual/baselines/server-sync-dark.png and b/tests/visual/baselines/server-sync-dark.png differ diff --git a/tests/visual/baselines/server-sync-light.png b/tests/visual/baselines/server-sync-light.png index a0c1c9fd..1859cd1d 100644 Binary files a/tests/visual/baselines/server-sync-light.png and b/tests/visual/baselines/server-sync-light.png differ diff --git a/tests/visual/baselines/settings-advanced-dark.png b/tests/visual/baselines/settings-advanced-dark.png index 870e68d4..41606d6c 100644 Binary files a/tests/visual/baselines/settings-advanced-dark.png and b/tests/visual/baselines/settings-advanced-dark.png differ diff --git a/tests/visual/baselines/settings-advanced-light.png b/tests/visual/baselines/settings-advanced-light.png index 4a1653c8..7fdb562d 100644 Binary files a/tests/visual/baselines/settings-advanced-light.png and b/tests/visual/baselines/settings-advanced-light.png differ diff --git a/tests/visual/baselines/settings-storage-dark.png b/tests/visual/baselines/settings-storage-dark.png index ac9717b4..9b8b2ca3 100644 Binary files a/tests/visual/baselines/settings-storage-dark.png and b/tests/visual/baselines/settings-storage-dark.png differ diff --git a/tests/visual/baselines/settings-storage-light.png b/tests/visual/baselines/settings-storage-light.png index 50c6f5fe..50028b04 100644 Binary files a/tests/visual/baselines/settings-storage-light.png and b/tests/visual/baselines/settings-storage-light.png differ diff --git a/tests/visual/baselines/settings-workspace-dark.png b/tests/visual/baselines/settings-workspace-dark.png index 256a2324..bbac5330 100644 Binary files a/tests/visual/baselines/settings-workspace-dark.png and b/tests/visual/baselines/settings-workspace-dark.png differ diff --git a/tests/visual/baselines/settings-workspace-light.png b/tests/visual/baselines/settings-workspace-light.png index c36b5af2..f1758016 100644 Binary files a/tests/visual/baselines/settings-workspace-light.png and b/tests/visual/baselines/settings-workspace-light.png differ