Fixes Windows not reading files properly.

This commit is contained in:
Deukhoofd 2022-03-18 00:38:38 +01:00
parent fd24ce63c1
commit 0b4806b354
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 11 additions and 1 deletions

View File

@ -95,7 +95,17 @@ BattleLibrary* BuildLibrary::Build(const std::string& pathString,
continue;
std::ifstream in(dirEntry.path());
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
asScriptResolver->CreateScript((const char*)dirEntry.path().c_str(), contents.c_str());
const auto* p = dirEntry.path().c_str();
// Windows defines paths as widechars, so we need to convert it to a normal human const char*
#if WINDOWS
std::mbstate_t state = std::mbstate_t();
int textLen = 1 + std::wcsrtombs(NULL, &p, 0, &state);
std::vector<char> storeTextBuffer(textLen);
std::wcsrtombs(&storeTextBuffer[0], &p, textLen, &state);
asScriptResolver->CreateScript(&storeTextBuffer[0], contents.c_str());
#else
asScriptResolver->CreateScript(p, contents.c_str());
#endif
}
asScriptResolver->FinalizeModule();
ScriptsTimeMs =