From 7fa6de1bf2920311e81441f9e267f7d1264a91f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 12 Jun 2026 08:45:57 +0200 Subject: [PATCH] Use ShellExecuteExW for Windows update. Took 3 minutes Took 5 seconds Took 30 seconds Took 19 seconds --- .../interface/widgets/dialogs/dlg_update.cpp | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_update.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_update.cpp index f12550fa8..135ef7cd6 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_update.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_update.cpp @@ -13,6 +13,9 @@ #include #include #include +#if defined(Q_OS_WIN) +#include +#endif DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) { @@ -219,9 +222,29 @@ void DlgUpdate::downloadError(const QString &errorString) void DlgUpdate::downloadSuccessful(const QUrl &filepath) { setLabel(tr("Installing...")); - // Try to open the installer. If it opens, quit Cockatrice - if (QProcess::startDetached( - QString("\"%1\" /R /D=\"%2\"").arg(filepath.toLocalFile(), QCoreApplication::applicationDirPath()))) { + + const QString installer = filepath.toLocalFile(); + const QString args = QString("/R /D=\"%1\"").arg(QCoreApplication::applicationDirPath()); + + bool launched = false; + +#if defined(Q_OS_WIN) + SHELLEXECUTEINFOW sei = {}; + sei.cbSize = sizeof(sei); + sei.fMask = SEE_MASK_NOCLOSEPROCESS; + sei.lpVerb = L"runas"; + sei.lpFile = reinterpret_cast(installer.utf16()); + sei.lpParameters = reinterpret_cast(args.utf16()); + sei.nShow = SW_SHOWNORMAL; + launched = ShellExecuteExW(&sei); + if (launched && sei.hProcess) { + CloseHandle(sei.hProcess); + } +#else + launched = QProcess::startDetached(installer, {"/R", QString("/D=%1").arg(QCoreApplication::applicationDirPath())}); +#endif + + if (launched) { QMetaObject::invokeMethod(static_cast(parent()), "close", Qt::QueuedConnection); qCInfo(DlgUpdateLog) << "Opened downloaded update file successfully - closing Cockatrice"; close();