diff --git a/src/DiffEngineTray/Startup.cs b/src/DiffEngineTray/Startup.cs index a752467a..3d84a1cd 100644 --- a/src/DiffEngineTray/Startup.cs +++ b/src/DiffEngineTray/Startup.cs @@ -2,12 +2,32 @@ public class Startup { + /// + /// Registers this executable, wherever it actually is. + /// + /// The path used to be guessed as %USERPROFILE%\.dotnet\tools\DiffEngineTray.exe, which + /// is only right for a default global install. A --tool-path install, a + /// DOTNET_CLI_HOME that moves the tools directory, or simply running a local build all + /// registered a path with nothing at it - so the tray never started at login, while the + /// Options checkbox, which reads the settings file rather than the registry, went on reporting + /// that it would. + /// + /// + /// Quoted, because a Run value is a command line: an unquoted path containing a space is read + /// as a program name followed by arguments. + /// + /// public static void Add() { - var profile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - var exePath = Path.Combine(profile, ".dotnet", "tools", "DiffEngineTray.exe"); + var exePath = Environment.ProcessPath; + if (exePath == null) + { + // No host path to register, which a normal launch does not produce + return; + } + using var key = GetRunKey(); - key.SetValue("DiffEngineTray", exePath); + key.SetValue("DiffEngineTray", $"\"{exePath}\""); } public static void Remove() @@ -25,4 +45,4 @@ public static bool Exists() static RegistryKey GetRunKey() => Registry.CurrentUser .OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true)!; -} \ No newline at end of file +}