From 48273b401e446ab793294e3353145f90d6e0998e Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Wed, 10 Mar 2021 16:01:19 -0800 Subject: [PATCH] Gamelist: Fix 'Open Containing Folder' Fix Gamelist context menu item 'Open Containing Folder' opening wrong target on Windows when game parent folder is [foobar] and grandparent folder contains file [foobar].bat or [foobar].exe Add trailing directory separator to parent folder path to force Windows to interpret path as directory. Fixes https://bugs.dolphin-emu.org/issues/12411 --- Source/Core/DolphinQt/GameList/GameList.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index ae8b3d5449..5de3736801 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -38,6 +38,7 @@ #include #include +#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); }