Skip to content

Commit 86d65e9

Browse files
authored
Fix #4774: 安装 Modrinth 整合包时下载图标 (#5119)
1 parent 1262a76 commit 86d65e9

16 files changed

Lines changed: 82 additions & 41 deletions

HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLModpackProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Modpack readManifest(ZipArchiveReader file, Path path, Charset encoding)
7979

8080
private final static class HMCLModpack extends Modpack {
8181
@Override
82-
public Task<?> getInstallTask(DefaultDependencyManager dependencyManager, Path zipFile, String name) {
82+
public Task<?> getInstallTask(DefaultDependencyManager dependencyManager, Path zipFile, String name, String iconUrl) {
8383
return new HMCLModpackInstallTask(((HMCLGameRepository) dependencyManager.getGameRepository()).getProfile(), zipFile, this, name);
8484
}
8585
}

HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public static Task<?> getInstallManuallyCreatedModpackTask(Profile profile, Path
188188
});
189189
}
190190

191-
public static Task<?> getInstallTask(Profile profile, Path zipFile, String name, Modpack modpack) {
191+
public static Task<?> getInstallTask(Profile profile, Path zipFile, String name, Modpack modpack, String iconUrl) {
192192
profile.getRepository().markVersionAsModpack(name);
193193

194194
ExceptionalRunnable<?> success = () -> {
@@ -208,17 +208,17 @@ public static Task<?> getInstallTask(Profile profile, Path zipFile, String name,
208208
};
209209

210210
if (modpack.getManifest() instanceof MultiMCInstanceConfiguration)
211-
return modpack.getInstallTask(profile.getDependency(), zipFile, name)
211+
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
212212
.whenComplete(Schedulers.defaultScheduler(), success, failure)
213213
.thenComposeAsync(createMultiMCPostInstallTask(profile, (MultiMCInstanceConfiguration) modpack.getManifest(), name))
214214
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
215215
else if (modpack.getManifest() instanceof McbbsModpackManifest)
216-
return modpack.getInstallTask(profile.getDependency(), zipFile, name)
216+
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
217217
.whenComplete(Schedulers.defaultScheduler(), success, failure)
218218
.thenComposeAsync(createMcbbsPostInstallTask(profile, (McbbsModpackManifest) modpack.getManifest(), name))
219219
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
220220
else
221-
return modpack.getInstallTask(profile.getDependency(), zipFile, name)
221+
return modpack.getInstallTask(profile.getDependency(), zipFile, name, iconUrl)
222222
.whenComplete(Schedulers.javafx(), success, failure)
223223
.withStagesHint(List.of("hmcl.modpack", "hmcl.modpack.download"));
224224
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public DownloadPage(String uploadVersion) {
8484
newGameTab.setNodeSupplier(loadVersionFor(() -> new VersionsPage(versionPageNavigator, i18n("install.installer.choose", i18n("install.installer.game")), "", DownloadProviders.getDownloadProvider(),
8585
"game", versionPageNavigator::onGameSelected)));
8686
modpackTab.setNodeSupplier(loadVersionFor(() -> {
87-
DownloadListPage page = HMCLLocalizedDownloadListPage.ofModPack((profile, __, file) -> {
88-
Versions.downloadModpackImpl(profile, uploadVersion, file);
87+
DownloadListPage page = HMCLLocalizedDownloadListPage.ofModPack((profile, __, mod, file) -> {
88+
Versions.downloadModpackImpl(profile, uploadVersion, mod, file);
8989
}, false);
9090

9191
JFXButton installLocalModpackButton = FXUtils.newRaisedButton(i18n("install.modpack"));
@@ -94,9 +94,9 @@ public DownloadPage(String uploadVersion) {
9494
page.getActions().add(installLocalModpackButton);
9595
return page;
9696
}));
97-
modTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofMod((profile, version, file) -> download(profile, version, file, "mods"), true)));
98-
resourcePackTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofResourcePack((profile, version, file) -> download(profile, version, file, "resourcepacks"), true)));
99-
shaderTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofShaderPack((profile, version, file) -> download(profile, version, file, "shaderpacks"), true)));
97+
modTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofMod((profile, version, mod, file) -> download(profile, version, file, "mods"), true)));
98+
resourcePackTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofResourcePack((profile, version, mod, file) -> download(profile, version, file, "resourcepacks"), true)));
99+
shaderTab.setNodeSupplier(loadVersionFor(() -> HMCLLocalizedDownloadListPage.ofShaderPack((profile, version, mod, file) -> download(profile, version, file, "shaderpacks"), true)));
100100
worldTab.setNodeSupplier(loadVersionFor(() -> new DownloadListPage(CurseForgeRemoteModRepository.WORLDS)));
101101
tab = new TabHeader(transitionPane, newGameTab, modpackTab, modTab, resourcePackTab, shaderTab, worldTab);
102102

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/LocalModpackPage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@ protected void onDescribe() {
180180
public static final SettingsMap.Key<Modpack> MODPACK_MANIFEST = new SettingsMap.Key<>("MODPACK_MANIFEST");
181181
public static final SettingsMap.Key<Charset> MODPACK_CHARSET = new SettingsMap.Key<>("MODPACK_CHARSET");
182182
public static final SettingsMap.Key<Boolean> MODPACK_MANUALLY_CREATED = new SettingsMap.Key<>("MODPACK_MANUALLY_CREATED");
183+
public static final SettingsMap.Key<String> MODPACK_ICON_URL = new SettingsMap.Key<>("MODPACK_ICON_URL");
183184
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.jackhuang.hmcl.ui.wizard.WizardController;
3434
import org.jackhuang.hmcl.ui.wizard.WizardProvider;
3535
import org.jackhuang.hmcl.util.SettingsMap;
36+
import org.jackhuang.hmcl.util.StringUtils;
3637

3738
import java.io.FileNotFoundException;
3839
import java.io.IOException;
@@ -45,6 +46,7 @@ public final class ModpackInstallWizardProvider implements WizardProvider {
4546
private final Profile profile;
4647
private final Path file;
4748
private final String updateVersion;
49+
private String iconUrl;
4850

4951
public ModpackInstallWizardProvider(Profile profile) {
5052
this(profile, null, null);
@@ -64,12 +66,18 @@ public ModpackInstallWizardProvider(Profile profile, Path modpackFile, String up
6466
this.updateVersion = updateVersion;
6567
}
6668

69+
public void setIconUrl(String iconUrl) {
70+
this.iconUrl = iconUrl;
71+
}
72+
6773
@Override
6874
public void start(SettingsMap settings) {
6975
if (file != null)
7076
settings.put(LocalModpackPage.MODPACK_FILE, file);
7177
if (updateVersion != null)
7278
settings.put(LocalModpackPage.MODPACK_NAME, updateVersion);
79+
if (StringUtils.isNotBlank(iconUrl))
80+
settings.put(LocalModpackPage.MODPACK_ICON_URL, iconUrl);
7381
settings.put(ModpackPage.PROFILE, profile);
7482
}
7583

@@ -78,6 +86,7 @@ private Task<?> finishModpackInstallingAsync(SettingsMap settings) {
7886
ServerModpackManifest serverModpackManifest = settings.get(RemoteModpackPage.MODPACK_SERVER_MANIFEST);
7987
Modpack modpack = settings.get(LocalModpackPage.MODPACK_MANIFEST);
8088
String name = settings.get(LocalModpackPage.MODPACK_NAME);
89+
String iconUrl = settings.get(LocalModpackPage.MODPACK_ICON_URL);
8190
Charset charset = settings.get(LocalModpackPage.MODPACK_CHARSET);
8291
boolean isManuallyCreated = settings.getOrDefault(LocalModpackPage.MODPACK_MANUALLY_CREATED, false);
8392

@@ -111,7 +120,7 @@ private Task<?> finishModpackInstallingAsync(SettingsMap settings) {
111120
return ModpackHelper.getInstallTask(profile, serverModpackManifest, name, modpack)
112121
.thenRunAsync(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
113122
} else {
114-
return ModpackHelper.getInstallTask(profile, selected, name, modpack)
123+
return ModpackHelper.getInstallTask(profile, selected, name, modpack, iconUrl)
115124
.thenRunAsync(Schedulers.javafx(), () -> profile.setSelectedVersion(name));
116125
}
117126
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private void onRefreshedVersions(HMCLGameRepository repository) {
299299
.thenApplyAsync(
300300
encoding -> ModpackHelper.readModpackManifest(modpackFile, encoding))
301301
.thenApplyAsync(modpack -> ModpackHelper
302-
.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack)
302+
.getInstallTask(repository.getProfile(), modpackFile, modpack.getName(), modpack, null)
303303
.executor())
304304
.thenAcceptAsync(Schedulers.javafx(), executor -> {
305305
Controllers.taskDialog(executor, i18n("modpack.installing"), TaskCancellationAction.NO_CANCEL);

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public void setFailed(boolean failed) {
157157
this.failed.set(failed);
158158
}
159159

160-
public void download(RemoteMod.Version file) {
160+
public void download(RemoteMod mod, RemoteMod.Version file) {
161161
if (this.callback == null) {
162-
saveAs(file);
162+
saveAs(mod, file);
163163
} else {
164-
this.callback.download(version.getProfile(), version.getVersion(), file);
164+
this.callback.download(version.getProfile(), version.getVersion(), mod, file);
165165
}
166166
}
167167

168-
public void saveAs(RemoteMod.Version file) {
168+
public void saveAs(RemoteMod mod, RemoteMod.Version file) {
169169
String extension = StringUtils.substringAfterLast(file.getFile().getFilename(), '.');
170170

171171
FileChooser fileChooser = new FileChooser();
@@ -287,7 +287,7 @@ protected ModDownloadPageSkin(DownloadPage control) {
287287
if (targetLoaders.contains(loader)) {
288288
list.getContent().addAll(
289289
ComponentList.createComponentListTitle(i18n("mods.download.recommend", gameVersion)),
290-
new ModItem(modVersion, control)
290+
new ModItem(control.addon, modVersion, control)
291291
);
292292
break resolve;
293293
}
@@ -308,7 +308,7 @@ protected ModDownloadPageSkin(DownloadPage control) {
308308
ComponentList sublist = new ComponentList(() -> {
309309
ArrayList<ModItem> items = new ArrayList<>(versions.size());
310310
for (RemoteMod.Version v : versions) {
311-
items.add(new ModItem(v, control));
311+
items.add(new ModItem(control.addon, v, control));
312312
}
313313
return items;
314314
});
@@ -373,7 +373,7 @@ private static final class DependencyModItem extends StackPane {
373373

374374
private static final class ModItem extends StackPane {
375375

376-
ModItem(RemoteMod.Version dataItem, DownloadPage selfPage) {
376+
ModItem(RemoteMod mod, RemoteMod.Version dataItem, DownloadPage selfPage) {
377377
VBox pane = new VBox(8);
378378
pane.setPadding(new Insets(8, 0, 8, 0));
379379

@@ -435,7 +435,7 @@ private static final class ModItem extends StackPane {
435435
}
436436

437437
RipplerContainer container = new RipplerContainer(pane);
438-
FXUtils.onClicked(container, () -> Controllers.dialog(new ModVersion(dataItem, selfPage)));
438+
FXUtils.onClicked(container, () -> Controllers.dialog(new ModVersion(mod, dataItem, selfPage)));
439439
getChildren().setAll(container);
440440

441441
// Workaround for https://github.com/HMCL-dev/HMCL/issues/2129
@@ -444,7 +444,7 @@ private static final class ModItem extends StackPane {
444444
}
445445

446446
private static final class ModVersion extends JFXDialogLayout {
447-
public ModVersion(RemoteMod.Version version, DownloadPage selfPage) {
447+
public ModVersion(RemoteMod mod, RemoteMod.Version version, DownloadPage selfPage) {
448448
RemoteModRepository.Type type = selfPage.repository.getType();
449449

450450
String title = switch (type) {
@@ -458,7 +458,7 @@ public ModVersion(RemoteMod.Version version, DownloadPage selfPage) {
458458

459459
VBox box = new VBox(8);
460460
box.setPadding(new Insets(8));
461-
ModItem modItem = new ModItem(version, selfPage);
461+
ModItem modItem = new ModItem(mod, version, selfPage);
462462
modItem.setMouseTransparent(true); // Item is displayed for info, clicking shouldn't open the dialog again
463463
box.getChildren().setAll(modItem);
464464
SpinnerPane spinnerPane = new SpinnerPane();
@@ -484,7 +484,7 @@ public ModVersion(RemoteMod.Version version, DownloadPage selfPage) {
484484
if (type == RemoteModRepository.Type.MODPACK || !spinnerPane.isLoading() && spinnerPane.getFailedReason() == null) {
485485
fireEvent(new DialogCloseEvent());
486486
}
487-
selfPage.download(version);
487+
selfPage.download(mod, version);
488488
});
489489
}
490490

@@ -494,7 +494,7 @@ public ModVersion(RemoteMod.Version version, DownloadPage selfPage) {
494494
if (!spinnerPane.isLoading() && spinnerPane.getFailedReason() == null) {
495495
fireEvent(new DialogCloseEvent());
496496
}
497-
selfPage.saveAs(version);
497+
selfPage.saveAs(mod, version);
498498
});
499499

500500
JFXButton cancelButton = new JFXButton(i18n("button.cancel"));
@@ -548,6 +548,6 @@ private void loadDependencies(RemoteMod.Version version, DownloadPage selfPage,
548548
}
549549

550550
public interface DownloadCallback {
551-
void download(Profile profile, @Nullable String version, RemoteMod.Version file);
551+
void download(Profile profile, @Nullable String version, RemoteMod mod, RemoteMod.Version file);
552552
}
553553
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ final class ModInfoDialog extends JFXDialogLayout {
493493
repository instanceof CurseForgeRemoteModRepository ? HMCLLocalizedDownloadListPage.ofCurseForgeMod(null, false) : HMCLLocalizedDownloadListPage.ofModrinthMod(null, false),
494494
remoteMod,
495495
new Profile.ProfileVersion(ModListPageSkin.this.getSkinnable().getProfile(), ModListPageSkin.this.getSkinnable().getInstanceId()),
496-
(profile, version, file) -> org.jackhuang.hmcl.ui.download.DownloadPage.download(profile, version, file, "mods")
496+
(profile, version, mod, file) -> org.jackhuang.hmcl.ui.download.DownloadPage.download(profile, version, file, "mods")
497497
));
498498
});
499499
button.setDisable(false);

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static void importModpack() {
7272
}
7373
}
7474

75-
public static void downloadModpackImpl(Profile profile, String version, RemoteMod.Version file) {
75+
public static void downloadModpackImpl(Profile profile, String version, RemoteMod mod, RemoteMod.Version file) {
7676
Path modpack;
7777
URI downloadURL;
7878
try {
@@ -88,11 +88,14 @@ public static void downloadModpackImpl(Profile profile, String version, RemoteMo
8888
new FileDownloadTask(downloadURL, modpack)
8989
.whenComplete(Schedulers.javafx(), e -> {
9090
if (e == null) {
91-
if (version != null) {
92-
Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(profile, modpack, version));
93-
} else {
94-
Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(profile, modpack));
95-
}
91+
ModpackInstallWizardProvider installWizardProvider;
92+
if (version != null)
93+
installWizardProvider = new ModpackInstallWizardProvider(profile, modpack, version);
94+
else
95+
installWizardProvider = new ModpackInstallWizardProvider(profile, modpack);
96+
if (StringUtils.isNotBlank(mod.getIconUrl()))
97+
installWizardProvider.setIconUrl(mod.getIconUrl());
98+
Controllers.getDecorator().startWizard(installWizardProvider);
9699
} else if (e instanceof CancellationException) {
97100
Controllers.showToast(i18n("message.cancelled"));
98101
} else {

HMCLCore/src/main/java/org/jackhuang/hmcl/mod/Modpack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public Modpack setManifest(ModpackManifest manifest) {
114114
return this;
115115
}
116116

117-
public abstract Task<?> getInstallTask(DefaultDependencyManager dependencyManager, Path zipFile, String name);
117+
public abstract Task<?> getInstallTask(DefaultDependencyManager dependencyManager, Path zipFile, String name, String iconUrl);
118118

119119
public static boolean acceptFile(String path, List<String> blackList, List<String> whiteList) {
120120
if (path.isEmpty())

0 commit comments

Comments
 (0)