From b5025a018dc48d2617b00ce0b8a597a82a5a82e6 Mon Sep 17 00:00:00 2001 From: CiiLu <109708109+CiiLu@users.noreply.github.com> Date: Fri, 1 May 2026 16:17:39 +0800 Subject: [PATCH 1/2] update --- .../game/LocalizedRemoteModRepository.java | 4 +- .../hmcl/ui/download/DownloadPage.java | 6 +- .../hmcl/ui/versions/DownloadListPage.java | 10 +- .../hmcl/ui/versions/DownloadPage.java | 60 +++--- .../hmcl/ui/versions/ModCheckUpdatesTask.java | 2 +- .../hmcl/ui/versions/ModListPageSkin.java | 4 +- .../hmcl/ui/versions/ModUpdatesPage.java | 12 +- .../jackhuang/hmcl/ui/versions/Versions.java | 10 +- .../download/fabric/FabricAPIInstallTask.java | 6 +- .../download/fabric/FabricAPIVersionList.java | 6 +- .../LegacyFabricAPIInstallTask.java | 6 +- .../LegacyFabricAPIVersionList.java | 6 +- .../download/quilt/QuiltAPIInstallTask.java | 6 +- .../download/quilt/QuiltAPIVersionList.java | 6 +- .../org/jackhuang/hmcl/mod/LocalModFile.java | 16 +- .../org/jackhuang/hmcl/mod/RemoteMod.java | 179 ++---------------- .../hmcl/mod/curse/CurseCompletionTask.java | 4 +- .../curse/CurseForgeRemoteModRepository.java | 4 +- .../modrinth/ModrinthModpackExportTask.java | 26 ++- .../modrinth/ModrinthRemoteModRepository.java | 13 +- 20 files changed, 115 insertions(+), 271 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteModRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteModRepository.java index 29b8fb5a13..bc25861a12 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteModRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LocalizedRemoteModRepository.java @@ -74,7 +74,7 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion } RemoteMod remoteMod = iterator.next(); - ModTranslations.Mod chineseTranslation = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteMod.getSlug()); + ModTranslations.Mod chineseTranslation = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteMod.slug()); if (chineseTranslation != null && !StringUtils.isBlank(chineseTranslation.getName()) && StringUtils.containsChinese(chineseTranslation.getName())) { searchResultArray[chineseIndex++] = remoteMod; } else { @@ -86,7 +86,7 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion StringUtils.LevCalculator levCalculator = new StringUtils.LevCalculator(); return new SearchResult(Stream.concat(Arrays.stream(searchResultArray, 0, chineseIndex).map(remoteMod -> { - ModTranslations.Mod chineseRemoteMod = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteMod.getSlug()); + ModTranslations.Mod chineseRemoteMod = ModTranslations.getTranslationsByRepositoryType(getType()).getModByCurseForgeId(remoteMod.slug()); if (chineseRemoteMod == null || StringUtils.isBlank(chineseRemoteMod.getName()) || !StringUtils.containsChinese(chineseRemoteMod.getName())) { return Pair.pair(remoteMod, Integer.MAX_VALUE); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java index 23b0c2880c..d2b307f495 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java @@ -156,8 +156,8 @@ public static void download(DownloadProvider downloadProvider, Profile profile, Path dest = runDirectory.resolve(subdirectoryName).resolve(result); Controllers.taskDialog(Task.composeAsync(() -> { - var task = new FileDownloadTask(downloadProvider.injectURLWithCandidates(file.getFile().getUrl()), dest); - task.setName(file.getName()); + var task = new FileDownloadTask(downloadProvider.injectURLWithCandidates(file.file().url()), dest); + task.setName(file.name()); return task; }).whenComplete(Schedulers.javafx(), exception -> { if (exception != null) { @@ -171,7 +171,7 @@ public static void download(DownloadProvider downloadProvider, Profile profile, } }), i18n("message.downloading"), TaskCancellationAction.NORMAL); handler.resolve(); - }, file.getFile().getFilename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValidForJar), new Validator(i18n("profile.already_exists"), (it) -> !finalExistingFiles.contains(it))); + }, file.file().filename(), new Validator(i18n("install.new_game.malformed"), FileUtils::isNameValidForJar), new Validator(i18n("profile.already_exists"), (it) -> !finalExistingFiles.contains(it))); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java index 5601cf167a..8c5bb9211d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java @@ -575,19 +575,19 @@ protected void updateItem(RemoteMod item, boolean empty) { if (empty || item == null) { setGraphic(null); } else { - ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(getSkinnable().repository.getType()).getModByCurseForgeId(item.getSlug()); - content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : item.getTitle()); - String description = item.getDescription(); + ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(getSkinnable().repository.getType()).getModByCurseForgeId(item.slug()); + content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : item.title()); + String description = item.description(); if (description != null) { description = description.replaceAll("\\R", " "); } content.setSubtitle(description); content.getTags().clear(); - for (String category : item.getCategories()) { + for (String category : item.categories()) { if (getSkinnable().shouldDisplayCategory(category)) content.addTag(getSkinnable().getLocalizedCategory(category)); } - iconLoader.load(imageContainer.imageProperty(), item.getIconUrl()); + iconLoader.load(imageContainer.imageProperty(), item.iconUrl()); setGraphic(wrapper); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java index 462cc870c9..ad015f98e1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java @@ -81,12 +81,12 @@ public DownloadPage(DownloadListPage page, RemoteMod addon, Profile.ProfileVersi this.repository = page.repository; this.addon = addon; this.translations = ModTranslations.getTranslationsByRepositoryType(repository.getType()); - this.mod = translations.getModByCurseForgeId(addon.getSlug()); + this.mod = translations.getModByCurseForgeId(addon.slug()); this.version = version; this.callback = callback; loadModVersions(); - this.state.set(State.fromTitle(addon.getTitle())); + this.state.set(State.fromTitle(addon.title())); } private void loadModVersions() { @@ -94,7 +94,7 @@ private void loadModVersions() { setFailed(false); Task.supplyAsync(() -> { - Stream versions = addon.getData().loadVersions(repository, page.getDownloadProvider()); + Stream versions = addon.data().loadVersions(repository, page.getDownloadProvider()); return sortVersions(versions); }).whenComplete(Schedulers.javafx(), (result, exception) -> { if (exception == null) { @@ -113,14 +113,14 @@ private SimpleMultimap> sortV SimpleMultimap> classifiedVersions = new SimpleMultimap<>(HashMap::new, ArrayList::new); versions.forEach(version -> { - for (String gameVersion : version.getGameVersions()) { + for (String gameVersion : version.gameVersions()) { classifiedVersions.put(gameVersion, version); } }); for (String gameVersion : classifiedVersions.keys()) { List versionList = classifiedVersions.get(gameVersion); - versionList.sort(Comparator.comparing(RemoteMod.Version::getDatePublished).reversed()); + versionList.sort(Comparator.comparing(RemoteMod.Version::datePublished).reversed()); } return classifiedVersions; } @@ -166,12 +166,12 @@ public void download(RemoteMod mod, RemoteMod.Version file) { } public void saveAs(RemoteMod mod, RemoteMod.Version file) { - String extension = StringUtils.substringAfterLast(file.getFile().getFilename(), '.'); + String extension = StringUtils.substringAfterLast(file.file().filename(), '.'); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(i18n("button.save_as")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(i18n("file"), "*." + extension)); - fileChooser.setInitialFileName(file.getFile().getFilename()); + fileChooser.setInitialFileName(file.file().filename()); Path dest = FileUtils.toPath(fileChooser.showSaveDialog(Controllers.getStage())); if (dest == null) { return; @@ -179,8 +179,8 @@ public void saveAs(RemoteMod mod, RemoteMod.Version file) { Controllers.taskDialog( Task.composeAsync(() -> { - var task = new FileDownloadTask(file.getFile().getUrl(), dest, file.getFile().getIntegrityCheck()); - task.setName(file.getName()); + var task = new FileDownloadTask(file.file().url(), dest, file.file().getIntegrityCheck()); + task.setName(file.name()); return task; }), i18n("message.downloading"), @@ -213,18 +213,18 @@ protected ModDownloadPageSkin(DownloadPage control) { descriptionPane.getStyleClass().add("card-non-transparent"); { var imageContainer = new ImageContainer(40); - if (StringUtils.isNotBlank(getSkinnable().addon.getIconUrl())) { - imageContainer.imageProperty().bind(FXUtils.newRemoteImage(getSkinnable().addon.getIconUrl(), 80, 80, true, true)); + if (StringUtils.isNotBlank(getSkinnable().addon.iconUrl())) { + imageContainer.imageProperty().bind(FXUtils.newRemoteImage(getSkinnable().addon.iconUrl(), 80, 80, true, true)); } descriptionPane.getChildren().add(imageContainer); TwoLineListItem content = new TwoLineListItem(); HBox.setHgrow(content, Priority.ALWAYS); - ModTranslations.Mod mod = getSkinnable().translations.getModByCurseForgeId(getSkinnable().addon.getSlug()); - content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : getSkinnable().addon.getTitle()); - content.setSubtitle(getSkinnable().addon.getDescription()); + ModTranslations.Mod mod = getSkinnable().translations.getModByCurseForgeId(getSkinnable().addon.slug()); + content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : getSkinnable().addon.title()); + content.setSubtitle(getSkinnable().addon.description()); content.getSubtitleLabel().setWrapText(true); - getSkinnable().addon.getCategories().stream() + getSkinnable().addon.categories().stream() .filter(category -> getSkinnable().page.shouldDisplayCategory(category)) .map(category -> getSkinnable().page.getLocalizedCategory(category)) .forEach(content::addTag); @@ -239,7 +239,7 @@ protected ModDownloadPageSkin(DownloadPage control) { } JFXHyperlink openUrlButton = new JFXHyperlink(control.page.getLocalizedOfficialPage()); - openUrlButton.setExternalLink(getSkinnable().addon.getPageUrl()); + openUrlButton.setExternalLink(getSkinnable().addon.pageUrl()); descriptionPane.getChildren().add(openUrlButton); openUrlButton.setMinWidth(Region.USE_PREF_SIZE); } @@ -282,7 +282,7 @@ protected ModDownloadPageSkin(DownloadPage control) { resolve: for (RemoteMod.Version modVersion : modVersions) { - for (ModLoaderType loader : modVersion.getLoaders()) { + for (ModLoaderType loader : modVersion.loaders()) { if (targetLoaders.contains(loader)) { list.getContent().addAll( ComponentList.createComponentListTitle(i18n("mods.download.recommend", gameVersion)), @@ -381,15 +381,15 @@ private static final class DependencyModItem extends LineButton { setNode(IDX_LEADING, pane); if (addon != RemoteMod.BROKEN) { - ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(page.repository.getType()).getModByCurseForgeId(addon.getSlug()); - content.setTitle(mod != null && I18n.isUseChinese() ? mod.getDisplayName() : addon.getTitle()); - content.setSubtitle(addon.getDescription()); - for (String category : addon.getCategories()) { + ModTranslations.Mod mod = ModTranslations.getTranslationsByRepositoryType(page.repository.getType()).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)); } - if (StringUtils.isNotBlank(addon.getIconUrl())) { - imageView.imageProperty().bind(FXUtils.newRemoteImage(addon.getIconUrl(), 80, 80, true, true)); + if (StringUtils.isNotBlank(addon.iconUrl())) { + imageView.imageProperty().bind(FXUtils.newRemoteImage(addon.iconUrl(), 80, 80, true, true)); } } else { content.setTitle(i18n("mods.broken_dependency.title")); @@ -415,10 +415,10 @@ private static final class ModItem extends StackPane { StackPane graphicPane = new StackPane(); TwoLineListItem content = new TwoLineListItem(); HBox.setHgrow(content, Priority.ALWAYS); - content.setTitle(dataItem.getName()); - content.setSubtitle(I18n.formatDateTime(dataItem.getDatePublished())); + content.setTitle(dataItem.name()); + content.setSubtitle(I18n.formatDateTime(dataItem.datePublished())); - switch (dataItem.getVersionType()) { + switch (dataItem.versionType()) { case Alpha: content.addTag(i18n("mods.channel.alpha")); graphicPane.getChildren().setAll(SVG.ALPHA_CIRCLE.createIcon(24)); @@ -433,7 +433,7 @@ private static final class ModItem extends StackPane { break; } - for (ModLoaderType modLoaderType : dataItem.getLoaders()) { + for (ModLoaderType modLoaderType : dataItem.loaders()) { switch (modLoaderType) { case FORGE: content.addTag(i18n("install.installer.forge")); @@ -482,7 +482,7 @@ public ModVersion(RemoteMod mod, RemoteMod.Version version, DownloadPage selfPag case SHADER_PACK -> "shaderpack.download.title"; default -> "mods.download.title"; }; - this.setHeading(new HBox(new Label(i18n(title, version.getName())))); + this.setHeading(new HBox(new Label(i18n(title, version.name())))); VBox box = new VBox(8); box.setPadding(new Insets(8)); @@ -549,8 +549,8 @@ private void loadDependencies(RemoteMod.Version version, DownloadPage selfPage, Task.composeAsync(() -> { // TODO: Massive tasks may cause OOM. EnumMap> dependencies = new EnumMap<>(RemoteMod.DependencyType.class); - List> queue = new ArrayList<>(version.getDependencies().size()); - for (RemoteMod.Dependency dependency : version.getDependencies()) { + List> queue = new ArrayList<>(version.dependencies().size()); + for (RemoteMod.Dependency dependency : version.dependencies()) { if (dependency.getType() == RemoteMod.DependencyType.INCOMPATIBLE || dependency.getType() == RemoteMod.DependencyType.BROKEN) { continue; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModCheckUpdatesTask.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModCheckUpdatesTask.java index 1d9b4a0641..d82f83c6fd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModCheckUpdatesTask.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModCheckUpdatesTask.java @@ -50,7 +50,7 @@ public ModCheckUpdatesTask(DownloadProvider downloadProvider, String gameVersion continue; } - if (candidate == null || candidate.getCandidate().getDatePublished().isBefore(update.getCandidate().getDatePublished())) { + if (candidate == null || candidate.getCandidate().datePublished().isBefore(update.getCandidate().datePublished())) { candidate = update; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java index 3dae72f082..0bbdc95844 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java @@ -480,9 +480,9 @@ final class ModInfoDialog extends JFXDialogLayout { Task.runAsync(() -> { Optional versionOptional = repository.getRemoteVersionByLocalFile(modInfo.getModInfo(), modInfo.getModInfo().getFile()); if (versionOptional.isPresent()) { - RemoteMod remoteMod = repository.getModById(DownloadProviders.getDownloadProvider(), versionOptional.get().getModid()); + RemoteMod remoteMod = repository.getModById(DownloadProviders.getDownloadProvider(), versionOptional.get().modid()); FXUtils.runInFX(() -> { - for (ModLoaderType modLoaderType : versionOptional.get().getLoaders()) { + for (ModLoaderType modLoaderType : versionOptional.get().loaders()) { String loaderName = switch (modLoaderType) { case FORGE -> i18n("install.installer.forge"); case CLEANROOM -> i18n("install.installer.cleanroom"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java index c0c0a2f46f..b6c27223e9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java @@ -202,9 +202,9 @@ public ModUpdateObject(LocalModFile.ModUpdate data) { enabled.set(!data.getLocalMod().getModManager().isDisabled(data.getLocalMod().getFile())); fileName.set(data.getLocalMod().getFileName()); - currentVersion.set(data.getCurrentVersion().getVersion()); - targetVersion.set(data.getCandidate().getVersion()); - switch (data.getCurrentVersion().getSelf().getType()) { + currentVersion.set(data.getCurrentVersion().version()); + targetVersion.set(data.getCandidate().version()); + switch (data.getCurrentVersion().self().getType()) { case CURSEFORGE: source.set(i18n("mods.curseforge")); break; @@ -291,15 +291,15 @@ public static class ModUpdateTask extends Task { dependents.add(Task .runAsync(Schedulers.javafx(), () -> local.setOld(true)) .thenComposeAsync(() -> { - String fileName = remote.getFile().getFilename(); + String fileName = remote.file().filename(); if (isDisabled) fileName += ModManager.DISABLED_EXTENSION; var task = new FileDownloadTask( - remote.getFile().getUrl(), + remote.file().url(), modManager.getModsDirectory().resolve(fileName)); - task.setName(remote.getName()); + task.setName(remote.name()); return task; }) .whenComplete(Schedulers.javafx(), exception -> { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java index 1c9c79a078..5f27a218e0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java @@ -80,11 +80,11 @@ public static void downloadModpackImpl(DownloadProvider downloadProvider, Profil Path modpack; List downloadURLs; try { - downloadURLs = downloadProvider.injectURLWithCandidates(file.getFile().getUrl()); + downloadURLs = downloadProvider.injectURLWithCandidates(file.file().url()); modpack = Files.createTempFile("modpack", ".zip"); } catch (IOException | IllegalArgumentException e) { Controllers.dialog( - i18n("install.failed.downloading.detail", file.getFile().getUrl()) + "\n" + StringUtils.getStackTrace(e), + i18n("install.failed.downloading.detail", file.file().url()) + "\n" + StringUtils.getStackTrace(e), i18n("download.failed.no_code"), MessageDialogPane.MessageType.ERROR); return; } @@ -97,14 +97,14 @@ public static void downloadModpackImpl(DownloadProvider downloadProvider, Profil installWizardProvider = new ModpackInstallWizardProvider(profile, modpack, version); else installWizardProvider = new ModpackInstallWizardProvider(profile, modpack); - if (StringUtils.isNotBlank(mod.getIconUrl())) - installWizardProvider.setIconUrl(mod.getIconUrl()); + if (StringUtils.isNotBlank(mod.iconUrl())) + installWizardProvider.setIconUrl(mod.iconUrl()); Controllers.getDecorator().startWizard(installWizardProvider); } else if (e instanceof CancellationException) { Controllers.showToast(i18n("message.cancelled")); } else { Controllers.dialog( - i18n("install.failed.downloading.detail", file.getFile().getUrl()) + "\n" + StringUtils.getStackTrace(e), + i18n("install.failed.downloading.detail", file.file().url()) + "\n" + StringUtils.getStackTrace(e), i18n("download.failed.no_code"), MessageDialogPane.MessageType.ERROR); } }), diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java index e74c8bf621..d8e0995571 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java @@ -58,9 +58,9 @@ public boolean isRelyingOnDependencies() { @Override public void execute() throws IOException { dependencies.add(new FileDownloadTask( - remote.getVersion().getFile().getUrl(), - dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("fabric-api-" + remote.getVersion().getVersion() + ".jar"), - remote.getVersion().getFile().getIntegrityCheck()) + remote.getVersion().file().url(), + dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("fabric-api-" + remote.getVersion().version() + ".jar"), + remote.getVersion().file().getIntegrityCheck()) ); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java index 0fde60902b..9c9bd6b4cd 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java @@ -43,9 +43,9 @@ public boolean hasType() { public Task refreshAsync() { return Task.runAsync(() -> { for (RemoteMod.Version modVersion : Lang.toIterable(ModrinthRemoteModRepository.MODS.getRemoteVersionsById(downloadProvider, "P7dR8mSH"))) { - for (String gameVersion : modVersion.getGameVersions()) { - versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.getVersion(), modVersion.getName(), modVersion.getDatePublished(), modVersion, - Collections.singletonList(modVersion.getFile().getUrl()))); + for (String gameVersion : modVersion.gameVersions()) { + versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, modVersion.version(), modVersion.name(), modVersion.datePublished(), modVersion, + Collections.singletonList(modVersion.file().url()))); } } }); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIInstallTask.java index 1a9c2de6a0..1a19df5953 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIInstallTask.java @@ -53,9 +53,9 @@ public boolean isRelyingOnDependencies() { @Override public void execute() throws IOException { dependencies.add(new FileDownloadTask( - remote.getVersion().getFile().getUrl(), - dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("legacy-fabric-api-" + remote.getVersion().getVersion() + ".jar"), - remote.getVersion().getFile().getIntegrityCheck()) + remote.getVersion().file().url(), + dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("legacy-fabric-api-" + remote.getVersion().version() + ".jar"), + remote.getVersion().file().getIntegrityCheck()) ); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIVersionList.java index d7b6588e43..692e700613 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/legacyfabric/LegacyFabricAPIVersionList.java @@ -43,9 +43,9 @@ public boolean hasType() { public Task refreshAsync() { return Task.runAsync(() -> { for (RemoteMod.Version modVersion : Lang.toIterable(ModrinthRemoteModRepository.MODS.getRemoteVersionsById(downloadProvider, "legacy-fabric-api"))) { - for (String gameVersion : modVersion.getGameVersions()) { - versions.put(gameVersion, new LegacyFabricAPIRemoteVersion(gameVersion, modVersion.getVersion(), modVersion.getName(), modVersion.getDatePublished(), modVersion, - Collections.singletonList(modVersion.getFile().getUrl()))); + for (String gameVersion : modVersion.gameVersions()) { + versions.put(gameVersion, new LegacyFabricAPIRemoteVersion(gameVersion, modVersion.version(), modVersion.name(), modVersion.datePublished(), modVersion, + Collections.singletonList(modVersion.file().url()))); } } }); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java index 5f06cccba5..245280e58b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIInstallTask.java @@ -58,9 +58,9 @@ public boolean isRelyingOnDependencies() { @Override public void execute() throws IOException { dependencies.add(new FileDownloadTask( - remote.getVersion().getFile().getUrl(), - dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("quilt-api-" + remote.getVersion().getVersion() + ".jar"), - remote.getVersion().getFile().getIntegrityCheck()) + remote.getVersion().file().url(), + dependencyManager.getGameRepository().getModsDirectory(version.getId()).resolve("quilt-api-" + remote.getVersion().version() + ".jar"), + remote.getVersion().file().getIntegrityCheck()) ); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java index d0b23fa8cf..e1473958de 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/quilt/QuiltAPIVersionList.java @@ -43,9 +43,9 @@ public boolean hasType() { public Task refreshAsync() { return Task.runAsync(() -> { for (RemoteMod.Version modVersion : Lang.toIterable(ModrinthRemoteModRepository.MODS.getRemoteVersionsById(downloadProvider, "qsl"))) { - for (String gameVersion : modVersion.getGameVersions()) { - versions.put(gameVersion, new QuiltAPIRemoteVersion(gameVersion, modVersion.getVersion(), modVersion.getName(), modVersion.getDatePublished(), modVersion, - Collections.singletonList(modVersion.getFile().getUrl()))); + for (String gameVersion : modVersion.gameVersions()) { + versions.put(gameVersion, new QuiltAPIRemoteVersion(gameVersion, modVersion.version(), modVersion.name(), modVersion.datePublished(), modVersion, + Collections.singletonList(modVersion.file().url()))); } } }); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/LocalModFile.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/LocalModFile.java index cb8b341ea1..ed82c31c51 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/LocalModFile.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/LocalModFile.java @@ -24,11 +24,7 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import static org.jackhuang.hmcl.util.logging.Logger.LOG; @@ -181,11 +177,11 @@ public void disable() throws IOException { public ModUpdate checkUpdates(DownloadProvider downloadProvider, String gameVersion, RemoteModRepository repository) throws IOException { Optional currentVersion = repository.getRemoteVersionByLocalFile(this, file); if (!currentVersion.isPresent()) return null; - List remoteVersions = repository.getRemoteVersionsById(downloadProvider, currentVersion.get().getModid()) - .filter(version -> version.getGameVersions().contains(gameVersion)) - .filter(version -> version.getLoaders().contains(getModLoaderType())) - .filter(version -> version.getDatePublished().compareTo(currentVersion.get().getDatePublished()) > 0) - .sorted(Comparator.comparing(RemoteMod.Version::getDatePublished).reversed()) + List remoteVersions = repository.getRemoteVersionsById(downloadProvider, currentVersion.get().modid()) + .filter(version -> version.gameVersions().contains(gameVersion)) + .filter(version -> version.loaders().contains(getModLoaderType())) + .filter(version -> version.datePublished().compareTo(currentVersion.get().datePublished()) > 0) + .sorted(Comparator.comparing(RemoteMod.Version::datePublished).reversed()) .toList(); if (remoteVersions.isEmpty()) return null; return new ModUpdate(this, currentVersion.get(), remoteVersions.get(0)); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java index 91628a7b50..446e0a76de 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java @@ -29,72 +29,20 @@ import java.util.Map; import java.util.stream.Stream; -public final class RemoteMod { - - public static final RemoteMod BROKEN = new RemoteMod("", "", "RemoteMod.BROKEN", "", Collections.emptyList(), "", "", new RemoteMod.IMod() { +public record RemoteMod(String slug, String author, String title, String description, List categories, + String pageUrl, String iconUrl, IMod data) { + public static final RemoteMod BROKEN = new RemoteMod("", "", "RemoteMod.BROKEN", "", Collections.emptyList(), "", "", new IMod() { @Override public List loadDependencies(RemoteModRepository modRepository, DownloadProvider downloadProvider) throws IOException { throw new IOException(); } @Override - public Stream loadVersions(RemoteModRepository modRepository, DownloadProvider downloadProvider) throws IOException { + public Stream loadVersions(RemoteModRepository modRepository, DownloadProvider downloadProvider) throws IOException { throw new IOException(); } }); - private final String slug; - private final String author; - private final String title; - private final String description; - private final List categories; - private final String pageUrl; - private final String iconUrl; - private final IMod data; - - public RemoteMod(String slug, String author, String title, String description, List categories, String pageUrl, String iconUrl, IMod data) { - this.slug = slug; - this.author = author; - this.title = title; - this.description = description; - this.categories = categories; - this.pageUrl = pageUrl; - this.iconUrl = iconUrl; - this.data = data; - } - - public String getSlug() { - return slug; - } - - public String getAuthor() { - return author; - } - - public String getTitle() { - return title; - } - - public String getDescription() { - return description; - } - - public List getCategories() { - return categories; - } - - public String getPageUrl() { - return pageUrl; - } - - public String getIconUrl() { - return iconUrl; - } - - public IMod getData() { - return data; - } - public enum VersionType { Release, Beta, @@ -212,113 +160,24 @@ public interface IVersion { Type getType(); } - public static class Version { - private final IVersion self; - private final String modid; - private final String name; - private final String version; - private final String changelog; - private final Instant datePublished; - private final VersionType versionType; - private final File file; - private final List dependencies; - private final List gameVersions; - private final List loaders; - - public Version(IVersion self, String modid, String name, String version, String changelog, Instant datePublished, VersionType versionType, File file, List dependencies, List gameVersions, List loaders) { - this.self = self; - this.modid = modid; - this.name = name; - this.version = version; - this.changelog = changelog; - this.datePublished = datePublished; - this.versionType = versionType; - this.file = file; - this.dependencies = dependencies; - this.gameVersions = gameVersions; - this.loaders = loaders; - } - - public IVersion getSelf() { - return self; - } - - public String getModid() { - return modid; - } - - public String getName() { - return name; - } - - public String getVersion() { - return version; - } - - public String getChangelog() { - return changelog; - } - - public Instant getDatePublished() { - return datePublished; - } - - public VersionType getVersionType() { - return versionType; - } - - public File getFile() { - return file; - } - - public List getDependencies() { - return dependencies; - } - - public List getGameVersions() { - return gameVersions; - } - - public List getLoaders() { - return loaders; - } + public record Version(IVersion self, String modid, String name, String version, String changelog, + Instant datePublished, VersionType versionType, File file, List dependencies, + List gameVersions, List loaders) { } - public static class File { - private final Map hashes; - private final String url; - private final String filename; - - public File(Map hashes, String url, String filename) { - this.hashes = hashes; - this.url = url; - this.filename = filename; - } - - public Map getHashes() { - return hashes; - } - + public record File(Map hashes, String url, String filename) { public FileDownloadTask.IntegrityCheck getIntegrityCheck() { - if (hashes.containsKey("md5")) { - return new FileDownloadTask.IntegrityCheck("MD5", hashes.get("md5")); - } else if (hashes.containsKey("sha1")) { - return new FileDownloadTask.IntegrityCheck("SHA-1", hashes.get("sha1")); - } else if (hashes.containsKey("sha256")) { - return new FileDownloadTask.IntegrityCheck("SHA-256", hashes.get("sha256")); - } else if (hashes.containsKey("sha512")) { - return new FileDownloadTask.IntegrityCheck("SHA-512", hashes.get("sha512")); - } else { - return null; + if (hashes.containsKey("md5")) { + return new FileDownloadTask.IntegrityCheck("MD5", hashes.get("md5")); + } else if (hashes.containsKey("sha1")) { + return new FileDownloadTask.IntegrityCheck("SHA-1", hashes.get("sha1")); + } else if (hashes.containsKey("sha256")) { + return new FileDownloadTask.IntegrityCheck("SHA-256", hashes.get("sha256")); + } else if (hashes.containsKey("sha512")) { + return new FileDownloadTask.IntegrityCheck("SHA-512", hashes.get("sha512")); + } else { + return null; + } } } - - public String getUrl() { - return url; - } - - public String getFilename() { - return filename; - } - } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java index 87a81716bd..0a97ccae62 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseCompletionTask.java @@ -122,7 +122,7 @@ public void execute() throws Exception { if (StringUtils.isBlank(file.fileName()) || file.url() == null) { try { RemoteMod.File remoteFile = CurseForgeRemoteModRepository.MODS.getModFile(Integer.toString(file.projectID()), Integer.toString(file.fileID())); - return file.withFileName(remoteFile.getFilename()).withURL(remoteFile.getUrl()); + return file.withFileName(remoteFile.filename()).withURL(remoteFile.url()); } catch (FileNotFoundException fof) { LOG.warning("Could not query api.curseforge.com for deleted mods: " + file.projectID() + ", " + file.fileID(), fof); notFound.set(true); @@ -184,7 +184,7 @@ public void execute() throws Exception { */ private Path guessFilePath(CurseManifestFile file, DownloadProvider downloadProvider, Path resourcePacksRoot, Path shaderPacksRoot) throws IOException { RemoteMod mod = CurseForgeRemoteModRepository.MODS.getModById(downloadProvider, Integer.toString(file.projectID())); - int classID = ((CurseAddon) mod.getData()).getClassId(); + int classID = ((CurseAddon) mod.data()).getClassId(); String fileName = file.fileName(); return switch (classID) { case 12, // Resource pack diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepository.java index 6921fbc479..5b19ad0986 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseForgeRemoteModRepository.java @@ -173,7 +173,7 @@ public SearchResult search(DownloadProvider downloadProvider, String gameVersion StringUtils.LevCalculator levCalculator = new StringUtils.LevCalculator(); return new SearchResult(response.getData().stream().map(CurseAddon::toMod).map(remoteMod -> { - String lowerCaseResult = remoteMod.getTitle().toLowerCase(Locale.ROOT); + String lowerCaseResult = remoteMod.title().toLowerCase(Locale.ROOT); int diff = levCalculator.calc(lowerCaseSearchFilter, lowerCaseResult); for (String s : StringUtils.tokenize(lowerCaseResult)) { @@ -244,7 +244,7 @@ public RemoteMod.File getModFile(String modId, String fileId) throws IOException try { Response response = withApiKey(HttpRequest.GET(String.format("%s/v1/mods/%s/files/%s", PREFIX, modId, fileId))) .getJson(Response.typeOf(CurseAddon.LatestFile.class)); - return response.getData().toVersion().getFile(); + return response.getData().toVersion().file(); } finally { SEMAPHORE.release(); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackExportTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackExportTask.java index e4bd101d8a..0d4fdf8202 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackExportTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackExportTask.java @@ -17,25 +17,21 @@ */ package org.jackhuang.hmcl.mod.modrinth; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; - import org.jackhuang.hmcl.download.LibraryAnalyzer; import org.jackhuang.hmcl.game.DefaultGameRepository; -import org.jackhuang.hmcl.mod.ModAdviser; -import org.jackhuang.hmcl.mod.Modpack; -import org.jackhuang.hmcl.mod.ModpackExportInfo; +import org.jackhuang.hmcl.mod.*; +import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.util.DigestUtils; import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.io.Zipper; -import org.jackhuang.hmcl.mod.LocalModFile; -import org.jackhuang.hmcl.mod.RemoteMod; -import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.*; import static org.jackhuang.hmcl.util.logging.Logger.LOG; @@ -107,9 +103,9 @@ private ModrinthManifest.File tryGetRemoteFile(Path file, String relativePath) t List downloads = new ArrayList<>(); if (modrinthVersion.isPresent()) - downloads.add(modrinthVersion.get().getFile().getUrl()); + downloads.add(modrinthVersion.get().file().url()); if (curseForgeVersion.isPresent()) - downloads.add(curseForgeVersion.get().getFile().getUrl()); + downloads.add(curseForgeVersion.get().file().url()); long fileSize = Files.size(file); if (fileSize > Integer.MAX_VALUE) { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java index 72c30f7bd7..c3e61d058b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java @@ -37,14 +37,7 @@ import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.time.Instant; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.concurrent.Semaphore; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -442,7 +435,7 @@ public List getVersions() { @Override public List loadDependencies(RemoteModRepository modRepository, DownloadProvider downloadProvider) throws IOException { Set dependencies = modRepository.getRemoteVersionsById(downloadProvider, getId()) - .flatMap(version -> version.getDependencies().stream()) + .flatMap(version -> version.dependencies().stream()) .collect(Collectors.toSet()); List mods = new ArrayList<>(); for (RemoteMod.Dependency dependency : dependencies) { @@ -829,7 +822,7 @@ public String getLatestVersion() { @Override public List loadDependencies(RemoteModRepository modRepository, DownloadProvider downloadProvider) throws IOException { Set dependencies = modRepository.getRemoteVersionsById(downloadProvider, getProjectId()) - .flatMap(version -> version.getDependencies().stream()) + .flatMap(version -> version.dependencies().stream()) .collect(Collectors.toSet()); List mods = new ArrayList<>(); for (RemoteMod.Dependency dependency : dependencies) { From 9a05a2d066d17243ad92340ec61e10e4ade34dc9 Mon Sep 17 00:00:00 2001 From: CiiLu <109708109+CiiLu@users.noreply.github.com> Date: Fri, 1 May 2026 16:23:33 +0800 Subject: [PATCH 2/2] update --- .../org/jackhuang/hmcl/mod/RemoteMod.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java index 446e0a76de..c83996082f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteMod.java @@ -167,17 +167,17 @@ public record Version(IVersion self, String modid, String name, String version, public record File(Map hashes, String url, String filename) { public FileDownloadTask.IntegrityCheck getIntegrityCheck() { - if (hashes.containsKey("md5")) { - return new FileDownloadTask.IntegrityCheck("MD5", hashes.get("md5")); - } else if (hashes.containsKey("sha1")) { - return new FileDownloadTask.IntegrityCheck("SHA-1", hashes.get("sha1")); - } else if (hashes.containsKey("sha256")) { - return new FileDownloadTask.IntegrityCheck("SHA-256", hashes.get("sha256")); - } else if (hashes.containsKey("sha512")) { - return new FileDownloadTask.IntegrityCheck("SHA-512", hashes.get("sha512")); - } else { - return null; - } + if (hashes.containsKey("md5")) { + return new FileDownloadTask.IntegrityCheck("MD5", hashes.get("md5")); + } else if (hashes.containsKey("sha1")) { + return new FileDownloadTask.IntegrityCheck("SHA-1", hashes.get("sha1")); + } else if (hashes.containsKey("sha256")) { + return new FileDownloadTask.IntegrityCheck("SHA-256", hashes.get("sha256")); + } else if (hashes.containsKey("sha512")) { + return new FileDownloadTask.IntegrityCheck("SHA-512", hashes.get("sha512")); + } else { + return null; } } + } }