From 4ada913c515cf090c65d9d155aa9880a50501591 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Mon, 12 Jul 2021 17:03:12 +0800 Subject: Project structure adjustment; Project configuration adjustment; Add version detection; UI interface improvements; Introduce JSON processing library; Update Documents; --- src/ui/help/VersionCheckThread.cpp | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/ui/help/VersionCheckThread.cpp (limited to 'src/ui/help/VersionCheckThread.cpp') 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) { + +} -- cgit v1.2.3