aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/help/VersionCheckThread.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-07-12 09:03:12 +0000
committerSaturneric <[email protected]>2021-07-12 09:03:12 +0000
commit4ada913c515cf090c65d9d155aa9880a50501591 (patch)
tree72043033991b643a2cce437f22497a961d73a745 /src/ui/help/VersionCheckThread.cpp
parentUpdate Documents; Update UI (diff)
downloadGpgFrontend-4ada913c515cf090c65d9d155aa9880a50501591.tar.gz
GpgFrontend-4ada913c515cf090c65d9d155aa9880a50501591.zip
Project structure adjustment;
Project configuration adjustment; Add version detection; UI interface improvements; Introduce JSON processing library; Update Documents;
Diffstat (limited to '')
-rw-r--r--src/ui/help/VersionCheckThread.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ui/help/VersionCheckThread.cpp b/src/ui/help/VersionCheckThread.cpp
new file mode 100644
index 00000000..7bd0eb8f
--- /dev/null
+++ b/src/ui/help/VersionCheckThread.cpp
@@ -0,0 +1,50 @@
+//
+// Created by Administrator on 2021/7/12.
+//
+
+#include "ui/help/VersionCheckThread.h"
+#include "GpgFrontendBuildInfo.h"
+#include "rapidjson/document.h"
+#include "rapidjson/writer.h"
+
+using namespace rapidjson;
+
+void VersionCheckThread::run() {
+ qDebug() << "Start Version Thread to get latest version from Github";
+
+ auto currentVersion = "v" + QString::number(VERSION_MAJOR) + "."
+ + QString::number(VERSION_MINOR) + "."
+ + QString::number(VERSION_PATCH);
+
+ while(mNetworkReply->isRunning()) {
+ QApplication::processEvents();
+ }
+
+ QByteArray bytes = mNetworkReply->readAll();
+
+ Document d;
+ d.Parse(bytes.constData());
+
+ QString latestVersion = d["tag_name"].GetString();
+
+ qDebug() << "Latest Version From Github" << latestVersion;
+
+ QRegularExpression re("^[vV](\\d+\\.)?(\\d+\\.)?(\\*|\\d+)");
+ QRegularExpressionMatch match = re.match(latestVersion);
+ if (match.hasMatch()) {
+ latestVersion = match.captured(0); // matched == "23 def"
+ qDebug() << "Latest Version Matched" << latestVersion;
+ } else {
+ latestVersion = currentVersion;
+ qDebug() << "Latest Version Unknown" << latestVersion;
+ }
+
+ if(latestVersion != currentVersion) {
+ emit upgradeVersion(currentVersion, latestVersion);
+ }
+
+}
+
+VersionCheckThread::VersionCheckThread(QNetworkReply *networkReply):mNetworkReply(networkReply) {
+
+}