From 5960e7dda61aba42678f0cd0eb83ed9513d6bd31 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sun, 20 Mar 2022 11:08:27 +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 ad9c9ba37..e7009a59d 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -159,15 +160,22 @@ void Utils::Gui::openFolderSelect(const Path &path) } #ifdef Q_OS_WIN - HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); - PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast(path.toString().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(path.toString().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(u"xdg-mime"_qs, {u"query"_qs, u"default"_qs, u"inode/directory"_qs});