Added a per-system game counter to the multi-scraper in addition to the total game count

This commit is contained in:
Leon Styhre 2023-07-01 15:20:24 +02:00
parent bbc5f0be9b
commit 67b84434db
4 changed files with 36 additions and 18 deletions

View file

@ -103,7 +103,7 @@ GuiScraperMenu::GuiScraperMenu(std::string title)
// Add systems (all systems with an existing platform ID are listed).
mSystems = std::make_shared<OptionListComponent<SystemData*>>(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<ScraperSearchParams> 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<ScraperSearchParams> GuiScraperMenu::getSearches(std::vector<SystemData*> systems,
GameFilterFunc selector)
std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>> GuiScraperMenu::getSearches(
std::vector<SystemData*> systems, GameFilterFunc selector)
{
std::queue<ScraperSearchParams> queue;
std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>> queue;
for (auto sys = systems.cbegin(); sys != systems.cend(); ++sys) {
std::vector<FileData*> 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);
}
}
}

View file

@ -48,8 +48,8 @@ private:
void openOfflineGenerator(GuiSettings* settings);
void openOtherOptions();
std::queue<ScraperSearchParams> getSearches(std::vector<SystemData*> systems,
GameFilterFunc selector);
std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>> getSearches(
std::vector<SystemData*> systems, GameFilterFunc selector);
std::shared_ptr<OptionListComponent<std::string>> mScraper;
std::shared_ptr<OptionListComponent<GameFilterFunc>> mFilters;

View file

@ -23,12 +23,13 @@
#include "guis/GuiMsgBox.h"
#include "guis/GuiScraperSearch.h"
GuiScraperMulti::GuiScraperMulti(const std::queue<ScraperSearchParams>& searches,
bool approveResults)
GuiScraperMulti::GuiScraperMulti(
const std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>>& 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<ScraperSearchParams>& 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<TextComponent>("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);

View file

@ -26,7 +26,9 @@ class TextComponent;
class GuiScraperMulti : public GuiComponent
{
public:
GuiScraperMulti(const std::queue<ScraperSearchParams>& searches, bool approveResults);
GuiScraperMulti(
const std::pair<std::queue<ScraperSearchParams>, std::map<SystemData*, int>>& searches,
bool approveResults);
virtual ~GuiScraperMulti();
@ -56,6 +58,7 @@ private:
std::shared_ptr<ComponentList> mResultList;
std::queue<ScraperSearchParams> mSearchQueue;
std::map<SystemData*, std::pair<int, int>> mQueueCountPerSystem;
std::vector<MetaDataDecl> mMetaDataDecl;
unsigned int mTotalGames;
unsigned int mCurrentGame;