From f753fef1c5ac38a48fe590233880c2dcb84be151 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 30 Oct 2020 12:53:35 +0100 Subject: [PATCH] Added a discrete game counting function. --- es-app/src/FileData.cpp | 16 ++++++++++++++++ es-app/src/FileData.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/es-app/src/FileData.cpp b/es-app/src/FileData.cpp index 8c297f066..cdcc99e0a 100644 --- a/es-app/src/FileData.cpp +++ b/es-app/src/FileData.cpp @@ -752,6 +752,22 @@ void FileData::sort(const SortType& type, bool mFavoritesOnTop) sort(*type.comparisonFunction, type.ascending, mGameCount); } +void FileData::countGames(std::pair& gameCount) +{ + for (unsigned int i = 0; i < mChildren.size(); i++) { + if (mChildren[i]->getType() == GAME && mChildren[i]->getCountAsGame()) { + if (!mChildren[i]->getFavorite()) + gameCount.first++; + else + gameCount.second++; + } + // Iterate through any folders. + else if (mChildren[i]->getType() == FOLDER) + mChildren[i]->countGames(gameCount); + } + mGameCount = gameCount; +} + FileData::SortType FileData::getSortTypeFromString(std::string desc) { std::vector SortTypes = FileSorts::SortTypes; diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index ebac70105..30c091fc1 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -123,6 +123,8 @@ public: std::pair& gameCount); void sort(const SortType& type, bool mFavoritesOnTop = false); MetaDataList metadata; + // Only count the games, a cheaper alternative to a full sort when that is not required. + void countGames(std::pair& gameCount); inline void setSortTypeString(std::string typestring) { mSortTypeString = typestring; } inline std::string getSortTypeString() { return mSortTypeString; }