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:
22 files changed
+834
-282
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Packaging;
|
||||
using Titano.Setup.Cli;
|
||||
@@ -10,10 +11,11 @@ namespace Titano.Setup.Engine;
|
||||
internal sealed record InstalledProduct(string Directory, InstallLog Log);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// Removes an installation using only its log: shortcuts that still start its programs (handed to another Titano
|
||||
/// product that installed the same program and shares them), file types, logged files, the log, the Add/Remove
|
||||
/// Programs entry and the sign-in entries of its programs, then the uninstaller itself. Files the log does not list,
|
||||
/// and anything that starts a program it does not list, are left alone; user data is deleted only through a plan the
|
||||
/// user saw and chose in the window. The Windows services of its programs are stopped and deleted by the caller first
|
||||
/// (<see cref="InstalledServices.ApplyAsync"/>), as that may need an elevated step.
|
||||
/// </summary>
|
||||
internal static class UninstallEngine
|
||||
@@ -42,8 +44,11 @@ internal static class UninstallEngine
|
||||
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, directory);
|
||||
StartupEntries.RemoveInside(directory);
|
||||
if (log.Shortcuts.Count > 0)
|
||||
{
|
||||
var others = SetupRegistry.OtherInstalls(directory, InstallEngine.Publisher);
|
||||
foreach (var link in log.Shortcuts) DeleteShortcut(link, log.Scope, directory, others);
|
||||
}
|
||||
progress?.Report(new SetupProgress(0.1, string.Empty));
|
||||
|
||||
var fileTypes = log.Associations.Where(a => SetupRegistry.IsValidFileType(a.Extension, a.ProgId)).ToList();
|
||||
@@ -64,6 +69,15 @@ internal static class UninstallEngine
|
||||
}
|
||||
|
||||
SetupRegistry.DeleteUninstallEntry(log.Scope, log.ProductKey);
|
||||
try
|
||||
{
|
||||
SetupRegistry.DeleteStartupEntries(CommandProgram.FullPaths(directory, log.Files));
|
||||
}
|
||||
catch (Exception ex) when (ex is System.Security.SecurityException or UnauthorizedAccessException or IOException)
|
||||
{
|
||||
// Windows skips a sign-in entry whose program is gone; not worth failing the removal.
|
||||
Log.Warning("setup", "Sign-in entries not removed", ex);
|
||||
}
|
||||
File.Delete(Path.Combine(directory, InstallLog.FileName));
|
||||
var uninstaller = Path.Combine(directory, log.UninstallerName);
|
||||
try
|
||||
@@ -89,9 +103,11 @@ internal static class UninstallEngine
|
||||
/// <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.
|
||||
/// name may have pointed it at its own copy since. When another installation (<paramref name="others"/>) shares
|
||||
/// the shortcut and has the same program, the shortcut is pointed at that copy instead, so the program that stays
|
||||
/// installed keeps its shortcut.
|
||||
/// </summary>
|
||||
public static void DeleteShortcut(string link, InstallScope scope, string directory)
|
||||
public static void DeleteShortcut(string link, InstallScope scope, string directory, IReadOnlyList<OtherInstall> others)
|
||||
{
|
||||
var folder = Path.GetDirectoryName(link);
|
||||
var allowed = folder is not null && link.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)
|
||||
@@ -110,11 +126,44 @@ internal static class UninstallEngine
|
||||
Log.Info("setup", $"Shortcut '{link}' now starts '{target}'; kept");
|
||||
return;
|
||||
}
|
||||
if (SharedCopy(link, scope, directory, target, others) is { } copy)
|
||||
{
|
||||
ShellLink.Create(link, copy, Path.GetFileNameWithoutExtension(link));
|
||||
Log.Info("setup", $"Shortcut '{link}' now starts '{copy}', which stays installed");
|
||||
return;
|
||||
}
|
||||
File.Delete(link);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or COMException)
|
||||
{
|
||||
Log.Warning("setup", $"Shortcut '{link}' not removed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The same program as <paramref name="target"/> (the same path inside its folder) installed by another product of
|
||||
/// the same scope whose log lists <paramref name="link"/> too; null when there is none.
|
||||
/// </summary>
|
||||
private static string? SharedCopy(string link, InstallScope scope, string directory, string target, IReadOnlyList<OtherInstall> others)
|
||||
{
|
||||
string relative;
|
||||
try
|
||||
{
|
||||
relative = PayloadPath.FromRelative(Path.GetRelativePath(directory, target));
|
||||
}
|
||||
catch (Exception ex) when (ex is PayloadException or ArgumentException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var other in others)
|
||||
{
|
||||
if (other is not { Directory: { } otherDirectory, Log: { } log } || log.Scope != scope) continue;
|
||||
if (!log.Shortcuts.Contains(link, StringComparer.OrdinalIgnoreCase) || !log.Files.Contains(relative, PayloadPath.Comparer)) continue;
|
||||
// The folder comes from another product's registry entry: one Windows cannot use is skipped.
|
||||
if (!SetupPaths.IsUsableInstallDirectory(otherDirectory)) continue;
|
||||
var copy = PayloadPath.Resolve(otherDirectory, relative);
|
||||
if (File.Exists(copy)) return copy;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user