merge: desktop settings fixes (V-4, V-6, V-7, V-30, V-31, V-32, V-34, ENG-08)
Merge branch fix2/desktop-settings into the verification branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
34 files changed
+1132
-171
No files matched your search
@@ -147,17 +147,31 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
public async Task<ArchiveSettings> GetSettingsAsync(Guid archiveId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var archive = await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false);
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
try
|
||||
return TryReadManifest(archive) is { } manifest
|
||||
? ArchiveSettings.Of(manifest)
|
||||
: new ArchiveSettings(archive.Name, new LayoutTemplates { Folder = archive.FolderTemplate, File = archive.FileTemplate },
|
||||
new ProxyPolicy { LongEdge = archive.ProxyLongEdge }, new ThumbnailPolicy());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The settings in the archive's <c>archive.json</c>, with its index row brought up to them when another process
|
||||
/// sharing the archive changed the file (a server's admin panel, another PC's Settings): imports and uploads take their
|
||||
/// templates and proxy size from that row. Null while the file cannot be read (offline, damaged, newer, of another
|
||||
/// archive): the row stays as it is, and only <see cref="GetSettingsAsync"/>'s stand-ins are known.
|
||||
/// </summary>
|
||||
public async Task<ArchiveSettings?> RefreshSettingsAsync(Guid archiveId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var archive = await LoadArchiveAsync(archiveId, cancellationToken).ConfigureAwait(false);
|
||||
if (TryReadManifest(archive) is not { } manifest) return null;
|
||||
var settings = ArchiveSettings.Of(manifest);
|
||||
if (!settings.IsRegisteredIn(archive))
|
||||
{
|
||||
if (File.Exists(paths.ManifestPath)) return ArchiveSettings.Of(ManifestStore.ReadArchive(paths.ManifestPath));
|
||||
// Read without the settings lease, as at open: an edit made meanwhile writes its own row, and the next refresh
|
||||
// settles a file that changes again.
|
||||
await RegisterAsync(new ArchivePaths(archive.RootPath), manifest, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("archive", $"Settings of {archive.RootPath} changed elsewhere: {manifest.LayoutTemplates.Folder} · {manifest.LayoutTemplates.File}, proxies {manifest.ProxyPolicy.LongEdge}");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
|
||||
{
|
||||
Log.Warning("archive", $"The settings of {paths.Root} cannot be read; the index's are used", ex);
|
||||
}
|
||||
return new ArchiveSettings(archive.Name, new LayoutTemplates { Folder = archive.FolderTemplate, File = archive.FileTemplate },
|
||||
new ProxyPolicy { LongEdge = archive.ProxyLongEdge }, new ThumbnailPolicy());
|
||||
return settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,6 +339,29 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
return archive;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The archive's <c>archive.json</c>; null (logged) while it cannot be read, when a newer Titano wrote it (this one
|
||||
/// would drop what it does not know) or when it belongs to another archive.
|
||||
/// </summary>
|
||||
private static ArchiveManifest? TryReadManifest(Archive archive)
|
||||
{
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
try
|
||||
{
|
||||
if (!File.Exists(paths.ManifestPath)) return null;
|
||||
var manifest = ManifestStore.ReadArchive(paths.ManifestPath);
|
||||
if (manifest.SchemaVersion > ArchiveManifest.CurrentSchemaVersion)
|
||||
Log.Warning("archive", $"{paths.ManifestPath} has schema version {manifest.SchemaVersion}, newer than this Titano's; the index's settings are used");
|
||||
else if (manifest.Id == archive.Id) return manifest;
|
||||
else Log.Warning("archive", $"{paths.ManifestPath} belongs to archive {manifest.Id}, not {archive.Id}; the index's settings are used");
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
|
||||
{
|
||||
Log.Warning("archive", $"The settings of {paths.Root} cannot be read; the index's are used", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task<Archive> LoadArchiveAsync(Guid archiveId, CancellationToken cancellationToken) =>
|
||||
await _db.Archives.GetAsync(archiveId, cancellationToken).ConfigureAwait(false) ?? throw new ArgumentException($"Unknown archive {archiveId}.", nameof(archiveId));
|
||||
|
||||
@@ -349,6 +386,14 @@ public sealed record ArchiveSettings(string Name, LayoutTemplates Templates, Pro
|
||||
|
||||
public static ArchiveSettings Of(ArchiveManifest manifest) => new(manifest.Name, manifest.LayoutTemplates, manifest.ProxyPolicy, manifest.ThumbnailPolicy);
|
||||
|
||||
/// <summary>Whether the index row <paramref name="archive"/> holds these settings (all it keeps: not the thumbnail policy).</summary>
|
||||
public bool IsRegisteredIn(Archive archive)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(archive);
|
||||
return Name == archive.Name && Templates.Folder == archive.FolderTemplate && Templates.File == archive.FileTemplate
|
||||
&& Proxies.LongEdge == archive.ProxyLongEdge;
|
||||
}
|
||||
|
||||
/// <summary>The first invalid field by its API name (<c>name</c>, <c>folderTemplate</c>, <c>fileTemplate</c>,
|
||||
/// <c>proxyLongEdge</c>, <c>thumbnailLongEdge</c>); null when every field is valid.</summary>
|
||||
public string? Problem()
|
||||
|
||||
Reference in new issue
Block a user