Compare commits

...

12 Commits

Author SHA1 Message Date
739010ba59 readyReadStandardOutput():
parse outout of ATBUpdateDC.
2025-03-07 12:20:40 +01:00
7ace073d12 finished():
start summary timer when binary  has finished.
2025-03-07 12:19:54 +01:00
e36ff70dd9 minor: rename name of binaries 2025-03-07 12:18:32 +01:00
57e65e2234 change for testing 2025-03-07 12:16:35 +01:00
79af890be6 set version to 2.0.0 2025-03-07 12:15:52 +01:00
24b83840cd handling of summary after installation 2025-03-07 12:15:16 +01:00
53946457ab minor: stepLabel format: rich text. 2025-03-07 12:11:41 +01:00
c3947e49ab cleaning up source code. move summary-handling to main-window. 2025-03-07 12:10:54 +01:00
7ecd45b547 cleaning up source. rename doUndate() to run(). 2025-03-07 12:09:07 +01:00
e7d8365c62 read ini-file and determine device controller to install 2025-03-07 12:06:03 +01:00
c304d1a78b readSettings()
read ini-file for binary (e.g. ATBUpdateTool, ATBUpdateDC etc).
	1: using optional path
	2: under /etc...
	3: under /opt...
2025-03-07 11:50:58 +01:00
a8d4ae3aee Minor: renamed binary to ATBUpdateShow 2025-03-07 11:44:48 +01:00
15 changed files with 410 additions and 287 deletions

View File

@ -10,10 +10,12 @@
#include <QDir> #include <QDir>
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
#include <QRegularExpression>
#include "message_handler.h" #include "message_handler.h"
#include "commandline_parser.h" #include "commandline_parser.h"
#include "utils.h" #include "utils.h"
#include "utils_internal.h"
#include "update.h" #include "update.h"
#include "System.h" #include "System.h"
@ -53,14 +55,20 @@ int main(int argc, char **argv) {
openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER); openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("ATBDownloadDCFirmware"); QCoreApplication::setOrganizationName("ATB Automatentechnik Baumann GmBH");
QCoreApplication::setApplicationName("ATBUpdateDC");
QCoreApplication::setApplicationVersion(APP_VERSION); QCoreApplication::setApplicationVersion(APP_VERSION);
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
atbInstallMessageHandler(atbDebugOutput); atbInstallMessageHandler(atbDebugOutput);
setDebugLevel(LOG_NOTICE); setDebugLevel(LOG_NOTICE);
} }
//return 0;
/*
CommandLineParser parser; CommandLineParser parser;
parser.process(a); parser.process(a);
parser.readSettings(); parser.readSettings();
@ -125,6 +133,30 @@ int main(int argc, char **argv) {
QString const &customerRepo QString const &customerRepo
= QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr)); = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
*/
QString const &psaDcDir = internal::customerRepoDcDir();
QString const &psaRepoRootDir = internal::customerRepoRoot();
QString const &psaRepoDir = internal::customerRepoDir();
QString const &branchName = internal::branchName();
bool debug = false;
bool noaction = true;
QString workingDir;
QString libca;
std::unique_ptr<QSettings> settings = internal::readSettings();
if (settings) {
settings->beginGroup("COMMON");
debug = settings->value("debug", false).toBool();
settings->endGroup();
settings->beginGroup("RUNTIME");
noaction = settings->value("noaction", true).toBool();
workingDir = settings->value("workingdir", "/tmp").toBool();
libca = settings->value("libca", "/usr/lib/libCAslave.so").toString();
settings->endGroup();
}
// etc/dc: located under mount-path // etc/dc: located under mount-path
std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir); std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
@ -135,47 +167,32 @@ int main(int argc, char **argv) {
if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) { if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) {
fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value())); fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value()));
} else { } else {
qInfo() << "using customer repository" << customerRepo;
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/dc")); if (debug) {
if (dir.exists()) { qInfo() << "using customer repository" << psaRepoDir;
fi.setFile(dir, dir.absoluteFilePath("dc2c.bin")); }
} else {
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST"; std::unique_ptr<QString> c = internal::dcCandidateToInstall();
return -1; if (c) {
fi.setFile(*c);
if (fi.exists() == false) {
qCritical() << "dc2c.bin candidate" << *c << "does not exist. STOP.";
return -1;
}
qInfo() << "dc2c.bin canditate" << fi.absoluteFilePath();
} }
} }
qInfo() << "downloading dc-firmware .." << fi.absoluteFilePath(); if (debug) {
qInfo() << "dc-firmware size (bytes) ." << fi.size(); qInfo() << "downloading dc-firmware" << fi.absoluteFilePath();
if (readDCVersion) { qInfo() << "dc-firmware size (bytes)" << fi.size();
qInfo() << "dc-version ..............." << Update::dcVersion(fi.absoluteFilePath()); qInfo() << "dc-version" << Update::dcVersion(fi.absoluteFilePath());
} }
QThread::currentThread()->setObjectName("main thread"); Update u(fi.absoluteFilePath(), libca, debug, noaction);
// qInfo() << "Main thread" << QThread::currentThreadId(); u.run();
Update update(customerRepo,
QString::number(customerNr),
branchName,
plugInDir,
plugInName,
workingDir,
psaDcDir);
update.doUpdate(fi.absoluteFilePath());
// MainWindow mw;
// mw.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
// mw.showFullScreen();
// qCritical() << "SHOW";
// mw.show();
qInfo() << "<DC-UPDATE-FINISH>"; qInfo() << "<DC-UPDATE-FINISH>";
return 0; return 0;
// return a.exec();
} }

View File

