fix(setup): an upgrade moves a renamed program's sign-in entry instead of deleting it
RemoveLeftovers deleted every Titano or Titano Uploader Run value that started a file the upgrade removed, including a client or Uploader the new version only renamed or moved. The new program then found no entry to follow and Start with Windows was silently off. Setup now points such an entry at the program of the same component in the new payload (its shortcut target), keeping the options and the value name, and removes it only when the component is no longer installed. Uninstall still removes the entries of the programs its log lists. StartupCommand.StartsFrom, left over from the superseded folder-scoped cleanup, is gone; StartupCommand.Retarget replaces it and its misleading test now covers how setup moves an entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
6 files changed
+141
-41
No files matched your search
@@ -28,6 +28,9 @@ internal static partial class SetupRegistry
|
||||
private const string UninstallRoot = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\";
|
||||
private const string ClassesRoot = @"Software\Classes\";
|
||||
|
||||
/// <summary>No replacement program: every matching sign-in entry is removed.</summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> NoPrograms = new Dictionary<string, string>();
|
||||
|
||||
private static RegistryKey Hive(InstallScope scope) => scope == InstallScope.AllUsers ? Registry.LocalMachine : Registry.CurrentUser;
|
||||
|
||||
/// <summary>The installation registered under <paramref name="productKey"/> whose folder still exists, current user first.</summary>
|
||||
@@ -101,24 +104,47 @@ internal static partial class SetupRegistry
|
||||
/// 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);
|
||||
}
|
||||
public static void DeleteStartupEntries(IReadOnlySet<string> programs) => MoveStartupEntries(programs, NoPrograms);
|
||||
|
||||
/// <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)
|
||||
public static IReadOnlyList<string> DeleteStartupEntries(RegistryKey run, IReadOnlySet<string> programs) => MoveStartupEntries(run, programs, NoPrograms);
|
||||
|
||||
/// <summary>
|
||||
/// After an upgrade: a sign-in entry of the client or the Uploader that starts one of <paramref name="dropped"/>
|
||||
/// (programs the previous version installed and this one does not) starts the program <paramref name="programs"/>
|
||||
/// gives for its value name instead, with the same options, when this version installs one (an update renamed or
|
||||
/// moved it, and the program would find no entry to follow); otherwise it is removed (the component was dropped).
|
||||
/// </summary>
|
||||
public static void MoveStartupEntries(IReadOnlySet<string> dropped, IReadOnlyDictionary<string, string> programs)
|
||||
{
|
||||
var removed = new List<string>();
|
||||
using var run = Registry.CurrentUser.OpenSubKey(StartupCommand.RunKey, writable: true);
|
||||
if (run is not null) MoveStartupEntries(run, dropped, programs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MoveStartupEntries(IReadOnlySet{string}, IReadOnlyDictionary{string, string})"/> in
|
||||
/// <paramref name="run"/>; returns the names moved or removed.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<string> MoveStartupEntries(RegistryKey run, IReadOnlySet<string> dropped, IReadOnlyDictionary<string, string> programs)
|
||||
{
|
||||
var changed = 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");
|
||||
var command = run.GetValue(name) as string;
|
||||
if (!CommandProgram.IsAmong(StartupCommand.Executable(command), dropped)) continue;
|
||||
if (programs.TryGetValue(name, out var program) && StartupCommand.Retarget(command, program) is { } moved)
|
||||
{
|
||||
run.SetValue(name, moved, RegistryValueKind.String);
|
||||
Titano.Core.Diagnostics.Log.Info("setup", $"Sign-in entry '{name}' now starts '{program}'");
|
||||
}
|
||||
else
|
||||
{
|
||||
run.DeleteValue(name, throwOnMissingValue: false);
|
||||
Titano.Core.Diagnostics.Log.Info("setup", $"Sign-in entry '{name}' removed");
|
||||
}
|
||||
changed.Add(name);
|
||||
}
|
||||
return removed;
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>Registers <paramref name="extension"/> to open with <c>"program" "%1"</c> under <paramref name="progId"/>.</summary>
|
||||
|
||||
Reference in new issue
Block a user