Added checking for update and triggering the updater.
This commit is contained in:
@ -20,6 +20,7 @@ add_library(${TARGET_APP} STATIC
|
||||
genericcore.cpp
|
||||
genericcore.h
|
||||
${TS_FILES}
|
||||
constants.h
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
15
constants.h
Normal file
15
constants.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
/// 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
|
||||
@ -1,9 +1,14 @@
|
||||
#include "genericcore.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@ -1,15 +1,28 @@
|
||||
#ifndef GENERICCORE_H
|
||||
#define GENERICCORE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user