Cockatrice/oracle/src/main.cpp
BruebachL 96b0888a73
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
[Oracle] Don't report a cancelled card database update as successful (#7082)
* [Oracle] Don't report a cancelled card database update as successful (#3470)

Took 3 minutes

* [Oracle] Only report cancel when nothing was saved yet

Rejecting the wizard after SaveSetsPage or a download page already
wrote the database to disk still replaced cards.xml on disk, but
wasCancelled() forced exit code 1 so Cockatrice skipped the reload.
Track successful saves with OracleWizard::markDatabaseSaved() and only
treat a cancel as a failure when nothing was saved.

* [Oracle] Restore updater stderr in card update error dialog

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-15 15:21:07 +02:00

92 lines
3.3 KiB
C++

#include "main.h"
#include "interface/theme_manager.h"
#include "oraclewizard.h"
#include <../../cockatrice/src/client/settings/cache_settings.h>
#include <QApplication>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QIcon>
#include <QString>
#include <QTimer>
#include <QTranslator>
#include <libcockatrice/settings/personal_settings.h>
#include <libcockatrice/utility/translation_loader.h>
QTranslator *translator, *qtTranslator;
ThemeManager *themeManager;
const QString translationPrefix = "oracle";
QString translationPath;
bool isSpoilersOnly;
bool isBackgrounded;
void installNewTranslator()
{
QString lang = SettingsCache::instance().personal().getLang();
// Qt's own strings and ours need a translator each: QTranslator discards its previous contents
// on every load, so loading both files into one translator silently drops the first of them.
TranslationLoader::loadQt(*qtTranslator, lang);
qApp->installTranslator(qtTranslator);
TranslationLoader::loadApplication(*translator, translationPrefix, lang,
TranslationLoader::applicationTranslationPaths(translationPath));
qApp->installTranslator(translator);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QCoreApplication::setOrganizationName("Cockatrice");
QCoreApplication::setOrganizationDomain("Cockatrice");
// This can't be changed, as it influences the default save path for cards.xml
QCoreApplication::setApplicationName("Cockatrice");
// If the program is opened with the -s flag, it will only do spoilers. Otherwise it will do MTGJSON/Tokens
QCommandLineParser parser;
QCommandLineOption spoilersOnlyOption("s", QCoreApplication::translate("main", "Only run in spoiler mode"));
QCommandLineOption backgroundOption("b", QCoreApplication::translate("main", "Run in no-confirm background mode"));
parser.addOption(spoilersOnlyOption);
parser.addOption(backgroundOption);
parser.process(app);
isSpoilersOnly = parser.isSet(spoilersOnlyOption);
isBackgrounded = parser.isSet(backgroundOption);
#ifdef Q_OS_MAC
translationPath = qApp->applicationDirPath() + "/../Resources/translations";
#elif defined(Q_OS_WIN)
translationPath = qApp->applicationDirPath() + "/translations";
#else // linux
translationPath = qApp->applicationDirPath() + "/../share/oracle/translations";
#endif
themeManager = new ThemeManager;
qtTranslator = new QTranslator;
translator = new QTranslator;
installNewTranslator();
OracleWizard wizard;
QIcon icon("theme:appicon.svg");
wizard.setWindowIcon(icon);
// Base name of the installed oracle.desktop; wayland reads the window icon from it and
// xdg-desktop-portal registers it as the app ID, so the case has to match the file name.
QGuiApplication::setDesktopFileName("oracle");
wizard.show();
if (isBackgrounded) {
QTimer::singleShot(0, &wizard, [&wizard]() { wizard.runInBackground(); });
}
const int execResult = app.exec();
// A cancel only counts when nothing was written yet: closing the wizard
// after the card database was already saved on disk is still an update.
return (wizard.wasCancelled() && !wizard.hasSavedDatabase()) ? 1 : execResult;
}