mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-13 22:07:01 -04:00
Fix official optifine download
This commit is contained in:
parent
a502785209
commit
c7589e4e3c
@ -265,8 +265,8 @@ public final class YggdrasilAccount extends Account {
|
|||||||
return "YggdrasilAccount[username=" + getUsername() + "]";
|
return "YggdrasilAccount[username=" + getUsername() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String BASE_URL = "http://localhost:8080/authserver/"; //"https://authserver.mojang.com/";
|
private static final String BASE_URL = "https://authserver.mojang.com/";
|
||||||
private static final String BASE_PROFILE = "http://localhost:8080/sessionserver/session/minecraft/profile/"; //"https://sessionserver.mojang.com/session/minecraft/profile/";
|
private static final String BASE_PROFILE = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
private static final URL ROUTE_AUTHENTICATE = NetworkUtils.toURL(BASE_URL + "authenticate");
|
private static final URL ROUTE_AUTHENTICATE = NetworkUtils.toURL(BASE_URL + "authenticate");
|
||||||
private static final URL ROUTE_REFRESH = NetworkUtils.toURL(BASE_URL + "refresh");
|
private static final URL ROUTE_REFRESH = NetworkUtils.toURL(BASE_URL + "refresh");
|
||||||
private static final URL ROUTE_VALIDATE = NetworkUtils.toURL(BASE_URL + "validate");
|
private static final URL ROUTE_VALIDATE = NetworkUtils.toURL(BASE_URL + "validate");
|
||||||
|
@ -27,7 +27,7 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public final class RemoteVersion<T> implements Comparable<RemoteVersion<T>> {
|
public class RemoteVersion<T> implements Comparable<RemoteVersion<T>> {
|
||||||
|
|
||||||
private final String gameVersion;
|
private final String gameVersion;
|
||||||
private final String selfVersion;
|
private final String selfVersion;
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Hello Minecraft! Launcher.
|
|
||||||
* Copyright (C) 2017 huangyuhui <huanghongxun2008@126.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
||||||
*/
|
|
||||||
package org.jackhuang.hmcl.download.optifine;
|
|
||||||
|
|
||||||
import org.jackhuang.hmcl.task.TaskResult;
|
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author huangyuhui
|
|
||||||
*/
|
|
||||||
public final class OptiFineDownloadFormatter extends TaskResult<String> {
|
|
||||||
|
|
||||||
private final String url;
|
|
||||||
|
|
||||||
public OptiFineDownloadFormatter(String url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() throws Exception {
|
|
||||||
String result = null;
|
|
||||||
String content = NetworkUtils.doGet(NetworkUtils.toURL(url));
|
|
||||||
Matcher m = PATTERN.matcher(content);
|
|
||||||
while (m.find())
|
|
||||||
result = m.group(1);
|
|
||||||
if (result == null)
|
|
||||||
throw new IllegalStateException("Cannot find version in " + content);
|
|
||||||
setResult("http://optifine.net/downloadx?f=OptiFine" + result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String ID = "optifine_formatter";
|
|
||||||
private static final Pattern PATTERN = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
|
|
||||||
}
|
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher.
|
||||||
|
* Copyright (C) 2017 huangyuhui <huanghongxun2008@126.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.download.optifine;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.download.RemoteVersion;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class OptiFineRemoteVersion extends RemoteVersion<Void> {
|
||||||
|
private final Supplier<String> url;
|
||||||
|
|
||||||
|
public OptiFineRemoteVersion(String gameVersion, String selfVersion, Supplier<String> url, Void tag) {
|
||||||
|
super(gameVersion, selfVersion, "", tag);
|
||||||
|
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrl() {
|
||||||
|
return url.get();
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ import org.jackhuang.hmcl.download.RemoteVersion;
|
|||||||
import org.jackhuang.hmcl.download.VersionList;
|
import org.jackhuang.hmcl.download.VersionList;
|
||||||
import org.jackhuang.hmcl.task.GetTask;
|
import org.jackhuang.hmcl.task.GetTask;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.NetworkUtils;
|
import org.jackhuang.hmcl.util.NetworkUtils;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@ -30,6 +31,7 @@ import org.w3c.dom.NodeList;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -42,6 +44,8 @@ import java.util.regex.Pattern;
|
|||||||
public final class OptiFineVersionList extends VersionList<Void> {
|
public final class OptiFineVersionList extends VersionList<Void> {
|
||||||
|
|
||||||
private static final Pattern PATTERN = Pattern.compile("OptiFine (.*?) ");
|
private static final Pattern PATTERN = Pattern.compile("OptiFine (.*?) ");
|
||||||
|
private static final Pattern LINK_PATTERN = Pattern.compile("\"downloadx\\?f=OptiFine(.*)\"");
|
||||||
|
|
||||||
public static final OptiFineVersionList INSTANCE = new OptiFineVersionList();
|
public static final OptiFineVersionList INSTANCE = new OptiFineVersionList();
|
||||||
|
|
||||||
private OptiFineVersionList() {
|
private OptiFineVersionList() {
|
||||||
@ -89,7 +93,9 @@ public final class OptiFineVersionList extends VersionList<Void> {
|
|||||||
gameVersion = matcher.group(1);
|
gameVersion = matcher.group(1);
|
||||||
if (gameVersion == null)
|
if (gameVersion == null)
|
||||||
continue;
|
continue;
|
||||||
versions.put(gameVersion, new RemoteVersion<>(gameVersion, version, url, null));
|
|
||||||
|
String finalURL = url;
|
||||||
|
versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, Lang.hideException(() -> getLink(finalURL)), null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,4 +103,14 @@ public final class OptiFineVersionList extends VersionList<Void> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getLink(String url) throws IOException {
|
||||||
|
String result = null;
|
||||||
|
String content = NetworkUtils.doGet(NetworkUtils.toURL(url));
|
||||||
|
Matcher m = LINK_PATTERN.matcher(content);
|
||||||
|
while (m.find())
|
||||||
|
result = m.group(1);
|
||||||
|
if (result == null)
|
||||||
|
throw new IllegalStateException("Cannot find version in " + content);
|
||||||
|
return "http://optifine.net/downloadx?f=OptiFine" + result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,20 +75,19 @@ public final class NetworkUtils {
|
|||||||
SSLContext c = SSLContext.getInstance("SSL");
|
SSLContext c = SSLContext.getInstance("SSL");
|
||||||
c.init(null, new X509TrustManager[] { XTM }, new SecureRandom());
|
c.init(null, new X509TrustManager[] { XTM }, new SecureRandom());
|
||||||
HttpsURLConnection.setDefaultSSLSocketFactory(c.getSocketFactory());
|
HttpsURLConnection.setDefaultSSLSocketFactory(c.getSocketFactory());
|
||||||
} catch (GeneralSecurityException e) {
|
} catch (GeneralSecurityException ignore) {
|
||||||
}
|
}
|
||||||
HttpsURLConnection.setDefaultHostnameVerifier(HNV);
|
HttpsURLConnection.setDefaultHostnameVerifier(HNV);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Supplier<String> userAgentSupplier = () -> RandomUserAgent.randomUserAgent();
|
private static Supplier<String> userAgentSupplier = RandomUserAgent::randomUserAgent;
|
||||||
|
|
||||||
public static String getUserAgent() {
|
public static String getUserAgent() {
|
||||||
return userAgentSupplier.get();
|
return userAgentSupplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUserAgentSupplier(Supplier<String> userAgentSupplier) {
|
public static void setUserAgentSupplier(Supplier<String> userAgentSupplier) {
|
||||||
Objects.requireNonNull(userAgentSupplier);
|
NetworkUtils.userAgentSupplier = Objects.requireNonNull(userAgentSupplier);
|
||||||
NetworkUtils.userAgentSupplier = userAgentSupplier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpURLConnection createConnection(URL url, Proxy proxy) throws IOException {
|
public static HttpURLConnection createConnection(URL url, Proxy proxy) throws IOException {
|
||||||
@ -103,7 +102,7 @@ public final class NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String doGet(URL url) throws IOException {
|
public static String doGet(URL url) throws IOException {
|
||||||
return IOUtils.readFullyAsString(url.openConnection().getInputStream());
|
return IOUtils.readFullyAsString(createConnection(url, Proxy.NO_PROXY).getInputStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String doGet(URL url, Proxy proxy) throws IOException {
|
public static String doGet(URL url, Proxy proxy) throws IOException {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user