From 739010ba59d5c5e9c869e9da6eab55b8428efdde Mon Sep 17 00:00:00 2001
From: Gerhard Hoffmann <g.hoffmann@atb-online.eu>
Date: Fri, 7 Mar 2025 12:20:40 +0100
Subject: [PATCH] readyReadStandardOutput(): 	parse outout of ATBUpdateDC.

---
 .../process/update_dc_command.cpp             | 42 ++++++++++++++++---
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/UpdatePTUDevCtrl/process/update_dc_command.cpp b/UpdatePTUDevCtrl/process/update_dc_command.cpp
index dba1c3e..241812f 100644
--- a/UpdatePTUDevCtrl/process/update_dc_command.cpp
+++ b/UpdatePTUDevCtrl/process/update_dc_command.cpp
@@ -21,13 +21,45 @@ void UpdateDCCommand::finished(int exitCode, QProcess::ExitStatus exitStatus) {
 void UpdateDCCommand::readyReadStandardOutput() {
     QProcess *p = (QProcess *)sender();
     if (p) {
-        QString s = p->readAllStandardOutput();
-
-        // TODO
         Worker *w = worker();
         if (w) {
-    // static constexpr const char *UPDATE_DC_FIRMARE_SUCCESS"success"};
-            emit w->showUpdateDCFirmware(UpdateCommand::UPDATE_DC_FIRMARE_SUCCESS);
+            QString s = p->readAllStandardOutput();
+            int i = -1;
+            if ((i = s.indexOf("<DC-VERSION>")) != -1) {
+                s = s.mid(i+12).trimmed();
+                if ((i = s.indexOf("\"")) != -1) {
+                    s = s.mid(i+1);
+                    if ((i = s.indexOf("\"")) != -1) {
+                        s = s.mid(0, i).trimmed();
+                    }
+                }
+                // emit w->showDcDownload(s);
+            } else
+            if ((i = s.indexOf("<DC-PROGRESS>")) != -1) {
+                bool ok;
+                int v = s.mid(i+13).trimmed().toInt(&ok);
+                if (ok) {
+                    emit w->setDcDownloadProgress(v);
+                    emit w->insertText(s.mid(0,i) + "\n");
+                }
+            } else
+            if ((i = s.indexOf("<DC-UPDATE-FINISH>")) != -1) {
+                emit w->showUpdateDCFirmware(internal::UPDATE_DC_FIRMARE_SUCCESS);
+                // QThread::sleep(3);
+                // emit w->summary();
+                // qApp->exit(0);
+            } else
+            if ((i = s.indexOf("<DC-UPDATE-SUCCESS>")) != -1) {
+                // TODO
+                emit w->summary();
+            } else
+            if ((i = s.indexOf("<DC-UPDATE-FAILURE>")) != -1) {
+                emit w->summary();
+                //qApp->exit(-1);
+            } else {
+                emit w->insertText(s);
+            }
+            m_commandResult += s;
         }
     }
 }