add: BMCLAPI support for fabric download

This commit is contained in:
huanghongxun 2020-02-09 00:55:51 +08:00
parent bdb6784a9b
commit b1301dcdec
3 changed files with 14 additions and 7 deletions

View File

@ -30,6 +30,7 @@ import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList;
public class BMCLAPIDownloadProvider implements DownloadProvider {
private final String apiRoot;
private final GameVersionList game;
private final FabricVersionList fabric;
private final ForgeBMCLVersionList forge;
private final LiteLoaderBMCLVersionList liteLoader;
private final OptiFineBMCLVersionList optifine;
@ -37,6 +38,7 @@ public class BMCLAPIDownloadProvider implements DownloadProvider {
public BMCLAPIDownloadProvider(String apiRoot) {
this.apiRoot = apiRoot;
this.game = new GameVersionList(this);
this.fabric = new FabricVersionList(this);
this.forge = new ForgeBMCLVersionList(apiRoot);
this.liteLoader = new LiteLoaderBMCLVersionList(this);
this.optifine = new OptiFineBMCLVersionList(apiRoot);
@ -62,7 +64,7 @@ public class BMCLAPIDownloadProvider implements DownloadProvider {
case "game":
return game;
case "fabric":
return FabricVersionList.INSTANCE;
return fabric;
case "forge":
return forge;
case "liteloader":
@ -83,6 +85,8 @@ public class BMCLAPIDownloadProvider implements DownloadProvider {
.replaceFirst("https?://files\\.minecraftforge\\.net/maven", apiRoot + "/maven")
.replace("http://dl.liteloader.com/versions/versions.json", apiRoot + "/maven/com/mumfrey/liteloader/versions.json")
.replace("http://dl.liteloader.com/versions", apiRoot + "/maven")
.replace("https://meta.fabricmc.net/v2/versions/game", apiRoot + "/fabric-meta/v2/versions")
.replace("https://maven.fabricmc.net", apiRoot + "/maven")
.replace("https://authlib-injector.yushi.moe", apiRoot + "/mirrors/authlib-injector");
}

View File

@ -29,6 +29,7 @@ import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList;
*/
public class MojangDownloadProvider implements DownloadProvider {
private final GameVersionList game;
private final FabricVersionList fabric;
private final ForgeBMCLVersionList forge;
private final LiteLoaderVersionList liteLoader;
private final OptiFineBMCLVersionList optifine;
@ -37,6 +38,7 @@ public class MojangDownloadProvider implements DownloadProvider {
String apiRoot = "https://bmclapi2.bangbang93.com";
this.game = new GameVersionList(this);
this.fabric = new FabricVersionList(this);
this.forge = new ForgeBMCLVersionList(apiRoot);
this.liteLoader = new LiteLoaderVersionList(this);
this.optifine = new OptiFineBMCLVersionList(apiRoot);
@ -58,7 +60,7 @@ public class MojangDownloadProvider implements DownloadProvider {
case "game":
return game;
case "fabric":
return FabricVersionList.INSTANCE;
return fabric;
case "forge":
return forge;
case "liteloader":

View File

@ -18,6 +18,7 @@
package org.jackhuang.hmcl.download.fabric;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.VersionList;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.gson.JsonUtils;
@ -34,10 +35,10 @@ import java.util.List;
import java.util.stream.Collectors;
public final class FabricVersionList extends VersionList<FabricRemoteVersion> {
private final DownloadProvider downloadProvider;
public static final FabricVersionList INSTANCE = new FabricVersionList();
private FabricVersionList() {
public FabricVersionList(DownloadProvider downloadProvider) {
this.downloadProvider = downloadProvider;
}
@Override
@ -73,7 +74,7 @@ public final class FabricVersionList extends VersionList<FabricRemoteVersion> {
private List<String> getVersions(String mavenServerURL, String packageName, String jarName) throws IOException, XMLStreamException {
List<String> versions = new ArrayList<>();
URL url = new URL(mavenServerURL + packageName + "/" + jarName + "/maven-metadata.xml");
URL url = new URL(downloadProvider.injectURL(mavenServerURL + packageName + "/" + jarName + "/maven-metadata.xml"));
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(url.openStream());
while(reader.hasNext()) {
@ -89,7 +90,7 @@ public final class FabricVersionList extends VersionList<FabricRemoteVersion> {
}
private List<String> getGameVersions(String metaUrl) throws IOException {
String json = NetworkUtils.doGet(NetworkUtils.toURL(metaUrl));
String json = NetworkUtils.doGet(NetworkUtils.toURL(downloadProvider.injectURL(metaUrl)));
return JsonUtils.GSON.<ArrayList<GameVersion>>fromJson(json, new TypeToken<ArrayList<GameVersion>>() {
}.getType()).stream().map(GameVersion::getVersion).collect(Collectors.toList());
}