diff --git a/README.md b/README.md index 50798e3..f1d5e18 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Non-exhaustive list of things open or in-progress... - [ ] Add self-updater logic - [ ] Documentation - [ ] Finalize UI design +- [ ] Design Beta-Release support ## Sources & 3rd party credits diff --git a/src/UpdateResponse.hpp b/src/UpdateResponse.hpp index 7e2fadb..04c1f42 100644 --- a/src/UpdateResponse.hpp +++ b/src/UpdateResponse.hpp @@ -48,9 +48,29 @@ namespace models public: /** True to disable, false to enable the updates globally */ bool updatesDisabled; + /** The latest updater version available */ + std::string latestVersion; + /** URL of the latest updater binary */ + std::string latestUrl; + + /** + * \brief Converts the version string to a SemVer type. + * \return The parsed version. + */ + semver::version GetSemVersion() const + { + try + { + return semver::version{latestVersion}; + } + catch (...) + { + return semver::version{0, 0, 0}; + } + } }; - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(UpdateConfig, updatesDisabled) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(UpdateConfig, updatesDisabled, latestVersion, latestUrl) /** * \brief An instance returned by the remote update API. @@ -68,7 +88,7 @@ namespace models * \param currentVersion The local version to check against. * \return True if a newer version is available, false otherwise. */ - [[nodiscard]] bool IsUpdateAvailable(const semver::version& currentVersion) const + [[nodiscard]] bool IsProductUpdateAvailable(const semver::version& currentVersion) const { if (releases.empty()) { @@ -79,6 +99,18 @@ namespace models return latest > currentVersion; } + + /** + * \brief Checks if a newer updater than the local version is available. + * \param currentVersion The local version to check against. + * \return True if a newer version is available, false otherwise. + */ + [[nodiscard]] bool IsNewerUpdaterAvailable(const semver::version& currentVersion) const + { + const auto latest = instance.GetSemVersion(); + + return latest > currentVersion; + } }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(UpdateResponse, instance, releases) diff --git a/src/main.cpp b/src/main.cpp index 6b89fd6..ec68f68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, if (local.RequestUpdateInfo(updateConfig)) { - if (updateConfig.IsUpdateAvailable(local.GetAppVersion())) + if (updateConfig.IsNewerUpdaterAvailable(local.GetAppVersion())) { auto t = 0; } diff --git a/wwwroot/api/nefarius/HidHide/updates.json b/wwwroot/api/nefarius/HidHide/updates.json index 942ca51..fe5a4da 100644 --- a/wwwroot/api/nefarius/HidHide/updates.json +++ b/wwwroot/api/nefarius/HidHide/updates.json @@ -1,4 +1,9 @@ { + "instance":{ + "updatesDisabled": false, + "latestVersion": "2.0.0", + "latestUrl": "http://localhost:5200/api/nefarius/HidHide/nefarius_HidHide_Updater.exe" + }, "releases":[ { "name": "test1",