Add version query when checking for update
This commit is contained in:
@@ -17,11 +17,14 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.upgrade;
|
||||
|
||||
import static org.jackhuang.hmcl.util.Lang.mapOf;
|
||||
import static org.jackhuang.hmcl.util.Pair.pair;
|
||||
import static org.jackhuang.hmcl.util.VersionNumber.asVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jackhuang.hmcl.Metadata;
|
||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
@@ -37,7 +40,8 @@ public final class UpdateChecker {
|
||||
private UpdateChecker() {}
|
||||
|
||||
private static ObjectProperty<RemoteVersion> latestVersion = new SimpleObjectProperty<>();
|
||||
private static StringProperty updateSource = new SimpleStringProperty(Metadata.UPDATE_SERVER_URL + "/api/update_link");
|
||||
private static StringProperty updateSource = new SimpleStringProperty(
|
||||
NetworkUtils.withQuery(Metadata.UPDATE_SERVER_URL + "/api/update_link", mapOf(pair("version", Metadata.VERSION))));
|
||||
private static BooleanBinding outdated = Bindings.createBooleanBinding(
|
||||
() -> {
|
||||
RemoteVersion latest = latestVersion.get();
|
||||
|
||||
@@ -20,9 +20,11 @@ package org.jackhuang.hmcl.util;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -48,6 +50,27 @@ public final class NetworkUtils {
|
||||
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
|
||||
}
|
||||
|
||||
public static String withQuery(String baseUrl, Map<String, String> params) {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder(baseUrl);
|
||||
boolean first = true;
|
||||
for (Entry<String, String> param : params.entrySet()) {
|
||||
if (first) {
|
||||
sb.append('?');
|
||||
first = false;
|
||||
} else {
|
||||
sb.append('&');
|
||||
}
|
||||
sb.append(URLEncoder.encode(param.getKey(), "UTF-8"));
|
||||
sb.append('=');
|
||||
sb.append(URLEncoder.encode(param.getValue(), "UTF-8"));
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpURLConnection createConnection(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
|
||||
Reference in New Issue
Block a user