diff --git a/src/update-checker/update-checker.cpp b/src/update-checker/update-checker.cpp index fff860f6..cb0a110b 100644 --- a/src/update-checker/update-checker.cpp +++ b/src/update-checker/update-checker.cpp @@ -13,12 +13,45 @@ #include "../plugin-support.h" #include +#include +#include extern "C" const char *PLUGIN_VERSION; static std::string latestVersionForUpdate; static std::mutex latestVersionMutex; +static bool is_newer_version(const std::string& remote, const std::string& local) +{ + std::regex version_regex(R"(^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z]+)(?:\.?(\d+))?)?$)"); + std::smatch remote_match; + std::smatch local_match; + + bool remote_valid = std::regex_match(remote, remote_match, version_regex); + bool local_valid = std::regex_match(local, local_match, version_regex); + + if (!remote_valid || !local_valid) { + // Fallback to basic string comparison if regex fails + return remote > local; + } + + int remote_major = std::stoi(remote_match[1].str()); + int remote_minor = std::stoi(remote_match[2].str()); + int remote_patch = std::stoi(remote_match[3].str()); + + int local_major = std::stoi(local_match[1].str()); + int local_minor = std::stoi(local_match[2].str()); + int local_patch = std::stoi(local_match[3].str()); + + if (remote_major != local_major) { + return remote_major > local_major; + } + if (remote_minor != local_minor) { + return remote_minor > local_minor; + } + return remote_patch > local_patch; +} + void check_update(void) { bool shouldCheckForUpdates = false; @@ -41,8 +74,8 @@ void check_update(void) } obs_log(LOG_INFO, "Latest release is %s", info.version.c_str()); - if (info.version == PLUGIN_VERSION) { - // No update available, latest version is the same as the current version + if (!is_newer_version(info.version, PLUGIN_VERSION)) { + // No update available, latest version is not newer than the current version std::lock_guard lock(latestVersionMutex); latestVersionForUpdate.clear(); return;