Skip to content

Commit

Permalink
Added path escaping for Auto Update #3568
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Jan 7, 2025
1 parent bdfef9f commit 4260f74
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/AutoUpdate/AutoUpdateControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace GHelper.AutoUpdate
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -105,6 +107,10 @@ async void CheckForUpdatesAsync()

}

public static string EscapeString(string input)
{
return Regex.Replace(input, @"\[|\]", "`$0");
}

async void AutoUpdate(string requestUri)
{
Expand All @@ -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
Expand Down

0 comments on commit 4260f74

Please sign in to comment.