mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[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.
This commit is contained in:
parent
ada774f5cc
commit
c47dc578e0
15 changed files with 510 additions and 98 deletions
|
|
@ -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);
|
||||
|
||||
|
|
@ -1057,11 +1058,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 +1144,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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue