Hopefully fixed non-ASCII paths not working on Windows.

Kind of emulator-dependent on if this works or not.
This commit is contained in:
Aloshi 2015-02-21 16:48:56 -06:00
parent 1500edbde3
commit df896cb933
3 changed files with 19 additions and 2 deletions

View file

@ -61,6 +61,7 @@ SystemData::~SystemData()
delete mRootFolder; delete mRootFolder;
} }
std::string strreplace(std::string str, const std::string& replace, const std::string& with) std::string strreplace(std::string str, const std::string& replace, const std::string& with)
{ {
size_t pos; 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 // everything else: assume bash and escape special characters with backslashes
std::string escapePath(const boost::filesystem::path& path) std::string escapePath(const boost::filesystem::path& path)
{ {
#ifdef _WIN32 #ifdef WIN32
// windows escapes stuff by just putting everything in quotes // windows escapes stuff by just putting everything in quotes
return '"' + fs::path(path).make_preferred().string() + '"'; return '"' + fs::path(path).make_preferred().string() + '"';
#else #else
@ -123,7 +124,7 @@ void SystemData::launchGame(Window* window, FileData* game)
LOG(LogInfo) << " " << command; LOG(LogInfo) << " " << command;
std::cout << "==============================================\n"; std::cout << "==============================================\n";
int exitCode = system(command.c_str()); int exitCode = runSystemCommand(command);
std::cout << "==============================================\n"; std::cout << "==============================================\n";
if(exitCode != 0) if(exitCode != 0)

View file

@ -2,6 +2,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <iostream> #include <iostream>
#include <codecvt>
std::string getHomePath() std::string getHomePath()
{ {
@ -52,3 +53,17 @@ int runRestartCommand()
return system("sudo shutdown -r now"); return system("sudo shutdown -r now");
#endif #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<wchar_t> convert_type;
std::wstring_convert<convert_type, wchar_t> converter;
std::wstring wchar_str = converter.from_bytes(cmd_utf8);
return _wsystem(wchar_str.c_str());
#else
return system(cmd_utf8.c_str());
#endif
}

View file

@ -21,3 +21,4 @@ std::string getHomePath();
int runShutdownCommand(); // shut down the system (returns 0 if successful) int runShutdownCommand(); // shut down the system (returns 0 if successful)
int runRestartCommand(); // restart 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)