From df896cb933882219572b4639cd2347ecf45fd102 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 21 Feb 2015 16:48:56 -0600 Subject: [PATCH] Hopefully fixed non-ASCII paths not working on Windows. Kind of emulator-dependent on if this works or not. --- es-app/src/SystemData.cpp | 5 +++-- es-core/src/platform.cpp | 15 +++++++++++++++ es-core/src/platform.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 224ffc20f..5e2b9b4c2 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -61,6 +61,7 @@ SystemData::~SystemData() delete mRootFolder; } + std::string strreplace(std::string str, const std::string& replace, const std::string& with) { size_t pos; @@ -75,7 +76,7 @@ std::string strreplace(std::string str, const std::string& replace, const std::s // everything else: assume bash and escape special characters with backslashes std::string escapePath(const boost::filesystem::path& path) { -#ifdef _WIN32 +#ifdef WIN32 // windows escapes stuff by just putting everything in quotes return '"' + fs::path(path).make_preferred().string() + '"'; #else @@ -123,7 +124,7 @@ void SystemData::launchGame(Window* window, FileData* game) LOG(LogInfo) << " " << command; std::cout << "==============================================\n"; - int exitCode = system(command.c_str()); + int exitCode = runSystemCommand(command); std::cout << "==============================================\n"; if(exitCode != 0) diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index a29bba42d..06cb4f884 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -2,6 +2,7 @@ #include #include #include +#include std::string getHomePath() { @@ -51,4 +52,18 @@ int runRestartCommand() #else // osx / linux return system("sudo shutdown -r now"); #endif +} + +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 + return system(cmd_utf8.c_str()); +#endif } \ No newline at end of file diff --git a/es-core/src/platform.h b/es-core/src/platform.h index b205d5f68..a0571b32a 100644 --- a/es-core/src/platform.h +++ b/es-core/src/platform.h @@ -21,3 +21,4 @@ std::string getHomePath(); int runShutdownCommand(); // shut down the system (returns 0 if successful) int runRestartCommand(); // restart the system (returns 0 if successful) +int runSystemCommand(const std::string& cmd_utf8); // run a utf-8 encoded in the shell (requires wstring conversion on Windows) \ No newline at end of file