Repository: HMCL-dev/HMCL (language: java)

Issue:
[Bug] 1.7.10-pre4 无法选择forge安装版本
### 平台 | Platform

Windows 10

### 问题描述 | Problem Description

选择 1.7.10-pre4 版本，选择 forge，并没有显示

但在 bmclapi 的结果看，他所支持的是 1.7.10_pre4

而 hmcl 向 bmclapi 请求的是 1.7.10-pre4

### 启动器崩溃报告 / 启动器日志文件 | Launcher Crash Report / Launcher Log File

-


Discussion / hints:
还有其他版本会出现此类问题吗？

Fix patch:
diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeBMCLVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeBMCLVersionList.java
index d63d7d156e..cd0cfcd109 100644
--- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeBMCLVersionList.java
+++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeBMCLVersionList.java
@@ -30,13 +30,16 @@
 
 import java.time.Instant;
 import java.time.format.DateTimeParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 
 import static org.jackhuang.hmcl.util.Lang.mapOf;
 import static org.jackhuang.hmcl.util.Lang.wrap;
-import static org.jackhuang.hmcl.util.logging.Logger.LOG;
 import static org.jackhuang.hmcl.util.Pair.pair;
+import static org.jackhuang.hmcl.util.logging.Logger.LOG;
 
 public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion> {
     private final String apiRoot;
@@ -63,10 +66,20 @@ public CompletableFuture<?> refreshAsync() {
         throw new UnsupportedOperationException("ForgeBMCLVersionList does not support loading the entire Forge remote version list.");
     }
 
+    public String toLookupVersion(String version) {
+        return "1.7.10-pre4".equals(version) ? "1.7.10_pre4" : version;
+    }
+
+    public String fromLookupVersion(String version) {
+        return "1.7.10_pre4".equals(version) ? "1.7.10-pre4" : version;
+    }
+
     @Override
     public CompletableFuture<?> refreshAsync(String gameVersion) {
+        String lookupVersion = toLookupVersion(gameVersion);
+
         return CompletableFuture.completedFuture(null)
-                .thenApplyAsync(wrap(unused -> HttpRequest.GET(apiRoot + "/forge/minecraft/" + gameVersion).<List<ForgeVersion>>getJson(new TypeToken<List<ForgeVersion>>() {
+                .thenApplyAsync(wrap(unused -> HttpRequest.GET(apiRoot + "/forge/minecraft/" + lookupVersion).<List<ForgeVersion>>getJson(new TypeToken<List<ForgeVersion>>() {
                 }.getType())))
                 .thenAcceptAsync(forgeVersions -> {
                     lock.writeLock().lock();
@@ -80,12 +93,12 @@ public CompletableFuture<?> refreshAsync(String gameVersion) {
                             List<String> urls = new ArrayList<>();
                             for (ForgeVersion.File file : version.getFiles())
                                 if ("installer".equals(file.getCategory()) && "jar".equals(file.getFormat())) {
-                                    String classifier = gameVersion + "-" + version.getVersion()
+                                    String classifier = lookupVersion + "-" + version.getVersion()
                                             + (StringUtils.isNotBlank(version.getBranch()) ? "-" + version.getBranch() : "");
                                     String fileName1 = "forge-" + classifier + "-" + file.getCategory() + "." + file.getFormat();
-                                    String fileName2 = "forge-" + classifier + "-" + gameVersion + "-" + file.getCategory() + "." + file.getFormat();
+                                    String fileName2 = "forge-" + classifier + "-" + lookupVersion + "-" + file.getCategory() + "." + file.getFormat();
                                     urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "/" + fileName1);
-                                    urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "-" + gameVersion + "/" + fileName2);
+                                    urls.add("https://files.minecraftforge.net/maven/net/minecraftforge/forge/" + classifier + "-" + lookupVersion + "/" + fileName2);
                                     urls.add(NetworkUtils.withQuery("https://bmclapi2.bangbang93.com/forge/download", mapOf(
                                             pair("mcversion", version.getGameVersion()),
                                             pair("version", version.getVersion()),
@@ -108,7 +121,7 @@ public CompletableFuture<?> refreshAsync(String gameVersion) {
                             }
 
                             versions.put(gameVersion, new ForgeRemoteVersion(
-                                    version.getGameVersion(), version.getVersion(), releaseDate, urls));
+                                    fromLookupVersion(version.getGameVersion()), version.getVersion(), releaseDate, urls));
                         }
                     } finally {
                         lock.writeLock().unlock();


Test patch: