2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// GuiScraperMulti.cpp
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Multiple game scraping user interface.
|
|
|
|
// Shows the progress for the scraping as it's running.
|
|
|
|
// This interface is triggered from GuiScraperMenu.
|
|
|
|
// GuiScraperSearch is called from here.
|
2020-05-26 16:34:33 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiScraperMulti.h"
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "CollectionSystemsManager.h"
|
2021-10-27 17:06:37 +00:00
|
|
|
#include "FileFilterIndex.h"
|
2022-01-15 13:12:56 +00:00
|
|
|
#include "GamelistFileParser.h"
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "MameNames.h"
|
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Window.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "components/ButtonComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/MenuComponent.h"
|
|
|
|
#include "components/TextComponent.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "guis/GuiMsgBox.h"
|
2020-06-06 12:14:13 +00:00
|
|
|
#include "guis/GuiScraperSearch.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
GuiScraperMulti::GuiScraperMulti(const std::queue<ScraperSearchParams>& searches,
|
2021-07-07 18:03:42 +00:00
|
|
|
bool approveResults)
|
2022-01-19 17:01:54 +00:00
|
|
|
: mBackground {":/graphics/frame.svg"}
|
|
|
|
, mGrid {glm::ivec2 {2, 6}}
|
2022-01-16 17:18:28 +00:00
|
|
|
, mSearchQueue {searches}
|
|
|
|
, mApproveResults {approveResults}
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(mSearchQueue.size());
|
|
|
|
|
|
|
|
addChild(&mBackground);
|
|
|
|
addChild(&mGrid);
|
|
|
|
|
|
|
|
mIsProcessing = true;
|
|
|
|
|
2020-11-17 22:06:54 +00:00
|
|
|
mTotalGames = static_cast<int>(mSearchQueue.size());
|
2020-06-21 12:25:28 +00:00
|
|
|
mCurrentGame = 0;
|
|
|
|
mTotalSuccessful = 0;
|
|
|
|
mTotalSkipped = 0;
|
|
|
|
|
|
|
|
// Set up grid.
|
2022-01-19 17:01:54 +00:00
|
|
|
mTitle = std::make_shared<TextComponent>("SCRAPING IN PROGRESS", Font::get(FONT_SIZE_LARGE),
|
|
|
|
0x555555FF, ALIGN_CENTER);
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mTitle, glm::ivec2 {0, 0}, false, true, glm::ivec2 {2, 2});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
mSystem = std::make_shared<TextComponent>("SYSTEM", Font::get(FONT_SIZE_MEDIUM), 0x777777FF,
|
|
|
|
ALIGN_CENTER);
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mSystem, glm::ivec2 {0, 2}, false, true, glm::ivec2 {2, 1});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
mSubtitle = std::make_shared<TextComponent>("subtitle text", Font::get(FONT_SIZE_SMALL),
|
|
|
|
0x888888FF, ALIGN_CENTER);
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mSubtitle, glm::ivec2 {0, 3}, false, true, glm::ivec2 {2, 1});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
if (mApproveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2022-01-19 17:01:54 +00:00
|
|
|
mSearchComp =
|
|
|
|
std::make_shared<GuiScraperSearch>(GuiScraperSearch::NEVER_AUTO_ACCEPT, mTotalGames);
|
2021-01-26 16:40:37 +00:00
|
|
|
else if (mApproveResults && Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2022-01-19 17:01:54 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(GuiScraperSearch::ACCEPT_SINGLE_MATCHES,
|
|
|
|
mTotalGames);
|
2021-01-26 16:40:37 +00:00
|
|
|
else if (!mApproveResults)
|
2021-07-07 18:03:42 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(
|
2022-01-19 17:01:54 +00:00
|
|
|
GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, mTotalGames);
|
2021-07-07 18:03:42 +00:00
|
|
|
mSearchComp->setAcceptCallback(
|
|
|
|
std::bind(&GuiScraperMulti::acceptResult, this, std::placeholders::_1));
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
|
|
|
|
mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this));
|
2021-10-15 18:58:40 +00:00
|
|
|
mSearchComp->setRefineCallback([&] {
|
2022-02-11 21:10:25 +00:00
|
|
|
mScrollUp->setOpacity(0.0f);
|
|
|
|
mScrollDown->setOpacity(0.0f);
|
2021-10-15 18:58:40 +00:00
|
|
|
mResultList->resetScrollIndicatorStatus();
|
|
|
|
});
|
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mSearchComp, glm::ivec2 {0, 4},
|
2021-07-07 18:03:42 +00:00
|
|
|
mSearchComp->getSearchType() != GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT,
|
2022-01-16 11:09:55 +00:00
|
|
|
true, glm::ivec2 {2, 1});
|
2021-10-15 18:58:40 +00:00
|
|
|
|
|
|
|
mResultList = mSearchComp->getResultList();
|
|
|
|
|
|
|
|
// Set up scroll indicators.
|
2022-01-19 17:01:54 +00:00
|
|
|
mScrollUp = std::make_shared<ImageComponent>();
|
|
|
|
mScrollDown = std::make_shared<ImageComponent>();
|
2021-10-15 18:58:40 +00:00
|
|
|
mScrollIndicator =
|
|
|
|
std::make_shared<ScrollIndicatorComponent>(mResultList, mScrollUp, mScrollDown);
|
|
|
|
|
|
|
|
mScrollUp->setResize(0.0f, mTitle->getFont()->getLetterHeight() / 2.0f);
|
|
|
|
mScrollUp->setOrigin(0.0f, -0.35f);
|
|
|
|
|
|
|
|
mScrollDown->setResize(0.0f, mTitle->getFont()->getLetterHeight() / 2.0f);
|
|
|
|
mScrollDown->setOrigin(0.0f, 0.35f);
|
|
|
|
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mScrollUp, glm::ivec2 {1, 0}, false, false, glm::ivec2 {1, 1});
|
|
|
|
mGrid.setEntry(mScrollDown, glm::ivec2 {1, 1}, false, false, glm::ivec2 {1, 1});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-10-15 18:58:40 +00:00
|
|
|
// Buttons.
|
2021-03-27 09:26:13 +00:00
|
|
|
std::vector<std::shared_ptr<ButtonComponent>> buttons;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
if (mApproveResults) {
|
2022-01-19 17:01:54 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>("REFINE SEARCH", "refine search", [&] {
|
|
|
|
// Check whether we should allow a refine of the game name.
|
|
|
|
if (!mSearchComp->getAcceptedResult()) {
|
|
|
|
bool allowRefine = false;
|
|
|
|
|
|
|
|
// Previously refined.
|
|
|
|
if (mSearchComp->getRefinedSearch())
|
|
|
|
allowRefine = true;
|
|
|
|
// Interactive mode and "Auto-accept single game matches" not enabled.
|
|
|
|
else if (mSearchComp->getSearchType() != GuiScraperSearch::ACCEPT_SINGLE_MATCHES)
|
|
|
|
allowRefine = true;
|
|
|
|
// Interactive mode with "Auto-accept single game matches" enabled and more
|
|
|
|
// than one result.
|
|
|
|
else if (mSearchComp->getSearchType() == GuiScraperSearch::ACCEPT_SINGLE_MATCHES &&
|
|
|
|
mSearchComp->getScraperResultsSize() > 1)
|
|
|
|
allowRefine = true;
|
|
|
|
// Dito but there were no games found, or the search has not been completed.
|
|
|
|
else if (mSearchComp->getSearchType() == GuiScraperSearch::ACCEPT_SINGLE_MATCHES &&
|
|
|
|
!mSearchComp->getFoundGame())
|
|
|
|
allowRefine = true;
|
|
|
|
|
|
|
|
if (allowRefine) {
|
|
|
|
// Copy any search refine that may have been previously entered by opening
|
|
|
|
// the input screen using the "Y" button shortcut.
|
|
|
|
mSearchQueue.front().nameOverride = mSearchComp->getNameOverride();
|
|
|
|
mSearchComp->openInputScreen(mSearchQueue.front());
|
|
|
|
mGrid.resetCursor();
|
2021-07-11 20:26:53 +00:00
|
|
|
}
|
2022-01-19 17:01:54 +00:00
|
|
|
}
|
|
|
|
}));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>("SKIP", "skip game", [&] {
|
2021-07-11 20:26:53 +00:00
|
|
|
// Skip game, unless the result has already been accepted.
|
|
|
|
if (!mSearchComp->getAcceptedResult()) {
|
|
|
|
skip();
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>("STOP", "stop",
|
2021-07-07 18:03:42 +00:00
|
|
|
std::bind(&GuiScraperMulti::finish, this)));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
mButtonGrid = makeButtonGrid(buttons);
|
2022-01-16 11:09:55 +00:00
|
|
|
mGrid.setEntry(mButtonGrid, glm::ivec2 {0, 5}, true, false, glm::ivec2 {2, 1});
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-02 15:51:07 +00:00
|
|
|
// Limit the width of the GUI on ultrawide monitors. The 1.778 aspect ratio value is
|
|
|
|
// the 16:9 reference.
|
|
|
|
float aspectValue = 1.778f / Renderer::getScreenAspectRatio();
|
2021-08-17 18:55:29 +00:00
|
|
|
float width = glm::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth();
|
2021-07-02 15:51:07 +00:00
|
|
|
|
2022-02-11 22:38:23 +00:00
|
|
|
float height = (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight() * 0.0637f) +
|
2021-10-15 18:58:40 +00:00
|
|
|
mSystem->getFont()->getLetterHeight() +
|
|
|
|
mSubtitle->getFont()->getHeight() * 1.75f + mButtonGrid->getSize().y +
|
|
|
|
Font::get(FONT_SIZE_MEDIUM)->getHeight() * 7.0f;
|
|
|
|
|
|
|
|
// TODO: Temporary hack, see below.
|
|
|
|
height -= 7.0f * Renderer::getScreenHeightModifier();
|
|
|
|
|
|
|
|
setSize(width, height);
|
2021-08-16 16:25:01 +00:00
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f,
|
|
|
|
(Renderer::getScreenHeight() - mSize.y) / 2.0f);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
doNextSearch();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GuiScraperMulti::~GuiScraperMulti()
|
|
|
|
{
|
2021-12-02 16:36:00 +00:00
|
|
|
if (mTotalSuccessful > 0 || mSearchComp->getSavedNewMedia()) {
|
2021-03-12 19:03:46 +00:00
|
|
|
// Sort all systems to possibly update their view style from Basic to Detailed or Video.
|
2021-07-07 18:03:42 +00:00
|
|
|
for (auto it = SystemData::sSystemVector.cbegin(); // Line break.
|
2021-11-17 16:35:34 +00:00
|
|
|
it != SystemData::sSystemVector.cend(); ++it) {
|
2021-03-12 19:03:46 +00:00
|
|
|
(*it)->sortSystem();
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::onSizeChanged()
|
|
|
|
{
|
2021-10-15 18:58:40 +00:00
|
|
|
mGrid.setRowHeightPerc(
|
|
|
|
0, (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight() * 0.0637f) /
|
|
|
|
mSize.y / 2.0f);
|
|
|
|
mGrid.setRowHeightPerc(
|
|
|
|
1, (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight() * 0.0637f) /
|
|
|
|
mSize.y / 2.0f);
|
|
|
|
mGrid.setRowHeightPerc(2, (mSystem->getFont()->getLetterHeight()) / mSize.y, false);
|
|
|
|
mGrid.setRowHeightPerc(3, mSubtitle->getFont()->getHeight() * 1.75f / mSize.y, false);
|
|
|
|
mGrid.setRowHeightPerc(4, ((Font::get(FONT_SIZE_MEDIUM)->getHeight() * 7.0f)) / mSize.y, false);
|
|
|
|
|
|
|
|
// TODO: Replace this temporary hack with a proper solution. There is some kind of rounding
|
|
|
|
// issue somewhere that causes a small alignment error. This code partly compensates for this
|
|
|
|
// at higher resolutions than 1920x1080.
|
|
|
|
if (Renderer::getScreenHeightModifier() > 1.0f)
|
|
|
|
mSize.y -= 3.0f * Renderer::getScreenHeightModifier();
|
|
|
|
|
|
|
|
mGrid.setColWidthPerc(1, 0.04f);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setSize(mSize);
|
2022-01-16 11:09:55 +00:00
|
|
|
mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f});
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::doNextSearch()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mSearchQueue.empty()) {
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update title.
|
|
|
|
std::stringstream ss;
|
|
|
|
mSystem->setText(Utils::String::toUpper(mSearchQueue.front().system->getFullName()));
|
|
|
|
|
2021-01-06 20:29:23 +00:00
|
|
|
std::string scrapeName;
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("ScraperSearchMetadataName")) {
|
|
|
|
scrapeName = mSearchQueue.front().game->getName();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mSearchQueue.front().game->isArcadeGame() &&
|
2021-07-07 18:03:42 +00:00
|
|
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
|
|
|
scrapeName =
|
|
|
|
Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath()) + " (" +
|
2021-11-17 20:32:40 +00:00
|
|
|
MameNames::getInstance().getCleanName(mSearchQueue.front().game->getCleanName()) +
|
2021-07-07 18:03:42 +00:00
|
|
|
")";
|
2021-01-06 20:29:23 +00:00
|
|
|
else
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
|
|
|
|
}
|
|
|
|
|
2022-02-11 21:10:25 +00:00
|
|
|
mScrollUp->setOpacity(0.0f);
|
|
|
|
mScrollDown->setOpacity(0.0f);
|
2021-10-15 18:58:40 +00:00
|
|
|
mResultList->resetScrollIndicatorStatus();
|
|
|
|
|
2021-01-31 20:53:53 +00:00
|
|
|
// Extract possible subfolders from the path.
|
2021-07-07 18:03:42 +00:00
|
|
|
std::string folderPath =
|
|
|
|
Utils::String::replace(Utils::FileSystem::getParent(mSearchQueue.front().game->getPath()),
|
|
|
|
mSearchQueue.front().system->getSystemEnvData()->mStartPath, "");
|
2021-01-31 20:53:53 +00:00
|
|
|
|
|
|
|
if (folderPath.size() >= 2) {
|
|
|
|
folderPath.erase(0, 1);
|
2021-07-07 18:03:42 +00:00
|
|
|
#if defined(_WIN64)
|
2021-01-31 20:53:53 +00:00
|
|
|
folderPath.push_back('\\');
|
|
|
|
folderPath = Utils::String::replace(folderPath, "/", "\\");
|
2021-07-07 18:03:42 +00:00
|
|
|
#else
|
2021-01-31 20:53:53 +00:00
|
|
|
folderPath.push_back('/');
|
2021-07-07 18:03:42 +00:00
|
|
|
#endif
|
2021-01-31 20:53:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update subtitle.
|
2020-12-25 14:28:19 +00:00
|
|
|
ss.str("");
|
2021-07-07 18:03:42 +00:00
|
|
|
ss << "GAME " << (mCurrentGame + 1) << " OF " << mTotalGames << " - " << folderPath
|
|
|
|
<< scrapeName
|
|
|
|
<< ((mSearchQueue.front().game->getType() == FOLDER) ? " " + ViewController::FOLDER_CHAR :
|
|
|
|
"");
|
2020-06-21 12:25:28 +00:00
|
|
|
mSubtitle->setText(ss.str());
|
|
|
|
|
|
|
|
mSearchComp->search(mSearchQueue.front());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::acceptResult(const ScraperSearchResult& result)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
ScraperSearchParams& search = mSearchQueue.front();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-10-27 17:06:37 +00:00
|
|
|
search.system->getIndex()->removeFromIndex(search.game);
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2021-10-27 17:06:37 +00:00
|
|
|
GuiScraperSearch::saveMetadata(result, search.game->metadata, search.game);
|
2022-01-15 13:12:56 +00:00
|
|
|
GamelistFileParser::updateGamelist(search.system);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-10-27 17:06:37 +00:00
|
|
|
search.system->getIndex()->addToIndex(search.game);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchQueue.pop();
|
2021-11-17 16:35:34 +00:00
|
|
|
++mCurrentGame;
|
|
|
|
++mTotalSuccessful;
|
2022-01-04 20:21:26 +00:00
|
|
|
CollectionSystemsManager::getInstance()->refreshCollectionSystems(search.game);
|
2020-06-21 12:25:28 +00:00
|
|
|
doNextSearch();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::skip()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchQueue.pop();
|
2021-11-17 16:35:34 +00:00
|
|
|
++mCurrentGame;
|
|
|
|
++mTotalSkipped;
|
2021-09-22 21:10:40 +00:00
|
|
|
mSearchComp->decreaseScrapeCount();
|
2021-01-26 16:40:37 +00:00
|
|
|
mSearchComp->unsetRefinedSearch();
|
2020-06-21 12:25:28 +00:00
|
|
|
doNextSearch();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::finish()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
if (mTotalSuccessful == 0) {
|
|
|
|
ss << "NO GAMES WERE SCRAPED";
|
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:03:42 +00:00
|
|
|
ss << mTotalSuccessful << " GAME" << ((mTotalSuccessful > 1) ? "S" : "")
|
|
|
|
<< " SUCCESSFULLY SCRAPED";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (mTotalSkipped > 0)
|
2021-07-07 18:03:42 +00:00
|
|
|
ss << "\n"
|
|
|
|
<< mTotalSkipped << " GAME" << ((mTotalSkipped > 1) ? "S" : "") << " SKIPPED";
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
mWindow->pushGui(new GuiMsgBox(getHelpStyle(), ss.str(), "OK", [&] {
|
2020-08-07 11:07:36 +00:00
|
|
|
mIsProcessing = false;
|
|
|
|
delete this;
|
|
|
|
}));
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()
|
|
|
|
{
|
2021-01-26 16:40:37 +00:00
|
|
|
std::vector<HelpPrompt> prompts = mGrid.getHelpPrompts();
|
|
|
|
return prompts;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|