From bccc658e8bb311c986f967bd8922456851a0f39e Mon Sep 17 00:00:00 2001 From: Andrey Filipenkov Date: Sat, 10 Sep 2022 16:03:54 +0300 Subject: [PATCH] fix launching server when Windows user name has non-latin characters --- client/CServerHandler.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index d9ce48f46..e0193efdc 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -47,6 +47,10 @@ #include +#ifdef VCMI_WINDOWS +#include +#endif + template class CApplyOnLobby; #ifdef VCMI_ANDROID @@ -694,7 +698,23 @@ void CServerHandler::threadRunServer() } comm += " > \"" + logName + '\"'; +#ifdef VCMI_WINDOWS + int result = -1; + const auto bufSize = ::MultiByteToWideChar(CP_UTF8, 0, comm.c_str(), comm.size(), nullptr, 0); + if(bufSize > 0) + { + std::wstring wComm(bufSize, {}); + const auto convertResult = ::MultiByteToWideChar(CP_UTF8, 0, comm.c_str(), comm.size(), &wComm[0], bufSize); + if(convertResult > 0) + result = ::_wsystem(wComm.c_str()); + else + logNetwork->error("Error " + std::to_string(GetLastError()) + ": failed to convert server launch command to wide string: " + comm); + } + else + logNetwork->error("Error " + std::to_string(GetLastError()) + ": failed to obtain buffer length to convert server launch command to wide string : " + comm); +#else int result = std::system(comm.c_str()); +#endif if (result == 0) { logNetwork->info("Server closed correctly");