diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteAddonRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteAddonRepository.java index dc54158d23..2155a6ae1b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteAddonRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteAddonRepository.java @@ -138,6 +138,11 @@ public abstract class LocalizedRemoteAddonRepository implements RemoteAddonRepos return getBackedRemoteModRepository().getAddonById(downloadProvider, id); } + @Override + public RemoteAddon resolveDependency(DownloadProvider downloadProvider, String id) throws IOException { + return getBackedRemoteModRepository().resolveDependency(downloadProvider, id); + } + @Override public RemoteAddon.File getAddonFile(String projectId, String fileId) throws IOException { return getBackedRemoteModRepository().getAddonFile(projectId, fileId); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/DownloadPage.java index 8f32d07cc4..27af95016f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/instances/DownloadPage.java @@ -50,6 +50,7 @@ import org.jetbrains.annotations.Nullable; import java.nio.file.Path; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; import static org.jackhuang.hmcl.ui.FXUtils.onEscPressed; @@ -397,21 +398,15 @@ public class DownloadPage extends Control implements DecoratorPage { }); setNode(IDX_LEADING, pane); - if (addon != RemoteAddon.BROKEN) { - ModTranslations.Mod mod = ModTranslations.getTranslationsByAddonType(type).getModByCurseForgeId(addon.slug()); - content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : addon.title()); - content.setSubtitle(addon.description()); - for (String category : addon.categories()) { - if (page.shouldDisplayCategory(category)) - content.addTag(page.getLocalizedCategory(category, null)); - } - if (StringUtils.isNotBlank(addon.iconUrl())) { - imageView.imageProperty().bind(FXUtils.newRemoteImage(addon.iconUrl(), 80, 80, true, true)); - } - } else { - content.setTitle(i18n("addon.broken_dependency.title")); - content.setSubtitle(i18n("addon.broken_dependency.desc")); - imageView.setImage(FXUtils.newBuiltinImage("/assets/img/icon@4x.png")); + ModTranslations.Mod mod = ModTranslations.getTranslationsByAddonType(type).getModByCurseForgeId(addon.slug()); + content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : addon.title()); + content.setSubtitle(addon.description()); + for (String category : addon.categories()) { + if (page.shouldDisplayCategory(category)) + content.addTag(page.getLocalizedCategory(category, null)); + } + if (StringUtils.isNotBlank(addon.iconUrl())) { + imageView.imageProperty().bind(FXUtils.newRemoteImage(addon.iconUrl(), 80, 80, true, true)); } } } @@ -545,6 +540,7 @@ public class DownloadPage extends Control implements DecoratorPage { scrollPane.setContent(dependenciesList); scrollPane.setFitToWidth(true); scrollPane.setFitToHeight(true); + FXUtils.onChangeAndOperate(scrollPane.widthProperty(), d -> FXUtils.setLimitWidth(dependenciesList, d.doubleValue())); FXUtils.smoothScrolling(scrollPane); FXUtils.setOverflowHidden(scrollPane, 8); spinnerPane.setContent(scrollPane); @@ -595,9 +591,12 @@ public class DownloadPage extends Control implements DecoratorPage { Task.composeAsync(() -> { // TODO: Massive tasks may cause OOM. EnumMap>> dependencies = new EnumMap<>(RemoteAddon.DependencyType.class); + AtomicBoolean hasBroken = new AtomicBoolean(false); List> queue = new ArrayList<>(version.dependencies().size()); for (RemoteAddon.Dependency dependency : version.dependencies()) { - if (dependency.getType() == RemoteAddon.DependencyType.INCOMPATIBLE || dependency.getType() == RemoteAddon.DependencyType.BROKEN) { + if (dependency.getType() == RemoteAddon.DependencyType.INCOMPATIBLE) continue; + if (dependency.getType() == RemoteAddon.DependencyType.BROKEN) { + hasBroken.set(true); continue; } @@ -612,24 +611,39 @@ public class DownloadPage extends Control implements DecoratorPage { .setSignificance(Task.TaskSignificance.MINOR) .thenAcceptAsync(Schedulers.javafx(), dep -> { if (dep == RemoteAddon.BROKEN) { + hasBroken.set(true); return; } DependencyAddonItem dependencyAddonItem = new DependencyAddonItem(selfPage.page, dep, selfPage.instanceReference); + var listener = FXUtils.onWeakChangeAndOperate(dependenciesList.widthProperty(), d -> FXUtils.setLimitWidth(dependencyAddonItem, d.doubleValue())); + dependencyAddonItem.getProperties().put("DependencyAddonItem.width", listener); dependencies.get(dependency.getType()).value().add(dependencyAddonItem); }) .setSignificance(Task.TaskSignificance.MINOR)); } - return Task.allOf(queue).thenSupplyAsync(() -> - dependencies.values().stream().flatMap(types -> - Stream.concat( - Stream.of(types.key()), - types.value().stream().sorted(Comparator.comparing(item -> item.addon.slug(), String.CASE_INSENSITIVE_ORDER))) - ).toList() - ); + return Task.allOf(queue).thenSupplyAsync(() -> { + var dependenciesStream = dependencies.values().stream().flatMap(types -> { + if (types.value().isEmpty()) return Stream.of(); + return Stream.concat( + Stream.of(types.key()), + types.value().stream().sorted(Comparator.comparing(item -> item.addon.slug(), String.CASE_INSENSITIVE_ORDER))); + }); + if (!hasBroken.get()) { + return dependenciesStream; + } else { + Label warning = new Label(i18n("addon.dependencies.has_broken")); + warning.setWrapText(true); + warning.setPadding(new Insets(0, 8, 0, 8)); + return Stream.concat( + Stream.of(warning), + dependenciesStream + ); + } + }); }).whenComplete(Schedulers.javafx(), (result, exception) -> { if (exception == null) { - dependenciesList.getContent().setAll(result); + dependenciesList.getContent().setAll(result.toList()); spinnerPane.setFailedReason(null); } else { dependenciesList.getContent().setAll(); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 96f06124ec..672b254bb3 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -161,8 +161,6 @@ account.skin.upload.failed=Failed to upload skin. account.skin.invalid_skin=Invalid skin file. account.username=Username -addon.broken_dependency.title=Broken dependency -addon.broken_dependency.desc=This dependency existed before, but it does not exist anymore. Try using another download source. addon.category=Category addon.changelog=Changelog addon.changelog.empty=Currently no changelog @@ -187,6 +185,7 @@ addon.dependency.tool=Required Dependencies (Must be downloaded separately. Miss addon.dependency.include=Built-in Dependencies (Already packaged in the addon file by the author. No need to download separately) addon.dependency.incompatible=Incompatible Addons (Installing these addons at the same time will prevent the game from launching) addon.dependency.broken=Broken Dependencies (This addon existed before, but it does not exist anymore. Try using another download source.) +addon.dependencies.has_broken=This version has broken dependencies. Please try another download source, or installation could be unsuccessful. addon.download.recommend=Recommended Version for Minecraft %1s addon.download.title.release=Minecraft %s addon.download.title.snapshot=Minecraft %s (Snapshots) diff --git a/HMCL/src/main/resources/assets/lang/I18N_ar.properties b/HMCL/src/main/resources/assets/lang/I18N_ar.properties index 95e20c2468..3b1e9c7f9a 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ar.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ar.properties @@ -156,8 +156,6 @@ account.skin.upload.failed=فشل رفع المظهر. account.skin.invalid_skin=ملف المظهر غير صالح. account.username=اسم المستخدم -addon.broken_dependency.title=تبعية معطوبة -addon.broken_dependency.desc=كانت هذه التبعية موجودة مسبقاً، لكنها لم تعد كذلك. جرّب استخدام مصدر تنزيل آخر. addon.category=الفئة addon.channel.alpha=ألفا addon.channel.beta=بيتا diff --git a/HMCL/src/main/resources/assets/lang/I18N_es.properties b/HMCL/src/main/resources/assets/lang/I18N_es.properties index ec11203a3d..4d1c14ae69 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_es.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_es.properties @@ -136,8 +136,6 @@ account.skin.upload.failed=No se pudo subir el aspecto. account.skin.invalid_skin=Archivo de aspecto inválido. account.username=Nombre de usuario -addon.broken_dependency.title=Dependencia rota -addon.broken_dependency.desc=Esta dependencia existía antes, pero ahora no existe. Intente utilizar otra fuente de descarga. addon.category=Categoría addon.channel.alpha=Alpha addon.channel.beta=Beta diff --git a/HMCL/src/main/resources/assets/lang/I18N_lzh.properties b/HMCL/src/main/resources/assets/lang/I18N_lzh.properties index b03771e524..2f517b5898 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_lzh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_lzh.properties @@ -138,8 +138,6 @@ account.skin.upload.failed=匯之外觀而未成 account.skin.invalid_skin=外觀之案有謬 account.username=戶名 -addon.broken_dependency.title=所依之壞者 -addon.broken_dependency.desc=夫改囊素存於改囊庫,今闕矣,宜易他源。 addon.category=類 addon.changelog=迭更誌 addon.channel.alpha=預版 diff --git a/HMCL/src/main/resources/assets/lang/I18N_ru.properties b/HMCL/src/main/resources/assets/lang/I18N_ru.properties index d2c83825f6..49735dfe6d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ru.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ru.properties @@ -135,8 +135,6 @@ account.skin.upload.failed=Не удалось загрузить скин. account.skin.invalid_skin=Недопустимый файл скина. account.username=Имя пользователя -addon.broken_dependency.title=Сломанная зависимость -addon.broken_dependency.desc=Эта зависимость существовала раньше, но теперь ее нет. Попробуйте использовать другой источник скачивания. addon.category=Категория addon.channel.alpha=Альфа addon.channel.beta=Бета diff --git a/HMCL/src/main/resources/assets/lang/I18N_uk.properties b/HMCL/src/main/resources/assets/lang/I18N_uk.properties index 3eec4b737c..25044542c8 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_uk.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_uk.properties @@ -167,8 +167,6 @@ account.skin.upload.failed=Не вдалося завантажити скін. account.skin.invalid_skin=Недійсний файл скіна. account.username=Ім'я користувача -addon.broken_dependency.title=Зламана залежність -addon.broken_dependency.desc=Ця залежність існувала раніше, але тепер її немає. Спробуйте використовувати інше джерело завантаження. addon.category=Категорія addon.changelog=Список змін addon.changelog.empty=Наразі немає списку змін diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index caff311186..48e4524a3d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -159,8 +159,6 @@ account.skin.upload.failed=外觀上傳失敗 account.skin.invalid_skin=無法識別的外觀檔案 account.username=使用者名稱 -addon.broken_dependency.title=損壞的相依內容 -addon.broken_dependency.desc=該相依內容曾經存在於附加內容下載源中,但現在已被刪除,請嘗試其他下載源。 addon.category=類別 addon.changelog=更新日誌 addon.changelog.empty=暫無更新日誌 @@ -185,6 +183,7 @@ addon.dependency.tool=相依庫 (必須單獨下載,缺少可能會導致遊 addon.dependency.include=內建相依內容 (作者已經打包在檔案中,無需單獨下載) addon.dependency.incompatible=不相容附加內容 (與正在下載的檔案同時安裝會導致遊戲無法啟動) addon.dependency.broken=損壞的相依內容 (該相依內容曾經存在於附加內容下載源中,但現在已被刪除,請嘗試其他下載源) +addon.dependencies.has_broken=此版本存在損壞的前置內容。請嘗試切換下載源,否則安裝可能失敗。 addon.download.recommend=推薦版本 - Minecraft %1s addon.download.title.release=Minecraft %s addon.download.title.snapshot=Minecraft %s (快照) 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 ed8b84ace4..cc1c47a2dc 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -161,8 +161,6 @@ account.skin.upload.failed=皮肤上传失败 account.skin.invalid_skin=无法识别的皮肤文件 account.username=用户名 -addon.broken_dependency.title=损坏的前置内容 -addon.broken_dependency.desc=该前置内容曾经在该附加内容下载源上存在过,但现在被删除了。换个下载源试试吧。 addon.category=类别 addon.changelog=更新日志 addon.changelog.empty=暂无更新日志 @@ -187,6 +185,7 @@ addon.dependency.tool=前置库 (必须另外下载,缺失可能会导致游 addon.dependency.include=内置的前置内容 (已经由作者打包在文件中,无需另外下载) addon.dependency.incompatible=不兼容的附加内容 (同时与正在下载的文件安装会导致游戏无法启动) addon.dependency.broken=损坏的前置内容 (该前置内容曾经在该附加内容下载源上存在过,但现在被删除了,换个下载源试试吧) +addon.dependencies.has_broken=此版本存在损坏的前置内容。请尝试切换下载源,否则安装可能失败。 addon.download.recommend=推荐版本 - Minecraft %1s addon.download.title.release=Minecraft %s addon.download.title.snapshot=Minecraft %s (快照) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/RemoteAddonRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/RemoteAddonRepository.java index 9c850c4b9f..500f230c17 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/RemoteAddonRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/RemoteAddonRepository.java @@ -88,9 +88,9 @@ public interface RemoteAddonRepository { RemoteAddon getAddonById(DownloadProvider downloadProvider, String id) throws IOException; - default RemoteAddon resolveDependency(DownloadProvider downloadProvider, String id) throws IOException { - return getAddonById(downloadProvider, id); - } + /// @return the dependency resolved, or {@link RemoteAddon#BROKEN} when the dependency is not found + /// @throws IOException if an I/O error occurs, except for when the desired dependency is not found + RemoteAddon resolveDependency(DownloadProvider downloadProvider, String id) throws IOException; RemoteAddon.File getAddonFile(String projectId, String fileId) throws IOException; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/CurseForgeRemoteAddonRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/CurseForgeRemoteAddonRepository.java index 632c79d3a9..7daed17112 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/CurseForgeRemoteAddonRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/CurseForgeRemoteAddonRepository.java @@ -26,13 +26,12 @@ import org.jackhuang.hmcl.util.Immutable; import org.jackhuang.hmcl.util.MurmurHash2; import org.jackhuang.hmcl.util.Pair; import org.jackhuang.hmcl.util.StringUtils; -import org.jackhuang.hmcl.util.io.HttpRequest; -import org.jackhuang.hmcl.util.io.JarUtils; -import org.jackhuang.hmcl.util.io.NetworkUtils; +import org.jackhuang.hmcl.util.io.*; import org.jackhuang.hmcl.util.versioning.GameVersionNumber; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; @@ -178,7 +177,7 @@ public final class CurseForgeRemoteAddonRepository implements RemoteAddonReposit } if (response == null) { - throw exception != null ? exception : new IOException("No candidates found"); + throw exception != null ? exception : new NoCandidatesException(); } // https://github.com/HMCL-dev/HMCL/issues/1549 @@ -298,6 +297,19 @@ public final class CurseForgeRemoteAddonRepository implements RemoteAddonReposit } } + @Override + public RemoteAddon resolveDependency(DownloadProvider downloadProvider, String id) throws IOException { + try { + return getAddonById(downloadProvider, id); + } catch (IOException e) { + if (e instanceof NoCandidatesException) throw e; + if (e instanceof FileNotFoundException + || e instanceof ResponseCodeException rce && rce.getResponseCode() == 404) + return RemoteAddon.BROKEN; + throw e; + } + } + @Override public RemoteAddon.File getAddonFile(String projectId, String fileId) throws IOException { SEMAPHORE.acquireUninterruptibly(); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/ModrinthRemoteAddonRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/ModrinthRemoteAddonRepository.java index 628783e2ce..2187a4ca0b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/ModrinthRemoteAddonRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/repository/ModrinthRemoteAddonRepository.java @@ -31,6 +31,7 @@ import org.jackhuang.hmcl.util.gson.JsonSerializable; import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.io.HttpRequest; import org.jackhuang.hmcl.util.io.NetworkUtils; +import org.jackhuang.hmcl.util.io.NoCandidatesException; import org.jackhuang.hmcl.util.io.ResponseCodeException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -204,7 +205,7 @@ public final class ModrinthRemoteAddonRepository implements RemoteAddonRepositor } } - throw exception != null ? exception : new IOException("No candidates found"); + throw exception != null ? exception : new NoCandidatesException(); } finally { SEMAPHORE.release(); } @@ -258,7 +259,7 @@ public final class ModrinthRemoteAddonRepository implements RemoteAddonRepositor } } - throw exception != null ? exception : new IOException("No candidates found"); + throw exception != null ? exception : new NoCandidatesException(); } finally { SEMAPHORE.release(); } @@ -268,13 +269,19 @@ public final class ModrinthRemoteAddonRepository implements RemoteAddonRepositor public RemoteAddon resolveDependency(DownloadProvider downloadProvider, String id) throws IOException { try { return getAddonById(downloadProvider, id); - } catch (ResponseCodeException e) { - if (e.getResponseCode() == 502 || e.getResponseCode() == 404) { + } catch (IOException e) { + if (e instanceof NoCandidatesException) throw e; + List l = new ArrayList<>(List.of(e)); + l.addAll(List.of(e.getSuppressed())); + if (l.stream().allMatch(t -> { + var cause = t.getCause(); + return cause == null + || cause instanceof FileNotFoundException + || cause instanceof ResponseCodeException rce && rce.getResponseCode() == 404; + })) { // Which means the file does not exist return RemoteAddon.BROKEN; } throw e; - } catch (FileNotFoundException e) { - return RemoteAddon.BROKEN; } } @@ -310,7 +317,7 @@ public final class ModrinthRemoteAddonRepository implements RemoteAddonRepositor } } - throw exception != null ? exception : new IOException("No candidates found"); + throw exception != null ? exception : new NoCandidatesException(); } finally { SEMAPHORE.release(); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NoCandidatesException.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NoCandidatesException.java new file mode 100644 index 0000000000..ed59bce50f --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NoCandidatesException.java @@ -0,0 +1,27 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2026 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.util.io; + +import java.io.IOException; + +public class NoCandidatesException extends IOException { + + public NoCandidatesException() { + super("No candidates found"); + } +}