From 4ef3e94c5681fbe8b0dbc06fc00f07a908a69d82 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 17 Dec 2022 18:37:58 +0100 Subject: [PATCH] (Unix) Improved the .desktop file parser. --- es-app/src/FileData.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index da3876dbd..9315e0795 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -27,6 +27,7 @@ #include "views/ViewController.h" #include +#include FileData::FileData(FileType type, const std::string& path, @@ -1463,10 +1464,19 @@ void FileData::launchGame() validFile = true; if (line.substr(0, 5) == "Exec=") { romPath = {line.substr(5, line.size() - 5)}; - romPath = Utils::String::replace(romPath, "%F", ""); - romPath = Utils::String::replace(romPath, "%f", ""); - romPath = Utils::String::replace(romPath, "%U", ""); - romPath = Utils::String::replace(romPath, "%u", ""); + const std::string regexString {"[^%]%"}; + // Field codes, some of these are deprecated but may still exist in older + // .desktop files. Any matching codes escaped by double %% characters will + // be left as-is. + std::string codeCharacters {"fFuUdDnNickvm"}; + std::smatch searchResult; + while (!codeCharacters.empty()) { + while (std::regex_search(romPath, searchResult, + std::regex(regexString + codeCharacters.back()))) + romPath.replace(searchResult.position(0) + 1, searchResult.length() - 1, + ""); + codeCharacters.pop_back(); + } romPath = Utils::String::replace(romPath, "%%", "%"); romPath = Utils::String::trim(romPath); command = Utils::String::replace(command, binaryPath, "");