From d943f2d89abe67f1847dc842b6ded0c5cadeb1ee Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Fri, 31 Oct 2025 14:47:27 +0100 Subject: [PATCH] Added checking for update and triggering the updater. --- CMakeLists.txt | 1 + constants.h | 15 ++++++++++++ genericcore.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ genericcore.h | 15 +++++++++++- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 constants.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d922ce0..9256626 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(${TARGET_APP} STATIC genericcore.cpp genericcore.h ${TS_FILES} + constants.h ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/constants.h b/constants.h new file mode 100644 index 0000000..b9ebc8a --- /dev/null +++ b/constants.h @@ -0,0 +1,15 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H + +#include + +/// Platform dependent +#ifdef Q_OS_LINUX +static const QString UPDATER_EXE = "maintenancetool"; +#elif defined(Q_OS_MAC) +static const QString UPDATER_EXE = "maintenancetool.app/Contents/MacOS/maintenancetool"; +#elif defined(Q_OS_WIN) +static const QString UPDATER_EXE = "maintenancetool.exe"; +#endif + +#endif // CONSTANTS_H diff --git a/genericcore.cpp b/genericcore.cpp index f296c21..7d5daed 100644 --- a/genericcore.cpp +++ b/genericcore.cpp @@ -1,9 +1,14 @@ #include "genericcore.h" +#include +#include #include +#include +#include #include #include "CoreConfig.h" +#include "constants.h" using namespace std; @@ -16,3 +21,60 @@ QString GenericCore::toString() const { } void GenericCore::sayHello() const { qDebug() << "Hello from the core!"; } + +bool GenericCore::isApplicationUpdateAvailable() { + QProcess process; + const QString programmString = getMaintenanceToolFilePath(); + const QStringList checkArgs("--checkupdates"); + process.start(programmString, checkArgs); + process.waitForFinished(); + + const int exitCode = process.exitCode(); + if (process.error() != QProcess::UnknownError) { + qDebug() << "Error checking for updates"; + emit displayStatusMessage("Error checking for updates"); + return false; + } + + QByteArray data = process.readAllStandardOutput(); + + QSettings settings; + settings.beginGroup("Application"); + settings.setValue("lastCheckForUpdate", QDateTime::currentDateTimeUtc()); + settings.endGroup(); + settings.sync(); + + if (data.isEmpty() || data.contains("currently no updates")) { + qInfo() << "No updates available"; + emit displayStatusMessage("No updates available."); + return false; + } + + return true; +} + +void GenericCore::triggerApplicationUpdate() { + // TODO include cleaness of undo stack + // if (!m_undoStack->isClean()) { + // saveItems(); + // } + // QStringList args("update componentA componentB"); + QStringList args("--start-updater"); + QString toolFilePath = getMaintenanceToolFilePath(); + QProcess::startDetached(toolFilePath, args); +} + +QString GenericCore::getMaintenanceToolFilePath() const { + QString applicationDirPath = QCoreApplication::applicationDirPath(); + +/// setting the applicationDirPath hard coded to test update feature from IDE +#ifdef QT_DEBUG + applicationDirPath = "/opt/GenericQtClient"; +#endif + +#ifdef Q_OS_MAC + applicationDirPath.append("/../../.."); +#endif + const QString filePath = applicationDirPath + "/" + UPDATER_EXE; + return filePath; +} diff --git a/genericcore.h b/genericcore.h index 3b4b4e6..bef0ac0 100644 --- a/genericcore.h +++ b/genericcore.h @@ -1,15 +1,28 @@ #ifndef GENERICCORE_H #define GENERICCORE_H +#include + class QString; -class GenericCore { +class GenericCore : public QObject { + Q_OBJECT + public: GenericCore(); ~GenericCore(); QString toString() const; void sayHello() const; + + bool isApplicationUpdateAvailable(); + void triggerApplicationUpdate(); + + signals: + void displayStatusMessage(QString message); + + private: + QString getMaintenanceToolFilePath() const; }; #endif // GENERICCORE_H