|
| 1 | +--- src/lib/ViZDoomController.h |
| 2 | ++++ src/lib/ViZDoomController.h |
| 3 | +@@ -29,0 +30,2 @@ |
| 4 | ++#else |
| 5 | ++ #include "boost/process.hpp" |
| 6 | +@@ -35 +36,0 @@ |
| 7 | +-#include "boost/process.hpp" |
| 8 | +@@ -52,0 +54 @@ |
| 9 | ++#ifndef _WIN32 |
| 10 | +@@ -54,0 +57 @@ |
| 11 | ++#endif |
| 12 | +--- src/lib/ViZDoomController.cpp |
| 13 | ++++ src/lib/ViZDoomController.cpp |
| 14 | +@@ -33,0 +34 @@ |
| 15 | ++#include <stdexcept> |
| 16 | +@@ -36,0 +38,28 @@ |
| 17 | ++ |
| 18 | ++#ifdef OS_WIN |
| 19 | ++ namespace { |
| 20 | ++ std::string quoteCommandArg(const std::string &arg) { |
| 21 | ++ if (arg.empty()) return "\"\""; |
| 22 | ++ if (arg.find_first_of(" \t\"") == std::string::npos) return arg; |
| 23 | ++ |
| 24 | ++ std::string quoted = "\""; |
| 25 | ++ size_t backslashes = 0; |
| 26 | ++ for (char ch : arg) { |
| 27 | ++ if (ch == '\\') { |
| 28 | ++ ++backslashes; |
| 29 | ++ } else if (ch == '"') { |
| 30 | ++ quoted.append(backslashes * 2 + 1, '\\'); |
| 31 | ++ quoted.push_back('"'); |
| 32 | ++ backslashes = 0; |
| 33 | ++ } else { |
| 34 | ++ quoted.append(backslashes, '\\'); |
| 35 | ++ backslashes = 0; |
| 36 | ++ quoted.push_back(ch); |
| 37 | ++ } |
| 38 | ++ } |
| 39 | ++ quoted.append(backslashes * 2, '\\'); |
| 40 | ++ quoted.push_back('"'); |
| 41 | ++ return quoted; |
| 42 | ++ } |
| 43 | ++ } |
| 44 | ++#endif |
| 45 | +@@ -1473,0 +1503,18 @@ |
| 46 | ++#ifdef OS_WIN |
| 47 | ++ std::string commandLine; |
| 48 | ++ for (size_t i = 0; i < this->doomArgs.size(); ++i) { |
| 49 | ++ if (i != 0) commandLine += " "; |
| 50 | ++ commandLine += quoteCommandArg(this->doomArgs[i]); |
| 51 | ++ } |
| 52 | ++ |
| 53 | ++ STARTUPINFOA startupInfo = { sizeof(startupInfo) }; |
| 54 | ++ PROCESS_INFORMATION processInfo = {}; |
| 55 | ++ std::vector<char> commandLineBuffer(commandLine.begin(), commandLine.end()); |
| 56 | ++ commandLineBuffer.push_back('\0'); |
| 57 | ++ |
| 58 | ++ if (!CreateProcessA(NULL, commandLineBuffer.data(), NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo)) |
| 59 | ++ throw std::runtime_error("Failed to launch ViZDoom process."); |
| 60 | ++ WaitForSingleObject(processInfo.hProcess, INFINITE); |
| 61 | ++ CloseHandle(processInfo.hThread); |
| 62 | ++ CloseHandle(processInfo.hProcess); |
| 63 | ++#else |
| 64 | +@@ -1478,0 +1526 @@ |
| 65 | ++#endif |
0 commit comments