mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-22 12:34:19 +00:00
Avoid spawning a new explorer.exe process when selecting "Open containing
folder". Closes #5564.
This commit is contained in:
parent
bb956b8453
commit
9cb01dedba
@ -52,6 +52,7 @@
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <powrprof.h>
|
#include <powrprof.h>
|
||||||
|
#include <Shlobj.h>
|
||||||
const int UNLEN = 256;
|
const int UNLEN = 256;
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -578,35 +579,14 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
|
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||||
// Dir separators MUST be win-style slashes
|
ITEMIDLIST *pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
|
||||||
|
if (pidl) {
|
||||||
// QProcess::startDetached() has an obscure bug. If the path has
|
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
|
||||||
// no spaces and a comma(and maybe other special characters) it doesn't
|
::ILFree(pidl);
|
||||||
// get wrapped in quotes. So explorer.exe can't find the correct path and
|
|
||||||
// displays the default one. If we wrap the path in quotes and pass it to
|
|
||||||
// QProcess::startDetached() explorer.exe still shows the default path. In
|
|
||||||
// this case QProcess::startDetached() probably puts its own quotes around ours.
|
|
||||||
|
|
||||||
STARTUPINFO startupInfo;
|
|
||||||
::ZeroMemory(&startupInfo, sizeof(startupInfo));
|
|
||||||
startupInfo.cb = sizeof(startupInfo);
|
|
||||||
|
|
||||||
PROCESS_INFORMATION processInfo;
|
|
||||||
::ZeroMemory(&processInfo, sizeof(processInfo));
|
|
||||||
|
|
||||||
QString cmd = QString("explorer.exe /select,\"%1\"").arg(Utils::Fs::toNativePath(absolutePath));
|
|
||||||
LPWSTR lpCmd = new WCHAR[cmd.size() + 1];
|
|
||||||
cmd.toWCharArray(lpCmd);
|
|
||||||
lpCmd[cmd.size()] = 0;
|
|
||||||
|
|
||||||
bool ret = ::CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo);
|
|
||||||
delete [] lpCmd;
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
::CloseHandle(processInfo.hProcess);
|
|
||||||
::CloseHandle(processInfo.hThread);
|
|
||||||
}
|
}
|
||||||
|
if ((hresult == S_OK) || (hresult == S_FALSE))
|
||||||
|
::CoUninitialize();
|
||||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
||||||
|
@ -37,8 +37,8 @@ DEFINES += _UNICODE
|
|||||||
DEFINES += WIN32
|
DEFINES += WIN32
|
||||||
DEFINES += _WIN32
|
DEFINES += _WIN32
|
||||||
DEFINES += WIN32_LEAN_AND_MEAN
|
DEFINES += WIN32_LEAN_AND_MEAN
|
||||||
DEFINES += _WIN32_WINNT=0x0500
|
DEFINES += _WIN32_WINNT=0x0501
|
||||||
DEFINES += _WIN32_IE=0x0500
|
DEFINES += _WIN32_IE=0x0501
|
||||||
DEFINES += _CRT_SECURE_NO_DEPRECATE
|
DEFINES += _CRT_SECURE_NO_DEPRECATE
|
||||||
DEFINES += _SCL_SECURE_NO_DEPRECATE
|
DEFINES += _SCL_SECURE_NO_DEPRECATE
|
||||||
DEFINES += __USE_W32_SOCKETS
|
DEFINES += __USE_W32_SOCKETS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user