Extract VERSION to avoid duplication

This commit is contained in:
luisangelsm
2026-03-30 17:19:40 +02:00
parent 74aebffd9b
commit 79a8acbd42
9 changed files with 46 additions and 44 deletions

View File

@ -6,16 +6,15 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QRegExp>
#include <QStringList>
#include <QTimer>
#include <QUrl>
#include <QVersionNumber>
#include <QtGlobal>
#define PREVIOUS_VERSION_TESTING "6.0.0"
HttpVersionChecker::HttpVersionChecker()
: HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/common/yacreader_global.h", DEFAULT_USER_AGENT)
: HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/VERSION", DEFAULT_USER_AGENT)
{
connect(this, &HttpVersionChecker::dataReady, this, QOverload<const QByteArray &>::of(&HttpVersionChecker::checkNewVersion));
}
@ -27,39 +26,17 @@ void HttpVersionChecker::checkNewVersion(const QByteArray &data)
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{
QRegExp rx("#define VERSION \"([0-9]+).([0-9]+).([0-9]+)\"");
bool newVersion = false;
bool sameVersion = true;
// bool currentVersionIsNewer = false;
#ifdef QT_DEBUG
QString version(PREVIOUS_VERSION_TESTING);
const auto currentVersion = QVersionNumber::fromString(PREVIOUS_VERSION_TESTING);
#else
QString version(VERSION);
const auto currentVersion = QVersionNumber::fromString(QString::fromLatin1(VERSION));
#endif
QStringList sl = version.split(".");
if (rx.indexIn(sourceContent) != -1) {
int length = qMin(sl.size(), (rx.cap(4) != "") ? 4 : 3);
for (int i = 0; i < length; i++) {
if (rx.cap(i + 1).toInt() < sl.at(i).toInt()) {
return false;
}
if (rx.cap(i + 1).toInt() > sl.at(i).toInt()) {
newVersion = true;
break;
} else
sameVersion = sameVersion && rx.cap(i + 1).toInt() == sl.at(i).toInt();
}
if (!newVersion && sameVersion) {
if ((sl.size() == 3) && (rx.cap(4) != ""))
newVersion = true;
}
}
const auto latestVersion = QVersionNumber::fromString(sourceContent.trimmed());
if (newVersion == true) {
if (!currentVersion.isNull() && !latestVersion.isNull() && QVersionNumber::compare(latestVersion, currentVersion) > 0) {
emit newVersionDetected();
return true;
} else {
return false;
}
return false;
}