Files
Chronos/src/Chronos.Setup/Views/ComponentOption.cs
T
Alby96andClaude Opus 5.5 7d0c6554a4 feat(setup): one setup for Chronos Desktop and Chronos Uploader
Chronos Server now ships as a Docker image only, so the Windows setup no
longer offers it and the separate Uploader setup goes: one setup installs,
updates, adds and removes Chronos Desktop and Chronos Uploader in place.

- Install log format 2 records each component's files, shortcuts, version
  and SHA-256; format 1 logs (1.0) are still read. A file of a removed
  program that changed since setup installed it is kept, never deleted.
- A Chronos Server 1.0 for Windows installed by 1.0 is retained as "no
  longer offered": its files and service are untouched until the user
  unticks it or explicit /COMPONENTS leave it out; then it is removed with
  its service. A format 1 log keeps every file the payload does not know.
- The separate 1.0 Chronos Uploader product is replaced: the Uploader is
  preselected, its sign-in entry moves to the new copy (Task Manager state
  kept), its shortcut is handed over and the old product is uninstalled.
  An all-users copy under a per-user install stays and is said so.
- The setup window shows the dry-run plan (Changes: adds, removes,
  replaces) before Update; with every program unticked the primary action
  becomes Uninstall. /COMPONENTS=Desktop names the desktop app.
- pack-installer refuses Server (--legacy packs a 1.0 one for the CI test);
  release.yml publishes only Chronos-Setup-<v>.exe and the portable zip;
  the installer test covers add/remove in place, the Uploader replacement
  and the retained Server.

Refs #64

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 13:13:54 +01:00

112 lines
4.7 KiB
C#

using Chronos.Core.Localization;
using Chronos.Core.Packaging;
using Chronos.Setup.Engine;
using Chronos.Ui.Mvvm;
namespace Chronos.Setup.Views;
/// <summary>
/// A component checkbox: localized name and tooltip (falling back to the manifest), its state (size, "Installed ·
/// size", or "No longer offered" for a retained one) and selection. Unticking an installed component removes it;
/// unticking a retained one (Chronos Server 1.0 for Windows) removes it with its service. A component that installs for
/// all users only says so in its tooltip, and is unavailable when an installation that is not an all-users one inside
/// Program Files is upgraded.
/// </summary>
internal sealed class ComponentOption : LocalizedViewModel
{
private readonly PayloadComponent? _component;
private readonly string? _unavailableToolTip;
private readonly Action _changed;
private bool _selected;
/// <param name="installedVersion">The version installed now; null when it is not installed.</param>
/// <param name="unavailableToolTip">The tooltip key saying why it cannot be added here; null when it can.</param>
public ComponentOption(PayloadComponent component, bool selected, string? installedVersion, string? unavailableToolTip, Action changed)
{
_component = component;
_selected = selected;
InstalledVersion = installedVersion;
_unavailableToolTip = unavailableToolTip;
_changed = changed;
Id = component.Id;
}
/// <summary>A retained component: ticked keeps it as it is, unticked removes it with its service.</summary>
public ComponentOption(RetainedComponent retained, bool selected, Action changed)
{
Retained = retained;
_selected = selected;
InstalledVersion = retained.Version;
_changed = changed;
Id = retained.Id;
}
public string Id { get; }
/// <summary>The retained component this row keeps or removes; null for a component of the payload.</summary>
public RetainedComponent? Retained { get; }
public bool IsRetained => Retained is not null;
/// <summary>The version installed now; null when it is not installed.</summary>
public string? InstalledVersion { get; }
public bool IsInstalled => InstalledVersion is not null;
/// <summary>The component's name; a retained one carries its version ("Chronos Server 1.0.0").</summary>
public string Name => Retained is { } retained ? Loc.L("Setup.Component.Versioned", BaseName, retained.Version) : BaseName;
private string BaseName => Loc.Get("Setup.Component." + Id, Loc.Culture) ?? _component?.DisplayName ?? Id;
/// <summary>Installs for all users only (a program a LocalSystem service runs from Program Files).</summary>
public bool AllUsersOnly => _component?.AllUsersOnly == true;
/// <summary>False when it cannot be installed here: it needs all users in Program Files and this installation is not.</summary>
public bool IsAvailable => _unavailableToolTip is null;
public string ToolTip => _unavailableToolTip is { } reason ? Loc.L(reason)
: Retained is { } retained ? Loc.L("Tooltips.Setup.Component.Retained", retained.Version)
: AllUsersOnly ? Loc.L("Tooltips.Setup.AllUsersOnly", Description)
: InstalledVersion is { } version ? Loc.L("Tooltips.Setup.Component.InstalledVersion", Description, version)
: Description;
private string Description => Loc.Get("Tooltips.Setup.Component." + Id, Loc.Culture) ?? Loc.L("Tooltips.Setup.Component");
/// <summary>The right-hand text of the row: the size, "Installed · size", or "No longer offered".</summary>
public string StateText => IsRetained ? Loc.L("Setup.Component.NoLongerOffered")
: IsInstalled ? Loc.L("Setup.Component.Installed", SizeText)
: SizeText;
public string SizeText => ByteSize.Format(_component?.EstimatedSize ?? 0);
public bool IsSelected
{
get => _selected;
set
{
if (Set(ref _selected, value)) _changed();
}
}
}
/// <summary>Language offered in the picker.</summary>
internal sealed record LanguageOption(string Code, string Name);
/// <summary>Decimal byte sizes as Explorer shows them for drives ("1.5 MB"), units in the UI language ("1,5 Mo").</summary>
internal static class ByteSize
{
private static readonly string[] Formats = ["Common.Size.B", "Common.Size.KB", "Common.Size.MB", "Common.Size.GB", "Common.Size.TB"];
public static string Format(long bytes)
{
double value = bytes;
var unit = 0;
while (value >= 1000 && unit < Formats.Length - 1)
{
value /= 1000;
unit++;
}
return Loc.L(Formats[unit], value.ToString(unit == 0 || value >= 100 ? "0" : "0.#", Loc.Culture));
}
}