diff --git a/codegen/src/Main.cpp b/codegen/src/Main.cpp index 44defd573..2824da0db 100644 --- a/codegen/src/Main.cpp +++ b/codegen/src/Main.cpp @@ -133,7 +133,7 @@ int main(int argc, char** argv) try { if (auto sdkPath = std::getenv("GEODE_SDK")) { auto versionPath = std::filesystem::path(sdkPath) / "VERSION"; if (std::filesystem::exists(versionPath)) { - std::ifstream versionFile(versionPath); + auto versionFile = openInputFile(versionPath); std::string version; std::getline(versionFile, version); codegen::sdkVersion = codegen::Version::fromString(version); diff --git a/codegen/src/Shared.hpp b/codegen/src/Shared.hpp index 66d7fb952..f1417e363 100644 --- a/codegen/src/Shared.hpp +++ b/codegen/src/Shared.hpp @@ -8,8 +8,42 @@ #include #include +#ifdef _WIN32 +#include +#include +#include +#endif + using std::istreambuf_iterator; +// Cross-platform helper to open a file stream with Unicode path support +// On Windows, we need to use wide strings for proper Unicode support +#ifdef _WIN32 +inline std::ifstream openInputFile(std::filesystem::path const& path) { + std::ifstream file; + file.open(path.wstring()); + return file; +} + +inline std::ofstream openOutputFile(std::filesystem::path const& path) { + std::ofstream file; + file.open(path.wstring()); + return file; +} +#else +inline std::ifstream openInputFile(std::filesystem::path const& path) { + std::ifstream file; + file.open(path); + return file; +} + +inline std::ofstream openOutputFile(std::filesystem::path const& path) { + std::ofstream file; + file.open(path); + return file; +} +#endif + #ifdef _MSC_VER #pragma warning(disable : 4996) #endif @@ -32,15 +66,13 @@ std::string generateInlineSources(Root const& root, std::filesystem::path const& // returns true if the file contents were different (overwritten), false otherwise inline bool writeFile(std::filesystem::path const& writePath, std::string const& output) { - std::ifstream readfile; + auto readfile = openInputFile(writePath); readfile >> std::noskipws; - readfile.open(writePath); std::string data((std::istreambuf_iterator(readfile)), std::istreambuf_iterator()); readfile.close(); if (data != output) { - std::ofstream writefile; - writefile.open(writePath); + auto writefile = openOutputFile(writePath); writefile << output; writefile.close();