From 8402fde6b59fb2e13f2851e0539813dfbf4fb30e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 29 Apr 2024 15:00:52 +0200 Subject: [PATCH] Reformat m_versionInfo in case a version is included in the commit-message. --- UpdatePTUDevCtrl/worker.cpp | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/UpdatePTUDevCtrl/worker.cpp b/UpdatePTUDevCtrl/worker.cpp index b0b279d..2e74058 100644 --- a/UpdatePTUDevCtrl/worker.cpp +++ b/UpdatePTUDevCtrl/worker.cpp @@ -1256,15 +1256,48 @@ PSAInstalled Worker::getPSAInstalled() { psaInstalled.versionInfo.created = "N/A"; if (m_versionInfo.size() == 3) { - qCritical() << QString("***** %1:%2").arg(__func__).arg(__LINE__) - << "m_versionInfo" << m_versionInfo << "*****"; - psaInstalled.versionInfo.lastCommit = QString("%1-%2") - .arg(QCoreApplication::applicationPid()) - .arg(m_versionInfo.at(0)); - psaInstalled.versionInfo.reason = m_versionInfo.at(1); + QString const &lastCommit = m_versionInfo.at(0); + QString reason = m_versionInfo.at(1); + QDateTime const dt = QDateTime::fromString(m_versionInfo.at(2), Qt::ISODate); + QString version{""}; + QString date{""}; + if (dt.isValid()) { + date += " "; + date += dt.date().toString(Qt::ISODate); + } + static const QRegularExpression re("^\\s*(\\d+)\\.(\\d+)\\.(\\d+)(.*$)"); + QRegularExpressionMatch match = re.match(reason); + if (match.hasMatch()) { + int const lastCapturedIndex = match.lastCapturedIndex(); + if (lastCapturedIndex >= 1) { + version += " v"; + version += match.captured(1); // major + } + if (lastCapturedIndex >= 2) { + version += "."; + version += match.captured(2); // minor + } + if (lastCapturedIndex >= 3) { + version += "."; + version += match.captured(3); // patch + } + if (lastCapturedIndex >= 4) { // rest after version + reason = match.captured(4); + } + } + + psaInstalled.versionInfo.lastCommit = QString("%1%2").arg(lastCommit).arg(version); + psaInstalled.versionInfo.reason = reason; psaInstalled.versionInfo.created = m_versionInfo.at(2); } + //qCritical() << ""; + //qCritical() << "VERSION-INFO"; + //qCritical() << "LAST-COMMIT" << psaInstalled.versionInfo.lastCommit; + //qCritical() << "REASON" << psaInstalled.versionInfo.reason; + //qCritical() << "CREATED" << psaInstalled.versionInfo.created; + //qCritical() << ""; + if (m_zoneNr != 0) { QString const &n = QString("%1").arg(m_zoneNr).rightJustified(2, '0'); psaInstalled.tariff.name = QString("tariff%1.json").arg(n);