From f972c4976244e9820f078181eae6c31183dda7aa Mon Sep 17 00:00:00 2001 From: Glavo Date: Fri, 24 Jan 2025 09:11:22 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20#3539:=20=E5=AE=89=E8=A3=85=20MultiMC=20?= =?UTF-8?q?=E6=95=B4=E5=90=88=E5=8C=85=E5=90=8E=E5=BA=94=E5=BD=93=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=9B=BE=E6=A0=87=20(#3541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jackhuang/hmcl/ui/export/ExportWizardProvider.java | 3 ++- .../hmcl/mod/multimc/MultiMCInstanceConfiguration.java | 10 +++++++++- .../hmcl/mod/multimc/MultiMCModpackInstallTask.java | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ExportWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ExportWizardProvider.java index 12ee29fc52..aa6c04bd69 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ExportWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ExportWizardProvider.java @@ -192,7 +192,8 @@ public void execute() { /* overrideJavaArgs */ true, /* overrideConsole */ true, /* overrideCommands */ true, - /* overrideWindow */ true + /* overrideWindow */ true, + /* iconKey */ null // TODO ), modpackFile); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCInstanceConfiguration.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCInstanceConfiguration.java index 8a24499294..bd61ca231b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCInstanceConfiguration.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCInstanceConfiguration.java @@ -58,6 +58,7 @@ public final class MultiMCInstanceConfiguration implements ModpackManifest { private final boolean overrideConsole; // OverrideConsole private final boolean overrideCommands; // OverrideCommands private final boolean overrideWindow; // OverrideWindow + private final String iconKey; private final MultiMCManifest mmcPack; @@ -94,6 +95,7 @@ public final class MultiMCInstanceConfiguration implements ModpackManifest { wrapperCommand = readValue(p, "WrapperCommand"); name = defaultName; notes = Optional.ofNullable(readValue(p, "notes")).orElse(""); + iconKey = readValue(p, "iconKey"); } /** @@ -112,7 +114,7 @@ private String readValue(Properties p, String key) { return value; } - public MultiMCInstanceConfiguration(String instanceType, String name, String gameVersion, Integer permGen, String wrapperCommand, String preLaunchCommand, String postExitCommand, String notes, String javaPath, String jvmArgs, boolean fullscreen, Integer width, Integer height, Integer maxMemory, Integer minMemory, boolean showConsole, boolean showConsoleOnError, boolean autoCloseConsole, boolean overrideMemory, boolean overrideJavaLocation, boolean overrideJavaArgs, boolean overrideConsole, boolean overrideCommands, boolean overrideWindow) { + public MultiMCInstanceConfiguration(String instanceType, String name, String gameVersion, Integer permGen, String wrapperCommand, String preLaunchCommand, String postExitCommand, String notes, String javaPath, String jvmArgs, boolean fullscreen, Integer width, Integer height, Integer maxMemory, Integer minMemory, boolean showConsole, boolean showConsoleOnError, boolean autoCloseConsole, boolean overrideMemory, boolean overrideJavaLocation, boolean overrideJavaArgs, boolean overrideConsole, boolean overrideCommands, boolean overrideWindow, String iconKey) { this.instanceType = instanceType; this.name = name; this.gameVersion = gameVersion; @@ -138,6 +140,7 @@ public MultiMCInstanceConfiguration(String instanceType, String name, String gam this.overrideCommands = overrideCommands; this.overrideWindow = overrideWindow; this.mmcPack = null; + this.iconKey = iconKey; } public String getInstanceType() { @@ -310,6 +313,10 @@ public boolean isOverrideWindow() { return overrideWindow; } + public String getIconKey() { + return iconKey; + } + public Properties toProperties() { Properties p = new Properties(); if (instanceType != null) p.setProperty("InstanceType", instanceType); @@ -336,6 +343,7 @@ public Properties toProperties() { if (wrapperCommand != null) p.setProperty("WrapperCommand", wrapperCommand); if (name != null) p.setProperty("name", name); if (notes != null) p.setProperty("notes", notes); + if (iconKey != null) p.setProperty("iconKey", iconKey); return p; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackInstallTask.java index 973da7726e..900f3a01a9 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackInstallTask.java @@ -199,6 +199,14 @@ public void execute() throws Exception { Path jarmods = root.resolve("jarmods"); if (Files.exists(jarmods)) FileUtils.copyDirectory(jarmods, repository.getVersionRoot(name).toPath().resolve("jarmods")); + + String iconKey = this.manifest.getIconKey(); + if (iconKey != null) { + Path iconFile = root.resolve(iconKey + ".png"); + if (Files.exists(iconFile)) { + FileUtils.copyFile(iconFile, repository.getVersionRoot(name).toPath().resolve("icon.png")); + } + } } dependencies.add(repository.saveAsync(version));