Compare commits
12 Commits
0fe318b291
...
739010ba59
Author | SHA1 | Date | |
---|---|---|---|
739010ba59 | |||
7ace073d12 | |||
e36ff70dd9 | |||
57e65e2234 | |||
79af890be6 | |||
24b83840cd | |||
53946457ab | |||
c3947e49ab | |||
7ecd45b547 | |||
e7d8365c62 | |||
c304d1a78b | |||
a8d4ae3aee |
@ -10,10 +10,12 @@
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QThread>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "message_handler.h"
|
||||
#include "commandline_parser.h"
|
||||
#include "utils.h"
|
||||
#include "utils_internal.h"
|
||||
#include "update.h"
|
||||
#include "System.h"
|
||||
|
||||
@ -53,14 +55,20 @@ int main(int argc, char **argv) {
|
||||
openlog("DC", LOG_PERROR | LOG_CONS, LOG_USER);
|
||||
|
||||
QCoreApplication a(argc, argv);
|
||||
QCoreApplication::setApplicationName("ATBDownloadDCFirmware");
|
||||
QCoreApplication::setOrganizationName("ATB Automatentechnik Baumann GmBH");
|
||||
QCoreApplication::setApplicationName("ATBUpdateDC");
|
||||
QCoreApplication::setApplicationVersion(APP_VERSION);
|
||||
|
||||
|
||||
if (!messageHandlerInstalled()) { // change internal qt-QDebug-handling
|
||||
atbInstallMessageHandler(atbDebugOutput);
|
||||
setDebugLevel(LOG_NOTICE);
|
||||
}
|
||||
|
||||
|
||||
//return 0;
|
||||
|
||||
/*
|
||||
CommandLineParser parser;
|
||||
parser.process(a);
|
||||
parser.readSettings();
|
||||
@ -125,6 +133,30 @@ int main(int argc, char **argv) {
|
||||
|
||||
QString const &customerRepo
|
||||
= 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
|
||||
std::optional<QString> mountPath = System::checkForUSBStick(psaDcDir);
|
||||
@ -135,47 +167,32 @@ int main(int argc, char **argv) {
|
||||
if ((mountPath = System::checkForSDCard(psaDcDir)).has_value()) {
|
||||
fi.setFile(mountPath.value(), System::getDCFileOnSDCard(mountPath.value()));
|
||||
} else {
|
||||
qInfo() << "using customer repository" << customerRepo;
|
||||
|
||||
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/dc"));
|
||||
if (dir.exists()) {
|
||||
fi.setFile(dir, dir.absoluteFilePath("dc2c.bin"));
|
||||
} else {
|
||||
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
|
||||
return -1;
|
||||
if (debug) {
|
||||
qInfo() << "using customer repository" << psaRepoDir;
|
||||
}
|
||||
|
||||
std::unique_ptr<QString> c = internal::dcCandidateToInstall();
|
||||
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();
|
||||
qInfo() << "dc-firmware size (bytes) ." << fi.size();
|
||||
if (readDCVersion) {
|
||||
qInfo() << "dc-version ..............." << Update::dcVersion(fi.absoluteFilePath());
|
||||
if (debug) {
|
||||
qInfo() << "downloading dc-firmware" << fi.absoluteFilePath();
|
||||
qInfo() << "dc-firmware size (bytes)" << fi.size();
|
||||
qInfo() << "dc-version" << Update::dcVersion(fi.absoluteFilePath());
|
||||
}
|
||||
|
||||
QThread::currentThread()->setObjectName("main thread");
|
||||
// qInfo() << "Main thread" << QThread::currentThreadId();
|
||||
|
||||
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();
|
||||
Update u(fi.absoluteFilePath(), libca, debug, noaction);
|
||||
u.run();
|
||||
|
||||
qInfo() << "<DC-UPDATE-FINISH>";
|
||||
|
||||
return 0;
|
||||
// return a.exec();
|
||||
}
|
||||
|
@ -37,48 +37,38 @@ static const QMap<QString, int> baudrateMap = {
|
||||
|
||||
QPluginLoader Update::pluginLoader;
|
||||
|
||||
hwinf *Update::loadDCPlugin(QDir const &plugInDir, QString const &fname) {
|
||||
hwinf *Update::loadDCPlugin(QString const &libCA /* absolute file path */) {
|
||||
hwinf *hw = nullptr;
|
||||
if (plugInDir.exists()) {
|
||||
QString pluginLibName(fname);
|
||||
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
||||
QFileInfo info(pluginLibName);
|
||||
if (info.exists()) {
|
||||
pluginLibName = plugInDir.absoluteFilePath(pluginLibName);
|
||||
pluginLoader.setFileName(pluginLibName);
|
||||
// static QPluginLoader pluginLoader(pluginLibName);
|
||||
if (!pluginLoader.load()) {
|
||||
qCritical() << "in directory" << plugInDir.absolutePath();
|
||||
qCritical() << "cannot load plugin" << pluginLoader.fileName();
|
||||
qCritical() << pluginLoader.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
QFileInfo libCAInfo(libCA);
|
||||
if (libCAInfo.exists()) {
|
||||
pluginLoader.setFileName(libCA);
|
||||
// static QPluginLoader pluginLoader(pluginLibName);
|
||||
if (!pluginLoader.load()) {
|
||||
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()) {
|
||||
qCritical() << pluginLoader.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
QObject *plugin = pluginLoader.instance();
|
||||
if (!plugin) {
|
||||
qCritical() << "cannot start instance";
|
||||
return nullptr;
|
||||
}
|
||||
if (! (hw = qobject_cast<hwinf *>(plugin))) {
|
||||
qCritical() << "cannot cast plugin" << plugin << "to hwinf";
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
qCritical() << pluginLibName << "does not exist";
|
||||
if (!pluginLoader.isLoaded()) {
|
||||
qCritical() << pluginLoader.errorString();
|
||||
return nullptr;
|
||||
}
|
||||
QObject *plugin = pluginLoader.instance();
|
||||
if (!plugin) {
|
||||
qCritical() << "cannot start instance";
|
||||
return nullptr;
|
||||
}
|
||||
if (! (hw = qobject_cast<hwinf *>(plugin))) {
|
||||
qCritical() << "cannot cast plugin" << plugin << "to hwinf";
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
qCritical() << "plugins directory" << plugInDir.absolutePath()
|
||||
<< "does not exist";
|
||||
qCritical() << libCAInfo.absoluteFilePath() << "does not exist";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return hw;
|
||||
}
|
||||
|
||||
@ -109,75 +99,18 @@ QString Update::dcVersion(QString const &dcBinFile) {
|
||||
}
|
||||
|
||||
class hwapi;
|
||||
Update::Update(QString customerRepository,
|
||||
QString customerNrStr,
|
||||
QString branchName,
|
||||
QString plugInDir,
|
||||
QString pluginName,
|
||||
QString workingDir,
|
||||
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(QString const &dcFileName, QString const &libCA, bool debug, bool noaction)
|
||||
: m_dcFileName(dcFileName)
|
||||
, m_hw(loadDCPlugin(libCA))
|
||||
, m_sys_areDCdataValid(false)
|
||||
, m_debug(debug)
|
||||
, m_noaction(noaction) {
|
||||
}
|
||||
|
||||
Update::~Update() {
|
||||
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 {
|
||||
switch (ret) { // return values of dc are:
|
||||
case 0: // 0: no answer by now
|
||||
@ -280,8 +213,9 @@ Update::sendNextDataBlock(QByteArray const &binary, int bNum) const {
|
||||
}
|
||||
|
||||
bool Update::startBootloader() const {
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "start boot loader";
|
||||
QThread::msleep(1000);
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "starting bootloader ...done";
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "start boot loader ...done";
|
||||
return true;
|
||||
|
||||
#if 0
|
||||
@ -304,6 +238,7 @@ bool Update::startBootloader() const {
|
||||
}
|
||||
|
||||
bool Update::stopBootloader() const {
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "stopping bootloader";
|
||||
QThread::msleep(1000);
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "stopping bootloader ...done";
|
||||
return true;
|
||||
@ -325,6 +260,7 @@ bool Update::stopBootloader() const {
|
||||
}
|
||||
|
||||
bool Update::resetDeviceController() const {
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "resetting device controller";
|
||||
// TODO
|
||||
// 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
|
||||
// bootloader is really not running anymore.
|
||||
*/
|
||||
bool Update::doUpdate(QString const &dcFileName) {
|
||||
qInfo() << "<DC-VERSION>" << Update::dcVersion(dcFileName);
|
||||
int Update::run() {
|
||||
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())
|
||||
//: QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
|
||||
if (m_debug) {
|
||||
qInfo() << "start dc-update for" << m_dcFileName << "at" << m_start.toString(Qt::ISODate);
|
||||
qInfo() << "<DC-VERSION>" << Update::dcVersion(m_dcFileName);
|
||||
}
|
||||
|
||||
//if (!m_hw) {
|
||||
// qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
// << "ERROR!!! m_hw == nullptr";
|
||||
// return false;
|
||||
//}
|
||||
m_hw->dc_autoRequest(false);
|
||||
|
||||
qInfo() << "DC auto request OFF";
|
||||
|
||||
QByteArray ba = loadBinaryDCFile(m_dcFileName);
|
||||
if (ba.size() > 0) {
|
||||
@ -462,6 +401,7 @@ bool Update::doUpdate(QString const &dcFileName) {
|
||||
// fill last block of data to be sent with 0xFF
|
||||
ba = ba.leftJustified(m_totalBlocks*64, (char)(0xFF));
|
||||
|
||||
// TODO
|
||||
resetDeviceController();
|
||||
if (startBootloader()) {
|
||||
int currentBlock = 0;
|
||||
@ -499,10 +439,11 @@ bool Update::doUpdate(QString const &dcFileName) {
|
||||
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
|
||||
#endif
|
||||
}
|
||||
// TODO
|
||||
stopBootloader(); // there is no harm in stopping the bootloader even
|
||||
// if starting the bootloader failed
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-SUCCESS>";
|
||||
return true;
|
||||
return -(int)Result::SUCCESS;
|
||||
}
|
||||
|
||||
qInfo() << nextTimePoint().toUtf8().constData() << "<DC-UPDATE-FAILURE>";
|
||||
|
@ -17,27 +17,21 @@
|
||||
|
||||
#ifdef PTU5
|
||||
#define SERIAL_PORT "ttymxc2"
|
||||
#define BAUDRATE 115200
|
||||
#else
|
||||
#define SERIAL_PORT "ttyUSB0"
|
||||
#define BAUDRATE 115200
|
||||
#endif
|
||||
|
||||
class QSerialPort;
|
||||
class Update : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
QString m_dcFileName{};
|
||||
hwinf *m_hw = nullptr;
|
||||
char const *m_serialInterface;
|
||||
char const *m_baudrate;
|
||||
QString m_customerRepository;
|
||||
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;
|
||||
bool m_sys_areDCdataValid{};
|
||||
bool m_debug;
|
||||
bool m_noaction;
|
||||
|
||||
static QPluginLoader pluginLoader;
|
||||
|
||||
@ -47,34 +41,18 @@ class Update : public QObject {
|
||||
return QStringLiteral("+%1s").arg(secs, 7, 'f', 2, QChar('0'));
|
||||
}
|
||||
|
||||
bool openSerialPort();
|
||||
bool closeSerialPort();
|
||||
|
||||
QSerialPort *m_serial;
|
||||
|
||||
public:
|
||||
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 QStringList split(QString line, QChar sep = ',');
|
||||
|
||||
explicit Update(QString customerRepository,
|
||||
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");
|
||||
|
||||
explicit Update(QString const &dcBinFile, QString const &libCA, bool debug, bool noaction);
|
||||
virtual ~Update() override;
|
||||
|
||||
bool doUpdate(QString const &dcFileName);
|
||||
int run();
|
||||
static QString dcVersion(QString const &dcBinFile);
|
||||
|
||||
private:
|
||||
|
@ -1,6 +1,6 @@
|
||||
QT += core
|
||||
|
||||
TARGET = show_update
|
||||
TARGET = ATBUpdateShow
|
||||
|
||||
VERSION="1.0.0"
|
||||
win32 {
|
||||
|
@ -147,7 +147,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
# 1.5.5 : Call into binary ptuPackageVersion to get installed package
|
||||
# versions.
|
||||
# 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:
|
||||
# 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT.
|
||||
# 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu
|
||||
|
@ -30,7 +30,7 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, m_worker(worker)
|
||||
, m_width(70)
|
||||
, m_width(60)
|
||||
, m_progressRunning(false)
|
||||
, 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_DC_CONFIGURATION] = "Install DC configuration ";
|
||||
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) {
|
||||
QString &tmp = m_updateSteps[i];
|
||||
int len = m_showLineLength - tmp.length();
|
||||
while (--len > 0) {
|
||||
tmp += " ";
|
||||
}
|
||||
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));
|
||||
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("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("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("").leftJustified(m_width-3, '=');
|
||||
|
||||
@ -109,7 +113,12 @@ MainWindow::MainWindow(Worker *worker, QWidget *parent)
|
||||
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(m_worker, SIGNAL(summary()),this,SLOT(onSummary()));
|
||||
connect(m_worker, SIGNAL(showSummary(QString)),this,SLOT(onShowSummary(QString)));
|
||||
connect(m_worker, SIGNAL(disableExit()),this,SLOT(onDisableExit()));
|
||||
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)));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
// QString s = ui->updateLabel->text();
|
||||
QString s("\n");
|
||||
|
||||
@ -161,6 +253,9 @@ void MainWindow::onSetDcDownloadProgress(int v) {
|
||||
}
|
||||
|
||||
void MainWindow::onShowTariffUpdate(QString) {
|
||||
return;
|
||||
|
||||
|
||||
ui->exit->setEnabled(false);
|
||||
|
||||
QString s = ui->stepLabel->text();
|
||||
@ -341,13 +436,12 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
|
||||
|
||||
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>";
|
||||
} else {
|
||||
s += " <font color='Red'>UNKNOWN STATUS</font>";
|
||||
}
|
||||
|
||||
m_updateSteps[UPDATE_DC] = s;
|
||||
s.clear();
|
||||
for (int i = 0; i < m_updateSteps.size(); ++i) {
|
||||
if (i != UPDATE_DC) {
|
||||
@ -356,6 +450,7 @@ void MainWindow::onShowUpdateDCFirmware(QString status) {
|
||||
s += m_updateSteps[i];
|
||||
}
|
||||
}
|
||||
|
||||
ui->stepLabel->setText(s);
|
||||
}
|
||||
|
||||
@ -440,6 +535,9 @@ void MainWindow::onShowJsonDownload(QString) {
|
||||
}
|
||||
|
||||
void MainWindow::onShowDcDownload(QString version) {
|
||||
return;
|
||||
|
||||
|
||||
m_targetDcVersion = version;
|
||||
ui->exit->setEnabled(false);
|
||||
|
||||
|
@ -68,6 +68,7 @@ public slots:
|
||||
void onShowUpdateDCFirmware(QString);
|
||||
void onSetDcDownloadProgress(int);
|
||||
void onShowSummary(QString);
|
||||
void onSummary();
|
||||
#if EMERGENCY_LEAVE_BL==1
|
||||
void emergencyLeaveBL();
|
||||
#endif
|
||||
|
@ -51,6 +51,9 @@
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
|
@ -50,7 +50,7 @@ void Command::readyReadStandardOutput() {
|
||||
s = s.mid(0, i).trimmed();
|
||||
}
|
||||
}
|
||||
emit m_worker->showDcDownload(s);
|
||||
// emit m_worker->showDcDownload(s);
|
||||
} else
|
||||
if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
|
||||
bool ok;
|
||||
@ -61,14 +61,15 @@ void Command::readyReadStandardOutput() {
|
||||
}
|
||||
} else
|
||||
if ((i = s.indexOf("<DC-UPDATE-FINISH>")) != -1) {
|
||||
m_worker->summary();
|
||||
emit m_worker->summary();
|
||||
// qApp->exit(0);
|
||||
} else
|
||||
if ((i = s.indexOf("<DC-UPDATE-SUCCESS>")) != -1) {
|
||||
m_worker->summary();
|
||||
// TODO
|
||||
emit m_worker->summary();
|
||||
} else
|
||||
if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
|
||||
m_worker->summary();
|
||||
emit m_worker->summary();
|
||||
//qApp->exit(-1);
|
||||
} else
|
||||
if ((i = s.indexOf("<JS-PROGRESS>")) != -1) {
|
||||
|
@ -113,15 +113,15 @@ void UpdateCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
"sync customer repository with /etc");
|
||||
m_worker->clientForUpdate().sendCmdEvent(e);
|
||||
} else
|
||||
if (m_command.contains("ATBDownloadDCFirmware")) {
|
||||
if (m_command.contains("ATBUpdateDC")) {
|
||||
ISMAS::EventData e(ISMAS::CONTINUE,
|
||||
internal::PERCENT_UPDATE_DC,
|
||||
0,
|
||||
"ATBDownloadDCFirmware",
|
||||
"ATBUpdateDC",
|
||||
"downloaded new dc-firmware. about to reboot...");
|
||||
m_worker->clientForUpdate().sendCmdEvent(e);
|
||||
} else
|
||||
if (m_command.contains("ATBUpdateShowPSAInstalled")) {
|
||||
if (m_command.contains("ATBUpdateShow")) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "process/update_dc_command.h"
|
||||
#include "worker.h"
|
||||
#include "utils_internal.h"
|
||||
|
||||
UpdateDCCommand::UpdateDCCommand(QString const &command,
|
||||
Worker *worker,
|
||||
@ -10,19 +11,55 @@ UpdateDCCommand::UpdateDCCommand(QString const &command,
|
||||
}
|
||||
|
||||
void UpdateDCCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
Worker *w = worker();
|
||||
if (w) {
|
||||
w->summaryTimer()->start();
|
||||
}
|
||||
return UpdateCommand::finished(exitCode, exitStatus);
|
||||
}
|
||||
|
||||
void UpdateDCCommand::readyReadStandardOutput() {
|
||||
QProcess *p = (QProcess *)sender();
|
||||
if (p) {
|
||||
QString s = p->readAllStandardOutput();
|
||||
|
||||
// TODO
|
||||
Worker *w = worker();
|
||||
if (w) {
|
||||
// static constexpr const char *UPDATE_DC_FIRMARE_SUCCESS"success"};
|
||||
emit w->showUpdateDCFirmware(UpdateCommand::UPDATE_DC_FIRMARE_SUCCESS);
|
||||
QString s = p->readAllStandardOutput();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ Worker::Worker(int customerNr,
|
||||
, m_pluginVersionPrmCalcConfig(getPluginVersion("/opt/app/ATBAPP/plugins/libPRM_CalculatePricePlugin_ConfigUi.so"))
|
||||
, m_pluginVersionTcpZvt(getPluginVersion("/opt/app/ATBAPP/plugins/libTCP_ZVT_CCPlugin.so"))
|
||||
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
|
||||
, m_waitForNewUpdates(this)
|
||||
, m_summaryTimer(this)
|
||||
, m_filesToUpdate()
|
||||
, m_updateProcessRunning(true)
|
||||
, m_mainWindow(nullptr) /* contains plugin */
|
||||
@ -202,8 +202,8 @@ Worker::Worker(int customerNr,
|
||||
int next = 1;
|
||||
m_workList.push_back(
|
||||
std::make_unique<CheckIsmasConnectivityCommand>(
|
||||
//QString("echo CheckIsmasConnectivityCommand")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected")
|
||||
QString("echo ATBUpdateCheck --ismas-connected")
|
||||
//QString("/opt/app/tools/atbupdate/ATBUpdateCheck --ismas-connected")
|
||||
, this, ++next));
|
||||
|
||||
// *** check if update activated in ISMAS ***
|
||||
@ -211,8 +211,8 @@ Worker::Worker(int customerNr,
|
||||
// if the update has been activated via ISMAS.
|
||||
m_workList.push_back(
|
||||
std::make_unique<CheckUpdateActivationCommand>(
|
||||
//QString("echo CheckUpdateActivationCommand")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateCheck --update-requested")
|
||||
QString("echo ATBUpdateCheck --update-requested")
|
||||
//QString("/opt/app/tools/atbupdate/ATBUpdateCheck --update-requested")
|
||||
, this, ++next));
|
||||
|
||||
// *** check and fetch git-customer repository ***
|
||||
@ -221,24 +221,24 @@ Worker::Worker(int customerNr,
|
||||
// the corresponding branch, and check the integrity of the repository.
|
||||
m_workList.push_back(
|
||||
std::make_unique<CheckAndFetchCustomerRepositoryCommand>(
|
||||
// QString("echo CheckAndFetchCustomerRepositoryCommand")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateGit")
|
||||
QString("echo ATBUpdateGit")
|
||||
// QString("/opt/app/tools/atbupdate/ATBUpdateGit")
|
||||
, this, ++next));
|
||||
|
||||
// *** exec opkg-commands (noaction) ***
|
||||
// NOTE: first run the opkg commands with no action -> dry-run
|
||||
m_workList.push_back(
|
||||
std::make_unique<ExecOpkgCommand>(
|
||||
// QString("echo ExecOpkgCommand noaction")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg --noaction")
|
||||
QString("echo ATBUpdateOpkg --noaction")
|
||||
// QString("/opt/app/tools/atbupdate/ATBUpdateOpkg --noaction")
|
||||
, this, ++next, true));
|
||||
|
||||
// *** exec opkg-commands ***
|
||||
// NOTE: first run the opkg commands with action -> no dry-run
|
||||
m_workList.push_back(
|
||||
std::make_unique<ExecOpkgCommand>(
|
||||
//QString("echo ExecOpkgCommand run")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateOpkg")
|
||||
QString("echo ExecOpkgCommand run")
|
||||
// QString("/opt/app/tools/atbupdate/ATBUpdateOpkg")
|
||||
, this, ++next, false));
|
||||
|
||||
// *** send json files down to device controller ***
|
||||
@ -257,14 +257,14 @@ Worker::Worker(int customerNr,
|
||||
// send device-controller firmware down to device-controller-hardware
|
||||
m_workList.push_back(
|
||||
std::make_unique<UpdateDCCommand>(
|
||||
QString("echo ATBDownloadDCFirmware")
|
||||
// QString("/opt/app/tools/atbupdate/ATBDownloadDCFirmware --read-dc-version true")
|
||||
// QString("echo ATBUpdateDC")
|
||||
QString("/opt/app/tools/atbupdate/ATBUpdateDC")
|
||||
, this, ++next));
|
||||
|
||||
// show/send software-status
|
||||
m_workList.push_back(
|
||||
std::make_unique<ShowSoftwareStatusCommand>(
|
||||
QString("echo ATBUpdateShowPSAInstalled")
|
||||
QString("echo ATBUpdateShow")
|
||||
, this, -1));
|
||||
|
||||
// reboot machine
|
||||
@ -1615,78 +1615,3 @@ bool Worker::jsUpdate() {
|
||||
bool Worker::dcUpdate() {
|
||||
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();
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ class Worker : public QThread{
|
||||
QString const m_pluginVersionTcpZvt;
|
||||
|
||||
int m_ismasUpdateRequests;
|
||||
QTimer m_waitForNewUpdates;
|
||||
QTimer m_summaryTimer;
|
||||
|
||||
QStringList m_filesToUpdate;
|
||||
QStringList m_filesToDownload;
|
||||
@ -453,6 +453,8 @@ public:
|
||||
void setHW(hwinf *hw) { m_hw = hw; }
|
||||
hwinf *getHW() { return m_hw; }
|
||||
|
||||
QString customerRepository() { return m_customerRepository; }
|
||||
|
||||
IsmasClient &getIsmasClient() { return m_ismasClient; }
|
||||
IsmasClient const &getIsmasClient() const { return m_ismasClient; }
|
||||
|
||||
@ -473,7 +475,6 @@ public:
|
||||
|
||||
bool jsUpdate();
|
||||
bool dcUpdate();
|
||||
void summary();
|
||||
QDateTime start() { return m_start; }
|
||||
|
||||
QByteArray standardOutput() const { return m_standardOutput; }
|
||||
@ -481,6 +482,8 @@ public:
|
||||
WorkList const &workList() const { return m_workList; }
|
||||
WorkList &workList() { return m_workList; }
|
||||
|
||||
QTimer *summaryTimer() { return &m_summaryTimer; }
|
||||
|
||||
signals:
|
||||
void appendText(QString, QString suffix = "");
|
||||
void insertText(QString);
|
||||
@ -507,6 +510,7 @@ signals:
|
||||
void showDownloadDCJsonFilesStatus(QString);
|
||||
void showSyncCustRepoStatus(QString);
|
||||
void showUpdateDCFirmware(QString);
|
||||
void summary();
|
||||
void showSummary(QString);
|
||||
void setDcDownloadProgress(int);
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#define UTILS_INTERNAL_H_INCLUDED
|
||||
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <memory>
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -62,13 +64,19 @@ namespace internal {
|
||||
static constexpr const int PERCENT_UPDATE_DC{80};
|
||||
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);
|
||||
QString customerRepoRoot();
|
||||
QString customerRepoDir();
|
||||
QString customerRepoDcDir();
|
||||
QString customerRepoDirName();
|
||||
QString repositoryUrl();
|
||||
QString branchName();
|
||||
bool customerRepoExists();
|
||||
std::unique_ptr<QSettings> readSettings(QString const &optionalDirName = "");
|
||||
std::unique_ptr<QString> dcCandidateToInstall(QString const &dcDirectory = "");
|
||||
}
|
||||
|
||||
#endif // UTILS_INTERNAL_H_INCLUDED
|
||||
|
@ -1,8 +1,12 @@
|
||||
#include "utils.h"
|
||||
#include "utils_internal.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFileInfoList>
|
||||
|
||||
namespace internal {
|
||||
|
||||
@ -35,6 +39,11 @@ QString customerRepoDir() {
|
||||
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() {
|
||||
QString const repoDir{customerRepoDir()};
|
||||
return !repoDir.isEmpty() ? QDir(repoDir).exists() : false;
|
||||
@ -52,4 +61,104 @@ QString branchName() {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user