From 262304c777f4905fc74b9c4b5d1d9819d645d54d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 3 Nov 2021 10:57:45 +0100 Subject: [PATCH] Use correct encoding when calling external updater --- src/PrusaSlicer.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 17a59d04a..2b4209576 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -679,14 +679,18 @@ bool CLI::setup(int argc, char **argv) #ifdef _WIN32 // find updater exe - for (auto& dir_entry : boost::filesystem::directory_iterator(path_to_binary.parent_path())) { + for (const auto& dir_entry : boost::filesystem::directory_iterator(path_to_binary.parent_path())) { if (dir_entry.path().filename() == "prusaslicer-updater.exe") { // run updater. Original args: /silent -restartapp prusa-slicer.exe -startappfirst - std::string args = dir_entry.path().string(); - args += " /silent"; + + // Using quoted string as mentioned in CreateProcessW docs. + std::wstring wcmd = L"\"" + dir_entry.path().wstring() + L"\""; + wcmd += L" /silent"; + + // additional information - STARTUPINFOA si; + STARTUPINFOW si; PROCESS_INFORMATION pi; // set the size of the structures @@ -695,8 +699,8 @@ bool CLI::setup(int argc, char **argv) ZeroMemory(&pi, sizeof(pi)); // start the program up - CreateProcessA(NULL, // the path - const_cast(args.c_str()), // Command line + if (CreateProcessW(NULL, // the path + wcmd.data(), // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE @@ -705,11 +709,11 @@ bool CLI::setup(int argc, char **argv) NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses) - ); - // Close process and thread handles. - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - + )) { + // Close process and thread handles. + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } break; } }