@ -37,48 +37,38 @@ static const QMap<QString, int> baudrateMap = {
QPluginLoader Update::pluginLoader; QPluginLoader Update::pluginLoader;
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) { hwinf *Update::loadDCPlugin(QString const &libCA /* absolute file path */) {
hwinf *hw = nullptr; hwinf *hw = nullptr;
if (plugInDir.exists()) { QFileInfo libCAInfo(libCA);
QString pluginLibName(fname); if (libCAInfo.exists()) {
pluginLibName = plugInDir.absoluteFilePath(pluginLibName); pluginLoader.setFileName(libCA);
QFileInfo info(pluginLibName); // static QPluginLoader pluginLoader(pluginLibName);
if (info.exists()) { if (!pluginLoader.load()) {
pluginLibName = plugInDir.absoluteFilePath(pluginLibName); qCritical() << "cannot load plugin" << pluginLoader.fileName();
pluginLoader.setFileName(pluginLibName); qCritical() << pluginLoader.errorString();
// static QPluginLoader pluginLoader(pluginLibName); return nullptr;
if (!pluginLoader.load()) { }
qCritical() << "in directory" << plugInDir.absolutePath();
qCritical() << "cannot load plugin" << pluginLoader.fileName();
qCritical() << pluginLoader.errorString();
return nullptr;
}
qCritical() << "loadDCPlugin() plugin directory:" << plugInDir.absolutePath(); // qCritical() << "loadDCPlugin() plugin file name:" << pluginLoader.fileName();
qCritical() << "loadDCPlugin() plugin file name:" << pluginLoader.fileName();
if (!pluginLoader.isLoaded()) { if (!pluginLoader.isLoaded()) {
qCritical() << pluginLoader.errorString(); qCritical() << pluginLoader.errorString();
return nullptr; return nullptr;
} }
QObject *plugin = pluginLoader.instance(); QObject *plugin = pluginLoader.instance();
if (!plugin) { if (!plugin) {
qCritical() << "cannot start instance"; qCritical() << "cannot start instance";
return nullptr; return nullptr;
} }
if (! (hw = qobject_cast<hwinf *>(plugin))) { if (! (hw = qobject_cast<hwinf *>(plugin))) {
qCritical() << "cannot cast plugin" << plugin << "to hwinf"; qCritical() << "cannot cast plugin" << plugin << "to hwinf";
return nullptr;
}
} else {
qCritical() << pluginLibName << "does not exist";
return nullptr; return nullptr;
} }
} else { } else {
qCritical() << "plugins directory" << plugInDir.absolutePath() qCritical() << libCAInfo.absoluteFilePath() << "does not exist";
<< "does not exist";
return nullptr; return nullptr;
} }
return hw; return hw;
} }
@ -109,75 +99,18 @@ QString Update::dcVersion(QString const &dcBinFile) {
} }
class hwapi; class hwapi;
Update::Update(QString customerRepository, Update::Update(QString const &dcFileName, QString const &libCA, bool debug, bool noaction)
QString customerNrStr, : m_dcFileName(dcFileName)
QString branchName, , m_hw(loadDCPlugin(libCA))
QString plugInDir, , m_sys_areDCdataValid(false)
QString pluginName, , m_debug(debug)
QString workingDir, , m_noaction(noaction) {
QString psaDcDir,
bool dryRun,
QObject *parent,
char const *serialInterface,
char const *baudrate)
: QObject(parent) {
#if 0
, m_hw(loadDCPlugin(QDir(plugInDir), pluginName))
, m_serialInterface(serialInterface)
, m_baudrate(baudrate)
, m_customerRepository(customerRepository)
, m_customerNrStr(customerNrStr)
, m_branchName(branchName)
, m_pluginName(pluginName)
, m_workingDir(workingDir)
, m_psaDcDir(psaDcDir)
, m_dryRun(dryRun)
, m_sys_areDCdataValid(false) {
if (!m_hw) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???";
} else {
// carun stoppen
}
#endif
m_start = QDateTime::currentDateTime();
} }
Update::~Update() { Update::~Update() {
unloadDCPlugin(); unloadDCPlugin();
} }
bool Update::openSerialPort() {
// const SettingsDialog::Settings p = m_settings->settings();
m_serial->setPortName(SERIAL_PORT);
m_serial->setBaudRate(QSerialPort::Baud115200);
m_serial->setDataBits(QSerialPort::DataBits::Data8);
m_serial->setParity(QSerialPort::Parity::NoParity);
m_serial->setStopBits(QSerialPort::StopBits::OneStop);
m_serial->setFlowControl(QSerialPort::FlowControl::NoFlowControl);
if (m_serial->open(QIODevice::ReadWrite)) {
//showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
// .arg(p.name, p.stringBaudRate, p.stringDataBits,
// p.stringParity, p.stringStopBits, p.stringFlowControl));
return true;
} else {
//QMessageBox::critical(this, tr("Error"), m_serial->errorString());
//showStatusMessage(tr("Open error"));
}
return false;
}
bool Update::closeSerialPort() {
if (m_serial->isOpen()) {
m_serial->close();
return true;
}
return false;
//showStatusMessage(tr("Disconnected"));
}
Update::DownloadResult Update::sendStatus(int ret) const { Update::DownloadResult Update::sendStatus(int ret) const {
switch (ret) { // return values of dc are: switch (ret) { // return values of dc are:
case 0: // 0: no answer by now case 0: // 0: no answer by now
@ -280,8 +213,9 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const {
} }
bool Update::startBootloader() const { bool Update::startBootloader() const {
qInfo() << nextTimePoint().toUtf8().constData() << "start boot loader";
QThread::msleep(1000); QThread::msleep(1000);
qInfo() << nextTimePoint().toUtf8().constData() << "starting bootloader ...done"; qInfo() << nextTimePoint().toUtf8().constData() << "start boot loader ...done";
return true; return true;
#if 0 #if 0
@ -304,6 +238,7 @@ bool Update::startBootloader() const {
} }
bool Update::stopBootloader() const { bool Update::stopBootloader() const {
qInfo() << nextTimePoint().toUtf8().constData() << "stopping bootloader";
QThread::msleep(1000); QThread::msleep(1000);
qInfo() << nextTimePoint().toUtf8().constData() << "stopping bootloader ...done"; qInfo() << nextTimePoint().toUtf8().constData() << "stopping bootloader ...done";
return true; return true;
@ -325,6 +260,7 @@ bool Update::stopBootloader() const {
} }
bool Update::resetDeviceController() const { bool Update::resetDeviceController() const {
qInfo() << nextTimePoint().toUtf8().constData() << "resetting device controller";
// TODO // TODO
// m_hw->bl_rebootDC(); // m_hw->bl_rebootDC();
@ -439,19 +375,22 @@ QByteArray Update::loadBinaryDCFile(QString const &filename) const {
// There is no problem to repeat this command until the // There is no problem to repeat this command until the
// bootloader is really not running anymore. // bootloader is really not running anymore.
*/ */
bool Update::doUpdate(QString const &dcFileName) { int Update::run() {
qInfo() << "<DC-VERSION>" << Update::dcVersion(dcFileName); if (!m_hw) {
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???";
return -(int)Result::PLUGIN_LOAD_ERROR;
}
m_dcFileName = dcFileName; m_start = QDateTime::currentDateTime();
//QString const &fToWorkOn = usbStickDetected ? QDir::cleanPath(it->trimmed()) if (m_debug) {
//: QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed()); qInfo() << "start dc-update for" << m_dcFileName << "at" << m_start.toString(Qt::ISODate);
qInfo() << "<DC-VERSION>" << Update::dcVersion(m_dcFileName);
}
//if (!m_hw) { m_hw->dc_autoRequest(false);
// qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
// << "ERROR!!! m_hw == nullptr"; qInfo() << "DC auto request OFF";
// return false;
//}
QByteArray ba = loadBinaryDCFile(m_dcFileName); QByteArray ba = loadBinaryDCFile(m_dcFileName);
if (ba.size() > 0) { if (ba.size() > 0) {
@ -462,6 +401,7 @@ bool Update::doUpdate(QString const &dcFileName) {
// fill last block of data to be sent with 0xFF // fill last block of data to be sent with 0xFF
ba = ba.leftJustified(m_totalBlocks*64, (char)(0xFF)); ba = ba.leftJustified(m_totalBlocks*64, (char)(0xFF));
// TODO
resetDeviceController(); resetDeviceController();
if (startBootloader()) { if (startBootloader()) {
int currentBlock = 0; int currentBlock = 0;
@ -499,10 +439,11 @@ bool Update::doUpdate(QString const &dcFileName) {
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK()); qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
#endif #endif
} }
// TODO
stopBootloader(); // there is no harm in stopping the bootloader even stopBootloader(); // there is no harm in stopping the bootloader even
// if starting the bootloader failed // if starting the bootloader failed
qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-SUCCESS>"; qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-SUCCESS>";
return true; return -(int)Result::SUCCESS;
} }
qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-FAILURE>"; qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-FAILURE>";

View File

@ -17,27 +17,21 @@
#ifdef PTU5 #ifdef PTU5
#define SERIAL_PORT "ttymxc2" #define SERIAL_PORT "ttymxc2"
#define BAUDRATE 115200
#else #else
#define SERIAL_PORT "ttyUSB0" #define SERIAL_PORT "ttyUSB0"
#define BAUDRATE 115200
#endif #endif
class QSerialPort; class QSerialPort;
class Update : public QObject { class Update : public QObject {
Q_OBJECT Q_OBJECT
QString m_dcFileName{};
hwinf *m_hw = nullptr; hwinf *m_hw = nullptr;
char const *m_serialInterface; bool m_sys_areDCdataValid{};
char const *m_baudrate; bool m_debug;
QString m_customerRepository; bool m_noaction;
QString m_customerNrStr;
QString m_branchName;
QString m_pluginName;
QString m_workingDir;
QString m_psaDcDir;
QString m_dcFileName;
bool m_maintenanceMode;
bool m_dryRun;
bool m_sys_areDCdataValid;
static QPluginLoader pluginLoader; static QPluginLoader pluginLoader;
@ -47,34 +41,18 @@ class Update : public QObject {
return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0')); return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
} }
bool openSerialPort();
bool closeSerialPort();
QSerialPort *m_serial;
public: public:
enum class DownloadResult {OK, ERROR, TIMEOUT, NOP}; enum class DownloadResult {OK, ERROR, TIMEOUT, NOP};
enum class FileTypeJson {CONFIG=1, DEVICE=2, CASH=3, SERIAL=4, TIME=5, PRINTER=6}; enum class Result {SUCCESS=0, PLUGIN_LOAD_ERROR};
static hwinf *loadDCPlugin(QDir const &plugInDir, QString const &fn); static hwinf *loadDCPlugin(QString const &libCA = "/usr/lib/libCAslave.so");
static bool unloadDCPlugin(); static bool unloadDCPlugin();
static QStringList split(QString line, QChar sep = ','); static QStringList split(QString line, QChar sep = ',');
explicit Update(QString customerRepository, explicit Update(QString const &dcBinFile, QString const &libCA, bool debug, bool noaction);
QString customerNrStr,
QString branchName,
QString plugInDir,
QString pluginName,
QString workingDir,
QString psaDcDir,
bool dryRun = false,
QObject *parent = nullptr,
char const *serialInterface = SERIAL_PORT,
char const *baudrate = "115200");
virtual ~Update() override; virtual ~Update() override;
bool doUpdate(QString const &dcFileName); int run();
static QString dcVersion(QString const &dcBinFile); static QString dcVersion(QString const &dcBinFile);
private: private:

View File

@ -1,6 +1,6 @@
QT += core QT += core
TARGET = show_update TARGET = ATBUpdateShow
VERSION="1.0.0" VERSION="1.0.0"
win32 { win32 {

View File

@ -147,7 +147,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
# 1.5.5 : Call into binary ptuPackageVersion to get installed package # 1.5.5 : Call into binary ptuPackageVersion to get installed package
# versions. # versions.
# 1.5.6 : Show additional update progress info in status bar. # 1.5.6 : Show additional update progress info in status bar.
VERSION="1.5.6" # 2.0.0 : Rewrite of UpdateTool.
VERSION="2.0.0"
# PLANNED TODOS: # PLANNED TODOS:
# 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT. # 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT.
# 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu # 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu

View File

@ -30,7 +30,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, m_worker(worker) , m_worker(worker)
, m_width(70) , m_width(60)
, m_progressRunning(false) , m_progressRunning(false)
, m_updateStep(UpdateDcEvent::UpdateStep::NONE) { , m_updateStep(UpdateDcEvent::UpdateStep::NONE) {
@ -44,16 +44,20 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
m_updateSteps[INSTALL_SW_PACKETS] = "Install SW packets "; m_updateSteps[INSTALL_SW_PACKETS] = "Install SW packets ";
m_updateSteps[INSTALL_DC_CONFIGURATION] = "Install DC configuration "; m_updateSteps[INSTALL_DC_CONFIGURATION] = "Install DC configuration ";
m_updateSteps[SYNCHRONIZE_REPOSITORY] = "Synchronize repository/filesystem "; m_updateSteps[SYNCHRONIZE_REPOSITORY] = "Synchronize repository/filesystem ";
m_updateSteps[UPDATE_DC] = "Update DC"; m_updateSteps[UPDATE_DC] = "Update DC ";
QString text{};
for (int i = 0; i < m_updateSteps.size(); ++i) { for (int i = 0; i < m_updateSteps.size(); ++i) {
QString &tmp = m_updateSteps[i]; QString &tmp = m_updateSteps[i];
int len = m_showLineLength - tmp.length(); int len = m_showLineLength - tmp.length();
while (--len > 0) { while (--len > 0) {
tmp += "&nbsp;"; tmp += "&nbsp;";
} }
ui->stepLabel->setText(tmp + "\n"); m_updateSteps[i] = tmp;
text += m_updateSteps[i];
} }
ui->stepLabel->setTextFormat(Qt::RichText);
ui->stepLabel->setText(text);
this->setStatusBar(new QStatusBar(this)); this->setStatusBar(new QStatusBar(this));
QFont f; QFont f;
@ -73,7 +77,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
lst << QString("Update tool version : %1 - %2 %3").arg(APP_VERSION).arg(APP_BUILD_DATE).arg(APP_BUILD_TIME).leftJustified(m_width-3); lst << QString("Update tool version : %1 - %2 %3").arg(APP_VERSION).arg(APP_BUILD_DATE).arg(APP_BUILD_TIME).leftJustified(m_width-3);
lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3); lst << QString("Machine number : %1 ").arg(m_worker->machineNr()).leftJustified(m_width-3);
lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3); lst << QString("Customer number : %1 ").arg(m_worker->customerNr()).leftJustified(m_width-3);
lst << QString("Zone number : %1 (%2)").arg(m_worker->zoneNr()).arg(Utils::zoneName(m_worker->zoneNr())).leftJustified(m_width-3); lst << QString("Zone number : %1 ").arg(m_worker->zoneNr()).leftJustified(m_width-3);
lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3); lst << QString("APISM version : %1").arg(m_worker->apismVersion()).leftJustified(m_width-3);
lst << QString("").leftJustified(m_width-3, '='); lst << QString("").leftJustified(m_width-3, '=');
@ -109,7 +113,12 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
m_statusTimer->start(1000); m_statusTimer->start(1000);
} }
connect(m_worker->summaryTimer(), SIGNAL(timeout()), this, SLOT(onSummary()));
m_worker->summaryTimer()->setSingleShot(true);
m_worker->summaryTimer()->setInterval(5000);
connect(ui->exit, SIGNAL(clicked()),this,SLOT(onQuit())); connect(ui->exit, SIGNAL(clicked()),this,SLOT(onQuit()));
connect(m_worker, SIGNAL(summary()),this,SLOT(onSummary()));
connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString))); connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString)));
connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit())); connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit()));
connect(m_worker, SIGNAL(showDcDownload(QString)),this,SLOT(onShowDcDownload(QString))); connect(m_worker, SIGNAL(showDcDownload(QString)),this,SLOT(onShowDcDownload(QString)));
@ -142,8 +151,91 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,QString))); connect(m_worker, SIGNAL(replaceLast(QStringList,QString)),this, SLOT(onReplaceLast(QStringList,QString)));
} }
void MainWindow::onSummary() {
QThread::sleep(3);
QString summary, first, second, line, tmp;
QVector<QPair<QString, QString>> vec = Utils::installedPackages();
if (m_worker) {
vec.append(Utils::installedTariffFiles(m_worker, m_worker->customerRepository()));
vec.append(Utils::installedJsonFiles(m_worker, m_worker->customerRepository()));
}
int max_first = 0, max_second = 0;
for (int i = 0; i < vec.size(); ++i) {
max_first = std::max(max_first, vec[i].first.length());
max_second = std::max(max_second, vec[i].second.length());
}
max_first += 5;
summary = "UPDATE SUMMARY\n\n";
if (m_worker) {
first = QString("%1").arg("start", max_first, QChar(' '));
tmp = QString("%1").arg(m_worker->start().toString(Qt::ISODate));
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
first = QString("%1").arg("update tool version", max_first, QChar(' '));
tmp = QString("%1 - %2 %3").arg(APP_VERSION).arg(APP_BUILD_DATE).arg(APP_BUILD_TIME);
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
if (m_worker) {
first = QString("%1").arg("machine number", max_first, QChar(' '));
tmp = QString("%1").arg(m_worker->machineNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("customer number", max_first, QChar(' '));
tmp = QString("%1").arg(m_worker->customerNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("zone number", max_first, QChar(' '));
tmp = QString("%1").arg(m_worker->zoneNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
tmp = targetDcVersion();
if (!tmp.isEmpty()) {
first = QString("%1").arg("target device controller", max_first, QChar(' '));
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
if (m_worker) {
first = QString("%1").arg("apism", max_first, QChar(' '));
tmp = QString("%1").arg(m_worker->apismVersion());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
for (int i = 0; i < vec.size(); ++i) {
first = QString("%1").arg(vec[i].first, max_first, QChar(' '));
second = QString("%1").arg(vec[i].second, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
if (m_worker) {
emit m_worker->showSummary(summary);
emit m_worker->enableExit();
}
}
void MainWindow::onShowSummary(QString text) { void MainWindow::onShowSummary(QString text) {
// QString s = ui->updateLabel->text(); // QString s = ui->updateLabel->text();
QString s("\n"); QString s("\n");
@ -161,6 +253,9 @@ void MainWindow::onSetDcDownloadProgress(int v) {
} }
void MainWindow::onShowTariffUpdate(QString) { void MainWindow::onShowTariffUpdate(QString) {
return;
ui->exit->setEnabled(false); ui->exit->setEnabled(false);
QString s = ui->stepLabel->text(); QString s = ui->stepLabel->text();
@ -341,13 +436,12 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
QString s = m_updateSteps[UPDATE_DC].trimmed(); QString s = m_updateSteps[UPDATE_DC].trimmed();
if (status.contains(UpdateCommand::UPDATE_DC_FIRMARE_SUCCESS, Qt::CaseInsensitive)) { if (status.contains(internal::UPDATE_DC_FIRMARE_SUCCESS, Qt::CaseInsensitive)) {
s += " <font color='Green'>success</font>"; s += " <font color='Green'>success</font>";
} else { } else {
s += " <font color='Red'>UNKNOWN STATUS</font>"; s += " <font color='Red'>UNKNOWN STATUS</font>";
} }
m_updateSteps[UPDATE_DC] = s;
s.clear(); s.clear();
for (int i = 0; i < m_updateSteps.size(); ++i) { for (int i = 0; i < m_updateSteps.size(); ++i) {
if (i != UPDATE_DC) { if (i != UPDATE_DC) {
@ -356,6 +450,7 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
s += m_updateSteps[i]; s += m_updateSteps[i];
} }
} }
ui->stepLabel->setText(s); ui->stepLabel->setText(s);
} }
@ -440,6 +535,9 @@ void MainWindow::onShowJsonDownload(QString) {
} }
void MainWindow::onShowDcDownload(QString version) { void MainWindow::onShowDcDownload(QString version) {
return;
m_targetDcVersion = version; m_targetDcVersion = version;
ui->exit->setEnabled(false); ui->exit->setEnabled(false);

View File

@ -68,6 +68,7 @@ public slots:
void onShowUpdateDCFirmware(QString); void onShowUpdateDCFirmware(QString);
void onSetDcDownloadProgress(int); void onSetDcDownloadProgress(int);
void onShowSummary(QString); void onShowSummary(QString);
void onSummary();
#if EMERGENCY_LEAVE_BL==1 #if EMERGENCY_LEAVE_BL==1
void emergencyLeaveBL(); void emergencyLeaveBL();
#endif #endif

View File

@ -51,6 +51,9 @@
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="3"> <item row="3" column="0" colspan="3">

View File

@ -50,7 +50,7 @@ void Command::readyReadStandardOutput() {
s = s.mid(0, i).trimmed(); s = s.mid(0, i).trimmed();
} }
} }
emit m_worker->showDcDownload(s); // emit m_worker->showDcDownload(s);
} else } else
if ((i = s.indexOf("<DC-PROGRESS>")) != -1) { if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
bool ok; bool ok;
@ -61,14 +61,15 @@ void Command::readyReadStandardOutput() {
} }
} else } else
if ((i = s.indexOf("<DC-UPDATE-FINISH>")) != -1) { if ((i = s.indexOf("<DC-UPDATE-FINISH>")) != -1) {
m_worker->summary(); emit m_worker->summary();
// qApp->exit(0); // qApp->exit(0);
} else } else
if ((i = s.indexOf("<DC-UPDATE-SUCCESS>")) != -1) { if ((i = s.indexOf("<DC-UPDATE-SUCCESS>")) != -1) {
m_worker->summary(); // TODO
emit m_worker->summary();
} else } else
if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) { if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
m_worker->summary(); emit m_worker->summary();
//qApp->exit(-1); //qApp->exit(-1);
} else } else
if ((i = s.indexOf("<JS-PROGRESS>")) != -1) { if ((i = s.indexOf("<JS-PROGRESS>")) != -1) {

View File

@ -113,15 +113,15 @@ void UpdateCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
"sync customer repository with /etc"); "sync customer repository with /etc");
m_worker->clientForUpdate().sendCmdEvent(e); m_worker->clientForUpdate().sendCmdEvent(e);
} else } else
if (m_command.contains("ATBDownloadDCFirmware")) { if (m_command.contains("ATBUpdateDC")) {
ISMAS::EventData e(ISMAS::CONTINUE, ISMAS::EventData e(ISMAS::CONTINUE,
internal::PERCENT_UPDATE_DC, internal::PERCENT_UPDATE_DC,
0, 0,
"ATBDownloadDCFirmware", "ATBUpdateDC",
"downloaded new dc-firmware. about to reboot..."); "downloaded new dc-firmware. about to reboot...");
m_worker->clientForUpdate().sendCmdEvent(e); m_worker->clientForUpdate().sendCmdEvent(e);
} else } else
if (m_command.contains("ATBUpdateShowPSAInstalled")) { if (m_command.contains("ATBUpdateShow")) {
// TODO // TODO
} }

