mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Use QVersionNumber for Version Comparison
This commit is contained in:
parent
a3e4daecca
commit
9f582b3e03
@ -39,8 +39,8 @@ int main(int argc, char *argv[])
|
|||||||
if (Config()->getAutoUpdateEnabled()) {
|
if (Config()->getAutoUpdateEnabled()) {
|
||||||
UpdateWorker *updateWorker = new UpdateWorker;
|
UpdateWorker *updateWorker = new UpdateWorker;
|
||||||
QObject::connect(updateWorker, &UpdateWorker::checkComplete,
|
QObject::connect(updateWorker, &UpdateWorker::checkComplete,
|
||||||
[=](const QString & version, const QString & error) {
|
[=](const QVersionNumber &version, const QString & error) {
|
||||||
if (error == "" && version != CUTTER_VERSION_FULL) {
|
if (error == "" && version > UpdateWorker::currentVersionNumber()) {
|
||||||
updateWorker->showUpdateDialog(true);
|
updateWorker->showUpdateDialog(true);
|
||||||
}
|
}
|
||||||
updateWorker->deleteLater();
|
updateWorker->deleteLater();
|
||||||
|
@ -20,15 +20,15 @@
|
|||||||
#include "CutterConfig.h"
|
#include "CutterConfig.h"
|
||||||
|
|
||||||
UpdateWorker::UpdateWorker(QObject *parent) :
|
UpdateWorker::UpdateWorker(QObject *parent) :
|
||||||
QObject(parent), latestVersion(""), pending(false)
|
QObject(parent), pending(false)
|
||||||
{
|
{
|
||||||
connect(&t, &QTimer::timeout, [this]() {
|
connect(&t, &QTimer::timeout, [this]() {
|
||||||
if (pending) {
|
if (pending) {
|
||||||
disconnect(checkReply, nullptr, this, nullptr);
|
disconnect(checkReply, nullptr, this, nullptr);
|
||||||
checkReply->close();
|
checkReply->close();
|
||||||
checkReply->deleteLater();
|
checkReply->deleteLater();
|
||||||
emit checkComplete("", tr("Time limit exceeded during version check. Please check your "
|
emit checkComplete(QVersionNumber(), tr("Time limit exceeded during version check. Please check your "
|
||||||
"internet connection and try again."));
|
"internet connection and try again."));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -73,10 +73,10 @@ void UpdateWorker::showUpdateDialog(bool showDontCheckForUpdatesButton)
|
|||||||
mb.setWindowTitle(tr("Version control"));
|
mb.setWindowTitle(tr("Version control"));
|
||||||
mb.setText(tr("There is an update available for Cutter.<br/>")
|
mb.setText(tr("There is an update available for Cutter.<br/>")
|
||||||
+ "<b>" + tr("Current version:") + "</b> " CUTTER_VERSION_FULL "<br/>"
|
+ "<b>" + tr("Current version:") + "</b> " CUTTER_VERSION_FULL "<br/>"
|
||||||
+ "<b>" + tr("Latest version:") + "</b> " + latestVersion + "<br/><br/>"
|
+ "<b>" + tr("Latest version:") + "</b> " + latestVersion.toString() + "<br/><br/>"
|
||||||
+ tr("For update, please check the link:<br/>")
|
+ tr("For update, please check the link:<br/>")
|
||||||
+ QString("<a href=\"https://github.com/radareorg/cutter/releases/tag/v%1\">"
|
+ QString("<a href=\"https://github.com/radareorg/cutter/releases/tag/v%1\">"
|
||||||
"https://github.com/radareorg/cutter/releases/tag/v%1</a><br/>").arg(latestVersion)
|
"https://github.com/radareorg/cutter/releases/tag/v%1</a><br/>").arg(latestVersion.toString())
|
||||||
+ tr("or click \"Download\" to download latest version of Cutter."));
|
+ tr("or click \"Download\" to download latest version of Cutter."));
|
||||||
if (showDontCheckForUpdatesButton) {
|
if (showDontCheckForUpdatesButton) {
|
||||||
mb.setStandardButtons(QMessageBox::Save | QMessageBox::Reset | QMessageBox::Ok);
|
mb.setStandardButtons(QMessageBox::Save | QMessageBox::Reset | QMessageBox::Ok);
|
||||||
@ -126,7 +126,7 @@ void UpdateWorker::showUpdateDialog(bool showDontCheckForUpdatesButton)
|
|||||||
QDesktopServices::openUrl(path.join('/'));
|
QDesktopServices::openUrl(path.join('/'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
download(fullFileName, latestVersion);
|
download(fullFileName, latestVersion.toString());
|
||||||
// Calling show() before exec() is only way make dialog non-modal
|
// Calling show() before exec() is only way make dialog non-modal
|
||||||
// it seems wierd, but it works
|
// it seems wierd, but it works
|
||||||
progressDial.show();
|
progressDial.show();
|
||||||
@ -149,15 +149,18 @@ void UpdateWorker::abortDownload()
|
|||||||
void UpdateWorker::serveVersionCheckReply()
|
void UpdateWorker::serveVersionCheckReply()
|
||||||
{
|
{
|
||||||
pending = false;
|
pending = false;
|
||||||
QString versionReply = "";
|
QString versionReplyStr = "";
|
||||||
QString errStr = "";
|
QString errStr = "";
|
||||||
if (checkReply->error()) {
|
if (checkReply->error()) {
|
||||||
errStr = checkReply->errorString();
|
errStr = checkReply->errorString();
|
||||||
} else {
|
} else {
|
||||||
versionReply = QJsonDocument::fromJson(checkReply->readAll()).object().value("tag_name").toString();
|
versionReplyStr = QJsonDocument::fromJson(checkReply->readAll()).object().value("tag_name").toString();
|
||||||
versionReply.remove('v');
|
versionReplyStr.remove('v');
|
||||||
|
}
|
||||||
|
QVersionNumber versionReply = QVersionNumber::fromString(versionReplyStr);
|
||||||
|
if (!versionReply.isNull()) {
|
||||||
|
latestVersion = versionReply;
|
||||||
}
|
}
|
||||||
latestVersion = versionReply;
|
|
||||||
checkReply->close();
|
checkReply->close();
|
||||||
checkReply->deleteLater();
|
checkReply->deleteLater();
|
||||||
emit checkComplete(versionReply, errStr);
|
emit checkComplete(versionReply, errStr);
|
||||||
@ -202,10 +205,15 @@ QString UpdateWorker::getRepositoryFileName() const
|
|||||||
downloadFileName = "Cutter-v%1-x%2.macOS.dmg";
|
downloadFileName = "Cutter-v%1-x%2.macOS.dmg";
|
||||||
#endif
|
#endif
|
||||||
downloadFileName = downloadFileName
|
downloadFileName = downloadFileName
|
||||||
.arg(latestVersion)
|
.arg(latestVersion.toString())
|
||||||
.arg(QSysInfo::buildAbi().split('-').at(2).contains("64")
|
.arg(QSysInfo::buildAbi().split('-').at(2).contains("64")
|
||||||
? "64"
|
? "64"
|
||||||
: "32");
|
: "32");
|
||||||
|
|
||||||
return downloadFileName;
|
return downloadFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVersionNumber UpdateWorker::currentVersionNumber()
|
||||||
|
{
|
||||||
|
return QVersionNumber(CUTTER_VERSION_MAJOR, CUTTER_VERSION_MINOR, CUTTER_VERSION_PATCH);
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtNetwork/QNetworkAccessManager>
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
|
#include <QVersionNumber>
|
||||||
|
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
|
|
||||||
@ -54,6 +55,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void showUpdateDialog(bool showDontCheckForUpdatesButton);
|
void showUpdateDialog(bool showDontCheckForUpdatesButton);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the version of this Cutter binary, derived from CUTTER_VERSION_MAJOR, CUTTER_VERSION_MINOR and CUTTER_VERSION_PATCH.
|
||||||
|
*/
|
||||||
|
static QVersionNumber currentVersionNumber();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @fn void UpdateWorker::abortDownload()
|
* @fn void UpdateWorker::abortDownload()
|
||||||
@ -71,10 +77,10 @@ signals:
|
|||||||
* @fn UpdateWorker::checkComplete(const QString& verson, const QString& errorMsg)
|
* @fn UpdateWorker::checkComplete(const QString& verson, const QString& errorMsg)
|
||||||
*
|
*
|
||||||
* The signal is emitted when check has been done with an empty @a errorMsg string.
|
* The signal is emitted when check has been done with an empty @a errorMsg string.
|
||||||
* In case of an error @a currVerson is empty and @a errorMsg contains description
|
* In case of an error @a currVerson is null and @a errorMsg contains description
|
||||||
* of error.
|
* of error.
|
||||||
*/
|
*/
|
||||||
void checkComplete(const QString &currVerson, const QString &errorMsg);
|
void checkComplete(const QVersionNumber &currVerson, const QString &errorMsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UpdateWorker::downloadProcess(size_t bytesReceived, size_t bytesTotal)
|
* @fn UpdateWorker::downloadProcess(size_t bytesReceived, size_t bytesTotal)
|
||||||
@ -112,7 +118,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager nm;
|
QNetworkAccessManager nm;
|
||||||
QString latestVersion;
|
QVersionNumber latestVersion;
|
||||||
QTimer t;
|
QTimer t;
|
||||||
bool pending;
|
bool pending;
|
||||||
QFile downloadFile;
|
QFile downloadFile;
|
||||||
|
@ -91,11 +91,11 @@ void AboutDialog::on_checkForUpdatesButton_clicked()
|
|||||||
|
|
||||||
connect(&updateWorker, &UpdateWorker::checkComplete, &waitDialog, &QProgressDialog::cancel);
|
connect(&updateWorker, &UpdateWorker::checkComplete, &waitDialog, &QProgressDialog::cancel);
|
||||||
connect(&updateWorker, &UpdateWorker::checkComplete,
|
connect(&updateWorker, &UpdateWorker::checkComplete,
|
||||||
[&updateWorker](const QString & version, const QString & error) {
|
[&updateWorker](const QVersionNumber &version, const QString & error) {
|
||||||
if (error != "") {
|
if (error != "") {
|
||||||
QMessageBox::critical(nullptr, tr("Error!"), error);
|
QMessageBox::critical(nullptr, tr("Error!"), error);
|
||||||
} else {
|
} else {
|
||||||
if (version == CUTTER_VERSION_FULL) {
|
if (version <= UpdateWorker::currentVersionNumber()) {
|
||||||
QMessageBox::information(nullptr, tr("Version control"), tr("Cutter is up to date!"));
|
QMessageBox::information(nullptr, tr("Version control"), tr("Cutter is up to date!"));
|
||||||
} else {
|
} else {
|
||||||
updateWorker.showUpdateDialog(false);
|
updateWorker.showUpdateDialog(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user