Compare commits

...

3 Commits

2 changed files with 59 additions and 30 deletions

View File

@ -123,7 +123,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
# Check m_hw (pointer to CA-(Slave)Plugin) before its use. # Check m_hw (pointer to CA-(Slave)Plugin) before its use.
# Only exit() if firmware is configured to be possibly updated, but # Only exit() if firmware is configured to be possibly updated, but
# loading the CA-plugin failed. # 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: # 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

@ -592,23 +592,31 @@ QStringList Update::getDcSoftAndHardWareVersion() {
QString Update::getFileVersion(QString const& jsonFileName) { QString Update::getFileVersion(QString const& jsonFileName) {
// "version":"15.10.2023 14:55 02.00.06", // "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; QString fileVersion("");
QFile inputFile(jsonFileName); QFile inputFile(QDir::cleanPath(m_customerRepository + QDir::separator() + jsonFileName));
if (inputFile.open(QIODevice::ReadOnly)) {
QTextStream in(&inputFile);
while (!in.atEnd()) {
QString line = in.readLine();
QRegularExpressionMatch match; if (inputFile.exists()) {
int idx = line.indexOf(re, 0, &match); if (inputFile.open(QIODevice::ReadOnly)) {
if (idx != -1) { QTextStream in(&inputFile);
fileVersion = match.captured(match.lastCapturedIndex()); while (!in.atEnd()) {
break; QString line = in.readLine();
}
} QRegularExpressionMatch match;
inputFile.close(); 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; return fileVersion;
@ -619,58 +627,78 @@ bool Update::checkDownloadedJsonVersions(QStringList const& jsonFileNames) {
for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) { for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
uint8_t jsonNr = 0; 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; jsonNr = 1;
} else } else
if (fInfo.fileName().endsWith("device.json")) { if (fName.endsWith("device.json")) {
jsonNr = 2; jsonNr = 2;
} else } else
if (fInfo.fileName().endsWith("cash.json")) { if (fName.endsWith("cash.json")) {
jsonNr = 3; jsonNr = 3;
} else { } else {
QRegularExpressionMatch match; QRegularExpressionMatch match;
static const QRegularExpression re("^(.*print)([0-3][0-9])\\.json\\s*$"); 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) { if (idx != -1) {
QString captured = match.captured(match.lastCapturedIndex()); QString captured = match.captured(match.lastCapturedIndex());
bool ok = false; bool ok = false;
int n = captured.toInt(&ok); int n = captured.toInt(&ok);
if (ok) { if (ok) {
jsonNr = n + 4; jsonNr = n + 5;
} }
} }
} }
if (jsonNr != 0) { 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); m_hw->sys_requestJsonVersions(jsonNr);
QThread::msleep(500); QThread::msleep(500);
char buf[64]; char buf[64];
memset(buf, 0x00, sizeof(buf)); memset(buf, 0x00, sizeof(buf));
m_hw->sys_getJsonVersions(jsonNr, 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]); QString const fileVersion = getFileVersion(jsonFileNames[i]);
qCritical() << "installed version:" << installedVersion; QFileInfo fi(jsonFileNames[i]);
qCritical() << " file version:" << fileVersion;
qCritical() << endl;
qCritical() << " json request nr:" << jsonNr;
if (installedVersion == fileVersion) { 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 { } else {
qCritical() << "CANNOT FIND JSON-NR FOR" << jsonFileNames[i]; qCritical() << "CANNOT FIND JSON-NR FOR" << fName;
} }
} }
return false; return false;
} }
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) { bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
if (!m_hw) { if (!m_hw) {