View File

@ -1,5 +1,6 @@
#include "process/update_dc_command.h" #include "process/update_dc_command.h"
#include "worker.h" #include "worker.h"
#include "utils_internal.h"
UpdateDCCommand::UpdateDCCommand(QString const &command, UpdateDCCommand::UpdateDCCommand(QString const &command,
Worker *worker, Worker *worker,
@ -10,19 +11,55 @@ UpdateDCCommand::UpdateDCCommand(QString const &command,
} }
void UpdateDCCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) { void UpdateDCCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
Worker *w = worker();
if (w) {
w->summaryTimer()->start();
}
return UpdateCommand::finished(exitCode, exitStatus); return UpdateCommand::finished(exitCode, exitStatus);
} }
void UpdateDCCommand::readyReadStandardOutput() { void UpdateDCCommand::readyReadStandardOutput() {
QProcess *p = (QProcess *)sender(); QProcess *p = (QProcess *)sender();
if (p) { if (p) {
QString s = p->readAllStandardOutput();
// TODO
Worker *w = worker(); Worker *w = worker();
if (w) { if (w) {
// static constexpr const char *UPDATE_DC_FIRMARE_SUCCESS"success"}; QString s = p->readAllStandardOutput();
emit w->showUpdateDCFirmware(UpdateCommand::UPDATE_DC_FIRMARE_SUCCESS); int i = -1;
if ((i = s.indexOf("<DC-VERSION>")) != -1) {
s = s.mid(i+12).trimmed();
if ((i = s.indexOf("\"")) != -1) {
s = s.mid(i+1);
if ((i = s.indexOf("\"")) != -1) {
s = s.mid(0, i).trimmed();
}
}
// emit w->showDcDownload(s);
} else
if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
bool ok;
int v = s.mid(i+13).trimmed().toInt(&ok);
if (ok) {
emit w->setDcDownloadProgress(v);
emit w->insertText(s.mid(0,i) + "\n");
}
} else
if ((i = s.indexOf("<DC-UPDATE-FINISH>")) != -1) {
emit w->showUpdateDCFirmware(internal::UPDATE_DC_FIRMARE_SUCCESS);
// QThread::sleep(3);
// emit w->summary();
// qApp->exit(0);
} else
if ((i = s.indexOf("<DC-UPDATE-SUCCESS>")) != -1) {
// TODO
emit w->summary();
} else
if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
emit w->summary();
//qApp->exit(-1);
} else {
emit w->insertText(s);
}
m_commandResult += s;
} }
} }
} }

