forked from qt-creator/qt-creator
Core: Use Windows API to create path to explorer.exe
Searching after "explorer.exe" in PATH can fail, as seen in a report on #qtcreator channel on Discord. Explorer.exe is always part of %systemroot%, which can be programatically obtained via SHGetFolderPath function. Fixes: QTCREATORBUG-30765 Change-Id: Id2c4f3bd9c51234cb9e16d936202dfbcb1975606 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -32,10 +32,28 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#ifdef QTCREATOR_PCH_H
|
||||||
|
#define CALLBACK WINAPI
|
||||||
|
#endif
|
||||||
|
#include <qt_windows.h>
|
||||||
|
#include <shlobj.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
static FilePath windowsDirectory()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
wchar_t str[UNICODE_STRING_MAX_CHARS] = {};
|
||||||
|
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_WINDOWS, nullptr, 0, str)))
|
||||||
|
return FilePath::fromUserInput(QString::fromUtf16(reinterpret_cast<char16_t *>(str)));
|
||||||
|
#endif
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
// Show error with option to open settings.
|
// Show error with option to open settings.
|
||||||
static void showGraphicalShellError(QWidget *parent, const QString &app, const QString &error)
|
static void showGraphicalShellError(QWidget *parent, const QString &app, const QString &error)
|
||||||
{
|
{
|
||||||
@@ -56,13 +74,7 @@ void FileUtils::showInGraphicalShell(QWidget *parent, const FilePath &pathIn)
|
|||||||
const QFileInfo fileInfo = pathIn.toFileInfo();
|
const QFileInfo fileInfo = pathIn.toFileInfo();
|
||||||
// Mac, Windows support folder or file.
|
// Mac, Windows support folder or file.
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
const FilePath explorer = FilePath("explorer.exe").searchInPath();
|
const FilePath explorer = windowsDirectory().pathAppended("explorer.exe");
|
||||||
if (explorer.isEmpty()) {
|
|
||||||
QMessageBox::warning(parent,
|
|
||||||
Tr::tr("Launching Windows Explorer Failed"),
|
|
||||||
Tr::tr("Could not find explorer.exe in path to launch Windows Explorer."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QStringList param;
|
QStringList param;
|
||||||
if (!pathIn.isDir())
|
if (!pathIn.isDir())
|
||||||
param += QLatin1String("/select,");
|
param += QLatin1String("/select,");
|
||||||
|
Reference in New Issue
Block a user