The desktop now uses the per-home layout from P3.1: each home keeps its own projects, proxies and originals, and a server is known by its id whichever address reaches it. - Settings keep the known servers (id, name, last address, certificate, aliases, originals archive). Reset and Import keep them; Export leaves them out. - SyncHost records each server the first time it signs in with an id. It names the cache and workspace folders by that id, and re-keys the folders a server had under its addresses at sign-in. The re-key waits while transfer or workspace jobs are pending. - Download originals goes to the server's own archive. It is created beside this PC's archive at the first download, and a toast says where. A sequence that already has a local copy keeps receiving into that copy's archive. A server without an id keeps the 1.0 behaviour. - At start, after the index opens and before any job runs, the folders are sorted into their homes. A toast reports the result: sorted, pending or failed. - The workspace host gives each home's store its own sync. Find, List, usage, clean-up and the trash plan and empty cover every home. Server comparisons go through the identity, so a project stays Online when its server is reached by another address. - The render-node downloads and the server import staging move into the server's folder of the cache. The cache trim keeps `servers`, and the scheduled scan also scans the originals archives. - Settings shows the Home folders rows (Workspace) and the Known servers table (Server). The diagnostics bundle lists the homes. - The dead `AppPaths.CreateDirectories` and `ThumbnailsDirectory` are removed. Refs #66 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
4.5 KiB
C#
98 lines
4.5 KiB
C#
using System.IO;
|
||
using System.Windows.Input;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Data.Workspaces;
|
||
using Chronos.Ui.Mvvm;
|
||
|
||
namespace Chronos.App.Settings;
|
||
|
||
/// <summary>
|
||
/// One home's folder in Settings › Workspace › Home folders (owner review 5, #66): "This PC" for the projects of this PC's
|
||
/// archive (<c>local</c>), one row per server for its projects (<c>servers\<id></c>), with Open.
|
||
/// </summary>
|
||
public sealed class HomeFolderRow(string name, string path, string toolTip, Action<string> open)
|
||
{
|
||
public string Name { get; } = name;
|
||
|
||
/// <summary>The folder as shown (a capture's own folders stand for the real ones).</summary>
|
||
public string Path { get; } = AppEnvironment.Shown(path);
|
||
|
||
public string ToolTip { get; } = toolTip;
|
||
|
||
public ICommand OpenCommand { get; } = new RelayCommand(() => open(path));
|
||
|
||
/// <summary>The rows of the workspace's homes: this PC first, then each server by name; none while the workspace is not made.</summary>
|
||
public static IReadOnlyList<HomeFolderRow> Of(WorkspaceHomes homes, IReadOnlyList<KnownServer> known, Action<string> open)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(homes);
|
||
ArgumentNullException.ThrowIfNull(known);
|
||
ArgumentNullException.ThrowIfNull(open);
|
||
if (!homes.IsSplit) return [new HomeFolderRow(Loc.L("Settings.Workspace.ThisPc"), homes.Root, Loc.L("Tooltips.Settings.Workspace.ThisPc", AppEnvironment.Shown(homes.Root)), open)];
|
||
var rows = new List<HomeFolderRow>
|
||
{
|
||
new(Loc.L("Settings.Workspace.ThisPc"), homes.LocalRoot, Loc.L("Tooltips.Settings.Workspace.ThisPc", AppEnvironment.Shown(homes.LocalRoot)), open),
|
||
};
|
||
foreach (var home in homes.Homes().Where(h => h is { IsLocal: false, IsLegacy: false }).OrderBy(h => NameOf(h, known), StringComparer.CurrentCultureIgnoreCase))
|
||
{
|
||
var name = NameOf(home, known);
|
||
rows.Add(new HomeFolderRow(name, home.Store.Root,
|
||
Loc.L("Tooltips.Settings.Workspace.ServerHome", name, AppEnvironment.Shown(home.Store.Root)), open));
|
||
}
|
||
return rows;
|
||
}
|
||
|
||
/// <summary>The server's name as this PC knows it, else as its folder records it, else the folder's name.</summary>
|
||
private static string NameOf(WorkspaceHome home, IReadOnlyList<KnownServer> known) =>
|
||
(home.Server?.Id is { } id ? known.FirstOrDefault(k => k.Id == id)?.Name : null)
|
||
?? home.Server?.Name ?? home.Server?.Address ?? System.IO.Path.GetFileName(home.Store.Root);
|
||
}
|
||
|
||
/// <summary>
|
||
/// A server this PC signed in to, in Settings › Server › Known servers (owner review 5, #66): its name, last address, id
|
||
/// (short, the whole one in the tooltip), whether this PC is signed in to it now, and its folders: the archive of its
|
||
/// downloaded originals and its share of the cache, each with Open.
|
||
/// </summary>
|
||
public sealed class KnownServerRow
|
||
{
|
||
private readonly string? _originals;
|
||
private readonly string _cache;
|
||
|
||
public KnownServerRow(KnownServer server, bool signedIn, string? originalsRoot, string cacheFolder, Action<string> open)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(server);
|
||
ArgumentNullException.ThrowIfNull(open);
|
||
Server = server;
|
||
IsSignedIn = signedIn;
|
||
_originals = originalsRoot;
|
||
_cache = cacheFolder;
|
||
OpenOriginalsCommand = new RelayCommand(() => open(_originals!), () => _originals is not null && Directory.Exists(_originals));
|
||
OpenCacheCommand = new RelayCommand(() => open(_cache), () => Directory.Exists(_cache));
|
||
}
|
||
|
||
public KnownServer Server { get; }
|
||
|
||
public string Name => Server.Name is { Length: > 0 } name ? name : Server.LastAddress ?? Server.Id.ToString("N");
|
||
|
||
public string Address => Server.LastAddress ?? "—";
|
||
|
||
/// <summary>The first 8 hex digits of the id; the tooltip has it whole.</summary>
|
||
public string ShortId => Server.Id.ToString("N")[..8];
|
||
|
||
public string IdToolTip => Loc.L("Tooltips.Settings.Server.ServerId", Server.Id.ToString("D"));
|
||
|
||
public bool IsSignedIn { get; }
|
||
|
||
public string StateText => Loc.L(IsSignedIn ? "Settings.Server.SignedIn" : "Settings.Server.Offline");
|
||
|
||
public string StateToolTip => Loc.L(IsSignedIn ? "Tooltips.Settings.Server.SignedIn" : "Tooltips.Settings.Server.Offline");
|
||
|
||
public string OriginalsPath => _originals is null ? "—" : AppEnvironment.Shown(_originals);
|
||
|
||
public string CachePath => AppEnvironment.Shown(_cache);
|
||
|
||
public ICommand OpenOriginalsCommand { get; }
|
||
|
||
public ICommand OpenCacheCommand { get; }
|
||
}
|