From 3d29e8521d044659291ea2f375f5a75ceb39566b Mon Sep 17 00:00:00 2001 From: EncVar Date: Sat, 9 Nov 2024 14:32:19 +0800 Subject: [PATCH 1/3] feat: mcim support --- .../org/jackhuang/hmcl/setting/Config.java | 27 +++++++++++++++++++ .../hmcl/ui/main/DownloadSettingsPage.java | 8 +++++- .../resources/assets/lang/I18N.properties | 1 + .../curse/CurseForgeRemoteModRepository.java | 10 ++++++- .../modrinth/ModrinthRemoteModRepository.java | 15 ++++++++++- 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index b124c509a5..4767203c7c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -24,6 +24,8 @@ import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.*; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.ObservableMap; @@ -34,6 +36,8 @@ import org.hildan.fxgson.factories.JavaFxPropertyTypeAdapterFactory; import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorServer; +import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository; +import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository; import org.jackhuang.hmcl.util.gson.EnumOrdinalDeserializer; import org.jackhuang.hmcl.util.gson.FileTypeAdapter; import org.jackhuang.hmcl.util.i18n.Locales; @@ -142,6 +146,9 @@ public static Config fromJson(String json) throws JsonParseException { @SerializedName("autoChooseDownloadType") private BooleanProperty autoChooseDownloadType = new SimpleBooleanProperty(true); + @SerializedName("enableMCIM") + private BooleanProperty enableMCIM = new SimpleBooleanProperty(false); + @SerializedName("versionListSource") private StringProperty versionListSource = new SimpleStringProperty("balanced"); @@ -207,6 +214,20 @@ public static Config fromJson(String json) throws JsonParseException { public Config() { PropertyUtils.attachListener(this, helper); + enableMCIM.addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observableValue, Boolean previous, Boolean now) { + ModrinthRemoteModRepository.MODS.mcim(now); + ModrinthRemoteModRepository.MODPACKS.mcim(now); + ModrinthRemoteModRepository.RESOURCE_PACKS.mcim(now); + + CurseForgeRemoteModRepository.MODS.mcim(now); + CurseForgeRemoteModRepository.MODPACKS.mcim(now); + CurseForgeRemoteModRepository.RESOURCE_PACKS.mcim(now); + + return; + } + }); } @Override @@ -505,6 +526,12 @@ public void setAutoChooseDownloadType(boolean autoChooseDownloadType) { this.autoChooseDownloadType.set(autoChooseDownloadType); } + public void enableMCIM() { this.enableMCIM.set(true); } + + public void disableMCIM() { this.enableMCIM.set(false); } + + public Property enableMCIMProperty() { return enableMCIM; } + public String getVersionListSource() { return versionListSource.get(); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java index 695c89ddfa..f8c2137dd6 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java @@ -96,7 +96,13 @@ public DownloadSettingsPage() { selectedItemPropertyFor(cboDownloadSource).bindBidirectional(config().downloadTypeProperty()); } - downloadSource.getChildren().setAll(chooseWrapper, versionListSourcePane, downloadSourcePane); + VBox checkBoxWrapper = new VBox(); + checkBoxWrapper.setPadding(new Insets(8, 0, 8, 0)); + JFXCheckBox enableMCIMCheckbox = new JFXCheckBox(i18n("settings.launcher.enable_mcim")); + enableMCIMCheckbox.selectedProperty().bindBidirectional(config().enableMCIMProperty()); + checkBoxWrapper.getChildren().setAll(enableMCIMCheckbox); + + downloadSource.getChildren().setAll(chooseWrapper, versionListSourcePane, downloadSourcePane, checkBoxWrapper); } content.getChildren().addAll(ComponentList.createComponentListTitle(i18n("settings.launcher.download_source")), downloadSource); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index 43b6d4256f..0375f4206c 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -1230,6 +1230,7 @@ settings.launcher.download.threads.auto=Automatically Determine settings.launcher.download.threads.hint=Too many threads may cause your system to freeze, and your download speed may be affected by your ISP and download servers. It is not always the case that more threads increase your download speed. settings.launcher.download_source=Download Source settings.launcher.download_source.auto=Automatically Choose Download Sources +settings.launcher.enable_mcim=Enable MCIM mod info mirror settings.launcher.enable_game_list=Show instance list in homepage settings.launcher.font=Font settings.launcher.general=General 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 3913ef7f0e..b0e48c734b 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 @@ -42,7 +42,7 @@ public final class CurseForgeRemoteModRepository implements RemoteModRepository { - private static final String PREFIX = "https://api.curseforge.com"; + private String PREFIX = "https://api.curseforge.com"; private static final String apiKey = System.getProperty("hmcl.curseforge.apikey", JarUtils.getManifestAttribute("CurseForge-Api-Key", "")); private static final int WORD_PERFECT_MATCH_WEIGHT = 5; @@ -64,6 +64,14 @@ public Type getType() { return type; } + public CurseForgeRemoteModRepository mcim(boolean enabled) { + if(enabled) + this.PREFIX = "https://mod.mcimirror.top/curseforge"; + else + this.PREFIX = "https://api.curseforge.com"; + return this; + } + private int toModsSearchSortField(SortType sort) { // https://docs.curseforge.com/#tocS_ModsSearchSortField switch (sort) { 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 c257a38816..0c0a6a0c05 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 @@ -28,6 +28,7 @@ import org.jackhuang.hmcl.util.io.HttpRequest; import org.jackhuang.hmcl.util.io.NetworkUtils; import org.jackhuang.hmcl.util.io.ResponseCodeException; +import org.jackhuang.hmcl.util.logging.Logger; import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -46,7 +47,7 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository { public static final ModrinthRemoteModRepository MODPACKS = new ModrinthRemoteModRepository("modpack"); public static final ModrinthRemoteModRepository RESOURCE_PACKS = new ModrinthRemoteModRepository("resourcepack"); - private static final String PREFIX = "https://api.modrinth.com"; + private String PREFIX = "https://api.modrinth.com"; private final String projectType; @@ -76,6 +77,18 @@ private static String convertSortType(SortType sortType) { } } + public ModrinthRemoteModRepository mcim(boolean enabled) { + if(enabled) { + this.PREFIX = "https://mod.mcimirror.top/modrinth"; + Logger.LOG.info("MCIM enabled"); + } + else { + this.PREFIX = "https://api.modrinth.com"; + Logger.LOG.info("MCIM disabled"); + } + return this; + } + @Override public SearchResult search(String gameVersion, @Nullable RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, SortType sort, SortOrder sortOrder) throws IOException { List> facets = new ArrayList<>(); From 08ea7bd9886acb169955d67ec6014948416340ee Mon Sep 17 00:00:00 2001 From: EncVar Date: Sat, 9 Nov 2024 14:41:21 +0800 Subject: [PATCH 2/3] enhancement: optimize field name --- .../main/java/org/jackhuang/hmcl/setting/Config.java | 10 +++------- .../jackhuang/hmcl/ui/main/DownloadSettingsPage.java | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index 4767203c7c..dbf70872a4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -147,7 +147,7 @@ public static Config fromJson(String json) throws JsonParseException { private BooleanProperty autoChooseDownloadType = new SimpleBooleanProperty(true); @SerializedName("enableMCIM") - private BooleanProperty enableMCIM = new SimpleBooleanProperty(false); + private BooleanProperty mcimEnablement = new SimpleBooleanProperty(false); @SerializedName("versionListSource") private StringProperty versionListSource = new SimpleStringProperty("balanced"); @@ -214,7 +214,7 @@ public static Config fromJson(String json) throws JsonParseException { public Config() { PropertyUtils.attachListener(this, helper); - enableMCIM.addListener(new ChangeListener() { + mcimEnablement.addListener(new ChangeListener() { @Override public void changed(ObservableValue observableValue, Boolean previous, Boolean now) { ModrinthRemoteModRepository.MODS.mcim(now); @@ -526,11 +526,7 @@ public void setAutoChooseDownloadType(boolean autoChooseDownloadType) { this.autoChooseDownloadType.set(autoChooseDownloadType); } - public void enableMCIM() { this.enableMCIM.set(true); } - - public void disableMCIM() { this.enableMCIM.set(false); } - - public Property enableMCIMProperty() { return enableMCIM; } + public BooleanProperty getMCIMEnablementProperty() { return mcimEnablement; } public String getVersionListSource() { return versionListSource.get(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java index f8c2137dd6..5792c55d49 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/DownloadSettingsPage.java @@ -99,7 +99,7 @@ public DownloadSettingsPage() { VBox checkBoxWrapper = new VBox(); checkBoxWrapper.setPadding(new Insets(8, 0, 8, 0)); JFXCheckBox enableMCIMCheckbox = new JFXCheckBox(i18n("settings.launcher.enable_mcim")); - enableMCIMCheckbox.selectedProperty().bindBidirectional(config().enableMCIMProperty()); + enableMCIMCheckbox.selectedProperty().bindBidirectional(config().getMCIMEnablementProperty()); checkBoxWrapper.getChildren().setAll(enableMCIMCheckbox); downloadSource.getChildren().setAll(chooseWrapper, versionListSourcePane, downloadSourcePane, checkBoxWrapper); From e2aaf1d22fa118874ffcd0fa6fed184468f2d557 Mon Sep 17 00:00:00 2001 From: EncVar Date: Sat, 9 Nov 2024 14:49:12 +0800 Subject: [PATCH 3/3] enhancement: remove redundant logger --- .../org/jackhuang/hmcl/setting/Config.java | 25 ++++++++----------- .../curse/CurseForgeRemoteModRepository.java | 4 +-- .../modrinth/ModrinthRemoteModRepository.java | 12 +++------ 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index dbf70872a4..11f109d77d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -24,8 +24,6 @@ import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.*; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.ObservableMap; @@ -214,19 +212,16 @@ public static Config fromJson(String json) throws JsonParseException { public Config() { PropertyUtils.attachListener(this, helper); - mcimEnablement.addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observableValue, Boolean previous, Boolean now) { - ModrinthRemoteModRepository.MODS.mcim(now); - ModrinthRemoteModRepository.MODPACKS.mcim(now); - ModrinthRemoteModRepository.RESOURCE_PACKS.mcim(now); - - CurseForgeRemoteModRepository.MODS.mcim(now); - CurseForgeRemoteModRepository.MODPACKS.mcim(now); - CurseForgeRemoteModRepository.RESOURCE_PACKS.mcim(now); - - return; - } + mcimEnablement.addListener((observableValue, previous, now) -> { + ModrinthRemoteModRepository.MODS.mcim(now); + ModrinthRemoteModRepository.MODPACKS.mcim(now); + ModrinthRemoteModRepository.RESOURCE_PACKS.mcim(now); + + CurseForgeRemoteModRepository.MODS.mcim(now); + CurseForgeRemoteModRepository.MODPACKS.mcim(now); + CurseForgeRemoteModRepository.RESOURCE_PACKS.mcim(now); + + return; }); } 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 b0e48c734b..b2b3da4754 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 @@ -64,12 +64,12 @@ public Type getType() { return type; } - public CurseForgeRemoteModRepository mcim(boolean enabled) { + public void mcim(boolean enabled) { if(enabled) this.PREFIX = "https://mod.mcimirror.top/curseforge"; else this.PREFIX = "https://api.curseforge.com"; - return this; + return; } private int toModsSearchSortField(SortType sort) { 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 0c0a6a0c05..e4fc73ffbd 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 @@ -77,16 +77,12 @@ private static String convertSortType(SortType sortType) { } } - public ModrinthRemoteModRepository mcim(boolean enabled) { - if(enabled) { + public void mcim(boolean enabled) { + if(enabled) this.PREFIX = "https://mod.mcimirror.top/modrinth"; - Logger.LOG.info("MCIM enabled"); - } - else { + else this.PREFIX = "https://api.modrinth.com"; - Logger.LOG.info("MCIM disabled"); - } - return this; + return; } @Override