Fixed an issue where attempting to refine or skip a scraper search could lead to a crash.

This commit is contained in:
Leon Styhre 2021-07-11 22:26:53 +02:00
parent 122b9b2374
commit abbc3384fd
4 changed files with 37 additions and 13 deletions

View file

@ -72,8 +72,11 @@ GuiGameScraper::GuiGameScraper(Window* window,
buttons.push_back( buttons.push_back(
std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH", "refine search", [&] { std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH", "refine search", [&] {
// Refine the search, unless the result has already been accepted.
if (!mSearch->getAcceptedResult()) {
mSearch->openInputScreen(mSearchParams); mSearch->openInputScreen(mSearchParams);
mGrid.resetCursor(); mGrid.resetCursor();
}
})); }));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] {
if (mSearch->getSavedNewMedia()) { if (mSearch->getSavedNewMedia()) {

View file

@ -79,13 +79,22 @@ GuiScraperMulti::GuiScraperMulti(Window* window,
if (mApproveResults) { if (mApproveResults) {
buttons.push_back( buttons.push_back(
std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH", "refine search", [&] { std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH", "refine search", [&] {
// 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()); mSearchComp->openInputScreen(mSearchQueue.front());
mGrid.resetCursor(); mGrid.resetCursor();
}
})); }));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip game", [&] { buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip game", [&] {
// Skip game, unless the result has already been accepted.
if (!mSearchComp->getAcceptedResult()) {
skip(); skip();
mGrid.resetCursor(); mGrid.resetCursor();
}
})); }));
} }

View file

@ -49,6 +49,7 @@ GuiScraperSearch::GuiScraperSearch(Window* window, SearchType type, unsigned int
addChild(&mGrid); addChild(&mGrid);
mBlockAccept = false; mBlockAccept = false;
mAcceptedResult = false;
mRetrySearch = false; mRetrySearch = false;
mRetryCount = 0; mRetryCount = 0;
@ -325,6 +326,7 @@ void GuiScraperSearch::updateViewStyle()
void GuiScraperSearch::search(const ScraperSearchParams& params) void GuiScraperSearch::search(const ScraperSearchParams& params)
{ {
mBlockAccept = true; mBlockAccept = true;
mAcceptedResult = false;
mMiximageResult = false; mMiximageResult = false;
mScrapeResult = {}; mScrapeResult = {};
@ -347,6 +349,7 @@ void GuiScraperSearch::stop()
mMDRetrieveURLsHandle.reset(); mMDRetrieveURLsHandle.reset();
mMiximageGenerator.reset(); mMiximageGenerator.reset();
mBlockAccept = false; mBlockAccept = false;
mAcceptedResult = false;
mMiximageResult = false; mMiximageResult = false;
mScrapeResult = {}; mScrapeResult = {};
} }
@ -546,12 +549,17 @@ bool GuiScraperSearch::input(InputConfig* config, Input input)
return true; return true;
} }
// Refine search. // Refine the search, unless the result has already been accepted or we're in semi-automatic
if (config->isMappedTo("y", input) && input.value != 0) // 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); openInputScreen(mLastSearch);
}
}
// Skip game. // Skip game, unless the result has already been accepted.
if (mScrapeCount > 1 && config->isMappedTo("x", input) && input.value != 0) if (!mAcceptedResult && mScrapeCount > 1 && config->isMappedTo("x", input) && input.value != 0)
mSkipCallback(); mSkipCallback();
return GuiComponent::input(config, input); return GuiComponent::input(config, input);
@ -573,6 +581,7 @@ void GuiScraperSearch::render(const Transform4x4f& parentTrans)
void GuiScraperSearch::returnResult(ScraperSearchResult result) void GuiScraperSearch::returnResult(ScraperSearchResult result)
{ {
mBlockAccept = true; mBlockAccept = true;
mAcceptedResult = true;
// Resolve metadata image before returning. // Resolve metadata image before returning.
if (result.mediaFilesDownloadStatus != COMPLETED) { if (result.mediaFilesDownloadStatus != COMPLETED) {
@ -791,8 +800,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params)
} }
else { else {
// If searching based on the actual file name, then expand to the full game name // 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 // in case the scraper is set to TheGamesDB and it's an arcade game. This is
// as TheGamesDB has issues with searches using the short MAME names. // required as TheGamesDB does not support searches using the short MAME names.
if (params.game->isArcadeGame() && if (params.game->isArcadeGame() &&
Settings::getInstance()->getString("Scraper") == "thegamesdb") Settings::getInstance()->getString("Scraper") == "thegamesdb")
searchString = MameNames::getInstance()->getCleanName(params.game->getCleanName()); searchString = MameNames::getInstance()->getCleanName(params.game->getCleanName());

View file

@ -47,6 +47,8 @@ public:
void search(const ScraperSearchParams& params); void search(const ScraperSearchParams& params);
void openInputScreen(ScraperSearchParams& from); void openInputScreen(ScraperSearchParams& from);
void stop(); void stop();
int getScraperResultSize() { return static_cast<int>(mScraperResults.size()); }
bool getAcceptedResult() { return mAcceptedResult; }
SearchType getSearchType() const { return mSearchType; } SearchType getSearchType() const { return mSearchType; }
bool getSavedNewMedia() bool getSavedNewMedia()
{ {
@ -145,6 +147,7 @@ private:
unsigned int mScrapeCount; unsigned int mScrapeCount;
bool mRefinedSearch; bool mRefinedSearch;
bool mBlockAccept; bool mBlockAccept;
bool mAcceptedResult;
bool mFoundGame; bool mFoundGame;
bool mScrapeRatings; bool mScrapeRatings;