From ed0f694cd2cd85cc2cf3175d6c1960ba7def886e Mon Sep 17 00:00:00 2001 From: Curve Date: Fri, 14 May 2021 22:13:54 +0200 Subject: [PATCH] refactor: use semver for versioning --- .gitmodules | 3 +++ CMakeLists.txt | 5 +++-- lib/semver | 1 + src/helper/version/check.cpp | 23 ++++------------------- 4 files changed, 11 insertions(+), 21 deletions(-) create mode 160000 lib/semver diff --git a/.gitmodules b/.gitmodules index 08c425f..d3d29c9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -32,3 +32,6 @@ [submodule "deployment/flatpak/shared-modules"] path = deployment/flatpak/shared-modules url = https://github.com/flathub/shared-modules +[submodule "lib/semver"] + path = lib/semver + url = https://github.com/Neargye/semver diff --git a/CMakeLists.txt b/CMakeLists.txt index 712c132..52c8424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(soundux VERSION 0.2.2 DESCRIPTION "") +project(soundux VERSION 0.2.3 DESCRIPTION "") -set(FULL_VERSION_STRING "0.2.2_b3") +set(FULL_VERSION_STRING "0.2.3") option(EMBED_PATH "The path used for embedding" "OFF") option(USE_FLATPAK "Allows the program to run under flatpak" OFF) @@ -45,6 +45,7 @@ endif() target_compile_definitions(soundux PRIVATE SOUNDUX_VERSION="${FULL_VERSION_STRING}" WNCK_I_KNOW_THIS_IS_UNSTABLE=1) target_include_directories(soundux SYSTEM PRIVATE "src") target_include_directories(soundux SYSTEM PRIVATE "lib/miniaudio") +target_include_directories(soundux SYSTEM PRIVATE "lib/semver/include") target_include_directories(soundux SYSTEM PRIVATE "lib/fancypp/include") target_include_directories(soundux SYSTEM PRIVATE "lib/json/single_include") target_include_directories(soundux SYSTEM PRIVATE "lib/InstanceGuard/Source") diff --git a/lib/semver b/lib/semver new file mode 160000 index 0000000..b06119f --- /dev/null +++ b/lib/semver @@ -0,0 +1 @@ +Subproject commit b06119fed9dd00f37c4d62625d82357862cf2dd6 diff --git a/src/helper/version/check.cpp b/src/helper/version/check.cpp index 87cb5e2..0299dea 100644 --- a/src/helper/version/check.cpp +++ b/src/helper/version/check.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include httplib::Client VersionCheck::client("https://api.github.com"); @@ -19,27 +19,12 @@ std::optional VersionCheck::getStatus() auto latestTag = parsed[0]["name"]; if (!latestTag.is_null()) { - static std::regex lastNumber(R"(.*(\d))"); - bool outdated = false; - - std::smatch match; auto latestTagStr = latestTag.get(); - if (std::regex_search(latestTagStr, match, lastNumber)) - { - auto remoteNumber = std::stoi(match[1]); - auto localVersion = std::string(SOUNDUX_VERSION); - if (std::regex_search(localVersion, match, lastNumber)) - { - auto localNumber = std::stoi(match[1]); - if (remoteNumber > localNumber) - { - outdated = true; - } - } - } + auto remote = semver::from_string(latestTagStr); + auto local = semver::from_string(SOUNDUX_VERSION); - return Soundux::Objects::VersionStatus{SOUNDUX_VERSION, latestTag, outdated}; + return Soundux::Objects::VersionStatus{SOUNDUX_VERSION, latestTagStr, remote > local}; } Fancy::fancy.logTime().warning() << "Failed to find latest tag" << std::endl; }