From 8c3c3e4e0f21c07fcea5fba8818ef7654de0d2a4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 17 Oct 2023 23:03:17 +0200 Subject: [PATCH] Added some additional gamelist.xml cleanup logic to GuiOrphanedDataCleanup --- es-app/src/guis/GuiOrphanedDataCleanup.cpp | 35 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/es-app/src/guis/GuiOrphanedDataCleanup.cpp b/es-app/src/guis/GuiOrphanedDataCleanup.cpp index ed91691dc..b39f30a08 100644 --- a/es-app/src/guis/GuiOrphanedDataCleanup.cpp +++ b/es-app/src/guis/GuiOrphanedDataCleanup.cpp @@ -520,7 +520,7 @@ void GuiOrphanedDataCleanup::cleanupGamelists() "/gamelist.xml_CLEANUP.tmp"}; if (Utils::FileSystem::exists(tempFile)) { - LOG(LogWarning) << "Found existing temporary file \"" << tempFile << "\""; + LOG(LogWarning) << "Found existing temporary file \"" << tempFile << "\", deleting it"; if (!Utils::FileSystem::removeFile(tempFile)) { LOG(LogError) << "Couldn't remove temporary file \"" << tempFile << "\""; { @@ -567,6 +567,7 @@ void GuiOrphanedDataCleanup::cleanupGamelists() } const std::vector knownTags {"game", "folder"}; + const std::vector& extensions {system->getSystemEnvData()->mSearchExtensions}; // Step through every game and folder element so that the order of entries will remain // in the target gamelist.xml file. @@ -583,7 +584,35 @@ void GuiOrphanedDataCleanup::cleanupGamelists() ++removeCount; } else if (Utils::FileSystem::exists(startPath + "/" + path)) { - targetRoot.append_copy((*it)); + if (tag == "game") { + // Remove entries with extensions not defined in es_systems.xml. + if (std::find(extensions.cbegin(), extensions.cend(), + Utils::FileSystem::getExtension(path)) != extensions.cend()) { + targetRoot.append_copy((*it)); + } + else { + LOG(LogInfo) << "Found orphaned " << tag << " entry \"" << path << "\""; + ++removeCount; + } + } + else { + bool folderExists {false}; + for (auto child : system->getRootFolder()->getChildrenRecursive()) { + if (child->getType() == FOLDER && + child->getPath() == + system->getRootFolder()->getPath() + path.substr(1)) { + folderExists = true; + break; + } + } + if (folderExists) { + targetRoot.append_copy((*it)); + } + else { + LOG(LogInfo) << "Found orphaned " << tag << " entry \"" << path << "\""; + ++removeCount; + } + } } else { LOG(LogInfo) << "Found orphaned " << tag << " entry \"" << path << "\""; @@ -794,7 +823,7 @@ void GuiOrphanedDataCleanup::cleanupCollections() const std::string tempFile {collectionFile + "_CLEANUP.tmp"}; if (Utils::FileSystem::exists(tempFile)) { - LOG(LogWarning) << "Found existing temporary file \"" << tempFile << "\""; + LOG(LogWarning) << "Found existing temporary file \"" << tempFile << "\", deleting it"; if (!Utils::FileSystem::removeFile(tempFile)) { LOG(LogError) << "Couldn't remove temporary file"; {