From da66d75a455f0d811d7db3c2034049f5740148b7 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 21 Nov 2024 09:14:05 +0100 Subject: [PATCH] getPSAInstalled(): call ptuPackagesVersion. Convert returned JSON-array into JsonObject to be appended to CMD_SENDVERSION. --- UpdatePTUDevCtrl/worker.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/UpdatePTUDevCtrl/worker.cpp b/UpdatePTUDevCtrl/worker.cpp index e7d9081..603debd 100644 --- a/UpdatePTUDevCtrl/worker.cpp +++ b/UpdatePTUDevCtrl/worker.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "message_handler.h" #include @@ -1461,5 +1462,41 @@ PSAInstalled Worker::getPSAInstalled() { } } + psaInstalled.ptuPackageVersion = "{}"; + if (QFile::exists("/usr/bin/ptuPackageVersions")) { + Command c("/usr/bin/ptuPackageVersions -i -o json"); + if (c.execute(m_workingDirectory)) { + QString r = c.getCommandResult(); + // ptuPackageVersions returns a json-array + QJsonArray const &ja = QJsonDocument::fromJson(r.remove(QRegExp("\\n")).toUtf8()).array(); + if (!ja.empty()) { + // transform the array into an object, containing the objects + // of the array (christian needs it this way) + QJsonObject o; + foreach (QJsonValue const &value, ja) { + if (value.isObject()) { + QJsonObject obj = value.toObject(); + QStringList keys = obj.keys(); + if (!keys.isEmpty()) { + QString const &k = obj.keys().first(); + QJsonValue const &v = obj.value(k); + o.insert(k, v); + } + } + } + + psaInstalled.ptuPackageVersion = + QJsonDocument(o).toJson(QJsonDocument::Compact); + + } else { + qCritical() << __func__ << ":" << __LINE__ + << "ERROR array return by ptuPackageVersions empty"; + } + } else { + qCritical() << __func__ << ":" << __LINE__ + << "ERROR executing ptuPackageVersions"; + } + } + return psaInstalled; }