From 5f7ffe98c8f90f112b480be914c56759359c0f73 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 29 Jul 2020 19:01:49 +0200 Subject: [PATCH] Added metadata flag to mark whether a file should be counted as a game. This is useful for DOS games for instance, to exclude files such as installers, setup files etc. --- NEWS.md | 1 + es-app/src/CollectionSystemManager.cpp | 17 +++++++++++++- es-app/src/FileData.cpp | 31 +++++++++++++++++++++----- es-app/src/FileData.h | 3 ++- es-app/src/MetaData.cpp | 1 + es-app/src/SystemData.cpp | 3 ++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0e850e8c5..32e103a0b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -40,6 +40,7 @@ Many bugs have been fixed, and numerous features that were only partially implem * Added new component GuiComplexTextEditPopup to handle changes to configuration file entries and similar * Speed improvements and optimizations, the application now starts faster and feels more responsive * Added metadata entry to mark games as broken/not working +* Added metadata entry to indicate whether the file should be counted as a game (for example useful to exclude setup files and similar for DOS games) * Moved all resources to a subdirectory structure and enabled the CMake install prefix variable to generate the resources search path * Changed theme directory to the install prefix (e.g. /usr/local/share/emulationstation/themes) with themes in the home directory taking precedence * No more attempts to open files directly under /etc, instead only the install prefix directory and the home directory are used diff --git a/es-app/src/CollectionSystemManager.cpp b/es-app/src/CollectionSystemManager.cpp index ee6af7cd5..45d799aa9 100644 --- a/es-app/src/CollectionSystemManager.cpp +++ b/es-app/src/CollectionSystemManager.cpp @@ -316,6 +316,12 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS ViewController::get()-> getGameListView(curSys).get()->remove(collectionEntry, false); } + else if (name == "all" && !file->getCountAsGame()) { + // If the countasgame flag has been set to false, then remove the game. + ViewController::get()-> + getGameListView(curSys).get()->remove(collectionEntry, false); + } + else { // Re-index with new metadata. fileIndex->addToIndex(collectionEntry); @@ -323,10 +329,15 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS } } else { + bool addGame = false; // We didn't find it here - we need to check if we should add it. if (name == "recent" && file->metadata.get("playcount") > "0" && includeFileInAutoCollections(file) || name == "favorites" && - file->metadata.get("favorite") == "true") { + file->metadata.get("favorite") == "true") + addGame = true; + else if (name == "all" && file->getCountAsGame()) + addGame = true; + if (addGame) { CollectionFileData* newGame = new CollectionFileData(file, curSys); rootFolder->addChild(newGame); fileIndex->addToIndex(newGame); @@ -827,6 +838,10 @@ void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysDa } if (include) { + // Exclude files that are set not to be counted as games. + if (rootFolder->getName() == "all" && !(*gameIt)->getCountAsGame()) + continue; + CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys); rootFolder->addChild(newGame); index->addToIndex(newGame); diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index ad20f6654..01b014b08 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -115,6 +115,14 @@ const bool FileData::getHidden() return false; } +const bool FileData::getCountAsGame() +{ + if (metadata.get("countasgame") == "true") + return true; + else + return false; +} + const std::vector FileData::getChildrenRecursive() const { std::vector childrenRecursive; @@ -297,19 +305,32 @@ const std::vector& FileData::getChildrenListToDisplay() } } -std::vector FileData::getFilesRecursive(unsigned int typeMask, bool displayedOnly) const +std::vector FileData::getFilesRecursive(unsigned int typeMask, + bool displayedOnly, bool countAllGames) const { std::vector out; FileFilterIndex* idx = mSystem->getIndex(); for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) { if ((*it)->getType() & typeMask) { - if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) - out.push_back(*it); + if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) { + if (countAllGames) + out.push_back(*it); + else if ((*it)->getCountAsGame()) + out.push_back(*it); + } } if ((*it)->getChildren().size() > 0) { - std::vector subchildren = (*it)->getFilesRecursive(typeMask, displayedOnly); - out.insert(out.cend(), subchildren.cbegin(), subchildren.cend()); + std::vector subChildren = (*it)->getFilesRecursive(typeMask, displayedOnly); + if (countAllGames) { + out.insert(out.cend(), subChildren.cbegin(), subChildren.cend()); + } + else { + for (auto it = subChildren.cbegin(); it != subChildren.cend(); it++) { + if ((*it)->getCountAsGame()) + out.push_back(*it); + } + } } } diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index f09a52323..917c3cb36 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -48,6 +48,7 @@ public: const std::string& getSortName(); const bool getFavorite(); const bool getHidden(); + const bool getCountAsGame(); const std::vector getChildrenRecursive() const; inline FileType getType() const { return mType; } inline const std::string& getPath() const { return mPath; } @@ -77,7 +78,7 @@ public: const std::vector& getChildrenListToDisplay(); std::vector getFilesRecursive(unsigned int typeMask, - bool displayedOnly = false) const; + bool displayedOnly = false, bool countAllGames = true) const; void addChild(FileData* file); // Error if mType != FOLDER void removeChild(FileData* file); //Error if mType != FOLDER diff --git a/es-app/src/MetaData.cpp b/es-app/src/MetaData.cpp index d52def367..56d99e0d7 100644 --- a/es-app/src/MetaData.cpp +++ b/es-app/src/MetaData.cpp @@ -27,6 +27,7 @@ MetaDataDecl gameDecls[] = { {"broken", MD_BOOL, "false", false, "broken/not working", "enter broken off/on", false}, {"hidden", MD_BOOL, "false", false, "hidden", "enter hidden off/on", false}, {"kidgame", MD_BOOL, "false", false, "kidgame", "enter kidgame off/on", false}, +{"countasgame", MD_BOOL, "true", false, "count as game", "enter count as game off/on", false}, {"launchcommand", MD_LAUNCHCOMMAND, "", false, "launch command", "enter game launch command " "(emulator override)", false}, {"playcount", MD_INT, "0", false, "play count", "enter number of times played", false}, diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 6ec63bcca..47a5b4c64 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -598,7 +598,8 @@ FileData* SystemData::getRandomGame(const FileData* currentGame) unsigned int SystemData::getDisplayedGameCount() const { - return (unsigned int)mRootFolder->getFilesRecursive(GAME, true).size(); + // Pass the flag to only count games that are marked with the flag 'countasgame'. + return (unsigned int)mRootFolder->getFilesRecursive(GAME, true, false).size(); } void SystemData::loadTheme()