mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 05:16:13 -04:00
Deny access to CurseForge without api key (#1858)
This commit is contained in:
parent
024c90d688
commit
7ee81f7425
@ -39,6 +39,7 @@ import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
|
||||
import org.jackhuang.hmcl.ui.animation.TransitionPane;
|
||||
import org.jackhuang.hmcl.ui.construct.AdvancedListBox;
|
||||
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
|
||||
import org.jackhuang.hmcl.ui.construct.TabControl;
|
||||
import org.jackhuang.hmcl.ui.construct.TabHeader;
|
||||
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
|
||||
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
||||
@ -128,19 +129,19 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
|
||||
item.setTitle(i18n("resourcepack"));
|
||||
item.setLeftGraphic(wrap(SVG::textureBox));
|
||||
item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(resourcePackTab));
|
||||
item.setOnAction(e -> tab.select(resourcePackTab));
|
||||
item.setOnAction(e -> selectTabIfCurseForgeAvailable(resourcePackTab));
|
||||
})
|
||||
// .addNavigationDrawerItem(item -> {
|
||||
// item.setTitle(i18n("download.curseforge.customization"));
|
||||
// item.setLeftGraphic(wrap(SVG::script));
|
||||
// item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(customizationTab));
|
||||
// item.setOnAction(e -> tab.select(customizationTab));
|
||||
// item.setOnAction(e -> selectTabIfCurseForgeAvailable(customizationTab));
|
||||
// })
|
||||
.addNavigationDrawerItem(item -> {
|
||||
item.setTitle(i18n("world"));
|
||||
item.setLeftGraphic(wrap(SVG::earth));
|
||||
item.activeProperty().bind(tab.getSelectionModel().selectedItemProperty().isEqualTo(worldTab));
|
||||
item.setOnAction(e -> tab.select(worldTab));
|
||||
item.setOnAction(e -> selectTabIfCurseForgeAvailable(worldTab));
|
||||
});
|
||||
FXUtils.setLimitWidth(sideBar, 200);
|
||||
setLeft(sideBar);
|
||||
@ -149,7 +150,14 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
|
||||
setCenter(transitionPane);
|
||||
}
|
||||
|
||||
private <T extends Node> Supplier<T> loadVersionFor(Supplier<T> nodeSupplier) {
|
||||
private void selectTabIfCurseForgeAvailable(TabControl.Tab<?> newTab) {
|
||||
if (CurseForgeRemoteModRepository.isAvailable())
|
||||
tab.select(newTab);
|
||||
else
|
||||
Controllers.dialog(i18n("download.curseforge.unavailable"));
|
||||
}
|
||||
|
||||
private static <T extends Node> Supplier<T> loadVersionFor(Supplier<T> nodeSupplier) {
|
||||
return () -> {
|
||||
T node = nodeSupplier.get();
|
||||
if (node instanceof VersionPage.VersionLoadable) {
|
||||
@ -159,7 +167,7 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage
|
||||
};
|
||||
}
|
||||
|
||||
private void download(Profile profile, @Nullable String version, RemoteMod.Version file, String subdirectoryName) {
|
||||
private static void download(Profile profile, @Nullable String version, RemoteMod.Version file, String subdirectoryName) {
|
||||
if (version == null) version = profile.getSelectedVersion();
|
||||
|
||||
Path runDirectory = profile.getRepository().hasVersion(version) ? profile.getRepository().getRunDirectory(version).toPath() : profile.getRepository().getBaseDirectory().toPath();
|
||||
|
@ -32,7 +32,10 @@ public class ModDownloadListPage extends DownloadListPage {
|
||||
|
||||
supportChinese.set(true);
|
||||
downloadSources.get().setAll("mods.curseforge", "mods.modrinth");
|
||||
downloadSource.set("mods.curseforge");
|
||||
if (CurseForgeRemoteModRepository.isAvailable())
|
||||
downloadSource.set("mods.curseforge");
|
||||
else
|
||||
downloadSource.set("mods.modrinth");
|
||||
}
|
||||
|
||||
private class Repository extends LocalizedRemoteModRepository {
|
||||
|
@ -32,7 +32,10 @@ public class ModpackDownloadListPage extends DownloadListPage {
|
||||
|
||||
supportChinese.set(true);
|
||||
downloadSources.get().setAll("mods.curseforge", "mods.modrinth");
|
||||
downloadSource.set("mods.curseforge");
|
||||
if (CurseForgeRemoteModRepository.isAvailable())
|
||||
downloadSource.set("mods.curseforge");
|
||||
else
|
||||
downloadSource.set("mods.modrinth");
|
||||
}
|
||||
|
||||
private class Repository extends LocalizedRemoteModRepository {
|
||||
|
@ -308,6 +308,7 @@ download=Download
|
||||
download.code.404=File not found on the remote server\: %s
|
||||
download.content=Addons
|
||||
download.curseforge.customization=Light and shadow, and game customization
|
||||
download.curseforge.unavailable=HMCL nightly build does not support access to CurseForge, please use stable version or beta version to download.
|
||||
download.existing=The file cannot be saved because it already exists. You can use 'Save As' to save the file elsewhere.
|
||||
download.external_link=Open Website
|
||||
download.failed=Failed to download %1$s, response code\: %2$d
|
||||
|
@ -295,6 +295,7 @@ download=下載
|
||||
download.code.404=遠端伺服器沒有需要下載的檔案: %s
|
||||
download.content=遊戲內容
|
||||
download.curseforge.customization=光影與遊戲定制
|
||||
download.curseforge.unavailable=HMCL 預覽版暫不支持訪問 CurseForge,請使用穩定版或測試版進行下載。
|
||||
download.existing=檔案已存在,無法保存。你可以選擇另存為將檔案保存至其他地方。
|
||||
download.external_link=打開下載網站
|
||||
download.failed=下載失敗: %1$s,錯誤碼:%2$d
|
||||
|
@ -295,6 +295,7 @@ download=下载
|
||||
download.code.404=远程服务器不包含需要下载的文件: %s
|
||||
download.content=游戏内容
|
||||
download.curseforge.customization=光影与游戏定制
|
||||
download.curseforge.unavailable=HMCL 预览版暂不支持访问 CurseForge,请使用稳定版或测试版进行下载。
|
||||
download.existing=文件已存在,无法保存。你可以在模组选择栏中的右侧按钮另存为将文件保存至其他地方。
|
||||
download.external_link=打开下载网站
|
||||
download.failed=下载失败: %1$s,错误码:%2$d
|
||||
|
@ -40,9 +40,12 @@ import static org.jackhuang.hmcl.util.Pair.pair;
|
||||
public final class CurseForgeRemoteModRepository implements RemoteModRepository {
|
||||
|
||||
private static final String PREFIX = "https://api.curseforge.com";
|
||||
|
||||
private static final String apiKey = System.getProperty("hmcl.curseforge.apikey", JarUtils.getManifestAttribute("CurseForge-Api-Key", ""));
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return !apiKey.isEmpty();
|
||||
}
|
||||
|
||||
private final Type type;
|
||||
private final int section;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user