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..11f109d77d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -34,6 +34,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 +144,9 @@ public static Config fromJson(String json) throws JsonParseException { @SerializedName("autoChooseDownloadType") private BooleanProperty autoChooseDownloadType = new SimpleBooleanProperty(true); + @SerializedName("enableMCIM") + private BooleanProperty mcimEnablement = new SimpleBooleanProperty(false); + @SerializedName("versionListSource") private StringProperty versionListSource = new SimpleStringProperty("balanced"); @@ -207,6 +212,17 @@ public static Config fromJson(String json) throws JsonParseException { public Config() { PropertyUtils.attachListener(this, helper); + 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; + }); } @Override @@ -505,6 +521,8 @@ public void setAutoChooseDownloadType(boolean autoChooseDownloadType) { this.autoChooseDownloadType.set(autoChooseDownloadType); } + 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 695c89ddfa..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 @@ -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().getMCIMEnablementProperty()); + 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 afa765ec70..a8f828631e 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..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 @@ -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 void mcim(boolean enabled) { + if(enabled) + this.PREFIX = "https://mod.mcimirror.top/curseforge"; + else + this.PREFIX = "https://api.curseforge.com"; + return; + } + 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..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 @@ -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,14 @@ private static String convertSortType(SortType sortType) { } } + public void mcim(boolean enabled) { + if(enabled) + this.PREFIX = "https://mod.mcimirror.top/modrinth"; + else + this.PREFIX = "https://api.modrinth.com"; + return; + } + @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<>();