Files
Chronos/src/Chronos.App/Infrastructure/ArchiveSetup.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

140 lines
6.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.IO;
using Chronos.App.Archiving;
using Chronos.Core.Diagnostics;
using Chronos.Data.Archiving;
namespace Chronos.App.Infrastructure;
/// <summary>
/// First-run and Library archive choices (BRIEF §12.1): create a local archive or adopt an existing folder tree.
/// </summary>
public interface IArchiveSetup
{
/// <summary>Creates (or opens) the local archive rooted at <paramref name="root"/>.</summary>
Task CreateAsync(string root, CancellationToken cancellationToken = default);
/// <summary>Indexes the photos under <paramref name="folder"/> in place, or opens a previous Chronos archive there.</summary>
Task AdoptAsync(string folder, CancellationToken cancellationToken = default);
}
/// <summary>
/// Creates or adopts the archive through the archive engine (originals stay where they are), remembers it as the
/// archive to open at start and queues a full scan that indexes its sequences. A folder that becomes a new archive gets
/// the naming templates, proxy size and thumbnail size of Settings › Archive; an existing archive keeps its own.
/// </summary>
public sealed class EngineArchiveSetup(AppServices services) : IArchiveSetup
{
public Task CreateAsync(string root, CancellationToken cancellationToken = default) => OpenAsync(root, cancellationToken);
public Task AdoptAsync(string folder, CancellationToken cancellationToken = default) => OpenAsync(folder, cancellationToken);
private async Task OpenAsync(string path, CancellationToken cancellationToken)
{
var archives = services.Archives ?? throw new InvalidOperationException("The index is not open.", services.OpenError);
var root = Path.GetFullPath(path);
var defaults = services.Settings.ArchiveDefaults();
var archive = await Task.Run(async () =>
{
Directory.CreateDirectory(root);
return await archives.AdoptAsync(root, defaults, cancellationToken).ConfigureAwait(false);
}, cancellationToken);
services.Settings.LastArchivePath = root;
services.SaveSettings();
await services.QueueScanAsync(archive, full: true, cancellationToken);
Log.Info("archive", $"Archive {archive.Name} ready at {root}");
}
}
/// <summary>
/// Runs an archive action from the UI; a failure becomes a toast instead of an unhandled exception. The toast says why
/// in one localized sentence (<see cref="Cause"/>); the exception's own text stays in the log.
/// </summary>
public static class ArchiveActions
{
public static async Task<bool> TryAsync(Shell.ShellViewModel shell, Func<IArchiveSetup, Task> action)
{
try
{
await action(shell.Services.ArchiveSetup);
return true;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException or InvalidDataException
or ArgumentException or Data.DatabaseException)
{
Log.Error("archive", "Archive action failed", ex);
shell.Notify(Core.Localization.Loc.L("Errors.Archive.Open"), Cause(ex), isError: true);
return false;
}
}
/// <summary>
/// Why creating, opening or changing an archive failed: the archive's own sentences for files (an unreadable
/// archive.json included), access and the index (<see cref="ArchiveFailures"/>), otherwise <see cref="Shell.ErrorText"/>
/// (a catalog sentence, or "Something went wrong").
/// </summary>
public static string Cause(Exception ex) =>
ex is IOException or InvalidDataException or UnauthorizedAccessException or Data.DatabaseException ? ArchiveFailures.Cause(ex) : Shell.ErrorText.For(ex);
}
/// <summary>Archive roots offered by default and their free space.</summary>
public static class ArchiveLocations
{
public const string DefaultFolderName = "ChronosArchive";
/// <summary>"&lt;fixed drive with the most free space&gt;\ChronosArchive".</summary>
public static string SuggestRoot()
{
try
{
var best = DriveInfo.GetDrives()
.Where(d => d.DriveType == DriveType.Fixed && d.IsReady)
.OrderByDescending(d => d.AvailableFreeSpace)
.FirstOrDefault();
if (best is not null) return Path.Combine(best.RootDirectory.FullName, DefaultFolderName);
}
catch (IOException)
{
}
catch (UnauthorizedAccessException)
{
}
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), DefaultFolderName);
}
/// <summary>Free bytes on the volume of <paramref name="path"/>; null when unknown.</summary>
public static long? FreeSpace(string? path)
{
if (string.IsNullOrWhiteSpace(path)) return null;
try
{
var root = Path.GetPathRoot(Path.GetFullPath(path));
if (string.IsNullOrEmpty(root)) return null;
var drive = new DriveInfo(root);
return drive.IsReady ? drive.AvailableFreeSpace : null;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or NotSupportedException)
{
return null;
}
}
/// <summary>The problem of an archive root as a localized sentence; null when it can be used.</summary>
public static string? Validate(string? path)
{
if (string.IsNullOrWhiteSpace(path)) return Core.Localization.Loc.L("Errors.Path.Empty");
try
{
if (!Path.IsPathFullyQualified(path)) return Core.Localization.Loc.L("Errors.Path.NotAbsolute");
var full = Path.GetFullPath(path);
if (File.Exists(full)) return Core.Localization.Loc.L("Errors.Path.IsFile");
var root = Path.GetPathRoot(full);
if (string.IsNullOrEmpty(root) || !Directory.Exists(root)) return Core.Localization.Loc.L("Errors.Path.NoDrive");
return null;
}
catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException)
{
return Core.Localization.Loc.L("Errors.Path.Invalid");
}
}
}