Index: source/lib/path.h =================================================================== --- source/lib/path.h +++ source/lib/path.h @@ -37,10 +37,14 @@ #ifndef INCLUDED_PATH #define INCLUDED_PATH +#include "lib/sysdep/os.h" #include "lib/utf8.h" #include #include +#if OS_WIN +#include +#endif #include namespace ERR @@ -126,6 +130,19 @@ return path.empty(); } + // TODO: This macro should be removed later when macOS supports std::filesystem. + // Currently it does in more recent SDKs, but it also causes a slowdown on + // OpenGL. See #6193. +#if OS_WIN + /** + * @returns a STL version of the path. + */ + std::filesystem::path fileSystemPath() const + { + return std::filesystem::path(path); + } +#endif + const String& string() const { return path; Index: source/ps/Mod.cpp =================================================================== --- source/ps/Mod.cpp +++ source/ps/Mod.cpp @@ -22,6 +22,7 @@ #include "i18n/L10n.h" #include "lib/file/file_system.h" #include "lib/file/vfs/vfs.h" +#include "lib/sysdep/os.h" #include "lib/utf8.h" #include "ps/Filesystem.h" #include "ps/GameSetup/GameSetup.h" @@ -35,6 +36,9 @@ #include #include #include +#if OS_WIN +#include +#endif #include #include #include @@ -48,11 +52,14 @@ bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& text) { +#if OS_WIN + const std::filesystem::path modJsonPath = (modsPath / mod / L"mod.json").fileSystemPath(); +#else + const std::string modJsonPath = (modsPath / mod / L"mod.json").string8(); +#endif // Attempt to open mod.json first. - std::ifstream modjson; - modjson.open((modsPath / mod / L"mod.json").string8()); - - if (!modjson.is_open()) + std::ifstream modjson(modJsonPath); + if (!modjson) { modjson.close(); @@ -69,8 +76,8 @@ text = modinfo.GetAsString(); // Attempt to write the mod.json file so we'll take the fast path next time. - std::ofstream out_mod_json((modsPath / mod / L"mod.json").string8()); - if (out_mod_json.good()) + std::ofstream out_mod_json(modJsonPath); + if (out_mod_json) { out_mod_json << text; out_mod_json.close();