mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
fix version sorting
This commit is contained in:
@@ -31,42 +31,62 @@ public class UpdateChecker {
|
||||
String ret = null;
|
||||
Json5Element element = json5.parse(reader);
|
||||
reader.close();
|
||||
|
||||
Json5Object rel = null;
|
||||
Json5Object snap = null;
|
||||
|
||||
if (element instanceof Json5Array) {
|
||||
final Json5Array arr = element.getAsJson5Array();
|
||||
if (arr.size() > 0) {
|
||||
for (int i = 0; i < Math.min(2, arr.size()); i++) {
|
||||
element = arr.get(i);
|
||||
if (element instanceof Json5Object) {
|
||||
final Json5Object obj = element.getAsJson5Object();
|
||||
if (allowSnapshots || !obj.get("prerelease").getAsBoolean()) {
|
||||
final String tag = obj.get("tag_name").getAsString();
|
||||
final Semver ver = new Semver(tag.startsWith("v") ? tag.substring(1) : tag);
|
||||
String comm;
|
||||
try {
|
||||
comm = ver.getBuild().get(0).trim();
|
||||
} catch (Throwable t) {
|
||||
comm = "";
|
||||
}
|
||||
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD && OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
|
||||
element = obj.get("assets");
|
||||
if (element instanceof Json5Array) {
|
||||
final Json5Array aArr = element.getAsJson5Array();
|
||||
if (aArr.size() > 0) {
|
||||
element = aArr.get(0);
|
||||
if (element instanceof Json5Object) {
|
||||
final Json5Object vObj = element.getAsJson5Object();
|
||||
ret = vObj.get("browser_download_url").getAsString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
element = arr.get(i);
|
||||
if (element instanceof Json5Object) {
|
||||
final Json5Object obj = element.getAsJson5Object();
|
||||
if (!obj.has("published_at")) {
|
||||
continue;
|
||||
}
|
||||
final boolean pre = obj.get("prerelease").getAsBoolean();
|
||||
if (!pre) {
|
||||
if (rel == null || obj.get("published_at").getAsString().compareTo(rel.get("published_at").getAsString()) > 0) {
|
||||
rel = obj;
|
||||
}
|
||||
} else {
|
||||
if (snap == null || obj.get("published_at").getAsString().compareTo(snap.get("published_at").getAsString()) > 0) {
|
||||
snap = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
final Json5Object obj = i == 0 ? rel : snap;
|
||||
if (obj == null || (i == 1 && !allowSnapshots)) {
|
||||
continue;
|
||||
}
|
||||
final String tag = obj.get("tag_name").getAsString();
|
||||
final Semver ver = new Semver(tag.startsWith("v") ? tag.substring(1) : tag);
|
||||
String comm;
|
||||
try {
|
||||
comm = ver.getBuild().get(0).trim();
|
||||
} catch (Throwable t) {
|
||||
comm = "";
|
||||
}
|
||||
if (ver.isGreaterThan(currentVersion) || (allowSnapshots && currentVersion.diff(ver) == VersionDiff.BUILD && OriginBlacklist.isNonNull(comm) && !BuildInfo.get("git_cm_hash").startsWith(comm))) {
|
||||
element = obj.get("assets");
|
||||
if (element instanceof Json5Array) {
|
||||
final Json5Array aArr = element.getAsJson5Array();
|
||||
if (aArr.size() > 0) {
|
||||
element = aArr.get(0);
|
||||
if (element instanceof Json5Object) {
|
||||
ret = element.getAsJson5Object().get("browser_download_url").getAsString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
return ret;
|
||||
} catch (final Throwable t) {
|
||||
|
||||
Reference in New Issue
Block a user