fix(setup): remove the Task Manager state of a sign-in entry setup removes
Uninstalling (or an upgrade dropping a program) deleted the client's or the Uploader's Run value but left its StartupApproved\Run value behind. A moved entry keeps that state, so an entry the user turned off stays off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+35
-12
No files matched your search
@@ -102,12 +102,17 @@ internal static partial class SetupRegistry
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the sign-in entries of the client and the Uploader (<c>HKCU\…\Run</c>, written by the programs
|
/// 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
|
/// 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.
|
/// installation lists), with the on/off state Task Manager keeps for them (<see cref="StartupApproval"/>); another
|
||||||
|
/// copy's entries, and other programs' values, stay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void DeleteStartupEntries(IReadOnlySet<string> programs) => MoveStartupEntries(programs, NoPrograms);
|
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>
|
/// <summary>
|
||||||
public static IReadOnlyList<string> DeleteStartupEntries(RegistryKey run, IReadOnlySet<string> programs) => MoveStartupEntries(run, programs, NoPrograms);
|
/// <see cref="DeleteStartupEntries(IReadOnlySet{string})"/> in <paramref name="run"/> and <paramref name="approval"/>;
|
||||||
|
/// returns the names removed.
|
||||||
|
/// </summary>
|
||||||
|
public static IReadOnlyList<string> DeleteStartupEntries(RegistryKey run, RegistryKey? approval, IReadOnlySet<string> programs) =>
|
||||||
|
MoveStartupEntries(run, approval, programs, NoPrograms);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// After an upgrade: a sign-in entry of the client or the Uploader that starts one of <paramref name="dropped"/>
|
/// After an upgrade: a sign-in entry of the client or the Uploader that starts one of <paramref name="dropped"/>
|
||||||
@@ -118,14 +123,18 @@ internal static partial class SetupRegistry
|
|||||||
public static void MoveStartupEntries(IReadOnlySet<string> dropped, IReadOnlyDictionary<string, string> programs)
|
public static void MoveStartupEntries(IReadOnlySet<string> dropped, IReadOnlyDictionary<string, string> programs)
|
||||||
{
|
{
|
||||||
using var run = Registry.CurrentUser.OpenSubKey(StartupCommand.RunKey, writable: true);
|
using var run = Registry.CurrentUser.OpenSubKey(StartupCommand.RunKey, writable: true);
|
||||||
if (run is not null) MoveStartupEntries(run, dropped, programs);
|
if (run is null) return;
|
||||||
|
using var approval = Registry.CurrentUser.OpenSubKey(StartupApproval.RunKey, writable: true);
|
||||||
|
MoveStartupEntries(run, approval, dropped, programs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="MoveStartupEntries(IReadOnlySet{string}, IReadOnlyDictionary{string, string})"/> in
|
/// <see cref="MoveStartupEntries(IReadOnlySet{string}, IReadOnlyDictionary{string, string})"/> in
|
||||||
/// <paramref name="run"/>; returns the names moved or removed.
|
/// <paramref name="run"/>; a removed entry's on/off state goes from <paramref name="approval"/> too, a moved one keeps
|
||||||
|
/// it. Returns the names moved or removed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IReadOnlyList<string> MoveStartupEntries(RegistryKey run, IReadOnlySet<string> dropped, IReadOnlyDictionary<string, string> programs)
|
public static IReadOnlyList<string> MoveStartupEntries(RegistryKey run, RegistryKey? approval, IReadOnlySet<string> dropped,
|
||||||
|
IReadOnlyDictionary<string, string> programs)
|
||||||
{
|
{
|
||||||
var changed = new List<string>();
|
var changed = new List<string>();
|
||||||
foreach (var name in (ReadOnlySpan<string>)[StartupCommand.ClientValue, StartupCommand.UploaderValue])
|
foreach (var name in (ReadOnlySpan<string>)[StartupCommand.ClientValue, StartupCommand.UploaderValue])
|
||||||
@@ -140,6 +149,8 @@ internal static partial class SetupRegistry
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
run.DeleteValue(name, throwOnMissingValue: false);
|
run.DeleteValue(name, throwOnMissingValue: false);
|
||||||
|
// Its Task Manager state goes with it: nothing of the entry stays behind.
|
||||||
|
approval?.DeleteValue(name, throwOnMissingValue: false);
|
||||||
Titano.Core.Diagnostics.Log.Info("setup", $"Sign-in entry '{name}' removed");
|
Titano.Core.Diagnostics.Log.Info("setup", $"Sign-in entry '{name}' removed");
|
||||||
}
|
}
|
||||||
changed.Add(name);
|
changed.Add(name);
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public sealed class SetupEngineTests(TestContext context)
|
|||||||
{
|
{
|
||||||
private const string TestsKey = @"Software\Titano.Tests";
|
private const string TestsKey = @"Software\Titano.Tests";
|
||||||
|
|
||||||
|
/// <summary>The StartupApproved state Task Manager writes for an entry it turned off.</summary>
|
||||||
|
private static readonly byte[] TurnedOff = [0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[Case(@"""C:\Program Files\Titano\Titano.Server.exe"" --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
[Case(@"""C:\Program Files\Titano\Titano.Server.exe"" --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
||||||
[Case(@"C:\Program Files\Titano\Titano.Server.exe --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
[Case(@"C:\Program Files\Titano\Titano.Server.exe --service", @"C:\Program Files\Titano\Titano.Server.exe")]
|
||||||
@@ -158,7 +161,8 @@ public sealed class SetupEngineTests(TestContext context)
|
|||||||
var keyPath = TestsKey + @"\" + Guid.NewGuid().ToString("N");
|
var keyPath = TestsKey + @"\" + Guid.NewGuid().ToString("N");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var run = Registry.CurrentUser.CreateSubKey(keyPath, writable: true))
|
using (var run = Registry.CurrentUser.CreateSubKey(keyPath + @"\Run", writable: true))
|
||||||
|
using (var approval = Registry.CurrentUser.CreateSubKey(keyPath + @"\Approved", writable: true))
|
||||||
{
|
{
|
||||||
run.SetValue("Titano Uploader", $"\"{Path.Combine(folder, "Uploader", "Titano.Uploader.exe")}\" --tray");
|
run.SetValue("Titano Uploader", $"\"{Path.Combine(folder, "Uploader", "Titano.Uploader.exe")}\" --tray");
|
||||||
// A portable Titano unpacked in a subfolder of the same folder: not a program this installation lists.
|
// A portable Titano unpacked in a subfolder of the same folder: not a program this installation lists.
|
||||||
@@ -166,10 +170,14 @@ public sealed class SetupEngineTests(TestContext context)
|
|||||||
// Another program in the same folder, and a copy in a sibling folder.
|
// Another program in the same folder, and a copy in a sibling folder.
|
||||||
run.SetValue("Other", $"\"{Path.Combine(folder, "Other.exe")}\" --background");
|
run.SetValue("Other", $"\"{Path.Combine(folder, "Other.exe")}\" --background");
|
||||||
run.SetValue("Sibling", $"\"{folder} 2\\Titano.Uploader.exe\"");
|
run.SetValue("Sibling", $"\"{folder} 2\\Titano.Uploader.exe\"");
|
||||||
|
// Both Titano entries were turned off in Task Manager.
|
||||||
|
approval.SetValue("Titano Uploader", TurnedOff, RegistryValueKind.Binary);
|
||||||
|
approval.SetValue("Titano", TurnedOff, RegistryValueKind.Binary);
|
||||||
|
|
||||||
var programs = CommandProgram.FullPaths(folder, ["Titano.exe", "Uploader/Titano.Uploader.exe", "Other.exe"]);
|
var programs = CommandProgram.FullPaths(folder, ["Titano.exe", "Uploader/Titano.Uploader.exe", "Other.exe"]);
|
||||||
Assert.SequenceEqual(["Titano Uploader"], SetupRegistry.DeleteStartupEntries(run, programs));
|
Assert.SequenceEqual(["Titano Uploader"], SetupRegistry.DeleteStartupEntries(run, approval, programs));
|
||||||
Assert.SequenceEqual(["Other", "Sibling", "Titano"], run.GetValueNames().Order(StringComparer.Ordinal));
|
Assert.SequenceEqual(["Other", "Sibling", "Titano"], run.GetValueNames().Order(StringComparer.Ordinal));
|
||||||
|
Assert.SequenceEqual(["Titano"], approval.GetValueNames());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -194,21 +202,25 @@ public sealed class SetupEngineTests(TestContext context)
|
|||||||
Assert.Equal(Path.Combine(folder, "Titano.exe"), programs["Titano"]);
|
Assert.Equal(Path.Combine(folder, "Titano.exe"), programs["Titano"]);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var run = Registry.CurrentUser.CreateSubKey(keyPath, writable: true))
|
using (var run = Registry.CurrentUser.CreateSubKey(keyPath + @"\Run", writable: true))
|
||||||
|
using (var approval = Registry.CurrentUser.CreateSubKey(keyPath + @"\Approved", writable: true))
|
||||||
{
|
{
|
||||||
run.SetValue("Titano", $"\"{Path.Combine(folder, "Titano.old.exe")}\" --minimized");
|
run.SetValue("Titano", $"\"{Path.Combine(folder, "Titano.old.exe")}\" --minimized");
|
||||||
run.SetValue("Titano Uploader", $"\"{Path.Combine(folder, "Titano.Uploader.exe")}\" --tray");
|
run.SetValue("Titano Uploader", $"\"{Path.Combine(folder, "Titano.Uploader.exe")}\" --tray");
|
||||||
run.SetValue("Other", $"\"{Path.Combine(folder, "Other.exe")}\" --background");
|
run.SetValue("Other", $"\"{Path.Combine(folder, "Other.exe")}\" --background");
|
||||||
|
approval.SetValue("Titano", TurnedOff, RegistryValueKind.Binary);
|
||||||
|
approval.SetValue("Titano Uploader", TurnedOff, RegistryValueKind.Binary);
|
||||||
|
|
||||||
var dropped = CommandProgram.FullPaths(folder, ["Titano.old.exe", "Titano.Uploader.exe", "Other.exe"]);
|
var dropped = CommandProgram.FullPaths(folder, ["Titano.old.exe", "Titano.Uploader.exe", "Other.exe"]);
|
||||||
Assert.SequenceEqual(["Titano", "Titano Uploader"], SetupRegistry.MoveStartupEntries(run, dropped, programs));
|
Assert.SequenceEqual(["Titano", "Titano Uploader"], SetupRegistry.MoveStartupEntries(run, approval, dropped, programs));
|
||||||
// The new client finds its entry on, with its option; the Uploader no longer starts; other values stay.
|
// The new client finds its entry with its option, still turned off; the Uploader no longer starts; other values stay.
|
||||||
Assert.Equal($"\"{Path.Combine(folder, "Titano.exe")}\" --minimized", run.GetValue("Titano"));
|
Assert.Equal($"\"{Path.Combine(folder, "Titano.exe")}\" --minimized", run.GetValue("Titano"));
|
||||||
Assert.SequenceEqual(["Other", "Titano"], run.GetValueNames().Order(StringComparer.Ordinal));
|
Assert.SequenceEqual(["Other", "Titano"], run.GetValueNames().Order(StringComparer.Ordinal));
|
||||||
|
Assert.SequenceEqual(["Titano"], approval.GetValueNames());
|
||||||
// An entry that starts another copy is not this upgrade's to move.
|
// An entry that starts another copy is not this upgrade's to move.
|
||||||
var other = $"\"{Path.Combine(folder + " 2", "Titano.old.exe")}\" --minimized";
|
var other = $"\"{Path.Combine(folder + " 2", "Titano.old.exe")}\" --minimized";
|
||||||
run.SetValue("Titano", other);
|
run.SetValue("Titano", other);
|
||||||
Assert.Empty(SetupRegistry.MoveStartupEntries(run, dropped, programs));
|
Assert.Empty(SetupRegistry.MoveStartupEntries(run, approval, dropped, programs));
|
||||||
Assert.Equal(other, run.GetValue("Titano"));
|
Assert.Equal(other, run.GetValue("Titano"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user