code: Fix version comparison logic
This is a lot more complex that I expected it to be.
This commit is contained in:
parent
0439fddabd
commit
65c45c4461
|
|
@ -152,60 +152,56 @@ bool streamfx::version_info::is_older_than(const version_info other)
|
||||||
|
|
||||||
// Compare Major version:
|
// Compare Major version:
|
||||||
// - Theirs is greater: Remote is newer.
|
// - Theirs is greater: Remote is newer.
|
||||||
// - Ours is greater: Remote is older.
|
|
||||||
// - Continue the check.
|
|
||||||
if (major < other.major)
|
if (major < other.major)
|
||||||
return true;
|
return true;
|
||||||
|
// - Ours is greater: Remote is older.
|
||||||
if (major > other.major)
|
if (major > other.major)
|
||||||
return false;
|
return false;
|
||||||
|
// - Continue the check.
|
||||||
|
|
||||||
// Compare Minor version:
|
// Compare Minor version:
|
||||||
// - Theirs is greater: Remote is newer.
|
// - Theirs is greater: Remote is newer.
|
||||||
// - Ours is greater: Remote is older.
|
|
||||||
// - Continue the check.
|
|
||||||
if (minor < other.minor)
|
if (minor < other.minor)
|
||||||
return true;
|
return true;
|
||||||
|
// - Ours is greater: Remote is older.
|
||||||
if (minor > other.minor)
|
if (minor > other.minor)
|
||||||
return false;
|
return false;
|
||||||
|
// - Continue the check.
|
||||||
|
|
||||||
// Compare Patch version:
|
// Compare Patch version:
|
||||||
// - Theirs is greater: Remote is newer.
|
// - Theirs is greater: Remote is newer.
|
||||||
// - Ours is greater: Remote is older.
|
|
||||||
// - Continue the check.
|
|
||||||
if (patch < other.patch)
|
if (patch < other.patch)
|
||||||
return true;
|
return true;
|
||||||
|
// - Ours is greater: Remote is older.
|
||||||
if (patch > other.patch)
|
if (patch > other.patch)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Compare Tweak and Stage version:
|
|
||||||
// - Theirs is greater: Remote is newer.
|
|
||||||
// - Ours is greater: Special logic.
|
|
||||||
// - Continue the check.
|
// - Continue the check.
|
||||||
|
|
||||||
|
// Compare Stage
|
||||||
|
// - Theirs is Stable, we are not: Remote is newer.
|
||||||
|
if ((stage != version_stage::STABLE) && (other.stage == version_stage::STABLE))
|
||||||
|
return true;
|
||||||
|
// - Continue the check.
|
||||||
|
|
||||||
|
// Compare Tweak
|
||||||
|
// - Theirs is greater: Remote is newer.
|
||||||
if (tweak < other.tweak)
|
if (tweak < other.tweak)
|
||||||
return true;
|
return true;
|
||||||
if ((tweak > other.tweak) && (other.stage != version_stage::STABLE)) {
|
// - Ours is greater: Remote is older.
|
||||||
// If the remote isn't a stable release, it's always considered older.
|
if (tweak > other.tweak)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 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.
|
// - Continue the check.
|
||||||
if (stage < other.stage)
|
|
||||||
return false;
|
// Compare Stage (again)
|
||||||
|
// - Ours is greater: Remote is newer.
|
||||||
if (stage > other.stage)
|
if (stage > other.stage)
|
||||||
return true;
|
return true;
|
||||||
|
// - Theirs is greater: Remote is older.
|
||||||
|
if (stage < other.stage)
|
||||||
|
return false;
|
||||||
|
|
||||||
// If there are no further tests, assume this version is older.
|
// If all tests failed so far, assume the compared version is identical or newer.
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
streamfx::version_info::operator std::string()
|
streamfx::version_info::operator std::string()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue