diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index 5df15ff4d..5394eec04 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -592,21 +592,14 @@ public final class LauncherHelper { private static CompletableFuture downloadJavaImpl(GameJavaVersion javaVersion, DownloadProvider downloadProvider) { CompletableFuture future = new CompletableFuture<>(); - TaskExecutorDialogPane javaDownloadingPane = new TaskExecutorDialogPane(TaskCancellationAction.NORMAL); - - TaskExecutor executor = JavaRepository.downloadJava(javaVersion, downloadProvider) + Controllers.taskDialog(JavaRepository.downloadJava(javaVersion, downloadProvider) .whenComplete(Schedulers.javafx(), (downloadedJava, exception) -> { if (exception != null) { future.completeExceptionally(exception); } else { future.complete(downloadedJava); } - }) - .executor(false); - - javaDownloadingPane.setExecutor(executor, true); - Controllers.dialog(javaDownloadingPane); - executor.start(); + }), i18n("download.java"), TaskCancellationAction.NORMAL); return future; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java index 4109eb7d9..a848a5af5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java @@ -83,6 +83,10 @@ public class InstallerItem extends Control { case "optifine": imageUrl = "/assets/img/command.png"; break; + case "quilt": + case "quilt-api": + imageUrl = "/assets/img/quilt.png"; + break; default: imageUrl = null; break; @@ -111,40 +115,63 @@ public class InstallerItem extends Control { public final InstallerItem forge = new InstallerItem(FORGE); public final InstallerItem liteLoader = new InstallerItem(LITELOADER); public final InstallerItem optiFine = new InstallerItem(OPTIFINE); + public final InstallerItem quilt = new InstallerItem(QUILT); + public final InstallerItem quiltApi = new InstallerItem(QUILT_API); public InstallerItemGroup() { forge.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { if (fabric.libraryVersion.get() != null) return FABRIC.getPatchId(); + if (quilt.libraryVersion.get() != null) return QUILT.getPatchId(); return null; - }, fabric.libraryVersion)); + }, fabric.libraryVersion, quilt.libraryVersion)); liteLoader.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { if (fabric.libraryVersion.get() != null) return FABRIC.getPatchId(); + if (quilt.libraryVersion.get() != null) return QUILT.getPatchId(); return null; - }, fabric.libraryVersion)); + }, fabric.libraryVersion, quilt.libraryVersion)); optiFine.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { if (fabric.libraryVersion.get() != null) return FABRIC.getPatchId(); + if (quilt.libraryVersion.get() != null) return QUILT.getPatchId(); return null; - }, fabric.libraryVersion)); + }, fabric.libraryVersion, quilt.libraryVersion)); for (InstallerItem fabric : new InstallerItem[]{fabric, fabricApi}) { fabric.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { + if (forge.libraryVersion.get() != null) return FORGE.getPatchId(); if (liteLoader.libraryVersion.get() != null) return LITELOADER.getPatchId(); if (optiFine.libraryVersion.get() != null) return OPTIFINE.getPatchId(); - if (forge.libraryVersion.get() != null) return FORGE.getPatchId(); + if (quilt.libraryVersion.get() != null) return QUILT.getPatchId(); + if (quiltApi.libraryVersion.get() != null) return QUILT_API.getPatchId(); return null; - }, optiFine.libraryVersion, forge.libraryVersion)); + }, forge.libraryVersion, liteLoader.libraryVersion, optiFine.libraryVersion, quilt.libraryVersion, quiltApi.libraryVersion)); } fabricApi.dependencyName.bind(Bindings.createStringBinding(() -> { if (fabric.libraryVersion.get() == null) return FABRIC.getPatchId(); else return null; }, fabric.libraryVersion)); + + for (InstallerItem quilt : new InstallerItem[]{quilt, quiltApi}) { + quilt.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { + if (fabric.libraryVersion.get() != null) return FABRIC.getPatchId(); + if (fabricApi.libraryVersion.get() != null) return FABRIC_API.getPatchId(); + if (forge.libraryVersion.get() != null) return FORGE.getPatchId(); + if (liteLoader.libraryVersion.get() != null) return LITELOADER.getPatchId(); + if (optiFine.libraryVersion.get() != null) return OPTIFINE.getPatchId(); + return null; + }, fabric.libraryVersion, fabricApi.libraryVersion, forge.libraryVersion, liteLoader.libraryVersion, optiFine.libraryVersion)); + } + + quiltApi.dependencyName.bind(Bindings.createStringBinding(() -> { + if (quilt.libraryVersion.get() == null) return QUILT.getPatchId(); + else return null; + }, quilt.libraryVersion)); } public InstallerItem[] getLibraries() { - return new InstallerItem[]{game, forge, liteLoader, optiFine, fabric, fabricApi}; + return new InstallerItem[]{game, forge, liteLoader, optiFine, fabric, fabricApi, quilt, quiltApi}; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java index c5957b33f..319c60653 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java @@ -34,6 +34,7 @@ import org.jackhuang.hmcl.download.forge.ForgeNewInstallTask; import org.jackhuang.hmcl.download.forge.ForgeOldInstallTask; import org.jackhuang.hmcl.download.game.GameAssetDownloadTask; import org.jackhuang.hmcl.download.game.GameInstallTask; +import org.jackhuang.hmcl.download.java.JavaDownloadTask; import org.jackhuang.hmcl.download.liteloader.LiteLoaderInstallTask; import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask; import org.jackhuang.hmcl.game.HMCLModpackInstallTask; @@ -148,6 +149,8 @@ public final class TaskListPane extends StackPane { task.setName(i18n("modpack.export")); } else if (task instanceof MinecraftInstanceTask) { task.setName(i18n("modpack.scan")); + } else if (task instanceof JavaDownloadTask) { + task.setName(i18n("download.java")); } Platform.runLater(() -> { @@ -243,6 +246,7 @@ public final class TaskListPane extends StackPane { case "hmcl.install.optifine": message = i18n("install.installer.install", i18n("install.installer.optifine") + " " + stageValue); break; case "hmcl.install.fabric": message = i18n("install.installer.install", i18n("install.installer.fabric") + " " + stageValue); break; case "hmcl.install.fabric-api": message = i18n("install.installer.install", i18n("install.installer.fabric-api") + " " + stageValue); break; + case "hmcl.install.quilt": message = i18n("install.installer.install", i18n("install.installer.quilt") + " " + stageValue); break; default: message = i18n(stageKey); break; } // @formatter:on diff --git a/HMCL/src/main/resources/assets/img/quilt.png b/HMCL/src/main/resources/assets/img/quilt.png new file mode 100644 index 000000000..591ad3365 Binary files /dev/null and b/HMCL/src/main/resources/assets/img/quilt.png differ diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 892b56256..cbd7cb8a0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -312,6 +312,7 @@ download.provider.mojang=Mojang (OptiFine is provided by BMCLAPI) download.provider.official=From Official Sources download.provider.balanced=From Fastest Available download.provider.mirror=From Mirror +download.java=Downloading Java download.javafx=Downloading dependencies for launcher... download.javafx.notes=We are currently downloading dependencies for HMCL from the Internet.\n\ \n\ @@ -590,6 +591,7 @@ install.installer.install_online.tooltip=We currently support Fabric, Forge, Opt install.installer.liteloader=LiteLoader install.installer.not_installed=Not Selected install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=Install a Modpack install.new_game=Add a New Instance diff --git a/HMCL/src/main/resources/assets/lang/I18N_es.properties b/HMCL/src/main/resources/assets/lang/I18N_es.properties index 030497e74..d1bb51669 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_es.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_es.properties @@ -588,6 +588,7 @@ install.installer.install_online.tooltip=Actualmente soportamos Fabric, Forge, O install.installer.liteloader=LiteLoader install.installer.not_installed=No seleccionado install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=Instalar un Modpack install.new_game=Añadir instancia diff --git a/HMCL/src/main/resources/assets/lang/I18N_ja.properties b/HMCL/src/main/resources/assets/lang/I18N_ja.properties index e9a217039..cb4ece011 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ja.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ja.properties @@ -444,6 +444,7 @@ install.installer.install_online.tooltip=Fabric、Forge、OptiFine、LiteLoader install.installer.liteloader=LiteLoader install.installer.not_installed=インストールされていません install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=modpackを導入 install.new_game=新規作成 diff --git a/HMCL/src/main/resources/assets/lang/I18N_ru.properties b/HMCL/src/main/resources/assets/lang/I18N_ru.properties index 8c8ec42ae..7d0d03f0b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ru.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ru.properties @@ -446,6 +446,7 @@ install.installer.install_online.tooltip=Поддержка установки F install.installer.liteloader=LiteLoader install.installer.not_installed=Не установлен install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=Установить модпак install.new_game=Установить новую игру diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 74891f62c..7369e0cb0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -300,6 +300,7 @@ download.provider.mojang=官方伺服器 (OptiFine 自動安裝的下載來源 download.provider.official=儘量使用官方源(最新,但可能加載慢) download.provider.balanced=選擇加載速度快的下載源(平衡,但可能不是最新) download.provider.mirror=儘量使用鏡像源(加載快,但可能不是最新) +download.java=下載 Java download.javafx=正在下載必要的運行時組件 download.javafx.notes=正在通過網絡下載 HMCL 必要的運行時組件。\n點擊“切換下載源”按鈕查看詳情以及選擇下載源,點擊“取消”按鈕停止並退出。\n注意:如果下載速度過慢,請嘗試切换下載源。 download.javafx.component=正在下載模塊 %s @@ -451,6 +452,7 @@ install.installer.install_online.tooltip=支援安裝 Fabric、Forge、OptiFine install.installer.liteloader=LiteLoader install.installer.not_installed=不安裝 install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=安裝模組包 install.new_game=安裝新遊戲版本 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index ca6fb2d5c..60dc61a79 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -300,6 +300,7 @@ download.provider.mojang=官方(OptiFine 自动安装使用 BMCLAPI 下载源 download.provider.official=尽量使用官方源(最新,但可能加载慢) download.provider.balanced=选择加载速度快的下载源(平衡,但可能不是最新) download.provider.mirror=尽量使用镜像源(加载快,但可能不是最新) +download.java=下载 Java download.javafx=正在下载必要的运行时组件…… download.javafx.notes=正在通过网络下载 HMCL 必要的运行时组件。\n点击“切换下载源”按钮查看详情以及选择下载源,点击“取消”按钮停止并退出。\n注意:若下载速度过慢,请尝试切换下载源 download.javafx.component=正在下载模块 %s @@ -451,6 +452,7 @@ install.installer.install_online.tooltip=支持安装 Fabric、Forge、OptiFine install.installer.liteloader=LiteLoader install.installer.not_installed=不安装 install.installer.optifine=OptiFine +install.installer.quilt=Quilt install.installer.version=%s install.modpack=安装整合包 install.new_game=安装新游戏版本 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.java index 18d172e56..3b2294216 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.java @@ -23,6 +23,8 @@ import org.jackhuang.hmcl.download.forge.ForgeBMCLVersionList; import org.jackhuang.hmcl.download.game.GameVersionList; import org.jackhuang.hmcl.download.liteloader.LiteLoaderBMCLVersionList; import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList; +import org.jackhuang.hmcl.download.quilt.QuiltAPIVersionList; +import org.jackhuang.hmcl.download.quilt.QuiltVersionList; /** * @@ -33,20 +35,22 @@ public class BMCLAPIDownloadProvider implements DownloadProvider { private final GameVersionList game; private final FabricVersionList fabric; private final FabricAPIVersionList fabricApi; - private final QuiltVersionList quilt; private final ForgeBMCLVersionList forge; private final LiteLoaderBMCLVersionList liteLoader; private final OptiFineBMCLVersionList optifine; + private final QuiltVersionList quilt; + private final QuiltAPIVersionList quiltApi; public BMCLAPIDownloadProvider(String apiRoot) { this.apiRoot = apiRoot; this.game = new GameVersionList(this); this.fabric = new FabricVersionList(this); this.fabricApi = new FabricAPIVersionList(this); - this.quilt = new QuiltVersionList(this); this.forge = new ForgeBMCLVersionList(apiRoot); this.liteLoader = new LiteLoaderBMCLVersionList(this); this.optifine = new OptiFineBMCLVersionList(apiRoot); + this.quilt = new QuiltVersionList(this); + this.quiltApi = new QuiltAPIVersionList(this); } public String getApiRoot() { @@ -74,12 +78,14 @@ public class BMCLAPIDownloadProvider implements DownloadProvider { return fabricApi; case "forge": return forge; - case "quilt": - return quilt; case "liteloader": return liteLoader; case "optifine": return optifine; + case "quilt": + return quilt; + case "quilt-api": + return quiltApi; default: throw new IllegalArgumentException("Unrecognized version list id: " + id); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java index 7cc903b15..77e9bdf7b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java @@ -161,7 +161,6 @@ public final class LibraryAnalyzer implements Iterable[0-9.]+)(-([0-9.]+))?$"); @@ -177,6 +176,8 @@ public final class LibraryAnalyzer implements Iterablehttp://wiki.vg @@ -35,6 +37,8 @@ public class MojangDownloadProvider implements DownloadProvider { private final ForgeBMCLVersionList forge; private final LiteLoaderVersionList liteLoader; private final OptiFineBMCLVersionList optifine; + private final QuiltVersionList quilt; + private final QuiltAPIVersionList quiltApi; public MojangDownloadProvider() { String apiRoot = "https://bmclapi2.bangbang93.com"; @@ -45,6 +49,8 @@ public class MojangDownloadProvider implements DownloadProvider { this.forge = new ForgeBMCLVersionList(apiRoot); this.liteLoader = new LiteLoaderVersionList(this); this.optifine = new OptiFineBMCLVersionList(apiRoot); + this.quilt = new QuiltVersionList(this); + this.quiltApi = new QuiltAPIVersionList(this); } @Override @@ -72,6 +78,10 @@ public class MojangDownloadProvider implements DownloadProvider { return liteLoader; case "optifine": return optifine; + case "quilt": + return quilt; + case "quilt-api": + return quiltApi; default: throw new IllegalArgumentException("Unrecognized version list id: " + id); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/java/JavaDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/java/JavaDownloadTask.java index 002526f3d..7c35f9375 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/java/JavaDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/java/JavaDownloadTask.java @@ -94,7 +94,7 @@ public class JavaDownloadTask extends Task { RemoteFiles.RemoteFile file = ((RemoteFiles.RemoteFile) entry.getValue()); if (file.getDownloads().containsKey("lzma")) { DownloadInfo download = file.getDownloads().get("lzma"); - File tempFile = Files.createTempFile("hmcl", "tmp").toFile(); + File tempFile = jvmDir.resolve(entry.getKey() + ".lzma").toFile(); FileDownloadTask task = new FileDownloadTask(NetworkUtils.toURL(download.getUrl()), tempFile, new FileDownloadTask.IntegrityCheck("SHA-1", download.getSha1())); task.setName(entry.getKey()); dependencies.add(task.thenRunAsync(() -> { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java new file mode 100644 index 000000000..4d3f88790 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java @@ -0,0 +1,67 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.quilt; + +import org.jackhuang.hmcl.download.DefaultDependencyManager; +import org.jackhuang.hmcl.game.Version; +import org.jackhuang.hmcl.task.FileDownloadTask; +import org.jackhuang.hmcl.task.Task; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Note: Quilt should be installed first. + * + * @author huangyuhui + */ +public final class QuiltAPIInstallTask extends Task { + + private final DefaultDependencyManager dependencyManager; + private final Version version; + private final QuiltAPIRemoteVersion remote; + private final List> dependencies = new ArrayList<>(1); + + public QuiltAPIInstallTask(DefaultDependencyManager dependencyManager, Version version, QuiltAPIRemoteVersion remoteVersion) { + this.dependencyManager = dependencyManager; + this.version = version; + this.remote = remoteVersion; + } + + @Override + public Collection> getDependencies() { + return dependencies; + } + + @Override + public boolean isRelyingOnDependencies() { + return false; + } + + @Override + public void execute() throws IOException { + dependencies.add(new FileDownloadTask( + new URL(remote.getVersion().getFile().getUrl()), + dependencyManager.getGameRepository().getRunDirectory(version.getId()).toPath().resolve("mods").resolve("quilt-api-" + remote.getVersion().getVersion() + ".jar").toFile(), + remote.getVersion().getFile().getIntegrityCheck()) + ); + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIRemoteVersion.java new file mode 100644 index 000000000..12113d340 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIRemoteVersion.java @@ -0,0 +1,68 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.quilt; + +import org.jackhuang.hmcl.download.DefaultDependencyManager; +import org.jackhuang.hmcl.download.LibraryAnalyzer; +import org.jackhuang.hmcl.download.RemoteVersion; +import org.jackhuang.hmcl.download.fabric.FabricAPIInstallTask; +import org.jackhuang.hmcl.game.Version; +import org.jackhuang.hmcl.mod.RemoteMod; +import org.jackhuang.hmcl.task.Task; + +import java.util.Date; +import java.util.List; + +public class QuiltAPIRemoteVersion extends RemoteVersion { + private final String fullVersion; + private final RemoteMod.Version version; + + /** + * Constructor. + * + * @param gameVersion the Minecraft version that this remote version suits. + * @param selfVersion the version string of the remote version. + * @param urls the installer or universal jar original URL. + */ + QuiltAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, Date datePublished, RemoteMod.Version version, List urls) { + super(LibraryAnalyzer.LibraryType.QUILT_API.getPatchId(), gameVersion, selfVersion, datePublished, urls); + + this.fullVersion = fullVersion; + this.version = version; + } + + @Override + public String getFullVersion() { + return fullVersion; + } + + public RemoteMod.Version getVersion() { + return version; + } + + @Override + public Task getInstallTask(DefaultDependencyManager dependencyManager, Version baseVersion) { + return new QuiltAPIInstallTask(dependencyManager, baseVersion, this); + } + + @Override + public int compareTo(RemoteVersion o) { + if (!(o instanceof QuiltAPIRemoteVersion)) return 0; + return -this.getReleaseDate().compareTo(o.getReleaseDate()); + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java new file mode 100644 index 000000000..7cd914b37 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java @@ -0,0 +1,56 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.quilt; + +import org.jackhuang.hmcl.download.DownloadProvider; +import org.jackhuang.hmcl.download.VersionList; +import org.jackhuang.hmcl.download.fabric.FabricAPIRemoteVersion; +import org.jackhuang.hmcl.mod.RemoteMod; +import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository; +import org.jackhuang.hmcl.util.Lang; + +import java.util.Collections; +import java.util.concurrent.CompletableFuture; + +import static org.jackhuang.hmcl.util.Lang.wrap; + +public class QuiltAPIVersionList extends VersionList { + + private final DownloadProvider downloadProvider; + + public QuiltAPIVersionList(DownloadProvider downloadProvider) { + this.downloadProvider = downloadProvider; + } + + @Override + public boolean hasType() { + return false; + } + + @Override + public CompletableFuture refreshAsync() { + return CompletableFuture.runAsync(wrap(() -> { + for (RemoteMod.Version modVersion : Lang.toIterable(ModrinthRemoteModRepository.MODS.getRemoteVersionsById("qsl"))) { + for (String gameVersion : modVersion.getGameVersions()) { + versions.put(gameVersion, new QuiltAPIRemoteVersion(gameVersion, modVersion.getVersion(), modVersion.getName(), modVersion.getDatePublished(), modVersion, + Collections.singletonList(modVersion.getFile().getUrl()))); + } + } + })); + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltInstallTask.java index 1772ce330..66cab6485 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltInstallTask.java @@ -85,13 +85,13 @@ public final class QuiltInstallTask extends Task { @Override public void execute() { - setResult(getPatch(JsonUtils.GSON.fromJson(launchMetaTask.getResult(), FabricInfo.class), remote.getGameVersion(), remote.getSelfVersion())); + setResult(getPatch(JsonUtils.GSON.fromJson(launchMetaTask.getResult(), QuiltInfo.class), remote.getGameVersion(), remote.getSelfVersion())); dependencies.add(dependencyManager.checkLibraryCompletionAsync(getResult(), true)); } - private Version getPatch(FabricInfo fabricInfo, String gameVersion, String loaderVersion) { - JsonObject launcherMeta = fabricInfo.launcherMeta; + private Version getPatch(QuiltInfo quiltInfo, String gameVersion, String loaderVersion) { + JsonObject launcherMeta = quiltInfo.launcherMeta; Arguments arguments = new Arguments(); String mainClass; @@ -117,19 +117,34 @@ public final class QuiltInstallTask extends Task { } } - libraries.add(new Library(Artifact.fromDescriptor(fabricInfo.intermediary.maven), "https://maven.fabricmc.net/", null)); - libraries.add(new Library(Artifact.fromDescriptor(fabricInfo.loader.maven), "https://maven.fabricmc.net/", null)); + libraries.add(new Library(Artifact.fromDescriptor(quiltInfo.hashed.maven), getMavenRepositoryByGroup(quiltInfo.hashed.maven), null)); + libraries.add(new Library(Artifact.fromDescriptor(quiltInfo.intermediary.maven), getMavenRepositoryByGroup(quiltInfo.intermediary.maven), null)); + libraries.add(new Library(Artifact.fromDescriptor(quiltInfo.loader.maven), getMavenRepositoryByGroup(quiltInfo.loader.maven), null)); - return new Version(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), loaderVersion, 30000, arguments, mainClass, libraries); + return new Version(LibraryAnalyzer.LibraryType.QUILT.getPatchId(), loaderVersion, 30000, arguments, mainClass, libraries); } - public static class FabricInfo { + private static String getMavenRepositoryByGroup(String maven) { + Artifact artifact = Artifact.fromDescriptor(maven); + switch (artifact.getGroup()) { + case "net.fabricmc": + return "https://maven.fabricmc.net/"; + case "org.quiltmc": + return "https://maven.quiltmc.org/repository/release/"; + default: + return "https://maven.fabricmc.net/"; + } + } + + public static class QuiltInfo { private final LoaderInfo loader; private final IntermediaryInfo hashed; + private final IntermediaryInfo intermediary; private final JsonObject launcherMeta; - public FabricInfo(LoaderInfo loader, IntermediaryInfo intermediary, JsonObject launcherMeta) { + public QuiltInfo(LoaderInfo loader, IntermediaryInfo hashed, IntermediaryInfo intermediary, JsonObject launcherMeta) { this.loader = loader; + this.hashed = hashed; this.intermediary = intermediary; this.launcherMeta = launcherMeta; } @@ -138,6 +153,10 @@ public final class QuiltInstallTask extends Task { return loader; } + public IntermediaryInfo getHashed() { + return hashed; + } + public IntermediaryInfo getIntermediary() { return intermediary; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltRemoteVersion.java index c27e96498..561c6d760 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltRemoteVersion.java @@ -35,7 +35,7 @@ public class QuiltRemoteVersion extends RemoteVersion { * @param urls the installer or universal jar original URL. */ QuiltRemoteVersion(String gameVersion, String selfVersion, List urls) { - super(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), gameVersion, selfVersion, null, urls); + super(LibraryAnalyzer.LibraryType.QUILT.getPatchId(), gameVersion, selfVersion, null, urls); } @Override