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 aa5bf1956..dc0f6a075 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 @@ -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 Supplier loadVersionFor(Supplier nodeSupplier) { + private void selectTabIfCurseForgeAvailable(TabControl.Tab newTab) { + if (CurseForgeRemoteModRepository.isAvailable()) + tab.select(newTab); + else + Controllers.dialog(i18n("download.curseforge.unavailable")); + } + + private static Supplier loadVersionFor(Supplier 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(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java index 0af781f97..a86291fd8 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModDownloadListPage.java @@ -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 { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModpackDownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModpackDownloadListPage.java index e8be19219..bcfbec688 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModpackDownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModpackDownloadListPage.java @@ -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 { diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index f19d77f62..9d1dfb199 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -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 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 8d276266c..82b8674da 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -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 diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 591cb5f48..ed4b83e5a 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -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 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 1f5045549..b67104e40 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 @@ -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;