summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorskidau <skidau@gmail.com>2015-07-20 14:09:36 +1000
committerskidau <skidau@gmail.com>2015-07-20 14:09:36 +1000
commitad68de59bcfe8aa7c84d4d66db4abd25c4477090 (patch)
treeac7027325a3d3b73892b110a4f0725b54b319309 /Source/Core
parent654c44b87079897ef857f87713d39a292afc3f0a (diff)
parentc5b81b1aff9d9f34bac41da71ae02905fe4ee913 (diff)
Merge pull request #2665 from AdmiralCurtiss/relative-memory-card-paths
GameCube Config: Store paths relatively when selected file is within Dolphin's directory. (Windows)
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/FileUtil.cpp6
-rw-r--r--Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp28
2 files changed, 21 insertions, 13 deletions
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;
diff --git a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp
index 369d383dc7..f4426ef3a9 100644
--- a/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp
+++ b/Source/Core/DolphinWX/Config/GameCubeConfigPane.cpp
@@ -8,6 +8,7 @@
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/filedlg.h>
+#include <wx/filename.h>
#include <wx/gbsizer.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
@@ -331,23 +332,26 @@ void GameCubeConfigPane::ChooseSlotPath(bool is_slot_a, TEXIDevices device_type)
}
}
}
+
+ wxFileName newFilename(filename);
+ newFilename.MakeAbsolute();
+ filename = newFilename.GetFullPath();
+
#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.
+ // TODO: Replace this with a cleaner, non-wx solution once std::filesystem is standard
+ std::string exeDir = File::GetExeDirectory() + '\\';
+ 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...
- if (filename.compare(is_slot_a ? pathB : pathA) != 0)
+ wxFileName otherFilename(is_slot_a ? pathB : pathA);
+ otherFilename.MakeAbsolute();
+ if (newFilename.GetFullPath().compare(otherFilename.GetFullPath()) != 0)
{
if (memcard)
{