Skip to content

Commit

Permalink
Windows: Fix "Show in Explorer" with long paths even if 8.3 names are…
Browse files Browse the repository at this point in the history
… disabled.
  • Loading branch information
jdpurcell committed Oct 13, 2023
1 parent 170bba5 commit fccc653
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,15 +913,16 @@ void MainWindow::openContainingFolder()

const QFileInfo selectedFileInfo = getCurrentFileDetails().fileInfo;

#ifdef Q_OS_WIN
#ifdef WIN32_LOADED
QString pathToSelect = QDir::toNativeSeparators(selectedFileInfo.absoluteFilePath());
if (pathToSelect.length() > 259)
if (pathToSelect.length() > 259 && pathToSelect.startsWith(R"(\\)"))
{
// The Shell API seems to handle long paths, unless they are UNC :(
pathToSelect = QVWin32Functions::getShortPath(pathToSelect);
if (pathToSelect.isEmpty())
return;
}
QProcess::startDetached("explorer", QStringList() << "/select," << pathToSelect);
QVWin32Functions::showInExplorer(pathToSelect);
#elif defined Q_OS_MACOS
QProcess::execute("open", QStringList() << "-R" << selectedFileInfo.absoluteFilePath());
#else
Expand Down
12 changes: 12 additions & 0 deletions src/qvwin32functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ QString QVWin32Functions::getShortPath(const QString &path)
return getLongOrShortPath(path, GetShortPathNameW);
}

bool QVWin32Functions::showInExplorer(const QString &path)
{
bool result = false;
LPITEMIDLIST pIdl;
if (SUCCEEDED(SHParseDisplayName(reinterpret_cast<const wchar_t*>(path.utf16()), nullptr, &pIdl, 0, nullptr)))
{
result = SUCCEEDED(SHOpenFolderAndSelectItems(pIdl, 0, nullptr, 0));
ILFree(pIdl);
}
return result;
}

QByteArray QVWin32Functions::getIccProfileForWindow(const QWindow *window)
{
QByteArray result;
Expand Down
2 changes: 2 additions & 0 deletions src/qvwin32functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class QVWin32Functions

static QString getShortPath(const QString &path);

static bool showInExplorer(const QString &path);

static QByteArray getIccProfileForWindow(const QWindow *window);
};

Expand Down

0 comments on commit fccc653

Please sign in to comment.