From 24addad11e64584d89c2982ecf39a456c5e40cbf Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 8 May 2024 16:09:18 +0200 Subject: [PATCH] Implement getFileversion(). --- DownloadDCJsonFiles/update.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/DownloadDCJsonFiles/update.cpp b/DownloadDCJsonFiles/update.cpp index dded6e9..420b895 100644 --- a/DownloadDCJsonFiles/update.cpp +++ b/DownloadDCJsonFiles/update.cpp @@ -279,6 +279,39 @@ bool Update::checkJsonVersions(QStringList const& jsonFileNames) { return false; } + +QString Update::getFileVersion(QString const& jsonFileName) { + // "version":"15.10.2023 14:55 02.00.06", + static const QRegularExpression re("^.*(\\\"[Vv]ersion\\\":)([\\s\\\"]{0,})([^,\\\"]{0,}).*$"); + + QString fileVersion(""); + QFile inputFile(QDir::cleanPath(m_customerRepository + QDir::separator() + jsonFileName)); + + 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; +} + bool Update::downloadJson(enum FileTypeJson type, int templateIdx, QString jsFileToSendToDC) const {