diff options
author | Saturneric <[email protected]> | 2021-07-20 16:42:50 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-07-20 16:42:50 +0000 |
commit | c57feb6a678e27140bb9ae7d132b641947514c31 (patch) | |
tree | 5ed7a7728c084214ce858323a4eccdcba98200b6 /src/ui/help/VersionCheckThread.cpp | |
parent | Update Workflow (diff) | |
parent | Fix problem that macos cannot use multi-languages. (diff) | |
download | GpgFrontend-c57feb6a678e27140bb9ae7d132b641947514c31.tar.gz GpgFrontend-c57feb6a678e27140bb9ae7d132b641947514c31.zip |
Merge branch 'develop' into develop-ci
Diffstat (limited to '')
-rw-r--r-- | src/ui/help/VersionCheckThread.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/ui/help/VersionCheckThread.cpp b/src/ui/help/VersionCheckThread.cpp new file mode 100644 index 00000000..c7c77d1c --- /dev/null +++ b/src/ui/help/VersionCheckThread.cpp @@ -0,0 +1,55 @@ +// +// 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(); + } + + if(mNetworkReply->error() != QNetworkReply::NoError) { + qDebug() << "VersionCheckThread Found Network Error"; + return; + } + + 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) { + +} |