From 0c3a7d7d94d3a63a5b668725c29e5c51a17165cd Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 23 Sep 2021 17:07:27 +0200 Subject: [PATCH] Alternative emulators now work correctly when games are launched from collection systems. --- es-app/src/FileData.cpp | 24 ++++++++++++++++++------ es-app/src/SystemData.cpp | 10 ++++++++++ es-app/src/SystemData.h | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 6c977dd0f..4b8329203 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -746,14 +746,26 @@ void FileData::launchGame(Window* window) { LOG(LogInfo) << "Launching game \"" << this->metadata.get("name") << "\"..."; + SystemData* gameSystem = nullptr; std::string command = ""; - std::string alternativeEmulator = getSystem()->getAlternativeEmulator(); + std::string alternativeEmulator; + + if (mSystem->isCollection()) + gameSystem = SystemData::getSystemByName(mSystemName); + else + gameSystem = mSystem; + + // This is just a precaution as getSystemByName() should always return a valid result. + if (gameSystem == nullptr) + gameSystem = mSystem; + + alternativeEmulator = gameSystem->getAlternativeEmulator(); // Check if there is a game-specific alternative emulator configured. // This takes precedence over any system-wide alternative emulator configuration. if (Settings::getInstance()->getBool("AlternativeEmulatorPerGame") && !metadata.get("altemulator").empty()) { - command = getSystem()->getLaunchCommandFromLabel(metadata.get("altemulator")); + command = gameSystem->getLaunchCommandFromLabel(metadata.get("altemulator")); if (command == "") { LOG(LogWarning) << "Invalid alternative emulator \"" << metadata.get("altemulator") << "\" configured for game"; @@ -767,16 +779,16 @@ void FileData::launchGame(Window* window) // Check if there is a system-wide alternative emulator configured. if (command == "" && alternativeEmulator != "") { - command = getSystem()->getLaunchCommandFromLabel(alternativeEmulator); + command = gameSystem->getLaunchCommandFromLabel(alternativeEmulator); if (command == "") { LOG(LogWarning) << "Invalid alternative emulator \"" << alternativeEmulator.substr(9, alternativeEmulator.length() - 9) - << "\" configured for system \"" << getSystem()->getName() << "\""; + << "\" configured for system \"" << gameSystem->getName() << "\""; } else { LOG(LogDebug) << "FileData::launchGame(): Using alternative emulator \"" - << getSystem()->getAlternativeEmulator() << "\"" - << " as configured for system \"" << this->getSystem()->getName() << "\""; + << gameSystem->getAlternativeEmulator() << "\"" + << " as configured for system \"" << gameSystem->getName() << "\""; } } diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 9c565c0d2..adaa2c9b6 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -969,6 +969,16 @@ bool SystemData::isVisible() return true; } +SystemData* SystemData::getSystemByName(const std::string& systemName) +{ + for (auto it : sSystemVector) { + if ((*it).getName() == systemName) + return it; + } + + return nullptr; +} + SystemData* SystemData::getNext() const { std::vector::const_iterator it = getIterator(); diff --git a/es-app/src/SystemData.h b/es-app/src/SystemData.h index 381dd4380..8dd7bd4fd 100644 --- a/es-app/src/SystemData.h +++ b/es-app/src/SystemData.h @@ -131,6 +131,7 @@ public: bool isVisible(); + static SystemData* getSystemByName(const std::string& systemName); SystemData* getNext() const; SystemData* getPrev() const; static SystemData* getRandomSystem(const SystemData* currentSystem);