Merge branch 'review2-p5a-fix2-desktop' into review2-p5a-int2

# Conflicts:
#	i18n/en/Editor.resx
#	i18n/en/Tooltips.resx
#	i18n/it/Tooltips.it.resx
#	src/Chronos.Data/Workspaces/WorkspaceSync.cs
#	tests/Chronos.Data.Tests/Workspaces/WorkspaceRecoveryTests.cs
This commit is contained in:
Alby96 committed 2026-11-03 12:15:27 +01:00
commit 47c660735f
30 files changed
+1021 -110

No files matched your search

@@ -35,6 +35,20 @@ public static class WorkspaceJobs
/// parameters name).
/// </summary>
public static IReadOnlyList<IJobHandler> CreateHandlers(ChronosDatabase db, ArchiveService archives) => [new WorkspaceCopyJobHandler(db, archives)];
/// <summary>
/// What a first copy of a sequence's proxies writes into a workspace, as the copy reckons it before it starts (the
/// archive's proxies' sizes, an estimate for those it makes), and the free bytes on <paramref name="workspaceRoot"/>'s
/// drive (null when it cannot be measured): "Open in workspace" shows both. The copy keeps <see cref="CopySpaceReserve"/>
/// free besides.
/// </summary>
/// <exception cref="InvalidOperationException">The index has no such sequence or archive.</exception>
public static Task<(long Bytes, long? Free)> CopyFactsAsync(ChronosDatabase db, ArchiveService archives, Guid sequenceId, string workspaceRoot,
CancellationToken cancellationToken = default) =>
new WorkspaceCopyJobHandler(db, archives).FactsAsync(sequenceId, workspaceRoot, cancellationToken);
/// <summary>Bytes the copy leaves free on the workspace's drive besides what it copies.</summary>
public static long CopySpaceReserve => WorkspaceCopyJobHandler.SpaceReserve;
}
/// <summary>
@@ -62,7 +76,7 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
private static readonly TimeSpan CheckpointEvery = TimeSpan.FromSeconds(5);
/// <summary>Bytes left free on the workspace's drive besides the copy, as a download keeps (<see cref="SyncTransfers"/>).</summary>
private const long SpaceReserve = 512L << 20;
internal const long SpaceReserve = 512L << 20;
/// <summary>A proxy at <see cref="ProxyEstimateEdge"/> px, when the archive has none to measure: some 1.5 MB.</summary>
private const long ProxyEstimate = 3L << 19;
@@ -364,11 +378,13 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
/// nothing for a frame the workspace holds a file of already (kept, or replaced by one of about its size), the archive's
/// proxy's size where it has one, else an estimate at the proxy size the copy makes (<see cref="Estimate"/>).
/// </summary>
private static long[] Remaining(WorkspaceProject project, SequencePaths folder, List<Frame> frames, ProxyPolicy policy)
{
var held = Directory.Exists(project.ProxiesDirectory)
private static long[] Remaining(WorkspaceProject project, SequencePaths folder, List<Frame> frames, ProxyPolicy policy) =>
Remaining(Directory.Exists(project.ProxiesDirectory)
? Directory.EnumerateFiles(project.ProxiesDirectory).Select(Path.GetFileName).ToHashSet(StringComparer.OrdinalIgnoreCase)
: [];
: [], folder, frames, policy);
private static long[] Remaining(HashSet<string?> held, SequencePaths folder, List<Frame> frames, ProxyPolicy policy)
{
var proxies = Directory.Exists(folder.Proxies)
? new DirectoryInfo(folder.Proxies).EnumerateFiles().ToDictionary(f => f.Name, f => f.Length, StringComparer.OrdinalIgnoreCase)
: [];
@@ -385,6 +401,17 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
return remaining;
}
/// <summary>What a first copy of the sequence writes (nothing held yet), and the free bytes of the workspace's drive.</summary>
internal async Task<(long Bytes, long? Free)> FactsAsync(Guid sequenceId, string workspaceRoot, CancellationToken cancellationToken)
{
var (row, frames) = await FramesAsync(sequenceId, cancellationToken).ConfigureAwait(false);
var archive = await db.Archives.GetAsync(row.ArchiveId, cancellationToken).ConfigureAwait(false)
?? throw new InvalidOperationException(Loc.L("Archive.Log.SequenceMissing", sequenceId));
var paths = new ArchivePaths(archive.RootPath);
var policy = ManifestStore.ReadArchive(paths.ManifestPath).ProxyPolicy;
return (Remaining([], paths.Sequence(row.Folder), frames, policy)[0], FreeBytes(workspaceRoot));
}
/// <summary>A proxy's size when the archive has none to measure: some 1.5 MB at 1920 px, scaled by the area at the copy's long edge.</summary>
private static long Estimate(Frame frame, ProxyPolicy policy)
{