From 41bfbf2e83d2932617e4e967bce4b5e8b847e095 Mon Sep 17 00:00:00 2001 From: Zach H Date: Mon, 14 Jan 2019 01:11:05 -0500 Subject: [PATCH] Force Oracle run on new install/update (#3497) * Force Oracle run on new install/update Signed-off-by: Zach Halpern * Add settings option to disable such a check Signed-off-by: Zach Halpern --- cockatrice/src/dlg_settings.cpp | 6 +++++- cockatrice/src/dlg_settings.h | 1 + cockatrice/src/settingscache.cpp | 14 ++++++++++++++ cockatrice/src/settingscache.h | 12 ++++++++++++ cockatrice/src/window_main.cpp | 32 ++++++++++++++++++++++++++++---- cockatrice/src/window_main.h | 15 +++++++++++++++ 6 files changed, 75 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index f184da69..6b0e8497 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -53,6 +53,7 @@ GeneralSettingsPage::GeneralSettingsPage() updateReleaseChannelBox.setCurrentIndex(settingsCache->getUpdateReleaseChannel()->getIndex()); updateNotificationCheckBox.setChecked(settingsCache->getNotifyAboutUpdates()); + newVersionOracleCheckBox.setChecked(settingsCache->getNotifyAboutNewVersion()); // pixmap cache pixmapCacheEdit.setMinimum(PIXMAPCACHE_SIZE_MIN); @@ -69,6 +70,7 @@ GeneralSettingsPage::GeneralSettingsPage() connect(&updateReleaseChannelBox, SIGNAL(currentIndexChanged(int)), settingsCache, SLOT(setUpdateReleaseChannel(int))); connect(&updateNotificationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotifyAboutUpdate(int))); + connect(&newVersionOracleCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setNotifyAboutNewVersion(int))); connect(&showTipsOnStartup, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool))); auto *personalGrid = new QGridLayout; @@ -79,7 +81,8 @@ GeneralSettingsPage::GeneralSettingsPage() personalGrid->addWidget(&pixmapCacheLabel, 2, 0); personalGrid->addWidget(&pixmapCacheEdit, 2, 1); personalGrid->addWidget(&updateNotificationCheckBox, 3, 0); - personalGrid->addWidget(&showTipsOnStartup, 4, 0); + personalGrid->addWidget(&newVersionOracleCheckBox, 4, 0); + personalGrid->addWidget(&showTipsOnStartup, 5, 0); personalGroupBox = new QGroupBox; personalGroupBox->setLayout(personalGrid); @@ -242,6 +245,7 @@ void GeneralSettingsPage::retranslateUi() pixmapCacheLabel.setText(tr("Picture cache size:")); updateReleaseChannelLabel.setText(tr("Update channel")); updateNotificationCheckBox.setText(tr("Notify if a feature supported by the server is missing in my client")); + newVersionOracleCheckBox.setText(tr("Automatically run Oracle when running a new version of Cockatrice")); showTipsOnStartup.setText(tr("Show tips on startup")); } diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 6dc44e12..479e6677 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -60,6 +60,7 @@ private: QGroupBox *pathsGroupBox; QComboBox languageBox; QCheckBox updateNotificationCheckBox; + QCheckBox newVersionOracleCheckBox; QComboBox updateReleaseChannelBox; QLabel languageLabel; QLabel pixmapCacheLabel; diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 8586da97..393b014d 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -177,6 +177,7 @@ SettingsCache::SettingsCache() mbDownloadSpoilers = settings->value("personal/downloadspoilers", false).toBool(); notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool(); + notifyAboutNewVersion = settings->value("personal/newversionnotification", true).toBool(); updateReleaseChannel = settings->value("personal/updatereleasechannel", 0).toInt(); lang = settings->value("personal/lang").toString(); @@ -275,6 +276,7 @@ SettingsCache::SettingsCache() spectatorsCanSeeEverything = settings->value("game/spectatorscanseeeverything", false).toBool(); rememberGameSettings = settings->value("game/remembergamesettings", true).toBool(); clientID = settings->value("personal/clientid", "notset").toString(); + clientVersion = settings->value("personal/clientversion", "notset").toString(); knownMissingFeatures = settings->value("interface/knownmissingfeatures", "").toString(); } @@ -589,6 +591,12 @@ void SettingsCache::setClientID(QString _clientID) settings->setValue("personal/clientid", clientID); } +void SettingsCache::setClientVersion(QString _clientVersion) +{ + clientVersion = std::move(_clientVersion); + settings->setValue("personal/clientversion", clientVersion); +} + QStringList SettingsCache::getCountries() const { static QStringList countries = QStringList() << "ad" @@ -910,6 +918,12 @@ void SettingsCache::setNotifyAboutUpdate(int _notifyaboutupdate) settings->setValue("personal/updatenotification", notifyAboutUpdates); } +void SettingsCache::setNotifyAboutNewVersion(int _notifyaboutnewversion) +{ + notifyAboutNewVersion = static_cast(_notifyaboutnewversion); + settings->setValue("personal/newversionnotification", notifyAboutNewVersion); +} + void SettingsCache::setDownloadSpoilerStatus(bool _spoilerStatus) { mbDownloadSpoilers = _spoilerStatus; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 34421fcf..0dca177f 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -66,6 +66,7 @@ private: QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, spoilerDatabasePath, tokenDatabasePath, themeName; bool notifyAboutUpdates; + bool notifyAboutNewVersion; bool showTipsOnStartup; QList seenTips; bool mbDownloadSpoilers; @@ -97,6 +98,7 @@ private: QString picUrl; QString picUrlFallback; QString clientID; + QString clientVersion; QString knownMissingFeatures; int pixmapCacheSize; bool scaleCards; @@ -200,6 +202,10 @@ public: { return notifyAboutUpdates; } + bool getNotifyAboutNewVersion() const + { + return notifyAboutNewVersion; + } bool getShowTipsOnStartup() const { return showTipsOnStartup; @@ -387,11 +393,16 @@ public: return maxFontSize; } void setClientID(QString clientID); + void setClientVersion(QString clientVersion); void setKnownMissingFeatures(QString _knownMissingFeatures); QString getClientID() { return clientID; } + QString getClientVersion() + { + return clientVersion; + } QString getKnownMissingFeatures() { return knownMissingFeatures; @@ -492,6 +503,7 @@ public slots: void setSpectatorsCanSeeEverything(const bool _spectatorsCanSeeEverything); void setRememberGameSettings(const bool _rememberGameSettings); void setNotifyAboutUpdate(int _notifyaboutupdate); + void setNotifyAboutNewVersion(int _notifyaboutnewversion); void setUpdateReleaseChannel(int _updateReleaseChannel); void setMaxFontSize(int _max); }; diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index bdca76c9..657ddc61 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -317,9 +317,9 @@ void MainWindow::actAbout() void MainWindow::actTips() { - if (tip != NULL) { + if (tip != nullptr) { delete tip; - tip = NULL; + tip = nullptr; } tip = new DlgTipOfTheDay(); if (tip->successfulInit) { @@ -828,13 +828,30 @@ MainWindow::MainWindow(QWidget *parent) if (tip->successfulInit && settingsCache->getShowTipsOnStartup() && tip->newTipsAvailable) { tip->show(); } + + // Only run the check updater if the user wants it (defaults to on) + if (settingsCache->getNotifyAboutNewVersion()) { + auto versionUpdater = new MainUpdateHelper(); + connect(versionUpdater, SIGNAL(newVersionDetected(QString)), this, SLOT(alertForcedOracleRun(QString))); + QtConcurrent::run(versionUpdater, &MainUpdateHelper::testForNewVersion); + } +} + +void MainWindow::alertForcedOracleRun(const QString &newVersion) +{ + settingsCache->setClientVersion(newVersion); + QMessageBox::information(this, tr("New Version"), + tr("Congratulations on updating to Cockatrice %1!\n" + "Oracle will now launch to update your card database.") + .arg(newVersion)); + actCheckCardUpdates(); } MainWindow::~MainWindow() { - if (tip != NULL) { + if (tip != nullptr) { delete tip; - tip = NULL; + tip = nullptr; } if (trayIcon) { trayIcon->hide(); @@ -1271,3 +1288,10 @@ void MainWindow::promptForgotPasswordReset() dlg.getPlayerName(), dlg.getToken(), dlg.getPassword()); } } + +void MainUpdateHelper::testForNewVersion() +{ + if (settingsCache->getClientVersion() != VERSION_STRING) { + emit newVersionDetected(VERSION_STRING); + } +} diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index d6c7238b..68067924 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -101,6 +101,8 @@ private slots: void actManageSets(); void actEditTokens(); + void alertForcedOracleRun(const QString &); + private: static const QString appName; static const QStringList fileNameFilters; @@ -146,4 +148,17 @@ protected: QString extractInvalidUsernameMessage(QString &in); }; +class MainUpdateHelper : public QObject +{ + Q_OBJECT + +signals: + void newVersionDetected(QString); + +public: + explicit MainUpdateHelper() = default; + ~MainUpdateHelper() override = default; + void testForNewVersion(); +}; + #endif