mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 01:55:10 -07:00
[Oracle/Client] Report card database download progress (#7253)
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
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>
This commit is contained in:
parent
69e8f80fa1
commit
7d867b9745
16 changed files with 821 additions and 197 deletions
|
|
@ -182,6 +182,13 @@ void FirstRunWizard::onCardDatabaseUpdateFinished(bool success)
|
|||
}
|
||||
}
|
||||
|
||||
void FirstRunWizard::onCardDatabaseUpdateProgress(const QString &stage, qint64 done, qint64 total)
|
||||
{
|
||||
if (cardDatabasePage) {
|
||||
cardDatabasePage->onUpdateProgress(stage, done, total);
|
||||
}
|
||||
}
|
||||
|
||||
void FirstRunWizard::finish()
|
||||
{
|
||||
accept();
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ public slots:
|
|||
/** @brief Forwarded from MainWindow once the background card database update process exits. */
|
||||
void onCardDatabaseUpdateFinished(bool success);
|
||||
|
||||
/** @brief Forwarded from MainWindow while the background card database update process runs. */
|
||||
void onCardDatabaseUpdateProgress(const QString &stage, qint64 done, qint64 total);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <QTimer>
|
||||
#include <QUrl>
|
||||
#include <QVBoxLayout>
|
||||
#include <climits>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/settings/updates_settings.h>
|
||||
|
||||
|
|
@ -179,6 +180,25 @@ void CardDatabaseSetupPage::onUpdateFinished(bool success)
|
|||
}
|
||||
}
|
||||
|
||||
void CardDatabaseSetupPage::onUpdateProgress(const QString &stage, qint64 done, qint64 total)
|
||||
{
|
||||
if (state != State::Running) {
|
||||
return;
|
||||
}
|
||||
progressBar->setRange(0, total > 0 ? static_cast<int>(qMin<qint64>(total, INT_MAX)) : 0);
|
||||
progressBar->setValue(static_cast<int>(qMin<qint64>(done, INT_MAX)));
|
||||
if (total > 0) {
|
||||
const int percent = static_cast<int>((100.0 * done) / total);
|
||||
if (stage == QLatin1String("download")) {
|
||||
statusLabel->setText(tr("Downloading the card database (%1%)…").arg(percent));
|
||||
} else if (stage == QLatin1String("scan")) {
|
||||
statusLabel->setText(tr("Parsing the card database (%1%)…").arg(percent));
|
||||
} else if (stage == QLatin1String("import")) {
|
||||
statusLabel->setText(tr("Importing cards (%1%)…").arg(percent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString CardDatabaseSetupPage::nextButtonText() const
|
||||
{
|
||||
return state == State::NotStarted ? tr("Download") : QString();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public:
|
|||
void retranslateUi() override;
|
||||
|
||||
void onUpdateFinished(bool success);
|
||||
void onUpdateProgress(const QString &stage, qint64 done, qint64 total);
|
||||
|
||||
signals:
|
||||
void updateRequested();
|
||||
|
|
|
|||
|
|
@ -682,6 +682,7 @@ void MainWindow::runFirstRunWizard()
|
|||
connect(wizard, &FirstRunWizard::cardDatabaseUpdateRequested, this, &MainWindow::actCheckCardUpdatesBackground);
|
||||
connect(wizard, &FirstRunWizard::manualCardDatabaseSetupRequested, this, &MainWindow::actCheckCardUpdates);
|
||||
connect(this, &MainWindow::cardDatabaseUpdateFinished, wizard, &FirstRunWizard::onCardDatabaseUpdateFinished);
|
||||
connect(this, &MainWindow::cardDatabaseUpdateProgress, wizard, &FirstRunWizard::onCardDatabaseUpdateProgress);
|
||||
connect(wizard, &FirstRunWizard::registerRequested, connectionController, &ConnectionController::registerToServer);
|
||||
connect(wizard, &FirstRunWizard::connectRequested, connectionController, &ConnectionController::connectToServer);
|
||||
|
||||
|
|
@ -843,6 +844,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
}
|
||||
bClosingDown = true;
|
||||
|
||||
if (cardUpdateProcess && cardUpdateProcess->state() != QProcess::NotRunning) {
|
||||
if (QMessageBox::question(this, tr("Are you sure?"),
|
||||
tr("A card database update is still running. Quitting now will cancel it.\n"
|
||||
"Are you sure you want to quit?"),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No) {
|
||||
event->ignore();
|
||||
bClosingDown = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tabSupervisor->close()) {
|
||||
event->ignore();
|
||||
bClosingDown = false;
|
||||
|
|
@ -1057,11 +1069,45 @@ void MainWindow::createCardUpdateProcess(bool background)
|
|||
if (!background) {
|
||||
cardUpdateProcess->start(updaterCmd, QStringList());
|
||||
} else {
|
||||
cardUpdateOutputBuffer.clear();
|
||||
connect(cardUpdateProcess, &QProcess::readyReadStandardOutput, this, &MainWindow::cardUpdateProgressOutput);
|
||||
cardUpdateProcess->start(updaterCmd, QStringList("-b"));
|
||||
statusBar()->showMessage(tr("Card database update running."));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::cardUpdateProgressOutput()
|
||||
{
|
||||
if (!cardUpdateProcess) {
|
||||
return;
|
||||
}
|
||||
cardUpdateOutputBuffer.append(cardUpdateProcess->readAllStandardOutput());
|
||||
while (true) {
|
||||
const int newline = cardUpdateOutputBuffer.indexOf('\n');
|
||||
if (newline < 0) {
|
||||
break;
|
||||
}
|
||||
const QByteArray line = cardUpdateOutputBuffer.left(newline).trimmed();
|
||||
cardUpdateOutputBuffer.remove(0, newline + 1);
|
||||
// Protocol emitted by `oracle -b`: "PROGRESS <stage> <done> <total>"
|
||||
if (!line.startsWith("PROGRESS ")) {
|
||||
continue;
|
||||
}
|
||||
const QList<QByteArray> parts = line.split(' ');
|
||||
if (parts.size() != 4) {
|
||||
continue;
|
||||
}
|
||||
bool doneOk = false;
|
||||
bool totalOk = false;
|
||||
const qint64 done = parts.at(2).toLongLong(&doneOk);
|
||||
const qint64 total = parts.at(3).toLongLong(&totalOk);
|
||||
if (!doneOk || !totalOk || done < 0 || total < 0) {
|
||||
continue;
|
||||
}
|
||||
emit cardDatabaseUpdateProgress(QString::fromLatin1(parts.at(1)), done, total);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::exitCardDatabaseUpdate()
|
||||
{
|
||||
if (!cardUpdateProcess) {
|
||||
|
|
@ -1109,6 +1155,8 @@ void MainWindow::cardUpdateError(QProcess::ProcessError err)
|
|||
|
||||
void MainWindow::cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
cardUpdateProgressOutput(); // drain any progress lines not yet parsed
|
||||
|
||||
const bool success = (exitStatus == QProcess::NormalExit) && (exitCode == 0);
|
||||
if (exitStatus == QProcess::NormalExit) {
|
||||
SettingsCache::instance().updates().setLastCardUpdateCheck(QDateTime::currentDateTime().date());
|
||||
|
|
|
|||
|
|
@ -68,6 +68,11 @@ signals:
|
|||
/** @brief Emitted after the background card-database update subprocess exits. */
|
||||
void cardDatabaseUpdateFinished(bool success);
|
||||
|
||||
/** @brief Emitted while the background card-database update subprocess runs.
|
||||
* @p stage is one of "download", "scan" or "import"; @p done/@p total
|
||||
* are byte counts for the first two stages and set indices for "import". */
|
||||
void cardDatabaseUpdateProgress(const QString &stage, qint64 done, qint64 total);
|
||||
|
||||
public slots:
|
||||
void actCheckCardUpdates();
|
||||
void actCheckCardUpdatesBackground();
|
||||
|
|
@ -96,6 +101,7 @@ private slots:
|
|||
|
||||
void cardUpdateError(QProcess::ProcessError err);
|
||||
void cardUpdateFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
void cardUpdateProgressOutput();
|
||||
void refreshShortcuts();
|
||||
void cardDatabaseLoadingFailed();
|
||||
void cardDatabaseNewSetsFound(int numUnknownSets, QStringList unknownSetsNames);
|
||||
|
|
@ -159,6 +165,7 @@ private:
|
|||
LatencyStatusWidget *latencyStatus = nullptr; ///< status bar widget with live round-trip stats and history graph
|
||||
bool bHasActivated, askedForDbUpdater;
|
||||
QProcess *cardUpdateProcess;
|
||||
QByteArray cardUpdateOutputBuffer;
|
||||
DlgViewLog *logviewDialog;
|
||||
GameReplay *replay;
|
||||
DlgTipOfTheDay *tip;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue