diff --git a/i18n/en/Editor.resx b/i18n/en/Editor.resx
index 8c4cc113..f6a59fbb 100644
--- a/i18n/en/Editor.resx
+++ b/i18n/en/Editor.resx
@@ -184,6 +184,15 @@
This frame cannot be read.Vectorsoriginal | corrected
+ Project file applied
+ The project file’s settings were not applied.long
+ The sequence of this project file is not in the library.long
+ Retry
+ Save project file
+ Project file saved
+ Project file folder
+ Undo
+ This file is not a Titano project or cannot be read.longProxies not receivedGetting the proxiesAuto
diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx
index 71b9d485..7c28df55 100644
--- a/i18n/en/Tooltips.resx
+++ b/i18n/en/Tooltips.resx
@@ -210,6 +210,10 @@
Show or hide the shot dataOverlay the motion to the next frame measured by the engineDrag the line to compare · drag to pan · wheel zooms · double-click 1:1
+ Project files are for sequences in an archive on this PC
+ Apply the project file’s settings again
+ Save a .titano file that opens this sequence with these settings when double-clicked
+ Bring back the settings the sequence had before the file was opened · Ctrl+ZYour account can look at this server sequence but not change itEdited with proxies on this PC; changes are saved on {0} and analyses and renders run thereShown from {0}; your account can look at this sequence but not change it
diff --git a/i18n/it/Editor.it.resx b/i18n/it/Editor.it.resx
index b91e383a..1e8570ad 100644
--- a/i18n/it/Editor.it.resx
+++ b/i18n/it/Editor.it.resx
@@ -173,6 +173,15 @@
Questo fotogramma non si può leggere.Vettorioriginale | corretto
+ File di progetto applicato
+ Le impostazioni del file di progetto non sono state applicate.long
+ La sequenza di questo file di progetto non è nella libreria.long
+ Riprova
+ Salva file progetto
+ File di progetto salvato
+ Cartella file progetto
+ Annulla
+ Questo file non è un progetto Titano o non si può leggere.longProxy non ricevutiScaricamento dei proxyAuto
diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx
index acfb90d1..bfa8bc87 100644
--- a/i18n/it/Tooltips.it.resx
+++ b/i18n/it/Tooltips.it.resx
@@ -210,6 +210,10 @@
Mostra o nasconde i dati di scattoSovrappone il movimento verso il fotogramma successivo misurato dal motoreTrascina la linea per confrontare · trascina per spostare · la rotellina ingrandisce · doppio clic 1:1
+ I file di progetto sono per le sequenze di un archivio su questo PC
+ Applica di nuovo le impostazioni del file di progetto
+ Salva un file .titano che, con un doppio clic, apre questa sequenza con queste impostazioni
+ Ripristina le impostazioni che la sequenza aveva prima di aprire il file · Ctrl+ZIl tuo account può vedere questa sequenza del server ma non modificarlaModificata con i proxy su questo PC; le modifiche si salvano su {0} e analisi e render vengono eseguiti lìMostrata da {0}; il tuo account può vedere questa sequenza ma non modificarla
diff --git a/src/Titano.App/App.xaml.cs b/src/Titano.App/App.xaml.cs
index e9900ac1..842cc69b 100644
--- a/src/Titano.App/App.xaml.cs
+++ b/src/Titano.App/App.xaml.cs
@@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Threading;
using Titano.App.DesignTime;
+using Titano.App.Editor;
using Titano.App.Infrastructure;
using Titano.App.Shell;
using Titano.Core.Diagnostics;
@@ -12,11 +13,15 @@ namespace Titano.App;
///
/// Titano desktop client. Local mode starts here: settings and language before the first window, then the window,
/// then the index and the job engine () off the UI thread. --capture <dir>
-/// renders every screen with synthetic data in a throw-away data folder and exits.
+/// renders every screen with synthetic data in a throw-away data folder and exits. A file argument is a
+/// .titano project file (Explorer passes it on a double-click) opened once the index is open. One Titano runs
+/// per data folder: a second launch hands its file to the running one and exits ().
///
public partial class App : Application
{
+ private readonly TaskCompletionSource _started = new(TaskCreationOptions.RunContinuationsAsynchronously);
private FileLogSink? _log;
+ private SingleInstance? _instance;
public AppEnvironment Environment { get; private set; } = null!;
public AppSettings Settings { get; private set; } = null!;
@@ -36,6 +41,19 @@ public partial class App : Application
Log.SetSink(capture ? new TeeLogSink(_log, new StderrLogSink()) : _log);
Log.Info("app", $"Titano {AppServices.VersionText} starting; data at {Environment.DataDirectory}");
+ var projectFile = capture ? null : ProjectFileArgument(e.Args);
+ if (!capture)
+ {
+ _instance = SingleInstance.TryAcquire(Environment.DataDirectory);
+ if (_instance is null)
+ {
+ var handed = SingleInstance.HandOver(Environment.DataDirectory, projectFile is null ? [] : [projectFile]);
+ Log.Info("app", handed ? "Titano already runs on this data folder; arguments handed over" : "Titano already runs on this data folder");
+ Shutdown();
+ return;
+ }
+ }
+
Settings = capture ? new AppSettings { Language = "en" } : AppSettings.Load(Environment.SettingsPath);
UiLanguage.Apply(Settings.Language);
ThemeManager.Initialize(this, capture ? AppTheme.Dark : Settings.Theme);
@@ -65,11 +83,12 @@ public partial class App : Application
return;
}
window.Show();
- _ = StartAsync(shell);
+ _instance?.Listen(args => Dispatcher.BeginInvoke(() => OnHandOver(shell, args)));
+ _ = StartAsync(shell, projectFile);
}
- /// Opens the index and the job engine after the window is visible, then fills the screens.
- private async Task StartAsync(ShellViewModel shell)
+ /// Opens the index and the job engine after the window is visible, fills the screens, then opens the project file given.
+ private async Task StartAsync(ShellViewModel shell, string? projectFile)
{
try
{
@@ -80,10 +99,58 @@ public partial class App : Application
{
shell.ReportError(ex);
}
+ finally
+ {
+ _started.TrySetResult();
+ }
+ if (projectFile is not null) await OpenProjectFileAsync(shell, projectFile);
+ }
+
+ /// A later launch: its window comes to the front here, and its project file opens.
+ private void OnHandOver(ShellViewModel shell, IReadOnlyList args)
+ {
+ if (MainWindow is { } window)
+ {
+ window.Show();
+ if (window.WindowState == WindowState.Minimized) window.WindowState = WindowState.Normal;
+ window.Activate();
+ }
+ if (ProjectFileArgument(args) is { } projectFile) _ = OpenProjectFileAsync(shell, projectFile);
+ }
+
+ /// Opens a project file once the index is open; failures become the usual one-sentence toast.
+ private async Task OpenProjectFileAsync(ShellViewModel shell, string path)
+ {
+ await _started.Task;
+ try
+ {
+ await new ProjectFiles(shell).OpenAsync(path);
+ }
+ catch (Exception ex)
+ {
+ shell.ReportError(ex);
+ }
+ }
+
+ /// The first argument that is not an option, as a full path (the hand-over crosses working folders).
+ private static string? ProjectFileArgument(IReadOnlyList args)
+ {
+ if (args.FirstOrDefault(a => !a.StartsWith("--", StringComparison.Ordinal) && a.Length > 0) is not { } file) return null;
+ try
+ {
+ return System.IO.Path.GetFullPath(file);
+ }
+ catch (Exception ex) when (ex is ArgumentException or NotSupportedException or System.IO.PathTooLongException)
+ {
+ Log.Warning("app", $"Ignoring argument '{file}'", ex);
+ return null;
+ }
}
public void SaveSettings()
{
+ // A launch that handed over to the running Titano exits before loading any settings.
+ if (Settings is null) return;
try
{
Settings.Save(Environment.SettingsPath);
@@ -108,6 +175,7 @@ public partial class App : Application
{
Log.Warning("app", "Services stopped with an error", ex);
}
+ _instance?.Dispose();
Log.Info("app", "Titano exiting");
_log?.Dispose();
if (Environment.IsCapture) Environment.DeleteCaptureData();
diff --git a/src/Titano.App/Editor/EditorPanels.xaml b/src/Titano.App/Editor/EditorPanels.xaml
index f29069e1..bf1d3b5f 100644
--- a/src/Titano.App/Editor/EditorPanels.xaml
+++ b/src/Titano.App/Editor/EditorPanels.xaml
@@ -293,6 +293,9 @@
+
+
ShellActions.Reveal(Editor.Session.Content.Renders[0].OutputPath), () => CanReveal);
_restore = new AsyncRelayCommand(RestoreAsync, () => !Editor.IsLocked && SelectedCopy is not null);
+ SaveProjectCommand = new AsyncRelayCommand(() => new ProjectFiles(Editor.Shell).SaveAsync(Editor.Session), () => !Editor.IsRemote);
ResetFrameRateCommand = new RelayCommand(() => EditOverrides(o => o with { FrameRate = null }));
Width = new EditableField(string.Empty, ValidateSize, v => EditOverrides(o => o with { Width = ParseSize(v) }), () => Loc.L("Tooltips.Editor.Export.Width"));
Height = new EditableField(string.Empty, ValidateSize, v => EditOverrides(o => o with { Height = ParseSize(v) }), () => Loc.L("Tooltips.Editor.Export.Height"));
@@ -178,6 +179,14 @@ public sealed class ExportTab : EditorTab
/// The newest render is a file on this PC (a server's renders stay on the server).
public bool CanReveal => Editor.Session.Content.Renders is [{ OutputPath.Length: > 0 }, ..];
+ ///
+ /// Saves a .titano project file of this sequence and its settings (BRIEF §18); a server sequence has no
+ /// archive on this PC for the file to name.
+ ///
+ public ICommand SaveProjectCommand { get; }
+
+ public string SaveProjectToolTip => Editor.IsRemote ? Loc.L("Tooltips.Editor.ProjectFile.Remote") : Loc.L("Tooltips.Editor.ProjectFile.Save");
+
// ---- Export "Sync" (Export.html, next to Save to) ----
/// Send each render made on this PC to the server the sequence is linked to; remembered in the project.
diff --git a/src/Titano.App/Editor/ProjectFiles.cs b/src/Titano.App/Editor/ProjectFiles.cs
new file mode 100644
index 00000000..da170b8b
--- /dev/null
+++ b/src/Titano.App/Editor/ProjectFiles.cs
@@ -0,0 +1,92 @@
+using System.IO;
+using Titano.App.Infrastructure;
+using Titano.App.Shell;
+using Titano.Core.Diagnostics;
+using Titano.Core.Localization;
+using Titano.Core.Project;
+using Titano.Data.Processing;
+
+namespace Titano.App.Editor;
+
+///
+/// .titano project files (BRIEF §18): the editor saves one for the open sequence of this PC's archive, and
+/// opening one (a double-click, which Windows passes to Titano.exe) opens its sequence in the editor and gives it the
+/// file's settings as one undoable step.
+///
+public sealed class ProjectFiles(ShellViewModel shell)
+{
+ /// Asks for a folder and saves the session's sequence and current settings there; never replaces a file.
+ public async Task SaveAsync(EditorSession session)
+ {
+ if (session.IsRemote) return;
+ if (shell.Services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
+ if (shell.Services.Dialogs.PickFolder(Loc.L("Editor.ProjectFile.Title")) is not { } folder) return;
+ var bundle = await ProjectBundles.CreateAsync(db, session.Content.Sequence.Id, session.Project, session.Content.Count);
+ var path = await Task.Run(() =>
+ {
+ var free = ProjectBundle.FreePathIn(folder, bundle.Sequence.Title ?? session.Content.Sequence.DisplayTitle);
+ bundle.Save(free);
+ return free;
+ });
+ Log.Info("project", $"Project file '{path}' saved for sequence {bundle.Sequence.Id}");
+ shell.Notify(Loc.L("Editor.ProjectFile.Saved"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"),
+ () => ShellActions.Reveal(path));
+ }
+
+ ///
+ /// Opens the project file at : its sequence in the editor (found by id, else by archive and
+ /// folder), then the file's settings as one undo step. Says in one sentence why when the file cannot be read, its
+ /// sequence is not in the library, or the sequence cannot take the settings now.
+ ///
+ public async Task OpenAsync(string path)
+ {
+ ProjectBundle bundle;
+ try
+ {
+ bundle = await Task.Run(() => ProjectBundle.Load(path));
+ }
+ catch (Exception ex) when (ex is InvalidDataException or IOException or UnauthorizedAccessException)
+ {
+ Log.Warning("project", $"Project file '{path}' not opened", ex);
+ shell.Notify(Loc.L("Editor.ProjectFile.Unreadable"), Path.GetFileName(path), Loc.L("Common.OpenLogs"), Loc.L("Tooltips.Common.OpenLogs"),
+ () => ShellActions.Reveal(shell.Services.Environment.LogDirectory), isError: true);
+ return;
+ }
+ if (shell.Services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
+ if (await ProjectBundles.ResolveAsync(db, bundle) is not { } sequence)
+ {
+ Log.Info("project", $"Project file '{path}': sequence {bundle.Sequence.Id} ('{bundle.Sequence.Folder}' in archive {bundle.Archive.Id}) not in the index");
+ shell.Notify(Loc.L("Editor.ProjectFile.NotFound"), bundle.Sequence.Title ?? Path.GetFileName(path), Loc.L("Shell.Nav.Archive"),
+ Loc.L("Tooltips.Nav.Archive"), () => shell.Navigate(SectionKey.Archive), isError: true);
+ return;
+ }
+ // Not opened: the editor said why, or kept the open sequence's edit the user chose not to discard.
+ if (await shell.Sequence.ShowAsync(sequence.Id) is not { } editor) return;
+ Apply(editor, bundle);
+ }
+
+ /// Gives the open sequence the file's settings, unless the editor cannot change them now (a job runs, read-only).
+ private void Apply(EditorViewModel editor, ProjectBundle bundle)
+ {
+ var session = editor.Session;
+ var settings = bundle.ProjectFor(session.Project, session.Content.Count);
+ if (settings.ToJson() == session.Project.ToJson()) return;
+ if (editor.IsLocked)
+ {
+ shell.Notify(Loc.L("Editor.ProjectFile.Locked"), editor.LockedToolTip, Loc.L("Editor.ProjectFile.Retry"), Loc.L("Tooltips.Editor.ProjectFile.Retry"),
+ () =>
+ {
+ // Still the same editor: the file's settings, laid over the project as it is then.
+ if (ReferenceEquals(shell.Sequence.Editor, editor)) Apply(editor, bundle);
+ }, isError: true);
+ return;
+ }
+ var before = session.Project;
+ if (!session.Edit(_ => settings)) return;
+ session.EndEditRun();
+ var restore = new ProjectRestore(session, before, session.Project);
+ Log.Info("project", $"Project file settings applied to sequence {session.Content.Sequence.Id}");
+ shell.Notify(Loc.L("Editor.ProjectFile.Applied"), session.Content.Sequence.DisplayTitle, Loc.L("Editor.ProjectFile.Undo"),
+ Loc.L("Tooltips.Editor.ProjectFile.Undo"), () => restore.Undo());
+ }
+}
diff --git a/src/Titano.App/Infrastructure/SingleInstance.cs b/src/Titano.App/Infrastructure/SingleInstance.cs
new file mode 100644
index 00000000..c689c60b
--- /dev/null
+++ b/src/Titano.App/Infrastructure/SingleInstance.cs
@@ -0,0 +1,126 @@
+using System.Diagnostics;
+using System.IO;
+using System.IO.Pipes;
+using System.Runtime.InteropServices;
+using System.Security.Cryptography;
+using System.Text;
+using Titano.Core.Diagnostics;
+
+namespace Titano.App.Infrastructure;
+
+///
+/// One Titano per data folder in a Windows session (two would share one index and job engine): a named mutex marks
+/// the running instance, and a later launch (a double-clicked .titano file, the Start menu) hands its file
+/// arguments over a named pipe (current user only), lets the running window come to the front and exits. Same
+/// protocol as the Uploader's, kept per program so neither depends on the other.
+///
+public sealed partial class SingleInstance : IDisposable
+{
+ private const string Header = "TITANO/1";
+ private const int MaxMessageBytes = 1 << 20;
+ private const int AnyProcess = -1;
+
+ private readonly Mutex _mutex;
+ private readonly string _pipeName;
+ private readonly CancellationTokenSource _stop = new();
+
+ private SingleInstance(Mutex mutex, string pipeName)
+ {
+ _mutex = mutex;
+ _pipeName = pipeName;
+ }
+
+ /// The instance guard for , or null when another Titano already uses it in this session.
+ public static SingleInstance? TryAcquire(string dataDirectory)
+ {
+ var mutex = new Mutex(initiallyOwned: true, @"Local\Titano.App." + Key(dataDirectory), out var createdNew);
+ if (createdNew) return new SingleInstance(mutex, PipeName(dataDirectory));
+ mutex.Dispose();
+ return null;
+ }
+
+ ///
+ /// Sends (absolute paths; empty = just show the window) to the Titano running on
+ /// ; false when it could not be reached.
+ ///
+ public static bool HandOver(string dataDirectory, IReadOnlyList args)
+ {
+ // This launch came from the user, so it may give the running window the right to come to the front.
+ AllowSetForegroundWindow(AnyProcess);
+ try
+ {
+ using var pipe = new NamedPipeClientStream(".", PipeName(dataDirectory), PipeDirection.Out, PipeOptions.CurrentUserOnly);
+ pipe.Connect(3000);
+ pipe.Write(Encode(args));
+ pipe.Flush();
+ return true;
+ }
+ catch (Exception ex) when (ex is IOException or TimeoutException or UnauthorizedAccessException)
+ {
+ Log.Warning("instance", "Could not reach the running Titano", ex);
+ return false;
+ }
+ }
+
+ /// Receives messages from later launches; runs on a pool thread.
+ public void Listen(Action> received) => _ = ListenAsync(_pipeName, received, _stop.Token);
+
+ public void Dispose()
+ {
+ _stop.Cancel();
+ _mutex.ReleaseMutex();
+ _mutex.Dispose();
+ _stop.Dispose();
+ }
+
+ /// UTF-8: a header line, then one argument per line (paths cannot contain line breaks).
+ public static byte[] Encode(IReadOnlyList args) =>
+ Encoding.UTF8.GetBytes(Header + "\n" + string.Join("\n", args.Where(a => !a.Contains('\n', StringComparison.Ordinal))));
+
+ /// Arguments of a message, or null when it is not one of ours.
+ public static IReadOnlyList? Decode(ReadOnlySpan message)
+ {
+ if (message.Length > MaxMessageBytes) return null;
+ var lines = Encoding.UTF8.GetString(message).Split('\n');
+ if (lines[0] != Header) return null;
+ return [.. lines.Skip(1).Where(l => l.Length > 0)];
+ }
+
+ /// The data folder's identity (case-insensitive, as Windows paths are): a portable copy has its own instance.
+ private static string Key(string dataDirectory) =>
+ Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(Path.GetFullPath(dataDirectory).TrimEnd('\\', '/').ToUpperInvariant())))[..16];
+
+ private static string PipeName(string dataDirectory)
+ {
+ using var process = Process.GetCurrentProcess();
+ return $"Titano.App.{process.SessionId}.{Environment.UserName}.{Key(dataDirectory)}";
+ }
+
+ private static async Task ListenAsync(string pipeName, Action> received, CancellationToken ct)
+ {
+ while (!ct.IsCancellationRequested)
+ {
+ try
+ {
+ await using var pipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte,
+ PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly);
+ await pipe.WaitForConnectionAsync(ct).ConfigureAwait(false);
+ using var buffer = new MemoryStream();
+ await pipe.CopyToAsync(buffer, ct).ConfigureAwait(false);
+ if (Decode(buffer.GetBuffer().AsSpan(0, (int)buffer.Length)) is { } args) received(args);
+ }
+ catch (OperationCanceledException)
+ {
+ return;
+ }
+ catch (IOException ex)
+ {
+ Log.Warning("instance", "Hand-over pipe failed; listening again", ex);
+ }
+ }
+ }
+
+ [LibraryImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static partial bool AllowSetForegroundWindow(int processId);
+}
diff --git a/src/Titano.App/Sections/SequenceViewModel.cs b/src/Titano.App/Sections/SequenceViewModel.cs
index 63fb5fc4..8e7f1393 100644
--- a/src/Titano.App/Sections/SequenceViewModel.cs
+++ b/src/Titano.App/Sections/SequenceViewModel.cs
@@ -75,6 +75,20 @@ public sealed class SequenceViewModel : SectionViewModel
return _switch;
}
+ ///
+ /// Shows in the editor, as the Library does, and returns its editor once open; null
+ /// when it did not open (the reason was reported, or the open sequence's unsaved edit was kept) or waits for its
+ /// proxies.
+ ///
+ public async Task ShowAsync(Guid sequenceId)
+ {
+ Shell.OpenSequence(sequenceId);
+ // Already chosen and shown but not open (an earlier open failed): opening it again is what is asked now.
+ if (_openId != sequenceId && _switch.IsCompleted) _ = OpenAsync(sequenceId);
+ await Settled(_switch);
+ return _openId == sequenceId ? Editor : null;
+ }
+
///
/// Fetches the proxies of server sequence into this PC's cache (a download job, shown in
/// the job bar and on the Jobs screen) and opens it in the editor once they are here, if it is still the sequence
diff --git a/src/Titano.Core/Project/ProjectBundle.cs b/src/Titano.Core/Project/ProjectBundle.cs
new file mode 100644
index 00000000..bbbf34c8
--- /dev/null
+++ b/src/Titano.Core/Project/ProjectBundle.cs
@@ -0,0 +1,167 @@
+using System.Globalization;
+using System.Text;
+using System.Text.Json;
+using Titano.Core.IO;
+using Titano.Core.Naming;
+
+namespace Titano.Core.Project;
+
+/// The archive a project file's sequence lives in: its id, and its name and folder when the file was saved.
+public sealed record BundleArchive(Guid Id, string Name, string? Path);
+
+/// The sequence a project file applies to: its id, folder (relative to the archive), title and frame count when saved.
+public sealed record BundleSequence(Guid Id, string Folder, string? Title, int Frames);
+
+///
+/// A .titano project file (BRIEF §18, file associations): which sequence of which archive, and the project
+/// settings to open it with. The photos stay in the archive; opening the file opens that sequence in the editor with
+/// these settings. UTF-8 JSON with a format name and version, so a newer file is refused rather than misread:
+/// { "format": "titano-project", "formatVersion": 1, "saved": …, "archive": { "id", "name", "path" },
+/// "sequence": { "id", "folder", "title", "frames" }, "project": { …project.json… } }
+///
+public sealed record ProjectBundle(BundleArchive Archive, BundleSequence Sequence, ProjectSettings Project, DateTimeOffset Saved)
+{
+ public const string Extension = ".titano";
+ public const string FormatName = "titano-project";
+ public const int CurrentFormatVersion = 1;
+
+ /// Project settings take a few kilobytes; a larger file is not a project file.
+ public const int MaxBytes = 4 << 20;
+
+ private static readonly JsonWriterOptions Indented = new() { Indented = true };
+
+ public string ToJson()
+ {
+ using var buffer = new MemoryStream();
+ using (var w = new Utf8JsonWriter(buffer, Indented))
+ {
+ w.WriteStartObject();
+ w.WriteString("format", FormatName);
+ w.WriteNumber("formatVersion", CurrentFormatVersion);
+ w.WriteString("saved", Saved);
+ w.WriteStartObject("archive");
+ w.WriteString("id", Archive.Id);
+ w.WriteString("name", Archive.Name);
+ if (Archive.Path is not null) w.WriteString("path", Archive.Path);
+ w.WriteEndObject();
+ w.WriteStartObject("sequence");
+ w.WriteString("id", Sequence.Id);
+ w.WriteString("folder", Sequence.Folder);
+ if (Sequence.Title is not null) w.WriteString("title", Sequence.Title);
+ w.WriteNumber("frames", Sequence.Frames);
+ w.WriteEndObject();
+ w.WritePropertyName("project");
+ // The project as project.json holds it, so both are read by the same tolerant reader.
+ using (var project = JsonDocument.Parse(Project.ToJson())) project.RootElement.WriteTo(w);
+ w.WriteEndObject();
+ }
+ return Encoding.UTF8.GetString(buffer.GetBuffer(), 0, (int)buffer.Length);
+ }
+
+ /// Reads a project file's text.
+ /// Not a Titano project file, damaged, or written by a newer Titano.
+ public static ProjectBundle Parse(string json)
+ {
+ JsonDocument document;
+ try
+ {
+ document = JsonDocument.Parse(json, new JsonDocumentOptions { MaxDepth = 64 });
+ }
+ catch (JsonException ex)
+ {
+ throw new InvalidDataException("The project file is not valid JSON.", ex);
+ }
+ using (document)
+ {
+ var root = document.RootElement;
+ if (root.ValueKind != JsonValueKind.Object || Text(root, "format") != FormatName) throw new InvalidDataException("Not a Titano project file.");
+ if (!root.TryGetProperty("formatVersion", out var v) || v.ValueKind != JsonValueKind.Number || !v.TryGetInt32(out var version) || version < 1)
+ throw new InvalidDataException("The project file has no valid format version.");
+ if (version > CurrentFormatVersion) throw new InvalidDataException($"The project file uses format {version}, newer than this Titano ({CurrentFormatVersion}).");
+
+ var archive = Section(root, "archive");
+ var sequence = Section(root, "sequence");
+ var folder = Text(sequence, "folder");
+ if (string.IsNullOrWhiteSpace(folder)) throw new InvalidDataException("The project file names no sequence folder.");
+ var frames = sequence.TryGetProperty("frames", out var f) && f.ValueKind == JsonValueKind.Number && f.TryGetInt32(out var count) && count >= 0 ? count : 0;
+ if (!root.TryGetProperty("project", out var project) || project.ValueKind != JsonValueKind.Object)
+ throw new InvalidDataException("The project file holds no project settings.");
+ ProjectSettings settings;
+ try
+ {
+ settings = ProjectSettings.FromJson(project.GetRawText());
+ }
+ catch (JsonException ex)
+ {
+ throw new InvalidDataException("The project settings in the file cannot be read.", ex);
+ }
+ var saved = root.TryGetProperty("saved", out var s) && s.ValueKind == JsonValueKind.String && s.TryGetDateTimeOffset(out var when) ? when : default;
+ return new ProjectBundle(
+ new BundleArchive(Id(archive), Text(archive, "name") ?? string.Empty, Text(archive, "path")),
+ new BundleSequence(Id(sequence), folder, Text(sequence, "title"), frames),
+ settings,
+ saved);
+ }
+ }
+
+ /// Reads a project file.
+ /// Not a Titano project file (or too large to be one), damaged, or newer.
+ /// The file cannot be read.
+ public static ProjectBundle Load(string path)
+ {
+ using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
+ if (stream.Length > MaxBytes) throw new InvalidDataException("The file is too large to be a Titano project file.");
+ using var reader = new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
+ return Parse(reader.ReadToEnd());
+ }
+
+ /// Writes the file atomically (temp, flush, rename): an interrupted save never leaves half a file.
+ public void Save(string path) => AtomicFile.WriteAllText(path, ToJson());
+
+ ///
+ /// The settings to give the sequence when the file is opened, the sequence having
+ /// frames and settings: the file's settings, except the frame positions (exclusions,
+ /// hero frame, camera keyframes) when frames were added or removed since the file was saved, as they would now
+ /// point at other frames; the sequence keeps its own.
+ ///
+ public ProjectSettings ProjectFor(ProjectSettings current, int frameCount) => frameCount == Sequence.Frames
+ ? Project
+ : Project with
+ {
+ ExcludedFrames = current.ExcludedFrames,
+ HeroFrame = current.HeroFrame,
+ Camera = Project.Camera with { Keyframes = current.Camera.Keyframes },
+ };
+
+ /// A file name for the project of a sequence titled , valid on every file system.
+ public static string FileNameFor(string title) =>
+ (PathTemplate.SanitizeSegment(title) is { Length: > 0 } name ? name : "Titano") + Extension;
+
+ ///
+ /// A path in for the project of that names no existing file
+ /// ("Harbour sunset.titano", then "Harbour sunset (2).titano"…): saving never replaces an earlier project file.
+ ///
+ public static string FreePathIn(string folder, string title)
+ {
+ var name = Path.GetFileNameWithoutExtension(FileNameFor(title));
+ var path = Path.Combine(folder, name + Extension);
+ for (var n = 2; File.Exists(path) || Directory.Exists(path); n++)
+ path = Path.Combine(folder, string.Create(CultureInfo.InvariantCulture, $"{name} ({n}){Extension}"));
+ return path;
+ }
+
+ private static JsonElement Section(JsonElement root, string name)
+ {
+ if (!root.TryGetProperty(name, out var section) || section.ValueKind != JsonValueKind.Object)
+ throw new InvalidDataException($"The project file has no '{name}' section.");
+ return section;
+ }
+
+ private static Guid Id(JsonElement section) =>
+ section.TryGetProperty("id", out var id) && id.ValueKind == JsonValueKind.String && id.TryGetGuid(out var guid) && guid != Guid.Empty
+ ? guid
+ : throw new InvalidDataException("The project file has a missing or invalid id.");
+
+ private static string? Text(JsonElement section, string name) =>
+ section.TryGetProperty(name, out var value) && value.ValueKind == JsonValueKind.String ? value.GetString() : null;
+}
diff --git a/src/Titano.Data/Processing/ProjectBundles.cs b/src/Titano.Data/Processing/ProjectBundles.cs
new file mode 100644
index 00000000..f339b0ca
--- /dev/null
+++ b/src/Titano.Data/Processing/ProjectBundles.cs
@@ -0,0 +1,42 @@
+using Titano.Core.Model;
+using Titano.Core.Project;
+
+namespace Titano.Data.Processing;
+
+///
+/// .titano project files (BRIEF §18) against this index: the file for a sequence of one of its archives, and
+/// the sequence a file names.
+///
+public static class ProjectBundles
+{
+ ///
+ /// The project file of with (the editor's current
+ /// settings), whose frame positions refer to frames.
+ ///
+ /// The sequence is not in the index.
+ public static async Task CreateAsync(TitanoDatabase db, Guid sequenceId, ProjectSettings project, int frames,
+ CancellationToken cancellationToken = default)
+ {
+ var sequence = await db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false)
+ ?? throw new InvalidOperationException($"Sequence {sequenceId} is not in the index.");
+ var archive = await db.Archives.GetAsync(sequence.ArchiveId, cancellationToken).ConfigureAwait(false);
+ return new ProjectBundle(
+ new BundleArchive(sequence.ArchiveId, archive?.Name ?? string.Empty, archive?.RootPath),
+ new BundleSequence(sequence.Id, sequence.Folder, sequence.DisplayTitle, frames),
+ project,
+ DateTimeOffset.UtcNow);
+ }
+
+ ///
+ /// The sequence names: by its id, else the sequence in the same folder of the same
+ /// archive (an index rebuilt elsewhere, or a folder adopted again, gives it a new id). Null when this index has
+ /// neither: the archive is not added here, or the sequence was deleted.
+ ///
+ public static async Task ResolveAsync(TitanoDatabase db, ProjectBundle bundle, CancellationToken cancellationToken = default)
+ {
+ if (await db.Sequences.GetAsync(bundle.Sequence.Id, cancellationToken).ConfigureAwait(false) is { } byId) return byId;
+ var locations = await db.Sequences.ListLocationsAsync(bundle.Archive.Id, cancellationToken).ConfigureAwait(false);
+ var match = locations.FirstOrDefault(l => string.Equals(l.Folder, bundle.Sequence.Folder, StringComparison.OrdinalIgnoreCase));
+ return match is null ? null : await db.Sequences.GetAsync(match.Id, cancellationToken).ConfigureAwait(false);
+ }
+}
diff --git a/tests/Titano.App.Tests/Editor/ProjectFilesTests.cs b/tests/Titano.App.Tests/Editor/ProjectFilesTests.cs
new file mode 100644
index 00000000..b6d32728
--- /dev/null
+++ b/tests/Titano.App.Tests/Editor/ProjectFilesTests.cs
@@ -0,0 +1,157 @@
+using System.IO;
+using System.Windows;
+using Titano.App.DesignTime;
+using Titano.App.Editor;
+using Titano.App.Infrastructure;
+using Titano.App.Shell;
+using Titano.App.Tests.Windows;
+using Titano.Core.Localization;
+using Titano.Core.Project;
+using Titano.Testing;
+using Titano.Ui.Controls;
+using Titano.Ui.Theming;
+
+namespace Titano.App.Tests.Editor;
+
+///
+/// .titano project files (BRIEF §18) in the real main window on the editor sample: the editor saves one, and
+/// opening one shows its sequence with the file's settings as one undo step, or says in one sentence why not.
+///
+[WindowsOnly]
+[Serial]
+[Timeout(300_000)]
+public sealed class ProjectFilesTests(TestContext context)
+{
+ [Test]
+ public Task AProjectFileSavesAndOpensItsSequenceWithItsSettings() => ScreenHost.RunAsync(async () =>
+ {
+ var folder = context.CreateTempDirectory("project-files");
+ var environment = AppEnvironment.ForCapture();
+ UiLanguage.Apply("en");
+ ThemeManager.Apply(AppTheme.Dark);
+ var services = new AppServices(environment, new AppSettings { Language = "en", FirstRunCompleted = true }, () => { }, new FolderDialogs(folder));
+ var sample = SampleData.Configure(services);
+ var shell = new ShellViewModel(services);
+ var toasts = new List();
+ shell.PendingToasts.CollectionChanged += (_, e) => toasts.AddRange(e.NewItems?.OfType() ?? []);
+ var window = new MainWindow(shell)
+ {
+ WindowStartupLocation = WindowStartupLocation.Manual,
+ Left = -20000,
+ Top = -20000,
+ Width = 1200,
+ Height = 788,
+ ShowActivated = false,
+ ShowInTaskbar = false,
+ };
+ window.Show();
+ try
+ {
+ await sample.OpenEmptyAsync();
+ await shell.StartAsync();
+ var id = await sample.FillEditorAsync();
+ var files = new ProjectFiles(shell);
+
+ // Saved under the sequence's title, never over an earlier file.
+ var editor = Assert.NotNull(await shell.Sequence.ShowAsync(id));
+ await files.SaveAsync(editor.Session);
+ await files.SaveAsync(editor.Session);
+ var path = Path.Combine(folder, "Harbour sunset.titano");
+ Assert.FileExists(path);
+ Assert.FileExists(Path.Combine(folder, "Harbour sunset (2).titano"));
+ Assert.Equal(Loc.L("Editor.ProjectFile.Saved"), toasts[^1].Title);
+ var bundle = ProjectBundle.Load(path);
+ Assert.Equal(id, bundle.Sequence.Id);
+ Assert.Equal(editor.FrameCount, bundle.Sequence.Frames);
+ Assert.Equal(editor.Session.Project.ToJson(), bundle.Project.ToJson());
+
+ // Opening it with other settings shows the sequence with them, as one step Undo takes back.
+ var before = editor.Session.Project;
+ bundle.ExposureOffset(0.7).Save(path);
+ await files.OpenAsync(path);
+ Assert.Same(editor, shell.Sequence.Editor);
+ Assert.Equal(0.7, editor.Session.Project.Exposure.ExposureOffsetEv);
+ var applied = toasts[^1];
+ Assert.Equal(Loc.L("Editor.ProjectFile.Applied"), applied.Title);
+ Assert.False(applied.IsError);
+ applied.ActionCommand!.Execute(null);
+ Assert.Equal(before.ToJson(), editor.Session.Project.ToJson());
+
+ // A sequence this library does not have, and a file that is not a project: one sentence each.
+ var elsewhere = bundle with
+ {
+ Archive = bundle.Archive with { Id = Guid.CreateVersion7() },
+ Sequence = bundle.Sequence with { Id = Guid.CreateVersion7(), Folder = "2026/elsewhere" },
+ };
+ var missing = Path.Combine(folder, "Elsewhere.titano");
+ elsewhere.Save(missing);
+ await files.OpenAsync(missing);
+ Assert.Equal(Loc.L("Editor.ProjectFile.NotFound"), toasts[^1].Title);
+ Assert.True(toasts[^1].IsError);
+
+ var text = Path.Combine(folder, "notes.titano");
+ await File.WriteAllTextAsync(text, "not a project");
+ await files.OpenAsync(text);
+ Assert.Equal(Loc.L("Editor.ProjectFile.Unreadable"), toasts[^1].Title);
+ Assert.True(toasts[^1].IsError);
+ Assert.Same(editor, shell.Sequence.Editor, "the open sequence stays");
+ await editor.Session.FlushAsync();
+ }
+ finally
+ {
+ window.Close();
+ await shell.Sequence.CloseAsync();
+ shell.Dispose();
+ await services.DisposeAsync();
+ environment.DeleteCaptureData();
+ }
+ });
+
+ [Test]
+ public void AHandOverMessageRoundTrips()
+ {
+ string[] args = [@"C:\Users\me\Desktop\Harbour sunset.titano"];
+ Assert.SequenceEqual(args, SingleInstance.Decode(SingleInstance.Encode(args))!);
+ Assert.Empty(SingleInstance.Decode(SingleInstance.Encode([]))!);
+ Assert.Null(SingleInstance.Decode("TITANO-UPLOADER/1\nE:\\"u8));
+ }
+
+ [Test]
+ public void ASecondLaunchOnTheSameDataFolderHandsItsFileToTheFirst()
+ {
+ var data = context.CreateTempDirectory("instance");
+ var first = Assert.NotNull(SingleInstance.TryAcquire(data));
+ try
+ {
+ var received = new TaskCompletionSource>(TaskCreationOptions.RunContinuationsAsynchronously);
+ first.Listen(args => received.TrySetResult(args));
+ Assert.Null(SingleInstance.TryAcquire(data), "one Titano per data folder");
+ using (var other = SingleInstance.TryAcquire(context.CreateTempDirectory("other-copy")))
+ Assert.NotNull(other, "a portable copy with its own data folder runs on its own");
+
+ Assert.True(SingleInstance.HandOver(data, [@"D:\Projects\Roof.titano"]));
+ Assert.True(received.Task.Wait(TimeSpan.FromSeconds(10)), "the running instance received the hand-over");
+ Assert.SequenceEqual([@"D:\Projects\Roof.titano"], received.Task.Result);
+ }
+ finally
+ {
+ first.Dispose();
+ }
+ }
+
+ /// Dialogs that pick one folder and cancel everything else.
+ private sealed class FolderDialogs(string folder) : IAppDialogs
+ {
+ public string? PickFolder(string title, string? initialFolder = null) => folder;
+ public string? PickJsonFile(string title) => null;
+ public bool Confirm(ConfirmRequest request) => false;
+ public bool SignIn(string server, string? username, Func> signIn) => false;
+ }
+}
+
+internal static class ProjectBundleTestExtensions
+{
+ /// The same file with another exposure offset.
+ public static ProjectBundle ExposureOffset(this ProjectBundle bundle, double ev) =>
+ bundle with { Project = bundle.Project with { Exposure = bundle.Project.Exposure with { ExposureOffsetEv = ev } } };
+}
diff --git a/tests/Titano.Core.Tests/Project/ProjectBundleTests.cs b/tests/Titano.Core.Tests/Project/ProjectBundleTests.cs
new file mode 100644
index 00000000..d7a6fe9f
--- /dev/null
+++ b/tests/Titano.Core.Tests/Project/ProjectBundleTests.cs
@@ -0,0 +1,104 @@
+using Titano.Core.Project;
+using Titano.Testing;
+
+namespace Titano.Core.Tests.Project;
+
+/// The .titano project file (BRIEF §18): a sequence reference plus the settings to open it with.
+public sealed class ProjectBundleTests(TestContext context)
+{
+ private static readonly Guid ArchiveId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01");
+ private static readonly Guid SequenceId = Guid.Parse("0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a02");
+
+ [Test]
+ public void ARoundTripKeepsTheReferenceAndTheSettings()
+ {
+ var bundle = Sample();
+ var path = Path.Combine(context.CreateTempDirectory("bundle"), ProjectBundle.FileNameFor("Harbour sunset"));
+ bundle.Save(path);
+
+ var back = ProjectBundle.Load(path);
+ Assert.Equal(bundle.Archive, back.Archive);
+ Assert.Equal(bundle.Sequence, back.Sequence);
+ Assert.Equal(bundle.Saved, back.Saved);
+ Assert.Equal(bundle.Project.ToJson(), back.Project.ToJson());
+ Assert.Equal(0.8, back.Project.Exposure.DeflickerStrength.Resolve(1.0));
+ Assert.SequenceEqual([3, 7], back.Project.ExcludedFrames);
+
+ var json = File.ReadAllText(path);
+ Assert.Contains("\"format\": \"titano-project\"", json);
+ Assert.Contains("\"formatVersion\": 1", json);
+ }
+
+ [Test]
+ public void OtherFilesAreRefusedAsNotProjectFiles()
+ {
+ Assert.Throws(() => ProjectBundle.Parse("not json"));
+ Assert.Throws(() => ProjectBundle.Parse("[1, 2]"));
+ // The archive's own meta files are JSON too, but not project files.
+ Assert.Throws(() => ProjectBundle.Parse("""{ "schemaVersion": 1, "id": "0192a4c1-7b3e-7cc0-8a51-2f9d0e6b1a01" }"""));
+ var json = Sample().ToJson();
+ Assert.Throws(() => ProjectBundle.Parse(json.Replace("\"formatVersion\": 1", "\"formatVersion\": 2", StringComparison.Ordinal)));
+ Assert.Throws(() => ProjectBundle.Parse(json.Replace(SequenceId.ToString(), "not-a-guid", StringComparison.Ordinal)));
+ Assert.Throws(() => ProjectBundle.Parse(json.Replace("\"version\": 1", "\"version\": 99", StringComparison.Ordinal)));
+ Assert.Throws(() => ProjectBundle.Parse(json.Replace("\"folder\"", "\"place\"", StringComparison.Ordinal)));
+ }
+
+ [Test]
+ public void AFileTooLargeToBeAProjectIsNotRead()
+ {
+ var path = Path.Combine(context.CreateTempDirectory("bundle"), "huge.titano");
+ using (var stream = File.Create(path)) stream.SetLength(ProjectBundle.MaxBytes + 1L);
+ Assert.Throws(() => ProjectBundle.Load(path));
+ }
+
+ [Test]
+ public void FramePositionsApplyOnlyToTheFramesTheyWereSavedFor()
+ {
+ var bundle = Sample();
+ var current = new ProjectSettings
+ {
+ ExcludedFrames = [1],
+ HeroFrame = 2,
+ Camera = new CameraSettings { Keyframes = [new CameraKey(0, 0.5, 0.5, 1, 0)] },
+ };
+
+ Assert.Same(bundle.Project, bundle.ProjectFor(current, frameCount: 3600));
+
+ var changed = bundle.ProjectFor(current, frameCount: 3610);
+ Assert.SequenceEqual([1], changed.ExcludedFrames);
+ Assert.Equal(2, changed.HeroFrame);
+ Assert.Same(current.Camera.Keyframes, changed.Camera.Keyframes);
+ // Everything else comes from the file.
+ Assert.Equal(0.8, changed.Exposure.DeflickerStrength.Resolve(1.0));
+ Assert.Equal(bundle.Project.Camera.Crop, changed.Camera.Crop);
+ }
+
+ [Theory]
+ [Case("Harbour sunset", "Harbour sunset.titano")]
+ [Case("Roof: 12/03 \"storm\"?", "Roof_ 12_03 _storm__.titano")]
+ [Case("CON", "_CON.titano")]
+ [Case(" ", "Titano.titano")]
+ public void TheFileNameComesFromTheTitle(string title, string expected) => Assert.Equal(expected, ProjectBundle.FileNameFor(title));
+
+ [Test]
+ public void SavingNeverReplacesAnEarlierProjectFile()
+ {
+ var folder = context.CreateTempDirectory("bundle");
+ Assert.Equal(Path.Combine(folder, "Harbour sunset.titano"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
+ File.WriteAllText(Path.Combine(folder, "Harbour sunset.titano"), "{}");
+ Directory.CreateDirectory(Path.Combine(folder, "Harbour sunset (2).titano"));
+ Assert.Equal(Path.Combine(folder, "Harbour sunset (3).titano"), ProjectBundle.FreePathIn(folder, "Harbour sunset"));
+ }
+
+ private static ProjectBundle Sample() => new(
+ new BundleArchive(ArchiveId, "Main archive", @"D:\Timelapse"),
+ new BundleSequence(SequenceId, "2026/2026-09-28 Harbour sunset", "Harbour sunset", 3600),
+ new ProjectSettings
+ {
+ Exposure = new ExposureSettings { DeflickerStrength = new Auto().WithManual(0.8) },
+ Camera = new CameraSettings { Crop = [0.1, 0.1, 0.9, 0.9], Keyframes = [new CameraKey(120, 0.4, 0.5, 1.2, 0)] },
+ ExcludedFrames = [3, 7],
+ HeroFrame = 1800,
+ },
+ new DateTimeOffset(2026, 10, 12, 9, 30, 0, TimeSpan.Zero));
+}
diff --git a/tests/Titano.Data.Tests/Processing/ProjectBundlesTests.cs b/tests/Titano.Data.Tests/Processing/ProjectBundlesTests.cs
new file mode 100644
index 00000000..32308b56
--- /dev/null
+++ b/tests/Titano.Data.Tests/Processing/ProjectBundlesTests.cs
@@ -0,0 +1,65 @@
+using Titano.Core.Project;
+using Titano.Data.Processing;
+using Titano.Data.Tests.Infrastructure;
+using Titano.Testing;
+
+namespace Titano.Data.Tests.Processing;
+
+/// A .titano project file names a sequence of this index, found again by id or by its folder (BRIEF §18).
+public abstract class ProjectBundlesTests(TestContext context) : RepositoryTest(context)
+{
+ [Test]
+ public async Task TheFileNamesTheSequenceAndItsArchive()
+ {
+ var db = await OpenTitanoAsync();
+ var archive = TestData.Archive("Main");
+ await db.Archives.UpsertAsync(archive, Ct);
+ var sequence = TestData.Sequence(archive.Id, title: "Harbour sunset");
+ await db.Sequences.UpsertAsync(sequence, Ct);
+ var project = new ProjectSettings { ExcludedFrames = [2] };
+
+ var bundle = await ProjectBundles.CreateAsync(db, sequence.Id, project, frames: 120, Ct);
+
+ Assert.Equal(new BundleArchive(archive.Id, "Main", archive.RootPath), bundle.Archive);
+ Assert.Equal(new BundleSequence(sequence.Id, sequence.Folder, "Harbour sunset", 120), bundle.Sequence);
+ Assert.Same(project, bundle.Project);
+ Assert.Equal(sequence.Id, (await ProjectBundles.ResolveAsync(db, ProjectBundle.Parse(bundle.ToJson()), Ct))!.Id);
+ await Assert.ThrowsAsync(() => ProjectBundles.CreateAsync(db, Guid.CreateVersion7(), project, 0, Ct));
+ }
+
+ [Test]
+ public async Task ASequenceWithANewIdIsFoundByItsFolderInTheSameArchive()
+ {
+ var db = await OpenTitanoAsync();
+ var archive = TestData.Archive("Main");
+ var other = TestData.Archive("Other");
+ await db.Archives.UpsertAsync(archive, Ct);
+ await db.Archives.UpsertAsync(other, Ct);
+ var adoptedAgain = TestData.Sequence(archive.Id) with { Folder = "2026/2026-09-28 Harbour" };
+ var elsewhere = TestData.Sequence(other.Id) with { Folder = "2026/2026-09-28 Roof" };
+ await db.Sequences.UpsertAsync(adoptedAgain, Ct);
+ await db.Sequences.UpsertAsync(elsewhere, Ct);
+
+ var bundle = Bundle(archive.Id, Guid.CreateVersion7(), "2026/2026-09-28 HARBOUR");
+ Assert.Equal(adoptedAgain.Id, (await ProjectBundles.ResolveAsync(db, bundle, Ct))!.Id);
+
+ // A folder of another archive, an unknown folder or an archive this index does not have: not found.
+ Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(archive.Id, Guid.CreateVersion7(), "2026/2026-09-28 Roof"), Ct));
+ Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(archive.Id, Guid.CreateVersion7(), "2025/missing"), Ct));
+ Assert.Null(await ProjectBundles.ResolveAsync(db, Bundle(Guid.CreateVersion7(), Guid.CreateVersion7(), "2026/2026-09-28 Harbour"), Ct));
+ }
+
+ private static ProjectBundle Bundle(Guid archiveId, Guid sequenceId, string folder) =>
+ new(new BundleArchive(archiveId, "Main", null), new BundleSequence(sequenceId, folder, "Harbour", 10), new ProjectSettings(), TestData.Now);
+}
+
+public sealed class SqliteProjectBundlesTests(TestContext context) : ProjectBundlesTests(context)
+{
+ protected override Backend Backend => Backend.SqliteMemory;
+}
+
+[RequiresEnvironment(PgTestServer.Variable)]
+public sealed class PostgresProjectBundlesTests(TestContext context) : ProjectBundlesTests(context)
+{
+ protected override Backend Backend => Backend.Postgres;
+}