导出带启动器 Modrinth 整合包使用 zip 格式 & 内部改为 mrpack (#5195)

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
辞庐
2026-01-15 23:53:07 +08:00
committed by GitHub
parent 83782f5628
commit 6fd6022210
3 changed files with 26 additions and 12 deletions

View File

@@ -22,10 +22,10 @@ import org.jackhuang.hmcl.Metadata;
import org.jackhuang.hmcl.mod.ModAdviser; import org.jackhuang.hmcl.mod.ModAdviser;
import org.jackhuang.hmcl.mod.ModpackExportInfo; import org.jackhuang.hmcl.mod.ModpackExportInfo;
import org.jackhuang.hmcl.mod.mcbbs.McbbsModpackExportTask; import org.jackhuang.hmcl.mod.mcbbs.McbbsModpackExportTask;
import org.jackhuang.hmcl.mod.modrinth.ModrinthModpackExportTask;
import org.jackhuang.hmcl.mod.multimc.MultiMCInstanceConfiguration; import org.jackhuang.hmcl.mod.multimc.MultiMCInstanceConfiguration;
import org.jackhuang.hmcl.mod.multimc.MultiMCModpackExportTask; import org.jackhuang.hmcl.mod.multimc.MultiMCModpackExportTask;
import org.jackhuang.hmcl.mod.server.ServerModpackExportTask; import org.jackhuang.hmcl.mod.server.ServerModpackExportTask;
import org.jackhuang.hmcl.mod.modrinth.ModrinthModpackExportTask;
import org.jackhuang.hmcl.setting.Config; import org.jackhuang.hmcl.setting.Config;
import org.jackhuang.hmcl.setting.FontManager; import org.jackhuang.hmcl.setting.FontManager;
import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profile;
@@ -41,7 +41,9 @@ import org.jackhuang.hmcl.util.io.Zipper;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.setting.ConfigHolder.config;
@@ -132,7 +134,9 @@ public final class ExportWizardProvider implements WizardProvider {
exported.getAuthlibInjectorServers().setAll(config().getAuthlibInjectorServers()); exported.getAuthlibInjectorServers().setAll(config().getAuthlibInjectorServers());
zip.putTextFile(exported.toJson(), ".hmcl/hmcl.json"); zip.putTextFile(exported.toJson(), ".hmcl/hmcl.json");
zip.putFile(tempModpack, "modpack.zip"); zip.putFile(tempModpack, ModpackTypeSelectionPage.MODPACK_TYPE_MODRINTH.equals(modpackType)
? "modpack.mrpack"
: "modpack.zip");
Path bg = Metadata.HMCL_CURRENT_DIRECTORY.resolve("background"); Path bg = Metadata.HMCL_CURRENT_DIRECTORY.resolve("background");
if (!Files.isDirectory(bg)) if (!Files.isDirectory(bg))
@@ -263,10 +267,10 @@ public final class ExportWizardProvider implements WizardProvider {
@Override @Override
public void execute() { public void execute() {
dependency = new ModrinthModpackExportTask( dependency = new ModrinthModpackExportTask(
profile.getRepository(), profile.getRepository(),
version, version,
exportInfo, exportInfo,
modpackFile modpackFile
); );
} }

View File

@@ -109,7 +109,7 @@ public final class ModpackInfoPage extends Control implements WizardPage {
private void onNext() { private void onNext() {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(i18n("modpack.wizard.step.initialization.save")); fileChooser.setTitle(i18n("modpack.wizard.step.initialization.save"));
if (controller.getSettings().get(MODPACK_TYPE) == MODPACK_TYPE_MODRINTH) { if (!packWithLauncher.get() && controller.getSettings().get(MODPACK_TYPE) == MODPACK_TYPE_MODRINTH) {
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(i18n("modpack"), "*.mrpack")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(i18n("modpack"), "*.mrpack"));
fileChooser.setInitialFileName(name.get() + (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS ? "" : ".mrpack")); fileChooser.setInitialFileName(name.get() + (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS ? "" : ".mrpack"));
} else { } else {

View File

@@ -293,11 +293,21 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage {
checkedModpack = true; checkedModpack = true;
if (repository.getVersionCount() == 0) { if (repository.getVersionCount() == 0) {
Path modpackFile = Metadata.CURRENT_DIRECTORY.resolve("modpack.zip"); Path zipModpack = Metadata.CURRENT_DIRECTORY.resolve("modpack.zip");
if (Files.exists(modpackFile)) { Path mrpackModpack = Metadata.CURRENT_DIRECTORY.resolve("modpack.mrpack");
Path modpackFile;
if (Files.exists(zipModpack)) {
modpackFile = zipModpack;
} else if (Files.exists(mrpackModpack)) {
modpackFile = mrpackModpack;
} else {
modpackFile = null;
}
if (modpackFile != null) {
Task.supplyAsync(() -> CompressingUtils.findSuitableEncoding(modpackFile)) Task.supplyAsync(() -> CompressingUtils.findSuitableEncoding(modpackFile))
.thenApplyAsync( .thenApplyAsync(encoding -> ModpackHelper.readModpackManifest(modpackFile, encoding))
encoding -> ModpackHelper.readModpackManifest(modpackFile, encoding))
.thenApplyAsync(modpack -> ModpackHelper .thenApplyAsync(modpack -> ModpackHelper
.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack, null) .getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack, null)
.executor()) .executor())