Escape %ROM% by putting everything in quotes on Windows.

Use backslashes in %ROM% and %ROM_RAW% on Windows.
This commit is contained in:
Aloshi 2015-02-21 16:04:09 -06:00
parent 1de0b888aa
commit 1500edbde3

View file

@ -70,11 +70,17 @@ std::string strreplace(std::string str, const std::string& replace, const std::s
return str; return str;
} }
// plaform-specific escape path function
// on windows: just puts the path in quotes
// 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)
{ {
// a quick and dirty way to insert a backslash before most characters that would mess up a bash path; #ifdef _WIN32
// someone with regex knowledge should make this into a one-liner // windows escapes stuff by just putting everything in quotes
std::string pathStr = path.generic_string(); return '"' + fs::path(path).make_preferred().string() + '"';
#else
// a quick and dirty way to insert a backslash before most characters that would mess up a bash path
std::string pathStr = path.string();
const char* invalidChars = " '\"\\!$^&*(){}[]?;<>"; const char* invalidChars = " '\"\\!$^&*(){}[]?;<>";
for(unsigned int i = 0; i < pathStr.length(); i++) for(unsigned int i = 0; i < pathStr.length(); i++)
@ -94,6 +100,7 @@ std::string escapePath(const boost::filesystem::path& path)
} }
return pathStr; return pathStr;
#endif
} }
void SystemData::launchGame(Window* window, FileData* game) void SystemData::launchGame(Window* window, FileData* game)
@ -108,7 +115,7 @@ void SystemData::launchGame(Window* window, FileData* game)
const std::string rom = escapePath(game->getPath()); const std::string rom = escapePath(game->getPath());
const std::string basename = game->getPath().stem().string(); const std::string basename = game->getPath().stem().string();
const std::string rom_raw = game->getPath().string(); const std::string rom_raw = fs::path(game->getPath()).make_preferred().string();
command = strreplace(command, "%ROM%", rom); command = strreplace(command, "%ROM%", rom);
command = strreplace(command, "%BASENAME%", basename); command = strreplace(command, "%BASENAME%", basename);