Merge pull request #9579 from Dentomologist/fix_open_containing_folder

Gamelist: Fix 'Open Containing Folder'
This commit is contained in:
Léo Lam 2021-03-16 09:52:46 +01:00 committed by GitHub
commit 5cea85f008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -38,6 +38,7 @@
#include <QTableView>
#include <QUrl>
#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Core/Config/MainSettings.h"
@ -576,8 +577,18 @@ void GameList::OpenContainingFolder()
if (!game)
return;
QUrl url = QUrl::fromLocalFile(
QFileInfo(QString::fromStdString(game->GetFilePath())).dir().absolutePath());
// Remove everything after the last separator in the game's path, resulting in the parent
// directory path with a trailing separator. Keeping the trailing separator prevents Windows from
// mistakenly opening a .bat or .exe file in the grandparent folder when that file has the same
// base name as the folder (See https://bugs.dolphin-emu.org/issues/12411).
std::string parent_directory_path;
SplitPath(game->GetFilePath(), &parent_directory_path, nullptr, nullptr);
if (parent_directory_path.empty())
{
return;
}
const QUrl url = QUrl::fromLocalFile(QString::fromStdString(parent_directory_path));
QDesktopServices::openUrl(url);
}