Fix version checking

This commit is contained in:
luisangelsm
2026-03-30 20:17:05 +02:00
parent a8c936ee6f
commit 9dfc35527b

View File

@ -11,8 +11,6 @@
#include <QVersionNumber> #include <QVersionNumber>
#include <QtGlobal> #include <QtGlobal>
#define PREVIOUS_VERSION_TESTING "6.0.0"
HttpVersionChecker::HttpVersionChecker() HttpVersionChecker::HttpVersionChecker()
: HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/VERSION", DEFAULT_USER_AGENT) : HttpWorker("https://raw.githubusercontent.com/YACReader/yacreader/master/VERSION", DEFAULT_USER_AGENT)
{ {
@ -26,12 +24,17 @@ void HttpVersionChecker::checkNewVersion(const QByteArray &data)
bool HttpVersionChecker::checkNewVersion(QString sourceContent) bool HttpVersionChecker::checkNewVersion(QString sourceContent)
{ {
#ifdef QT_DEBUG
const auto currentVersion = QVersionNumber::fromString(PREVIOUS_VERSION_TESTING);
#else
const auto currentVersion = QVersionNumber::fromString(QString::fromLatin1(VERSION)); const auto currentVersion = QVersionNumber::fromString(QString::fromLatin1(VERSION));
#endif const auto trimmedSourceContent = sourceContent.trimmed();
const auto latestVersion = QVersionNumber::fromString(sourceContent.trimmed()); qsizetype suffixIndex = 0;
const auto latestVersion = QVersionNumber::fromString(trimmedSourceContent, &suffixIndex);
if (trimmedSourceContent.isEmpty() ||
suffixIndex != trimmedSourceContent.size() ||
latestVersion.segments().size() != 3) {
return false;
}
if (!currentVersion.isNull() && !latestVersion.isNull() && QVersionNumber::compare(latestVersion, currentVersion) > 0) { if (!currentVersion.isNull() && !latestVersion.isNull() && QVersionNumber::compare(latestVersion, currentVersion) > 0) {
emit newVersionDetected(); emit newVersionDetected();