From 9ad8c6f7a930f0aa579022306da2485d8042e714 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Sun, 15 Nov 2026 14:00:46 +0100 Subject: [PATCH] feat: wire separate homes into the desktop (owner review 5 P3.2) The desktop now uses the per-home layout from P3.1: each home keeps its own projects, proxies and originals, and a server is known by its id whichever address reaches it. - Settings keep the known servers (id, name, last address, certificate, aliases, originals archive). Reset and Import keep them; Export leaves them out. - SyncHost records each server the first time it signs in with an id. It names the cache and workspace folders by that id, and re-keys the folders a server had under its addresses at sign-in. The re-key waits while transfer or workspace jobs are pending. - Download originals goes to the server's own archive. It is created beside this PC's archive at the first download, and a toast says where. A sequence that already has a local copy keeps receiving into that copy's archive. A server without an id keeps the 1.0 behaviour. - At start, after the index opens and before any job runs, the folders are sorted into their homes. A toast reports the result: sorted, pending or failed. - The workspace host gives each home's store its own sync. Find, List, usage, clean-up and the trash plan and empty cover every home. Server comparisons go through the identity, so a project stays Online when its server is reached by another address. - The render-node downloads and the server import staging move into the server's folder of the cache. The cache trim keeps `servers`, and the scheduled scan also scans the originals archives. - Settings shows the Home folders rows (Workspace) and the Known servers table (Server). The diagnostics bundle lists the homes. - The dead `AppPaths.CreateDirectories` and `ThumbnailsDirectory` are removed. Refs #66 Co-Authored-By: Claude Opus 5.5 --- i18n/en/Archive.resx | 1 + i18n/en/Errors.resx | 3 + i18n/en/Settings.resx | 8 + i18n/en/Shell.resx | 7 + i18n/en/Tooltips.resx | 13 + i18n/it/Archive.it.resx | 1 + i18n/it/Errors.it.resx | 3 + i18n/it/Settings.it.resx | 8 + i18n/it/Shell.it.resx | 7 + i18n/it/Tooltips.it.resx | 13 + src/Chronos.App/DesignTime/SampleData.cs | 12 +- src/Chronos.App/Editor/ProjectFiles.cs | 2 +- src/Chronos.App/Infrastructure/AppServices.cs | 79 +++++- src/Chronos.App/Infrastructure/AppSettings.cs | 38 +++ .../Infrastructure/DiagnosticsBundle.cs | 45 +++ src/Chronos.App/Jobs/DesktopScheduleHost.cs | 11 +- src/Chronos.App/Library/LibraryActions.cs | 6 +- src/Chronos.App/Sections/ImportViewModel.cs | 15 +- .../Sections/SequencePickerViewModel.cs | 2 +- src/Chronos.App/Sections/SequenceViewModel.cs | 6 +- src/Chronos.App/Sections/SettingsView.xaml | 78 ++++++ src/Chronos.App/Sections/SettingsViewModel.cs | 97 ++++++- src/Chronos.App/Sections/VideosViewModel.cs | 2 +- src/Chronos.App/Server/SyncHost.cs | 260 ++++++++++++++++-- src/Chronos.App/Server/SyncTableViewModel.cs | 6 +- src/Chronos.App/Settings/HomeRows.cs | 97 +++++++ src/Chronos.App/Videos/VideoSources.cs | 20 +- .../Workspace/ProjectMenuViewModel.cs | 2 +- .../Workspace/WorkspaceHost.Cleanup.cs | 70 +++-- .../Workspace/WorkspaceHost.Move.cs | 4 +- src/Chronos.App/Workspace/WorkspaceHost.cs | 156 +++++++---- src/Chronos.Core.Windows/Shell/AppPaths.cs | 16 +- .../Workspace/ServerHomeTests.cs | 64 ++++- .../Workspace/WorkspaceCleanupHostTests.cs | 10 +- .../Workspace/WorkspaceEditorTests.cs | 8 +- .../Workspace/WorkspaceFallbackTests.cs | 14 +- .../Workspace/WorkspaceHostTests.cs | 86 ++++-- .../Workspace/WorkspaceLocalRenderTests.cs | 14 +- .../Workspace/WorkspaceMenuTests.cs | 10 +- .../Workspace/WorkspaceNewerFormatTests.cs | 6 +- .../Workspace/WorkspaceOpenPolicyTests.cs | 2 +- .../Workspace/WorkspaceSectionTests.cs | 6 +- .../Workspace/WorkspaceTestBed.cs | 2 +- .../Shell/AppPathsTests.cs | 16 +- 44 files changed, 1106 insertions(+), 220 deletions(-) create mode 100644 src/Chronos.App/Settings/HomeRows.cs diff --git a/i18n/en/Archive.resx b/i18n/en/Archive.resx index 3cb381b3..77fb1442 100644 --- a/i18n/en/Archive.resx +++ b/i18n/en/Archive.resx @@ -291,6 +291,7 @@ Restore database… Run maintenance Trash… + {0} (server)the name of the archive of a server's downloaded originals; {0} the server's name {0:N0} issue {0:N0} issues The orphan search stoppedlong diff --git a/i18n/en/Errors.resx b/i18n/en/Errors.resx index 5c16556f..6b0eb1c2 100644 --- a/i18n/en/Errors.resx +++ b/i18n/en/Errors.resx @@ -9,6 +9,8 @@ The archive could not be opened.long The current index could not be backed up or replaced; the restore runs again at the next start.long This backup cannot be restored; choose another one.long + {0} presents the ID of {1} with another certificate; check that it is not a copy of that server.{0} the server's name now, {1} the name it had + The folders could not be sorted: {0}. Nothing was deleted; Chronos tries again at the next start.{0} the reason Enter a number from {0} to {1}. Enter a whole number from {0} to {1}. Enter a folder. @@ -34,6 +36,7 @@ {0} did not arrive intact; download it again.{0} file name The sequence is no longer in this PC's archive index. Open or create an archive on this PC to receive the originals. + No folder could be made for the originals of {0}; check that the drive of this PC's archive can be written.{0} the server's name Not connected to this server; connect and retry the job. This sequence is not on the server yet; upload it first. No original reached the server: they are missing here or already in another server sequence. diff --git a/i18n/en/Settings.resx b/i18n/en/Settings.resx index 8619d1c8..38ce56ae 100644 --- a/i18n/en/Settings.resx +++ b/i18n/en/Settings.resx @@ -178,12 +178,18 @@ testing… Reset section Search settings + Server cache Trusted certificates Default server Forget: {0} + Known servers None Offer this PC + Offline + Originals folder Render node + Server ID + Signed in Clear Spilled frames and decoded thumbnails are deleted and rebuilt when needed. Originals, proxies and renders are not touched.long Clear the cache? @@ -206,11 +212,13 @@ Workspace folder changed Choose the workspace folderlong; folder picker title Folder + Home folders Kept versions Folder not changed Projects found: {0}{0} count of the projects the folder chosen holds Projects left: {0}{0} count of the projects the folder in use keeps Sync + This PC Use folder {0} version {0} versions diff --git a/i18n/en/Shell.resx b/i18n/en/Shell.resx index d9200b8f..e8b4e776 100644 --- a/i18n/en/Shell.resx +++ b/i18n/en/Shell.resx @@ -5,6 +5,13 @@ 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 Chronosinvariant + Server ID clash + {0} project moved{0} count + {0} projects moved{0} count + Originals folder made + Folders pending + Projects in use, or a workspace being moved, follow at the next start.long; toast message under Folders pending + Folders sorted Job finished {0} job finished {0} jobs finished diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 3be6f60e..ba8ca96d 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -805,6 +805,14 @@ Frames whose mean brightness is at most this share of white count as night (star fields, night presets) · Enter applies, Esc reverts Open the data folder in Explorer Show the workspace folder in Explorer + This server's proxies, render-node files and staged imports, inside the cache folder + Servers this PC has signed in to, with the folders kept for each + Not signed in: its projects open from the workspace and wait to sync + Show this server's share of the cache in Explorer + Show the archive of this server's downloaded originals in Explorer + Where Download originals puts this server's photos, apart from this PC's archive + Identifies the server even when its address or name changes: {0}{0} the whole id + This PC is signed in to this server now Version, build, system, licence, third-party code Portable mode, logs, diagnostics, database backup and restore, reset Analysis width, night and star thresholds, deep analysis @@ -892,6 +900,7 @@ Replace the installed version in place · your data is kept Collapse navigation to icons · Ctrl+B Show navigation names · Ctrl+B + Show the logs folder in Explorer: the log says which folder could not be sorted Pause the job shown; it continues from its checkpoint when resumed Stop the current job · it can be resumed later Add a folder to watch @@ -975,6 +984,10 @@ Keep the workspace's trash as it is What the workspace folder takes on its drive, its trash included The workspace's folder (a fast disk is best); Change uses another one, Move takes the projects along + Each home keeps its projects in its own folder inside the workspace + Open this home's folder in Explorer + Projects of sequences on {0}: {1}{0} the server's name, {1} the folder + Projects of sequences in this PC's archive: {0}{0} the folder Move the workspace folder with its projects to another folder, after a plan; each file is checked before its source goes Past this size, the media of the projects used longest ago are removed once they are in step with their home; their versions stay The workspace grows as needed; only Clean after removes media diff --git a/i18n/it/Archive.it.resx b/i18n/it/Archive.it.resx index 3fecf541..cea69074 100644 --- a/i18n/it/Archive.it.resx +++ b/i18n/it/Archive.it.resx @@ -285,6 +285,7 @@ Ripristina database… Esegui manutenzione Cestino… + {0} (server) {0:N0} problema {0:N0} problemi Ricerca degli orfani interrotta diff --git a/i18n/it/Errors.it.resx b/i18n/it/Errors.it.resx index 601bb54b..2000a8d5 100644 --- a/i18n/it/Errors.it.resx +++ b/i18n/it/Errors.it.resx @@ -9,6 +9,8 @@ Impossibile aprire l'archivio. Non è stato possibile copiare o sostituire l'indice attuale; il ripristino riparte al prossimo avvio. Questa copia non si può ripristinare; scegline un'altra. + {0} presenta l'ID di {1} con un altro certificato; verifica che non sia una copia di quel server. + Non è stato possibile riordinare le cartelle: {0}. Non è stato eliminato nulla; Chronos riprova al prossimo avvio. Inserisci un numero da {0} a {1}. Inserisci un numero intero da {0} a {1}. Inserisci una cartella. @@ -34,6 +36,7 @@ {0} non è arrivato integro; scaricalo di nuovo. La sequenza non è più nell'indice dell'archivio di questo PC. Apri o crea un archivio su questo PC per ricevere gli originali. + Non è stato possibile creare una cartella per gli originali di {0}; verifica che il disco dell'archivio di questo PC sia scrivibile. Non connesso a questo server; collegati e riprova l'attività. Questa sequenza non è ancora sul server; caricala prima. Nessun originale è arrivato al server: mancano qui o sono già in un'altra sequenza del server. diff --git a/i18n/it/Settings.it.resx b/i18n/it/Settings.it.resx index c0bc4322..0a78d616 100644 --- a/i18n/it/Settings.it.resx +++ b/i18n/it/Settings.it.resx @@ -175,12 +175,18 @@ in prova… Ripristina sezione Cerca impostazioni + Cache del server Certificati attendibili Server predefinito Dimentica: {0} + Server noti Nessuno Offri questo PC + Non in linea + Cartella originali Nodo di rendering + ID server + Connesso Svuota I fotogrammi temporanei e le miniature vengono eliminati e ricreati quando servono. Originali, proxy ed esportazioni restano intatti. Svuotare la cache? @@ -203,11 +209,13 @@ Cartella cambiata Scegli la cartella dello spazio di lavoro Cartella + Cartelle per origine Versioni tenute Cartella non cambiata Progetti trovati: {0} Progetti lasciati: {0} Sincronizzazione + Questo PC Usa cartella {0} versione {0} versioni diff --git a/i18n/it/Shell.it.resx b/i18n/it/Shell.it.resx index 0b51d68b..13b193e9 100644 --- a/i18n/it/Shell.it.resx +++ b/i18n/it/Shell.it.resx @@ -4,6 +4,13 @@ 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 + ID server in conflitto + {0} progetto spostato + {0} progetti spostati + Cartella originali creata + Cartelle in attesa + I progetti in uso, o uno spazio di lavoro in spostamento, seguono al prossimo avvio. + Cartelle riordinate Attività completata {0} attività completata {0} attività completate diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 4a6a5ca8..3ab4112f 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -876,6 +876,14 @@ I fotogrammi con luminosità media al massimo pari a questa quota del bianco contano come notturni (campi stellari, preset notturni) · Invio applica, Esc annulla Apri la cartella dati in Esplora file Mostra la cartella dello spazio di lavoro in Esplora file + Proxy, file del nodo di rendering e importazioni in attesa di questo server, dentro la cartella della cache + I server a cui questo PC ha effettuato l'accesso, con le cartelle tenute per ciascuno + Accesso non effettuato: i suoi progetti si aprono dallo spazio di lavoro e attendono la sincronizzazione + Mostra la parte della cache di questo server in Esplora file + Mostra l'archivio degli originali scaricati da questo server in Esplora file + Dove Scarica originali mette le foto di questo server, separate dall'archivio di questo PC + Identifica il server anche quando cambiano indirizzo o nome: {0} + Questo PC ha effettuato l'accesso a questo server ora Quando Chronos è ridotto a icona o in secondo piano, schede inserite, attività finite e messaggi del server compaiono anche come notifiche di Windows Versione, build, sistema, licenza, codice di terze parti Modalità portatile, log, diagnostica, backup e ripristino del database, valori predefiniti @@ -935,6 +943,10 @@ Svuota per sempre il cestino dello spazio di lavoro, dopo un elenco di ciò che contiene e una conferma scritta Il cestino dello spazio di lavoro è vuoto La cartella dello spazio di lavoro (meglio un disco veloce); Cambia ne usa un'altra, Sposta porta con sé i progetti + Ogni origine tiene i suoi progetti in una cartella propria dentro lo spazio di lavoro + Apri la cartella di questa origine in Esplora file + Progetti delle sequenze su {0}: {1} + Progetti delle sequenze nell'archivio di questo PC: {0} Il progetto che hai aperto per ultimo per la sequenza Il progetto Principale della sequenza, che ne tiene le impostazioni Sposta la cartella dello spazio di lavoro con i suoi progetti in un'altra cartella, dopo un piano; ogni file è verificato prima di rimuovere l'origine @@ -989,6 +1001,7 @@ Sostituisci la versione installata · i tuoi dati restano Riduci la navigazione alle icone · Ctrl+B Mostra i nomi della navigazione · Ctrl+B + Mostra la cartella dei log in Esplora file: il log dice quale cartella non è stata riordinata Mette in pausa l'attività mostrata; quando la riprendi continua dal punto di ripresa Ferma l'attività in corso · potrai riprenderla Aggiungi una cartella da controllare diff --git a/src/Chronos.App/DesignTime/SampleData.cs b/src/Chronos.App/DesignTime/SampleData.cs index ace1ca49..27577fb2 100644 --- a/src/Chronos.App/DesignTime/SampleData.cs +++ b/src/Chronos.App/DesignTime/SampleData.cs @@ -84,7 +84,7 @@ public sealed class SampleData services.CheckForUpdateAsync = _ => Task.FromResult(null); services.Devices.Dispose(); services.Devices = new SampleDeviceMonitor(); - services.Sync.RemoteFactory = (_, _, _) => sample._remote; + services.Sync.RemoteFactory = (_, _, _, _) => sample._remote; services.Sync.EditorFactory = (_, _, _) => sample._remote; // The schedules keep the sample's moment: nothing becomes due while the screenshots are taken. services.SchedulerTime = new FixedTime(Now); @@ -134,6 +134,16 @@ public sealed class SampleData settings.ProtectedToken = "sample-token"; settings.TrustedCertificates = [new TrustedCertificate { Fingerprint = ServerFingerprint, Server = "https://nas.local:8443", TrustedAt = new DateTimeOffset(2026, 9, 1, 9, 30, 0, TimeSpan.Zero) }]; settings.RecentServers = ["https://nas.local:8443"]; + // Settings › Server › Known servers (owner review 5): the sample's server, known by its id. + settings.KnownServers = + [ + new KnownServer + { + Id = Guid.Parse("5a3c1f0e-7d2b-4c8e-9f10-2b6d4e8a1c37"), Name = "Studio NAS", LastAddress = "https://nas.local:8443", Fingerprint = ServerFingerprint, + Aliases = [Chronos.Data.Sync.SyncService.ServerKey(new Uri("https://nas.local:8443"))], LastSeen = Now, + }, + ]; + _services.Sync.KnownServersChanged(); settings.RenderNodeOptIn = true; // The jobs sample shows a deep analysis that yielded to the render (owner review 1). settings.PriorityQueue = true; diff --git a/src/Chronos.App/Editor/ProjectFiles.cs b/src/Chronos.App/Editor/ProjectFiles.cs index e1436daa..49eb6313 100644 --- a/src/Chronos.App/Editor/ProjectFiles.cs +++ b/src/Chronos.App/Editor/ProjectFiles.cs @@ -74,7 +74,7 @@ public sealed class ProjectFiles(ShellViewModel shell) if (bundle.Workspace is { } workspace) { // A workspace's own working state opens as it is; a copy of one (saved elsewhere, another PC's) gives its project its settings. - var own = shell.Services.Workspace.Store.Find(workspace.ProjectId) is { } project + var own = shell.Services.Workspace.Find(workspace.ProjectId) is { } project && string.Equals(Path.GetFullPath(project.BundlePath), Path.GetFullPath(path), StringComparison.OrdinalIgnoreCase); await shell.Sequence.ShowAsync(sequence.Id, new ProjectRequest(sequence.Id, workspace.ProjectId), own ? null : editor => Apply(editor, bundle)); return; diff --git a/src/Chronos.App/Infrastructure/AppServices.cs b/src/Chronos.App/Infrastructure/AppServices.cs index d87a7c8d..c88ee52b 100644 --- a/src/Chronos.App/Infrastructure/AppServices.cs +++ b/src/Chronos.App/Infrastructure/AppServices.cs @@ -12,6 +12,7 @@ using Chronos.App.Workspace; using Chronos.Core.Archiving; using Chronos.Core.Diagnostics; using Chronos.Core.Export; +using Chronos.Core.IO; using Chronos.Core.Imaging; using Chronos.Core.Imaging.Decoders; using Chronos.Core.Model; @@ -21,6 +22,7 @@ using Chronos.Core.Windows.MediaFoundation; using Chronos.Core.Windows.Wic; using Chronos.Data; using Chronos.Data.Archiving; +using Chronos.Data.Homes; using Chronos.Data.Jobs; using Chronos.Data.Processing; using Chronos.Data.Scheduling; @@ -78,6 +80,8 @@ public sealed class AppServices : IAsyncDisposable Workspace = new WorkspaceHost(environment, settings, saveSettings, () => Database, () => Archives, () => Engine); // A server that keeps projects is the home of the workspace projects of its sequences (owner review 2, R8, phase 5b). Workspace.ServerHomes = Sync.ProjectHome; + // A server home's folder is named by its server's id, whichever address reached it (owner review 5, #66). + Workspace.Identity = () => Sync.Identity; Sync.ProjectChanged += Workspace.OnServerProjectChanged; Server = new ServerSession(settings, saveSettings, new ChronosServerApiFactory(), new DpapiTokenProtector()); Encoders = new MediaFoundationInventory(); @@ -151,6 +155,12 @@ public sealed class AppServices : IAsyncDisposable /// How the restore staged in Settings › Advanced went when the index opened; null when none was staged. public StagedRestoreResult? StagedRestore { get; private set; } + /// What the sorting of the folders into homes did when the index opened (owner review 5, #66); null when it had nothing to do. + public HomeLayoutResult? HomeLayout { get; private set; } + + /// Why the folders could not be sorted into homes when the index opened; null when they were, or had nothing to sort. + public Exception? HomeLayoutError { get; private 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(); @@ -201,7 +211,8 @@ public sealed class AppServices : IAsyncDisposable new(services.Processing?.Options ?? WorkspaceJobOptions.For(archives).Processing, () => services.Settings.PauseUploadsOnMetered && MeteredNetwork.IsMetered(), services.Workspace.MovedAsync, - () => services.Workspace.Root); + () => services.Workspace.Root, + services.Workspace.SameServer); /// /// Queues a scan of unless one is already waiting or running; the sequences it indexes get @@ -284,6 +295,8 @@ public sealed class AppServices : IAsyncDisposable _schedulerReady.TrySetResult(false); return; } + // Before any job runs: the folders of the workspace and the cache go to their homes (owner review 5, #66). + await SortHomesAsync(Database, ct); try { await StartJobsAsync(Database, startEngine: true, ct); @@ -474,6 +487,66 @@ public sealed class AppServices : IAsyncDisposable } } + /// + /// Sorts the workspace's projects and the cache's server folders into their homes (owner review 5, #66: + /// ; renames only, a clash to the trash, never deleted), or takes up a sorting a previous + /// start left half done. Projects in use or a workspace being moved wait for a later start; a failure is logged and kept + /// for Settings to tell (), and the start goes on: the folders not sorted read as before. + /// + private async Task SortHomesAsync(ChronosDatabase database, CancellationToken ct) + { + try + { + var migration = new HomeLayoutMigration(new HomeLayoutOptions + { + DataDirectory = Environment.DataDirectory, + WorkspaceRoot = Workspace.IsEnabled ? Workspace.Root : null, + CacheRoot = CacheStore.Folder(Environment, Settings), + Identity = Sync.Identity, + CurrentServer = Sync.LastServer, + Database = database, + }); + var result = await Task.Run(() => migration.ApplyAsync(ct), ct); + if (result != HomeLayoutResult.Nothing) + { + HomeLayout = result; + Log.Info("app", $"Folders sorted into homes: {result.ProjectsMoved} project(s), {result.EntriesMoved} entr(ies), {result.InUse} in use, " + + $"{result.Clashes} clash(es){(result.Deferred is { } deferred ? $", the workspace waits ({deferred})" : string.Empty)}"); + } + } + catch (Exception ex) when (ex is HomeLayoutException or IOException or UnauthorizedAccessException or InvalidDataException or DatabaseException) + { + HomeLayoutError = ex; + Log.Error("app", "The folders could not be sorted into homes; the next start tries again", ex); + } + finally + { + Workspace.Reopen(); + } + } + + /// + /// The scan schedule scanned this PC's archive (any thread): the archives of the servers' downloaded originals are scanned + /// after it (owner review 5, Q1: they are archives of their own, which the schedule, made for one archive, does not name). + /// + private void OnScheduledScanDone(Job job) + { + if (job is not { Kind: JobKind.Scan, State: JobState.Done, ScheduleId: not null, TargetIds: [var scanned] }) return; + _ = Task.Run(async () => + { + try + { + var archives = await Sync.OriginalsArchivesAsync(_stopping.Token).ConfigureAwait(false); + if (archives.Any(a => a.Id == scanned)) return; + foreach (var originals in archives) await QueueScanAsync(originals, full: false, _stopping.Token).ConfigureAwait(false); + } + catch (Exception ex) when (ex is DatabaseException or InvalidOperationException or OperationCanceledException) + { + Log.Warning("app", "The archives of the servers' originals could not be queued to be scanned", ex); + } + }); + } + private async Task StartJobsAsync(ChronosDatabase database, bool startEngine, CancellationToken ct) { _wic = new WicDecoderProvider(); @@ -508,6 +581,7 @@ public sealed class AppServices : IAsyncDisposable Engine = new JobEngine(database, handlers, new JobEngineOptions { WorkerId = WorkerId, Kinds = kinds, PriorityQueue = () => PriorityQueue }); // The workspace's size limit runs after each copy of media into it (phase 5c). Engine.JobChanged += Workspace.OnJobChanged; + Engine.JobChanged += OnScheduledScanDone; // Sync follows the engine's jobs before it runs any: a render resumed at start that finishes at once is still sent (Export "Sync"). Sync.Update(); // With no handler the engine must not run: an empty kind list would let workers claim (and fail) every job. @@ -554,7 +628,8 @@ public sealed class AppServices : IAsyncDisposable var node = new RenderNodeClient(client, processing.Options, new RenderNodeOptions { ClientName = System.Environment.MachineName, - CacheDirectory = Path.Combine(cache, "render-node"), + // Each server keeps its own downloads (owner review 5, #66: the render-node folder of its home in the cache). + CacheDirectory = Path.Combine(CacheStore.ServerFolder(cache, Sync.KeyOf(session.Address), Sync.Identity), HomeFolders.RenderNode), CacheLimitBytes = Settings.CacheLimitGb * (1L << 30), }); node.Start(); diff --git a/src/Chronos.App/Infrastructure/AppSettings.cs b/src/Chronos.App/Infrastructure/AppSettings.cs index f8abdfe0..0e41bd62 100644 --- a/src/Chronos.App/Infrastructure/AppSettings.cs +++ b/src/Chronos.App/Infrastructure/AppSettings.cs @@ -10,6 +10,7 @@ using Chronos.Core.Naming; using Chronos.Core.Project; using Chronos.Data.Archiving; using Chronos.Data.Repositories; +using Chronos.Data.Sync; using Chronos.Ui.Theming; namespace Chronos.App.Infrastructure; @@ -66,6 +67,27 @@ public sealed class TrustedCertificate public DateTimeOffset TrustedAt { get; set; } } +/// +/// A server this PC signed in to that announced its stable id (owner review 5, #66): its name and last address, the TLS +/// fingerprint it presented, the address keys it was reached under before (or besides) its id +/// (: projects, links and jobs made then still name them), the archive its +/// downloaded originals go to, and when it was last seen. Its folders (servers\<id> in the workspace and the +/// cache) are named by the id, never by the name. +/// +public sealed class KnownServer +{ + public Guid Id { get; set; } + public string? Name { get; set; } + public string? LastAddress { get; set; } + public string? Fingerprint { get; set; } + public List Aliases { get; set; } = []; + + /// The archive of this PC that holds the server's downloaded originals (owner review 5, Q1); null until the first download. + public Guid? OriginalsArchiveId { get; set; } + + public DateTimeOffset LastSeen { get; set; } +} + /// /// Per-user preferences (language, theme, window layout, archive defaults, server session). Kept in /// settings.json next to the database and written atomically, because language and theme apply before the @@ -257,6 +279,19 @@ public sealed class AppSettings public List TrustedCertificates { get; set; } = []; public List RecentServers { get; set; } = []; + /// + /// The servers known by their stable id and the address keys each was reached under (owner review 5, #66): a server's + /// projects, links and jobs stay its own whatever address it is reached by. This PC's state: Reset and Import keep it, + /// Export leaves it out. + /// + public List KnownServers { get; set; } = []; + + /// The alias table of , as the sync and the workspace compare server keys through it. + public ServerIdentity KnownIdentity() => new([.. KnownServers.Where(k => k.Id != Guid.Empty).Select(k => new KnownServerKey(k.Id, [.. k.Aliases]))]); + + /// The known server of ; null when this PC has none. + public KnownServer? FindKnownServer(Guid id) => KnownServers.FirstOrDefault(k => k.Id == id); + /// Let the server send render jobs to this PC (BRIEF §14.7). public bool RenderNodeOptIn { get; set; } @@ -377,6 +412,7 @@ public sealed class AppSettings ProtectedToken = ProtectedToken, TrustedCertificates = TrustedCertificates, RecentServers = RecentServers, + KnownServers = KnownServers, Window = Window, RailCollapsed = RailCollapsed, EditorGroups = EditorGroups, @@ -400,6 +436,7 @@ public sealed class AppSettings copy.WorkspaceFolder = null; copy.WorkspaceRecent = []; copy.WorkspaceOpened = []; + copy.KnownServers = []; return copy; } @@ -423,6 +460,7 @@ public sealed class AppSettings imported.WorkspaceFolder = WorkspaceFolder; imported.WorkspaceRecent = WorkspaceRecent; imported.WorkspaceOpened = WorkspaceOpened; + imported.KnownServers = KnownServers; return imported; } } diff --git a/src/Chronos.App/Infrastructure/DiagnosticsBundle.cs b/src/Chronos.App/Infrastructure/DiagnosticsBundle.cs index 35c54b61..ad08192c 100644 --- a/src/Chronos.App/Infrastructure/DiagnosticsBundle.cs +++ b/src/Chronos.App/Infrastructure/DiagnosticsBundle.cs @@ -5,10 +5,12 @@ using System.Text; using Chronos.App.Settings; using Chronos.Core.Diagnostics; using Chronos.Core.Export; +using Chronos.Core.IO; using Chronos.Core.Model; using Chronos.Core.Windows.Codecs; using Chronos.Data; using Chronos.Data.Sqlite; +using Chronos.Data.Sync; namespace Chronos.App.Infrastructure; @@ -34,8 +36,11 @@ public static class DiagnosticsBundle var settings = services.Settings.ToJson(); var tailBytes = AppLogging.DiagnosticsTailBytes(services.Settings); var report = Report(services.Environment, extraLines) + DatabaseLine(services.Database); + var workspace = services.Workspace; + var cache = CacheStore.Folder(services.Environment, services.Settings); return Task.Run(async () => { + report += HomesLines(workspace, cache); var failures = services.Database is { } db ? (await db.Jobs.ListAsync(JobState.Failed, FailedJobs, null, ct).ConfigureAwait(false)).Items : []; var codecs = Codecs(services.Encoders); var path = ExportNaming.Unique(folder, $"Chronos diagnostics {DateTime.Now.ToString("yyyy-MM-dd HHmm", CultureInfo.InvariantCulture)}", ".zip"); @@ -76,6 +81,33 @@ public static class DiagnosticsBundle return sb.ToString(); } + /// The homes' folders (owner review 5, #66): the workspace's, each with its projects, and the servers' in the cache. + private static string HomesLines(Chronos.App.Workspace.WorkspaceHost workspace, string cache) + { + var sb = new StringBuilder(); + try + { + if (workspace.IsEnabled && Directory.Exists(workspace.Root)) + { + var homes = workspace.Homes; + sb.AppendLine(CultureInfo.InvariantCulture, $"Workspace {homes.Root} ({(homes.IsSplit ? "homes" : "1.0 layout")})"); + foreach (var home in homes.Homes()) + sb.AppendLine(CultureInfo.InvariantCulture, $" {(home.IsLegacy ? "(parent)" : home.Folder)}: {home.Store.List().Count} project(s){(home.Server?.Name is { } name ? " · " + name : string.Empty)}"); + } + var servers = CacheStore.ServersFolder(cache); + if (Directory.Exists(servers)) + { + foreach (var folder in Directory.EnumerateDirectories(servers).Order(StringComparer.Ordinal)) + sb.AppendLine(CultureInfo.InvariantCulture, $"Cache home {Path.GetFileName(folder)}"); + } + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException) + { + sb.AppendLine("The homes could not be listed: " + ex.Message); + } + return sb.ToString(); + } + private static string DatabaseLine(ChronosDatabase? database) { if (database is null) return "Index not open\n"; @@ -135,6 +167,19 @@ public static class CacheStore public static string Folder(AppEnvironment environment, AppSettings settings) => string.IsNullOrWhiteSpace(settings.CacheFolder) ? environment.CacheDirectory : settings.CacheFolder!; + /// The servers' homes in the cache (<cache>\servers, owner review 5, #66). + public static string ServersFolder(string cache) => Path.Combine(cache, HomeFolders.Servers); + + /// + /// The home of server in the cache (<cache>\servers\<folder>, named by its + /// canonical key through ): its proxies, render-node downloads and staged imports. + /// + public static string ServerFolder(string cache, string serverKey, ServerIdentity identity) + { + ArgumentNullException.ThrowIfNull(identity); + return Path.Combine(ServersFolder(cache), identity.FolderName(serverKey)); + } + /// Creates the folder (if needed) and marks it as Chronos's. public static void Prepare(string folder) { diff --git a/src/Chronos.App/Jobs/DesktopScheduleHost.cs b/src/Chronos.App/Jobs/DesktopScheduleHost.cs index cf29b2f5..3a378ce3 100644 --- a/src/Chronos.App/Jobs/DesktopScheduleHost.cs +++ b/src/Chronos.App/Jobs/DesktopScheduleHost.cs @@ -84,7 +84,11 @@ public sealed class DesktopScheduleHost(AppSettings settings, Func GetArchiveAsync(CancellationToken cancellationToken) { if (database() is not { } db || archives() is not { } service) return null; - var archive = CurrentArchive.Pick(await db.Archives.ListAsync(cancellationToken).ConfigureAwait(false), settings.LastArchivePath); + var listed = await db.Archives.ListAsync(cancellationToken).ConfigureAwait(false); + // Never a server's originals archive in place of this PC's (owner review 5): the app scans those after this one. + var originals = settings.KnownServers.Select(k => k.OriginalsArchiveId).OfType().ToHashSet(); + var archive = (settings.LastArchivePath is { Length: > 0 } last ? CurrentArchive.At(listed, last) : null) + ?? CurrentArchive.Pick([.. listed.Where(a => !originals.Contains(a.Id))], null) ?? CurrentArchive.Pick(listed, null); if (archive is null || ArchiveService.GetAvailability(archive) == ArchiveAvailability.Offline) return null; try { @@ -110,14 +114,15 @@ public sealed class DesktopScheduleHost(AppSettings settings, Funccache-trim (owner review 2, R10): brings the cache folder down to Settings › Storage › /// Cache limit, oldest files first, skipping files in use (). The proxies of server sequences /// (complete sets the sync keeps), the render node's folder (it trims its own downloads to the same limit) and the copies an -/// import to the server stages are never trimmed; Settings › Storage › Clear still empties everything. +/// import to the server stages are never trimmed, in the former shared folders and in each server's own (servers, +/// owner review 5); Settings › Storage › Clear still empties everything. /// public sealed class CacheTrimStep(Func folder, Func limitBytes) : ICleanupStep { public const string StepName = "cache-trim"; /// Folders of the cache the trim leaves whole. - public static IReadOnlyList Kept { get; } = ["proxies", "render-node", "server-import"]; + public static IReadOnlyList Kept { get; } = ["proxies", "render-node", "server-import", Chronos.Core.IO.HomeFolders.Servers]; public string Name => StepName; diff --git a/src/Chronos.App/Library/LibraryActions.cs b/src/Chronos.App/Library/LibraryActions.cs index 6f99ff4d..a13f8711 100644 --- a/src/Chronos.App/Library/LibraryActions.cs +++ b/src/Chronos.App/Library/LibraryActions.cs @@ -117,11 +117,7 @@ public sealed class LibraryActions(ShellViewModel shell) await remote.Service.EnqueueSendExportsAsync(engine, remote.Server, selected.Sequence); return true; case SyncAction.DownloadOriginals when entry is not null: - if ((entry.Local?.ArchiveId ?? (await Services.Sync.CurrentArchiveAsync())?.Id) is not { } archive) - { - shell.Notify(Loc.L("Errors.Sync.NoArchive")); - return false; - } + if (await Services.Sync.OriginalsForDownloadAsync(entry.Local, (title, message, isError) => shell.Notify(title, message, isError: isError)) is not { } archive) return false; await remote.Service.EnqueueDownloadAsync(engine, remote.Server, entry.Id, entry.Title, SyncDownloadMode.Originals, archive); return true; case SyncAction.GetExports when entry is not null: diff --git a/src/Chronos.App/Sections/ImportViewModel.cs b/src/Chronos.App/Sections/ImportViewModel.cs index acd4a894..fc17cc81 100644 --- a/src/Chronos.App/Sections/ImportViewModel.cs +++ b/src/Chronos.App/Sections/ImportViewModel.cs @@ -989,7 +989,20 @@ public sealed class ImportViewModel : SectionViewModel /// What the signed-in user may still store on the server; null without a quota. private long? ServerSpace() => Services.Server.User is { QuotaBytes: > 0 } user ? System.Math.Max(0, user.QuotaBytes - user.UsedBytes) : null; - private string ServerStagingRoot => Path.Combine(CacheStore.Folder(Services.Environment, Services.Settings), "server-import"); + /// + /// Where an import to the server is staged before it is uploaded: the signed-in server's own folder of the cache + /// (servers\<id>\import, owner review 5); signed out, the cache's former shared folder. + /// + private string ServerStagingRoot + { + get + { + var cache = CacheStore.Folder(Services.Environment, Services.Settings); + return Services.Sync.Server is { } server + ? Path.Combine(CacheStore.ServerFolder(cache, server, Services.Sync.Identity), Chronos.Core.IO.HomeFolders.Import) + : Path.Combine(cache, Chronos.Data.Homes.HomeLayoutMigration.LegacyServerImport); + } + } private async Task PlanAsync() { diff --git a/src/Chronos.App/Sections/SequencePickerViewModel.cs b/src/Chronos.App/Sections/SequencePickerViewModel.cs index 8cb7db73..21fef618 100644 --- a/src/Chronos.App/Sections/SequencePickerViewModel.cs +++ b/src/Chronos.App/Sections/SequencePickerViewModel.cs @@ -189,7 +189,7 @@ public sealed class SequencePickerViewModel : LocalizedViewModel { var generation = _generation; foreach (var item in WorkspaceItems.Where(i => change.ProjectId is { } id ? i.ProjectId == id - : i.Entry.IsServerHome && string.Equals(i.Entry.Home.Server, change.Server, StringComparison.OrdinalIgnoreCase)).ToList()) + : i.Entry.IsServerHome && Shell.Services.Workspace.SameServer(i.Entry.Home.Server, change.Server)).ToList()) { if (generation != _generation) return; try diff --git a/src/Chronos.App/Sections/SequenceViewModel.cs b/src/Chronos.App/Sections/SequenceViewModel.cs index c6e7a8fb..e9987ec0 100644 --- a/src/Chronos.App/Sections/SequenceViewModel.cs +++ b/src/Chronos.App/Sections/SequenceViewModel.cs @@ -643,7 +643,7 @@ public sealed class SequenceViewModel : SectionViewModel { workspace.Remember(row.Id, entry.ProjectId); workspace.RecordOpened(entry.ProjectId); - return (new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine), row.DisplayTitle); + return (new WorkspaceSequenceSource(workspace.SyncOf(entry.ProjectId), entry.ProjectId, db, decoder, services.Engine), row.DisplayTitle); } var projectId = entry?.ProjectId ?? request?.ProjectId; string? newName = null; @@ -748,9 +748,9 @@ public sealed class SequenceViewModel : SectionViewModel // Its analyses and renders travel on a connection of the signed-in session, when that is the project's server: // made again whenever the sign-in changes, so a project opened signed out renders once signed in. var server = entry.Home.Server; - var editorHome = new WorkspaceServerHome(() => string.Equals(sync.Server, server, StringComparison.OrdinalIgnoreCase) ? sync.ConnectEditor() : null, + var editorHome = new WorkspaceServerHome(() => sync.Identity.Same(sync.Server, server) ? sync.ConnectEditor() : null, () => sync.Session); - return new ServerOpen((new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine, editorHome), entry.SequenceTitle)); + return new ServerOpen((new WorkspaceSequenceSource(workspace.SyncOf(entry.ProjectId), entry.ProjectId, db, decoder, services.Engine, editorHome), entry.SequenceTitle)); } // An account that may not edit checks nothing out: it is shown with proxies, read-only, as on an older server. if (!sync.Policy.CanEdit || sync.ServerHome(remoteId) is not { } home) return null; diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml index d1deb8e3..299d4d7d 100644 --- a/src/Chronos.App/Sections/SettingsView.xaml +++ b/src/Chronos.App/Sections/SettingsView.xaml @@ -563,6 +563,28 @@ Visibility="{Binding WorkspaceRows.HasUsageText, Converter={StaticResource BoolToVisibility}}" /> + + + + + + + + + + + + + +