From 9aa73f5a5c4cc40b854fb724b4a8d179e34a42fb Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Mon, 20 Dec 2021 01:22:38 +0800 Subject: [PATCH] fix(download): download fabric-api from curseforge. --- .../fabric/FabricAPIRemoteVersion.java | 10 +++++-- .../download/fabric/FabricAPIVersionList.java | 30 +++++-------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java index 479d48497..3865d41ad 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java @@ -21,6 +21,7 @@ import org.jackhuang.hmcl.download.*; import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.task.Task; +import java.time.Instant; import java.util.List; public class FabricAPIRemoteVersion extends RemoteVersion { @@ -33,8 +34,8 @@ public class FabricAPIRemoteVersion extends RemoteVersion { * @param selfVersion the version string of the remote version. * @param urls the installer or universal jar original URL. */ - FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, List urls) { - super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, null, urls); + FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, Instant datePublished, List urls) { + super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, datePublished, urls); this.fullVersion = fullVersion; } @@ -49,4 +50,9 @@ public class FabricAPIRemoteVersion extends RemoteVersion { return new FabricAPIInstallTask(dependencyManager, baseVersion, this); } + @Override + public int compareTo(RemoteVersion o) { + if (!(o instanceof FabricAPIRemoteVersion)) return 0; + return -this.getReleaseDate().compareTo(o.getReleaseDate()); + } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java index 86c8cccac..5baeb3cb0 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java @@ -19,12 +19,10 @@ package org.jackhuang.hmcl.download.fabric; import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.VersionList; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; +import org.jackhuang.hmcl.mod.RemoteMod; +import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository; +import org.jackhuang.hmcl.util.Lang; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import java.util.Collection; import java.util.Collections; import java.util.concurrent.CompletableFuture; @@ -49,24 +47,10 @@ public class FabricAPIVersionList extends VersionList { @Override public CompletableFuture refreshAsync() { return CompletableFuture.runAsync(wrap(() -> { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.parse("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml"); - Element r = doc.getDocumentElement(); - NodeList versionElements = r.getElementsByTagName("version"); - for (int i = 0; i < versionElements.getLength(); i++) { - String versionName = versionElements.item(i).getTextContent(); - - Matcher matcher = FABRIC_VERSION_PATTERN.matcher(versionName); - if (matcher.find()) { - String fabricVersion = matcher.group("version"); - if (matcher.group("build") != null) { - fabricVersion += "." + matcher.group("build"); - } - String gameVersion = matcher.group("mcversion"); - versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, fabricVersion, versionName, - Collections.singletonList(String.format( - "https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/%1$s/fabric-api-%1$s.jar", versionName)))); + for (RemoteMod.Version modVersion : Lang.toIterable(CurseForgeRemoteModRepository.MODS.getRemoteVersionsById("306612"))) { + for (String gameVersion : modVersion.getGameVersions()) { + versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.getName(), modVersion.getName(), modVersion.getDatePublished(), + Collections.singletonList(modVersion.getFile().getUrl()))); } } }));