From 9d480fc2b93911e317d62f10f57d9e76e5084465 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 13 Jun 2025 17:53:57 +0800 Subject: [PATCH] Quote the executable path to survive spaces & Improve code quality --- Flow.Launcher/App.xaml.cs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 23dbb1b40..e9ccbca22 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -349,29 +349,26 @@ namespace Flow.Launcher /// public static void RestartApp(bool forceAdmin = false) { - if (Win32Helper.IsAdministrator() || forceAdmin) - { - RestartAppAsAdministrator(); - } - else - { - // Restart requires Squirrel's Update.exe to be present in the parent folder, - // it is only published from the project's release pipeline. When debugging without it, - // the project may not restart or just terminates. This is expected. - UpdateManager.RestartApp(Constant.ApplicationFileName); - } + // Restart requires Squirrel's Update.exe to be present in the parent folder, + // it is only published from the project's release pipeline. When debugging without it, + // the project may not restart or just terminates. This is expected. + RestartAppAsAdministrator(Win32Helper.IsAdministrator() || forceAdmin); } - // Since Squirrel does not provide a way to restart the app as administrator, - // we need to do it manually by starting the update.exe with the runas verb - private static void RestartAppAsAdministrator() + /// + /// Since Squirrel does not provide a way to restart the app as administrator, + /// we need to do it manually by starting the update.exe with the runas verb + /// + /// Whether to run the application as administrator or not + /// Thrown when the Update.exe is not found in the expected location + private static void RestartAppAsAdministrator(bool runAsAdmin) { var startInfo = new ProcessStartInfo { FileName = getUpdateExe(), - Arguments = $"--processStartAndWait {Constant.ExecutablePath}", + Arguments = $"--processStartAndWait \"{Constant.ExecutablePath}\"", UseShellExecute = true, - Verb = "runas", + Verb = runAsAdmin ? "runas" : "" }; Process.Start(startInfo); Thread.Sleep(500);