FIx: unable to download Forge installer

This commit is contained in:
huanghongxun 2019-09-05 15:49:27 +08:00
parent a9feb65fc8
commit ce3b9e3b1f
3 changed files with 22 additions and 7 deletions

View File

@ -28,11 +28,16 @@ import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.gson.Validation;
import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.jackhuang.hmcl.util.Lang.mapOf;
import static org.jackhuang.hmcl.util.Pair.pair;
public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion> {
public static final ForgeBMCLVersionList INSTANCE = new ForgeBMCLVersionList();
@ -79,10 +84,13 @@ public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion>
String jar = null;
for (ForgeVersion.File file : version.getFiles())
if ("installer".equals(file.getCategory()) && "jar".equals(file.getFormat())) {
String classifier = gameVersion + "-" + version.getVersion()
+ (StringUtils.isNotBlank(version.getBranch()) ? "-" + version.getBranch() : "");
String fileName = "forge-" + classifier + "-" + file.getCategory() + "." + file.getFormat();
jar = "https://bmclapi2.bangbang93.com/maven/net/minecraftforge/forge/" + classifier + "/" + fileName;
jar = NetworkUtils.withQuery("https://bmclapi2.bangbang93.com/forge/download", mapOf(
pair("mcversion", version.getGameVersion()),
pair("version", version.getVersion()),
pair("branch", version.getBranch()),
pair("category", file.getCategory()),
pair("format", file.getFormat())
));
}
if (jar == null)
@ -121,18 +129,22 @@ public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion>
this.files = files;
}
@Nullable
public String getBranch() {
return branch;
}
@NotNull
public String getGameVersion() {
return mcversion;
}
@NotNull
public String getVersion() {
return version;
}
@NotNull
public List<File> getFiles() {
return files;
}

View File

@ -231,12 +231,13 @@ public class ForgeNewInstallTask extends Task<Version> {
command.add(mainClass);
List<String> args = processor.getArgs().stream().map(arg -> {
List<String> args = new ArrayList<>(processor.getArgs().size());
for (String arg : processor.getArgs()) {
String parsed = parseLiteral(arg, data, ExceptionalFunction.identity());
if (parsed == null)
throw new IOException("Invalid forge installation configuration");
return parsed;
}).collect(Collectors.toList());
args.add(parsed);
}
command.addAll(args);

View File

@ -40,6 +40,8 @@ public final class NetworkUtils {
StringBuilder sb = new StringBuilder(baseUrl);
boolean first = true;
for (Entry<String, String> param : params.entrySet()) {
if (param.getValue() == null)
continue;
if (first) {
sb.append('?');
first = false;