From c97c831b5cdc5008436733ffcca8946e666c03c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BE=AF=E7=BA=A2=E5=8B=8B?= <houhongxun@kylinos.cn>
Date: Wed, 17 Apr 2024 14:40:24 +0800
Subject: [PATCH] kylin-burner: fix version showing "none" on about dialog
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: 侯红勋 <houhongxun@kylinos.cn>
---
 src/view/kybaboutdialog.cpp | 38 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)

diff --git a/src/view/kybaboutdialog.cpp b/src/view/kybaboutdialog.cpp
index b8c4201..9e20b7e 100644
--- a/src/view/kybaboutdialog.cpp
+++ b/src/view/kybaboutdialog.cpp
@@ -31,12 +31,12 @@
 #include <QStyle>
 #include <QDesktopServices>
 #include <QScrollBar>
+#include <QRegularExpression>
+#include <QProcess>
 
 KYBAboutDialog *KYBAboutDialog::m_oInstance = nullptr;
 QMutex          KYBAboutDialog::m_oMutex;
 
-#define VERSION "3.10.3"
-
 #include <QDebug>
 
 KYBAboutDialog::KYBAboutDialog(QWidget *parent) :
@@ -211,31 +211,19 @@ KYBAboutDialog::~KYBAboutDialog()
 
 QString KYBAboutDialog::getCurrentVersion()
 {
-    FILE *pp = NULL;
-    char *line = NULL;
-    size_t len = 0;
-    ssize_t read;
-    char *q = NULL;
-    QString version = tr("none");
-
-    pp = popen("dpkg -l kylin-burner", "r");
-    if(NULL == pp)
-        return version;
+	QProcess v_p;
+	v_p.start("rpm", QStringList() << "-q" << "kylin-burner");
 
-    while((read = getline(&line, &len, pp)) != -1){
-        q = strrchr(line, '\n');
-        *q = '\0';
+	if (!v_p.waitForFinished())
+		return "none";
 
-        QString content = line;
-        QStringList list = content.split(" ");
+	QByteArray ba = v_p.readAllStandardOutput();
 
-        list.removeAll("");
-
-        if (list.size() >= 3)
-            version = list.at(2);
-    }
+	QRegularExpression qe("-([^-]+)-[^-]+\n$");
 
-    free(line);
-    pclose(pp);
-    return version;
+	QRegularExpressionMatch qem = qe.match(ba);
+	if (qem.hasMatch()) {
+		return qem.captured(1);
+	}
+	return "none";
 }
-- 
2.43.0

