From e5894831ec62f40f0f1d78daf40f60c4a20e19c5 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sun, 20 Mar 2022 21:54:34 +0300 Subject: [PATCH] Prevent crash when open torrent destination folder Uses the same workaround as Qt does to call ShellExecute() when you use QDesktopServices::openUrl(). PR #16670. Closes #16423. --- src/gui/utils.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index c29c165ee..9894d1cc4 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -167,15 +168,22 @@ void Utils::Gui::openFolderSelect(const QString &absolutePath) } #ifdef Q_OS_WIN - HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); - PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast(Utils::Fs::toNativePath(path).utf16())); - if (pidl) + auto *thread = QThread::create([path]() { - ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); - ::ILFree(pidl); - } - if ((hresult == S_OK) || (hresult == S_FALSE)) - ::CoUninitialize(); + if (SUCCEEDED(::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) + { + PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast(Utils::Fs::toNativePath(path).utf16())); + if (pidl) + { + ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); + ::ILFree(pidl); + } + + ::CoUninitialize(); + } + }); + QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater); + thread->start(); #elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) QProcess proc; proc.start("xdg-mime", {"query", "default", "inode/directory"});