View File

@ -185,7 +185,7 @@ Worker::Worker(int customerNr,
, m_pluginVersionPrmCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin_ConfigUi.so")) , m_pluginVersionPrmCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin_ConfigUi.so"))
, m_pluginVersionTcpZvt(getPluginVersion("/opt/app/ATBAPP/plugins/libTCP_ZVT_CCPlugin.so")) , m_pluginVersionTcpZvt(getPluginVersion("/opt/app/ATBAPP/plugins/libTCP_ZVT_CCPlugin.so"))
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS) , m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
, m_waitForNewUpdates(this) , m_summaryTimer(this)
, m_filesToUpdate() , m_filesToUpdate()
, m_updateProcessRunning(true) , m_updateProcessRunning(true)
, m_mainWindow(nullptr) /* contains plugin */ , m_mainWindow(nullptr) /* contains plugin */
@ -202,8 +202,8 @@ Worker::Worker(int customerNr,
int next = 1; int next = 1;
m_workList.push_back( m_workList.push_back(
std::make_unique<CheckIsmasConnectivityCommand>( std::make_unique<CheckIsmasConnectivityCommand>(
//QString("echo CheckIsmasConnectivityCommand") QString("echo ATBUpdateCheck --ismas-connected")
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected") //QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected")
, this, ++next)); , this, ++next));
// *** check if update activated in ISMAS *** // *** check if update activated in ISMAS ***
@ -211,8 +211,8 @@ Worker::Worker(int customerNr,
// if the update has been activated via ISMAS. // if the update has been activated via ISMAS.
m_workList.push_back( m_workList.push_back(
std::make_unique<CheckUpdateActivationCommand>( std::make_unique<CheckUpdateActivationCommand>(
//QString("echo CheckUpdateActivationCommand") QString("echo ATBUpdateCheck --update-requested")
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --update-requested") //QString("/opt/app/tools/atbupdate/ATBUpdateCheck --update-requested")
, this, ++next)); , this, ++next));
// *** check and fetch git-customer repository *** // *** check and fetch git-customer repository ***
@ -221,24 +221,24 @@ Worker::Worker(int customerNr,
// the corresponding branch, and check the integrity of the repository. // the corresponding branch, and check the integrity of the repository.
m_workList.push_back( m_workList.push_back(
std::make_unique<CheckAndFetchCustomerRepositoryCommand>( std::make_unique<CheckAndFetchCustomerRepositoryCommand>(
// QString("echo CheckAndFetchCustomerRepositoryCommand") QString("echo ATBUpdateGit")
QString("/opt/app/tools/atbupdate/ATBUpdateGit") // QString("/opt/app/tools/atbupdate/ATBUpdateGit")
, this, ++next)); , this, ++next));
// *** exec opkg-commands (noaction) *** // *** exec opkg-commands (noaction) ***
// NOTE: first run the opkg commands with no action -> dry-run // NOTE: first run the opkg commands with no action -> dry-run
m_workList.push_back( m_workList.push_back(
std::make_unique<ExecOpkgCommand>( std::make_unique<ExecOpkgCommand>(
// QString("echo ExecOpkgCommand noaction") QString("echo ATBUpdateOpkg --noaction")
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg --noaction") // QString("/opt/app/tools/atbupdate/ATBUpdateOpkg --noaction")
, this, ++next, true)); , this, ++next, true));
// *** exec opkg-commands *** // *** exec opkg-commands ***
// NOTE: first run the opkg commands with action -> no dry-run // NOTE: first run the opkg commands with action -> no dry-run
m_workList.push_back( m_workList.push_back(
std::make_unique<ExecOpkgCommand>( std::make_unique<ExecOpkgCommand>(
//QString("echo ExecOpkgCommand run") QString("echo ExecOpkgCommand run")
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg") // QString("/opt/app/tools/atbupdate/ATBUpdateOpkg")
, this, ++next, false)); , this, ++next, false));
// *** send json files down to device controller *** // *** send json files down to device controller ***
@ -257,14 +257,14 @@ Worker::Worker(int customerNr,
// send device-controller firmware down to device-controller-hardware // send device-controller firmware down to device-controller-hardware
m_workList.push_back( m_workList.push_back(
std::make_unique<UpdateDCCommand>( std::make_unique<UpdateDCCommand>(
QString("echo ATBDownloadDCFirmware") // QString("echo ATBUpdateDC")
// QString("/opt/app/tools/atbupdate/ATBDownloadDCFirmware --read-dc-version true") QString("/opt/app/tools/atbupdate/ATBUpdateDC")
, this, ++next)); , this, ++next));
// show/send software-status // show/send software-status
m_workList.push_back( m_workList.push_back(
std::make_unique<ShowSoftwareStatusCommand>( std::make_unique<ShowSoftwareStatusCommand>(
QString("echo ATBUpdateShowPSAInstalled") QString("echo ATBUpdateShow")
, this, -1)); , this, -1));
// reboot machine // reboot machine
@ -1615,78 +1615,3 @@ bool Worker::jsUpdate() {
bool Worker::dcUpdate() { bool Worker::dcUpdate() {
return m_dcDownloadFirmware->start("/opt/app/tools/atbupdate"); return m_dcDownloadFirmware->start("/opt/app/tools/atbupdate");
} }
void Worker::summary() {
QString summary, first, second, line, tmp;
QVector<QPair<QString, QString>> vec = Utils::installedPackages();
vec.append(Utils::installedTariffFiles(this, m_customerRepository));
vec.append(Utils::installedJsonFiles(this, m_customerRepository));
int max_first = 0, max_second = 0;
for (int i = 0; i < vec.size(); ++i) {
max_first = std::max(max_first, vec[i].first.length());
max_second = std::max(max_second, vec[i].second.length());
}
max_first += 5;
summary = "UPDATE SUMMARY\n\n";
first = QString("%1").arg("start", max_first, QChar(' '));
tmp = QString("%1").arg(start().toString(Qt::ISODate));
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("update tool version", max_first, QChar(' '));
tmp = QString("%1 - %2 %3").arg(APP_VERSION).arg(APP_BUILD_DATE).arg(APP_BUILD_TIME);
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("machine number", max_first, QChar(' '));
tmp = QString("%1").arg(machineNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("customer number", max_first, QChar(' '));
tmp = QString("%1").arg(customerNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
first = QString("%1").arg("zone number", max_first, QChar(' '));
tmp = QString("%1").arg(zoneNr());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
if (m_mainWindow) {
tmp = m_mainWindow->targetDcVersion();
if (!tmp.isEmpty()) {
first = QString("%1").arg("target device controller", max_first, QChar(' '));
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
}
first = QString("%1").arg("apism", max_first, QChar(' '));
tmp = QString("%1").arg(apismVersion());
second = QString("%1").arg(tmp, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
for (int i = 0; i < vec.size(); ++i) {
first = QString("%1").arg(vec[i].first, max_first, QChar(' '));
second = QString("%1").arg(vec[i].second, -max_second, QChar(' '));
line = first + ": " + second;
summary += line + "\n";
}
emit showSummary(summary);
emit enableExit();
}

View File

@ -178,7 +178,7 @@ class Worker : public QThread{
QString const m_pluginVersionTcpZvt; QString const m_pluginVersionTcpZvt;
int m_ismasUpdateRequests; int m_ismasUpdateRequests;
QTimer m_waitForNewUpdates; QTimer m_summaryTimer;
QStringList m_filesToUpdate; QStringList m_filesToUpdate;
QStringList m_filesToDownload; QStringList m_filesToDownload;
@ -453,6 +453,8 @@ public:
void setHW(hwinf *hw) { m_hw = hw; } void setHW(hwinf *hw) { m_hw = hw; }
hwinf *getHW() { return m_hw; } hwinf *getHW() { return m_hw; }
QString customerRepository() { return m_customerRepository; }
IsmasClient &getIsmasClient() { return m_ismasClient; } IsmasClient &getIsmasClient() { return m_ismasClient; }
IsmasClient const &getIsmasClient() const { return m_ismasClient; } IsmasClient const &getIsmasClient() const { return m_ismasClient; }
@ -473,7 +475,6 @@ public:
bool jsUpdate(); bool jsUpdate();
bool dcUpdate(); bool dcUpdate();
void summary();
QDateTime start() { return m_start; } QDateTime start() { return m_start; }
QByteArray standardOutput() const { return m_standardOutput; } QByteArray standardOutput() const { return m_standardOutput; }
@ -481,6 +482,8 @@ public:
WorkList const &workList() const { return m_workList; } WorkList const &workList() const { return m_workList; }
WorkList &workList() { return m_workList; } WorkList &workList() { return m_workList; }
QTimer *summaryTimer() { return &m_summaryTimer; }
signals: signals:
void appendText(QString, QString suffix = ""); void appendText(QString, QString suffix = "");
void insertText(QString); void insertText(QString);
@ -507,6 +510,7 @@ signals:
void showDownloadDCJsonFilesStatus(QString); void showDownloadDCJsonFilesStatus(QString);
void showSyncCustRepoStatus(QString); void showSyncCustRepoStatus(QString);
void showUpdateDCFirmware(QString); void showUpdateDCFirmware(QString);
void summary();
void showSummary(QString); void showSummary(QString);
void setDcDownloadProgress(int); void setDcDownloadProgress(int);

View File

@ -2,6 +2,8 @@
#define UTILS_INTERNAL_H_INCLUDED #define UTILS_INTERNAL_H_INCLUDED
#include <QString> #include <QString>
#include <QSettings>
#include <memory>
namespace internal { namespace internal {
@ -62,13 +64,19 @@ namespace internal {
static constexpr const int PERCENT_UPDATE_DC{80}; static constexpr const int PERCENT_UPDATE_DC{80};
static constexpr const int PERCENT_SHOW_FINAL_STATUS{90}; static constexpr const int PERCENT_SHOW_FINAL_STATUS{90};
static constexpr const char *DEFAULT_INI_DIR{"/etc/tools/atbupdate/"};
static constexpr const char *DEFAULT_INSTALL_DIR{"/opt/app/tools/atbupdate/"};
int read1stLineOfFile(QString fileName); int read1stLineOfFile(QString fileName);
QString customerRepoRoot(); QString customerRepoRoot();
QString customerRepoDir(); QString customerRepoDir();
QString customerRepoDcDir();
QString customerRepoDirName(); QString customerRepoDirName();
QString repositoryUrl(); QString repositoryUrl();
QString branchName(); QString branchName();
bool customerRepoExists(); bool customerRepoExists();
std::unique_ptr<QSettings> readSettings(QString const &optionalDirName = "");
std::unique_ptr<QString> dcCandidateToInstall(QString const &dcDirectory = "");
} }
#endif // UTILS_INTERNAL_H_INCLUDED #endif // UTILS_INTERNAL_H_INCLUDED

View File

@ -1,8 +1,12 @@
#include "utils.h" #include "utils_internal.h"
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QTextStream> #include <QTextStream>
#include <QSettings>
#include <QDebug>
#include <QCryptographicHash>
#include <QFileInfoList>
namespace internal { namespace internal {
@ -35,6 +39,11 @@ QString customerRepoDir() {
return !n.isEmpty() ? QDir::cleanPath(r + QDir::separator() + n) : ""; return !n.isEmpty() ? QDir::cleanPath(r + QDir::separator() + n) : "";
} }
QString customerRepoDcDir() {
QString const &r = customerRepoDir();
return QDir::cleanPath(r + QDir::separator() + "etc/dc/");
}
bool customerRepoExists() { bool customerRepoExists() {
QString const repoDir{customerRepoDir()}; QString const repoDir{customerRepoDir()};
return !repoDir.isEmpty() ? QDir(repoDir).exists() : false; return !repoDir.isEmpty() ? QDir(repoDir).exists() : false;
@ -52,4 +61,104 @@ QString branchName() {
return ""; return "";
} }
std::unique_ptr<QSettings> readSettings(QString const &optionalDirName) {
std::unique_ptr<QSettings> settings{std::make_unique<QSettings>()};
QString const fileName{settings->applicationName() + ".ini"};
QDir d;
if (!optionalDirName.isEmpty()) {
d = QDir{optionalDirName};
if (d.exists()) { // try to find ini-file under optionalDirname
QFileInfo fi{d, optionalDirName};
if (fi.exists()) {
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
return settings;
} else {
qCritical() << fi.absoluteFilePath() << "not found."
<< "Try" << internal::DEFAULT_INI_DIR;
}
} else {
qCritical() << optionalDirName << "not found."
<< "Try" << internal::DEFAULT_INSTALL_DIR;
}
}
d = internal::DEFAULT_INI_DIR;
if (d.exists()) { // try to find ini-file under /etc/tools/atbupdate
QFileInfo fi{d, fileName};
if (fi.exists()) {
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
return settings;
} else {
qCritical() << fi.absoluteFilePath() << "not found."
<< "Try" << internal::DEFAULT_INSTALL_DIR;
}
} else {
qCritical() << internal::DEFAULT_INI_DIR << "not found."
<< "Try" << internal::DEFAULT_INSTALL_DIR;
}
d = QDir{internal::DEFAULT_INSTALL_DIR};
if (d.exists()) { // try to find ini-file under /opt/app/tools/atbupdate
QFileInfo fi{d, fileName};
if (fi.exists()) {
settings.reset(new QSettings(fi.absoluteFilePath(), QSettings::IniFormat));
return settings;
} else {
qCritical() << fi.absoluteFilePath() << "not found.";
}
} else {
qCritical() << internal::DEFAULT_INSTALL_DIR << "not found.";
}
return settings;
}
std::unique_ptr<QString> dcCandidateToInstall(QString const &dcDirectory) {
std::unique_ptr<QString> dcCandidate{nullptr};
QDir dcDir{dcDirectory.isEmpty() ? customerRepoDcDir() : dcDirectory};
if (dcDir.exists()) {
QFileInfoList fileInfoList =
dcDir.entryInfoList(QStringList("*.bin"),
QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
QFileInfo dc2cbin{dcDir.absoluteFilePath("dc2c.bin")};
if (dc2cbin.exists()) {
QCryptographicHash md5gen(QCryptographicHash::Md5);
QByteArray ba_dc2cbin{};
{
QFile f{dc2cbin.absoluteFilePath()};
if (f.open(QIODevice::ReadOnly)) {
md5gen.addData(f.readAll());
ba_dc2cbin = md5gen.result();
md5gen.reset();
}
}
if (ba_dc2cbin.size() > 0) {
QFileInfoList::const_iterator it;
for (it = fileInfoList.cbegin(); it != fileInfoList.cend(); ++it) {
if (it->absoluteFilePath() != dc2cbin.absoluteFilePath()) {
QFile f{it->absoluteFilePath()};
if (f.open(QIODevice::ReadOnly)) {
md5gen.addData(f.readAll());
if (ba_dc2cbin == md5gen.result()) {
dcCandidate.reset(new QString(f.fileName()));
break;
}
md5gen.reset();
}
}
}
}
}
}
return dcCandidate;
}
} // namespace internal } // namespace internal