diff --git a/app/AutoUpdate/AutoUpdateControl.cs b/app/AutoUpdate/AutoUpdateControl.cs index 38dc7aac..5b6714cb 100644 --- a/app/AutoUpdate/AutoUpdateControl.cs +++ b/app/AutoUpdate/AutoUpdateControl.cs @@ -3,6 +3,7 @@ using System.Net; using System.Reflection; using System.Text.Json; +using System.Text.RegularExpressions; namespace GHelper.AutoUpdate { @@ -39,7 +40,8 @@ public void LoadReleases() try { Process.Start(new ProcessStartInfo(versionUrl) { UseShellExecute = true }); - } catch (Exception ex) + } + catch (Exception ex) { Logger.WriteLine("Failed to open releases page:" + ex.Message); } @@ -105,6 +107,10 @@ async void CheckForUpdatesAsync() } + public static string EscapeString(string input) + { + return Regex.Replace(input, @"\[|\]", "`$0"); + } async void AutoUpdate(string requestUri) { @@ -126,7 +132,7 @@ async void AutoUpdate(string requestUri) Logger.WriteLine(zipName); Logger.WriteLine(exeName); - string command = $"$ErrorActionPreference = \"Stop\"; Wait-Process -Name \"GHelper\"; Expand-Archive \"{zipName}\" -DestinationPath . -Force; Remove-Item \"{zipName}\" -Force; \".\\{exeName}\"; "; + string command = $"$ErrorActionPreference = \"Stop\"; Set-Location -Path '{EscapeString(exeDir)}'; Wait-Process -Name \"GHelper\"; Expand-Archive \"{zipName}\" -DestinationPath . -Force; Remove-Item \"{zipName}\" -Force; \".\\{exeName}\"; "; Logger.WriteLine(command); try