Files
Chronos/src/Titano.Setup/App.cs
T
Claude c97b4fb82c feat(setup): add one-screen installer, uninstaller and silent mode
Titano.Setup reads the TPK1 payload from its own executable and installs per
user (%LOCALAPPDATA%\Programs) or for all users (Program Files, relaunched
elevated through ShellExecuteEx "runas"). Extraction is hash-verified into a
staging folder and committed with rollback; upgrades replace files in place,
remove obsolete ones and never touch %LOCALAPPDATA%\Titano.

- Components, scope, folder (IFileOpenDialog picker), desktop and Start menu
  shortcuts (IShellLinkW), start-after-install, language picker
- Add/Remove Programs entry, .titano file type, install log
- /uninstall [/S] removes only logged files, shortcuts and registry entries;
  user data only when "Remove my data" is ticked; the uninstaller deletes
  itself through a temporary helper copy
- Silent switches /S /DIR= /COMPONENTS= /ALLUSERS /NODESKTOP /NOSTARTMENU
  /LAUNCH /LANG= with documented exit codes; running programs are asked to
  close, never killed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 10:16:20 +00:00

77 lines
2.6 KiB
C#

using System.Windows;
using Titano.Core.Diagnostics;
using Titano.Core.Packaging;
using Titano.Setup.Cli;
using Titano.Setup.Engine;
using Titano.Setup.Views;
using Titano.Ui.Theming;
namespace Titano.Setup;
/// <summary>
/// Interactive setup: opens the payload (or, for <c>/uninstall</c>, the installation), elevates an all-users
/// uninstall up front, and shows the setup window. The exit code is the view model's outcome.
/// </summary>
internal sealed class App(SetupArguments arguments) : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
ShutdownMode = ShutdownMode.OnExplicitShutdown;
ThemeManager.Initialize(this, AppTheme.Dark);
_ = StartAsync();
}
private async Task StartAsync()
{
try
{
var model = arguments.Uninstall ? await ForUninstallAsync() : ForInstall();
if (model is null) return;
var window = new SetupWindow(model);
MainWindow = window;
window.Closed += (_, _) =>
{
model.Dispose();
Shutdown((int)model.ExitCode);
};
window.Show();
}
catch (Exception ex)
{
Log.Error("setup", "Setup could not start", ex);
Shutdown((int)SetupExitCode.Failed);
}
}
private SetupViewModel ForInstall()
{
PayloadReader? payload = null;
try
{
payload = PayloadReader.OpenCurrentProcess();
return SetupViewModel.ForInstall(arguments, payload);
}
catch (Exception ex) when (ex is PayloadException or SetupException)
{
payload?.Dispose();
Log.Error("setup", "Cannot install", ex);
return SetupViewModel.ForFailure(arguments, SilentSetup.CodeFor(ex));
}
}
/// <summary>The uninstall window, or null when this process handed over to an elevated copy and is shutting down.</summary>
private async Task<SetupViewModel?> ForUninstallAsync()
{
var product = UninstallEngine.Locate(arguments.Directory, SilentSetup.PayloadProduct());
if (product is null) return SetupViewModel.ForFailure(arguments, SetupExitCode.NotInstalled);
if (product.Log.Scope == InstallScope.AllUsers && !Elevation.IsElevated)
{
var code = arguments.Elevated ? SetupExitCode.ElevationDeclined : await Elevation.RunElevatedAsync(arguments, null);
Shutdown((int)code);
return null;
}
return SetupViewModel.ForUninstall(arguments, product);
}
}