From 4f75263385240e771d7f35cb5382efff7771ea1f Mon Sep 17 00:00:00 2001 From: fluentcoding Date: Fri, 9 Oct 2020 15:38:06 +0200 Subject: [PATCH 1/3] Slippi combo configs are now processing paths relative to the config itself. --- Source/Core/Common/FileUtil.cpp | 49 ++++++++++++++++++++ Source/Core/Common/FileUtil.h | 6 +++ Source/Core/Core/Slippi/SlippiReplayComm.cpp | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 4f097d1342..1e22a78549 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -42,6 +42,7 @@ #include #include #endif +#include #ifndef S_ISDIR #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) @@ -723,6 +724,54 @@ std::string GetBundleDirectory() } #endif +std::string GetAbsolutePathFromRelativePath(const std::string &path, const std::string &origin) { + std::string tempPath = path; + std::string tempOrigin = origin; +#ifdef _WIN32 + LPCWSTR winPath = s2ws(tempPath).c_str(); + if (!PathIsRelativeW(winPath)) + { + return tempPath; + } + std::replace(tempOrigin.begin(), tempOrigin.end(), '/', '\\'); + std::replace(tempPath.begin(), tempPath.end(), '/', '\\'); + if (tempOrigin.back() != '\\' && tempPath.front() != '\\') + { + tempOrigin.push_back('\\'); + } + else if (tempOrigin.back() == '\\' && tempPath.front() == '\\') + { + tempOrigin.pop_back(); + } +#else + if (tempPath.at(0) == '/') + { + return tempPath; + } + if (tempPath.back() != '/' && tempOrigin.front() != '/') + { + tempPath.push_back('/'); + } + else if (tempPath.back() == '/' && tempOrigin.front() == '/') + { + tempPath.erase(tempPath.size() - 1); + } +#endif + return tempOrigin + tempPath; +} + +std::wstring s2ws(const std::string &s) +{ + int len; + int slength = (int)s.length() + 1; + len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); + wchar_t *buf = new wchar_t[len]; + MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len); + std::wstring r(buf); + delete[] buf; + return r; +} + std::string &GetExeDirectory() { static std::string DolphinPath; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index ba6e97bb57..03cd333135 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -139,6 +139,12 @@ std::string CreateTempDir(); // Get a filename that can hopefully be atomically renamed to the given path. std::string GetTempFilenameForAtomicWrite(const std::string& path); +// Converts a relative path to an absolute path if it is a relative one +std::string GetAbsolutePathFromRelativePath(const std::string &path, const std::string &origin); + +// Converts String to WString +std::wstring s2ws(const std::string &s); + // Gets a set user directory path // Don't call prior to setting the base user directory const std::string& GetUserPath(unsigned int dir_index); diff --git a/Source/Core/Core/Slippi/SlippiReplayComm.cpp b/Source/Core/Core/Slippi/SlippiReplayComm.cpp index 51550d81f7..59c22b4f91 100644 --- a/Source/Core/Core/Slippi/SlippiReplayComm.cpp +++ b/Source/Core/Core/Slippi/SlippiReplayComm.cpp @@ -211,7 +211,7 @@ void SlippiReplayComm::loadFile() { json el = *it; WatchSettings w = {}; - w.path = el.value("path", ""); + w.path = File::GetAbsolutePathFromRelativePath(el.value("path", ""), configFilePath.substr(0, configFilePath.find_last_of("\\/"))); w.startFrame = el.value("startFrame", Slippi::GAME_FIRST_FRAME); w.endFrame = el.value("endFrame", INT_MAX); w.gameStartAt = el.value("gameStartAt", ""); From 28dd4895bf7af28121beeea0c3379d60b5dbf12d Mon Sep 17 00:00:00 2001 From: fluentcoding Date: Fri, 9 Oct 2020 16:16:43 +0200 Subject: [PATCH 2/3] Fix macOS/Linux builds resulting into an error --- Source/Core/Common/FileUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 1e22a78549..4aa15cb2be 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #else #include #include @@ -42,7 +43,6 @@ #include #include #endif -#include #ifndef S_ISDIR #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) From c3644c7982f190c5478934962a6bb13dc93fe8a2 Mon Sep 17 00:00:00 2001 From: fluentcoding Date: Fri, 9 Oct 2020 17:01:49 +0200 Subject: [PATCH 3/3] Fixing it again and small update --- 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 4aa15cb2be..ccfcee4963 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -754,7 +754,7 @@ std::string GetAbsolutePathFromRelativePath(const std::string &path, const std:: } else if (tempPath.back() == '/' && tempOrigin.front() == '/') { - tempPath.erase(tempPath.size() - 1); + tempPath.pop_back(); } #endif return tempOrigin + tempPath; @@ -762,6 +762,7 @@ std::string GetAbsolutePathFromRelativePath(const std::string &path, const std:: std::wstring s2ws(const std::string &s) { +#ifdef _WIN32 int len; int slength = (int)s.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0); @@ -770,6 +771,9 @@ std::wstring s2ws(const std::string &s) std::wstring r(buf); delete[] buf; return r; +#else + return NULL; +#endif } std::string &GetExeDirectory()