Qt: Improve update checker system to prevent downgrades #1749 (#1768)

* Qt: Improve update checker system to prevent downgrades

* Code cleanup

* Return 0 as fallback

* Satisfy clang-format

---------

Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
This commit is contained in:
RedBlackAka 2026-03-10 17:01:40 +01:00 committed by GitHub
parent 784fc8cca9
commit d9f28c5b2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,12 +180,21 @@ bool IsPrereleaseBuild() {
}
#ifdef ENABLE_QT_UPDATE_CHECKER
bool ShouldCheckForPrereleaseUpdates() {
static bool ShouldCheckForPrereleaseUpdates() {
const bool update_channel = UISettings::values.update_check_channel.GetValue();
const bool using_prerelease_channel =
(update_channel == UISettings::UpdateCheckChannels::PRERELEASE);
return (IsPrereleaseBuild() || using_prerelease_channel);
}
static int GetMajorVersion(const std::string& version) {
size_t dot = version.find('.');
try {
return std::stoi(version.substr(0, dot));
} catch (...) {
return 0;
}
}
#endif
GMainWindow::GMainWindow(Core::System& system_)
@ -422,7 +431,11 @@ GMainWindow::GMainWindow(Core::System& system_)
UpdateChecker::GetLatestRelease(ShouldCheckForPrereleaseUpdates());
if (latest_release_tag && latest_release_tag.value() != Common::g_build_fullname) {
return QString::fromStdString(latest_release_tag.value());
const int latest_major_version = GetMajorVersion(latest_release_tag.value());
const int current_major_version = GetMajorVersion(Common::g_build_fullname);
if (current_major_version <= latest_major_version) {
return QString::fromStdString(latest_release_tag.value());
}
}
return QString{};
});