feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #68.
This commit is contained in:
1 parent
988068ee8e
commit
20d64af4a4
793 files changed
+23882
-2096
No files matched your search
@@ -44,6 +44,16 @@ public sealed class AppEnvironment
|
||||
public string LogDirectory => Path.Combine(DataDirectory, "logs");
|
||||
public string CacheDirectory => Path.Combine(DataDirectory, "cache");
|
||||
public string BackupDirectory => Path.Combine(DataDirectory, "backups");
|
||||
|
||||
/// <summary>The private folder of the server this PC runs while it shares its library: certificate, settings, uploads, logs.</summary>
|
||||
public string ShareDirectory => Path.Combine(DataDirectory, "server");
|
||||
|
||||
/// <summary>The PC's name as the screens show it: a capture shows <see cref="SamplePcName"/>.</summary>
|
||||
public string PcName => IsCapture ? SamplePcName : Environment.MachineName;
|
||||
|
||||
/// <summary>The PC name captures show.</summary>
|
||||
public const string SamplePcName = "STUDIO-PC";
|
||||
|
||||
public string DatabasePath => Path.Combine(DataDirectory, AppPaths.DatabaseFileName);
|
||||
public string SettingsPath => Path.Combine(DataDirectory, AppPaths.SettingsFileName);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using Chronos.App.About;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.Import;
|
||||
using Chronos.App.Jobs;
|
||||
@@ -13,14 +12,17 @@ using Chronos.App.Workspace;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Imaging.Decoders;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Updates;
|
||||
using Chronos.Core.Video.Managed;
|
||||
using Chronos.Core.Windows.MediaFoundation;
|
||||
using Chronos.Core.Windows.Wic;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Homes;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Data.Scheduling;
|
||||
@@ -72,12 +74,15 @@ public sealed class AppServices : IAsyncDisposable
|
||||
// The editor's open and closed groups survive a restart (owner review 1, R3).
|
||||
Chronos.App.Editor.EditorSettings.Groups.Bind(settings.EditorGroups, saveSettings);
|
||||
_renderNode = new RenderNodeHost(StartRenderNode);
|
||||
Share = new LibraryShare(this);
|
||||
ArchiveSetup = new EngineArchiveSetup(this);
|
||||
Sync = new SyncHost(this);
|
||||
ScheduleHost = new DesktopScheduleHost(settings, () => Database, () => Archives);
|
||||
Workspace = new WorkspaceHost(environment, settings, saveSettings, () => Database, () => Archives, () => Engine);
|
||||
// A server that keeps projects is the home of the workspace projects of its sequences (owner review 2, R8, phase 5b).
|
||||
Workspace.ServerHomes = Sync.ProjectHome;
|
||||
// A server home's folder is named by its server's id, whichever address reached it (owner review 5, #66).
|
||||
Workspace.Identity = () => Sync.Identity;
|
||||
Sync.ProjectChanged += Workspace.OnServerProjectChanged;
|
||||
Server = new ServerSession(settings, saveSettings, new ChronosServerApiFactory(), new DpapiTokenProtector());
|
||||
Encoders = new MediaFoundationInventory();
|
||||
@@ -110,6 +115,7 @@ public sealed class AppServices : IAsyncDisposable
|
||||
{
|
||||
if (_server is not null) _server.PropertyChanged -= OnServerChanged;
|
||||
_server = value;
|
||||
_server.IsOwnLibrary = Share.IsOwn;
|
||||
_server.PropertyChanged += OnServerChanged;
|
||||
UpdateRenderNode();
|
||||
Sync.Update();
|
||||
@@ -119,6 +125,9 @@ public sealed class AppServices : IAsyncDisposable
|
||||
/// <summary>Sync with the signed-in server: engine, job connection, background comparison.</summary>
|
||||
public SyncHost Sync { get; }
|
||||
|
||||
/// <summary>Settings › Server › Share this library: this PC's library served to the LAN while Chronos runs (owner review 5, #67).</summary>
|
||||
public LibraryShare Share { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A job of this PC moved a sequence's folder or changed its title or file names (a Reorganize step), or replaced its
|
||||
/// frames' files (a conversion), with the sequence's id (any thread): an open editor reads it again where and as it is now.
|
||||
@@ -151,6 +160,12 @@ public sealed class AppServices : IAsyncDisposable
|
||||
/// <summary>How the restore staged in Settings › Advanced went when the index opened; null when none was staged.</summary>
|
||||
public StagedRestoreResult? StagedRestore { get; private set; }
|
||||
|
||||
/// <summary>What the sorting of the folders into homes did when the index opened (owner review 5, #66); null when it had nothing to do.</summary>
|
||||
public HomeLayoutResult? HomeLayout { get; private set; }
|
||||
|
||||
/// <summary>Why the folders could not be sorted into homes when the index opened; null when they were, or had nothing to sort.</summary>
|
||||
public Exception? HomeLayoutError { get; private set; }
|
||||
|
||||
/// <summary>Card detection, eject and format (BRIEF §13); started with the index, replaced by a fake in capture.</summary>
|
||||
public IDeviceMonitor Devices { get; set; } = new WindowsDeviceMonitor();
|
||||
|
||||
@@ -201,7 +216,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
new(services.Processing?.Options ?? WorkspaceJobOptions.For(archives).Processing,
|
||||
() => services.Settings.PauseUploadsOnMetered && MeteredNetwork.IsMetered(),
|
||||
services.Workspace.MovedAsync,
|
||||
() => services.Workspace.Root);
|
||||
() => services.Workspace.Root,
|
||||
services.Workspace.SameServer);
|
||||
|
||||
/// <summary>
|
||||
/// Queues a scan of <paramref name="archive"/> unless one is already waiting or running; the sequences it indexes get
|
||||
@@ -228,6 +244,7 @@ public sealed class AppServices : IAsyncDisposable
|
||||
SaveSettingsAction();
|
||||
UpdateRenderNode();
|
||||
ApplyJobSettings();
|
||||
if (!Environment.IsCapture) Share.Apply();
|
||||
}
|
||||
|
||||
/// <summary>Writes the settings file and nothing else: for choices that change only what is shown (the rail, the sequence edited last).</summary>
|
||||
@@ -284,6 +301,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
_schedulerReady.TrySetResult(false);
|
||||
return;
|
||||
}
|
||||
// Before any job runs: the folders of the workspace and the cache go to their homes (owner review 5, #66).
|
||||
await SortHomesAsync(Database, ct);
|
||||
try
|
||||
{
|
||||
await StartJobsAsync(Database, startEngine: true, ct);
|
||||
@@ -316,6 +335,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
{
|
||||
await _stopping.CancelAsync().ConfigureAwait(false);
|
||||
await _schedules.ConfigureAwait(false);
|
||||
// First: the shared library's clients and its subscriptions to the engine and the scheduler go before they do.
|
||||
await Share.DisposeAsync().ConfigureAwait(false);
|
||||
_schedulerReady.TrySetResult(false);
|
||||
if (Scheduler is not null) await Scheduler.DisposeAsync().ConfigureAwait(false);
|
||||
_stopping.Dispose();
|
||||
@@ -348,6 +369,7 @@ public sealed class AppServices : IAsyncDisposable
|
||||
await StartSchedulerAsync(ct).ConfigureAwait(false);
|
||||
if (reopen is null)
|
||||
{
|
||||
await Share.StartAsync(ct).ConfigureAwait(false);
|
||||
await ScanNowAsync(started, ct).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
@@ -356,6 +378,7 @@ public sealed class AppServices : IAsyncDisposable
|
||||
{
|
||||
if (!string.Equals(reopen, Settings.LastArchivePath, StringComparison.OrdinalIgnoreCase)) return;
|
||||
if (!await ReopenAsync(reopen, ct).ConfigureAwait(false)) continue;
|
||||
await Share.StartAsync(ct).ConfigureAwait(false);
|
||||
await ScanNowAsync(null, ct).ConfigureAwait(false);
|
||||
Scheduler?.Wake();
|
||||
return;
|
||||
@@ -474,6 +497,66 @@ public sealed class AppServices : IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sorts the workspace's projects and the cache's server folders into their homes (owner review 5, #66:
|
||||
/// <see cref="HomeLayoutMigration"/>; renames only, a clash to the trash, never deleted), or takes up a sorting a previous
|
||||
/// start left half done. Projects in use or a workspace being moved wait for a later start; a failure is logged and kept
|
||||
/// for Settings to tell (<see cref="HomeLayoutError"/>), and the start goes on: the folders not sorted read as before.
|
||||
/// </summary>
|
||||
private async Task SortHomesAsync(ChronosDatabase database, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var migration = new HomeLayoutMigration(new HomeLayoutOptions
|
||||
{
|
||||
DataDirectory = Environment.DataDirectory,
|
||||
WorkspaceRoot = Workspace.IsEnabled ? Workspace.Root : null,
|
||||
CacheRoot = CacheStore.Folder(Environment, Settings),
|
||||
Identity = Sync.Identity,
|
||||
CurrentServer = Sync.LastServer,
|
||||
Database = database,
|
||||
});
|
||||
var result = await Task.Run(() => migration.ApplyAsync(ct), ct);
|
||||
if (result != HomeLayoutResult.Nothing)
|
||||
{
|
||||
HomeLayout = result;
|
||||
Log.Info("app", $"Folders sorted into homes: {result.ProjectsMoved} project(s), {result.EntriesMoved} entr(ies), {result.InUse} in use, "
|
||||
+ $"{result.Clashes} clash(es){(result.Deferred is { } deferred ? $", the workspace waits ({deferred})" : string.Empty)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeLayoutException or IOException or UnauthorizedAccessException or InvalidDataException or DatabaseException)
|
||||
{
|
||||
HomeLayoutError = ex;
|
||||
Log.Error("app", "The folders could not be sorted into homes; the next start tries again", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Workspace.Reopen();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The scan schedule scanned this PC's archive (any thread): the archives of the servers' downloaded originals are scanned
|
||||
/// after it (owner review 5, Q1: they are archives of their own, which the schedule, made for one archive, does not name).
|
||||
/// </summary>
|
||||
private void OnScheduledScanDone(Job job)
|
||||
{
|
||||
if (job is not { Kind: JobKind.Scan, State: JobState.Done, ScheduleId: not null, TargetIds: [var scanned] }) return;
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var archives = await Sync.OriginalsArchivesAsync(_stopping.Token).ConfigureAwait(false);
|
||||
if (archives.Any(a => a.Id == scanned)) return;
|
||||
foreach (var originals in archives) await QueueScanAsync(originals, full: false, _stopping.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is DatabaseException or InvalidOperationException or OperationCanceledException)
|
||||
{
|
||||
Log.Warning("app", "The archives of the servers' originals could not be queued to be scanned", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async Task StartJobsAsync(ChronosDatabase database, bool startEngine, CancellationToken ct)
|
||||
{
|
||||
_wic = new WicDecoderProvider();
|
||||
@@ -486,19 +569,24 @@ public sealed class AppServices : IAsyncDisposable
|
||||
MemoryBudget = () => ProcessingTuning.MemoryBudget(Settings, GC.GetGCMemoryInfo().TotalAvailableMemoryBytes),
|
||||
// The housekeeping schedule trims the cache to Settings › Storage › Cache limit (owner review 2, R10).
|
||||
// The workspace-cleanup schedule removes the media past Settings › Workspace's Clean after and Size limit, and reports its trash (phase 5c).
|
||||
// The shared library's upload-cleanup schedule runs on this PC's scheduler (owner review 5, #67).
|
||||
CleanupSteps = [new CacheTrimStep(() => CacheStore.Folder(Environment, Settings), () => Settings.CacheLimitGb * (1L << 30)),
|
||||
new WorkspaceCleanStep(() => Workspace), new WorkspaceTrashStep(() => Workspace)],
|
||||
new WorkspaceCleanStep(() => Workspace), new WorkspaceTrashStep(() => Workspace), new ShareUploadsStep(() => Share)],
|
||||
BackupDirectory = Environment.BackupDirectory,
|
||||
// Told after each step of a Reorganize, and each sequence a conversion replaced or made, while the rest of the job runs.
|
||||
SequenceChanged = (id, _, _) =>
|
||||
// While the library is shared, its clients see thumbnails and proxies of what a scan finds, as a server's do.
|
||||
ImagesAfterScanWhen = () => Share.IsOn,
|
||||
// Told after each step of a Reorganize, and each sequence a conversion replaced or made, while the rest of the job
|
||||
// runs; the shared library's clients are told too.
|
||||
SequenceChanged = (id, change, token) =>
|
||||
{
|
||||
SequenceReorganized?.Invoke(id);
|
||||
return Task.CompletedTask;
|
||||
return Share.SequenceChangedAsync(id, change, token);
|
||||
},
|
||||
ProjectsChanged = (changed, token) => Share.ProjectsChangedAsync(changed, token),
|
||||
};
|
||||
Archives = new ArchiveService(database, archive);
|
||||
// The videos folder may not lie in the workspace either, and a copy of a server's renders downloads through its connection (phase 5).
|
||||
Archives.Videos.ProtectedFolders = () => [Workspace.Root];
|
||||
Archives.Videos.ProtectedFolders = () => [Workspace.Root, Share.Folder];
|
||||
Archives.Videos.Servers = Sync;
|
||||
Processing = new ProcessingService(database, ProcessingOptions(archive));
|
||||
Sync.Open(database, Archives, archive);
|
||||
@@ -508,6 +596,7 @@ public sealed class AppServices : IAsyncDisposable
|
||||
Engine = new JobEngine(database, handlers, new JobEngineOptions { WorkerId = WorkerId, Kinds = kinds, PriorityQueue = () => PriorityQueue });
|
||||
// The workspace's size limit runs after each copy of media into it (phase 5c).
|
||||
Engine.JobChanged += Workspace.OnJobChanged;
|
||||
Engine.JobChanged += OnScheduledScanDone;
|
||||
// Sync follows the engine's jobs before it runs any: a render resumed at start that finishes at once is still sent (Export "Sync").
|
||||
Sync.Update();
|
||||
// With no handler the engine must not run: an empty kind list would let workers claim (and fail) every job.
|
||||
@@ -528,6 +617,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
AllowsHardware = presetId => AllowsHardware(Settings.HardwareEncoding, presetId),
|
||||
Host = EncoderHost.Client,
|
||||
ProducedBy = System.Environment.MachineName,
|
||||
// A render or an advice recorded on this PC reaches the shared library's clients (owner review 5, #67).
|
||||
SequenceChanged = (id, change, token) => Share.SequenceChangedAsync(id, change, token),
|
||||
Tune = basis => ProcessingTuning.Apply(basis, Settings, GC.GetGCMemoryInfo().TotalAvailableMemoryBytes, System.Environment.ProcessorCount,
|
||||
CacheStore.Folder(Environment, Settings)),
|
||||
};
|
||||
@@ -554,7 +645,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
var node = new RenderNodeClient(client, processing.Options, new RenderNodeOptions
|
||||
{
|
||||
ClientName = System.Environment.MachineName,
|
||||
CacheDirectory = Path.Combine(cache, "render-node"),
|
||||
// Each server keeps its own downloads (owner review 5, #66: the render-node folder of its home in the cache).
|
||||
CacheDirectory = Path.Combine(CacheStore.ServerFolder(cache, Sync.KeyOf(session.Address), Sync.Identity), HomeFolders.RenderNode),
|
||||
CacheLimitBytes = Settings.CacheLimitGb * (1L << 30),
|
||||
});
|
||||
node.Start();
|
||||
|
||||
@@ -10,6 +10,7 @@ using Chronos.Core.Naming;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Repositories;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Ui.Theming;
|
||||
|
||||
namespace Chronos.App.Infrastructure;
|
||||
@@ -66,6 +67,61 @@ public sealed class TrustedCertificate
|
||||
public DateTimeOffset TrustedAt { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A server this PC signed in to that announced its stable id (owner review 5, #66): its name and last address, the TLS
|
||||
/// fingerprint it presented, the address keys it was reached under before (or besides) its id
|
||||
/// (<see cref="Chronos.Data.Sync.SyncService.ServerKey"/>: projects, links and jobs made then still name them), the archive its
|
||||
/// downloaded originals go to, and when it was last seen. Its folders (<c>servers\<id></c> in the workspace and the
|
||||
/// cache) are named by the id, never by the name.
|
||||
/// </summary>
|
||||
public sealed class KnownServer
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? LastAddress { get; set; }
|
||||
public string? Fingerprint { get; set; }
|
||||
public List<string> Aliases { get; set; } = [];
|
||||
|
||||
/// <summary>The archive of this PC that holds the server's downloaded originals (owner review 5, Q1); null until the first download.</summary>
|
||||
public Guid? OriginalsArchiveId { get; set; }
|
||||
|
||||
public DateTimeOffset LastSeen { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Server › Sharing (owner review 5, #67): this PC's library served to the LAN by the server Chronos hosts
|
||||
/// while it runs. Absent in a 1.0 settings file: off, on Docker's ports.
|
||||
/// </summary>
|
||||
public sealed class ShareSettings
|
||||
{
|
||||
public const int DefaultHttpsPort = 8443;
|
||||
public const int DefaultHttpPort = 8080;
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>The name clients see; empty: this PC's name.</summary>
|
||||
public string? Name { get; set; }
|
||||
|
||||
public int HttpsPort { get; set; } = DefaultHttpsPort;
|
||||
public int HttpPort { get; set; } = DefaultHttpPort;
|
||||
|
||||
/// <summary>The ports clients reach when a router forwards others to this PC; null: the ones above.</summary>
|
||||
public int? PublicHttpsPort { get; set; }
|
||||
|
||||
public int? PublicHttpPort { get; set; }
|
||||
|
||||
/// <summary>Announce the library to Chronos programs on the local network.</summary>
|
||||
public bool Discovery { get; set; } = true;
|
||||
|
||||
/// <summary>What restarts a running share when it changes (the name, the ports, the discovery); the rest applies live.</summary>
|
||||
public bool SameEndpoint(ShareSettings other)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(other);
|
||||
return string.Equals(Name?.Trim() ?? string.Empty, other.Name?.Trim() ?? string.Empty, StringComparison.Ordinal) && HttpsPort == other.HttpsPort &&
|
||||
HttpPort == other.HttpPort && PublicHttpsPort == other.PublicHttpsPort && PublicHttpPort == other.PublicHttpPort && Discovery == other.Discovery;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Per-user preferences (language, theme, window layout, archive defaults, server session). Kept in
|
||||
/// <c>settings.json</c> next to the database and written atomically, because language and theme apply before the
|
||||
@@ -257,6 +313,22 @@ public sealed class AppSettings
|
||||
public List<TrustedCertificate> TrustedCertificates { get; set; } = [];
|
||||
public List<string> RecentServers { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The servers known by their stable id and the address keys each was reached under (owner review 5, #66): a server's
|
||||
/// projects, links and jobs stay its own whatever address it is reached by. This PC's state: Reset and Import keep it,
|
||||
/// Export leaves it out.
|
||||
/// </summary>
|
||||
public List<KnownServer> KnownServers { get; set; } = [];
|
||||
|
||||
/// <summary>The alias table of <see cref="KnownServers"/>, as the sync and the workspace compare server keys through it.</summary>
|
||||
public ServerIdentity KnownIdentity() => new([.. KnownServers.Where(k => k.Id != Guid.Empty).Select(k => new KnownServerKey(k.Id, [.. k.Aliases]))]);
|
||||
|
||||
/// <summary>The known server of <paramref name="id"/>; null when this PC has none.</summary>
|
||||
public KnownServer? FindKnownServer(Guid id) => KnownServers.FirstOrDefault(k => k.Id == id);
|
||||
|
||||
/// <summary>Settings › Server › Sharing: this PC's library shared to the LAN while Chronos runs (owner review 5, #67).</summary>
|
||||
public ShareSettings Share { get; set; } = new();
|
||||
|
||||
/// <summary>Let the server send render jobs to this PC (BRIEF §14.7).</summary>
|
||||
public bool RenderNodeOptIn { get; set; }
|
||||
|
||||
@@ -377,6 +449,7 @@ public sealed class AppSettings
|
||||
ProtectedToken = ProtectedToken,
|
||||
TrustedCertificates = TrustedCertificates,
|
||||
RecentServers = RecentServers,
|
||||
KnownServers = KnownServers,
|
||||
Window = Window,
|
||||
RailCollapsed = RailCollapsed,
|
||||
EditorGroups = EditorGroups,
|
||||
@@ -400,6 +473,7 @@ public sealed class AppSettings
|
||||
copy.WorkspaceFolder = null;
|
||||
copy.WorkspaceRecent = [];
|
||||
copy.WorkspaceOpened = [];
|
||||
copy.KnownServers = [];
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -423,6 +497,7 @@ public sealed class AppSettings
|
||||
imported.WorkspaceFolder = WorkspaceFolder;
|
||||
imported.WorkspaceRecent = WorkspaceRecent;
|
||||
imported.WorkspaceOpened = WorkspaceOpened;
|
||||
imported.KnownServers = KnownServers;
|
||||
return imported;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ using System.Text;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Export;
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Windows.Codecs;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Sqlite;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.App.Infrastructure;
|
||||
|
||||
@@ -34,8 +36,11 @@ public static class DiagnosticsBundle
|
||||
var settings = services.Settings.ToJson();
|
||||
var tailBytes = AppLogging.DiagnosticsTailBytes(services.Settings);
|
||||
var report = Report(services.Environment, extraLines) + DatabaseLine(services.Database);
|
||||
var workspace = services.Workspace;
|
||||
var cache = CacheStore.Folder(services.Environment, services.Settings);
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
report += HomesLines(workspace, cache);
|
||||
var failures = services.Database is { } db ? (await db.Jobs.ListAsync(JobState.Failed, FailedJobs, null, ct).ConfigureAwait(false)).Items : [];
|
||||
var codecs = Codecs(services.Encoders);
|
||||
var path = ExportNaming.Unique(folder, $"Chronos diagnostics {DateTime.Now.ToString("yyyy-MM-dd HHmm", CultureInfo.InvariantCulture)}", ".zip");
|
||||
@@ -76,6 +81,33 @@ public static class DiagnosticsBundle
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>The homes' folders (owner review 5, #66): the workspace's, each with its projects, and the servers' in the cache.</summary>
|
||||
private static string HomesLines(Chronos.App.Workspace.WorkspaceHost workspace, string cache)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
try
|
||||
{
|
||||
if (workspace.IsEnabled && Directory.Exists(workspace.Root))
|
||||
{
|
||||
var homes = workspace.Homes;
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"Workspace {homes.Root} ({(homes.IsSplit ? "homes" : "1.0 layout")})");
|
||||
foreach (var home in homes.Homes())
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $" {(home.IsLegacy ? "(parent)" : home.Folder)}: {home.Store.List().Count} project(s){(home.Server?.Name is { } name ? " · " + name : string.Empty)}");
|
||||
}
|
||||
var servers = CacheStore.ServersFolder(cache);
|
||||
if (Directory.Exists(servers))
|
||||
{
|
||||
foreach (var folder in Directory.EnumerateDirectories(servers).Order(StringComparer.Ordinal))
|
||||
sb.AppendLine(CultureInfo.InvariantCulture, $"Cache home {Path.GetFileName(folder)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
|
||||
{
|
||||
sb.AppendLine("The homes could not be listed: " + ex.Message);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static string DatabaseLine(ChronosDatabase? database)
|
||||
{
|
||||
if (database is null) return "Index not open\n";
|
||||
@@ -135,6 +167,19 @@ public static class CacheStore
|
||||
public static string Folder(AppEnvironment environment, AppSettings settings) =>
|
||||
string.IsNullOrWhiteSpace(settings.CacheFolder) ? environment.CacheDirectory : settings.CacheFolder!;
|
||||
|
||||
/// <summary>The servers' homes in the cache (<c><cache>\servers</c>, owner review 5, #66).</summary>
|
||||
public static string ServersFolder(string cache) => Path.Combine(cache, HomeFolders.Servers);
|
||||
|
||||
/// <summary>
|
||||
/// The home of server <paramref name="serverKey"/> in the cache (<c><cache>\servers\<folder></c>, named by its
|
||||
/// canonical key through <paramref name="identity"/>): its proxies, render-node downloads and staged imports.
|
||||
/// </summary>
|
||||
public static string ServerFolder(string cache, string serverKey, ServerIdentity identity)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(identity);
|
||||
return Path.Combine(ServersFolder(cache), identity.FolderName(serverKey));
|
||||
}
|
||||
|
||||
/// <summary>Creates the folder (if needed) and marks it as Chronos's.</summary>
|
||||
public static void Prepare(string folder)
|
||||
{
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Chronos.App.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Public links (BRIEF §19.4, amended 2026-10-23, R2): the Gitea repository that publishes the releases. Release
|
||||
/// builds pass the repository they publish to as the ChronosReleasesUrl property.
|
||||
/// </summary>
|
||||
public static class ProductLinks
|
||||
{
|
||||
/// <summary>The repository of local builds, as Directory.Build.props sets it.</summary>
|
||||
public const string DefaultRepository = "https://gitea.encke-hake.ts.net/BalboSoft/Chronos";
|
||||
|
||||
/// <summary>"https://host/owner/name" of the releases repository.</summary>
|
||||
public static string Repository { get; } = Normalise(
|
||||
typeof(ProductLinks).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.FirstOrDefault(a => a.Key == "ChronosReleasesUrl")?.Value) ?? DefaultRepository;
|
||||
|
||||
public static string Releases => $"{Repository}/releases";
|
||||
|
||||
/// <summary>The published stable releases, from which the update check takes the newest (BRIEF §18).</summary>
|
||||
public static string StableReleasesApi => StableReleasesApiOf(Repository);
|
||||
|
||||
/// <summary>The licence (EULA) at the root of the releases repository (BRIEF §12.9).</summary>
|
||||
public static string Licence => $"{Repository}/src/branch/main/EULA.md";
|
||||
|
||||
/// <summary>Where translations are reviewed by the community (BRIEF §16).</summary>
|
||||
public static string Issues => $"{Repository}/issues";
|
||||
|
||||
/// <summary>
|
||||
/// The Gitea API address of a repository's published stable releases: "https://host[/prefix]/owner/name" →
|
||||
/// "https://host[/prefix]/api/v1/repos/owner/name/releases?draft=false&pre-release=false&limit=50" (Gitea may
|
||||
/// be served under a path prefix).
|
||||
/// </summary>
|
||||
public static string StableReleasesApiOf(string repository)
|
||||
{
|
||||
var uri = new Uri(repository, UriKind.Absolute);
|
||||
var segments = uri.AbsolutePath.Trim('/').Split('/', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segments.Length < 2) throw new ArgumentException($"Not a repository address: {repository}", nameof(repository));
|
||||
var prefix = string.Concat(segments[..^2].Select(s => "/" + s));
|
||||
return $"{uri.GetLeftPart(UriPartial.Authority)}{prefix}/api/v1/repos/{segments[^2]}/{segments[^1]}/releases?draft=false&pre-release=false&limit=50";
|
||||
}
|
||||
|
||||
/// <summary>The address without surrounding spaces, trailing slashes or ".git"; null when empty.</summary>
|
||||
internal static string? Normalise(string? repository)
|
||||
{
|
||||
var text = repository?.Trim().TrimEnd('/');
|
||||
if (text is not null && text.EndsWith(".git", StringComparison.OrdinalIgnoreCase)) text = text[..^4];
|
||||
return string.IsNullOrEmpty(text) ? null : text;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user