From c56992407eaa14682a085366a6d03082c17b18b8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 6 Feb 2018 13:38:05 +0200 Subject: [PATCH] Resolved issue #667. Check for updates - Test version. --HG-- branch : develop --- src/app/tape/dialogs/dialogabouttape.cpp | 2 +- src/app/valentina/dialogs/dialogaboutapp.cpp | 2 +- src/app/valentina/main.cpp | 6 +- src/libs/fervor/fvupdater.cpp | 65 +++++++++++++++++--- src/libs/fervor/fvupdater.h | 5 +- src/libs/fervor/fvupdatewindow.cpp | 15 ++++- src/libs/fervor/fvupdatewindow.ui | 2 +- src/libs/ifc/xml/vabstractconverter.cpp | 3 +- 8 files changed, 80 insertions(+), 20 deletions(-) diff --git a/src/app/tape/dialogs/dialogabouttape.cpp b/src/app/tape/dialogs/dialogabouttape.cpp index 48aa408ba..d5250c218 100644 --- a/src/app/tape/dialogs/dialogabouttape.cpp +++ b/src/app/tape/dialogs/dialogabouttape.cpp @@ -61,7 +61,7 @@ DialogAboutTape::DialogAboutTape(QWidget *parent) connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []() { // Set feed URL before doing anything else - FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); + FvUpdater::sharedUpdater()->SetFeedURL(FvUpdater::CurrentFeedURL()); FvUpdater::sharedUpdater()->CheckForUpdatesNotSilent(); }); diff --git a/src/app/valentina/dialogs/dialogaboutapp.cpp b/src/app/valentina/dialogs/dialogaboutapp.cpp index ad608fb3a..3ea792c8d 100644 --- a/src/app/valentina/dialogs/dialogaboutapp.cpp +++ b/src/app/valentina/dialogs/dialogaboutapp.cpp @@ -72,7 +72,7 @@ DialogAboutApp::DialogAboutApp(QWidget *parent) : connect(ui->pushButtonCheckUpdate, &QPushButton::clicked, []() { // Set feed URL before doing anything else - FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); + FvUpdater::sharedUpdater()->SetFeedURL(FvUpdater::CurrentFeedURL()); FvUpdater::sharedUpdater()->CheckForUpdatesNotSilent(); }); diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index d9201f3b6..6c5b5ab57 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -64,12 +64,12 @@ int main(int argc, char *argv[]) app.InitOptions(); // Due to unknown reasons version checker cause a crash. See issue #633. - // Before we will find what cause such crashes it will stay disabled in Release mode. -#ifndef V_NO_ASSERT + // Before we will find what cause such crashes it will stay disabled in Release mode on Mac OS. +#if !defined(Q_OS_MAC) || !defined(V_NO_ASSERT) if (VApplication::IsGUIMode()) { // Set feed URL before doing anything else - FvUpdater::sharedUpdater()->SetFeedURL(defaultFeedURL); + FvUpdater::sharedUpdater()->SetFeedURL(FvUpdater::CurrentFeedURL()); // Check for updates automatically FvUpdater::sharedUpdater()->CheckForUpdatesSilent(); diff --git a/src/libs/fervor/fvupdater.cpp b/src/libs/fervor/fvupdater.cpp index 3c325d74f..d5d4c6317 100644 --- a/src/libs/fervor/fvupdater.cpp +++ b/src/libs/fervor/fvupdater.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "../ifc/exception/vexception.h" #include "../ifc/xml/vabstractconverter.h" @@ -51,7 +52,11 @@ #include "fvavailableupdate.h" #include "fvupdatewindow.h" +namespace +{ const QString defaultFeedURL = QStringLiteral("https://valentinaproject.bitbucket.io/Appcast.xml"); +const QString testFeedURL = QStringLiteral("https://valentinaproject.bitbucket.io/Appcast_testing.xml"); +} QPointer FvUpdater::m_Instance; @@ -78,6 +83,52 @@ void FvUpdater::drop() mutex.unlock(); } +//--------------------------------------------------------------------------------------------------------------------- +QString FvUpdater::CurrentFeedURL() +{ + return FvUpdater::IsTestBuild() ? testFeedURL : defaultFeedURL; +} + +//--------------------------------------------------------------------------------------------------------------------- +int FvUpdater::CurrentVersion() +{ +#ifdef Q_OS_MAC + const QString path = QCoreApplication::applicationDirPath() + QLatin1String("/../Resources/VERSION"); +#else + const QString path = QApplication::applicationDirPath() + QDir::separator() + QLatin1String("VERSION"); +#endif + + QFile file(path); + if (file.exists()) + { + if (not file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + return APP_VERSION; + } + + QTextStream in(&file); + try + { + return VAbstractConverter::GetVersion(in.read(15)); + } + catch(const VException &) + { + return APP_VERSION; + } + } + else + { + return APP_VERSION; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool FvUpdater::IsTestBuild() +{ + const int version = FvUpdater::CurrentVersion(); + return (version != 0x0 && version != APP_VERSION); +} + //--------------------------------------------------------------------------------------------------------------------- FvUpdater::FvUpdater() : QObject(nullptr), @@ -110,7 +161,7 @@ void FvUpdater::showUpdaterWindowUpdatedWithCurrentUpdateProposal() // Create a new window m_updaterWindow = new FvUpdateWindow(qApp->getMainWindow()); m_updaterWindow->UpdateWindowWithCurrentProposedUpdate(); - m_updaterWindow->show(); + m_updaterWindow->exec(); } //--------------------------------------------------------------------------------------------------------------------- @@ -521,7 +572,7 @@ bool FvUpdater::VersionIsIgnored(const QString &version) return true; // Ignore invalid version } - if (decVersion == APP_VERSION) + if (decVersion == FvUpdater::CurrentVersion()) { return true; } @@ -536,7 +587,7 @@ bool FvUpdater::VersionIsIgnored(const QString &version) } } - if (decVersion > APP_VERSION) + if (decVersion > FvUpdater::CurrentVersion()) { // Newer version - do not skip return false; @@ -560,7 +611,7 @@ void FvUpdater::IgnoreVersion(const QString &version) return ; // Ignore invalid version } - if (decVersion == APP_VERSION) + if (decVersion == FvUpdater::CurrentVersion()) { // Don't ignore the current version return; @@ -618,8 +669,7 @@ void FvUpdater::showErrorDialog(const QString &message, bool showEvenInSilentMod QMessageBox dlFailedMsgBox; dlFailedMsgBox.setIcon(QMessageBox::Critical); - dlFailedMsgBox.setText(tr("Error")); - dlFailedMsgBox.setInformativeText(message); + dlFailedMsgBox.setText(message); dlFailedMsgBox.exec(); } @@ -637,7 +687,6 @@ void FvUpdater::showInformationDialog(const QString &message, bool showEvenInSil QMessageBox dlInformationMsgBox; dlInformationMsgBox.setIcon(QMessageBox::Information); - dlInformationMsgBox.setText(tr("Information")); - dlInformationMsgBox.setInformativeText(message); + dlInformationMsgBox.setText(message); dlInformationMsgBox.exec(); } diff --git a/src/libs/fervor/fvupdater.h b/src/libs/fervor/fvupdater.h index da57bea3f..f02696a19 100644 --- a/src/libs/fervor/fvupdater.h +++ b/src/libs/fervor/fvupdater.h @@ -35,8 +35,6 @@ #include "fvavailableupdate.h" #include "fvupdatewindow.h" -extern const QString defaultFeedURL; - class FvUpdater : public QObject { Q_OBJECT @@ -45,6 +43,9 @@ public: // Singleton static FvUpdater* sharedUpdater(); static void drop(); + static QString CurrentFeedURL(); + static int CurrentVersion(); + static bool IsTestBuild(); // Set / get feed URL void SetFeedURL(const QUrl &feedURL); diff --git a/src/libs/fervor/fvupdatewindow.cpp b/src/libs/fervor/fvupdatewindow.cpp index 241a52226..d51b9c14a 100644 --- a/src/libs/fervor/fvupdatewindow.cpp +++ b/src/libs/fervor/fvupdatewindow.cpp @@ -67,9 +67,18 @@ bool FvUpdateWindow::UpdateWindowWithCurrentProposedUpdate() return false; } - const QString downloadString = m_ui->wouldYouLikeToDownloadLabel->text() - .arg(QGuiApplication::applicationDisplayName(), proposedUpdate->GetEnclosureVersion(), - QCoreApplication::applicationVersion()); + QString downloadString; + if (FvUpdater::IsTestBuild()) + { + downloadString = QString("New %1 test build is now available. Would you like to download it now?") + .arg(QGuiApplication::applicationDisplayName()); + } + else + { + downloadString = m_ui->wouldYouLikeToDownloadLabel->text() + .arg(QGuiApplication::applicationDisplayName(), proposedUpdate->GetEnclosureVersion(), + QCoreApplication::applicationVersion()); + } m_ui->wouldYouLikeToDownloadLabel->setText(downloadString); return true; diff --git a/src/libs/fervor/fvupdatewindow.ui b/src/libs/fervor/fvupdatewindow.ui index da38a53f5..d5f6f6e58 100644 --- a/src/libs/fervor/fvupdatewindow.ui +++ b/src/libs/fervor/fvupdatewindow.ui @@ -29,7 +29,7 @@ - A new version of %1 is available! + %1 update is available! diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index cf01259e5..eb3657c5a 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -154,7 +154,8 @@ int VAbstractConverter::GetVersion(const QString &version) //--------------------------------------------------------------------------------------------------------------------- void VAbstractConverter::ValidateVersion(const QString &version) { - const QRegularExpression rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$")); + const QRegularExpression rx(QStringLiteral("^([0-9]|[1-9][0-9]|[1-2][0-5][0-5]).([0-9]|[1-9][0-9]|[1-2][0-5][0-5])" + ".([0-9]|[1-9][0-9]|[1-2][0-5][0-5])$")); if (rx.match(version).hasMatch() == false) {