fix(workspace): settle conflicts in one answer and give refused folders a way on
Phase 5a fix round 2 of owner review 2 (desktop):
- Take library's no longer commits the working state first, so a take that
leaves only the library's values sends no empty version; the working state
it replaces is kept aside in versions/.replaced, outside the chain.
- Conflicts list this side's value as the working state holds it, so one
answer settles them instead of asking again for the newer value.
- A conflict of format (library saved by a newer Chronos) offers only Save
both and Later, says why in its tooltip and shows no raw format numbers.
- Conflict lines count the photos a setting differs on ("Excluded frames
(3)") instead of dropping the duplicates.
- A read-only library is named as such, not as offline; checkouts from it
stay editable and their versions wait in the workspace.
- A workspace folder refused inside a library offers Choose folder, and
Settings > Workspace gets Change...: a plan (projects left, projects found)
is confirmed before the folder changes; nothing is moved.
- Open in workspace shows the copy's size and the drive's free space, and
warns when the copy would not fit with its 0.5 GB reserve.
- A cancelled first copy removes the half media it wrote.
- A copy whose project.chronos cannot be read is listed as damaged instead of
hidden, and goes only through Remove local copy > Discard, after a plan.
- Pruning keeps a version whose archive file is damaged (test added).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8256b72913
commit
64fc5521c0
30 files changed
+1017
-98
No files matched your search
@@ -558,7 +558,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
if (background && _asking is { IsClosed: false }) return;
|
||||
var lines = WorkspaceText.ConflictLines(conflict.Differences, 10);
|
||||
var dialog = new ConflictDialogViewModel(Name, WorkspaceHost.SiblingName(_source.Workspace?.Name ?? Name), lines, choice => ResolveAsync(choice, conflict),
|
||||
_ui.CloseDialog);
|
||||
_ui.CloseDialog, conflict.NewerFormat);
|
||||
if (!background)
|
||||
{
|
||||
// Asked now: one still waiting from the background (or showing, which this one replaces) would only repeat an older list.
|
||||
|
||||
@@ -49,11 +49,20 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
private bool _isNew;
|
||||
|
||||
/// <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>
|
||||
public OpenInWorkspaceDialogViewModel(string sequenceTitle, IReadOnlyList<SequenceProject> projects, Action<ArchiveDialogViewModel> close,
|
||||
IReadOnlyList<string>? taken = null)
|
||||
IReadOnlyList<string>? taken = null, WorkspaceCopyFacts? copy = null)
|
||||
: base(close)
|
||||
{
|
||||
SequenceTitle = sequenceTitle;
|
||||
Copy = copy;
|
||||
CopyFacts = copy is null ? []
|
||||
:
|
||||
[
|
||||
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")),
|
||||
];
|
||||
Projects = [.. projects.OrderByDescending(p => p.IsMain).Select(p => new ProjectOption(p))];
|
||||
_selected = Projects.FirstOrDefault();
|
||||
_isNew = Projects.Count == 0;
|
||||
@@ -68,6 +77,15 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
|
||||
public string SequenceTitle { get; }
|
||||
|
||||
/// <summary>The copy's bytes and the drive's free space, when measured.</summary>
|
||||
public WorkspaceCopyFacts? Copy { get; }
|
||||
|
||||
/// <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;
|
||||
|
||||
public string Heading => Loc.L("Editor.OpenWorkspace.Title");
|
||||
|
||||
public IReadOnlyList<ProjectOption> Projects { get; }
|
||||
@@ -381,25 +399,35 @@ public sealed class HistoryDialogViewModel : ArchiveDialogViewModel
|
||||
/// <summary>
|
||||
/// A sync that met settings both sides changed (owner review 2, R8: asked only on real conflicts): what differs, then
|
||||
/// Keep mine, Take the library's, or Save both (this workspace's versions go to a sibling project). Later leaves the
|
||||
/// conflict for the next Sync; editing goes on meanwhile.
|
||||
/// conflict for the next Sync; editing goes on meanwhile. A conflict of format (the library's project saved by a newer
|
||||
/// Chronos, <see cref="WorkspaceConflict.NewerFormat"/>) cannot be merged either way: only Save both and Later are offered.
|
||||
/// </summary>
|
||||
public sealed class ConflictDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
private readonly Func<ConflictChoice, Task> _resolve;
|
||||
|
||||
/// <param name="newerFormat">The library holds a newer Chronos's settings: nothing is merged, Save both is the only choice.</param>
|
||||
public ConflictDialogViewModel(string projectName, string siblingName, IReadOnlyList<string> differences, Func<ConflictChoice, Task> resolve,
|
||||
Action<ArchiveDialogViewModel> close)
|
||||
Action<ArchiveDialogViewModel> close, bool newerFormat = false)
|
||||
: base(close)
|
||||
{
|
||||
ProjectName = projectName;
|
||||
SiblingName = siblingName;
|
||||
Differences = differences;
|
||||
IsNewerFormat = newerFormat;
|
||||
// The format's number says nothing to the user: the line names the cause.
|
||||
Differences = newerFormat ? [Loc.L("Editor.Workspace.Conflict.NewerFormat")] : differences;
|
||||
_resolve = resolve;
|
||||
KeepMineCommand = new AsyncRelayCommand(() => ResolveAsync(ConflictChoice.KeepMine), () => !IsBusy);
|
||||
TakeHomeCommand = new AsyncRelayCommand(() => ResolveAsync(ConflictChoice.TakeServer), () => !IsBusy);
|
||||
KeepMineCommand = new AsyncRelayCommand(() => ResolveAsync(ConflictChoice.KeepMine), () => !IsBusy && CanMerge);
|
||||
TakeHomeCommand = new AsyncRelayCommand(() => ResolveAsync(ConflictChoice.TakeServer), () => !IsBusy && CanMerge);
|
||||
SaveBothCommand = new AsyncRelayCommand(() => ResolveAsync(ConflictChoice.SaveBoth), () => !IsBusy);
|
||||
}
|
||||
|
||||
/// <summary>The library's project was saved by a newer Chronos.</summary>
|
||||
public bool IsNewerFormat { get; }
|
||||
|
||||
/// <summary>Keep mine and Take the library's are offered (not for a conflict of format, which neither can settle).</summary>
|
||||
public bool CanMerge => !IsNewerFormat;
|
||||
|
||||
public string ProjectName { get; }
|
||||
|
||||
/// <summary>The project Save both makes for this workspace's versions.</summary>
|
||||
@@ -407,17 +435,19 @@ public sealed class ConflictDialogViewModel : ArchiveDialogViewModel
|
||||
|
||||
public string Heading => Loc.L("Editor.Workspace.Conflict.Title");
|
||||
|
||||
public string Message => Loc.L("Editor.Workspace.Conflict.Message", ProjectName);
|
||||
public string Message => Loc.L(IsNewerFormat ? "Editor.Workspace.Conflict.NewerMessage" : "Editor.Workspace.Conflict.Message", ProjectName);
|
||||
|
||||
public IReadOnlyList<string> Differences { get; }
|
||||
|
||||
public string DifferencesToolTip => Loc.L(IsNewerFormat ? "Tooltips.Editor.Workspace.NewerFormat" : "Tooltips.Editor.Workspace.Differences");
|
||||
|
||||
public ICommand KeepMineCommand { get; }
|
||||
|
||||
public ICommand TakeHomeCommand { get; }
|
||||
|
||||
public ICommand SaveBothCommand { get; }
|
||||
|
||||
public string SaveBothToolTip => Loc.L("Tooltips.Editor.Workspace.SaveBoth", SiblingName);
|
||||
public string SaveBothToolTip => Loc.L(IsNewerFormat ? "Tooltips.Editor.Workspace.SaveBothNewer" : "Tooltips.Editor.Workspace.SaveBoth", SiblingName);
|
||||
|
||||
private async Task ResolveAsync(ConflictChoice choice)
|
||||
{
|
||||
@@ -442,7 +472,8 @@ public sealed class ConflictDialogViewModel : ArchiveDialogViewModel
|
||||
/// "Remove local copy": the plan (files and size of the copy; versions not sent and changes not saved), then Remove
|
||||
/// (only when everything is at the library), Send first (sends, then removes), or Discard changes (removes once the
|
||||
/// user typed the project's name; the unsent work is kept aside in the workspace's trash). A project the library no
|
||||
/// longer has (<see cref="WorkspaceRemovalPlan.Gone"/>) can only be discarded that way.
|
||||
/// longer has (<see cref="WorkspaceRemovalPlan.Gone"/>), or a copy whose working state cannot be read
|
||||
/// (<see cref="WorkspaceRemovalPlan.Damaged"/>), can only be discarded that way.
|
||||
/// </summary>
|
||||
public sealed class RemoveCopyDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
@@ -466,7 +497,7 @@ public sealed class RemoveCopyDialogViewModel : ArchiveDialogViewModel
|
||||
new DialogFact(Loc.L("Editor.RemoveCopy.Changed"), Loc.L(plan.Modified ? "Editor.RemoveCopy.Yes" : "Editor.RemoveCopy.No")),
|
||||
];
|
||||
RemoveCommand = new AsyncRelayCommand(() => RunAsync(() => _remove(false)), () => !IsBusy && plan.IsSafe && !plan.Offline && !plan.Gone);
|
||||
SendFirstCommand = new AsyncRelayCommand(() => RunAsync(_sendFirst), () => !IsBusy && !plan.IsSafe && !plan.Conflict && !plan.Offline && !plan.Gone);
|
||||
SendFirstCommand = new AsyncRelayCommand(() => RunAsync(_sendFirst), () => !IsBusy && !plan.IsSafe && !plan.Conflict && !plan.Offline && !plan.Gone && !plan.Damaged);
|
||||
DiscardCommand = new AsyncRelayCommand(DiscardAsync, () => !IsBusy && HasUnsent);
|
||||
}
|
||||
|
||||
@@ -485,12 +516,14 @@ public sealed class RemoveCopyDialogViewModel : ArchiveDialogViewModel
|
||||
|
||||
public ICommand DiscardCommand { get; }
|
||||
|
||||
public string RemoveToolTip => Plan.Gone ? Loc.L("Errors.Workspace.ProjectGone")
|
||||
public string RemoveToolTip => Plan.Damaged ? Loc.L("Errors.Workspace.Damaged")
|
||||
: Plan.Gone ? Loc.L("Errors.Workspace.ProjectGone")
|
||||
: !Plan.IsSafe ? Loc.L("Errors.Workspace.Unsent")
|
||||
: Plan.Offline ? Loc.L("Errors.Workspace.Offline")
|
||||
: Loc.L("Tooltips.Editor.RemoveCopy.Remove");
|
||||
|
||||
public string SendFirstToolTip => Plan.Gone ? Loc.L("Errors.Workspace.ProjectGone")
|
||||
public string SendFirstToolTip => Plan.Damaged ? Loc.L("Errors.Workspace.Damaged")
|
||||
: Plan.Gone ? Loc.L("Errors.Workspace.ProjectGone")
|
||||
: Plan.Conflict ? Loc.L("Errors.Workspace.Conflict")
|
||||
: Plan.Offline ? Loc.L("Errors.Workspace.Offline")
|
||||
: Loc.L("Tooltips.Editor.RemoveCopy.SendFirst");
|
||||
|
||||
@@ -51,6 +51,23 @@
|
||||
ToolTip="{l:Loc Tooltips.Editor.OpenWorkspace.Originals}" ToolTipService.ShowOnDisabled="True" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<!-- What the copy writes and the room the workspace's drive has for it. -->
|
||||
<ItemsControl ItemsSource="{Binding CopyFacts}" Focusable="False" Margin="0,14,0,0" Grid.IsSharedSizeScope="True">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type ar:DialogFact}">
|
||||
<Grid Margin="0,0,0,6">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="116" SharedSizeGroup="CopyFactLabel" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding Label}" Style="{StaticResource Text.DialogLabel}" />
|
||||
<TextBlock Grid.Column="1" Text="{Binding Value}" TextTrimming="CharacterEllipsis" ToolTip="{Binding ToolTip}" Typography.NumeralAlignment="Tabular" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ui:StatusGlyph Kind="Warning" Text="{l:Loc Editor.OpenWorkspace.NoRoom}" ToolTip="{l:Loc Errors.Workspace.NoRoom}" FontSize="12" HorizontalAlignment="Left"
|
||||
Margin="116,2,0,0" Visibility="{Binding IsShortOfSpace, Converter={StaticResource BoolToVisibility}}" />
|
||||
<DockPanel Margin="0,20,0,0">
|
||||
<Button DockPanel.Dock="Right" Style="{StaticResource Button.Primary}" Content="{l:Loc Editor.OpenWorkspace.Open}" Command="{Binding OpenCommand}"
|
||||
ToolTip="{Binding OpenToolTip}" ToolTipService.ShowOnDisabled="True" IsDefault="True" MinWidth="96" Margin="8,0,0,0" />
|
||||
@@ -188,13 +205,13 @@
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
|
||||
<!-- A sync that met settings both sides changed: what differs, then Keep mine, Take the library's, Save both, or Later. -->
|
||||
<!-- A sync that met settings both sides changed: what differs, then Keep mine, Take the library's, Save both, or Later (only Save both and Later for a newer Chronos's project). -->
|
||||
<DataTemplate DataType="{x:Type ws:ConflictDialogViewModel}">
|
||||
<Border Style="{StaticResource Border.Dialog}" Width="560">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextWrapping="Wrap" TextTrimming="None" />
|
||||
<TextBlock Text="{Binding Message}" Margin="0,8,0,0" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" LineHeight="18" />
|
||||
<Border Style="{StaticResource Border.Card}" Margin="0,14,0,0" Padding="12,10" ToolTip="{l:Loc Tooltips.Editor.Workspace.Differences}">
|
||||
<Border Style="{StaticResource Border.Card}" Margin="0,14,0,0" Padding="12,10" ToolTip="{Binding DifferencesToolTip}">
|
||||
<ItemsControl ItemsSource="{Binding Differences}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
@@ -206,11 +223,17 @@
|
||||
<WrapPanel HorizontalAlignment="Right" Margin="0,20,0,0">
|
||||
<Button Content="{l:Loc Editor.Workspace.Conflict.Later}" Command="{Binding CloseCommand}" ToolTip="{l:Loc Tooltips.Editor.Workspace.Later}" IsCancel="True"
|
||||
MinWidth="96" Margin="0,0,8,8" />
|
||||
<Button Content="{l:Loc Server.Sync.Action.SaveBoth}" Command="{Binding SaveBothCommand}" ToolTip="{Binding SaveBothToolTip}" MinWidth="96" Margin="0,0,8,8" />
|
||||
<Button Content="{l:Loc Server.Sync.Action.SaveBoth}" Command="{Binding SaveBothCommand}" ToolTip="{Binding SaveBothToolTip}" MinWidth="96" Margin="0,0,8,8"
|
||||
Visibility="{Binding CanMerge, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Button Content="{l:Loc Editor.Workspace.Conflict.TakeHome}" Command="{Binding TakeHomeCommand}" ToolTip="{l:Loc Tooltips.Editor.Workspace.TakeHome}"
|
||||
MinWidth="96" Margin="0,0,8,8" />
|
||||
MinWidth="96" Margin="0,0,8,8" Visibility="{Binding CanMerge, Converter={StaticResource BoolToVisibility}}" />
|
||||
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Server.Sync.Action.KeepMine}" Command="{Binding KeepMineCommand}"
|
||||
ToolTip="{l:Loc Tooltips.Editor.Workspace.KeepMine}" IsDefault="True" MinWidth="96" Margin="0,0,0,8" />
|
||||
ToolTip="{l:Loc Tooltips.Editor.Workspace.KeepMine}" IsDefault="{Binding CanMerge, Mode=OneWay}" MinWidth="96" Margin="0,0,0,8"
|
||||
Visibility="{Binding CanMerge, Converter={StaticResource BoolToVisibility}}" />
|
||||
<!-- A conflict of format: Save both is the only choice that settles it. -->
|
||||
<Button Style="{StaticResource Button.Primary}" Content="{l:Loc Server.Sync.Action.SaveBoth}" Command="{Binding SaveBothCommand}" ToolTip="{Binding SaveBothToolTip}"
|
||||
IsDefault="{Binding IsNewerFormat, Mode=OneWay}" MinWidth="96" Margin="0,0,0,8"
|
||||
Visibility="{Binding CanMerge, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
|
||||
</WrapPanel>
|
||||
<ui:StatusGlyph Style="{StaticResource Status.DialogError}" HorizontalAlignment="Right" />
|
||||
</StackPanel>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.IO;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Localization;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// Choosing another workspace folder (owner review 2, R8): Settings › Workspace › Change, and the refusal of a folder
|
||||
/// inside a library, where Edit cannot be used until one is chosen. The folder is picked, its plan shown and confirmed
|
||||
/// (the projects the folder in use keeps, those the new one holds), a workspace project open in the editor closes (its
|
||||
/// last edit stored first), and only then does the setting change. Nothing is moved or deleted: the projects of the
|
||||
/// folder left stay there, listed again once it is chosen back. Moving a workspace with its projects comes in phase 5c.
|
||||
/// </summary>
|
||||
public static class WorkspaceFolderChange
|
||||
{
|
||||
/// <summary>The shell's flow: its folder picker and confirmation, its editor, its toasts.</summary>
|
||||
public static async Task<bool> ChooseAsync(ShellViewModel shell)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shell);
|
||||
var changed = await ChooseAsync(shell.Services.Workspace, shell.Services.Dialogs, async () =>
|
||||
{
|
||||
if (shell.Sequence.Editor?.Session.Source is not WorkspaceSequenceSource) return true;
|
||||
if (!await shell.Sequence.ConfirmCloseAsync()) return false;
|
||||
await shell.Sequence.CloseAsync();
|
||||
shell.KeepSequence(null);
|
||||
return true;
|
||||
}, message => shell.Notify(Loc.L("Settings.Workspace.NotChanged"), message, isError: true));
|
||||
if (changed) shell.Notify(Loc.L("Settings.Workspace.Changed"), shell.Services.Workspace.Root);
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Picks a folder through <paramref name="dialogs"/>, confirms its plan, lets <paramref name="closeProject"/> close a
|
||||
/// workspace project open in the editor (false keeps everything as it is), then makes it the workspace's folder.
|
||||
/// <paramref name="failed"/> hears why a folder was refused. True when the folder changed.
|
||||
/// </summary>
|
||||
public static async Task<bool> ChooseAsync(WorkspaceHost host, IAppDialogs dialogs, Func<Task<bool>> closeProject, Action<string> failed)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(host);
|
||||
ArgumentNullException.ThrowIfNull(dialogs);
|
||||
ArgumentNullException.ThrowIfNull(closeProject);
|
||||
ArgumentNullException.ThrowIfNull(failed);
|
||||
if (dialogs.PickFolder(Loc.L("Settings.Workspace.ChooseTitle"), Directory.Exists(host.Root) ? host.Root : null) is not { } folder) return false;
|
||||
try
|
||||
{
|
||||
var plan = await host.PlanFolderAsync(folder);
|
||||
if (plan.IsSame) return false;
|
||||
if (plan.InsideLibrary)
|
||||
{
|
||||
failed(Loc.L("Errors.Workspace.InsideLibraryFolder", plan.Folder));
|
||||
return false;
|
||||
}
|
||||
if (!dialogs.Confirm(Request(plan))) return false;
|
||||
if (!await closeProject()) return false;
|
||||
await host.UseFolderAsync(plan.Folder);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or ArgumentException or WorkspaceException)
|
||||
{
|
||||
Log.Warning("workspace", $"The workspace folder was not changed to {folder}", ex);
|
||||
failed(ex is WorkspaceException ? ex.Message : Loc.L("Errors.Workspace.FolderUnusable", folder));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Settings.Workspace.ChangeTitle"),
|
||||
Message = Loc.L("Settings.Workspace.ChangeMessage", plan.Folder, plan.Current),
|
||||
Detail = string.Join(Environment.NewLine, Loc.L("Settings.Workspace.ProjectsLeft", Formatting.Count(plan.ProjectsLeft)),
|
||||
Loc.L("Settings.Workspace.ProjectsFound", Formatting.Count(plan.ProjectsFound))),
|
||||
IsDetailMonospaced = false,
|
||||
SafeText = Loc.L("Archive.Dialog.Cancel"),
|
||||
SafeToolTip = Loc.L("Tooltips.Settings.KeepWorkspace"),
|
||||
ActionText = Loc.L("Settings.Workspace.Use"),
|
||||
ActionToolTip = Loc.L("Tooltips.Settings.UseWorkspace"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,39 @@ using Chronos.Data.Workspaces;
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>A workspace operation was refused for a reason the user can act on; the message is one localized sentence.</summary>
|
||||
public sealed class WorkspaceException(string message, Exception? inner = null) : InvalidOperationException(message, inner);
|
||||
public sealed class WorkspaceException(string message, Exception? inner = null) : InvalidOperationException(message, inner)
|
||||
{
|
||||
/// <summary>The workspace folder itself was refused (it lies inside a library): another folder is the way on (Settings › Workspace › Change).</summary>
|
||||
public bool FolderRefused { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>A project of this PC's workspace, as Edit's picker and the editor list it.</summary>
|
||||
/// <param name="HasMedia">The workspace holds the project's media (a copy that ended); without them it cannot open.</param>
|
||||
/// <param name="Saved">When its working state was last written.</param>
|
||||
/// <param name="Damaged">
|
||||
/// Its working state (<c>project.chronos</c>) cannot be read: listed by its folder, it cannot open, and Remove local copy
|
||||
/// can only keep its files aside in the workspace's trash (Discard).
|
||||
/// </param>
|
||||
public sealed record WorkspaceEntry(Guid ProjectId, Guid SequenceId, string Name, bool IsMain, BundleHome Home, string SequenceTitle, bool HasMedia,
|
||||
DateTimeOffset Saved);
|
||||
DateTimeOffset Saved, bool Damaged = false);
|
||||
|
||||
/// <summary>What changing the workspace folder to <see cref="Folder"/> does: Edit lists its projects from then on; nothing is moved.</summary>
|
||||
/// <param name="Current">The folder in use, whose projects stay where they are (listed again once it is chosen back).</param>
|
||||
/// <param name="ProjectsLeft">The projects the folder in use holds.</param>
|
||||
/// <param name="ProjectsFound">The projects <see cref="Folder"/> holds already (a workspace used before).</param>
|
||||
/// <param name="InsideLibrary">The folder lies inside a library: refused, as the copy would put its files among the library's.</param>
|
||||
public sealed record WorkspaceFolderPlan(string Current, string Folder, int ProjectsLeft, int ProjectsFound, bool InsideLibrary)
|
||||
{
|
||||
/// <summary>The folder chosen is the one in use: nothing to change.</summary>
|
||||
public bool IsSame => string.Equals(Path.TrimEndingDirectorySeparator(Current), Path.TrimEndingDirectorySeparator(Folder), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
|
||||
/// <summary>A project brought into the workspace and the copy of its media that was queued.</summary>
|
||||
public sealed record WorkspaceCheckout(SequenceProject Project, Job Copy);
|
||||
@@ -43,10 +69,12 @@ public sealed record WorkspaceHistory(IReadOnlyList<ProjectVersion> Versions, IR
|
||||
/// The home answered it no longer has the project or its sequence: nothing can be sent or checked there, so the copy can
|
||||
/// only go with its work kept aside (Discard).
|
||||
/// </param>
|
||||
public sealed record WorkspaceRemovalPlan(Guid ProjectId, string Name, int Files, long Bytes, int Unsent, bool Modified, bool Conflict, bool Offline, bool Gone = false)
|
||||
/// <param name="Damaged">The working state cannot be read: what it holds is not known, so the copy can only go with its files kept aside (Discard).</param>
|
||||
public sealed record WorkspaceRemovalPlan(Guid ProjectId, string Name, int Files, long Bytes, int Unsent, bool Modified, bool Conflict, bool Offline, bool Gone = false,
|
||||
bool Damaged = false)
|
||||
{
|
||||
/// <summary>Everything the copy holds is at the home: it can go without discarding anything.</summary>
|
||||
public bool IsSafe => Unsent == 0 && !Modified && !Conflict;
|
||||
public bool IsSafe => Unsent == 0 && !Modified && !Conflict && !Damaged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,33 +175,87 @@ public sealed class WorkspaceHost
|
||||
HomeOf(new BundleHome(BundleHome.ArchiveKind, sequenceId)) ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
|
||||
/// <summary>
|
||||
/// The projects of the workspace (one whose working state cannot be read is left out, and logged). A workspace folder
|
||||
/// not made yet that lies inside a library is not made by listing it: it lists nothing.
|
||||
/// The projects of the workspace; one whose working state cannot be read is listed as damaged (<see cref="WorkspaceEntry.Damaged"/>),
|
||||
/// never hidden, and logged. A workspace folder not made yet that lies inside a library is not made by listing it: it lists nothing.
|
||||
/// </summary>
|
||||
public Task<IReadOnlyList<WorkspaceEntry>> ListAsync(CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
if (!Directory.Exists(Root) && await InsideALibraryAsync(cancellationToken).ConfigureAwait(false)) return [];
|
||||
return (IReadOnlyList<WorkspaceEntry>)[.. Store.ListBundles().Select(b => Entry(b.Project, b.Bundle))];
|
||||
return (IReadOnlyList<WorkspaceEntry>)[.. Store.List().Select(EntryOrDamaged)];
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>The workspace projects of one sequence.</summary>
|
||||
public async Task<IReadOnlyList<WorkspaceEntry>> ProjectsOfAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
|
||||
[.. (await ListAsync(cancellationToken).ConfigureAwait(false)).Where(e => e.SequenceId == sequenceId)];
|
||||
|
||||
/// <summary>A workspace project by id; null when the workspace has none (or it cannot be read).</summary>
|
||||
/// <summary>A workspace project by id (damaged when its working state cannot be read); null when the workspace has none.</summary>
|
||||
public Task<WorkspaceEntry?> FindAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
if (!Directory.Exists(Root) && await InsideALibraryAsync(cancellationToken).ConfigureAwait(false)) return null;
|
||||
if (Store.Find(projectId) is not { } project) return null;
|
||||
try
|
||||
return Store.Find(projectId) is { } project ? EntryOrDamaged(project) : null;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// What changing the workspace folder to <paramref name="folder"/> would do (Settings › Workspace › Change, and the
|
||||
/// refusal of a folder inside a library): the projects the folder in use keeps where they are, those the new one holds
|
||||
/// already, and whether it lies inside a library. Nothing is written.
|
||||
/// </summary>
|
||||
public Task<WorkspaceFolderPlan> PlanFolderAsync(string folder, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(folder);
|
||||
var target = Path.GetFullPath(folder);
|
||||
return new WorkspaceFolderPlan(Root, target, CountProjects(Root), CountProjects(target), await InsideALibraryAsync(target, cancellationToken).ConfigureAwait(false));
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Edit's workspace becomes <paramref name="folder"/> (made, with its manifest, when it is new): Settings › Workspace ›
|
||||
/// Folder names it from now on (none when it is the default). The projects of the folder left stay there, untouched.
|
||||
/// </summary>
|
||||
/// <exception cref="WorkspaceException">The folder lies inside a library (<see cref="WorkspaceException.FolderRefused"/>).</exception>
|
||||
/// <exception cref="IOException">The folder cannot be made or read.</exception>
|
||||
/// <exception cref="InvalidDataException">The folder holds another program's or a newer workspace manifest.</exception>
|
||||
public async Task UseFolderAsync(string folder, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var plan = await PlanFolderAsync(folder, cancellationToken).ConfigureAwait(false);
|
||||
if (plan.IsSame) return;
|
||||
if (plan.InsideLibrary) throw new WorkspaceException(Loc.L("Errors.Workspace.InsideLibraryFolder", plan.Folder)) { FolderRefused = true };
|
||||
// Opened before it is named: a folder that is no workspace is refused while the one in use still is.
|
||||
await Task.Run(() => new WorkspaceStore(plan.Folder), cancellationToken).ConfigureAwait(false);
|
||||
// Back on the caller's thread (the UI's): the settings are written there.
|
||||
_settings.WorkspaceFolder = string.Equals(plan.Folder, Path.GetFullPath(DefaultRoot(_environment)), StringComparison.OrdinalIgnoreCase) ? null : plan.Folder;
|
||||
_savePreferences();
|
||||
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 () =>
|
||||
{
|
||||
return Entry(project, project.ReadBundle());
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
var (bytes, free) = await WorkspaceJobs.CopyFactsAsync(db, archives, sequenceId, root, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceCopyFacts(bytes, free);
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A first copy of a project's media cancelled before it ended: the photos it wrote (copies the home can make again)
|
||||
/// are removed, so the workspace holds no half media. A project whose copy ended once keeps its media (Update media
|
||||
/// cancelled leaves the earlier ones in use). False when there was nothing to remove.
|
||||
/// </summary>
|
||||
public Task<bool> RemovePartialMediaAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
if (Store.Find(projectId) is not { } project) return false;
|
||||
using (await project.LockAsync(LockWait, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
Log.Warning("workspace", $"The project in {project.Folder} cannot be read", ex);
|
||||
return null;
|
||||
if (File.Exists(project.MediaIndexPath) || !Directory.Exists(project.MediaDirectory)) return false;
|
||||
Directory.Delete(project.MediaDirectory, recursive: true);
|
||||
}
|
||||
Log.Info("workspace", $"The media a cancelled first copy of project {projectId} wrote were removed");
|
||||
return true;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>The project of <paramref name="sequenceId"/> opened last here, else the one saved last; null when the workspace has none.</summary>
|
||||
@@ -214,7 +296,8 @@ public sealed class WorkspaceHost
|
||||
var checkout = await Task.Run(async () =>
|
||||
{
|
||||
// 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));
|
||||
if (await InsideALibraryAsync(cancellationToken).ConfigureAwait(false))
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.InsideLibraryEdit", Root)) { FolderRefused = true };
|
||||
SequenceProject project;
|
||||
if (newName is not null)
|
||||
{
|
||||
@@ -505,6 +588,12 @@ public sealed class WorkspaceHost
|
||||
public Task<WorkspaceRemovalPlan> PlanRemovalAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
var project = Existing(projectId);
|
||||
if (EntryOrDamaged(project) is { Damaged: true } damaged)
|
||||
{
|
||||
// What it holds is not known: every version file not marked sent counts as unsent work, kept aside by Discard.
|
||||
var (count, size) = Measure(project.Folder);
|
||||
return new WorkspaceRemovalPlan(projectId, damaged.Name, count, size, project.Versions().Count(v => v.StoredAt is null), true, false, false, Damaged: true);
|
||||
}
|
||||
var name = project.ReadBundle().Workspace!.Name;
|
||||
var status = await StatusAsync(projectId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
var (files, bytes) = Measure(project.Folder);
|
||||
@@ -524,6 +613,14 @@ public sealed class WorkspaceHost
|
||||
var sequenceId = await Task.Run(async () =>
|
||||
{
|
||||
var project = Existing(projectId);
|
||||
if (EntryOrDamaged(project) is { Damaged: true })
|
||||
{
|
||||
// Its working state cannot be read: only Discard, which keeps every file of it aside, takes it out.
|
||||
if (!discard) throw new WorkspaceException(Loc.L("Errors.Workspace.Damaged"));
|
||||
await RemoveFolderAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Damaged local copy of project {projectId} removed, its files kept in {TrashFolder}");
|
||||
return (Guid?)null;
|
||||
}
|
||||
var workspace = project.ReadBundle().Workspace!;
|
||||
if (!discard)
|
||||
{
|
||||
@@ -533,9 +630,9 @@ public sealed class WorkspaceHost
|
||||
}
|
||||
await RemoveFolderAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Local copy of project {projectId} ('{workspace.Name}') removed{(discard ? ", its unsent work kept in " + TrashFolder : string.Empty)}");
|
||||
return workspace.Home.SequenceId;
|
||||
return (Guid?)workspace.Home.SequenceId;
|
||||
}, cancellationToken);
|
||||
Forget(sequenceId, projectId);
|
||||
if (sequenceId is { } sequence) Forget(sequence, projectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -657,10 +754,12 @@ public sealed class WorkspaceHost
|
||||
/// The workspace folder lies inside a library this index knows (a portable copy's <c>data</c> folder under a library
|
||||
/// at a drive's root): editing happens outside every library, so nothing is checked out or copied there.
|
||||
/// </summary>
|
||||
private async Task<bool> InsideALibraryAsync(CancellationToken cancellationToken)
|
||||
private Task<bool> InsideALibraryAsync(CancellationToken cancellationToken) => InsideALibraryAsync(Root, cancellationToken);
|
||||
|
||||
private async Task<bool> InsideALibraryAsync(string folder, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_db() is not { } db) return false;
|
||||
var root = Plain(Path.GetFullPath(Root));
|
||||
var root = Plain(Path.GetFullPath(folder));
|
||||
foreach (var archive in await db.Archives.ListAsync(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (DataLocation.IsUnder(root, Plain(Path.GetFullPath(archive.RootPath)))) return true;
|
||||
@@ -710,6 +809,38 @@ public sealed class WorkspaceHost
|
||||
bundle.Sequence.Title is { Length: > 0 } title ? title : bundle.Sequence.Folder, File.Exists(project.MediaIndexPath), bundle.Saved);
|
||||
}
|
||||
|
||||
/// <summary>The project's entry; a damaged one, named by its folder, when its working state cannot be read (logged).</summary>
|
||||
private static WorkspaceEntry EntryOrDamaged(WorkspaceProject project)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Entry(project, project.ReadBundle());
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Warning("workspace", $"The project in {project.Folder} cannot be read", ex);
|
||||
var saved = File.Exists(project.BundlePath) ? new DateTimeOffset(File.GetLastWriteTimeUtc(project.BundlePath), TimeSpan.Zero) : DateTimeOffset.MinValue;
|
||||
return new WorkspaceEntry(project.ProjectId, Guid.Empty, Path.GetFileName(project.Folder), false, new BundleHome(BundleHome.ArchiveKind, Guid.Empty),
|
||||
project.Folder, false, saved, Damaged: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The projects a workspace folder holds (folders named by a project id with a working state), without making or opening it.</summary>
|
||||
private static int CountProjects(string folder)
|
||||
{
|
||||
if (!Directory.Exists(folder)) return 0;
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateDirectories(folder).Count(d => Guid.TryParseExact(Path.GetFileName(d), "N", out _)
|
||||
&& File.Exists(Path.Combine(d, WorkspaceProject.BundleFile)));
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Info("workspace", $"The projects of {folder} could not be counted: {ex.Message}");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Files and bytes under <paramref name="folder"/>, the lease left out.</summary>
|
||||
private static (int Files, long Bytes) Measure(string folder)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Chronos.App.Workspace;
|
||||
|
||||
/// <summary>
|
||||
/// A project of the workspace in Edit's picker (owner review 2, R8): its name, its sequence (title and thumbnail) and
|
||||
/// where it stands, a chip read from its home after the list shows.
|
||||
/// where it stands, a chip read from its home after the list shows. A copy whose working state cannot be read is listed
|
||||
/// as damaged, by its folder.
|
||||
/// </summary>
|
||||
public sealed class WorkspaceProjectItem(WorkspaceEntry entry, SequenceItem? sequence) : ObservableObject
|
||||
{
|
||||
@@ -41,11 +42,16 @@ public sealed class WorkspaceProjectItem(WorkspaceEntry entry, SequenceItem? seq
|
||||
}
|
||||
}
|
||||
|
||||
public string StateText => Entry.HasMedia || _status is not null ? WorkspaceText.State(_status) : Loc.L("Editor.Workspace.State.MediaRemoved");
|
||||
/// <summary>Its working state cannot be read: it cannot open, and Remove local copy keeps its files aside.</summary>
|
||||
public bool IsDamaged => Entry.Damaged;
|
||||
|
||||
public StatusKind StateKind => Entry.HasMedia || _status is not null ? WorkspaceText.Kind(_status) : StatusKind.NoProxies;
|
||||
public string StateText => Entry.Damaged ? Loc.L("Editor.Workspace.State.Damaged")
|
||||
: Entry.HasMedia || _status is not null ? WorkspaceText.State(_status) : Loc.L("Editor.Workspace.State.MediaRemoved");
|
||||
|
||||
public string StateToolTip => Entry.HasMedia || _status is not null ? WorkspaceText.StateToolTip(_status) : Loc.L("Tooltips.Editor.Workspace.State.MediaRemoved");
|
||||
public StatusKind StateKind => Entry.Damaged ? StatusKind.Error : Entry.HasMedia || _status is not null ? WorkspaceText.Kind(_status) : StatusKind.NoProxies;
|
||||
|
||||
public string StateToolTip => Entry.Damaged ? Loc.L("Tooltips.Editor.Workspace.State.Damaged")
|
||||
: Entry.HasMedia || _status is not null ? WorkspaceText.StateToolTip(_status) : Loc.L("Tooltips.Editor.Workspace.State.MediaRemoved");
|
||||
|
||||
/// <summary>"Vertical social · Harbour sunset · In sync": what screen readers hear for the row.</summary>
|
||||
public string Description => string.Join(Loc.Separator, Name, SequenceTitle, StateText);
|
||||
|
||||
@@ -71,9 +71,17 @@ public static class WorkspaceText
|
||||
/// <summary>"28/10/2026 18:02".</summary>
|
||||
public static string When(DateTimeOffset at) => $"{Formatting.Date(at)} {Formatting.TimeOfDay(at)}";
|
||||
|
||||
/// <summary>One line per setting both sides changed ("Deflicker window 41 here, 33 in the library"), at most <paramref name="max"/>.</summary>
|
||||
public static IReadOnlyList<string> ConflictLines(IEnumerable<SettingsDifference> differences, int max) =>
|
||||
SyncText.Differences(differences, max, (label, mine, theirs) => Loc.L("Editor.Workspace.Difference", label, mine, theirs));
|
||||
/// <summary>
|
||||
/// One line per setting both sides changed ("Deflicker window 41 here, 33 in the library"), at most <paramref name="max"/>.
|
||||
/// A conflict of format (<see cref="ProjectMerge.FormatPath"/>) reads as its cause, never as the format's numbers.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<string> ConflictLines(IEnumerable<SettingsDifference> differences, int max)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(differences);
|
||||
var list = differences.ToList();
|
||||
if (list.Any(d => d.Path == ProjectMerge.FormatPath)) return [Loc.L("Editor.Workspace.Conflict.NewerFormat")];
|
||||
return SyncText.Differences(list, max, (label, mine, theirs) => Loc.L("Editor.Workspace.Difference", label, mine, theirs));
|
||||
}
|
||||
|
||||
/// <summary>One line per setting that differs between now and a version ("Deflicker window 41 now, 33 in that version").</summary>
|
||||
public static IReadOnlyList<string> CompareLines(IEnumerable<SettingsDifference> differences, int max) =>
|
||||
@@ -83,6 +91,9 @@ public static class WorkspaceText
|
||||
public static string Failure(Exception ex) => ex switch
|
||||
{
|
||||
WorkspaceException or LeaseUnavailableException => ex.Message,
|
||||
// A library that can be read but not written (a read-only share, a write-protected disk): the work waits here as offline.
|
||||
HomeUnavailableException { InnerException: ArchiveOfflineException { Availability: ArchiveAvailability.ReadOnly } }
|
||||
or ArchiveOfflineException { Availability: ArchiveAvailability.ReadOnly } => Loc.L("Errors.Workspace.ReadOnlyHome"),
|
||||
HomeUnavailableException or ArchiveOfflineException => Loc.L("Errors.Workspace.Offline"),
|
||||
ProjectException { Reason: ProjectError.NameTaken } => Loc.L("Errors.Workspace.NameTaken"),
|
||||
ProjectException { Reason: ProjectError.InvalidName } => Loc.L("Errors.Workspace.InvalidName"),
|
||||
|
||||
Reference in new issue
Block a user