From 67b84434db59e9d93026806827f677dbadda235e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 1 Jul 2023 15:20:24 +0200 Subject: [PATCH] Added a per-system game counter to the multi-scraper in addition to the total game count --- es-app/src/guis/GuiScraperMenu.cpp | 18 ++++++++++-------- es-app/src/guis/GuiScraperMenu.h | 4 ++-- es-app/src/guis/GuiScraperMulti.cpp | 27 ++++++++++++++++++++------- es-app/src/guis/GuiScraperMulti.h | 5 ++++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/es-app/src/guis/GuiScraperMenu.cpp b/es-app/src/guis/GuiScraperMenu.cpp index cde671f43..ec9116ef3 100644 --- a/es-app/src/guis/GuiScraperMenu.cpp +++ b/es-app/src/guis/GuiScraperMenu.cpp @@ -103,7 +103,7 @@ GuiScraperMenu::GuiScraperMenu(std::string title) // Add systems (all systems with an existing platform ID are listed). mSystems = std::make_shared>(getHelpStyle(), "SCRAPE THESE SYSTEMS", true); - for (unsigned int i = 0; i < SystemData::sSystemVector.size(); ++i) { + for (unsigned int i {0}; i < SystemData::sSystemVector.size(); ++i) { if (!SystemData::sSystemVector[i]->hasPlatformId(PlatformIds::PLATFORM_IGNORE)) { mSystems->add(SystemData::sSystemVector[i]->getFullName(), SystemData::sSystemVector[i], !SystemData::sSystemVector[i]->getPlatformIds().empty()); @@ -1260,10 +1260,9 @@ void GuiScraperMenu::start() return; } - std::queue searches = - getSearches(mSystems->getSelectedObjects(), mFilters->getSelected()); + auto searches = getSearches(mSystems->getSelectedObjects(), mFilters->getSelected()); - if (searches.empty()) { + if (searches.first.empty()) { mWindow->pushGui( new GuiMsgBox(getHelpStyle(), "ALL GAMES WERE FILTERED, NOTHING TO SCRAPE")); } @@ -1276,22 +1275,25 @@ void GuiScraperMenu::start() } } -std::queue GuiScraperMenu::getSearches(std::vector systems, - GameFilterFunc selector) +std::pair, std::map> GuiScraperMenu::getSearches( + std::vector systems, GameFilterFunc selector) { - std::queue queue; + std::pair, std::map> queue; + for (auto sys = systems.cbegin(); sys != systems.cend(); ++sys) { std::vector games {(*sys)->getRootFolder()->getScrapeFilesRecursive( Settings::getInstance()->getBool("ScraperIncludeFolders"), Settings::getInstance()->getBool("ScraperExcludeRecursively"), Settings::getInstance()->getBool("ScraperRespectExclusions"))}; + for (auto game = games.cbegin(); game != games.cend(); ++game) { if (selector((*sys), (*game))) { ScraperSearchParams search; search.game = *game; search.system = *sys; - queue.push(search); + ++queue.second[*sys]; + queue.first.push(search); } } } diff --git a/es-app/src/guis/GuiScraperMenu.h b/es-app/src/guis/GuiScraperMenu.h index 83ef361d8..ef839478c 100644 --- a/es-app/src/guis/GuiScraperMenu.h +++ b/es-app/src/guis/GuiScraperMenu.h @@ -48,8 +48,8 @@ private: void openOfflineGenerator(GuiSettings* settings); void openOtherOptions(); - std::queue getSearches(std::vector systems, - GameFilterFunc selector); + std::pair, std::map> getSearches( + std::vector systems, GameFilterFunc selector); std::shared_ptr> mScraper; std::shared_ptr> mFilters; diff --git a/es-app/src/guis/GuiScraperMulti.cpp b/es-app/src/guis/GuiScraperMulti.cpp index 6178b4d9c..554e332dc 100644 --- a/es-app/src/guis/GuiScraperMulti.cpp +++ b/es-app/src/guis/GuiScraperMulti.cpp @@ -23,12 +23,13 @@ #include "guis/GuiMsgBox.h" #include "guis/GuiScraperSearch.h" -GuiScraperMulti::GuiScraperMulti(const std::queue& searches, - bool approveResults) +GuiScraperMulti::GuiScraperMulti( + const std::pair, std::map>& searches, + bool approveResults) : mRenderer {Renderer::getInstance()} , mBackground {":/graphics/frame.svg"} , mGrid {glm::ivec2 {2, 6}} - , mSearchQueue {searches} + , mSearchQueue {searches.first} , mApproveResults {approveResults} { assert(mSearchQueue.size()); @@ -43,6 +44,9 @@ GuiScraperMulti::GuiScraperMulti(const std::queue& searches mTotalSuccessful = 0; mTotalSkipped = 0; + for (auto it = searches.second.begin(); it != searches.second.end(); ++it) + mQueueCountPerSystem[(*it).first] = std::make_pair(0, (*it).second); + // Set up grid. mTitle = std::make_shared("SCRAPING IN PROGRESS", Font::get(FONT_SIZE_LARGE), mMenuColorTitle, ALIGN_CENTER); @@ -215,8 +219,17 @@ void GuiScraperMulti::doNextSearch() // Update title. std::stringstream ss; - mSystem->setText(Utils::String::toUpper(mSearchQueue.front().system->getFullName())); + if (mQueueCountPerSystem.size() > 1) { + const int gameCount {++mQueueCountPerSystem[mSearchQueue.front().system].first}; + const int totalGameCount {mQueueCountPerSystem[mSearchQueue.front().system].second}; + mSystem->setText(Utils::String::toUpper(mSearchQueue.front().system->getFullName()) + + " [GAME " + std::to_string(gameCount) + " OF " + + std::to_string(totalGameCount) + "]"); + } + else { + mSystem->setText(Utils::String::toUpper(mSearchQueue.front().system->getFullName())); + } std::string scrapeName; if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) { @@ -238,9 +251,9 @@ void GuiScraperMulti::doNextSearch() mResultList->resetScrollIndicatorStatus(); // Extract possible subfolders from the path. - std::string folderPath = + std::string folderPath { Utils::String::replace(Utils::FileSystem::getParent(mSearchQueue.front().game->getPath()), - mSearchQueue.front().system->getSystemEnvData()->mStartPath, ""); + mSearchQueue.front().system->getSystemEnvData()->mStartPath, "")}; if (folderPath.size() >= 2) { folderPath.erase(0, 1); @@ -265,7 +278,7 @@ void GuiScraperMulti::doNextSearch() void GuiScraperMulti::acceptResult(const ScraperSearchResult& result) { - ScraperSearchParams& search = mSearchQueue.front(); + ScraperSearchParams& search {mSearchQueue.front()}; search.system->getIndex()->removeFromIndex(search.game); diff --git a/es-app/src/guis/GuiScraperMulti.h b/es-app/src/guis/GuiScraperMulti.h index f10e721e3..1cb8ac4ad 100644 --- a/es-app/src/guis/GuiScraperMulti.h +++ b/es-app/src/guis/GuiScraperMulti.h @@ -26,7 +26,9 @@ class TextComponent; class GuiScraperMulti : public GuiComponent { public: - GuiScraperMulti(const std::queue& searches, bool approveResults); + GuiScraperMulti( + const std::pair, std::map>& searches, + bool approveResults); virtual ~GuiScraperMulti(); @@ -56,6 +58,7 @@ private: std::shared_ptr mResultList; std::queue mSearchQueue; + std::map> mQueueCountPerSystem; std::vector mMetaDataDecl; unsigned int mTotalGames; unsigned int mCurrentGame;