Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Playback] Process paths in slippi combo files relative to the config itself #202

Open
wants to merge 3 commits into
base: slippi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Source/Core/Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <shellapi.h>
#include <windows.h>
#include <winerror.h>
#include <Shlwapi.h>
#else
#include <dirent.h>
#include <errno.h>
Expand Down Expand Up @@ -723,6 +724,58 @@ 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.pop_back();
}
#endif
return tempOrigin + tempPath;
}

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);
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;
#else
return NULL;
#endif
}

std::string &GetExeDirectory()
{
static std::string DolphinPath;
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Common/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Slippi/SlippiReplayComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down