Compare commits
16 Commits
f8472a3b87
...
1.4.8-1
Author | SHA1 | Date | |
---|---|---|---|
a3aef7594e | |||
afbcccf785 | |||
90e4e21391 | |||
4536284f34 | |||
a3a4c09c7f | |||
a5dd9af29a | |||
5124e1cca6 | |||
fc75585de3 | |||
1964b08349 | |||
c0d014644c | |||
b24c50c572 | |||
bbdadc9063 | |||
dc7f839d3f | |||
0a33d078be | |||
1d64769094 | |||
2e3af64c02 |
@@ -4,6 +4,9 @@ repository-url="https://git.mimbach49.de/GerhardHoffmann"
|
||||
[DIRECTORIES]
|
||||
plugin-directory="/usr/lib/"
|
||||
working-directory="/opt/app/tools/atbupdate/"
|
||||
psa-config-directory="etc/psa_config/"
|
||||
psa-tariff-directory="etc/psa_tariff/"
|
||||
|
||||
|
||||
[PLUGINS]
|
||||
plugin-name="libCAslave.so"
|
||||
|
@@ -90,7 +90,8 @@ HEADERS += \
|
||||
../common/include/System.h
|
||||
|
||||
OTHER_FILES += \
|
||||
ATBDownloadDCJsonFiles.ini
|
||||
ATBDownloadDCJsonFiles.ini \
|
||||
../ATBUpdateTool.ini
|
||||
|
||||
|
||||
##########################################################################################
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "commandline_parser.h"
|
||||
#include "utils.h"
|
||||
#include "update.h"
|
||||
#include "System.h"
|
||||
|
||||
#include <DeviceController/interfaces.h>
|
||||
|
||||
@@ -68,6 +69,8 @@ int main(int argc, char **argv) {
|
||||
QString plugInDir = parser.plugInDir();
|
||||
QString plugInName = parser.plugInName();
|
||||
QString workingDir = parser.workingDir();
|
||||
QString psaConfigDir = parser.psaConfigDir();
|
||||
QString psaTariffDir = parser.psaTariffDir();
|
||||
QString iniFileName = parser.iniFileName();
|
||||
bool const dryRun = parser.dryRun();
|
||||
bool const noUpdatePsaHardware = parser.noUpdatePsaHardware();
|
||||
@@ -90,6 +93,8 @@ int main(int argc, char **argv) {
|
||||
qInfo() << "plugInDir ................" << plugInDir;
|
||||
qInfo() << "plugInName ..............." << plugInName;
|
||||
qInfo() << "workingDir ..............." << workingDir;
|
||||
qInfo() << "psaConfigDir ............." << psaConfigDir;
|
||||
qInfo() << "psaTariffDir ............." << psaTariffDir;
|
||||
qInfo() << "dryRun ..................." << dryRun;
|
||||
qInfo() << "noUpdatePsaHardware ......" << noUpdatePsaHardware;
|
||||
qInfo() << "alwaysDownloadConfig ....." << alwaysDownloadConfig;
|
||||
@@ -108,28 +113,31 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString const customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
|
||||
|
||||
qCritical() << "Using customer repository" << customerRepo;
|
||||
|
||||
// always execute contents of opkg_commands-file
|
||||
QString const &customerRepo = QDir::cleanPath(workingDir + QDir::separator() + QString("customer_%1").arg(customerNr));
|
||||
QStringList filesToUpdate;
|
||||
|
||||
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
|
||||
|
||||
if (dir.exists()) {
|
||||
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
|
||||
if (!jsons.isEmpty()) {
|
||||
for (QStringList::size_type i=0; i<jsons.size(); ++i) {
|
||||
filesToUpdate << QDir::cleanPath(QString("etc/psa_config/") + jsons.at(i));
|
||||
}
|
||||
}
|
||||
// etc/psa_config: located under mount-path
|
||||
std::optional<QString> mountPath = System::checkForUSBStick(psaConfigDir);
|
||||
if (mountPath.has_value()) {
|
||||
filesToUpdate = System::getJsonFilesOnUsbStick(mountPath.value());
|
||||
} else {
|
||||
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
|
||||
return -1;
|
||||
qCritical() << "Using customer repository" << customerRepo;
|
||||
|
||||
QDir dir(QDir::cleanPath(customerRepo + QDir::separator() + "etc/psa_config"));
|
||||
if (dir.exists()) {
|
||||
QStringList jsons = dir.entryList(QStringList() << "DC2C*.json", QDir::Files);
|
||||
if (!jsons.isEmpty()) {
|
||||
for (QStringList::size_type i=0; i<jsons.size(); ++i) {
|
||||
filesToUpdate << QDir::cleanPath(QString("etc/psa_config/") + jsons.at(i));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << "DIRECTORY" << dir << "DOES NOT EXIST";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
|
||||
// qCritical() << "JSON FILES TO UPDATE" << filesToUpdate;
|
||||
|
||||
Update update(customerRepo,
|
||||
QString::number(customerNr),
|
||||
@@ -138,10 +146,13 @@ int main(int argc, char **argv) {
|
||||
plugInName,
|
||||
workingDir);
|
||||
|
||||
//update.checkJsonVersions();
|
||||
update.doUpdate(filesToUpdate);
|
||||
update.checkJsonVersions(filesToUpdate);
|
||||
update.doUpdate(filesToUpdate, mountPath.has_value());
|
||||
update.checkJsonVersions();
|
||||
//update.checkJsonVersions(filesToUpdate);
|
||||
|
||||
if (mountPath.has_value()) {
|
||||
System::umountUSBStick();
|
||||
}
|
||||
|
||||
//return a.exec();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -138,10 +138,11 @@ Update::~Update() {
|
||||
unloadDCPlugin();
|
||||
}
|
||||
|
||||
bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
||||
bool Update::doUpdate(QStringList const &filesToWorkOn, bool usbStickDetected) {
|
||||
|
||||
if (!m_hw) {
|
||||
qCritical() << "ERROR!!! m_hw == nullptr";
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! m_hw == nullptr";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -149,10 +150,12 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
||||
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
||||
// must deliver 'true', only then are all data from hwapi valid
|
||||
if (--tries < 0) {
|
||||
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
|
||||
return false;
|
||||
}
|
||||
qCritical() << "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
|
||||
m_hw->dc_autoRequest(true);
|
||||
QThread::msleep(500);
|
||||
}
|
||||
@@ -161,7 +164,8 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
||||
|
||||
QList<QString>::const_iterator it;
|
||||
for (it = filesToWorkOn.cbegin(); it != filesToWorkOn.cend(); ++it) {
|
||||
QString const &fToWorkOn = QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
|
||||
QString const &fToWorkOn = usbStickDetected ? QDir::cleanPath(it->trimmed())
|
||||
: QDir::cleanPath(m_customerRepository + QDir::separator() + it->trimmed());
|
||||
if (fToWorkOn.contains("DC2C_print", Qt::CaseInsensitive)
|
||||
&& fToWorkOn.endsWith(".json", Qt::CaseInsensitive)) {
|
||||
res = true;
|
||||
@@ -203,6 +207,25 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
||||
}
|
||||
|
||||
bool Update::checkJsonVersions(QStringList const& jsonFileNames) {
|
||||
if (!m_hw) {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! m_hw == nullptr";
|
||||
return false;
|
||||
}
|
||||
|
||||
int tries = 20;
|
||||
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
||||
// must deliver 'true', only then are all data from hwapi valid
|
||||
if (--tries < 0) {
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED";
|
||||
return false;
|
||||
}
|
||||
qCritical() << "(" << __func__ << ":" << __LINE__ << "):"
|
||||
<< "ERROR!!! DC DATA NOT VALID -> CA-SLAVE-PLUGIN NOT CONNECTED (" << tries << ")";
|
||||
m_hw->dc_autoRequest(true);
|
||||
QThread::msleep(500);
|
||||
}
|
||||
|
||||
for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
|
||||
|
||||
@@ -231,6 +254,7 @@ bool Update::checkJsonVersions(QStringList const& jsonFileNames) {
|
||||
bool ok = false;
|
||||
int n = captured.toInt(&ok);
|
||||
if (ok) {
|
||||
// note: use 5 (instead of 4 -> index has been shifted)
|
||||
jsonNr = n + 5;
|
||||
}
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
virtual ~Update() override;
|
||||
|
||||
bool doUpdate(QStringList const &jsonFilesToDownload);
|
||||
bool doUpdate(QStringList const &jsonFilesToDownload, bool usbStickDetected = false);
|
||||
|
||||
bool updatePrinterTemplate(int templateIdx, QString fname) const;
|
||||
bool updateConfig(QString jsFileToSendToDC);
|
||||
|
@@ -123,7 +123,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
# Check m_hw (pointer to CA-(Slave)Plugin) before its use.
|
||||
# Only exit() if firmware is configured to be possibly updated, but
|
||||
# loading the CA-plugin failed.
|
||||
VERSION="1.4.7"
|
||||
# 1.4.7 : Read Json-file versions of Json-files actually loaded into DC.
|
||||
VERSION="1.4.8"
|
||||
# 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
|
||||
|
@@ -60,6 +60,16 @@ CommandLineParser::CommandLineParser()
|
||||
QStringList() << "working-directory" << "working-directory",
|
||||
QCoreApplication::translate("main", "working directory of update-script."),
|
||||
QCoreApplication::translate("main", "directory")))
|
||||
, m_psaConfigDirectoryOption(
|
||||
QCommandLineOption(
|
||||
QStringList() << "psa-config-directory" << "psa-config-directory",
|
||||
QCoreApplication::translate("main", "config directory of json-files sent to dc."),
|
||||
QCoreApplication::translate("main", "directory")))
|
||||
, m_psaTariffDirectoryOption(
|
||||
QCommandLineOption(
|
||||
QStringList() << "psa-tariff-directory" << "psa-tariff-directory",
|
||||
QCoreApplication::translate("main", "tariff directory of tariff-json-files."),
|
||||
QCoreApplication::translate("main", "directory")))
|
||||
, m_dryRunOption(
|
||||
QCommandLineOption(
|
||||
QStringList() << "d" << "dry-run",
|
||||
@@ -111,6 +121,12 @@ void CommandLineParser::configure() {
|
||||
m_workingDirectoryOption.setDefaultValue("/opt/app/tools/atbupdate/");
|
||||
m_parser.addOption(m_workingDirectoryOption);
|
||||
|
||||
m_psaConfigDirectoryOption.setDefaultValue("etc/psa_config/");
|
||||
m_parser.addOption(m_psaConfigDirectoryOption);
|
||||
|
||||
m_psaTariffDirectoryOption.setDefaultValue("etc/psa_tariff/");
|
||||
m_parser.addOption(m_psaTariffDirectoryOption);
|
||||
|
||||
m_dryRunOption.setDefaultValue("false");
|
||||
m_parser.addOption(m_dryRunOption);
|
||||
|
||||
@@ -151,6 +167,12 @@ void CommandLineParser::readSettings() {
|
||||
if (key.contains("working-directory")) {
|
||||
m_workingDir = v.toString();
|
||||
} else
|
||||
if (key.contains("psa-config-directory")) {
|
||||
m_psaConfigDir = v.toString();
|
||||
} else
|
||||
if (key.contains("psa-tariff-directory")) {
|
||||
m_psaTariffDir = v.toString();
|
||||
} else
|
||||
if (key.contains("dry-run")) {
|
||||
m_dryRun = (v.toBool() ? "true" : "false");
|
||||
} else
|
||||
@@ -207,6 +229,20 @@ QString CommandLineParser::plugInName() {
|
||||
return m_plugInName;
|
||||
}
|
||||
|
||||
QString CommandLineParser::psaConfigDir() {
|
||||
if (m_parser.isSet(m_psaConfigDirectoryOption)) {
|
||||
m_psaConfigDir = m_parser.value(m_psaConfigDirectoryOption);
|
||||
}
|
||||
return m_psaConfigDir;
|
||||
}
|
||||
|
||||
QString CommandLineParser::psaTariffDir() {
|
||||
if (m_parser.isSet(m_psaTariffDirectoryOption)) {
|
||||
m_psaTariffDir = m_parser.value(m_psaTariffDirectoryOption);
|
||||
}
|
||||
return m_psaTariffDir;
|
||||
}
|
||||
|
||||
QString CommandLineParser::workingDir() {
|
||||
if (m_parser.isSet(m_workingDirectoryOption)) {
|
||||
m_workingDir = m_parser.value(m_workingDirectoryOption);
|
||||
|
@@ -11,6 +11,8 @@ class CommandLineParser : public QCommandLineParser {
|
||||
QString m_plugInDir;
|
||||
QString m_plugInName;
|
||||
QString m_workingDir;
|
||||
QString m_psaConfigDir;
|
||||
QString m_psaTariffDir;
|
||||
QString m_dryRun;
|
||||
QString m_noUpdatePsaHardware;
|
||||
QString m_showYoctoVersion;
|
||||
@@ -29,6 +31,8 @@ class CommandLineParser : public QCommandLineParser {
|
||||
QCommandLineOption m_alwaysDownloadConfigOption;
|
||||
QCommandLineOption m_alwaysDownloadDCOption;
|
||||
QCommandLineOption m_workingDirectoryOption;
|
||||
QCommandLineOption m_psaConfigDirectoryOption;
|
||||
QCommandLineOption m_psaTariffDirectoryOption;
|
||||
QCommandLineOption m_dryRunOption;
|
||||
QCommandLineOption m_extendedVersionOption;
|
||||
QCommandLineOption m_yoctoVersionOption;
|
||||
@@ -52,6 +56,8 @@ public:
|
||||
QString plugInDir();
|
||||
QString plugInName();
|
||||
QString workingDir();
|
||||
QString psaConfigDir();
|
||||
QString psaTariffDir();
|
||||
bool dryRun();
|
||||
bool noUpdatePsaHardware();
|
||||
bool yoctoVersion();
|
||||
|
@@ -592,23 +592,31 @@ QStringList Update::getDcSoftAndHardWareVersion() {
|
||||
|
||||
QString Update::getFileVersion(QString const& jsonFileName) {
|
||||
// "version":"15.10.2023 14:55 02.00.06",
|
||||
static const QRegularExpression re("^.*(\\\"version\\\":)(.*)$");
|
||||
static const QRegularExpression re("^.*(\\\"[Vv]ersion\\\":)([\\s\\\"]{0,})([^,\\\"]{0,}).*$");
|
||||
|
||||
QString fileVersion;
|
||||
QFile inputFile(jsonFileName);
|
||||
if (inputFile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream in(&inputFile);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
QString fileVersion("");
|
||||
QFile inputFile(QDir::cleanPath(m_customerRepository + QDir::separator() + jsonFileName));
|
||||
|
||||
QRegularExpressionMatch match;
|
||||
int idx = line.indexOf(re, 0, &match);
|
||||
if (idx != -1) {
|
||||
fileVersion = match.captured(match.lastCapturedIndex());
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
if (inputFile.exists()) {
|
||||
if (inputFile.open(QIODevice::ReadOnly)) {
|
||||
QTextStream in(&inputFile);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
|
||||
QRegularExpressionMatch match;
|
||||
int idx = line.indexOf(re, 0, &match);
|
||||
if (idx != -1) {
|
||||
int const lastCaptured = match.lastCapturedIndex();
|
||||
// the dc only sends 16 Byte
|
||||
fileVersion = match.captured(lastCaptured);
|
||||
fileVersion.truncate(16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
}
|
||||
} else {
|
||||
// qCritical() << "ERROR" << inputFile.fileName() << "does not exist";
|
||||
}
|
||||
|
||||
return fileVersion;
|
||||
@@ -619,58 +627,79 @@ bool Update::checkDownloadedJsonVersions(QStringList const& jsonFileNames) {
|
||||
for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
|
||||
|
||||
uint8_t jsonNr = 0;
|
||||
QFileInfo fInfo(jsonFileNames[i]);
|
||||
|
||||
if (fInfo.fileName().endsWith("conf.json")) {
|
||||
QString const &fName = jsonFileNames[i];
|
||||
|
||||
// send one request for every single version
|
||||
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res.
|
||||
// 6=printer template 1 ..... 36= template 32
|
||||
|
||||
if (fName.endsWith("conf.json")) {
|
||||
jsonNr = 1;
|
||||
} else
|
||||
if (fInfo.fileName().endsWith("device.json")) {
|
||||
if (fName.endsWith("device.json")) {
|
||||
jsonNr = 2;
|
||||
} else
|
||||
if (fInfo.fileName().endsWith("cash.json")) {
|
||||
if (fName.endsWith("cash.json")) {
|
||||
jsonNr = 3;
|
||||
} else {
|
||||
QRegularExpressionMatch match;
|
||||
static const QRegularExpression re("^(.*print)([0-3][0-9])\\.json\\s*$");
|
||||
int idx = fInfo.fileName().indexOf(re, 0, &match);
|
||||
int idx = fName.indexOf(re, 0, &match);
|
||||
if (idx != -1) {
|
||||
QString captured = match.captured(match.lastCapturedIndex());
|
||||
bool ok = false;
|
||||
int n = captured.toInt(&ok);
|
||||
if (ok) {
|
||||
jsonNr = n + 4;
|
||||
// note: the '5' is correct
|
||||
jsonNr = n + 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonNr != 0) {
|
||||
#if 0
|
||||
// send one request for every single version
|
||||
// jsonNr=1...36, 1=config file (cust.Nr) 2=devices 3=cash 4=res.
|
||||
// 5=printer template 1 ..... 36= template 32
|
||||
|
||||
m_hw->sys_requestJsonVersions(jsonNr);
|
||||
QThread::msleep(500);
|
||||
|
||||
char buf[64];
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
m_hw->sys_getJsonVersions(jsonNr, buf);
|
||||
buf[sizeof(buf)-1] = '\0';
|
||||
buf[16] = '\0'; // the DC only handles 16 bytes
|
||||
|
||||
QString const installedVersion(buf);
|
||||
static const QByteArray cb(16, (char)0xff);
|
||||
|
||||
QString const installedVersion(QString::fromStdString(buf));
|
||||
QString const fileVersion = getFileVersion(jsonFileNames[i]);
|
||||
|
||||
qCritical() << "installed version:" << installedVersion;
|
||||
qCritical() << " file version:" << fileVersion;
|
||||
QFileInfo fi(jsonFileNames[i]);
|
||||
|
||||
qCritical() << endl;
|
||||
qCritical() << " json request nr:" << jsonNr;
|
||||
|
||||
if (installedVersion == fileVersion) {
|
||||
|
||||
qCritical() << " json file:" << fi.fileName();
|
||||
qCritical() << " installed version in DC:" << installedVersion;
|
||||
} else
|
||||
if (cb == QByteArray(buf) && fileVersion == "") {
|
||||
qCritical() << "unknown json file (repo and DC):" << fi.fileName();
|
||||
} else {
|
||||
qCritical() << " json file:" << fi.fileName();
|
||||
qCritical() << " installed version in DC:" << installedVersion;
|
||||
qCritical() << " file version in repository:" << fileVersion;
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
qCritical() << "CANNOT FIND JSON-NR FOR" << jsonFileNames[i];
|
||||
qCritical() << "CANNOT FIND JSON-NR FOR" << fName;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||
|
||||
if (!m_hw) {
|
||||
|
@@ -869,6 +869,7 @@ bool Worker::execOpkgCommands() {
|
||||
QStringList opkgErrorLst;
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
// TODO: "^\\s*[#]{0,}$" : empty line or comment line starting with #
|
||||
static const QRegularExpression comment("^\\s*#.*$");
|
||||
if (line.indexOf(comment, 0) == -1) {
|
||||
// found opkg command
|
||||
|
@@ -3,6 +3,10 @@
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <optional>
|
||||
#include <initializer_list>
|
||||
|
||||
class System : public QObject
|
||||
{
|
||||
@@ -13,16 +17,17 @@ private:
|
||||
|
||||
static QString errorMsg;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
static const QStringList allowedJsonFiles;
|
||||
|
||||
static bool checkForSDCard();
|
||||
static bool umountSDCard();
|
||||
|
||||
static bool checkForUSBStick();
|
||||
static QString getUSBMountPath();
|
||||
static QString getUSBDeviceName();
|
||||
static std::optional<QString> checkForUSBStick(QString const &dirPathUnderMountPath = ".");
|
||||
static QString getUSBMountPath(QString const &dirPathUnderMountPath = ".");
|
||||
|
||||
//static QString getUSBDeviceName();
|
||||
static bool umountUSBStick();
|
||||
|
||||
static bool test_mount(const QString& dev, const QString &mountpoint);
|
||||
@@ -48,7 +53,7 @@ public:
|
||||
static QString getPTU4SerialNumber();
|
||||
static QString getPTU4MACAddress();
|
||||
|
||||
|
||||
static QStringList getJsonFilesOnUsbStick(QString const &mountPath);
|
||||
|
||||
};
|
||||
|
||||
|
@@ -7,10 +7,52 @@
|
||||
#include <QRegExp>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
#include <QDirIterator>
|
||||
|
||||
//#include "version.h"
|
||||
|
||||
|
||||
|
||||
|
||||
const QStringList System::allowedJsonFiles =
|
||||
std::initializer_list<QString>{
|
||||
QString("DC2C_conf.json"),
|
||||
QString("DC2C_cash.json"),
|
||||
QString("DC2C_device.json"),
|
||||
QString("DC2C_print01.json"),
|
||||
QString("DC2C_print02.json"),
|
||||
QString("DC2C_print03.json"),
|
||||
QString("DC2C_print04.json"),
|
||||
QString("DC2C_print05.json"),
|
||||
QString("DC2C_print06.json"),
|
||||
QString("DC2C_print07.json"),
|
||||
QString("DC2C_print08.json"),
|
||||
QString("DC2C_print09.json"),
|
||||
QString("DC2C_print10.json"),
|
||||
QString("DC2C_print11.json"),
|
||||
QString("DC2C_print12.json"),
|
||||
QString("DC2C_print13.json"),
|
||||
QString("DC2C_print14.json"),
|
||||
QString("DC2C_print15.json"),
|
||||
QString("DC2C_print16.json"),
|
||||
QString("DC2C_print17.json"),
|
||||
QString("DC2C_print18.json"),
|
||||
QString("DC2C_print19.json"),
|
||||
QString("DC2C_print20.json"),
|
||||
QString("DC2C_print21.json"),
|
||||
QString("DC2C_print22.json"),
|
||||
QString("DC2C_print23.json"),
|
||||
QString("DC2C_print24.json"),
|
||||
QString("DC2C_print25.json"),
|
||||
QString("DC2C_print26.json"),
|
||||
QString("DC2C_print27.json"),
|
||||
QString("DC2C_print28.json"),
|
||||
QString("DC2C_print29.json"),
|
||||
QString("DC2C_print30.json"),
|
||||
QString("DC2C_print31.json"),
|
||||
QString("DC2C_print32.json")
|
||||
};
|
||||
|
||||
QString System::errorMsg = "";
|
||||
|
||||
System::System(QObject *parent) :
|
||||
@@ -209,8 +251,7 @@ bool System::test_dir(const QString& dir)
|
||||
|
||||
|
||||
|
||||
bool System::checkForUSBStick()
|
||||
{
|
||||
std::optional<QString> System::checkForUSBStick(QString const &dirPathUnderMountPath) {
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
if (QFileInfo(getUSBMountPath()).isDir())
|
||||
@@ -219,11 +260,9 @@ bool System::checkForUSBStick()
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (getUSBMountPath().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
QString const &mountPath = getUSBMountPath(dirPathUnderMountPath);
|
||||
// qCritical() << "MOUNT-PATH" << mountPath;
|
||||
return mountPath.isEmpty() ? std::nullopt : std::optional<QString>(mountPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -235,8 +274,7 @@ bool System::checkForUSBStick()
|
||||
* Note, do not return an empty string ("") here because a calling method (which could not be
|
||||
* identified till now) is relying on this!
|
||||
*/
|
||||
QString System::getUSBMountPath()
|
||||
{
|
||||
QString System::getUSBMountPath(QString const &dirPathUnderMountPath) {
|
||||
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
@@ -277,8 +315,13 @@ QString System::getUSBMountPath()
|
||||
|
||||
mountLine = line.split(' ');
|
||||
if (mountLine.size() > 3) {
|
||||
qDebug() << "System::getUSBMountPath(): " << mountLine.at(0) << " is mounted on " << mountLine.at(2);
|
||||
return mountLine.at(2);
|
||||
qCritical() << "System::getUSBMountPath(): " << mountLine.at(0) << " is mounted on " << mountLine.at(2);
|
||||
QDir d(QDir::cleanPath(mountLine.at(2) + QDir::separator() + dirPathUnderMountPath));
|
||||
if (d.exists()) {
|
||||
return mountLine.at(2);
|
||||
} else {
|
||||
qCritical() << "directory" << d.absolutePath() << "does not exist";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -289,6 +332,27 @@ QString System::getUSBMountPath()
|
||||
return "";
|
||||
}
|
||||
|
||||
QStringList System::getJsonFilesOnUsbStick(QString const &mountPath) {
|
||||
QStringList jsonFiles;
|
||||
|
||||
// /media/sda2/etc/psa_config
|
||||
QString const &dirPath = QDir::cleanPath(mountPath + QDir::separator() + "etc" + QDir::separator() + "psa_config");
|
||||
QDir d(dirPath);
|
||||
if (d.exists()) {
|
||||
QDirIterator it(dirPath, QStringList() << "*.json", QDir::Files, QDirIterator::NoIteratorFlags);
|
||||
while (it.hasNext()) {
|
||||
QString const &jsonFile = it.next();
|
||||
QFileInfo fi(jsonFile);
|
||||
if (System::allowedJsonFiles.contains(fi.fileName())) {
|
||||
jsonFiles << jsonFile;
|
||||
} else {
|
||||
qCritical() << "Warning:" << fi.fileName() << "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jsonFiles;
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* static function to check if a mounted sd-card is writable.
|
||||
|
Reference in New Issue
Block a user