[Bugfix] 修复下载附加内容时依赖列表因文件缺失加载失败/类别标题不居中的问题 (#6532)

This commit is contained in:
ToobLac authored and GitHub committed 2026-09-04 20:51:10 +08:00
1 parent 00cd20a6e9
commit a4b930ded5
14 files changed
+106 -54

No files matched your search

@@ -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);
@@ -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/[email protected]"));
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<RemoteAddon.DependencyType, Pair<Label, List<DependencyAddonItem>>> dependencies = new EnumMap<>(RemoteAddon.DependencyType.class);
AtomicBoolean hasBroken = new AtomicBoolean(false);
List<Task<?>> 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();
@@ -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)
@@ -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=بيتا
@@ -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
@@ -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=預版
@@ -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=Бета
@@ -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=Наразі немає списку змін
@@ -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 (快照)
@@ -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 (快照)
@@ -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;
@@ -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();
@@ -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<Throwable> 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();
}
@@ -0,0 +1,27 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2026 huangyuhui <[email protected]> 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 <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util.io;
import java.io.IOException;
public class NoCandidatesException extends IOException {
public NoCandidatesException() {
super("No candidates found");
}
}