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.
This commit is contained in:
Leon Styhre 2020-07-29 19:01:49 +02:00
parent c9283a10e5
commit 5f7ffe98c8
6 changed files with 48 additions and 8 deletions

View file

@ -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 * 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 * 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 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 * 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 * 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 * No more attempts to open files directly under /etc, instead only the install prefix directory and the home directory are used

View file

@ -316,6 +316,12 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
ViewController::get()-> ViewController::get()->
getGameListView(curSys).get()->remove(collectionEntry, false); 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 { else {
// Re-index with new metadata. // Re-index with new metadata.
fileIndex->addToIndex(collectionEntry); fileIndex->addToIndex(collectionEntry);
@ -323,10 +329,15 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
} }
} }
else { else {
bool addGame = false;
// We didn't find it here - we need to check if we should add it. // We didn't find it here - we need to check if we should add it.
if (name == "recent" && file->metadata.get("playcount") > "0" && if (name == "recent" && file->metadata.get("playcount") > "0" &&
includeFileInAutoCollections(file) || name == "favorites" && 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); CollectionFileData* newGame = new CollectionFileData(file, curSys);
rootFolder->addChild(newGame); rootFolder->addChild(newGame);
fileIndex->addToIndex(newGame); fileIndex->addToIndex(newGame);
@ -827,6 +838,10 @@ void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysDa
} }
if (include) { 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); CollectionFileData* newGame = new CollectionFileData(*gameIt, newSys);
rootFolder->addChild(newGame); rootFolder->addChild(newGame);
index->addToIndex(newGame); index->addToIndex(newGame);

View file

@ -115,6 +115,14 @@ const bool FileData::getHidden()
return false; return false;
} }
const bool FileData::getCountAsGame()
{
if (metadata.get("countasgame") == "true")
return true;
else
return false;
}
const std::vector<FileData*> FileData::getChildrenRecursive() const const std::vector<FileData*> FileData::getChildrenRecursive() const
{ {
std::vector<FileData*> childrenRecursive; std::vector<FileData*> childrenRecursive;
@ -297,19 +305,32 @@ const std::vector<FileData*>& FileData::getChildrenListToDisplay()
} }
} }
std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask, bool displayedOnly) const std::vector<FileData*> FileData::getFilesRecursive(unsigned int typeMask,
bool displayedOnly, bool countAllGames) const
{ {
std::vector<FileData*> out; std::vector<FileData*> out;
FileFilterIndex* idx = mSystem->getIndex(); FileFilterIndex* idx = mSystem->getIndex();
for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) { for (auto it = mChildren.cbegin(); it != mChildren.cend(); it++) {
if ((*it)->getType() & typeMask) { if ((*it)->getType() & typeMask) {
if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) if (!displayedOnly || !idx->isFiltered() || idx->showFile(*it)) {
out.push_back(*it); if (countAllGames)
out.push_back(*it);
else if ((*it)->getCountAsGame())
out.push_back(*it);
}
} }
if ((*it)->getChildren().size() > 0) { if ((*it)->getChildren().size() > 0) {
std::vector<FileData*> subchildren = (*it)->getFilesRecursive(typeMask, displayedOnly); std::vector<FileData*> subChildren = (*it)->getFilesRecursive(typeMask, displayedOnly);
out.insert(out.cend(), subchildren.cbegin(), subchildren.cend()); 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);
}
}
} }
} }

View file

@ -48,6 +48,7 @@ public:
const std::string& getSortName(); const std::string& getSortName();
const bool getFavorite(); const bool getFavorite();
const bool getHidden(); const bool getHidden();
const bool getCountAsGame();
const std::vector<FileData*> getChildrenRecursive() const; const std::vector<FileData*> getChildrenRecursive() const;
inline FileType getType() const { return mType; } inline FileType getType() const { return mType; }
inline const std::string& getPath() const { return mPath; } inline const std::string& getPath() const { return mPath; }
@ -77,7 +78,7 @@ public:
const std::vector<FileData*>& getChildrenListToDisplay(); const std::vector<FileData*>& getChildrenListToDisplay();
std::vector<FileData*> getFilesRecursive(unsigned int typeMask, std::vector<FileData*> getFilesRecursive(unsigned int typeMask,
bool displayedOnly = false) const; bool displayedOnly = false, bool countAllGames = true) const;
void addChild(FileData* file); // Error if mType != FOLDER void addChild(FileData* file); // Error if mType != FOLDER
void removeChild(FileData* file); //Error if mType != FOLDER void removeChild(FileData* file); //Error if mType != FOLDER

View file

@ -27,6 +27,7 @@ MetaDataDecl gameDecls[] = {
{"broken", MD_BOOL, "false", false, "broken/not working", "enter broken off/on", false}, {"broken", MD_BOOL, "false", false, "broken/not working", "enter broken off/on", false},
{"hidden", MD_BOOL, "false", false, "hidden", "enter hidden 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}, {"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 " {"launchcommand", MD_LAUNCHCOMMAND, "", false, "launch command", "enter game launch command "
"(emulator override)", false}, "(emulator override)", false},
{"playcount", MD_INT, "0", false, "play count", "enter number of times played", false}, {"playcount", MD_INT, "0", false, "play count", "enter number of times played", false},

View file

@ -598,7 +598,8 @@ FileData* SystemData::getRandomGame(const FileData* currentGame)
unsigned int SystemData::getDisplayedGameCount() const 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() void SystemData::loadTheme()