fix(download): incorrect mcmod url for modpacks. Closes #1525.

This commit is contained in:
huanghongxun
2022-06-03 21:28:19 +08:00
parent ae484e3b67
commit 2a979d2b15
4 changed files with 24 additions and 11 deletions

View File

@@ -261,7 +261,7 @@ public class DownloadPage extends Control implements DecoratorPage {
if (getSkinnable().mod != null) { if (getSkinnable().mod != null) {
JFXHyperlink openMcmodButton = new JFXHyperlink(i18n("mods.mcmod")); JFXHyperlink openMcmodButton = new JFXHyperlink(i18n("mods.mcmod"));
openMcmodButton.setOnAction(e -> FXUtils.openLink(ModManager.getMcmodUrl(getSkinnable().mod.getMcmod()))); openMcmodButton.setOnAction(e -> FXUtils.openLink(getSkinnable().translations.getMcmodUrl(getSkinnable().mod)));
descriptionPane.getChildren().add(openMcmodButton); descriptionPane.getChildren().add(openMcmodButton);
if (StringUtils.isNotBlank(getSkinnable().mod.getMcbbs())) { if (StringUtils.isNotBlank(getSkinnable().mod.getMcbbs())) {

View File

@@ -261,7 +261,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
mcmodButton.setText(i18n("mods.mcmod.page")); mcmodButton.setText(i18n("mods.mcmod.page"));
mcmodButton.setOnAction(e -> { mcmodButton.setOnAction(e -> {
fireEvent(new DialogCloseEvent()); fireEvent(new DialogCloseEvent());
FXUtils.openLink(ModManager.getMcmodUrl(modInfo.getMod().getMcmod())); FXUtils.openLink(ModTranslations.MOD.getMcmodUrl(modInfo.getMod()));
}); });
getActions().add(mcmodButton); getActions().add(mcmodButton);
} }

View File

@@ -36,10 +36,25 @@ import static org.jackhuang.hmcl.util.Pair.pair;
* *
* @see <a href="https://www.mcmod.cn">mcmod.cn</a> * @see <a href="https://www.mcmod.cn">mcmod.cn</a>
*/ */
public final class ModTranslations { public enum ModTranslations {
public static ModTranslations MOD = new ModTranslations("/assets/mod_data.txt"); MOD("/assets/mod_data.txt") {
public static ModTranslations MODPACK = new ModTranslations("/assets/modpack_data.txt"); @Override
public static ModTranslations EMPTY = new ModTranslations(""); public String getMcmodUrl(Mod mod) {
return String.format("https://www.mcmod.cn/class/%s.html", mod.getMcmod());
}
},
MODPACK("/assets/modpack_data.txt") {
@Override
public String getMcmodUrl(Mod mod) {
return String.format("https://www.mcmod.cn/modpack/%s.html", mod.getMcmod());
}
},
EMPTY("") {
@Override
public String getMcmodUrl(Mod mod) {
return "";
}
};
public static ModTranslations getTranslationsByRepositoryType(RemoteModRepository.Type type) { public static ModTranslations getTranslationsByRepositoryType(RemoteModRepository.Type type) {
switch (type) { switch (type) {
@@ -59,7 +74,7 @@ public final class ModTranslations {
private List<Pair<String, Mod>> keywords; private List<Pair<String, Mod>> keywords;
private int maxKeywordLength = -1; private int maxKeywordLength = -1;
private ModTranslations(String resourceName) { ModTranslations(String resourceName) {
this.resourceName = resourceName; this.resourceName = resourceName;
} }
@@ -77,6 +92,8 @@ public final class ModTranslations {
return modIdMap.get(id); return modIdMap.get(id);
} }
public abstract String getMcmodUrl(Mod mod);
public List<Mod> searchMod(String query) { public List<Mod> searchMod(String query) {
if (!loadKeywords()) return Collections.emptyList(); if (!loadKeywords()) return Collections.emptyList();

View File

@@ -305,10 +305,6 @@ public final class ModManager {
return getModsDirectory().resolve(fileName); return getModsDirectory().resolve(fileName);
} }
public static String getMcmodUrl(String mcmodId) {
return String.format("https://www.mcmod.cn/class/%s.html", mcmodId);
}
public static String getMcbbsUrl(String mcbbsId) { public static String getMcbbsUrl(String mcbbsId) {
return String.format("https://www.mcbbs.net/thread-%s-1-1.html", mcbbsId); return String.format("https://www.mcbbs.net/thread-%s-1-1.html", mcbbsId);
} }