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"
|
|
|
|
#include "Gamelist.h"
|
|
|
|
#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"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/ViewController.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
GuiScraperMulti::GuiScraperMulti(Window* window,
|
|
|
|
const std::queue<ScraperSearchParams>& searches,
|
|
|
|
bool approveResults)
|
|
|
|
: GuiComponent(window)
|
|
|
|
, mBackground(window, ":/graphics/frame.svg")
|
|
|
|
, mGrid(window, Vector2i(1, 5))
|
|
|
|
, 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.
|
|
|
|
mTitle = std::make_shared<TextComponent>(mWindow, "SCRAPING IN PROGRESS",
|
2021-07-07 18:03:42 +00:00
|
|
|
Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
mSystem = std::make_shared<TextComponent>(mWindow, "SYSTEM", Font::get(FONT_SIZE_MEDIUM),
|
|
|
|
0x777777FF, ALIGN_CENTER);
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setEntry(mSystem, Vector2i(0, 1), false, true);
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
mSubtitle = std::make_shared<TextComponent>(
|
|
|
|
mWindow, "subtitle text", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setEntry(mSubtitle, Vector2i(0, 2), false, true);
|
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
if (mApproveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2021-07-07 18:03:42 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(
|
|
|
|
mWindow, GuiScraperSearch::NEVER_AUTO_ACCEPT, mTotalGames);
|
2021-01-26 16:40:37 +00:00
|
|
|
else if (mApproveResults && Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2021-07-07 18:03:42 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(
|
|
|
|
mWindow, 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>(
|
|
|
|
mWindow, GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, mTotalGames);
|
|
|
|
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-07-07 18:03:42 +00:00
|
|
|
mGrid.setEntry(mSearchComp, Vector2i(0, 3),
|
|
|
|
mSearchComp->getSearchType() != GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT,
|
|
|
|
true);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
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) {
|
2021-07-07 18:03:42 +00:00
|
|
|
buttons.push_back(
|
|
|
|
std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH", "refine search", [&] {
|
2021-07-11 20:26:53 +00:00
|
|
|
// 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 &&
|
2021-07-11 20:35:01 +00:00
|
|
|
mSearchComp->getScraperResultsSize() < 2)) {
|
2021-07-11 20:26:53 +00:00
|
|
|
mSearchComp->openInputScreen(mSearchQueue.front());
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}
|
2021-07-07 18:03:42 +00:00
|
|
|
}));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "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
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP", "stop",
|
|
|
|
std::bind(&GuiScraperMulti::finish, this)));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
|
|
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 4), true, false);
|
|
|
|
|
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();
|
|
|
|
float width = Math::clamp(0.95f * aspectValue, 0.70f, 0.95f) * Renderer::getScreenWidth();
|
|
|
|
|
|
|
|
setSize(width, Renderer::getScreenHeight() * 0.849f);
|
2021-07-07 18:03:42 +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-03-12 19:03:46 +00:00
|
|
|
if (mTotalSuccessful > 0) {
|
|
|
|
// 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.
|
|
|
|
it != SystemData::sSystemVector.cend(); it++) {
|
2021-03-12 19:03:46 +00:00
|
|
|
(*it)->sortSystem();
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 10:01:43 +00:00
|
|
|
ViewController::get()->onPauseVideo();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::onSizeChanged()
|
|
|
|
{
|
2021-07-07 18:03:42 +00:00
|
|
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32.0f, -32.0f));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setRowHeightPerc(0, mTitle->getFont()->getLetterHeight() * 1.9725f / mSize.y(), false);
|
2021-07-07 18:03:42 +00:00
|
|
|
mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2.0f) / mSize.y(), false);
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid.setRowHeightPerc(2, mSubtitle->getFont()->getHeight() * 1.75f / mSize.y(), false);
|
|
|
|
mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y(), false);
|
|
|
|
mGrid.setSize(mSize);
|
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()) + " (" +
|
|
|
|
MameNames::getInstance()->getCleanName(mSearchQueue.front().game->getCleanName()) +
|
|
|
|
")";
|
2021-01-06 20:29:23 +00:00
|
|
|
else
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
|
|
|
|
}
|
|
|
|
|
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-01-26 16:40:37 +00:00
|
|
|
GuiScraperSearch::saveMetadata(result, search.game->metadata, search.game);
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
updateGamelist(search.system);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchQueue.pop();
|
|
|
|
mCurrentGame++;
|
|
|
|
mTotalSuccessful++;
|
2021-03-12 19:05:01 +00:00
|
|
|
CollectionSystemsManager::get()->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();
|
|
|
|
mCurrentGame++;
|
|
|
|
mTotalSkipped++;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, 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();
|
|
|
|
// Remove the 'Choose' entry if in fully automatic mode.
|
|
|
|
if (!mApproveResults)
|
|
|
|
prompts.pop_back();
|
|
|
|
return prompts;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2020-06-07 18:09:02 +00:00
|
|
|
|
|
|
|
HelpStyle GuiScraperMulti::getHelpStyle()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
HelpStyle style = HelpStyle();
|
|
|
|
style.applyTheme(ViewController::get()->getState().getSystem()->getTheme(), "system");
|
|
|
|
return style;
|
2020-06-07 18:09:02 +00:00
|
|
|
}
|