-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updater: Compare all parts of the version number
This should fix the case where comparing '0.12.0b164' with '0.12.0a169' results in it claiming the former is newer. Also should fix the case where stable releases would always be treated as older. Fixes #1015
- Loading branch information
Showing
1 changed file
with
42 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) 2020 Michael Fabian Dirks <[email protected]> | ||
// Copyright (c) 2020-2023 Michael Fabian Dirks <[email protected]> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -168,49 +168,63 @@ void streamfx::from_json(const nlohmann::json& json, version_info& info) | |
bool streamfx::version_info::is_older_than(const version_info other) | ||
{ | ||
// 'true' if other is newer, otherwise false. | ||
// Except for stable releases, this simply compares the numbers of the version. | ||
|
||
// 1. Compare Major version: | ||
// A. Ours is greater: Remote is older. | ||
// B. Theirs is greater: Remote is newer. | ||
// C. Continue the check. | ||
if (major > other.major) | ||
return false; | ||
// Compare Major version: | ||
// - Theirs is greater: Remote is newer. | ||
// - Ours is greater: Remote is older. | ||
// - Continue the check. | ||
if (major < other.major) | ||
return true; | ||
|
||
// 2. Compare Minor version: | ||
// A. Ours is greater: Remote is older. | ||
// B. Theirs is greater: Remote is newer. | ||
// C. Continue the check. | ||
if (minor > other.minor) | ||
if (major > other.major) | ||
return false; | ||
|
||
// Compare Minor version: | ||
// - Theirs is greater: Remote is newer. | ||
// - Ours is greater: Remote is older. | ||
// - Continue the check. | ||
if (minor < other.minor) | ||
return true; | ||
if (minor > other.minor) | ||
return false; | ||
|
||
// 3. Compare Patch version: | ||
// A. Ours is greater: Remote is older. | ||
// B. Theirs is greater: Remote is newer. | ||
// C. Continue the check. | ||
// Compare Patch version: | ||
// - Theirs is greater: Remote is newer. | ||
// - Ours is greater: Remote is older. | ||
// - Continue the check. | ||
if (patch < other.patch) | ||
return true; | ||
if (patch > other.patch) | ||
return false; | ||
if (patch < other.patch) | ||
|
||
// Compare Tweak and Stage version: | ||
// - Theirs is greater: Remote is newer. | ||
// - Ours is greater: Special logic. | ||
// - Continue the check. | ||
if (tweak < other.tweak) | ||
return true; | ||
if ((tweak > other.tweak) && (other.stage != version_stage::STABLE)) { | ||
// If the remote isn't a stable release, it's always considered older. | ||
return false; | ||
|
||
// 4. Compare Type: | ||
// A. Outs is smaller: Remote is older. | ||
// B. Theirs is smaller: Remote is newer. | ||
// C. Continue the check. | ||
// 0.12.0 vs 0.12.0 | ||
// Major: equal, continue | ||
// Minor: equal, continue | ||
// Patch: equal, continue | ||
// Tweak: equal, continue | ||
// Ours is older? | ||
} | ||
|
||
// As a last effort, compare the stage. | ||
// - Theirs is greater: Remote is older. | ||
// - Ours is greater: Remote is newer. | ||
// - Continue the check. | ||
if (stage < other.stage) | ||
return false; | ||
if (stage > other.stage) | ||
return true; | ||
|
||
// 5. Compare Tweak: | ||
// A. Ours is greater or equal: Remote is older or identical. | ||
// B. Remote is newer | ||
if (tweak >= other.tweak) | ||
return false; | ||
|
||
// If there are no further tests, assume this version is older. | ||
return true; | ||
} | ||
|
||
|