diff --git a/UnleashedRecomp/config.cpp b/UnleashedRecomp/config.cpp index 4f5ad3e..b366a2f 100644 --- a/UnleashedRecomp/config.cpp +++ b/UnleashedRecomp/config.cpp @@ -2,7 +2,7 @@ void Config::Load() { try { - auto toml = toml::parse_file(TOML_FILE); + auto toml = toml::parse_file((GetUserPath() / TOML_FILE).string()); TOML_BEGIN_SECTION("System") { diff --git a/UnleashedRecomp/config.h b/UnleashedRecomp/config.h index a707957..6866862 100644 --- a/UnleashedRecomp/config.h +++ b/UnleashedRecomp/config.h @@ -1,7 +1,8 @@ #pragma once -// TODO: move this outside of the game directory? -#define TOML_FILE "SWA.toml" +#define USER_DIRECTORY "SWA" + +#define TOML_FILE "config.toml" #define TOML_BEGIN_SECTION(name) if (auto pSection = toml[name].as_table()) { const auto& section = *pSection; #define TOML_END_SECTION() } @@ -111,6 +112,23 @@ public: CONFIG_DEFINE(EMovieScaleMode, MovieScaleMode, EMovieScaleMode_Fit); CONFIG_DEFINE(EUIScaleMode, UIScaleMode, EUIScaleMode_Centre); + static std::filesystem::path GetUserPath() + { + if (std::filesystem::exists("portable.txt")) + return std::filesystem::current_path(); + + std::filesystem::path userPath{}; + + // TODO: handle platform-specific paths. + PWSTR knownPath = NULL; + if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &knownPath) == S_OK) + userPath = std::filesystem::path{ knownPath } / USER_DIRECTORY; + + CoTaskMemFree(knownPath); + + return userPath; + } + static void Load(); static void Save(); }; diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index e937141..c71a8ac 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -39,14 +39,12 @@ void KiSystemStartup() XamRegisterContent(gameContent, DirectoryExists(".\\game") ? ".\\game" : "."); XamRegisterContent(updateContent, ".\\update"); - if (FileExists(".\\save\\SYS-DATA")) - { - XamRegisterContent(XamMakeContent(XCONTENTTYPE_SAVEDATA, "SYS-DATA"), ".\\save"); - } - else if (FileExists(".\\SYS-DATA")) - { - XamRegisterContent(XamMakeContent(XCONTENTTYPE_SAVEDATA, "SYS-DATA"), "."); - } + const auto savePath = Config::GetUserPath() / "save"; + const auto saveName = "SYS-DATA"; + + // TODO: implement save slots? + if (std::filesystem::exists(savePath / saveName)) + XamRegisterContent(XamMakeContent(XCONTENTTYPE_SAVEDATA, saveName), savePath.string()); // Mount game XamContentCreateEx(0, "game", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr); diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 4f8f226..d8b63de 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -3,8 +3,10 @@ #define NOMINMAX #include +#include #include #include +#include #include #include #include