mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
Some checks failed
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
Build Desktop / Configure (push) Has been cancelled
Build Docker / Servatrice (arm) (push) Has been cancelled
Build Docker / Servatrice (x86) (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 44 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Servatrice_Debian 12 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 26 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled
Build Docker / Publish multi-platform Servatrice image (push) Has been cancelled
* [Oracle/Client] Report card database download progress Card database updates ran invisibly: MTGJSON parsing spun an indeterminate bar on the UI thread and the set import blocked the window, while the onboarding wizard spawned `oracle -b` with no progress to show at all. - Add byte-level scan progress to `RawJson::scanSetRanges` via an optional callback, throttled to ~100 reports per scan. - Emit `OracleImporter::dataReadProgress` during the scan and import sets on a worker thread, driving the wizard's progress bar per set. - With `-b`, write machine-readable `PROGRESS <stage> <done> <total>` lines to stdout for the download/scan/import stages; stderr keeps the log output. - Parse the oracle stdout in `MainWindow` and forward it to the onboarding wizard, giving the card database step a determinate bar with stage-specific status text. - Guard the async workers against the wizard being closed mid-run. - Add Google Test coverage for scan progress reporting. * [Oracle/Client] Harden oracle progress workers and quit prompt Address review feedback on the download-progress change: decompress and read sets files off the UI thread, cancel the load/import workers before the wizard can tear down the importer, and show an 'Extracting file...' status plus a clean 100% tail so the poll never looks stuck. Quitting Cockatrice while a card database update runs now asks for confirmation. * Show 100% for 500ms on complete. * Disable buttons on set import until done. * Clean up progress bar. * Drop wrapper around lambda --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
158 lines
4 KiB
C++
158 lines
4 KiB
C++
#include "oraclewizard.h"
|
|
|
|
#include "client/settings/cache_settings.h"
|
|
#include "main.h"
|
|
#include "oracleimporter.h"
|
|
#include "pages.h"
|
|
#include "pagetemplates.h"
|
|
|
|
#include <QCheckBox>
|
|
#include <QFileDialog>
|
|
#include <QGridLayout>
|
|
#include <QLineEdit>
|
|
#include <QNetworkReply>
|
|
#include <QPushButton>
|
|
#include <QScrollBar>
|
|
#include <QtConcurrent>
|
|
#include <QtGui>
|
|
#include <libcockatrice/settings/personal_settings.h>
|
|
|
|
OracleWizard::OracleWizard(QWidget *parent) : QWizard(parent)
|
|
{
|
|
// define a dummy context that will be used where needed
|
|
QString dummy = QT_TRANSLATE_NOOP("i18n", "English");
|
|
|
|
#ifdef Q_OS_WIN
|
|
setWizardStyle(QWizard::ModernStyle);
|
|
#endif
|
|
|
|
QString oracleSettingsFile = SettingsCache::instance().getSettingsPath() + "oracle.ini";
|
|
settings = new QSettings(oracleSettingsFile, QSettings::IniFormat, this);
|
|
|
|
// We moved the oracle-specific settings from global.ini to a separate oracle.ini after 2.10
|
|
if (!QFile::exists(oracleSettingsFile)) {
|
|
migrateOracleSettings();
|
|
}
|
|
|
|
connect(&SettingsCache::instance().personal(), &PersonalSettings::langChanged, this, &OracleWizard::updateLanguage);
|
|
|
|
importer = new OracleImporter(this);
|
|
|
|
nam = new QNetworkAccessManager(this);
|
|
|
|
QList<OracleWizardPage *> pages;
|
|
|
|
if (!isSpoilersOnly) {
|
|
pages << new IntroPage << new LoadSetsPage << new SaveSetsPage << new LoadTokensPage << new OutroPage;
|
|
} else {
|
|
pages << new LoadSpoilersPage << new OutroPage;
|
|
}
|
|
|
|
for (OracleWizardPage *page : pages) {
|
|
addPage(page);
|
|
|
|
// Connect background auto-advance
|
|
connect(page, &OracleWizardPage::readyToContinue, this, [this]() {
|
|
if (backgroundMode) {
|
|
next();
|
|
}
|
|
});
|
|
}
|
|
|
|
retranslateUi();
|
|
}
|
|
|
|
/**
|
|
* Migrates the oracle-specific settings from global.ini to oracle.ini
|
|
*/
|
|
void OracleWizard::migrateOracleSettings()
|
|
{
|
|
QString filePath = SettingsCache::instance().getSettingsPath() + "global.ini";
|
|
auto globalSettings = QSettings(filePath, QSettings::IniFormat, this);
|
|
|
|
auto tryMigrateValue = [this, &globalSettings](const QString &name) {
|
|
QVariant variant = globalSettings.value(name);
|
|
if (variant.isValid()) {
|
|
settings->setValue(name, variant.toString());
|
|
}
|
|
};
|
|
|
|
tryMigrateValue("allsetsurl");
|
|
tryMigrateValue("tokensurl");
|
|
tryMigrateValue("spoilersurl");
|
|
}
|
|
|
|
void OracleWizard::updateLanguage()
|
|
{
|
|
qApp->removeTranslator(translator);
|
|
installNewTranslator();
|
|
}
|
|
|
|
void OracleWizard::changeEvent(QEvent *event)
|
|
{
|
|
if (event->type() == QEvent::LanguageChange) {
|
|
retranslateUi();
|
|
}
|
|
|
|
QDialog::changeEvent(event);
|
|
}
|
|
|
|
void OracleWizard::retranslateUi()
|
|
{
|
|
setWindowTitle(tr("Oracle Importer"));
|
|
for (int i = 0; i < pageIds().count(); i++) {
|
|
dynamic_cast<OracleWizardPage *>(page(i))->retranslateUi();
|
|
}
|
|
}
|
|
|
|
void OracleWizard::accept()
|
|
{
|
|
QDialog::accept();
|
|
}
|
|
|
|
void OracleWizard::reject()
|
|
{
|
|
// The wizard is being closed while a page may still run a worker on the
|
|
// importer. Ask it to stop before the wizard (and the importer child) is
|
|
// destroyed, so the worker thread never touches freed memory.
|
|
if (auto *active = dynamic_cast<OracleWizardPage *>(currentPage())) {
|
|
active->cancelWork();
|
|
}
|
|
QWizard::reject();
|
|
}
|
|
|
|
void OracleWizard::runInBackground()
|
|
{
|
|
backgroundMode = true;
|
|
hide();
|
|
currentPage()->initializePage();
|
|
}
|
|
|
|
void OracleWizard::enableButtons()
|
|
{
|
|
button(QWizard::NextButton)->setDisabled(false);
|
|
button(QWizard::BackButton)->setDisabled(false);
|
|
}
|
|
|
|
void OracleWizard::disableButtons()
|
|
{
|
|
button(QWizard::NextButton)->setDisabled(true);
|
|
button(QWizard::BackButton)->setDisabled(true);
|
|
}
|
|
|
|
bool OracleWizard::saveTokensToFile(const QString &fileName)
|
|
{
|
|
QFile file(fileName);
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
qDebug() << "File open (w) failed for" << fileName;
|
|
return false;
|
|
}
|
|
|
|
if (file.write(tokensData) == -1) {
|
|
qDebug() << "File write (w) failed for" << fileName;
|
|
return false;
|
|
}
|
|
|
|
file.close();
|
|
return true;
|
|
}
|