Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现 #3366 Mod 镜像源 MCIM #3433

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -505,6 +521,8 @@ public void setAutoChooseDownloadType(boolean autoChooseDownloadType) {
this.autoChooseDownloadType.set(autoChooseDownloadType);
}

public BooleanProperty getMCIMEnablementProperty() { return mcimEnablement; }

public String getVersionListSource() {
return versionListSource.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<List<String>> facets = new ArrayList<>();
Expand Down