Compare numbers and fallback to string for updates

This commit is contained in:
libraryaddict 2019-03-07 14:48:53 +13:00
parent 989afe3d31
commit 6eb61b28f6

View File

@ -10,7 +10,6 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
public class UpdateChecker { public class UpdateChecker {
private final String resourceID; private final String resourceID;
@ -122,6 +121,20 @@ public class UpdateChecker {
return false; return false;
} }
// If both strings are numerical
if (cSplit[i].matches("[0-9]+") && nSplit[i].matches("[0-9]+")) {
int cInt = Integer.parseInt(cSplit[i]);
int nInt = Integer.parseInt(nSplit[i]);
// Same version
if (cInt == nInt) {
continue;
}
// Return if current version is inferior to new version
return cInt < nInt;
}
// String compare the versions, should perform the same as an int compare // String compare the versions, should perform the same as an int compare
int compareResult = cSplit[i].compareTo(nSplit[i]); int compareResult = cSplit[i].compareTo(nSplit[i]);