From 953fb1463850f071e5df2a25532c8e41eb198013 Mon Sep 17 00:00:00 2001 From: Alessandro Ampala <48158436+alessandroampala@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:59:26 +0100 Subject: [PATCH] Fix update on windows when path contains powershell wildcards (#1391) (#1779) * Fix update process on windows when there are some powershell wildcards in the installation path. (#1391) * Fix coding style error. (#1391) --- src/qt_gui/check_update.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/qt_gui/check_update.cpp b/src/qt_gui/check_update.cpp index a9aba0b84..d713f67fb 100644 --- a/src/qt_gui/check_update.cpp +++ b/src/qt_gui/check_update.cpp @@ -347,7 +347,11 @@ void CheckUpdate::DownloadUpdate(const QString& url) { QString userPath; Common::FS::PathToQString(userPath, Common::FS::GetUserPath(Common::FS::PathType::UserDir)); +#ifdef Q_OS_WIN + QString tempDownloadPath = QString(getenv("LOCALAPPDATA")) + "/Temp/temp_download_update"; +#else QString tempDownloadPath = userPath + "/temp_download_update"; +#endif QDir dir(tempDownloadPath); if (!dir.exists()) { dir.mkpath("."); @@ -393,6 +397,11 @@ void CheckUpdate::Install() { QString processCommand; #ifdef Q_OS_WIN + // On windows, overwrite tempDirPath with AppData/Local/Temp folder + // due to PowerShell Expand-Archive not being able to handle correctly + // paths in square brackets (ie: ./[shadps4]) + tempDirPath = QString(getenv("LOCALAPPDATA")) + "/Temp/temp_download_update"; + // Windows Batch Script scriptFileName = tempDirPath + "/update.ps1"; scriptContent = QStringLiteral( @@ -408,10 +417,11 @@ void CheckUpdate::Install() { "Start-Sleep -Seconds 3\n" "Copy-Item -Recurse -Force '%2\\*' '%3\\'\n" "Start-Sleep -Seconds 2\n" - "Remove-Item -Force '%3\\update.ps1'\n" - "Remove-Item -Force '%3\\temp_download_update.zip'\n" - "Start-Process '%3\\shadps4.exe'\n" - "Remove-Item -Recurse -Force '%2'\n"); + "Remove-Item -Force -LiteralPath '%3\\update.ps1'\n" + "Remove-Item -Force -LiteralPath '%3\\temp_download_update.zip'\n" + "Remove-Item -Recurse -Force '%2'\n" + "Start-Process -FilePath '%3\\shadps4.exe' " + "-WorkingDirectory ([WildcardPattern]::Escape('%3'))\n"); arguments << "-ExecutionPolicy" << "Bypass" << "-File" << scriptFileName;