@@ -38,10 +38,11 @@ public class RemoteVersion {
|
|||||||
String jarHash = Optional.ofNullable(response.get("jarsha1")).map(JsonElement::getAsString).orElse(null);
|
String jarHash = Optional.ofNullable(response.get("jarsha1")).map(JsonElement::getAsString).orElse(null);
|
||||||
String packXZUrl = Optional.ofNullable(response.get("packxz")).map(JsonElement::getAsString).orElse(null);
|
String packXZUrl = Optional.ofNullable(response.get("packxz")).map(JsonElement::getAsString).orElse(null);
|
||||||
String packXZHash = Optional.ofNullable(response.get("packxzsha1")).map(JsonElement::getAsString).orElse(null);
|
String packXZHash = Optional.ofNullable(response.get("packxzsha1")).map(JsonElement::getAsString).orElse(null);
|
||||||
|
boolean force = Optional.ofNullable(response.get("force")).map(JsonElement::getAsBoolean).orElse(false);
|
||||||
if (Pack200Utils.isSupported() && packXZUrl != null && packXZHash != null) {
|
if (Pack200Utils.isSupported() && packXZUrl != null && packXZHash != null) {
|
||||||
return new RemoteVersion(channel, version, packXZUrl, Type.PACK_XZ, new IntegrityCheck("SHA-1", packXZHash));
|
return new RemoteVersion(channel, version, packXZUrl, Type.PACK_XZ, new IntegrityCheck("SHA-1", packXZHash), force);
|
||||||
} else if (jarUrl != null && jarHash != null) {
|
} else if (jarUrl != null && jarHash != null) {
|
||||||
return new RemoteVersion(channel, version, jarUrl, Type.JAR, new IntegrityCheck("SHA-1", jarHash));
|
return new RemoteVersion(channel, version, jarUrl, Type.JAR, new IntegrityCheck("SHA-1", jarHash), force);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("No download url is available");
|
throw new IOException("No download url is available");
|
||||||
}
|
}
|
||||||
@@ -55,13 +56,15 @@ public class RemoteVersion {
|
|||||||
private final String url;
|
private final String url;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private final IntegrityCheck integrityCheck;
|
private final IntegrityCheck integrityCheck;
|
||||||
|
private final boolean force;
|
||||||
|
|
||||||
public RemoteVersion(UpdateChannel channel, String version, String url, Type type, IntegrityCheck integrityCheck) {
|
public RemoteVersion(UpdateChannel channel, String version, String url, Type type, IntegrityCheck integrityCheck, boolean force) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.integrityCheck = integrityCheck;
|
this.integrityCheck = integrityCheck;
|
||||||
|
this.force = force;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateChannel getChannel() {
|
public UpdateChannel getChannel() {
|
||||||
@@ -84,6 +87,10 @@ public class RemoteVersion {
|
|||||||
return integrityCheck;
|
return integrityCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isForce() {
|
||||||
|
return force;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + version + " from " + url + "]";
|
return "[" + version + " from " + url + "]";
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import javafx.beans.property.*;
|
|||||||
import javafx.beans.value.ObservableBooleanValue;
|
import javafx.beans.value.ObservableBooleanValue;
|
||||||
import org.jackhuang.hmcl.Metadata;
|
import org.jackhuang.hmcl.Metadata;
|
||||||
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
||||||
|
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -42,10 +43,13 @@ public final class UpdateChecker {
|
|||||||
RemoteVersion latest = latestVersion.get();
|
RemoteVersion latest = latestVersion.get();
|
||||||
if (latest == null || isDevelopmentVersion(Metadata.VERSION)) {
|
if (latest == null || isDevelopmentVersion(Metadata.VERSION)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else if (latest.isForce()
|
||||||
// We can update from development version to stable version,
|
|| Metadata.isNightly()
|
||||||
// which can be downgrading.
|
|| latest.getChannel() == UpdateChannel.NIGHTLY
|
||||||
|
|| latest.getChannel() != UpdateChannel.getChannel()) {
|
||||||
return !latest.getVersion().equals(Metadata.VERSION);
|
return !latest.getVersion().equals(Metadata.VERSION);
|
||||||
|
} else {
|
||||||
|
return VersionNumber.compare(Metadata.VERSION, latest.getVersion()) < 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
latestVersion);
|
latestVersion);
|
||||||
|
|||||||
Reference in New Issue
Block a user