mirror of
https://github.com/prusa3d/PrusaSlicer.git
synced 2026-11-26 23:29:07 +00:00
Reset AppConfig initialized flag when upgrading from alpha12 or older
Semver prerelease identifiers with numeric suffixes are now compared numerically, so alpha9 < alpha12 < alpha100.
This commit is contained in:
parent
d37719316f
commit
e5dbb3a695
3 changed files with 29 additions and 5 deletions
|
|
@ -214,7 +214,7 @@ semver_parse_version (const char *str, semver_t *ver) {
|
|||
static int
|
||||
compare_prerelease (char *x, char *y) {
|
||||
char *lastx, *lasty, *xptr, *yptr, *endptr;
|
||||
size_t xlen, ylen, xn, yn, min;
|
||||
size_t xlen, ylen, xn, yn, xd, yd, min;
|
||||
int xisnum, yisnum, xnum, ynum;
|
||||
int res;
|
||||
if (x == NULL && y == NULL) return 0;
|
||||
|
|
@ -247,9 +247,16 @@ compare_prerelease (char *x, char *y) {
|
|||
/* String comparison */
|
||||
xn = xptr - lastx;
|
||||
yn = yptr - lasty;
|
||||
min = xn < yn ? xn : yn;
|
||||
xd = xn;
|
||||
while (xd > 0 && lastx[xd - 1] >= '0' && lastx[xd - 1] <= '9') xd--;
|
||||
yd = yn;
|
||||
while (yd > 0 && lasty[yd - 1] >= '0' && lasty[yd - 1] <= '9') yd--;
|
||||
min = xd < yd ? xd : yd;
|
||||
if ((res = strncmp(lastx, lasty, min))) return res < 0 ? -1 : 1;
|
||||
if (xn != yn) return xn < yn ? -1 : 1;
|
||||
if (xd != yd) return xd < yd ? -1 : 1;
|
||||
xnum = strtol(lastx + xd, NULL, 10);
|
||||
ynum = strtol(lasty + yd, NULL, 10);
|
||||
if (xnum != ynum) return xnum < ynum ? -1 : 1;
|
||||
}
|
||||
|
||||
lastx = xptr + 1;
|
||||
|
|
|
|||
|
|
@ -668,9 +668,10 @@ void AppConfig::handle_legacy_config(AppConfig& app_config)
|
|||
}
|
||||
|
||||
const boost::optional<Semver> semver{Semver::parse(app_config.get<std::string>("version"))};
|
||||
if (!semver.has_value()) {
|
||||
return;
|
||||
if (semver.has_value() && *semver < Semver("3.0.0-alpha13")) {
|
||||
app_config.set("initialized", false);
|
||||
}
|
||||
app_config.set("version", std::string(Slic3r::VERSION));
|
||||
}
|
||||
|
||||
AppConfig::AppConfig() :
|
||||
|
|
|
|||
|
|
@ -81,3 +81,19 @@ TEST_CASE("Check parsing and comparing of config versions", "[Version]") {
|
|||
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha1")));
|
||||
REQUIRE(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha")));
|
||||
}
|
||||
|
||||
TEST_CASE("Compare prerelease identifiers with numeric suffixes", "[Version]") {
|
||||
using Slic3r::Semver;
|
||||
|
||||
REQUIRE(Semver("3.0.0-alpha9") < Semver("3.0.0-alpha12"));
|
||||
REQUIRE(Semver("3.0.0-alpha12") < Semver("3.0.0-alpha13"));
|
||||
REQUIRE(Semver("3.0.0-alpha12") < Semver("3.0.0-alpha100"));
|
||||
REQUIRE(Semver("3.0.0-alpha") < Semver("3.0.0-alpha1"));
|
||||
REQUIRE(Semver("3.0.0-alpha13") < Semver("3.0.0-beta1"));
|
||||
REQUIRE(Semver("3.0.0-beta2") < Semver("3.0.0-beta10"));
|
||||
REQUIRE(Semver("3.0.0-beta10") < Semver("3.0.0-rc1"));
|
||||
REQUIRE(Semver("3.0.0-rc2") < Semver("3.0.0"));
|
||||
REQUIRE(Semver("3.0.0-alpha12") == Semver("3.0.0-alpha12"));
|
||||
REQUIRE(Semver("3.0.0-alpha13") > Semver("3.0.0-alpha12"));
|
||||
REQUIRE(Semver("3.0.0-alpha.9") < Semver("3.0.0-alpha.12"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue