fix(installer): skip rewriting the autostart shortcut when already current
RegisterAutostartStep rewrote the Startup .lnk on every install/update/repair even when it already pointed at the right worker exe. AutostartShortcut.Install now reads the existing shortcut's target via ShortcutFactory.TryGetTarget and skips the rewrite when it matches, reporting the skip in progress output. Legacy service/scheduled-task cleanup stays unconditional (migration safety net).
This commit is contained in:
@@ -16,6 +16,11 @@ public sealed class RegisterAutostartStep : IInstallStep
|
||||
if (!File.Exists(workerExe))
|
||||
return StepResult.Fail($"Worker executable not found: {workerExe}");
|
||||
|
||||
// Legacy service/task cleanup below runs unconditionally on every install/update/repair,
|
||||
// even though it's a no-op once migrated. A cached "already migrated" flag could go stale
|
||||
// (e.g. a user re-adds the legacy service) and strand them with it still running; two
|
||||
// extra process starts per run is the price for that migration safety net.
|
||||
|
||||
// 1) Migrate away the legacy Windows service if present.
|
||||
progress.Report("Checking for legacy worker service...");
|
||||
var (queryExit, _) = await ProcessRunner.RunAsync("sc.exe", $"query {LegacyServiceName}", null, progress, ct);
|
||||
@@ -38,10 +43,11 @@ public sealed class RegisterAutostartStep : IInstallStep
|
||||
await ProcessRunner.RunAsync("schtasks.exe", $"/Delete /TN \"{LegacyTaskName}\" /F", null, progress, ct);
|
||||
|
||||
// 3) Register per-user autostart via a Startup-folder shortcut.
|
||||
progress.Report("Creating Startup shortcut...");
|
||||
progress.Report("Checking Startup shortcut...");
|
||||
try
|
||||
{
|
||||
AutostartShortcut.Install(AutostartShortcut.DefaultStartupDir, workerExe);
|
||||
var created = AutostartShortcut.Install(AutostartShortcut.DefaultStartupDir, workerExe);
|
||||
progress.Report(created ? "Startup shortcut created." : "Startup shortcut already up to date.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user