From 1500edbde3039863437851799f3a581e20c496d7 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 21 Feb 2015 16:04:09 -0600 Subject: [PATCH] Escape %ROM% by putting everything in quotes on Windows. Use backslashes in %ROM% and %ROM_RAW% on Windows. --- es-app/src/SystemData.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index d506d0f9f..224ffc20f 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -70,11 +70,17 @@ std::string strreplace(std::string str, const std::string& replace, const std::s 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) { - // a quick and dirty way to insert a backslash before most characters that would mess up a bash path; - // someone with regex knowledge should make this into a one-liner - std::string pathStr = path.generic_string(); +#ifdef _WIN32 + // windows escapes stuff by just putting everything in quotes + 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 = " '\"\\!$^&*(){}[]?;<>"; for(unsigned int i = 0; i < pathStr.length(); i++) @@ -94,6 +100,7 @@ std::string escapePath(const boost::filesystem::path& path) } return pathStr; +#endif } 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 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, "%BASENAME%", basename);