From c8cde5086fc3e6726aa9507e9ebc96a856dc3469 Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Fri, 16 Nov 2018 09:10:26 +0000 Subject: [PATCH] [Launcher] Add update checking. --- CMakeLists.txt | 12 ++++++++++++ src/main.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52d32eb..462edc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,18 @@ endif(CCACHE_FOUND) set(CMAKE_BUILD_TYPE RELEASE) +if(TESTING OR DEFINED ENV{TRAVIS}) +execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +find_package(Qt5Network REQUIRED) +add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}") +endif(TESTING OR DEFINED ENV{TRAVIS}) + + if(TESTING) SET(CMAKE_C_COMPILER "/usr/bin/clang") diff --git a/src/main.cpp b/src/main.cpp index 93640c1..6d4bdc8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,13 @@ #include "setenv_mingw.hpp" #endif +#ifdef GIT_COMMIT_HASH +#include +#include +#include + +#endif + #ifdef __linux__ #include #include @@ -48,6 +55,27 @@ int main(int argc, char* argv[]) #ifdef __linux__ catchUnixSignals({SIGQUIT, SIGINT, SIGTERM, SIGHUP}); #endif + +#ifdef GIT_COMMIT_HASH +QString current_version = QString(GIT_COMMIT_HASH); +qDebug() << "Current Version: " << current_version; + +QNetworkRequest request(QUrl("https://api.github.com/repos/NamedKitten/KittehPlayer/releases/tags/continuous")); +QNetworkAccessManager nam; +QNetworkReply *reply = nam.get(request); + +while(!reply->isFinished()) { +qApp->processEvents(); +} +QByteArray response_data = reply->readAll(); +QJsonDocument json = QJsonDocument::fromJson(response_data); +QJsonArray jsonArray = json["assets"].toArray(); +qDebug() << "Latest Version: " << json["target_commitish"].toString(); +if (json["target_commitish"].toString().endsWith(current_version) == 0) { + qDebug() << "Update Available. Please update ASAP."; +} +#endif + app.setOrganizationName("KittehPlayer"); app.setOrganizationDomain("namedkitten.pw"); app.setApplicationName("KittehPlayer");