From abbc3384fd34901368b700f78208d233ccad5a56 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 11 Jul 2021 22:26:53 +0200 Subject: [PATCH] Fixed an issue where attempting to refine or skip a scraper search could lead to a crash. --- es-app/src/guis/GuiGameScraper.cpp | 7 +++++-- es-app/src/guis/GuiScraperMulti.cpp | 17 +++++++++++++---- es-app/src/guis/GuiScraperSearch.cpp | 23 ++++++++++++++++------- es-app/src/guis/GuiScraperSearch.h | 3 +++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/es-app/src/guis/GuiGameScraper.cpp b/es-app/src/guis/GuiGameScraper.cpp index ded44f56b..98b74fd02 100644 --- a/es-app/src/guis/GuiGameScraper.cpp +++ b/es-app/src/guis/GuiGameScraper.cpp @@ -72,8 +72,11 @@ GuiGameScraper::GuiGameScraper(Window* window, buttons.push_back( std::make_shared(mWindow, "REFINE SEARCH", "refine search", [&] { - mSearch->openInputScreen(mSearchParams); - mGrid.resetCursor(); + // Refine the search, unless the result has already been accepted. + if (!mSearch->getAcceptedResult()) { + mSearch->openInputScreen(mSearchParams); + mGrid.resetCursor(); + } })); buttons.push_back(std::make_shared(mWindow, "CANCEL", "cancel", [&] { if (mSearch->getSavedNewMedia()) { diff --git a/es-app/src/guis/GuiScraperMulti.cpp b/es-app/src/guis/GuiScraperMulti.cpp index ce1e20574..73d99670d 100644 --- a/es-app/src/guis/GuiScraperMulti.cpp +++ b/es-app/src/guis/GuiScraperMulti.cpp @@ -79,13 +79,22 @@ GuiScraperMulti::GuiScraperMulti(Window* window, if (mApproveResults) { buttons.push_back( std::make_shared(mWindow, "REFINE SEARCH", "refine search", [&] { - mSearchComp->openInputScreen(mSearchQueue.front()); - mGrid.resetCursor(); + // Refine the search, unless the result has already been accepted or we're in + // semi-automatic mode and there are less than 2 search results. + if (!mSearchComp->getAcceptedResult() && + !(mSearchComp->getSearchType() == GuiScraperSearch::ACCEPT_SINGLE_MATCHES && + mSearchComp->getScraperResultSize() < 2)) { + mSearchComp->openInputScreen(mSearchQueue.front()); + mGrid.resetCursor(); + } })); buttons.push_back(std::make_shared(mWindow, "SKIP", "skip game", [&] { - skip(); - mGrid.resetCursor(); + // Skip game, unless the result has already been accepted. + if (!mSearchComp->getAcceptedResult()) { + skip(); + mGrid.resetCursor(); + } })); } diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 046a9c192..4fd119939 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -49,6 +49,7 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int addChild(&mGrid); mBlockAccept = false; + mAcceptedResult = false; mRetrySearch = false; mRetryCount = 0; @@ -325,6 +326,7 @@ void GuiScraperSearch::updateViewStyle() void GuiScraperSearch::search(const ScraperSearchParams& params) { mBlockAccept = true; + mAcceptedResult = false; mMiximageResult = false; mScrapeResult = {}; @@ -347,6 +349,7 @@ void GuiScraperSearch::stop() mMDRetrieveURLsHandle.reset(); mMiximageGenerator.reset(); mBlockAccept = false; + mAcceptedResult = false; mMiximageResult = false; mScrapeResult = {}; } @@ -546,12 +549,17 @@ bool GuiScraperSearch::input(InputConfig* config, Input input) return true; } - // Refine search. - if (config->isMappedTo("y", input) && input.value != 0) - openInputScreen(mLastSearch); + // Refine the search, unless the result has already been accepted or we're in semi-automatic + // mode and there are less than 2 search results. + if (!mAcceptedResult && config->isMappedTo("y", input) && input.value != 0) { + if (mSearchType != ACCEPT_SINGLE_MATCHES || + mSearchType == ACCEPT_SINGLE_MATCHES && mScraperResults.size() > 1) { + openInputScreen(mLastSearch); + } + } - // Skip game. - if (mScrapeCount > 1 && config->isMappedTo("x", input) && input.value != 0) + // Skip game, unless the result has already been accepted. + if (!mAcceptedResult && mScrapeCount > 1 && config->isMappedTo("x", input) && input.value != 0) mSkipCallback(); return GuiComponent::input(config, input); @@ -573,6 +581,7 @@ void GuiScraperSearch::render(const Transform4x4f& parentTrans) void GuiScraperSearch::returnResult(ScraperSearchResult result) { mBlockAccept = true; + mAcceptedResult = true; // Resolve metadata image before returning. if (result.mediaFilesDownloadStatus != COMPLETED) { @@ -791,8 +800,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params) } else { // If searching based on the actual file name, then expand to the full game name - // in case the scraper is set to TheGamesDB and it's an arcade game. This is required - // as TheGamesDB has issues with searches using the short MAME names. + // in case the scraper is set to TheGamesDB and it's an arcade game. This is + // required as TheGamesDB does not support searches using the short MAME names. if (params.game->isArcadeGame() && Settings::getInstance()->getString("Scraper") == "thegamesdb") searchString = MameNames::getInstance()->getCleanName(params.game->getCleanName()); diff --git a/es-app/src/guis/GuiScraperSearch.h b/es-app/src/guis/GuiScraperSearch.h index aeb607b79..6f71ab865 100644 --- a/es-app/src/guis/GuiScraperSearch.h +++ b/es-app/src/guis/GuiScraperSearch.h @@ -47,6 +47,8 @@ public: void search(const ScraperSearchParams& params); void openInputScreen(ScraperSearchParams& from); void stop(); + int getScraperResultSize() { return static_cast(mScraperResults.size()); } + bool getAcceptedResult() { return mAcceptedResult; } SearchType getSearchType() const { return mSearchType; } bool getSavedNewMedia() { @@ -145,6 +147,7 @@ private: unsigned int mScrapeCount; bool mRefinedSearch; bool mBlockAccept; + bool mAcceptedResult; bool mFoundGame; bool mScrapeRatings;