Skip to content

Commit 08f0b92

Browse files
committed
Windows updater: wait for installer and relaunch
Make the Windows deferred update launcher wait for the installer to finish and relaunch the correct PakFu binary. Pass the current app path into the generated batch script, add APP/APP_TO_START handling, use /wait when launching MSI or installer artifacts, and prefer the installer-managed %LOCALAPPDATA%\PakFu\pakfu.exe if present. Also fix the startDetached invocation to execute the composed command string.
1 parent b03af1a commit 08f0b92

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ Selector support:
231231
## Updates and Releases
232232
PakFu can check GitHub Releases at runtime and from CLI.
233233

234+
GUI updater install handoff:
235+
- Windows: `Install and Restart` waits for installer completion, then relaunches PakFu (preferring the installer-managed `%LOCALAPPDATA%\PakFu\pakfu.exe` after MSI updates).
236+
- macOS/Linux: PakFu exits and starts the downloaded installer artifact (`.pkg` / `.AppImage`) after shutdown.
237+
234238
Build-time updater config:
235239
- `-Dgithub_repo=themuffinator/PakFu` (default; see `meson_options.txt`)
236240
- `-Dupdate_channel=stable|beta|dev` (default: `stable`; full releases only; see `meson_options.txt`)

src/update/update_service.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace {
132132
}
133133

134134
const QString installer_absolute_path = installer_info.absoluteFilePath();
135+
const QString app_absolute_path = QFileInfo(QCoreApplication::applicationFilePath()).absoluteFilePath();
135136

136137
const QString temp_dir = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
137138
if (temp_dir.isEmpty()) {
@@ -164,6 +165,8 @@ namespace {
164165
"setlocal EnableExtensions\r\n"
165166
"set \"PID=%~1\"\r\n"
166167
"set \"INSTALLER=%~f2\"\r\n"
168+
"set \"APP=%~f3\"\r\n"
169+
"set \"APP_TO_START=%APP%\"\r\n"
167170
"set \"EXT=%~x2\"\r\n"
168171
":waitloop\r\n"
169172
"tasklist /FI \"PID eq %PID%\" 2>NUL | findstr /I \"%PID%\" >NUL\r\n"
@@ -172,9 +175,13 @@ namespace {
172175
" goto waitloop\r\n"
173176
")\r\n"
174177
"if /I \"%EXT%\"==\".msi\" (\r\n"
175-
" start \"\" msiexec.exe /i \"%INSTALLER%\"\r\n"
178+
" start \"\" /wait msiexec.exe /i \"%INSTALLER%\"\r\n"
179+
" if exist \"%LOCALAPPDATA%\\PakFu\\pakfu.exe\" set \"APP_TO_START=%LOCALAPPDATA%\\PakFu\\pakfu.exe\"\r\n"
176180
") else (\r\n"
177-
" start \"\" \"%INSTALLER%\"\r\n"
181+
" start \"\" /wait \"%INSTALLER%\"\r\n"
182+
")\r\n"
183+
"if exist \"%APP_TO_START%\" (\r\n"
184+
" start \"\" \"%APP_TO_START%\"\r\n"
178185
")\r\n"
179186
"start \"\" /B cmd.exe /C del /F /Q \"%~f0\" >NUL 2>&1\r\n"
180187
"endlocal\r\n";
@@ -183,8 +190,11 @@ namespace {
183190

184191
const QString script_path = QDir::toNativeSeparators(script.fileName());
185192
const QString installer_arg = QDir::toNativeSeparators(installer_absolute_path);
193+
const QString app_arg = QDir::toNativeSeparators(app_absolute_path);
194+
const QString cmd = QString("\"\"%1\" %2 \"%3\" \"%4\"\"")
195+
.arg(script_path, QString::number(pid), installer_arg, app_arg);
186196

187-
if (!QProcess::startDetached("cmd.exe", {"/C", script_path, QString::number(pid), installer_arg})) {
197+
if (!QProcess::startDetached("cmd.exe", {"/C", cmd})) {
188198
if (error) {
189199
*error = "Unable to start deferred update launcher.";
190200
}

0 commit comments

Comments
 (0)