From 51cae0d2e3f184a8654a0d7dcc5a6c83fa2abfb5 Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Mon, 12 Feb 2024 19:13:54 +0100 Subject: [PATCH] Fixed virtual paths were preprocessed using forward slash Fixes #33 Fixes #8 --- src/scriptCompiler.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/scriptCompiler.cpp b/src/scriptCompiler.cpp index b1a8080..5bee930 100644 --- a/src/scriptCompiler.cpp +++ b/src/scriptCompiler.cpp @@ -76,6 +76,13 @@ ScriptCompiler::ScriptCompiler() { init(); } +std::string PathToWindowsString(const std::filesystem::path& path) +{ + std::string result = path.generic_string(); + std::replace(result.begin(), result.end(), '/', '\\'); + return result; +} + CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path physicalPath, std::filesystem::path virtualPath) { std::ifstream inputFile(physicalPath); @@ -87,6 +94,7 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path physicalPat scriptCode.resize(filesize); inputFile.read(scriptCode.data(), filesize); + // Strip UTF-8 BOM if ( static_cast(scriptCode[0]) == 0xef && static_cast(scriptCode[1]) == 0xbb && @@ -100,8 +108,7 @@ CompiledCodeData ScriptCompiler::compileScript(std::filesystem::path physicalPat // throw std::domain_error("no include"); //} - - auto preprocessedScript = vm->parser_preprocessor().preprocess(*vm, scriptCode, sqf::runtime::fileio::pathinfo(physicalPath.string(), virtualPath.string()) ); + auto preprocessedScript = vm->parser_preprocessor().preprocess(*vm, scriptCode, sqf::runtime::fileio::pathinfo(physicalPath.string(), PathToWindowsString(virtualPath)) ); if (!preprocessedScript) { //__debugbreak(); return CompiledCodeData(); @@ -644,7 +651,7 @@ CompiledCodeData ScriptCompiler::compileScriptLua(std::filesystem::path physical void ScriptCompiler::initIncludePaths(const std::vector& paths) { for (auto& includefolder : paths) { - if (includefolder.string().length() == 3 && includefolder.string().substr(1) == ":/") { + if (includefolder.string().length() == 3 && includefolder.generic_string().substr(1) == ":/") { // pdrive //const std::filesystem::path ignoreGit(".git"); @@ -668,7 +675,7 @@ void ScriptCompiler::initIncludePaths(const std::vector& auto str = includefolder.lexically_normal().string(); if (str.back() == std::filesystem::path::preferred_separator) str.pop_back(); - vm->fileio().add_mapping(str, "/"); + vm->fileio().add_mapping(str, "\\"); } else { vm->fileio().add_mapping_auto(includefolder.string()); }