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>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-15 13:13:54 +01:00
1 parent 58ed737310
commit 7d0c6554a4
58 files changed
+1401 -233

No files matched your search

+62 -15
View File
@@ -1,43 +1,90 @@
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), size and selection. 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.
/// 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>
/// <param name="unavailableToolTip">The tooltip key saying why it cannot be added here; null when it can.</param>
internal sealed class ComponentOption(PayloadComponent component, bool selected, string? unavailableToolTip, Action changed) : LocalizedViewModel
internal sealed class ComponentOption : LocalizedViewModel
{
private bool _selected = selected;
private readonly PayloadComponent? _component;
private readonly string? _unavailableToolTip;
private readonly Action _changed;
private bool _selected;
public string Id => component.Id;
/// <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;
}
public string Name => Loc.Get("Setup.Component." + component.Id, Loc.Culture) ?? component.DisplayName;
/// <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;
}
/// <summary>Installs for all users only (the Server runs as a LocalSystem service from Program Files).</summary>
public bool AllUsersOnly => component.AllUsersOnly;
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 bool IsAvailable => _unavailableToolTip is null;
public string ToolTip => unavailableToolTip is { } reason ? Loc.L(reason)
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." + component.Id, Loc.Culture) ?? Loc.L("Tooltips.Setup.Component");
private string Description => Loc.Get("Tooltips.Setup.Component." + Id, Loc.Culture) ?? Loc.L("Tooltips.Setup.Component");
public string SizeText => ByteSize.Format(component.EstimatedSize);
/// <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();
if (Set(ref _selected, value)) _changed();
}
}
}
+38 -10
View File
@@ -13,8 +13,9 @@ namespace Chronos.Setup.Views;
/// <summary>
/// <c>Chronos.Setup.exe --capture &lt;dir&gt;</c>: renders the setup window in every stage (install options, programs
/// running, installing, installed, failed, uninstall with its data plan) in the dark and light themes, then in
/// Arabic (right to left, dark), from a small sample installer built in a temporary folder. Nothing is installed,
/// running, installing, installed, failed, uninstall with its data plan), the update of an installed copy that
/// replaces a legacy Uploader, and a retained Chronos Server 1.0 kept and unticked, in the dark and light themes, then
/// in Arabic (right to left, dark), from a small sample installer built in a temporary folder. Nothing is installed,
/// removed or registered.
/// </summary>
internal static class SetupCapture
@@ -94,16 +95,41 @@ internal static class SetupCapture
{
Program.ApplyLanguage(language);
using var payload = PayloadReader.Open(installer);
using var install = SetupViewModel.ForInstall(new SetupArguments(), payload);
var manifest = payload.Manifest;
// Nothing installed, whatever this machine has, so every capture shows the same screen.
using var install = SetupViewModel.ForInstall(new SetupArguments(), payload, InstallPlan.Resolve(manifest, new SetupArguments(), null, null, null));
// The desktop app 1.0 installed for this user, the separate 1.0 Uploader beside it: Update replaces it.
var perUser = SetupPaths.DefaultDirectory(InstallScope.CurrentUser, Product);
var legacy = new LegacyInstall(new InstalledProduct(SetupPaths.DefaultDirectory(InstallScope.CurrentUser, LegacyProducts.UploaderProduct),
new InstallLog { Product = LegacyProducts.UploaderProduct, Version = "1.0.0", Components = ["Uploader"], Files = ["Chronos.Uploader.exe"] }), InstallScope.CurrentUser);
using var update = SetupViewModel.ForInstall(new SetupArguments(), payload, InstallPlan.Resolve(manifest, new SetupArguments(),
new ExistingInstall(InstallScope.CurrentUser, perUser, "1.0.0"), new InstallLog { Product = Product, Version = "1.0.0", Components = ["Chronos"], Files = ["Chronos.exe"] }, legacy));
// Chronos 1.0 for all users with Chronos Server for Windows, which this setup no longer ships: kept, then unticked.
var allUsers = SetupPaths.DefaultDirectory(InstallScope.AllUsers, Product);
var withServer = new InstallLog
{
Product = Product,
Version = "1.0.0",
Scope = InstallScope.AllUsers,
Components = ["Chronos", "Uploader", "Server"],
Files = ["Chronos.exe", "Chronos.Uploader.exe", "Chronos.Server.exe"],
};
InstallPlan Retained() => InstallPlan.Resolve(manifest, new SetupArguments(), new ExistingInstall(InstallScope.AllUsers, allUsers, "1.0.0"), withServer, null);
using var retained = SetupViewModel.ForInstall(new SetupArguments(), payload, Retained());
using var removeServer = SetupViewModel.ForInstall(new SetupArguments(), payload, Retained());
foreach (var c in removeServer.Components.Where(c => c.IsRetained)) c.IsSelected = false;
// Both programs' data, whatever this machine has installed, so every capture shows the same screen.
using var uninstall = SetupViewModel.ForUninstall(new SetupArguments(), new InstalledProduct(
SetupPaths.DefaultDirectory(InstallScope.CurrentUser, Product), new InstallLog { Product = Product, Version = "1.0.0", Components = ["Chronos", "Uploader"] }),
perUser, new InstallLog { Product = Product, Version = "1.0.0", Components = ["Chronos", "Uploader"] }),
UserDataOwners.All);
foreach (var theme in themes)
{
ThemeManager.Apply(theme);
var name = suffix + "-" + theme.ToString().ToLowerInvariant();
Capture(install, [.. InstallStages.Select(s => ("setup-" + s.Name + name, s.Stage, (UserDataPlan?)null))], directory);
Capture(update, [("setup-update" + name, SetupStage.Options, null)], directory);
Capture(retained, [("setup-retained" + name, SetupStage.Options, null)], directory);
Capture(removeServer, [("setup-retained-remove" + name, SetupStage.Options, null)], directory);
Capture(uninstall, [("setup-uninstall" + name, SetupStage.Options, SamplePlan)], directory);
}
}
@@ -134,15 +160,17 @@ internal static class SetupCapture
}
}
/// <summary>Three components of random (incompressible) bytes, with the shortcuts the real installer carries.</summary>
/// <summary>
/// The two components of the real installer (the desktop app preselected), of random (incompressible) bytes, with
/// its shortcuts.
/// </summary>
private static string WriteSampleInstaller(string work)
{
var random = new Random(1);
var components = new (string Id, string DisplayName, bool Selected, string Program, int Bytes)[]
{
("Chronos", "Chronos", true, "Chronos.exe", 2_400_000),
("Uploader", "Chronos Uploader", true, "Chronos.Uploader.exe", 900_000),
("Server", "Chronos Server", false, "Chronos.Server.exe", 1_600_000),
("Uploader", "Chronos Uploader", false, "Chronos.Uploader.exe", 900_000),
};
foreach (var c in components)
{
@@ -155,9 +183,9 @@ internal static class SetupCapture
PayloadWriter.Write(Environment.ProcessPath ?? throw new InvalidOperationException("No process path."), new PayloadSource
{
Product = Product,
Version = "1.0.0",
Components = [.. components.Select(c => new PayloadComponentSource(c.Id, c.DisplayName, c.Selected, Path.Combine(work, c.Id), AllUsersOnly: c.Id == "Server"))],
Shortcuts = [.. components.Select(c => new PayloadShortcut { Component = c.Id, Name = c.DisplayName, Target = c.Program, StartMenu = true, Desktop = c.Id != "Server" })],
Version = "1.1.0",
Components = [.. components.Select(c => new PayloadComponentSource(c.Id, c.DisplayName, c.Selected, Path.Combine(work, c.Id)))],
Shortcuts = [.. components.Select(c => new PayloadShortcut { Component = c.Id, Name = c.DisplayName, Target = c.Program, StartMenu = true, Desktop = true })],
}, installer);
return installer;
}
+193 -35
View File
@@ -14,6 +14,10 @@ namespace Chronos.Setup.Views;
/// <summary>A line of the "Remove my data" dry run: a file or folder name (or "3 more items") and its size.</summary>
internal sealed record DataPlanRow(string Name, string Size, bool IsFileName);
/// <summary>One change of the dry-run plan shown before Update: a program added, removed or replaced.</summary>
/// <param name="IsRemoval">Shown in the warning colour: something installed goes.</param>
internal sealed record ChangeRow(string Text, string ToolTip, bool IsRemoval);
/// <summary>What the setup screen currently shows.</summary>
internal enum SetupStage
{
@@ -26,7 +30,10 @@ internal enum SetupStage
/// <summary>
/// The single setup screen for install and uninstall: options, a prompt when installed programs must close,
/// progress, success and failure. Work runs on the thread pool and reports through <see cref="Progress{T}"/>.
/// progress, success and failure. One setup installs, updates, adds and removes programs: the component rows show
/// what is installed, the Changes line is the dry-run plan of what Update adds, removes or replaces, and with every
/// component unticked the primary action becomes Uninstall, which opens the uninstall options of the same window.
/// Work runs on the thread pool and reports through <see cref="Progress{T}"/>.
/// </summary>
internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
{
@@ -39,10 +46,11 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
private readonly PayloadReader? _payload;
private readonly InstallEngine? _engine;
private readonly InstallPlan? _plan;
private readonly InstalledProduct? _installed;
private readonly string _product;
private readonly string? _version;
private readonly IReadOnlySet<string> _dataOwners;
private InstalledProduct? _installed;
private IReadOnlySet<string> _dataOwners;
private int _keptFiles;
private SetupStage _stage;
private string _directory = string.Empty;
private bool _allUsers;
@@ -66,7 +74,7 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
private IReadOnlyList<InstalledService> _stopped = [];
private SetupViewModel(SetupArguments arguments, string product, string? version, PayloadReader? payload, InstalledProduct? installed,
IReadOnlySet<string>? dataOwners = null)
IReadOnlySet<string>? dataOwners = null, InstallPlan? plan = null)
{
_arguments = arguments;
_product = product;
@@ -79,7 +87,7 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
if (payload is not null)
{
_engine = new InstallEngine(payload);
_plan = InstallPlan.Resolve(_engine.Manifest, arguments);
_plan = plan ?? InstallPlan.Resolve(_engine.Manifest, arguments);
_directory = _plan.Directory;
_allUsers = _plan.Scope == InstallScope.AllUsers;
}
@@ -88,11 +96,20 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
_launchAfter = arguments.Launch;
Components = _engine is null
? []
: [.. _engine.Manifest.Components.Select(c => new ComponentOption(c, _plan!.Components.Contains(c.Id, StringComparer.OrdinalIgnoreCase), UnavailableReason(c),
OnComponentsChanged))];
:
[
.. _engine.Manifest.Components.Select(c => new ComponentOption(c, _plan!.Components.Contains(c.Id, StringComparer.OrdinalIgnoreCase),
InstalledVersionOf(c.Id), UnavailableReason(c), OnComponentsChanged)),
.. _plan!.Retained.Select(r => new ComponentOption(r, _plan.Kept.Any(k => k.Id.Equals(r.Id, StringComparison.OrdinalIgnoreCase)), OnComponentsChanged)),
];
Languages = [.. Core.Localization.Languages.Shipped.Select(c => new LanguageOption(c, Core.Localization.Languages.NativeName(c)))];
PrimaryCommand = new RelayCommand(() => Start(IsUninstall ? UninstallAsync : InstallAsync), () => CanStart);
PrimaryCommand = new RelayCommand(() =>
{
if (IsUninstall) Start(UninstallAsync);
else if (IsUninstallAll) SwitchToUninstall();
else Start(InstallAsync);
}, () => CanStart);
BrowseCommand = new RelayCommand(Browse, () => IsOptions && CanChangeLocation);
CloseProgramsCommand = new RelayCommand(() =>
{
@@ -105,8 +122,9 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
RetryCommand = new RelayCommand(() => Start(_operation!), () => CanRetry && _operation is not null);
}
public static SetupViewModel ForInstall(SetupArguments arguments, PayloadReader payload) =>
new(arguments, payload.Manifest.Product, payload.Manifest.Version, payload, null);
/// <param name="plan">What was found on this PC; null resolves it from the registry (tests and captures pass their own).</param>
public static SetupViewModel ForInstall(SetupArguments arguments, PayloadReader payload, InstallPlan? plan = null) =>
new(arguments, payload.Manifest.Product, payload.Manifest.Version, payload, null, plan: plan);
/// <param name="dataOwners">Whose user data "Remove my data" covers; null works it out from the installed products.</param>
public static SetupViewModel ForUninstall(SetupArguments arguments, InstalledProduct installed, IReadOnlySet<string>? dataOwners = null) =>
@@ -136,7 +154,8 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
public SetupExitCode ExitCode { get; private set; } = SetupExitCode.Cancelled;
public bool IsInstall => _engine is not null;
/// <summary>Installing from the payload; false once Uninstall (every component unticked) opened the uninstall options.</summary>
public bool IsInstall => _engine is not null && _installed is null;
public bool IsUninstall => _installed is not null;
public string WindowTitle => IsUninstall ? Loc.L("Setup.Window.Uninstall", _product) : Loc.L("Setup.Window.Title", _product);
@@ -182,12 +201,73 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
public IReadOnlyList<ComponentOption> Components { get; }
private List<string> SelectedComponents => [.. Components.Where(c => c.IsSelected).Select(c => c.Id)];
/// <summary>The components of the payload that are ticked (retained ones excluded).</summary>
private List<string> SelectedComponents => [.. Components.Where(c => c.IsSelected && !c.IsRetained).Select(c => c.Id)];
/// <summary>The retained components that are ticked: kept as they are.</summary>
private List<RetainedComponent> KeptComponents => [.. Components.Where(c => c.IsSelected && c.Retained is not null).Select(c => c.Retained!)];
public string RequiredSpaceText => _engine is null ? string.Empty : Loc.L("Setup.Space.Required", ByteSize.Format(_engine.RequiredBytes(SelectedComponents)));
/// <summary>False when upgrading: the existing folder and scope are kept.</summary>
public bool CanChangeLocation => _plan?.Existing is null;
/// <summary>False when upgrading (the existing folder and scope are kept) or replacing a legacy Uploader (its scope is).</summary>
public bool CanChangeLocation => _plan is null || _plan.CanChangeLocation;
/// <summary>An installation of this product exists: Update replaces it in place.</summary>
private bool IsUpgrade => _plan?.Existing is not null;
/// <summary>Installed, and every component unticked: the primary action is Uninstall, which opens the uninstall options.</summary>
public bool IsUninstallAll => IsInstall && IsUpgrade && !Components.Any(c => c.IsSelected);
/// <summary>The Install or Update button is shown.</summary>
public bool IsInstallPrimary => IsInstallOptions && !IsUninstallAll;
/// <summary>The destructive Uninstall button of the install options is shown.</summary>
public bool IsUninstallAllPrimary => IsInstallOptions && IsUninstallAll;
/// <summary>Cancel is the default when the primary action removes something.</summary>
public bool IsCancelDefault => IsUninstallOptions || IsUninstallAllPrimary;
/// <summary>
/// The dry-run plan of the run, shown before it can start: programs added next to the installed ones, programs and a
/// retained Server removed, a legacy Uploader replaced (or left where it is). Empty for a new installation and for an
/// update in place.
/// </summary>
public IReadOnlyList<ChangeRow> Changes
{
get
{
if (!IsInstall || _plan is null || IsUninstallAll) return [];
var rows = new List<ChangeRow>();
var replaces = _plan.Legacy is { } found && LegacyProducts.CanMerge(found, Scope, _directory);
if (IsUpgrade)
{
foreach (var c in Components)
{
if (c.Retained is { } retained && !c.IsSelected)
rows.Add(new ChangeRow(Loc.L("Setup.Changes.Remove", c.Name), Loc.L("Tooltips.Setup.Changes.RemoveRetained", FileList(retained.Files)), true));
else if (!c.IsRetained && c.IsInstalled && !c.IsSelected)
rows.Add(new ChangeRow(Loc.L("Setup.Changes.Remove", c.Name), Loc.L("Tooltips.Setup.Changes.Remove"), true));
// An Uploader that replaces the legacy one is said by "Replaces Chronos Uploader 1.0.0" below.
else if (!c.IsRetained && !c.IsInstalled && c.IsSelected && !(replaces && c.Id.Equals(LegacyProducts.UploaderComponent, StringComparison.OrdinalIgnoreCase)))
rows.Add(new ChangeRow(Loc.L("Setup.Changes.Add", c.Name), Loc.L("Tooltips.Setup.Changes.Add"), false));
}
}
if (_plan.Legacy is { } legacy && Components.FirstOrDefault(c => c.Id.Equals(LegacyProducts.UploaderComponent, StringComparison.OrdinalIgnoreCase)) is { IsSelected: true } uploader)
{
rows.Add(replaces
? new ChangeRow(Loc.L("Setup.Changes.Replace", uploader.Name, legacy.Version), Loc.L("Tooltips.Setup.Changes.Replace", legacy.Directory), false)
: new ChangeRow(Loc.L("Setup.Changes.KeptSeparate", uploader.Name), Loc.L("Tooltips.Setup.Changes.KeptSeparate", legacy.Directory), false));
}
return rows;
}
}
public bool HasChanges => Changes.Count > 0;
/// <summary>The changes in one line ("Adds Chronos Uploader · Removes Chronos Server 1.0.0").</summary>
public string ChangesText => string.Join(" · ", Changes.Select(c => c.Text));
private InstallScope Scope => _allUsers ? InstallScope.AllUsers : InstallScope.CurrentUser;
public bool IsAllUsers
{
@@ -270,17 +350,21 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
public bool HasStartMenuOption => SelectedShortcuts().Any(s => s.StartMenu);
public bool HasLaunchOption => _engine?.LaunchTarget(SelectedComponents) is not null;
public string InstallText => CanChangeLocation ? Loc.L("Setup.Action.Install") : Loc.L("Setup.Action.Update");
public string InstallText => IsUpgrade ? Loc.L("Setup.Action.Update") : Loc.L("Setup.Action.Install");
/// <summary>What Install does, or why it is disabled: no program selected, or a folder it cannot use.</summary>
public string InstallToolTip => !Components.Any(c => c.IsSelected) ? Loc.L("Tooltips.Setup.NoComponent")
public string InstallToolTip => SelectedComponents.Count == 0 ? Loc.L("Tooltips.Setup.NoComponent")
: !IsDirectoryValid ? FolderErrorText
: CanChangeLocation ? Loc.L("Tooltips.Setup.Install") : Loc.L("Tooltips.Setup.Update");
: IsUpgrade ? Loc.L("Tooltips.Setup.Update") : Loc.L("Tooltips.Setup.Install");
/// <summary>Removing user data waits for its plan, so the user has seen what goes before choosing Uninstall.</summary>
/// <summary>
/// Removing user data waits for its plan, so the user has seen what goes before choosing Uninstall. Installing needs
/// a program of the payload (a retained one alone is not an installation); with nothing ticked on an installed copy
/// the action is Uninstall.
/// </summary>
private bool CanStart => IsOptions && (IsUninstall
? !_removeUserData || _dataPlan is not null
: IsInstall && IsDirectoryValid && Components.Any(c => c.IsSelected));
: IsInstall && (IsUninstallAll || (IsDirectoryValid && SelectedComponents.Count > 0)));
// ---- Uninstall options ----
@@ -360,6 +444,11 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
public string DoneText => IsUninstall ? Loc.L("Setup.Done.Removed", _product) : Loc.L("Setup.Done.Installed", _product);
/// <summary>"3 files kept": files of the previous version that changed since setup installed them, left in place.</summary>
public string KeptText => _keptFiles > 0 ? Loc.Plural("Setup.Done.Kept", _keptFiles) : string.Empty;
public bool HasKeptFiles => IsDone && _keptFiles > 0;
public bool CanLaunch => IsDone && _launchProgram is not null;
public string ErrorText => _failure switch
@@ -439,37 +528,48 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
{
var request = new InstallRequest(
Path.TrimEndingDirectorySeparator(Path.GetFullPath(_directory)),
_allUsers ? InstallScope.AllUsers : InstallScope.CurrentUser,
Scope,
SelectedComponents,
HasDesktopOption && _desktop,
HasStartMenuOption && _startMenu);
HasStartMenuOption && _startMenu)
{ Keep = KeptComponents };
var target = engine.LaunchTarget(request.Components);
var program = target is null ? null : PayloadPath.Resolve(request.Directory, target);
var launch = _launchAfter ? program : null;
var legacy = _plan!.LegacyToReplace(request.Components, request.Scope, request.Directory);
if (request.Scope == InstallScope.AllUsers && !Elevation.IsElevated)
{
await InstallElevatedAsync(request, program);
await InstallElevatedAsync(request, program, legacy);
return;
}
directory = request.Directory;
// Read before the upgrade rewrites the log, so a program it drops still names its service.
var programs = InstallPlan.Programs(engine.Manifest, request.Directory).ToList();
var programs = InstallPlan.Programs(engine.Manifest, request.Directory, request.Keep).ToList();
var owned = CommandProgram.FullPaths(request.Directory, programs);
if (await CloseProgramsAsync(request.Directory, programs, owned) is not { } running) return;
if (await CloseProgramsAsync(request.Directory, programs, owned, legacy?.Product) is not { } running) return;
BeginWork(indeterminate: false);
if (running.Count > 0)
// The services of a retained component the user unticked (the 1.0 Server) are deleted; the others are
// stopped for the upgrade and run again after it.
var removing = InstalledServices.Find(CommandProgram.FullPaths(request.Directory, _plan.Removed(request.Keep).SelectMany(r => r.Files)));
var stopping = running.ExceptBy(removing.Select(s => s.Name), s => s.Name, StringComparer.OrdinalIgnoreCase).ToList();
if (stopping.Count > 0)
{
_stopped = running;
await ApplyToServicesAsync(request.Directory, running, ServiceActions.Stop);
_stopped = stopping;
await ApplyToServicesAsync(request.Directory, stopping, ServiceActions.Stop);
}
await ApplyToServicesAsync(request.Directory, removing, ServiceActions.Remove);
var progress = new Progress<SetupProgress>(ReportProgress);
await Task.Run(() => engine.Install(request, progress, CancellationToken.None));
var result = await Task.Run(() => engine.Install(request, progress, CancellationToken.None));
_keptFiles = result.KeptFiles;
// Services whose program the upgrade removed go; the ones stopped for it run again.
var after = InstalledServices.Find(owned).Where(s => !File.Exists(s.Program)).UnionBy(_stopped, s => s.Name, StringComparer.OrdinalIgnoreCase).ToList();
_stopped = [];
await ApplyToServicesAsync(request.Directory, after, ServiceActions.Prune | ServiceActions.Start);
// The legacy Uploader goes once this installation works; a per-user one is the unelevated parent's to remove.
if (legacy is not null && !(_arguments.Elevated && legacy.Scope == InstallScope.CurrentUser))
await Task.Run(() => LegacyProducts.TryMerge(legacy, engine.Manifest, request.Directory));
_launchProgram = program;
Complete();
if (launch is not null) Launch();
@@ -483,15 +583,16 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
/// <summary>
/// All users without administrator rights: an elevated copy installs with the chosen options. This process
/// stays behind, hidden, to start <paramref name="program"/> unelevated if the copy asks for it.
/// stays behind, hidden, to start <paramref name="program"/> unelevated if the copy asks for it, and to remove a
/// per-user <paramref name="legacy"/> Uploader afterwards: it belongs to this account, not to the approving one.
/// </summary>
private async Task InstallElevatedAsync(InstallRequest request, string? program)
private async Task InstallElevatedAsync(InstallRequest request, string? program, LegacyInstall? legacy)
{
if (_arguments.Elevated) throw new SetupException(SetupExitCode.ElevationDeclined, "Still not elevated after relaunch.");
var switches = new SetupArguments
{
Directory = request.Directory,
Components = request.Components,
Components = [.. request.Components, .. request.Keep.Select(k => k.Id)],
AllUsers = true,
NoDesktopShortcut = !request.DesktopShortcuts,
NoStartMenu = !request.StartMenuShortcuts,
@@ -500,7 +601,27 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
};
var child = Elevation.Start(switches, WindowHandle) ?? throw new SetupException(SetupExitCode.ElevationDeclined, "Administrator approval declined.");
VisibilityRequested?.Invoke(this, false);
Finish(await Elevation.WaitAsync(child, program));
var code = await Elevation.WaitAsync(child, program);
if (code == SetupExitCode.Success && legacy is { Scope: InstallScope.CurrentUser })
await Task.Run(() => LegacyProducts.TryMerge(legacy, _engine!.Manifest, request.Directory));
Finish(code);
}
/// <summary>
/// Every component unticked on an installed copy: the uninstall options of that copy (folder, Remove my data and
/// its plan), in the same window.
/// </summary>
private void SwitchToUninstall()
{
if (UninstallEngine.Locate(_plan!.Directory, null) is not { } installed)
{
Fail(new SetupException(SetupExitCode.NotInstalled, $"No installation log in '{_plan.Directory}'."));
return;
}
_installed = installed;
_dataOwners = UserDataOwners.RemovableBeside(installed.Log.Components, SetupRegistry.OtherInstalls(installed.Directory, InstallEngine.Publisher));
_directory = installed.Directory;
Stage = SetupStage.Options;
}
private async Task UninstallAsync()
@@ -510,6 +631,13 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
{
var owned = CommandProgram.FullPaths(installed.Directory, installed.Log.Files);
if (await CloseProgramsAsync(installed.Directory, installed.Log.Files, owned) is not { } running) return;
if (installed.Log.Scope == InstallScope.AllUsers && !Elevation.IsElevated)
{
// Reached from the install options (every component unticked): an elevated copy removes the programs and
// their services; the data of this account, when chosen, is removed here afterwards.
await UninstallElevatedAsync(installed);
return;
}
BeginWork(indeterminate: false);
// Only now that the programs are closed. A service that was not running is still registered: none may
// outlive its program. If one cannot be deleted, the ones stopped here run again.
@@ -528,19 +656,32 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
}
}
private async Task UninstallElevatedAsync(InstalledProduct installed)
{
if (_arguments.Elevated) throw new SetupException(SetupExitCode.ElevationDeclined, "Still not elevated after relaunch.");
var switches = new SetupArguments { Uninstall = true, Silent = true, Directory = installed.Directory, Language = Loc.Culture.Name };
var child = Elevation.Start(switches, WindowHandle) ?? throw new SetupException(SetupExitCode.ElevationDeclined, "Administrator approval declined.");
BeginWork(indeterminate: true);
var code = await Elevation.WaitAsync(child, null);
if (code != SetupExitCode.Success) throw new SetupException(code, $"The elevated uninstall exited with {code}.");
if (_removeUserData && _dataPlan is { Entries.Count: > 0 } plan) await Task.Run(plan.Remove);
Complete();
}
/// <summary>
/// Null when the user must first confirm (Confirm stage) that the programs and services running from
/// <paramref name="directory"/> may close. Otherwise the running programs have closed, and the result lists the
/// <paramref name="directory"/> (and from <paramref name="alsoClose"/>, the legacy Uploader being replaced) may close. Otherwise the running programs have closed, and the result lists the
/// running services of <paramref name="owned"/>, which the caller stops or deletes: a program that does not close
/// stops setup before any service is touched.
/// </summary>
private async Task<IReadOnlyList<InstalledService>?> CloseProgramsAsync(string directory, IEnumerable<string> programs, IReadOnlySet<string> owned)
private async Task<IReadOnlyList<InstalledService>?> CloseProgramsAsync(string directory, IEnumerable<string> programs, IReadOnlySet<string> owned,
InstalledProduct? alsoClose = null)
{
// A confirmation answers one prompt only; a later attempt asks again.
var confirmed = _closeConfirmed;
_closeConfirmed = false;
var services = InstalledServices.Find(owned).Where(InstalledServices.IsRunning).ToList();
var running = RunningPrograms.Find(directory, programs, services);
var running = RunningPrograms.Find(directory, programs, services, alsoClose);
try
{
if (running.Count == 0 && services.Count == 0) return services;
@@ -688,9 +829,26 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
OnPropertyChanged(nameof(HasDesktopOption));
OnPropertyChanged(nameof(HasStartMenuOption));
OnPropertyChanged(nameof(HasLaunchOption));
OnPropertyChanged(nameof(Changes));
OnPropertyChanged(nameof(HasChanges));
OnPropertyChanged(nameof(ChangesText));
OnPropertyChanged(nameof(IsUninstallAll));
OnPropertyChanged(nameof(IsInstallPrimary));
OnPropertyChanged(nameof(IsUninstallAllPrimary));
OnPropertyChanged(nameof(IsCancelDefault));
OnDirectoryRuleChanged();
}
/// <summary>The installed version of <paramref name="component"/> when the installation upgraded here has it; null otherwise.</summary>
private string? InstalledVersionOf(string component) =>
_plan is { Existing: not null, Previous: { } previous } && previous.Components.Contains(component, StringComparer.OrdinalIgnoreCase)
? previous.VersionOf(component)
: null;
/// <summary>The files a removal plan names: the first few, then "…".</summary>
private static string FileList(IReadOnlyList<string> files) =>
files.Count <= 3 ? string.Join(", ", files) : string.Join(", ", files.Take(3)) + ", …";
/// <summary>The folder, the scope or the components changed: whether the folder is valid, and why not, may have too.</summary>
private void OnDirectoryRuleChanged()
{
+43 -11
View File
@@ -32,18 +32,20 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="44" />
<RowDefinition Height="44" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Each row says whether it is installed; a program this setup no longer ships is kept until unticked. -->
<TextBlock Text="{l:Loc Setup.Field.Components}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,3,16,0" />
<ItemsControl Grid.Column="1" ItemsSource="{Binding Components}" Focusable="False" Margin="0,0,0,8">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel Margin="0,0,0,6">
<TextBlock DockPanel.Dock="Right" Text="{Binding SizeText}" Style="{StaticResource Text.Secondary}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
<TextBlock DockPanel.Dock="Right" Text="{Binding StateText}" Style="{StaticResource Text.Secondary}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsSelected}" IsEnabled="{Binding IsAvailable}" ToolTip="{Binding ToolTip}"
ToolTipService.ShowOnDisabled="True" />
</DockPanel>
@@ -51,8 +53,30 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Grid.Row="1" Text="{l:Loc Setup.Field.Scope}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,16,0" />
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<!-- The dry-run plan: what Update adds, removes or replaces, before it can run. -->
<TextBlock Grid.Row="1" Text="{l:Loc Setup.Field.Changes}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,16,8"
Visibility="{Binding HasChanges, Converter={StaticResource BoolToVisibility}}" />
<ItemsControl Grid.Row="1" Grid.Column="1" ItemsSource="{Binding Changes}" Focusable="False" Margin="0,0,0,8"
Visibility="{Binding HasChanges, Converter={StaticResource BoolToVisibility}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="Change" Text="{Binding Text}" ToolTip="{Binding ToolTip}" Margin="0,0,16,0" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsRemoval}" Value="True">
<Setter TargetName="Change" Property="Foreground" Value="{DynamicResource Brush.Warning}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Grid.Row="2" Text="{l:Loc Setup.Field.Scope}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,16,0" />
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
<RadioButton Content="{l:Loc Setup.Scope.JustMe}" IsChecked="{Binding IsJustMe}" IsEnabled="{Binding CanChooseJustMe}"
ToolTipService.ShowOnDisabled="True" ToolTip="{Binding JustMeToolTip}" Margin="0,0,20,0" />
<RadioButton Content="{l:Loc Setup.Scope.AllUsers}" IsChecked="{Binding IsAllUsers}" IsEnabled="{Binding CanChangeLocation}"
@@ -60,8 +84,8 @@
</StackPanel>
<!-- The field comes before Browse in the Tab order, as on screen; a path reads left to right in every language. -->
<TextBlock Grid.Row="2" Text="{l:Loc Setup.Field.Folder}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,16,0" />
<Grid Grid.Row="2" Grid.Column="1" VerticalAlignment="Center">
<TextBlock Grid.Row="3" Text="{l:Loc Setup.Field.Folder}" Foreground="{DynamicResource Brush.TextMuted}" VerticalAlignment="Center" Margin="0,0,16,0" />
<Grid Grid.Row="3" Grid.Column="1" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
@@ -72,8 +96,8 @@
ToolTipService.ShowOnDisabled="True" ToolTip="{Binding BrowseToolTip}" />
</Grid>
<TextBlock Grid.Row="3" Text="{l:Loc Setup.Field.Options}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,16,0" />
<StackPanel Grid.Row="3" Grid.Column="1" Margin="0,12,0,0">
<TextBlock Grid.Row="4" Text="{l:Loc Setup.Field.Options}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,12,16,0" />
<StackPanel Grid.Row="4" Grid.Column="1" Margin="0,12,0,0">
<CheckBox Content="{l:Loc Setup.Options.Desktop}" IsChecked="{Binding DesktopShortcut}" ToolTip="{l:Loc Tooltips.Setup.Desktop}" Margin="0,0,0,6"
Visibility="{Binding HasDesktopOption, Converter={StaticResource BoolToVisibility}}" />
<CheckBox Content="{l:Loc Setup.Options.StartMenu}" IsChecked="{Binding StartMenuShortcuts}" ToolTip="{l:Loc Tooltips.Setup.StartMenu}" Margin="0,0,0,6"
@@ -154,8 +178,13 @@
<!-- Success -->
<DockPanel Grid.Row="1" VerticalAlignment="Center" Visibility="{Binding IsDone, Converter={StaticResource BoolToVisibility}}">
<ui:Icon Glyph="{StaticResource Icon.SuccessCircle}" Size="20" Foreground="{DynamicResource Brush.Success}" Margin="0,0,12,0" VerticalAlignment="Center" />
<TextBlock x:Name="DoneMessage" Text="{Binding DoneText}" Style="{StaticResource Text.Title}" TextWrapping="Wrap" VerticalAlignment="Center"
AutomationProperties.LiveSetting="Assertive" />
<StackPanel VerticalAlignment="Center">
<TextBlock x:Name="DoneMessage" Text="{Binding DoneText}" Style="{StaticResource Text.Title}" TextWrapping="Wrap"
AutomationProperties.LiveSetting="Assertive" />
<!-- Files of the previous version that changed since setup installed them were left in place. -->
<TextBlock Text="{Binding KeptText}" Style="{StaticResource Text.Secondary}" ToolTip="{l:Loc Tooltips.Setup.Done.Kept}" Margin="0,6,0,0"
Visibility="{Binding HasKeptFiles, Converter={StaticResource BoolToVisibility}}" />
</StackPanel>
</DockPanel>
<!-- Failure -->
@@ -174,9 +203,12 @@
Visibility="{Binding IsInstallOptions, Converter={StaticResource BoolToVisibility}}" />
<StackPanel x:Name="Footer" DockPanel.Dock="Right" Orientation="Horizontal">
<Button Content="{l:Loc Setup.Action.Cancel}" MinWidth="88" Margin="0,0,8,0" Command="{Binding CloseCommand}" ToolTip="{l:Loc Tooltips.Setup.Cancel}"
IsCancel="{Binding IsOptions}" IsDefault="{Binding IsUninstallOptions}" Visibility="{Binding IsOptions, Converter={StaticResource BoolToVisibility}}" />
IsCancel="{Binding IsOptions}" IsDefault="{Binding IsCancelDefault}" Visibility="{Binding IsOptions, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Primary}" MinWidth="104" Content="{Binding InstallText}" Command="{Binding PrimaryCommand}" ToolTip="{Binding InstallToolTip}"
ToolTipService.ShowOnDisabled="True" IsDefault="{Binding IsInstallOptions}" Visibility="{Binding IsInstallOptions, Converter={StaticResource BoolToVisibility}}" />
ToolTipService.ShowOnDisabled="True" IsDefault="{Binding IsInstallPrimary}" Visibility="{Binding IsInstallPrimary, Converter={StaticResource BoolToVisibility}}" />
<!-- Every component unticked on an installed copy: continue to the uninstall options. -->
<Button Style="{StaticResource Button.Destructive}" MinWidth="104" Content="{l:Loc Setup.Action.Uninstall}" Command="{Binding PrimaryCommand}"
ToolTip="{l:Loc Tooltips.Setup.UninstallAll}" Visibility="{Binding IsUninstallAllPrimary, Converter={StaticResource BoolToVisibility}}" />
<Button Style="{StaticResource Button.Destructive}" MinWidth="104" Content="{l:Loc Setup.Action.Uninstall}" Command="{Binding PrimaryCommand}" ToolTip="{l:Loc Tooltips.Setup.Uninstall}"
Visibility="{Binding IsUninstallOptions, Converter={StaticResource BoolToVisibility}}" />
+5 -1
View File
@@ -19,11 +19,13 @@ internal sealed partial class SetupWindow : ChronosWindow
{
private readonly SetupViewModel _model;
private SetupStage _shownStage;
private bool _shownUninstall;
public SetupWindow(SetupViewModel model)
{
_model = model;
_shownStage = model.Stage;
_shownUninstall = model.IsUninstall;
DataContext = model;
InitializeComponent();
// Ahead of the chrome's own Close binding, which is always enabled.
@@ -59,8 +61,10 @@ internal sealed partial class SetupWindow : ChronosWindow
{
if (e.PropertyName == nameof(SetupViewModel.IsDataPlanVisible) && _model.IsDataPlanVisible)
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () => Announce(DataPlanHeading));
if (_model.Stage == _shownStage) return;
// Uninstall from the install options keeps the Options stage but shows other buttons.
if (_model.Stage == _shownStage && _model.IsUninstall == _shownUninstall) return;
_shownStage = _model.Stage;
_shownUninstall = _model.IsUninstall;
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>
{
FocusDefault();