mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-14 05:55:13 +01:00
Use placeholders for serialized paths
This commit is contained in:
parent
74c06bd13e
commit
b5f394dd12
@ -729,6 +729,33 @@ void SetUserPath(const std::string& path) {
|
|||||||
g_paths.emplace(UserPath::StatesDir, user_path + STATES_DIR DIR_SEP);
|
g_paths.emplace(UserPath::StatesDir, user_path + STATES_DIR DIR_SEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string g_currentRomPath{};
|
||||||
|
|
||||||
|
void SetCurrentRomPath(const std::string& path) {
|
||||||
|
g_currentRomPath = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StringReplace(std::string& haystack, const std::string& a, const std::string& b, bool swap) {
|
||||||
|
const auto& needle = swap ? b : a;
|
||||||
|
const auto& replacement = swap ? a : b;
|
||||||
|
if (needle.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto index = haystack.find(needle, 0);
|
||||||
|
if (index == std::string::npos) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
haystack.replace(index, needle.size(), replacement);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SerializePath(const std::string& input, bool is_saving) {
|
||||||
|
auto result = input;
|
||||||
|
StringReplace(result, "%CITRA_ROM_FILE%", g_currentRomPath, is_saving);
|
||||||
|
StringReplace(result, "%CITRA_USER_DIR%", GetUserPath(UserPath::UserDir), is_saving);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& GetUserPath(UserPath path) {
|
const std::string& GetUserPath(UserPath path) {
|
||||||
// Set up all paths and files on the first run
|
// Set up all paths and files on the first run
|
||||||
if (g_paths.empty())
|
if (g_paths.empty())
|
||||||
|
@ -140,10 +140,15 @@ bool SetCurrentDir(const std::string& directory);
|
|||||||
|
|
||||||
void SetUserPath(const std::string& path = "");
|
void SetUserPath(const std::string& path = "");
|
||||||
|
|
||||||
|
void SetCurrentRomPath(const std::string& path);
|
||||||
|
|
||||||
// Returns a pointer to a string with a Citra data dir in the user's home
|
// Returns a pointer to a string with a Citra data dir in the user's home
|
||||||
// directory. To be used in "multi-user" mode (that is, installed).
|
// directory. To be used in "multi-user" mode (that is, installed).
|
||||||
const std::string& GetUserPath(UserPath path);
|
const std::string& GetUserPath(UserPath path);
|
||||||
|
|
||||||
|
// Replaces install-specific paths with standard placeholders, and back again
|
||||||
|
std::string SerializePath(const std::string& input, bool is_saving);
|
||||||
|
|
||||||
// Returns the path to where the sys file are
|
// Returns the path to where the sys file are
|
||||||
std::string GetSysDirectory();
|
std::string GetSysDirectory();
|
||||||
|
|
||||||
@ -318,7 +323,8 @@ private:
|
|||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void save(Archive& ar, const unsigned int) const {
|
void save(Archive& ar, const unsigned int) const {
|
||||||
ar << filename;
|
auto s_filename = SerializePath(filename, true);
|
||||||
|
ar << s_filename;
|
||||||
ar << openmode;
|
ar << openmode;
|
||||||
ar << flags;
|
ar << flags;
|
||||||
ar << Tell();
|
ar << Tell();
|
||||||
@ -327,6 +333,7 @@ private:
|
|||||||
template <class Archive>
|
template <class Archive>
|
||||||
void load(Archive& ar, const unsigned int) {
|
void load(Archive& ar, const unsigned int) {
|
||||||
ar >> filename;
|
ar >> filename;
|
||||||
|
filename = SerializePath(filename, false);
|
||||||
ar >> openmode;
|
ar >> openmode;
|
||||||
ar >> flags;
|
ar >> flags;
|
||||||
u64 pos;
|
u64 pos;
|
||||||
|
@ -214,6 +214,7 @@ System::ResultStatus System::SingleStep() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
|
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath) {
|
||||||
|
FileUtil::SetCurrentRomPath(filepath);
|
||||||
app_loader = Loader::GetLoader(filepath);
|
app_loader = Loader::GetLoader(filepath);
|
||||||
if (!app_loader) {
|
if (!app_loader) {
|
||||||
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
|
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
|
||||||
|
Loading…
Reference in New Issue
Block a user