fix(download): download fabric-api from curseforge.

This commit is contained in:
huanghongxun 2021-12-20 01:22:38 +08:00
parent 35943feb08
commit 9aa73f5a5c
2 changed files with 15 additions and 25 deletions

View File

@ -21,6 +21,7 @@ import org.jackhuang.hmcl.download.*;
import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.Task;
import java.time.Instant;
import java.util.List; import java.util.List;
public class FabricAPIRemoteVersion extends RemoteVersion { public class FabricAPIRemoteVersion extends RemoteVersion {
@ -33,8 +34,8 @@ public class FabricAPIRemoteVersion extends RemoteVersion {
* @param selfVersion the version string of the remote version. * @param selfVersion the version string of the remote version.
* @param urls the installer or universal jar original URL. * @param urls the installer or universal jar original URL.
*/ */
FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, List<String> urls) { FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, Instant datePublished, List<String> urls) {
super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, null, urls); super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, datePublished, urls);
this.fullVersion = fullVersion; this.fullVersion = fullVersion;
} }
@ -49,4 +50,9 @@ public class FabricAPIRemoteVersion extends RemoteVersion {
return new FabricAPIInstallTask(dependencyManager, baseVersion, this); return new FabricAPIInstallTask(dependencyManager, baseVersion, this);
} }
@Override
public int compareTo(RemoteVersion o) {
if (!(o instanceof FabricAPIRemoteVersion)) return 0;
return -this.getReleaseDate().compareTo(o.getReleaseDate());
}
} }

View File

@ -19,12 +19,10 @@ package org.jackhuang.hmcl.download.fabric;
import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.download.VersionList; import org.jackhuang.hmcl.download.VersionList;
import org.w3c.dom.Document; import org.jackhuang.hmcl.mod.RemoteMod;
import org.w3c.dom.Element; import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
import org.w3c.dom.NodeList; import org.jackhuang.hmcl.util.Lang;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -49,24 +47,10 @@ public class FabricAPIVersionList extends VersionList<FabricAPIRemoteVersion> {
@Override @Override
public CompletableFuture<?> refreshAsync() { public CompletableFuture<?> refreshAsync() {
return CompletableFuture.runAsync(wrap(() -> { return CompletableFuture.runAsync(wrap(() -> {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); for (RemoteMod.Version modVersion : Lang.toIterable(CurseForgeRemoteModRepository.MODS.getRemoteVersionsById("306612"))) {
DocumentBuilder builder = factory.newDocumentBuilder(); for (String gameVersion : modVersion.getGameVersions()) {
Document doc = builder.parse("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml"); versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.getName(), modVersion.getName(), modVersion.getDatePublished(),
Element r = doc.getDocumentElement(); Collections.singletonList(modVersion.getFile().getUrl())));
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))));
} }
} }
})); }));