fix(setup): handle install-folder services, startup entries, shared shortcuts and data

- Windows services whose program lies in the install folder (Titano.Server
  --install-service) are found in the registry and, through the Service
  Control Manager, stopped before files are replaced (they join the
  "programs running" prompt), started again after an upgrade that stopped
  them, deleted when an upgrade drops their program and on uninstall. An
  unelevated setup runs that step in an elevated copy (/SERVICES=...).
- The Server component installs for all users only (manifest allUsersOnly):
  choosing it moves a new install to Program Files and disables "Just me"
  with the reason; a per-user install cannot take it.
- Uninstall removes every HKCU Run value that starts a program in the folder
  (the Uploader's "Start with Windows").
- A shortcut that already starts an existing program elsewhere is neither
  retargeted nor logged, and a logged shortcut is deleted only while it
  still starts a program of this folder, so the two products no longer
  remove each other's "Titano Uploader" shortcuts.
- "Remove my data" lists and deletes only the data of this product's
  programs that no other installed Titano product uses (the desktop app and
  the Uploader share %LOCALAPPDATA%\Titano and its logs folder).
- The .titano file type is named in setup's language (Setup.FileType.*).

Setup tests run in Titano.App.Tests on Windows CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 10:29:16 +00:00
1 parent 81f10379c8
commit 4f6bbfba5d
32 files changed
+1175 -88

No files matched your search

+25 -11
View File
@@ -10,9 +10,11 @@ namespace Titano.Setup.Engine;
internal sealed record InstalledProduct(string Directory, InstallLog Log);
/// <summary>
/// Removes an installation using only its log: shortcuts, file types, logged files, the log and the Add/Remove
/// Programs entry, then the uninstaller itself. Files the log does not list are left alone; the user data folder
/// is deleted only when <c>removeUserData</c> is set by an explicit choice in the window.
/// Removes an installation using only its log: shortcuts that still start its programs, "Start with Windows" entries
/// pointing into its folder, file types, logged files, the log and the Add/Remove Programs entry, then the
/// uninstaller itself. Files the log does not list are left alone; user data is deleted only through a plan the user
/// saw and chose in the window. Windows services of the folder are stopped and deleted by the caller first
/// (<see cref="InstalledServices.ApplyAsync"/>), as that may need an elevated step.
/// </summary>
internal static class UninstallEngine
{
@@ -29,17 +31,19 @@ internal static class UninstallEngine
return null;
}
public static void Uninstall(InstalledProduct product, bool removeUserData, IProgress<SetupProgress>? progress)
/// <param name="userData">The "Remove my data" plan the user confirmed; null keeps the user data.</param>
public static void Uninstall(InstalledProduct product, UserDataPlan? userData, IProgress<SetupProgress>? progress)
{
var (directory, log) = product;
Log.Info("setup", $"Removing {log.Product} {log.Version} from '{directory}' (remove data: {removeUserData})");
Log.Info("setup", $"Removing {log.Product} {log.Version} from '{directory}' (remove data: {userData is not null})");
// First, so that a failure here leaves the program installed and the uninstaller able to retry.
if (removeUserData && Directory.Exists(SetupPaths.UserData))
if (userData is { Entries.Count: > 0 })
{
Log.Info("setup", $"Removing user data '{SetupPaths.UserData}' at the user's request");
Directory.Delete(SetupPaths.UserData, recursive: true);
Log.Info("setup", $"Removing {userData.Entries.Count} entries of '{userData.Folder}' at the user's request");
userData.Remove();
}
foreach (var link in log.Shortcuts) DeleteShortcut(link, log.Scope);
foreach (var link in log.Shortcuts) DeleteShortcut(link, log.Scope, directory);
StartupEntries.RemoveInside(directory);
progress?.Report(new SetupProgress(0.1, string.Empty));
var fileTypes = log.Associations.Where(a => SetupRegistry.IsValidFileType(a.Extension, a.ProgId)).ToList();
@@ -82,8 +86,12 @@ internal static class UninstallEngine
progress?.Report(new SetupProgress(1, string.Empty));
}
/// <summary>Deletes a shortcut recorded in a log, but only a <c>.lnk</c> directly in the Start menu or desktop folder.</summary>
public static void DeleteShortcut(string link, InstallScope scope)
/// <summary>
/// Deletes a shortcut recorded in a log, but only a <c>.lnk</c> directly in the Start menu or desktop folder that
/// still starts a program inside <paramref name="directory"/>: another product installing a program of the same
/// name may have pointed it at its own copy since.
/// </summary>
public static void DeleteShortcut(string link, InstallScope scope, string directory)
{
var folder = Path.GetDirectoryName(link);
var allowed = folder is not null && link.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)
@@ -96,6 +104,12 @@ internal static class UninstallEngine
}
try
{
if (ShellLink.TargetOf(link) is not { } target) return;
if (!CommandProgram.IsPathInside(target, directory))
{
Log.Info("setup", $"Shortcut '{link}' now starts '{target}'; kept");
return;
}
File.Delete(link);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)