From df70f50fdfcc69726f7d8fd186054dbe3e68c57e Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 26 Jun 2015 23:43:45 +0200 Subject: [PATCH 1/3] GetExeDirectory() shouldn't return paths with /../ in the middle. --- Source/Core/Common/FileUtil.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 4709c011b2..0b4a99bbd7 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -731,8 +731,12 @@ std::string& GetExeDirectory() if (DolphinPath.empty()) { TCHAR Dolphin_exe_Path[2048]; + TCHAR Dolphin_exe_Clean_Path[MAX_PATH]; GetModuleFileName(nullptr, Dolphin_exe_Path, 2048); - DolphinPath = TStrToUTF8(Dolphin_exe_Path); + if (_tfullpath(Dolphin_exe_Clean_Path, Dolphin_exe_Path, MAX_PATH) != nullptr) + DolphinPath = TStrToUTF8(Dolphin_exe_Clean_Path); + else + DolphinPath = TStrToUTF8(Dolphin_exe_Path); DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\')); } return DolphinPath; From 583e3fd9e01fba73db77adf32a3818c57075b81a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Fri, 26 Jun 2015 23:42:23 +0200 Subject: [PATCH 2/3] GameCubeConfig: If the user selects a memcard file path within Dolphin's directory, store the path relative to it. This makes Dolphin more portable in portable mode, since the memory card file is still found if the directory is moved somewhere else. This also means that we have to explicitly compare absolute paths if we want to check for both slots containing the same file. --- .../DolphinWX/Config/GameCubeConfigPane.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp index 369d383dc7..807015427c 100644 --- a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -332,22 +333,21 @@ void GameCubeConfigPane::ChooseSlotPath(bool is_slot_a, TEXIDevices device_type) } } #ifdef _WIN32 - if (!strncmp(File::GetExeDirectory().c_str(), filename.c_str(), File::GetExeDirectory().size())) - { - // If the Exe Directory Matches the prefix of the filename, we still need to verify - // that the next character is a directory separator character, otherwise we may create an invalid path - char next_char = filename.at(File::GetExeDirectory().size()) + 1; - if (next_char == '/' || next_char == '\\') - { - filename.erase(0, File::GetExeDirectory().size() + 1); - filename = "./" + filename; - } - } + // If the Memory Card file is within the Exe dir, we can assume that the user wants it to be stored relative + // to the executable, so it stays set correctly when the probably portable Exe dir is moved. + std::string exeDir = File::GetExeDirectory() + '\\'; + if (!strncmp(exeDir.c_str(), filename.c_str(), exeDir.size())) + filename.erase(0, exeDir.size()); + std::replace(filename.begin(), filename.end(), '\\', '/'); #endif // also check that the path isn't used for the other memcard... - if (filename.compare(is_slot_a ? pathB : pathA) != 0) + wxFileName newFilename(filename); + wxFileName otherFilename(is_slot_a ? pathB : pathA); + newFilename.MakeAbsolute(); + otherFilename.MakeAbsolute(); + if (newFilename.GetFullPath().compare(otherFilename.GetFullPath()) != 0) { if (memcard) { From c5b81b1aff9d9f34bac41da71ae02905fe4ee913 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 27 Jun 2015 18:34:54 +0200 Subject: [PATCH 3/3] GameCubeConfig: Case insensitive compare & absolute path compare for the part-of-exe-dir check. --- Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp index 807015427c..f4426ef3a9 100644 --- a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp @@ -332,20 +332,24 @@ void GameCubeConfigPane::ChooseSlotPath(bool is_slot_a, TEXIDevices device_type) } } } + + wxFileName newFilename(filename); + newFilename.MakeAbsolute(); + filename = newFilename.GetFullPath(); + #ifdef _WIN32 // If the Memory Card file is within the Exe dir, we can assume that the user wants it to be stored relative // to the executable, so it stays set correctly when the probably portable Exe dir is moved. + // TODO: Replace this with a cleaner, non-wx solution once std::filesystem is standard std::string exeDir = File::GetExeDirectory() + '\\'; - if (!strncmp(exeDir.c_str(), filename.c_str(), exeDir.size())) + if (wxString(filename).Lower().StartsWith(wxString(exeDir).Lower())) filename.erase(0, exeDir.size()); std::replace(filename.begin(), filename.end(), '\\', '/'); #endif // also check that the path isn't used for the other memcard... - wxFileName newFilename(filename); wxFileName otherFilename(is_slot_a ? pathB : pathA); - newFilename.MakeAbsolute(); otherFilename.MakeAbsolute(); if (newFilename.GetFullPath().compare(otherFilename.GetFullPath()) != 0) {