From d03b0e60c771d9612551eba17f99683ca869e2c2 Mon Sep 17 00:00:00 2001 From: Rael Gugelmin Cunha Date: Fri, 13 Nov 2020 15:07:55 -0300 Subject: [PATCH 1/2] Use ShellExecute to run emulators on Win32 --- es-core/src/platform.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index 81262310b7..77ece631dd 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -2,7 +2,7 @@ #include #ifdef WIN32 -#include +#include #else #include #endif @@ -30,14 +30,24 @@ int runRestartCommand() int runSystemCommand(const std::string& cmd_utf8) { -#ifdef WIN32 - // on Windows we use _wsystem to support non-ASCII paths - // which requires converting from utf8 to a wstring - typedef std::codecvt_utf8 convert_type; - std::wstring_convert converter; - std::wstring wchar_str = converter.from_bytes(cmd_utf8); - return _wsystem(wchar_str.c_str()); -#else +#ifdef WIN32 // windows + SHELLEXECUTEINFO ShExecInfo = {0}; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = NULL; + ShExecInfo.lpFile = cmd_utf8.c_str(); + ShExecInfo.lpParameters = ""; + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_SHOW; + ShExecInfo.hInstApp = NULL; + ShellExecuteEx(&ShExecInfo); + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + CloseHandle(ShExecInfo.hProcess); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + return dwExitCode; +#else // osx / linux return system(cmd_utf8.c_str()); #endif } From 72892db014976f972fe8710c4ae86292ecd0978f Mon Sep 17 00:00:00 2001 From: Rael Gugelmin Cunha Date: Fri, 13 Nov 2020 23:17:51 -0300 Subject: [PATCH 2/2] Properly parsing command params --- es-core/src/platform.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index 77ece631dd..e65176de4c 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -3,6 +3,8 @@ #include #ifdef WIN32 #include +#include "Shlwapi.h" +#pragma comment(lib, "Shlwapi.lib") #else #include #endif @@ -30,14 +32,16 @@ int runRestartCommand() int runSystemCommand(const std::string& cmd_utf8) { -#ifdef WIN32 // windows +#ifdef WIN32 + std::string args = std::string(PathGetArgs(cmd_utf8.c_str())); + std::string program = cmd_utf8.substr(0, cmd_utf8.length() - args.length()); SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; - ShExecInfo.lpFile = cmd_utf8.c_str(); - ShExecInfo.lpParameters = ""; + ShExecInfo.lpFile = program.c_str(); + ShExecInfo.lpParameters = args.c_str(); ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOW; ShExecInfo.hInstApp = NULL; @@ -47,7 +51,7 @@ int runSystemCommand(const std::string& cmd_utf8) DWORD dwExitCode = 0; GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); return dwExitCode; -#else // osx / linux +#else return system(cmd_utf8.c_str()); #endif }