merge: review2-p5a-fix-workspace into phase 5a fix round 1 integration

# Conflicts:
#	src/Chronos.Data/Workspaces/WorkspaceSync.cs
This commit is contained in:
Alby96 committed 2026-11-03 10:39:19 +01:00
commit 9772c2f934
18 files changed
+958 -93

No files matched your search

+26 -4
View File
@@ -2,10 +2,19 @@ using System.Globalization;
using System.Text;
using System.Text.Json;
using Chronos.Core.IO;
using Chronos.Core.Localization;
using Chronos.Core.Naming;
namespace Chronos.Core.Project;
/// <summary>A project file that would be larger than <see cref="ProjectBundle.MaxBytes"/>: refused before it is written, with a sentence for the user.</summary>
public sealed class ProjectTooLargeException(long bytes)
: IOException(Loc.L("Errors.Project.TooLarge", ProjectBundle.MaxBytes >> 20))
{
/// <summary>The size the file would have had.</summary>
public long Bytes { get; } = bytes;
}
/// <summary>The archive a project file's sequence lives in: its id, and its name and folder when the file was saved.</summary>
public sealed record BundleArchive(Guid Id, string Name, string? Path);
@@ -70,8 +79,12 @@ public sealed record ProjectBundle(BundleArchive Archive, BundleSequence Sequenc
/// <summary>The settings come from a newer Chronos (<see cref="ProjectSettings.IsNewerFormat"/>): show them, never edit them.</summary>
public bool IsReadOnly => Project.IsNewerFormat;
/// <summary>Project settings take a few kilobytes; a larger file is not a project file.</summary>
public const int MaxBytes = 4 << 20;
/// <summary>
/// The largest project file read or written, one limit for both: a workspace's working state parks every position by
/// photo until its media are copied (some 260 bytes each), so a 100,000-frame sequence with every frame excluded takes
/// some 26 MB; a larger file is not a project file.
/// </summary>
public const int MaxBytes = 64 << 20;
private static readonly JsonWriterOptions Indented = new() { Indented = true };
@@ -165,8 +178,17 @@ public sealed record ProjectBundle(BundleArchive Archive, BundleSequence Sequenc
return Parse(reader.ReadToEnd());
}
/// <summary>Writes the file atomically (temp, flush, rename): an interrupted save never leaves half a file.</summary>
public void Save(string path) => AtomicFile.WriteAllText(path, ToJson());
/// <summary>
/// Writes the file atomically (temp, flush, rename): an interrupted save never leaves half a file. A file larger than
/// <see cref="MaxBytes"/> is refused before anything is written, as no read could take it back.
/// </summary>
/// <exception cref="ProjectTooLargeException">The file would be larger than <see cref="MaxBytes"/>.</exception>
public void Save(string path)
{
var bytes = new UTF8Encoding(false).GetBytes(ToJson());
if (bytes.Length > MaxBytes) throw new ProjectTooLargeException(bytes.Length);
AtomicFile.WriteAllBytes(path, bytes);
}
/// <summary>
/// The settings to give the sequence when the file is opened, the sequence having <paramref name="frameCount"/>