From c2d3719edfc900f083ea7dd3c3bdc4425610d30a Mon Sep 17 00:00:00 2001
From: Leon Styhre <leon@leonstyhre.com>
Date: Wed, 22 Dec 2021 18:53:29 +0100
Subject: [PATCH] Fixed an issue where stale gamelist entries could get
 displayed.

---
 es-app/src/Gamelist.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/es-app/src/Gamelist.cpp b/es-app/src/Gamelist.cpp
index b302c17e1..55838ed94 100644
--- a/es-app/src/Gamelist.cpp
+++ b/es-app/src/Gamelist.cpp
@@ -44,7 +44,7 @@ FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType
             treeNode = children.at(key);
         }
 
-        // This is the end
+        // This is the end.
         if (path_it == --pathList.end()) {
             if (found)
                 return treeNode;
@@ -54,6 +54,19 @@ FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType
                 return nullptr;
             }
 
+            // Handle the special situation where a file exists and has an entry in the
+            // gamelist.xml file but the file extension is not configured in es_systems.xml.
+            const std::vector<std::string> extensions =
+                system->getSystemEnvData()->mSearchExtensions;
+
+            if (std::find(extensions.cbegin(), extensions.cend(),
+                          Utils::FileSystem::getExtension(path)) == extensions.cend()) {
+                LOG(LogWarning) << "File \"" << path
+                                << "\" is present in gamelist.xml but the extension is not "
+                                   "configured in es_systems.xml";
+                return nullptr;
+            }
+
             FileData* file = new FileData(type, path, system->getSystemEnvData(), system);
 
             // Skipping arcade assets from gamelist.