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"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "Gamelist.h"
|
2021-01-06 20:29:23 +00:00
|
|
|
#include "MameNames.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
|
|
|
#include "Window.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-26 16:34:33 +00:00
|
|
|
GuiScraperMulti::GuiScraperMulti(
|
2020-06-21 12:25:28 +00:00
|
|
|
Window* window,
|
|
|
|
const std::queue<ScraperSearchParams>& searches,
|
|
|
|
bool approveResults)
|
|
|
|
: GuiComponent(window),
|
2021-01-14 21:56:49 +00:00
|
|
|
mBackground(window, ":/graphics/frame.svg"),
|
2020-06-21 12:25:28 +00:00
|
|
|
mGrid(window, Vector2i(1, 5)),
|
2021-01-26 16:40:37 +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.
|
|
|
|
mTitle = std::make_shared<TextComponent>(mWindow, "SCRAPING IN PROGRESS",
|
|
|
|
Font::get(FONT_SIZE_LARGE), 0x555555FF, ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mTitle, Vector2i(0, 0), false, true);
|
|
|
|
|
|
|
|
mSystem = std::make_shared<TextComponent>(mWindow, "SYSTEM",
|
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mSystem, Vector2i(0, 1), false, true);
|
|
|
|
|
|
|
|
mSubtitle = std::make_shared<TextComponent>(mWindow, "subtitle text",
|
|
|
|
Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
|
|
|
|
mGrid.setEntry(mSubtitle, Vector2i(0, 2), false, true);
|
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
if (mApproveResults && !Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
2020-07-31 12:24:14 +00:00
|
|
|
GuiScraperSearch::NEVER_AUTO_ACCEPT, mTotalGames);
|
2021-01-26 16:40:37 +00:00
|
|
|
else if (mApproveResults && Settings::getInstance()->getBool("ScraperSemiautomatic"))
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
2020-07-31 12:24:14 +00:00
|
|
|
GuiScraperSearch::ACCEPT_SINGLE_MATCHES, mTotalGames);
|
2021-01-26 16:40:37 +00:00
|
|
|
else if (!mApproveResults)
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchComp = std::make_shared<GuiScraperSearch>(mWindow,
|
2020-07-31 12:24:14 +00:00
|
|
|
GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, mTotalGames);
|
2020-06-21 12:25:28 +00:00
|
|
|
mSearchComp->setAcceptCallback(std::bind(&GuiScraperMulti::acceptResult,
|
|
|
|
this, std::placeholders::_1));
|
|
|
|
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
|
|
|
|
mSearchComp->setCancelCallback(std::bind(&GuiScraperMulti::finish, this));
|
|
|
|
mGrid.setEntry(mSearchComp, Vector2i(0, 3), mSearchComp->getSearchType() !=
|
|
|
|
GuiScraperSearch::ALWAYS_ACCEPT_FIRST_RESULT, true);
|
|
|
|
|
|
|
|
std::vector< std::shared_ptr<ButtonComponent> > buttons;
|
|
|
|
|
2021-01-26 16:40:37 +00:00
|
|
|
if (mApproveResults) {
|
2020-06-21 12:25:28 +00:00
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "REFINE SEARCH",
|
|
|
|
"refine search", [&] {
|
|
|
|
mSearchComp->openInputScreen(mSearchQueue.front());
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}));
|
|
|
|
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip game", [&] {
|
|
|
|
skip();
|
|
|
|
mGrid.resetCursor();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "STOP",
|
|
|
|
"stop (progress saved)", std::bind(&GuiScraperMulti::finish, this)));
|
|
|
|
|
|
|
|
mButtonGrid = makeButtonGrid(mWindow, buttons);
|
|
|
|
mGrid.setEntry(mButtonGrid, Vector2i(0, 4), true, false);
|
|
|
|
|
|
|
|
setSize(Renderer::getScreenWidth() * 0.95f, Renderer::getScreenHeight() * 0.849f);
|
|
|
|
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() -
|
|
|
|
mSize.y()) / 2);
|
|
|
|
|
|
|
|
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.
|
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
|
|
|
it !=SystemData::sSystemVector.cend(); it++) {
|
|
|
|
(*it)->sortSystem();
|
|
|
|
}
|
|
|
|
}
|
2020-09-27 10:01:43 +00:00
|
|
|
ViewController::get()->onPauseVideo();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiScraperMulti::onSizeChanged()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));
|
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);
|
|
|
|
mGrid.setRowHeightPerc(1, (mSystem->getFont()->getLetterHeight() + 2) / mSize.y(), false);
|
|
|
|
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() &&
|
|
|
|
Settings::getInstance()->getString("Scraper") == "thegamesdb")
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath()) +
|
|
|
|
" (" + MameNames::getInstance()->getCleanName(mSearchQueue.front().game->
|
|
|
|
getCleanName()) + ")";
|
|
|
|
else
|
|
|
|
scrapeName = Utils::FileSystem::getFileName(mSearchQueue.front().game->getPath());
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:53:53 +00:00
|
|
|
// Extract possible subfolders from the path.
|
|
|
|
std::string folderPath = Utils::String::replace(
|
|
|
|
Utils::FileSystem::getParent(mSearchQueue.front().game->getPath()),
|
|
|
|
mSearchQueue.front().system->getSystemEnvData()->mStartPath, "");
|
|
|
|
|
|
|
|
if (folderPath.size() >= 2) {
|
|
|
|
folderPath.erase(0, 1);
|
|
|
|
#if defined(_WIN64)
|
|
|
|
folderPath.push_back('\\');
|
|
|
|
folderPath = Utils::String::replace(folderPath, "/", "\\");
|
|
|
|
#else
|
|
|
|
folderPath.push_back('/');
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Update subtitle.
|
2020-12-25 14:28:19 +00:00
|
|
|
ss.str("");
|
2021-01-31 20:53:53 +00:00
|
|
|
ss << "GAME " << (mCurrentGame + 1) << " OF " << mTotalGames << " - " << folderPath <<
|
|
|
|
scrapeName << ((mSearchQueue.front().game->getType() == FOLDER) ? " " +
|
2020-12-25 14:28:19 +00:00
|
|
|
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++;
|
|
|
|
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 {
|
2020-08-07 11:07:36 +00:00
|
|
|
ss << mTotalSuccessful << " GAME" <<
|
|
|
|
((mTotalSuccessful > 1) ? "S" : "") << " SUCCESSFULLY SCRAPED";
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
if (mTotalSkipped > 0)
|
2020-08-07 11:07:36 +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
|
|
|
}
|