mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Extract VERSION to avoid duplication
This commit is contained in:
@ -1,12 +1,23 @@
|
||||
# Common libraries for YACReader
|
||||
# Fine-grained STATIC targets per concern
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
# --- yr_global (no GUI, used by all 3 apps) ---
|
||||
add_library(yr_global STATIC
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.h
|
||||
version.h.in
|
||||
yacreader_global.h
|
||||
yacreader_global.cpp
|
||||
)
|
||||
target_include_directories(yr_global PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(yr_global PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
target_link_libraries(yr_global PUBLIC Qt::Core)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_compile_definitions(yr_global PRIVATE
|
||||
@ -171,6 +182,7 @@ target_link_libraries(rhi_flow_reader PUBLIC
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
yr_global
|
||||
)
|
||||
qt_add_shaders(rhi_flow_reader "flow_shaders_reader"
|
||||
BASE rhi/shaders
|
||||
@ -194,6 +206,7 @@ target_link_libraries(rhi_flow_library PUBLIC
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
yr_global
|
||||
)
|
||||
qt_add_shaders(rhi_flow_library "flow_shaders_library"
|
||||
BASE rhi/shaders
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
6
common/version.h.in
Normal file
6
common/version.h.in
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef YACREADER_VERSION_H
|
||||
#define YACREADER_VERSION_H
|
||||
|
||||
#define VERSION "@PROJECT_VERSION@"
|
||||
|
||||
#endif
|
||||
@ -9,7 +9,10 @@
|
||||
|
||||
class QLibrary;
|
||||
|
||||
#define VERSION "10.0.0"
|
||||
// Compatibility for already released apps that still parse this file for update checks.
|
||||
// TODO: remove after old releases have migrated away from scraping this header.
|
||||
// #define VERSION "10.0.0"
|
||||
#include "version.h"
|
||||
|
||||
// Used to check if the database needs to be updated, the version is stored in the database.
|
||||
// This value is only incremented when the database structure changes.
|
||||
|
||||
Reference in New Issue
Block a user