From b79fb62a0be0872a7b154283e4f18bb7a6c153a6 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Tue, 1 Oct 2024 20:12:24 +0200 Subject: [PATCH] Automatically determine current version from git tags --- .gitignore | 1 - src/QUAboutDialog.cpp | 5 ++--- src/QUMainWindow.cpp | 26 +++++++++++++------------- src/UltraStar-Manager.pro | 23 ++++++----------------- src/latest_version.xml | 1 - src/main.cpp | 5 ++--- src/main.h | 8 ++++---- 7 files changed, 27 insertions(+), 42 deletions(-) delete mode 100644 src/latest_version.xml diff --git a/.gitignore b/.gitignore index 65c036ca..bcbc555a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ *.stash *.user bin -src/version.h src/tmp src/*.autosave src/ui diff --git a/src/QUAboutDialog.cpp b/src/QUAboutDialog.cpp index 0cec992a..ac2d8f80 100644 --- a/src/QUAboutDialog.cpp +++ b/src/QUAboutDialog.cpp @@ -1,6 +1,5 @@ #include "QUAboutDialog.h" #include "main.h" -#include "version.h" #include #include #include @@ -107,10 +106,10 @@ QUAboutDialog::QUAboutDialog(QWidget *parent): QDialog(parent) { credits->setHtml(creditsText); - QDateTime dateTime = QDateTime::fromString(QString(date_time), "dd.MM.yyyy HH:mm"); + QDateTime dateTime = QDateTime::fromString(QString(xstr(DATE_TIME)), "dd.MM.yyyy HH:mm"); versionLbl->setText(QString(tr("Version: %1
Date: %2")) - .arg(QString(revision), dateTime.toString("yyyy-MM-dd, HH:mm"))); + .arg(QString(xstr(REVISION)), dateTime.toString("yyyy-MM-dd, HH:mm"))); resetText(); credits->document()->setDefaultStyleSheet("a {color: white}"); diff --git a/src/QUMainWindow.cpp b/src/QUMainWindow.cpp index 693ebdab..27458ae5 100644 --- a/src/QUMainWindow.cpp +++ b/src/QUMainWindow.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "QUSongItem.h" #include "QUDetailItem.h" @@ -993,9 +994,10 @@ void QUMainWindow::aboutMediaInfo() { } void QUMainWindow::checkForUpdate(bool silent) { - int currentVersion = MAJOR_VERSION*100 + MINOR_VERSION*10 + PATCH_VERSION; + QString currentVersion = QString(xstr(VERSION)); + int currentVersionNum = QString(currentVersion).remove('.').toInt(); - QUrl url("https://github.com/UltraStar-Deluxe/UltraStar-Manager/blob/master/src/latest_version.xml"); + QUrl url("https://api.github.com/repos/UltraStar-Deluxe/UltraStar-Manager/releases/latest"); QNetworkAccessManager *m_NetworkMngr = new QNetworkAccessManager(this); QNetworkReply *reply = m_NetworkMngr->get(QNetworkRequest(url)); @@ -1027,20 +1029,18 @@ void QUMainWindow::checkForUpdate(bool silent) { return; } - tmp.write(reply->readAll()); - tmp.seek(0); - QString line = QString(tmp.readLine()); + QJsonDocument json = QJsonDocument::fromJson(reply->readAll()); + QString line = json["tag_name"].toString(); QString latestVersionString = line; - int latestVersion = line.remove('.').toInt(); + int latestVersion = line.remove('.').remove('v').toInt(); delete reply; - tmp.remove(); - if (currentVersion < latestVersion) { + if (currentVersionNum < latestVersion) { QUMessageBox::information(this, tr("Update check successful."), - QString(tr("UltraStar Manager %1.%2.%3 is outdated.

" - "Download the most recent UltraStar-Manager %4 here.")) - .arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION) + QString(tr("UltraStar Manager %1 is outdated.

" + "Download the most recent UltraStar-Manager %2 here.")) + .arg(currentVersion) .arg(latestVersionString), BTN << ":/marks/accept.png" << "OK", 240); @@ -1051,8 +1051,8 @@ void QUMainWindow::checkForUpdate(bool silent) { QSettings settings; int result = QUMessageBox::information(this, tr("Update check successful."), - QString(tr("UltraStar Manager %1.%2.%3 is up to date!")) - .arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION), + QString(tr("UltraStar Manager %1 is up to date!")) + .arg(currentVersion), BTN << ":/marks/accept.png" << tr("OK. I will check again later.") << ":/marks/accept.png" << tr("OK. Check automatically on startup."), 240); diff --git a/src/UltraStar-Manager.pro b/src/UltraStar-Manager.pro index a3739d44..53adcc8e 100644 --- a/src/UltraStar-Manager.pro +++ b/src/UltraStar-Manager.pro @@ -241,6 +241,9 @@ INCLUDEPATH += . \ remoteimages \ webinfo +DEFINES += REVISION=$$system(git describe --always --tags --match "[0-9].[0-9].[0-9]") \ + VERSION=$$system(git describe --tags --abbrev=0 --match "[0-9].[0-9].[0-9]") + win32 { INCLUDEPATH += ../include/cld2/public \ ../include/taglib \ @@ -256,6 +259,8 @@ win32 { -lzlib RC_ICONS += UltraStar-Manager.ico + + DEFINES += DATE_TIME="$$system(date /T) $$system(time /T)" } macx { @@ -291,26 +296,10 @@ unix:!macx { QMAKE_LFLAGS += '-Wl,-rpath,\'\$$ORIGIN\'' } -QMAKE_EXTRA_TARGETS += revtarget -PRE_TARGETDEPS += version.h -revtarget.target = version.h - -win32 { - revtarget.commands = "$$system(echo 'const char *revision = \"$$system(git describe --always)\";' > $$revtarget.target)" - revtarget.commands += "$$system(echo 'const char *date_time = \"$$system(date /T) $$system(time /T)\";' >> $$revtarget.target)" -} - unix { -revtarget.commands = @echo \ - "const char *revision = \\\"`git describe --always`\\\"\\; \ - const char *date_time = \\\"`date +'%d.%m.%Y %H:%M'`\\\"\\;" \ - > $${PWD}/$$revtarget.target + DEFINES += DATE_TIME=\"$$quote($$system(date '+%d.%m.%Y\ %H:%M'))\" } -revtarget.depends = $$SOURCES \ - $$HEADERS \ - $$FORMS - unix:!macx { QMAKE_POST_LINK += $$sprintf($${QMAKE_MKDIR_CMD}, $$shell_path($${DESTDIR}/lib/)) $$escape_expand(\\n\\t) } diff --git a/src/latest_version.xml b/src/latest_version.xml deleted file mode 100644 index fe4e75fb..00000000 --- a/src/latest_version.xml +++ /dev/null @@ -1 +0,0 @@ -1.8.3 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index fdb378d2..99050587 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,8 +48,7 @@ int main(int argc, char *argv[]) { painter.drawText( 0, 0, 418, 130, Qt::AlignRight | Qt::AlignBottom, - QString("%1.%2").arg(MAJOR_VERSION).arg(MINOR_VERSION) - ); + QString(xstr(VERSION))); painter.end(); QSplashScreen splash(canvas); @@ -151,7 +150,7 @@ void initLanguage(QApplication &app, QTranslator &trContent, QTranslator &trQt, monty->initMessages(); - s.showMessage(QString(QObject::tr("%1.%2.%3 is loading...")).arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(PATCH_VERSION), Qt::AlignBottom | Qt::AlignRight, Qt::white); + s.showMessage(QString(QObject::tr("%1 is loading...")).arg(xstr(VERSION)), Qt::AlignBottom | Qt::AlignRight, Qt::white); // message needs to be here because it can be translated only after installing the translator if(!settingFound) diff --git a/src/main.h b/src/main.h index 23d15609..d661f787 100644 --- a/src/main.h +++ b/src/main.h @@ -1,12 +1,12 @@ #ifndef MAIN_H_ #define MAIN_H_ -#define MAJOR_VERSION 0x0001 -#define MINOR_VERSION 0x0009 -#define PATCH_VERSION 0x0000 - #define WIP_TEXT "" //" *work in progress* -> Please do not distribute." //#define WIP_VERSION //#define RC_VERSION +// Stringifiers needed to parse the VERSION preprocessor define as string +#define xstr(a) astr(a) +#define astr(a) #a + #endif /*MAIN_H_*/