feat(workspace): lay the phase 5c foundation
Phase 5c (owner review 2, R8) is built by six packages in parallel. This commit settles everything they share, so each one touches its own files: - job kinds WorkspaceRender (21), WorkspaceSend (22) and WorkspaceMove (23) with their wire names, default priorities, notices and parameter records; their handlers are registered as skeletons that throw until their package lands - WorkspaceJobOptions and a new CreateHandlers overload; the earlier ones stay and default the options - originals in the media index (an index of phase 5b reads as proxies only), their file names, and the exports/renders.json ledger of local renders, written atomically - the optional project and version of an uploaded render - the workspace settings (size limit, default media, version on render, clean-up age, project to open) and when each project was opened, which Reset and Import keep and Export leaves out - WorkspaceHost split into partial files, with stubs for usage, trash and the folder move, removal hooks for unsent renders and last originals, and a guard that holds work while the workspace moves - every new string of the phase in English and Italian, with tooltips Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
102f28b5df
commit
2e1c67f531
43 files changed
+1725
-128
No files matched your search
@@ -178,15 +178,27 @@ public sealed class AppServices : IAsyncDisposable
|
||||
typeof(AppServices).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0";
|
||||
|
||||
/// <summary>The job handlers of this PC's engine — the single registration list; a kind without a handler stays
|
||||
/// queued (it is never claimed here). The workspace copy is the desktop's alone: it writes into this PC's workspace, from
|
||||
/// this PC's archive or, through the signed-in session, from a server.</summary>
|
||||
/// queued (it is never claimed here). The workspace's jobs are the desktop's alone: they write into this PC's workspace
|
||||
/// (a copy from this PC's archive or, through the signed-in session, from a server; a local render with this PC's
|
||||
/// encoders; the sending of its renders home; the move of its folder, which Settings › Workspace then names).</summary>
|
||||
public static IReadOnlyList<IJobHandler> CreateJobHandlers(AppServices services) =>
|
||||
[
|
||||
.. services.Archives?.CreateJobHandlers() ?? [], .. services.Processing?.CreateJobHandlers() ?? [],
|
||||
.. services.Sync.Service?.CreateJobHandlers(services.Sync) ?? [],
|
||||
.. services.Database is { } db && services.Archives is { } archives ? WorkspaceJobs.CreateHandlers(db, archives, services.Sync) : [],
|
||||
.. services.Database is { } db && services.Archives is { } archives
|
||||
? WorkspaceJobs.CreateHandlers(db, archives, services.Sync, WorkspaceOptions(services, archives))
|
||||
: [],
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The workspace jobs' share of the desktop (phase 5c): its processing options for local renders, the metered hold of
|
||||
/// Settings › Server over transfers with a server, and the workspace that follows a moved folder.
|
||||
/// </summary>
|
||||
private static WorkspaceJobOptions WorkspaceOptions(AppServices services, ArchiveService archives) =>
|
||||
new(services.Processing?.Options ?? WorkspaceJobOptions.For(archives).Processing,
|
||||
() => services.Settings.PauseUploadsOnMetered && MeteredNetwork.IsMetered(),
|
||||
services.Workspace.MovedAsync);
|
||||
|
||||
/// <summary>
|
||||
/// Queues a scan of <paramref name="archive"/> unless one is already waiting or running; the sequences it indexes get
|
||||
/// a background deep analysis when Settings › Analysis asks for it.
|
||||
|
||||
@@ -7,6 +7,7 @@ using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Naming;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Ui.Theming;
|
||||
@@ -39,6 +40,21 @@ public enum HardwarePreference
|
||||
HardwareForPreviews,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Which project Edit opens for a sequence that has several in the workspace (Settings › Workspace › Open project, phase 5c).
|
||||
/// </summary>
|
||||
public enum WorkspaceOpenPolicy
|
||||
{
|
||||
/// <summary>The project opened last for the sequence (<see cref="AppSettings.WorkspaceRecent"/>), else the one saved last.</summary>
|
||||
LastUsed,
|
||||
|
||||
/// <summary>The sequence's Main project.</summary>
|
||||
Main,
|
||||
|
||||
/// <summary>Ask each time, listing the sequence's projects.</summary>
|
||||
Ask,
|
||||
}
|
||||
|
||||
/// <summary>A server certificate the user trusted on first use (BRIEF §12.7).</summary>
|
||||
public sealed class TrustedCertificate
|
||||
{
|
||||
@@ -58,6 +74,8 @@ public sealed class AppSettings
|
||||
public const int DefaultCacheLimitGb = 20;
|
||||
public const int DefaultScanIntervalMinutes = 10;
|
||||
public const int DefaultWorkspaceKeptVersions = 20;
|
||||
public const int DefaultWorkspaceSizeLimitGb = 100;
|
||||
public const int DefaultWorkspaceCleanAfterDays = 30;
|
||||
|
||||
/// <summary>2⁻⁴ of white: the deep analysis' night threshold (a mean log2 luminance of −4).</summary>
|
||||
public const double DefaultNightBrightnessPercent = 6.25;
|
||||
@@ -169,6 +187,36 @@ public sealed class AppSettings
|
||||
/// <summary>The workspace project opened last for each sequence (sequence id → project id); Edit opens it again.</summary>
|
||||
public Dictionary<Guid, Guid> WorkspaceRecent { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Phase 5c: past this size (GB of 2³⁰ bytes) the workspace's clean-up removes the media of the projects used longest ago
|
||||
/// that are in step with their home (never one open, with jobs, or with renders not sent); 0 = no limit.
|
||||
/// </summary>
|
||||
public int WorkspaceSizeLimitGb { get; set; } = DefaultWorkspaceSizeLimitGb;
|
||||
|
||||
/// <summary>
|
||||
/// What "Open in workspace" copies unless chosen otherwise: <see cref="BundleMedia.Proxies"/> or
|
||||
/// <see cref="BundleMedia.Originals"/> (the proxies plus the originals, to render on this PC).
|
||||
/// </summary>
|
||||
public string WorkspaceDefaultMedia { get; set; } = BundleMedia.Proxies;
|
||||
|
||||
/// <summary>A render of a project with changes not saved as a version saves one first (and sends it when Sync automatically is on).</summary>
|
||||
public bool WorkspaceVersionOnRender { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The workspace's clean-up removes the media of a project not opened for this many days, once it is in step with its
|
||||
/// home; 0 = never.
|
||||
/// </summary>
|
||||
public int WorkspaceCleanAfterDays { get; set; } = DefaultWorkspaceCleanAfterDays;
|
||||
|
||||
/// <summary>Which project Edit opens for a sequence with several in the workspace.</summary>
|
||||
public WorkspaceOpenPolicy WorkspaceOpenProject { get; set; } = WorkspaceOpenPolicy.LastUsed;
|
||||
|
||||
/// <summary>
|
||||
/// When each workspace project was last opened in Edit (project id → time), which the clean-up goes by (else the time
|
||||
/// its working state was saved). This PC's, like <see cref="WorkspaceRecent"/>.
|
||||
/// </summary>
|
||||
public Dictionary<Guid, DateTimeOffset> WorkspaceOpened { get; set; } = [];
|
||||
|
||||
// ---- Server ----
|
||||
public string? ServerUrl { get; set; }
|
||||
public string? ServerUsername { get; set; }
|
||||
@@ -285,6 +333,64 @@ public sealed class AppSettings
|
||||
|
||||
/// <summary>A deep copy (JSON round trip), used for import and reset.</summary>
|
||||
public AppSettings Clone() => Parse(ToJson()) ?? new AppSettings();
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Advanced › Reset: every default, but the values that are this PC's or this user's state rather than
|
||||
/// preferences: the archive and the session, the window and its rail, the sequence edited last, the first-run flag, the
|
||||
/// jobs cleared, and the workspace (its folder, moved only by its own operation, the projects opened last and when).
|
||||
/// </summary>
|
||||
public AppSettings ResetKeepingState() => new()
|
||||
{
|
||||
LastArchivePath = LastArchivePath,
|
||||
ServerUrl = ServerUrl,
|
||||
ServerUsername = ServerUsername,
|
||||
ProtectedToken = ProtectedToken,
|
||||
TrustedCertificates = TrustedCertificates,
|
||||
RecentServers = RecentServers,
|
||||
Window = Window,
|
||||
RailCollapsed = RailCollapsed,
|
||||
LastEditedSequence = LastEditedSequence,
|
||||
FirstRunCompleted = FirstRunCompleted,
|
||||
JobsClearedAt = JobsClearedAt,
|
||||
WorkspaceFolder = WorkspaceFolder,
|
||||
WorkspaceRecent = WorkspaceRecent,
|
||||
WorkspaceOpened = WorkspaceOpened,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Export: a copy without secrets and machine-bound values (the session, the window, the workspace's folder and
|
||||
/// what it remembers of its projects: another PC's ids mean nothing there).
|
||||
/// </summary>
|
||||
public AppSettings ForExport()
|
||||
{
|
||||
var copy = Clone();
|
||||
copy.ProtectedToken = null;
|
||||
copy.Window = null;
|
||||
copy.WorkspaceFolder = null;
|
||||
copy.WorkspaceRecent = [];
|
||||
copy.WorkspaceOpened = [];
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Import: <paramref name="imported"/> with this PC's own values taken from these settings: the session, the
|
||||
/// window and its rail, the sequence edited last, the first-run flag, and the workspace (its folder, the projects opened
|
||||
/// last and when). Changes and returns <paramref name="imported"/>.
|
||||
/// </summary>
|
||||
public AppSettings KeepLocalIn(AppSettings imported)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(imported);
|
||||
imported.ProtectedToken = ProtectedToken;
|
||||
imported.ServerUrl = ServerUrl;
|
||||
imported.Window = Window;
|
||||
imported.RailCollapsed = RailCollapsed;
|
||||
imported.LastEditedSequence = LastEditedSequence;
|
||||
imported.FirstRunCompleted = FirstRunCompleted;
|
||||
imported.WorkspaceFolder = WorkspaceFolder;
|
||||
imported.WorkspaceRecent = WorkspaceRecent;
|
||||
imported.WorkspaceOpened = WorkspaceOpened;
|
||||
return imported;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, UseStringEnumConverter = true)]
|
||||
|
||||
@@ -40,7 +40,8 @@ public static class JobNotices
|
||||
|
||||
private static bool Announces(JobKind kind) =>
|
||||
kind is JobKind.Render or JobKind.DeepAnalyse or JobKind.Verify or JobKind.Rebuild or JobKind.Maintenance or JobKind.UploadCommit
|
||||
or JobKind.Move or JobKind.Adopt or JobKind.EmptyTrash or JobKind.Convert;
|
||||
or JobKind.Move or JobKind.Adopt or JobKind.EmptyTrash or JobKind.Convert or JobKind.WorkspaceRender or JobKind.WorkspaceSend
|
||||
or JobKind.WorkspaceMove;
|
||||
|
||||
/// <summary>
|
||||
/// Work that keeps the index and its previews current: the next run repeats it, the Archive screen shows what is missing.
|
||||
|
||||
@@ -12,7 +12,7 @@ public static class JobText
|
||||
|
||||
/// <summary>True for jobs whose items are frames, so their speed reads in fps.</summary>
|
||||
public static bool CountsFrames(JobKind kind) =>
|
||||
kind is JobKind.Render or JobKind.Proxies or JobKind.Thumbs or JobKind.DeepAnalyse;
|
||||
kind is JobKind.Render or JobKind.Proxies or JobKind.Thumbs or JobKind.DeepAnalyse or JobKind.WorkspaceRender;
|
||||
|
||||
/// <summary>True for jobs whose progress counts bytes (hash verification, card import).</summary>
|
||||
public static bool CountsBytes(JobKind kind) => kind is JobKind.Verify or JobKind.Import;
|
||||
|
||||
@@ -1207,7 +1207,8 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
[
|
||||
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
|
||||
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
|
||||
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert, JobKind.WorkspaceCopy,
|
||||
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert, JobKind.WorkspaceCopy, JobKind.WorkspaceRender, JobKind.WorkspaceSend,
|
||||
JobKind.WorkspaceMove,
|
||||
];
|
||||
|
||||
/// <summary>Stores <paramref name="level"/> for <paramref name="kind"/>, keeping only the levels that differ from the defaults.</summary>
|
||||
@@ -1632,23 +1633,8 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
IsDestructive = true,
|
||||
});
|
||||
if (!confirmed) return;
|
||||
var defaults = new AppSettings
|
||||
{
|
||||
LastArchivePath = _s.LastArchivePath,
|
||||
ServerUrl = _s.ServerUrl,
|
||||
ServerUsername = _s.ServerUsername,
|
||||
ProtectedToken = _s.ProtectedToken,
|
||||
TrustedCertificates = _s.TrustedCertificates,
|
||||
RecentServers = _s.RecentServers,
|
||||
Window = _s.Window,
|
||||
RailCollapsed = _s.RailCollapsed,
|
||||
LastEditedSequence = _s.LastEditedSequence,
|
||||
FirstRunCompleted = _s.FirstRunCompleted,
|
||||
JobsClearedAt = _s.JobsClearedAt,
|
||||
// The workspace holds this PC's work: its folder stays where it is (moving it is its own operation).
|
||||
WorkspaceFolder = _s.WorkspaceFolder,
|
||||
WorkspaceRecent = _s.WorkspaceRecent,
|
||||
};
|
||||
// The workspace holds this PC's work: its folder stays where it is (moving it is its own operation).
|
||||
var defaults = _s.ResetKeepingState();
|
||||
// Start with Windows lives in the registry, not in the settings file: its default is off.
|
||||
Startup.SetEnabled(false);
|
||||
ApplyAll(defaults);
|
||||
@@ -1690,12 +1676,8 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
{
|
||||
var folder = Shell.Services.Dialogs.PickFolder(Loc.L("Settings.Export.Title"));
|
||||
if (folder is null) return;
|
||||
var copy = _s.Clone();
|
||||
// Secrets and machine-bound values stay on this PC.
|
||||
copy.ProtectedToken = null;
|
||||
copy.Window = null;
|
||||
copy.WorkspaceFolder = null;
|
||||
copy.WorkspaceRecent = [];
|
||||
var copy = _s.ForExport();
|
||||
var path = Path.Combine(folder, $"Chronos settings {DateTime.Now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}.json");
|
||||
await Task.Run(() => AtomicFile.WriteAllText(path, copy.ToJson()));
|
||||
Shell.Notify(Loc.L("Settings.Export.Done"), Path.GetFileName(path), Loc.L("Library.Export.Show"), Loc.L("Tooltips.Library.ShowExport"), () => ShellActions.Reveal(path));
|
||||
@@ -1720,18 +1702,9 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
Shell.Notify(Loc.L("Errors.Settings.Import"), isError: true);
|
||||
return;
|
||||
}
|
||||
// Everything but the session, the window and its rail, the sequence edited last (another PC's ids mean nothing here)
|
||||
// and the first-run flag.
|
||||
imported.ProtectedToken = _s.ProtectedToken;
|
||||
imported.ServerUrl = _s.ServerUrl;
|
||||
imported.Window = _s.Window;
|
||||
imported.RailCollapsed = _s.RailCollapsed;
|
||||
imported.LastEditedSequence = _s.LastEditedSequence;
|
||||
imported.FirstRunCompleted = _s.FirstRunCompleted;
|
||||
// The workspace is this PC's: its folder and the projects opened last stay.
|
||||
imported.WorkspaceFolder = _s.WorkspaceFolder;
|
||||
imported.WorkspaceRecent = _s.WorkspaceRecent;
|
||||
ApplyAll(imported);
|
||||
// Everything but the session, the window and its rail, the sequence edited last (another PC's ids mean nothing here),
|
||||
// the first-run flag and the workspace, which is this PC's (its folder, the projects opened last and when).
|
||||
ApplyAll(_s.KeepLocalIn(imported));
|
||||
// Settings of a PC never rewrite the shared archive.json: the imported templates and sizes are the defaults of new
|
||||
// archives, and the rows show the own settings of the archive at the (possibly imported) archive folder.
|
||||
_retarget = RetargetArchiveAsync();
|
||||
|
||||
@@ -66,6 +66,31 @@ public static class WorkspaceFolderChange
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Workspace › Move… (phase 5c): the shell's flow over <see cref="MoveAsync(WorkspaceHost, IAppDialogs, Func{Task{bool}}, Action{string})"/>,
|
||||
/// with its folder picker, confirmation, editor and toasts. True when the move was queued.
|
||||
/// </summary>
|
||||
public static Task<bool> MoveAsync(ShellViewModel shell)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shell);
|
||||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Picks the folder the workspace moves to through <paramref name="dialogs"/>, shows its plan
|
||||
/// (<see cref="WorkspaceHost.PlanMoveAsync"/>) and asks for the user's word, lets <paramref name="closeProject"/> close a
|
||||
/// workspace project open in the editor (false keeps everything as it is), then queues the move
|
||||
/// (<see cref="WorkspaceHost.QueueMoveAsync"/>). <paramref name="failed"/> hears why it was refused. True when it was queued.
|
||||
/// </summary>
|
||||
public static Task<bool> MoveAsync(WorkspaceHost host, IAppDialogs dialogs, Func<Task<bool>> closeProject, Action<string> failed)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(host);
|
||||
ArgumentNullException.ThrowIfNull(dialogs);
|
||||
ArgumentNullException.ThrowIfNull(closeProject);
|
||||
ArgumentNullException.ThrowIfNull(failed);
|
||||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||||
}
|
||||
|
||||
/// <summary>The plan as a confirmation: where Edit's projects come from now, and what stays where it is.</summary>
|
||||
public static ConfirmRequest Request(WorkspaceFolderPlan plan)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.IO;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Workspaces;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// What the workspace takes of its drive (Settings › Workspace, phase 5c): the projects' media (proxies and originals, which
|
||||
/// the clean-up and the size limit may remove), the whole folder, and its trash (<see cref="WorkspaceHost.TrashFolder"/>).
|
||||
/// </summary>
|
||||
/// <param name="MediaBytes">The bytes of every project's <c>media/</c> folder.</param>
|
||||
/// <param name="TotalBytes">The bytes of the whole workspace folder, its trash included.</param>
|
||||
/// <param name="TrashBytes">The bytes of the workspace's trash.</param>
|
||||
/// <param name="TrashItems">The entries of the workspace's trash (one per copy removed or originals set aside).</param>
|
||||
public sealed record WorkspaceUsage(long MediaBytes, long TotalBytes, long TrashBytes, int TrashItems)
|
||||
{
|
||||
/// <summary>A workspace that holds nothing.</summary>
|
||||
public static WorkspaceUsage None { get; } = new(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/// <summary>One entry of the workspace's trash as Empty… lists it: its folder name, size, files and when it was put there.</summary>
|
||||
public sealed record WorkspaceTrashItem(string Name, long Bytes, int Files, DateTimeOffset Trashed);
|
||||
|
||||
/// <summary>
|
||||
/// The plan of Settings › Workspace › Trash › Empty… (phase 5c): every entry of the workspace's trash and their bytes, and a
|
||||
/// fingerprint over their names, sizes and times. Emptying erases exactly these entries, and only while the fingerprint
|
||||
/// still matches (the user types the number of entries to confirm); schedules and the size limit never empty the trash.
|
||||
/// </summary>
|
||||
public sealed record WorkspaceTrashPlan(string Folder, IReadOnlyList<WorkspaceTrashItem> Items, long Bytes, string Fingerprint)
|
||||
{
|
||||
/// <summary>Nothing to erase: Empty… is disabled.</summary>
|
||||
public bool IsEmpty => Items.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>What emptying the workspace's trash erased.</summary>
|
||||
public sealed record WorkspaceTrashResult(int Items, long Bytes);
|
||||
|
||||
/// <summary>
|
||||
/// The workspace's clean-up side (phase 5c, P4): its usage, the plan and emptying of its trash, and what a local copy's removal
|
||||
/// keeps of renders not sent and originals the home lost. Stubs until the clean-up lands: usage and the trash read as empty,
|
||||
/// and a removal finds nothing more to keep.
|
||||
/// </summary>
|
||||
public sealed partial class WorkspaceHost
|
||||
{
|
||||
/// <summary>What the workspace takes of its drive (<see cref="WorkspaceUsage"/>), measured off the UI thread.</summary>
|
||||
public Task<WorkspaceUsage> UsageAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return Task.FromResult(WorkspaceUsage.None);
|
||||
}
|
||||
|
||||
/// <summary>The plan of emptying the workspace's trash (<see cref="WorkspaceTrashPlan"/>); nothing is erased.</summary>
|
||||
public Task<WorkspaceTrashPlan> PlanTrashAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return Task.FromResult(new WorkspaceTrashPlan(Path.Combine(Root, TrashFolder), [], 0, string.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Erases the entries of <paramref name="plan"/> from the workspace's trash for good, after the user typed their number;
|
||||
/// refused when the trash changed since the plan (<c>Errors.Workspace.TrashChanged</c>).
|
||||
/// </summary>
|
||||
/// <exception cref="WorkspaceException">The trash changed since the plan; nothing was erased.</exception>
|
||||
public Task<WorkspaceTrashResult> EmptyTrashAsync(WorkspaceTrashPlan plan, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
throw new NotImplementedException("Emptying the workspace's trash comes with phase 5c (P4).");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What a local copy's removal plan counts besides its versions (<see cref="WorkspaceRemovalPlan.UnsentRenders"/>,
|
||||
/// <see cref="WorkspaceRemovalPlan.LastOriginals"/>): renders of its ledger not sent, and originals the home no longer holds.
|
||||
/// </summary>
|
||||
private Task<(int UnsentRenders, int LastOriginals)> RemovalMediaAsync(WorkspaceProject project, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(project);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return Task.FromResult((0, 0));
|
||||
}
|
||||
|
||||
/// <summary>A removal without Discard is refused while the project's ledger holds renders not sent (Send first sends them).</summary>
|
||||
/// <exception cref="WorkspaceException">Renders wait to be sent.</exception>
|
||||
private Task EnsureRendersSentAsync(WorkspaceProject project, BundleWorkspace workspace, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(project);
|
||||
ArgumentNullException.ThrowIfNull(workspace);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Before a removed copy's media are deleted, under the project's lease: the originals the home no longer holds with the
|
||||
/// same SHA-256 moved into <paramref name="aside"/> (the copy's trash entry), never deleted.
|
||||
/// </summary>
|
||||
private Task KeepLastOriginalsAsync(WorkspaceProject project, string aside, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(project);
|
||||
ArgumentException.ThrowIfNullOrEmpty(aside);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Workspaces;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// The workspace's media (phase 5c, P1): what a copy writes (proxies, and the originals besides), copying the originals of a
|
||||
/// project, and going back to proxies only.
|
||||
/// </summary>
|
||||
public sealed partial class WorkspaceHost
|
||||
{
|
||||
/// <summary>The bytes the first copy of a sequence's media writes into the workspace, and the free bytes of the workspace's drive.</summary>
|
||||
/// <exception cref="WorkspaceException">The index or the archive engine is not open.</exception>
|
||||
public Task<WorkspaceCopyFacts> CopyFactsAsync(Guid sequenceId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var db = _db() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var archives = _archives() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var root = Root;
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var (bytes, free) = await WorkspaceJobs.CopyFactsAsync(db, archives, sequenceId, root, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceCopyFacts(bytes, free);
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>A project of the workspace as the plan of a move lists it: its size, and work not at its home yet (a warning, never a refusal).</summary>
|
||||
/// <param name="Unsent">Versions or renders wait to be sent to its home.</param>
|
||||
/// <param name="Modified">Changes not saved as a version.</param>
|
||||
public sealed record WorkspaceMoveProject(Guid ProjectId, string Name, int Files, long Bytes, bool Unsent, bool Modified);
|
||||
|
||||
/// <summary>
|
||||
/// The plan of Settings › Workspace › Move… (phase 5c): the workspace folder <see cref="From"/> moved with its projects to
|
||||
/// <see cref="To"/>: the projects and their bytes, the free bytes at the target, whether both lie on one volume (folders
|
||||
/// renamed) or not (files copied and hash-verified), why it is refused (null when it can go), and a fingerprint of what
|
||||
/// the plan read, which the move job checks again.
|
||||
/// </summary>
|
||||
/// <param name="Free">The free bytes of the target's drive; null when they cannot be measured.</param>
|
||||
/// <param name="Refusal">
|
||||
/// Why the move cannot go, one localized sentence: the target is the folder itself or inside it
|
||||
/// (<c>Errors.Workspace.MoveSameFolder</c>), already holds a workspace or a project of the same id
|
||||
/// (<c>Errors.Workspace.MoveTargetNotEmpty</c>), lacks the room (<c>Errors.Workspace.DiskFull</c>), or a workspace job is
|
||||
/// pending or running (<c>Errors.Workspace.JobsRunning</c>); null when it can go.
|
||||
/// </param>
|
||||
public sealed record WorkspaceMovePlan(string From, string To, IReadOnlyList<WorkspaceMoveProject> Projects, int Files, long Bytes, long? Free, bool SameVolume,
|
||||
string? Refusal, string Fingerprint)
|
||||
{
|
||||
/// <summary>Nothing refuses the move.</summary>
|
||||
public bool CanMove => Refusal is null;
|
||||
|
||||
/// <summary>Projects with work not at their home: the move keeps it, the plan says so.</summary>
|
||||
public int Warnings => Projects.Count(p => p.Unsent || p.Modified);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moving the workspace folder with its projects (phase 5c, P6): the plan, the <see cref="JobKind.WorkspaceMove"/> that
|
||||
/// carries it out, and the workspace that follows the folder once every file is verified there. While a move is queued or
|
||||
/// running the workspace is refused for syncs, saves and opens (<see cref="EnsureNotMoving"/>). Stubs until the move lands.
|
||||
/// </summary>
|
||||
public sealed partial class WorkspaceHost
|
||||
{
|
||||
/// <summary>A move of the workspace folder is queued or running: syncs, saves and opens wait for it.</summary>
|
||||
public bool IsMoving => false;
|
||||
|
||||
/// <summary>The plan of moving the workspace folder to <paramref name="to"/> (<see cref="WorkspaceMovePlan"/>); nothing is written.</summary>
|
||||
public Task<WorkspaceMovePlan> PlanMoveAsync(string to, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(to);
|
||||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||||
}
|
||||
|
||||
/// <summary>Queues the <see cref="JobKind.WorkspaceMove"/> of a plan the user confirmed.</summary>
|
||||
/// <exception cref="WorkspaceException">The plan refuses the move.</exception>
|
||||
public Task<Job> QueueMoveAsync(WorkspaceMovePlan plan, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Told by the move job once every file of the workspace is verified at <paramref name="to"/>
|
||||
/// (<c>WorkspaceJobOptions.Moved</c>): Settings › Workspace names the new folder and the workspace opens there.
|
||||
/// </summary>
|
||||
public Task MovedAsync(string from, string to)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(from);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(to);
|
||||
throw new NotImplementedException("Moving the workspace folder comes with phase 5c (P6).");
|
||||
}
|
||||
|
||||
/// <summary>Refuses an operation that writes into the workspace while its folder is being moved.</summary>
|
||||
/// <exception cref="WorkspaceException">A move is queued or running (<c>Errors.Workspace.Moving</c>).</exception>
|
||||
private void EnsureNotMoving()
|
||||
{
|
||||
if (IsMoving) throw new WorkspaceException(Loc.L("Errors.Workspace.Moving"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// The workspace's local renders (phase 5c, P2): rendering a project from the originals it holds on this PC, and sending its
|
||||
/// renders home.
|
||||
/// </summary>
|
||||
public sealed partial class WorkspaceHost
|
||||
{
|
||||
}
|
||||
@@ -70,8 +70,17 @@ public sealed record WorkspaceFolderPlan(string Current, string Folder, int Proj
|
||||
}
|
||||
|
||||
/// <summary>What "Open in workspace" shows of the copy it queues: its bytes (as the copy reckons them) and the free bytes of the workspace's drive.</summary>
|
||||
public sealed record WorkspaceCopyFacts(long Bytes, long? Free)
|
||||
/// <param name="Bytes">What the copy of the proxies writes.</param>
|
||||
/// <param name="OriginalsBytes">What the copy of the originals writes besides (phase 5c); null when not known.</param>
|
||||
public sealed record WorkspaceCopyFacts(long Bytes, long? Free, long? OriginalsBytes = null)
|
||||
{
|
||||
/// <summary>
|
||||
/// The drive lacks room for the copy of <paramref name="media"/> (<see cref="BundleMedia.Originals"/>: the proxies and the
|
||||
/// originals) and the reserve the copy keeps free.
|
||||
/// </summary>
|
||||
public bool TooLittleSpaceFor(string media) =>
|
||||
Free is { } free && free < Bytes + (media == BundleMedia.Originals ? OriginalsBytes ?? 0 : 0) + WorkspaceJobs.CopySpaceReserve;
|
||||
|
||||
/// <summary>The drive lacks the copy and the reserve the copy keeps: it would stop saying so.</summary>
|
||||
public bool TooLittleSpace => Free is { } free && free < Bytes + WorkspaceJobs.CopySpaceReserve;
|
||||
}
|
||||
@@ -113,8 +122,20 @@ public sealed record WorkspaceRemovalPlan(Guid ProjectId, string Name, int Files
|
||||
/// </summary>
|
||||
public string? KnownName { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Local renders not at the home yet (phase 5c, the project's ledger): Send first sends them, Discard keeps them in the
|
||||
/// workspace's trash with the rest of the work not sent.
|
||||
/// </summary>
|
||||
public int UnsentRenders { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Originals the workspace holds that the home no longer holds with the same SHA-256 (phase 5c): they go to the
|
||||
/// workspace's trash, never deleted, when the copy is removed.
|
||||
/// </summary>
|
||||
public int LastOriginals { get; init; }
|
||||
|
||||
/// <summary>Everything the copy holds is at the home: it can go without discarding anything.</summary>
|
||||
public bool IsSafe => Unsent == 0 && !Modified && !Conflict && !Damaged;
|
||||
public bool IsSafe => Unsent == 0 && UnsentRenders == 0 && !Modified && !Conflict && !Damaged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +150,7 @@ public sealed record WorkspaceRemovalPlan(Guid ProjectId, string Name, int Files
|
||||
/// Workspace › Kept versions only after the home returned each, a page of its history at a time. A capture (sample data, no
|
||||
/// engine) has no workspace: Edit opens the library there.
|
||||
/// </summary>
|
||||
public sealed class WorkspaceHost
|
||||
public sealed partial class WorkspaceHost
|
||||
{
|
||||
/// <summary>Where discarded work of removed local copies is kept (the store lists only folders named by a project id).</summary>
|
||||
public const string TrashFolder = ".trash";
|
||||
@@ -358,20 +379,6 @@ public sealed class WorkspaceHost
|
||||
Log.Info("workspace", $"The workspace folder is now {plan.Folder} ({plan.ProjectsLeft} project(s) stay in {plan.Current})");
|
||||
}
|
||||
|
||||
/// <summary>The bytes the first copy of a sequence's media writes into the workspace, and the free bytes of the workspace's drive.</summary>
|
||||
/// <exception cref="WorkspaceException">The index or the archive engine is not open.</exception>
|
||||
public Task<WorkspaceCopyFacts> CopyFactsAsync(Guid sequenceId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var db = _db() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var archives = _archives() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var root = Root;
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var (bytes, free) = await WorkspaceJobs.CopyFactsAsync(db, archives, sequenceId, root, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceCopyFacts(bytes, free);
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>The project of <paramref name="sequenceId"/> opened last here, else the one saved last; null when the workspace has none.</summary>
|
||||
public async Task<WorkspaceEntry?> LastUsedAsync(Guid sequenceId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -388,6 +395,16 @@ public sealed class WorkspaceHost
|
||||
_savePreferences();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records that Edit opened <paramref name="projectId"/> at <paramref name="at"/> (now when null): the clean-up's Clean
|
||||
/// after goes by it (phase 5c, <see cref="AppSettings.WorkspaceOpened"/>). Call it on the UI thread, which writes the settings.
|
||||
/// </summary>
|
||||
public void RecordOpened(Guid projectId, DateTimeOffset? at = null)
|
||||
{
|
||||
_settings.WorkspaceOpened[projectId] = at ?? DateTimeOffset.UtcNow;
|
||||
_savePreferences();
|
||||
}
|
||||
|
||||
/// <summary>The home's live projects of a sequence, Main first (made from the sequence's settings when it has none yet).</summary>
|
||||
public Task<IReadOnlyList<SequenceProject>> HomeProjectsAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
|
||||
HomeProjectsAsync(ArchiveHome(sequenceId), cancellationToken);
|
||||
@@ -426,6 +443,7 @@ public sealed class WorkspaceHost
|
||||
var sequenceId = home.SequenceId;
|
||||
var checkout = await Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
// Refused before anything is written: the copy job would refuse such a folder after the checkout filled it.
|
||||
if (await InsideALibraryAsync(cancellationToken).ConfigureAwait(false))
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.InsideLibraryEdit", Root)) { FolderRefused = true };
|
||||
@@ -461,6 +479,7 @@ public sealed class WorkspaceHost
|
||||
/// </summary>
|
||||
public Task<Job> QueueCopyAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
var bundle = Existing(projectId).ReadBundle();
|
||||
return await QueueCopyCoreAsync(bundle.Workspace!.Home, projectId, bundle.Workspace.Media.Kind, bundle.Sequence.Title ?? string.Empty, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
@@ -516,6 +535,7 @@ public sealed class WorkspaceHost
|
||||
{
|
||||
var version = await Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
EnsureWritable(await Sync.StatusAsync(projectId, null, cancellationToken).ConfigureAwait(false));
|
||||
return await Sync.CommitAsync(projectId, note, null, cancellationToken).ConfigureAwait(false);
|
||||
}, cancellationToken).ConfigureAwait(false);
|
||||
@@ -538,6 +558,7 @@ public sealed class WorkspaceHost
|
||||
/// <summary>The working state as a new local version without a note and without sending it; null when nothing changed.</summary>
|
||||
public Task<ProjectVersion?> CommitAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
EnsureWritable(await Sync.StatusAsync(projectId, null, cancellationToken).ConfigureAwait(false));
|
||||
return await Sync.CommitAsync(projectId, null, null, cancellationToken).ConfigureAwait(false);
|
||||
}, cancellationToken);
|
||||
@@ -551,6 +572,7 @@ public sealed class WorkspaceHost
|
||||
/// <exception cref="WorkspaceSyncException">The home refused a version for good.</exception>
|
||||
public Task<WorkspaceSyncResult> SyncAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
var home = HomeOfProject(projectId);
|
||||
var pulled = await Sync.PullAsync(projectId, home, cancellationToken).ConfigureAwait(false);
|
||||
// Deleted at the library: nothing to send, nothing to prune; the copy stays as it is.
|
||||
@@ -570,6 +592,7 @@ public sealed class WorkspaceHost
|
||||
public Task<WorkspaceSyncResult> ResolveAsync(Guid projectId, ConflictChoice choice, IReadOnlySet<string>? takeServer = null,
|
||||
WorkspaceConflict? shown = null, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
var home = HomeOfProject(projectId);
|
||||
WorkspaceSyncResult resolved;
|
||||
if (choice == ConflictChoice.SaveBoth)
|
||||
@@ -619,6 +642,7 @@ public sealed class WorkspaceHost
|
||||
/// </summary>
|
||||
public Task<ProjectSettings> RestoreAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
var status = await Sync.StatusAsync(projectId, null, cancellationToken).ConfigureAwait(false);
|
||||
if (status.ReadOnly) throw new WorkspaceException(Loc.L("Errors.Workspace.ReadOnly"));
|
||||
if (status.MediaRemoved) throw new WorkspaceException(Loc.L("Errors.Workspace.MediaMissing"));
|
||||
@@ -766,8 +790,9 @@ public sealed class WorkspaceHost
|
||||
// A conflict recorded counts as work not at the home, also once the library no longer has the project (Gone asks none);
|
||||
// one a settling replay took past its commit point is over, as the status reads it.
|
||||
var conflict = status.Conflict is not null || project.OpenConflict() is not null;
|
||||
var (unsentRenders, lastOriginals) = await RemovalMediaAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceRemovalPlan(projectId, name, files, bytes, status.Ahead + status.Damaged, status.Modified, conflict, status.Offline,
|
||||
status.State == WorkspaceState.Gone);
|
||||
status.State == WorkspaceState.Gone) { UnsentRenders = unsentRenders, LastOriginals = lastOriginals };
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
@@ -802,6 +827,7 @@ public sealed class WorkspaceHost
|
||||
// A version saved here that cannot be read may be one the home never had: only discarding keeps it aside.
|
||||
if (status.Ahead > 0 || status.Damaged > 0 || (status.Modified && !status.ReadOnly) || status.Conflict is not null)
|
||||
throw new WorkspaceException(Unsent(workspace.Home));
|
||||
await EnsureRendersSentAsync(project, workspace, cancellationToken).ConfigureAwait(false);
|
||||
await VerifyHomeAsync(projectId, workspace, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
await RemoveFolderAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
@@ -950,6 +976,8 @@ public sealed class WorkspaceHost
|
||||
}
|
||||
throw;
|
||||
}
|
||||
// Originals the home no longer holds go aside with the rest; only what the home can make again is deleted.
|
||||
await KeepLastOriginalsAsync(project, aside, cancellationToken).ConfigureAwait(false);
|
||||
if (Directory.Exists(project.MediaDirectory)) Directory.Delete(project.MediaDirectory, recursive: true);
|
||||
|
||||
void Move(string from, string to)
|
||||
@@ -1007,9 +1035,13 @@ public sealed class WorkspaceHost
|
||||
|
||||
private void Forget(Guid sequenceId, Guid projectId)
|
||||
{
|
||||
if (!_settings.WorkspaceRecent.TryGetValue(sequenceId, out var known) || known != projectId) return;
|
||||
_settings.WorkspaceRecent.Remove(sequenceId);
|
||||
_savePreferences();
|
||||
var changed = _settings.WorkspaceOpened.Remove(projectId);
|
||||
if (_settings.WorkspaceRecent.TryGetValue(sequenceId, out var known) && known == projectId)
|
||||
{
|
||||
_settings.WorkspaceRecent.Remove(sequenceId);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) _savePreferences();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user