Resolved issue #667. Check for updates - Test version.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-02-06 13:38:05 +02:00
parent e56423905d
commit c56992407e
8 changed files with 80 additions and 20 deletions

View File

@ -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();
});

View File

@ -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();
});

View File

@ -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();

View File

@ -42,6 +42,7 @@
#include <QXmlStreamAttributes>
#include <QtDebug>
#include <QSslConfiguration>
#include <QDir>
#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> 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();
}

View File

@ -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);

View File

@ -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;

View File

@ -29,7 +29,7 @@
</font>
</property>
<property name="text">
<string>A new version of %1 is available!</string>
<string>%1 update is available!</string>
</property>
</widget>
</item>

View File

@ -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)
{