fix(setup): change only what starts a program setup installed; Server only inside Program Files

Services, sign-in entries and shortcuts are matched against the full paths of the files the install log or the
payload lists, never against everything under the install folder: an install into a shared folder such as D:\Apps
or /DIR="C:\Program Files" no longer stops, starts or deletes other vendors' services or removes their Run values.
The elevated step now takes the names the unelevated setup found (/SERVICES=... /NAMES=...) and reads each service
again, acting only when it still starts a program of the folder's log or of its own payload (or, for Prune, a
program of the folder that is gone).

Programs are asked to close before any service is touched. On uninstall the services are deleted only once the
programs have closed, just before the files go; a failed install or uninstall starts again the services it
stopped, and after an upgrade setup starts exactly the services it stopped, whatever their start type.

The Server component installs only for all users in a folder inside Program Files. In the window a custom folder
outside it is invalid while the Server is selected, with a tooltip saying why; silent mode refuses it. An upgrade
of an installation elsewhere cannot add the Server, and one it carried is dropped with its service.

Sign-in entries use StartupCommand (the same file as on fix/shell-notify) and are removed by
SetupRegistry.DeleteStartupEntries only when the client's or the Uploader's value starts a program the install log
lists; an upgrade that drops a program removes its entry too. StartupEntries is gone.

A shortcut that starts another product's existing copy is still left alone but now logged; uninstalling the
product it starts hands it to another product of the same scope that lists it and has the same program, so the
Uploader that stays keeps its shortcuts. Another registered Titano installation whose folder or log cannot be read
now counts as using every program's data, so "Remove my data" never offers it.

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 11:41:30 +00:00
1 parent 3f9e78622f
commit 067e8ca062
22 files changed
+834 -282

No files matched your search

+42 -7
View File
@@ -2,12 +2,19 @@ using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Win32;
using Titano.Core.IO;
namespace Titano.Setup.Engine;
/// <summary>An installation found in Add/Remove Programs.</summary>
internal sealed record ExistingInstall(InstallScope Scope, string Directory, string Version);
/// <summary>
/// Another Titano installation registered in Add/Remove Programs: its folder, and its log when that can be read now
/// (null for a drive that is offline, a folder that is gone or a log that cannot be read).
/// </summary>
internal sealed record OtherInstall(string? Directory, InstallLog? Log);
/// <summary>Values written to the Add/Remove Programs entry.</summary>
internal sealed record UninstallEntry(string DisplayName, string Version, string Publisher, string Directory, string UninstallerPath, string DisplayIcon, long EstimatedBytes, string? AboutUrl);
@@ -36,12 +43,13 @@ internal static partial class SetupRegistry
}
/// <summary>
/// The logs of the other installations by <paramref name="publisher"/> (any product, either scope) except the one in
/// <paramref name="directory"/>: what an uninstall must leave working (the user data they share).
/// The other installations by <paramref name="publisher"/> (any product, either scope) except the one in
/// <paramref name="directory"/>: what an uninstall must leave working (the user data and shortcuts they share).
/// Every registered entry counts, also one whose folder or log cannot be read right now.
/// </summary>
public static IReadOnlyList<InstallLog> OtherInstalls(string directory, string publisher)
public static IReadOnlyList<OtherInstall> OtherInstalls(string directory, string publisher)
{
var found = new List<InstallLog>();
var found = new List<OtherInstall>();
foreach (var scope in (ReadOnlySpan<InstallScope>)[InstallScope.CurrentUser, InstallScope.AllUsers])
{
using var root = Hive(scope).OpenSubKey(UninstallRoot.TrimEnd('\\'));
@@ -52,9 +60,11 @@ internal static partial class SetupRegistry
{
using var key = root.OpenSubKey(name);
if (key?.GetValue("Publisher") is not string p || !p.Equals(publisher, StringComparison.Ordinal)) continue;
if (key.GetValue("InstallLocation") is not string location || !Directory.Exists(location)) continue;
if (CommandProgram.IsPathInside(location, directory) && CommandProgram.IsPathInside(directory, location)) continue;
if (InstallLog.TryLoad(location) is { } log) found.Add(log);
var location = key.GetValue("InstallLocation") as string;
if (location is { Length: > 0 } && CommandProgram.IsPathInside(location, directory) && CommandProgram.IsPathInside(directory, location)) continue;
var log = location is { Length: > 0 } && Directory.Exists(location) ? InstallLog.TryLoad(location) : null;
if (log is null) Titano.Core.Diagnostics.Log.Info("setup", $"Installation '{name}' in '{location}' cannot be read now; it counts as using every program");
found.Add(new OtherInstall(location, log));
}
catch (Exception ex) when (ex is System.Security.SecurityException or UnauthorizedAccessException or IOException)
{
@@ -86,6 +96,31 @@ internal static partial class SetupRegistry
public static void DeleteUninstallEntry(InstallScope scope, string productKey) =>
Hive(scope).DeleteSubKeyTree(UninstallRoot + productKey, throwOnMissingSubKey: false);
/// <summary>
/// Removes the sign-in entries of the client and the Uploader (<c>HKCU\…\Run</c>, written by the programs
/// themselves) that start one of <paramref name="programs"/> (<see cref="CommandProgram.FullPaths"/> of the files an
/// installation lists); another copy's entries, and other programs' values, stay.
/// </summary>
public static void DeleteStartupEntries(IReadOnlySet<string> programs)
{
using var run = Registry.CurrentUser.OpenSubKey(StartupCommand.RunKey, writable: true);
if (run is not null) DeleteStartupEntries(run, programs);
}
/// <summary><see cref="DeleteStartupEntries(IReadOnlySet{string})"/> in <paramref name="run"/>; returns the names removed.</summary>
public static IReadOnlyList<string> DeleteStartupEntries(RegistryKey run, IReadOnlySet<string> programs)
{
var removed = new List<string>();
foreach (var name in (ReadOnlySpan<string>)[StartupCommand.ClientValue, StartupCommand.UploaderValue])
{
if (!CommandProgram.IsAmong(StartupCommand.Executable(run.GetValue(name) as string), programs)) continue;
run.DeleteValue(name, throwOnMissingValue: false);
removed.Add(name);
Titano.Core.Diagnostics.Log.Info("setup", $"Sign-in entry '{name}' removed");
}
return removed;
}
/// <summary>Registers <paramref name="extension"/> to open with <c>"program" "%1"</c> under <paramref name="progId"/>.</summary>
public static void RegisterFileType(InstallScope scope, string extension, string progId, string description, string program)
{