Skip to content

Commit

Permalink
Implemented IsNewerUpdaterAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
nefarius committed Oct 10, 2023
1 parent f602b2b commit 97f08ee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 34 additions & 2 deletions src/UpdateResponse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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())
{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions wwwroot/api/nefarius/HidHide/updates.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 97f08ee

Please sign in to comment.