From 319b84c9493c9790ccbaa928fdf130b478e5796c Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 25 Mar 2023 21:51:38 +0100 Subject: [PATCH] Fix updating with directories with whitespaces --- src/Artemis.UI.Windows/ApplicationStateManager.cs | 8 ++++---- src/Artemis.UI.Windows/Scripts/update.ps1 | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Artemis.UI.Windows/ApplicationStateManager.cs b/src/Artemis.UI.Windows/ApplicationStateManager.cs index e3d9ddba1..c3b2eb3a6 100644 --- a/src/Artemis.UI.Windows/ApplicationStateManager.cs +++ b/src/Artemis.UI.Windows/ApplicationStateManager.cs @@ -100,9 +100,9 @@ public class ApplicationStateManager // Retain startup arguments after update by providing them to the script string script = Path.Combine(Constants.UpdatingFolder, "installing", "scripts", "update.ps1"); - string source = $"-sourceDirectory \"{Path.Combine(Constants.UpdatingFolder, "installing")}\""; - string destination = $"-destinationDirectory \"{Constants.ApplicationFolder}\""; - string args = argsList.Any() ? $"-artemisArgs \"{string.Join(',', argsList)}\"" : ""; + string source = $"-sourceDirectory \"'{Path.Combine(Constants.UpdatingFolder, "installing")}'\""; + string destination = $"-destinationDirectory \"'{Constants.ApplicationFolder}'\""; + string args = argsList.Any() ? $"-artemisArgs \"'{string.Join(',', argsList)}'\"" : ""; RunScriptWithOutputFile(script, $"{source} {destination} {args}", Path.Combine(Constants.DataFolder, "update-log.txt")); @@ -142,7 +142,7 @@ public class ApplicationStateManager string redirectSymbol = File.Exists(outputFile) && new FileInfo(outputFile).Length > 200000 ? ">" : ">>"; ProcessStartInfo info = new() { - Arguments = $"PowerShell -ExecutionPolicy Bypass -File \"{script}\" {arguments} {redirectSymbol} \"{outputFile}\"", + Arguments = $"-ExecutionPolicy Bypass -File \"{script}\" {arguments} {redirectSymbol} \"{outputFile}\"", FileName = "PowerShell.exe", WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, diff --git a/src/Artemis.UI.Windows/Scripts/update.ps1 b/src/Artemis.UI.Windows/Scripts/update.ps1 index 6d3fa3aca..607032109 100644 --- a/src/Artemis.UI.Windows/Scripts/update.ps1 +++ b/src/Artemis.UI.Windows/Scripts/update.ps1 @@ -26,21 +26,21 @@ if ($process) } # Check if the destination directory exists -if (!(Test-Path "$destinationDirectory")) +if (!(Test-Path $destinationDirectory)) { - Write-Error "The destination directory does not exist" + Write-Error "The destination directory at $destinationDirectory does not exist" Exit 1 } # Clear the destination directory but don't remove it, leaving ACL entries in tact Write-Host "Cleaning up old version where needed" -Get-ChildItem "$destinationDirectory" | Remove-Item -Recurse -Force +Get-ChildItem $destinationDirectory | Remove-Item -Recurse -Force # Move the contents of the source directory to the destination directory Write-Host "Installing new files" -Get-ChildItem "$sourceDirectory" | Move-Item -Destination "$destinationDirectory" +Get-ChildItem $sourceDirectory | Move-Item -Destination $destinationDirectory # Remove the now empty source directory -Remove-Item "$sourceDirectory" +Remove-Item $sourceDirectory Write-Host "Finished! Restarting Artemis" Start-Sleep -Seconds 1 @@ -48,9 +48,9 @@ Start-Sleep -Seconds 1 # When finished, run the updated version if ($artemisArgs) { - Start-Process -FilePath "$destinationDirectory\Artemis.UI.Windows.exe" -WorkingDirectory "$destinationDirectory" -ArgumentList $artemisArgs + Start-Process -FilePath "$destinationDirectory\Artemis.UI.Windows.exe" -WorkingDirectory $destinationDirectory -ArgumentList $artemisArgs } else { - Start-Process -FilePath "$destinationDirectory\Artemis.UI.Windows.exe" -WorkingDirectory "$destinationDirectory" + Start-Process -FilePath "$destinationDirectory\Artemis.UI.Windows.exe" -WorkingDirectory $destinationDirectory } \ No newline at end of file