feat(workspace): copy originals into the workspace and choose the project Edit opens
Phase 5c P1. A workspace copy of kind "originals" now copies each frame's original beside its proxy, so a later local render has full-quality input: streamed into a .part file, hashed as written, checked against the home's SHA-256, renamed and read back. Archive and server homes both work, a stopped copy resumes (originals: checkpoint), and the space check counts the originals. A frame whose original is gone, damaged or refused keeps its proxy and the job says how many; the copy does not fail. Stale originals are deleted only when the home holds the same SHA-256, otherwise moved to the workspace's trash. Proxies only... plans first (every original hashed against the home's frames), asks for an explicit confirmation, rewrites the media to proxies before it touches a file, refuses a plan that changed since, and trashes what the home no longer holds instead of deleting it. Edit: Open in workspace offers Originals (the settings' default, disabled when the drive lacks room) with the originals' size for archive and server homes; Settings > Workspace > Open project picks Last used, Main or asks which; each open is recorded for the clean-up. The project menu gains Copy originals... and Proxies only..., refused while changes are unsaved or jobs of the sequence run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e1c67f531
commit
0c51d11080
14 files changed
+1397
-70
No files matched your search
@@ -81,6 +81,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
private bool _isSyncing;
|
||||
private bool _homeFramesChanged;
|
||||
private Guid _copyJob;
|
||||
private bool _copyingOriginals;
|
||||
private bool _changingMedia;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>Counts the editor's changes, so only the last one's state read applies.</summary>
|
||||
@@ -110,6 +112,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
RenameCommand = new AsyncRelayCommand(OpenRenameAsync);
|
||||
DeleteCommand = new AsyncRelayCommand(DeleteAsync, () => !IsMain);
|
||||
RemoveCopyCommand = new AsyncRelayCommand(OpenRemoveCopyAsync);
|
||||
CopyOriginalsCommand = new AsyncRelayCommand(CopyOriginalsAsync, () => !HoldsOriginals && !IsMediaBusy);
|
||||
ProxiesOnlyCommand = new AsyncRelayCommand(ProxiesOnlyAsync, () => HoldsOriginals && !IsMediaBusy);
|
||||
source.JobChanged += OnJobChanged;
|
||||
session.ProjectChanged += OnProjectChanged;
|
||||
host.HomeChanged += OnHomeChanged;
|
||||
@@ -193,6 +197,27 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
|
||||
public ICommand UpdateMediaCommand => _updateMedia;
|
||||
|
||||
/// <summary>The workspace holds the project's originals besides its proxies (phase 5c): renders run on this PC.</summary>
|
||||
public bool HoldsOriginals => _source.Workspace?.Media.Kind == BundleMedia.Originals;
|
||||
|
||||
/// <summary>
|
||||
/// The media cannot change now: changes not saved as a version, a sync or a copy of the media running (the jobs of the
|
||||
/// sequence are asked when the command runs).
|
||||
/// </summary>
|
||||
public bool IsMediaBusy => _changingMedia || _isSyncing || _copyJob != Guid.Empty || _status is { Modified: true, ReadOnly: false };
|
||||
|
||||
/// <summary>Copy originals… (phase 5c): the project's originals into the workspace, to render on this PC.</summary>
|
||||
public ICommand CopyOriginalsCommand { get; }
|
||||
|
||||
/// <summary>Proxies only… (phase 5c): the originals copied here deleted once the home is checked to hold each one.</summary>
|
||||
public ICommand ProxiesOnlyCommand { get; }
|
||||
|
||||
public string CopyOriginalsToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy")
|
||||
: WorkspaceText.ForHome("Tooltips.Editor.Project.CopyOriginals", IsServerHome);
|
||||
|
||||
public string ProxiesOnlyToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy")
|
||||
: WorkspaceText.ForHome("Tooltips.Editor.Project.ProxiesOnly", IsServerHome);
|
||||
|
||||
/// <summary>Reads where the project stands (against its home) and whether the home's frames moved.</summary>
|
||||
public async Task RefreshAsync()
|
||||
{
|
||||
@@ -644,6 +669,130 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy originals…: refused while the media cannot change (<see cref="IsMediaBusy"/>, or a job of the sequence waits or
|
||||
/// runs); otherwise the copy is queued, the banner says it runs, and the editor reads the media again once it is done.
|
||||
/// </summary>
|
||||
private async Task CopyOriginalsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await StoreEditAsync();
|
||||
if (await MediaRefusalAsync() is { } refusal)
|
||||
{
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), refusal, isError: true);
|
||||
return;
|
||||
}
|
||||
var job = await _host.QueueOriginalsCopyAsync(ProjectId);
|
||||
_copyJob = job.Id;
|
||||
_copyingOriginals = true;
|
||||
RaiseState();
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyingOriginals"), _session.Content.Sequence.DisplayTitle, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"));
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"The originals of project {ProjectId} could not be queued for copy", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Proxies only…: the plan (each original hashed and weighed against the home, read now), confirmed by the user, then
|
||||
/// applied; the home out of reach, or anything changed since the plan, removes nothing.
|
||||
/// </summary>
|
||||
private async Task ProxiesOnlyAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await StoreEditAsync();
|
||||
if (await MediaRefusalAsync() is { } refusal)
|
||||
{
|
||||
_ui.Notify(Loc.L("Editor.Workspace.OriginalsNotRemoved"), refusal, isError: true);
|
||||
return;
|
||||
}
|
||||
SetChangingMedia(true);
|
||||
var plan = await _host.PlanProxiesOnlyAsync(ProjectId);
|
||||
if (_disposed) return;
|
||||
var detail = new List<string>
|
||||
{
|
||||
Loc.L("Editor.ProxiesOnly.Originals", Formatting.Count(plan.Originals)),
|
||||
Loc.L("Editor.ProxiesOnly.Size", Formatting.Bytes(plan.Bytes)),
|
||||
};
|
||||
if (plan.ToTrash > 0) detail.Add(Loc.L("Editor.ProxiesOnly.ToTrash", Formatting.Count(plan.ToTrash)));
|
||||
if (!_ui.Confirm(new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Editor.ProxiesOnly.Title", Name),
|
||||
Message = WorkspaceText.ForHome("Editor.ProxiesOnly.Message", IsServerHome),
|
||||
Detail = string.Join(Environment.NewLine, detail),
|
||||
IsDetailMonospaced = false,
|
||||
DetailToolTip = plan.ToTrash > 0 ? WorkspaceText.ForHome("Tooltips.Editor.ProxiesOnly.ToTrash", IsServerHome) : null,
|
||||
SafeText = Loc.L("Editor.Project.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Editor.ProxiesOnly.Keep"),
|
||||
ActionText = Loc.L("Editor.ProxiesOnly.Action"),
|
||||
ActionToolTip = Loc.L("Tooltips.Editor.ProxiesOnly.Action"),
|
||||
IsDestructive = true,
|
||||
}))
|
||||
return;
|
||||
var trashed = await _host.ProxiesOnlyAsync(ProjectId, plan);
|
||||
if (_disposed) return;
|
||||
await _session.ReloadAsync();
|
||||
_ui.Notify(Loc.L("Editor.Workspace.OriginalsRemoved"),
|
||||
trashed > 0 ? Loc.L("Editor.ProxiesOnly.ToTrash", Formatting.Count(trashed)) : _session.Content.Sequence.DisplayTitle);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"The originals of project {ProjectId} were not removed", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.OriginalsNotRemoved"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SetChangingMedia(false);
|
||||
await RefreshAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Why the media cannot change now (<c>Errors.Workspace.MediaBusy</c>): changes not saved as a version, a copy or sync
|
||||
/// running, or an analysis, render or workspace job of the sequence waiting or running; null when they can.
|
||||
/// </summary>
|
||||
private async Task<string?> MediaRefusalAsync()
|
||||
{
|
||||
var local = await _host.StatusAsync(ProjectId, askHome: false);
|
||||
if (_disposed) return null;
|
||||
Apply(WithLocal(_status, local));
|
||||
if (IsMediaBusy) return Loc.L("Errors.Workspace.MediaBusy");
|
||||
var jobs = await _source.ListJobsAsync(CancellationToken.None);
|
||||
var sequenceId = SequenceId;
|
||||
return jobs.Any(j => j.State is JobState.Queued or JobState.Running or JobState.Paused && j.TargetIds.Contains(sequenceId)
|
||||
&& j.Kind is JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render or JobKind.WorkspaceCopy or JobKind.WorkspaceRender
|
||||
or JobKind.WorkspaceSend)
|
||||
? Loc.L("Errors.Workspace.MediaBusy")
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>The copy of the originals ended: said, with the frames that have none (they stay proxies, and a local render waits for them).</summary>
|
||||
private void NotifyOriginalsCopied()
|
||||
{
|
||||
int missing;
|
||||
try
|
||||
{
|
||||
missing = _source.Project.ReadMedia()?.Frames.Count(f => f.Original is null) ?? 0;
|
||||
}
|
||||
catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Warning("workspace", $"The media of project {ProjectId} could not be read after the copy of its originals", ex);
|
||||
missing = 0;
|
||||
}
|
||||
if (missing == 0) _ui.Notify(Loc.L("Editor.Workspace.OriginalsCopied"), _session.Content.Sequence.DisplayTitle);
|
||||
else _ui.Notify(Loc.L("Editor.Workspace.OriginalsCopied"), Loc.L("Editor.Workspace.OriginalsMissing", Formatting.Count(missing)));
|
||||
}
|
||||
|
||||
private void SetChangingMedia(bool changing)
|
||||
{
|
||||
_changingMedia = changing;
|
||||
RaiseState();
|
||||
}
|
||||
|
||||
/// <summary>The editor's last edit stored in the working state before an operation reads it.</summary>
|
||||
/// <exception cref="WorkspaceException">It could not be stored (it is retried in the background; nothing was lost).</exception>
|
||||
private async Task StoreEditAsync()
|
||||
@@ -787,10 +936,13 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
{
|
||||
if (_disposed || job.Id != _copyJob) return;
|
||||
_copyJob = Guid.Empty;
|
||||
var originals = _copyingOriginals;
|
||||
_copyingOriginals = false;
|
||||
if (job.State == JobState.Failed) _ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), job.Error ?? _session.Content.Sequence.DisplayTitle, isError: true);
|
||||
try
|
||||
{
|
||||
if (job.State == JobState.Done) await _session.ReloadAsync();
|
||||
if (job.State == JobState.Done && originals) NotifyOriginalsCopied();
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
@@ -836,6 +988,10 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
OnPropertyChanged(nameof(RemoveCopyToolTip));
|
||||
OnPropertyChanged(nameof(MediaChangedToolTip));
|
||||
OnPropertyChanged(nameof(UpdateMediaToolTip));
|
||||
OnPropertyChanged(nameof(HoldsOriginals));
|
||||
OnPropertyChanged(nameof(IsMediaBusy));
|
||||
OnPropertyChanged(nameof(CopyOriginalsToolTip));
|
||||
OnPropertyChanged(nameof(ProxiesOnlyToolTip));
|
||||
_updateMedia.RaiseCanExecuteChanged();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
@@ -47,8 +47,9 @@ public static class ProjectNames
|
||||
/// <summary>
|
||||
/// "Open in workspace" (owner review 2, R8), asked when a sequence has no project in the workspace yet, and by the project
|
||||
/// menu's Open project: which project of its home (Main, made from the sequence's settings as they are, or another) or a
|
||||
/// new one with its name, and the media to copy (proxies; the originals come in phase 5c). Open queues the copy; the
|
||||
/// sequence opens once it is done.
|
||||
/// new one with its name, and the media to copy: the proxies, or (phase 5c) the originals besides, to render on this PC,
|
||||
/// offered while the workspace's drive has room for them (Settings › Workspace › Media chooses the default). Open queues
|
||||
/// the copy; the sequence opens once it is done.
|
||||
/// </summary>
|
||||
public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
@@ -56,6 +57,7 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
private readonly bool _server;
|
||||
private ProjectOption? _selected;
|
||||
private bool _isNew;
|
||||
private bool _isOriginals;
|
||||
|
||||
/// <param name="taken">The names a new project cannot take (default: those of <paramref name="projects"/>).</param>
|
||||
/// <param name="copy">What the copy of the media writes and the free space of the workspace's drive; null when not measured (shown as nothing).</param>
|
||||
@@ -63,8 +65,10 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
/// The projects whose copy here this Chronos cannot read (damaged, or a newer Chronos's), with why: listed, never chosen.
|
||||
/// </param>
|
||||
/// <param name="server">The sequence's home is a server (phase 5b): the texts name the server.</param>
|
||||
/// <param name="defaultMedia">The media chosen first (<see cref="AppSettings.WorkspaceDefaultMedia"/>); the proxies when the originals have no room.</param>
|
||||
public OpenInWorkspaceDialogViewModel(string sequenceTitle, IReadOnlyList<SequenceProject> projects, Action<ArchiveDialogViewModel> close,
|
||||
IReadOnlyList<string>? taken = null, WorkspaceCopyFacts? copy = null, IReadOnlyDictionary<Guid, string>? unreadable = null, bool server = false)
|
||||
IReadOnlyList<string>? taken = null, WorkspaceCopyFacts? copy = null, IReadOnlyDictionary<Guid, string>? unreadable = null, bool server = false,
|
||||
string defaultMedia = BundleMedia.Proxies)
|
||||
: base(close)
|
||||
{
|
||||
_server = server;
|
||||
@@ -76,7 +80,11 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
new DialogFact(Loc.L("Editor.OpenWorkspace.Size"), Formatting.Bytes(copy.Bytes), Reason: Loc.L("Tooltips.Editor.OpenWorkspace.Size")),
|
||||
new DialogFact(Loc.L("Editor.OpenWorkspace.Free"), copy.Free is { } free ? Formatting.Bytes(free) : Loc.L("Server.Sync.None"),
|
||||
Reason: Loc.L(copy.TooLittleSpace ? "Errors.Workspace.NoRoom" : "Tooltips.Editor.OpenWorkspace.Free")),
|
||||
.. copy.OriginalsBytes is { } originals
|
||||
? [new DialogFact(Loc.L("Editor.OpenWorkspace.Originals"), Formatting.Bytes(originals), Reason: Loc.L("Tooltips.Editor.OpenWorkspace.OriginalsSize"))]
|
||||
: Array.Empty<DialogFact>(),
|
||||
];
|
||||
_isOriginals = defaultMedia == BundleMedia.Originals && CanCopyOriginals;
|
||||
Projects = [.. projects.OrderByDescending(p => p.IsMain).Select(p => new ProjectOption(p, unreadable?.GetValueOrDefault(p.Id)))];
|
||||
_selected = Projects.FirstOrDefault(p => p.IsAvailable);
|
||||
_isNew = !HasProjects;
|
||||
@@ -97,8 +105,8 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
/// <summary>"Copy size" and "Free space", under the media.</summary>
|
||||
public IReadOnlyList<DialogFact> CopyFacts { get; }
|
||||
|
||||
/// <summary>The drive lacks room for the copy: the free space says so (the copy would stop saying how much is missing).</summary>
|
||||
public bool IsShortOfSpace => Copy?.TooLittleSpace == true;
|
||||
/// <summary>The drive lacks room for the copy of the media chosen: the free space says so (the copy would stop saying how much is missing).</summary>
|
||||
public bool IsShortOfSpace => Copy?.TooLittleSpaceFor(Media) == true;
|
||||
|
||||
public string Heading => Loc.L("Editor.OpenWorkspace.Title");
|
||||
|
||||
@@ -147,11 +155,37 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
|
||||
public string ProxiesToolTip => WorkspaceText.ForHome("Tooltips.Editor.OpenWorkspace.Proxies", _server);
|
||||
|
||||
/// <summary>The proxies, the only media this phase copies.</summary>
|
||||
public bool IsProxies => true;
|
||||
/// <summary>The proxies alone: light to edit, renders run where the originals are.</summary>
|
||||
public bool IsProxies
|
||||
{
|
||||
get => !_isOriginals;
|
||||
set
|
||||
{
|
||||
if (value) IsOriginals = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The originals: offered from phase 5c, to render on this PC.</summary>
|
||||
public bool CanCopyOriginals => false;
|
||||
/// <summary>The proxies and the originals (phase 5c): renders run on this PC.</summary>
|
||||
public bool IsOriginals
|
||||
{
|
||||
get => _isOriginals;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _isOriginals, value && CanCopyOriginals)) return;
|
||||
OnPropertyChanged(nameof(IsProxies));
|
||||
OnPropertyChanged(nameof(IsShortOfSpace));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The media <see cref="Open"/> copies.</summary>
|
||||
public string Media => _isOriginals ? BundleMedia.Originals : BundleMedia.Proxies;
|
||||
|
||||
/// <summary>The originals can be chosen: the drive has room for them besides the proxies (or was not measured: the copy measures again).</summary>
|
||||
public bool CanCopyOriginals => Copy?.TooLittleSpaceFor(BundleMedia.Originals) != true;
|
||||
|
||||
public string OriginalsToolTip => CanCopyOriginals
|
||||
? WorkspaceText.ForHome("Tooltips.Editor.OpenWorkspace.OriginalsReady", _server)
|
||||
: Loc.L("Tooltips.Editor.OpenWorkspace.NoRoomOriginals");
|
||||
|
||||
public ICommand OpenCommand { get; }
|
||||
|
||||
@@ -169,7 +203,7 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
private void Open()
|
||||
{
|
||||
if (!CanOpen) return;
|
||||
_choice.TrySetResult(_isNew ? new OpenChoice(null, NewName.Text.Trim(), BundleMedia.Proxies) : new OpenChoice(_selected!.Project.Id, null, BundleMedia.Proxies));
|
||||
_choice.TrySetResult(_isNew ? new OpenChoice(null, NewName.Text.Trim(), Media) : new OpenChoice(_selected!.Project.Id, null, Media));
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -181,6 +215,69 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A project of the workspace offered by "Open which project?" (Main in the UI language).</summary>
|
||||
public sealed record WorkspaceProjectChoice(WorkspaceEntry Entry)
|
||||
{
|
||||
public string Label => WorkspaceText.ProjectName(Entry.Name, Entry.IsMain);
|
||||
|
||||
public override string ToString() => Label;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Open which project?" (phase 5c, Settings › Workspace › Open project: Ask): Edit asks which of the sequence's projects in
|
||||
/// the workspace opens, the one opened last chosen first.
|
||||
/// </summary>
|
||||
public sealed class OpenProjectDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
private readonly TaskCompletionSource<WorkspaceEntry?> _choice = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
private WorkspaceProjectChoice? _selected;
|
||||
|
||||
/// <param name="projects">The sequence's readable projects in the workspace.</param>
|
||||
/// <param name="last">The project opened last, chosen first; null: Main.</param>
|
||||
public OpenProjectDialogViewModel(string sequenceTitle, IReadOnlyList<WorkspaceEntry> projects, Guid? last, Action<ArchiveDialogViewModel> close)
|
||||
: base(close)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(projects);
|
||||
Message = Loc.L("Editor.OpenProject.Message", sequenceTitle);
|
||||
Projects = [.. projects.OrderByDescending(p => p.IsMain).ThenBy(p => p.Name, StringComparer.CurrentCultureIgnoreCase).Select(p => new WorkspaceProjectChoice(p))];
|
||||
_selected = Projects.FirstOrDefault(p => p.Entry.ProjectId == last) ?? Projects.FirstOrDefault();
|
||||
OpenCommand = new RelayCommand(Open, () => _selected is not null);
|
||||
}
|
||||
|
||||
/// <summary>Completes with the project chosen, or null when the dialog was closed without one.</summary>
|
||||
public Task<WorkspaceEntry?> Choice => _choice.Task;
|
||||
|
||||
public string Heading => Loc.L("Editor.OpenProject.Title");
|
||||
|
||||
public string Message { get; }
|
||||
|
||||
public IReadOnlyList<WorkspaceProjectChoice> Projects { get; }
|
||||
|
||||
public WorkspaceProjectChoice? SelectedProject
|
||||
{
|
||||
get => _selected;
|
||||
set
|
||||
{
|
||||
if (Set(ref _selected, value)) CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand OpenCommand { get; }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_choice.TrySetResult(null);
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void Open()
|
||||
{
|
||||
if (_selected is null) return;
|
||||
_choice.TrySetResult(_selected.Entry);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Names a project: "New project" (made from the open project's last version at the home) or "Rename".</summary>
|
||||
public sealed class ProjectNameDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
|
||||
@@ -54,10 +54,10 @@
|
||||
IsEnabled="{Binding IsNew}" ToolTip="{Binding NewName.ToolTip}" MaxLength="60" AutomationProperties.Name="{l:Loc Editor.OpenWorkspace.New}" />
|
||||
<TextBlock Grid.Row="2" Text="{l:Loc Editor.OpenWorkspace.Media}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" Margin="0,14,0,0" />
|
||||
<StackPanel Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="0,14,0,0">
|
||||
<RadioButton GroupName="Media" Content="{l:Loc Editor.OpenWorkspace.Proxies}" IsChecked="{Binding IsProxies, Mode=OneWay}"
|
||||
<RadioButton GroupName="Media" Content="{l:Loc Editor.OpenWorkspace.Proxies}" IsChecked="{Binding IsProxies}"
|
||||
ToolTip="{Binding ProxiesToolTip}" Margin="0,0,16,0" />
|
||||
<RadioButton GroupName="Media" Content="{l:Loc Editor.OpenWorkspace.Originals}" IsEnabled="{Binding CanCopyOriginals}" IsChecked="False"
|
||||
ToolTip="{l:Loc Tooltips.Editor.OpenWorkspace.Originals}" ToolTipService.ShowOnDisabled="True" />
|
||||
<RadioButton GroupName="Media" Content="{l:Loc Editor.OpenWorkspace.Originals}" IsEnabled="{Binding CanCopyOriginals}" IsChecked="{Binding IsOriginals}"
|
||||
ToolTip="{Binding OriginalsToolTip}" ToolTipService.ShowOnDisabled="True" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<!-- What the copy writes and the room the workspace's drive has for it. -->
|
||||
@@ -88,6 +88,30 @@
|
||||
</DataTemplate>
|
||||
|
||||
<!-- New project and Rename: the name, checked as it is typed. -->
|
||||
<!-- Open which project? (Settings › Workspace › Open project: Ask): the sequence's projects in the workspace. -->
|
||||
<DataTemplate DataType="{x:Type ws:OpenProjectDialogViewModel}">
|
||||
<Border Style="{StaticResource Border.Dialog}" Width="460">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" />
|
||||
<TextBlock Text="{Binding Message}" Style="{StaticResource Text.Secondary}" Margin="0,4,0,0" TextWrapping="Wrap" />
|
||||
<Grid Margin="0,14,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="116" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{l:Loc Editor.OpenWorkspace.Project}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" />
|
||||
<ComboBox Grid.Column="1" ItemsSource="{Binding Projects}" SelectedItem="{Binding SelectedProject}" DisplayMemberPath="Label"
|
||||
ToolTip="{l:Loc Tooltips.Editor.OpenProject.Choose}" AutomationProperties.Name="{l:Loc Editor.OpenWorkspace.Project}" />
|
||||
</Grid>
|
||||
<DockPanel Margin="0,18,0,0">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Editor.OpenWorkspace.Open}" Command="{Binding OpenCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Editor.OpenProject.Choose}" IsDefault="True" MinWidth="96" Margin="8,0,0,0" />
|
||||
<Button DockPanel.Dock="Right" Content="{l:Loc Archive.Dialog.Cancel}" Command="{Binding CloseCommand}" ToolTip="{Binding CloseToolTip}" IsCancel="True" MinWidth="96" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type ws:ProjectNameDialogViewModel}">
|
||||
<Border Style="{StaticResource Border.Dialog}" Width="460">
|
||||
<StackPanel>
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
using System.IO;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Workspaces;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
@@ -9,7 +14,13 @@ namespace Chronos.App.Workspace;
|
||||
/// </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>
|
||||
/// <summary>A server's proxy when it says nothing of its size: some 1.5 MB, as the copy reckons one at 1920 px.</summary>
|
||||
private const long ServerProxyEstimate = 1_500_000;
|
||||
|
||||
/// <summary>
|
||||
/// The bytes the first copy of a sequence's media writes into the workspace (the proxies; the originals besides in
|
||||
/// <see cref="WorkspaceCopyFacts.OriginalsBytes"/>), 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)
|
||||
{
|
||||
@@ -19,7 +30,100 @@ public sealed partial class WorkspaceHost
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var (bytes, free) = await WorkspaceJobs.CopyFactsAsync(db, archives, sequenceId, root, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceCopyFacts(bytes, free);
|
||||
var originals = await WorkspaceOriginals.ArchiveOriginalsBytesAsync(db, archives, sequenceId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceCopyFacts(bytes, free, originals);
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the copy of a sequence of <paramref name="home"/> writes: for this PC's archive as
|
||||
/// <see cref="CopyFactsAsync(Guid, CancellationToken)"/>; for a server, reckoned from its frames (a proxy some 1.5 MB, the
|
||||
/// originals as large as the server says they are).
|
||||
/// </summary>
|
||||
/// <exception cref="HomeUnavailableException">The server cannot be reached now.</exception>
|
||||
public Task<WorkspaceCopyFacts> CopyFactsAsync(BundleHome home, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(home);
|
||||
if (home.IsArchive) return CopyFactsAsync(home.SequenceId, cancellationToken);
|
||||
var reached = Reachable(home);
|
||||
var root = Root;
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var frames = (await reached.FramesAsync(cancellationToken).ConfigureAwait(false)).Frames;
|
||||
var present = frames.Where(f => (f.Flags & FrameFlags.Missing) == 0).ToList();
|
||||
return new WorkspaceCopyFacts(present.Count * ServerProxyEstimate, FreeBytes(root), present.Sum(f => Math.Max(0, f.Size)));
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Copy originals…": queues the copy of a workspace project's media with its originals (phase 5c), unless a copy is
|
||||
/// waiting or running already (that one is returned). The project file says originals once the copy commits.
|
||||
/// </summary>
|
||||
/// <exception cref="WorkspaceException">The project is not here, or the workspace folder is being moved.</exception>
|
||||
public Task<Job> QueueOriginalsCopyAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
var bundle = Existing(projectId).ReadBundle();
|
||||
Log.Info("workspace", $"Originals of project {projectId} queued for copy");
|
||||
return await QueueCopyCoreAsync(bundle.Workspace!.Home, projectId, BundleMedia.Originals, bundle.Sequence.Title ?? string.Empty, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// The plan of "Proxies only…" (phase 5c): each original of the project hashed and weighed against the home's frames,
|
||||
/// read now. Nothing is changed.
|
||||
/// </summary>
|
||||
/// <exception cref="WorkspaceException">The home cannot be reached to check the originals (<c>Errors.Workspace.OriginalsCheck</c>).</exception>
|
||||
public Task<WorkspaceProxiesOnlyPlan> PlanProxiesOnlyAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
var project = Existing(projectId);
|
||||
var home = await CheckedHomeFramesAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
return WorkspaceOriginals.PlanProxiesOnly(project, home);
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Applies "Proxies only…" as planned (the user confirmed it): the home's frames read again, the plan refused when the
|
||||
/// project or the home changed since; then the originals the home holds are deleted, the others moved to the trash.
|
||||
/// </summary>
|
||||
/// <returns>The originals moved to the workspace's trash.</returns>
|
||||
/// <exception cref="WorkspaceException">The home cannot be reached, or the workspace folder is being moved.</exception>
|
||||
/// <exception cref="InvalidOperationException">The project or the home changed since the plan (<c>Errors.Workspace.MediaChanged</c>).</exception>
|
||||
public Task<int> ProxiesOnlyAsync(Guid projectId, WorkspaceProxiesOnlyPlan plan, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
EnsureNotMoving();
|
||||
var project = Existing(projectId);
|
||||
var home = await CheckedHomeFramesAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
return await WorkspaceOriginals.ApplyProxiesOnlyAsync(project, plan, home, LockWait, cancellationToken).ConfigureAwait(false);
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>The frames of the project's home, as it answers now; one out of reach refuses ("nothing was removed").</summary>
|
||||
private async Task<HomeFrames> CheckedHomeFramesAsync(WorkspaceProject project, CancellationToken cancellationToken)
|
||||
{
|
||||
var named = project.ReadBundle().Workspace!.Home;
|
||||
var refused = WorkspaceText.ForHome("Errors.Workspace.OriginalsCheck", !named.IsArchive);
|
||||
var home = HomeOf(named) ?? throw new WorkspaceException(refused);
|
||||
try
|
||||
{
|
||||
return await home.FramesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (HomeUnavailableException ex)
|
||||
{
|
||||
throw new WorkspaceException(refused, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Free bytes on the drive of <paramref name="folder"/>; null when it cannot be measured (a network share).</summary>
|
||||
private static long? FreeBytes(string folder)
|
||||
{
|
||||
try
|
||||
{
|
||||
var root = Path.GetPathRoot(Path.GetFullPath(folder));
|
||||
return string.IsNullOrEmpty(root) ? null : new DriveInfo(root).AvailableFreeSpace;
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or IOException or UnauthorizedAccessException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user