diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index a237e15b8..e51e7795a 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -342,7 +342,7 @@ download.failed.no_code=Failed to download download.failed.refresh=Failed to fetch version list. Please click here to retry. download.game=New Game download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/) -download.provider.mojang=Official (OptiFine is provided by BMCLAPI) +download.provider.mojang=Official (OptiFine is provided by OF-302) download.provider.official=From Official Sources download.provider.balanced=From Fastest Available download.provider.mirror=From Mirror diff --git a/HMCL/src/main/resources/assets/lang/I18N_es.properties b/HMCL/src/main/resources/assets/lang/I18N_es.properties index 7e66815c2..501455647 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_es.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_es.properties @@ -343,7 +343,7 @@ download.failed.no_code=No se ha podido descargar download.failed.refresh=No se ha podido obtener la lista de versiones. Por favor, haga clic aquí para volver a intentarlo. download.game=Nuevo juego download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/) -download.provider.mojang=Oficial (OptiFine es proporcionado por BMCLAPI) +download.provider.mojang=Oficial (OptiFine es proporcionado por OF-302) download.provider.official=De fuentes oficiales download.provider.balanced=De la fuente más rápida disponible download.provider.mirror=Desde espejo diff --git a/HMCL/src/main/resources/assets/lang/I18N_ja.properties b/HMCL/src/main/resources/assets/lang/I18N_ja.properties index 609bef992..c6aaf611d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ja.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ja.properties @@ -297,7 +297,7 @@ download.failed.empty=候補者なし。戻るにはここをクリックして download.failed.refresh=バージョンリストをダウンロードできません。ここをクリックして再試行してください。 download.game=ゲームのダウンロード download.provider.bmclapi=BMCLAPI(ミラーソース) -download.provider.mojang=Mojang(OptiFineはBMCLAPIにより提供されます) 推奨 +download.provider.mojang=Mojang(OptiFineはOF-302により提供されます) 推奨 download.provider.official=公式ソースからロード download.provider.balanced=mcbbsのソースからロード download.provider.mirror=ミラーソースからロード diff --git a/HMCL/src/main/resources/assets/lang/I18N_ru.properties b/HMCL/src/main/resources/assets/lang/I18N_ru.properties index 3b80f79d7..fda55a621 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ru.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ru.properties @@ -344,7 +344,7 @@ download.failed.no_code=Не удалось скачать download.failed.refresh=Не удалось получить список версий. Нажмите здесь, чтобы повторить попытку. download.game=Новая игра download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/) -download.provider.mojang=Официальный (OptiFine предоставляется BMCLAPI) +download.provider.mojang=Официальный (OptiFine предоставляется OF-302) download.provider.official=Из официальных источников download.provider.balanced=Из самых быстрых доступных download.provider.mirror=Из зеркала diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index 90c3b63fd..8c5538f2b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -344,7 +344,7 @@ download.failed.no_code=下載失敗 download.failed.refresh=載入版本清單失敗,按一下此處重試。 download.game=新遊戲 download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/) -download.provider.mojang=官方伺服器 (OptiFine 由 BMCLAPI 提供) +download.provider.mojang=官方伺服器 (OptiFine 由 OF-302 提供) download.provider.official=盡量使用官方源 (最新,但可能載入慢) download.provider.balanced=選取載入速度快的下載源 (平衡,但可能不是最新) download.provider.mirror=盡量使用鏡像源 (載入快,但可能不是最新) 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 de1c55bcf..fd5061425 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -352,7 +352,7 @@ download.failed.no_code=下载失败 download.failed.refresh=[加载版本列表失败,点击此处重试]\n(你可以点击右上角帮助按钮进行求助) download.game=新游戏 download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com) -download.provider.mojang=官方 (OptiFine 自动安装使用 BMCLAPI 下载源) +download.provider.mojang=官方 (OptiFine 自动安装使用 OF-302 下载源) download.provider.official=尽量使用官方源 (最新,但可能加载慢) download.provider.balanced=选择加载速度快的下载源 (平衡,但可能不是最新) download.provider.mirror=尽量使用镜像源 (加载快,但可能不是最新) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java index 86fc3e032..4d2d1eab6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java @@ -23,7 +23,7 @@ import org.jackhuang.hmcl.download.forge.ForgeVersionList; import org.jackhuang.hmcl.download.game.GameVersionList; import org.jackhuang.hmcl.download.liteloader.LiteLoaderVersionList; import org.jackhuang.hmcl.download.neoforge.NeoForgeOfficialVersionList; -import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList; +import org.jackhuang.hmcl.download.optifine.OptiFine302VersionList; import org.jackhuang.hmcl.download.quilt.QuiltAPIVersionList; import org.jackhuang.hmcl.download.quilt.QuiltVersionList; @@ -38,7 +38,7 @@ public class MojangDownloadProvider implements DownloadProvider { private final ForgeVersionList forge; private final NeoForgeOfficialVersionList neoforge; private final LiteLoaderVersionList liteLoader; - private final OptiFineBMCLVersionList optifine; + private final OptiFine302VersionList optifine; private final QuiltVersionList quilt; private final QuiltAPIVersionList quiltApi; @@ -52,7 +52,7 @@ public class MojangDownloadProvider implements DownloadProvider { this.forge = new ForgeVersionList(this); this.neoforge = new NeoForgeOfficialVersionList(this); this.liteLoader = new LiteLoaderVersionList(this); - this.optifine = new OptiFineBMCLVersionList(apiRoot); + this.optifine = new OptiFine302VersionList("https://hmcl-dev.github.io/metadata/optifine/"); this.quilt = new QuiltVersionList(this); this.quiltApi = new QuiltAPIVersionList(this); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFine302VersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFine302VersionList.java new file mode 100644 index 000000000..cd97f188f --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFine302VersionList.java @@ -0,0 +1,93 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2020 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.optifine; + +import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; +import org.jackhuang.hmcl.download.VersionList; +import org.jackhuang.hmcl.util.io.HttpRequest; +import org.jackhuang.hmcl.util.versioning.VersionNumber; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +/** + * @author huangyuhui + */ +public final class OptiFine302VersionList extends VersionList { + private final String versionListURL; + + public OptiFine302VersionList(String versionListURL) { + this.versionListURL = versionListURL; + } + + @Override + public boolean hasType() { + return true; + } + + @Override + public CompletableFuture refreshAsync() { + return HttpRequest.GET(versionListURL).getJsonAsync(TypeToken.get(OptiFine302VersionList.VersionList.class)).thenAcceptAsync(root -> { + lock.writeLock().lock(); + + try { + versions.clear(); + for (OptiFineVersion element : root.versions) { + String gameVersion = VersionNumber.normalize(element.gameVersion); + versions.put(gameVersion, new OptiFineRemoteVersion( + gameVersion, element.version, + root.downloadBases.stream().map(u -> u + element.fileName).collect(Collectors.toList()), + element.fileName.startsWith("pre") + )); + } + } finally { + lock.writeLock().unlock(); + } + }); + } + + private static final class VersionList { + @SerializedName("file") + private final List versions; + + @SerializedName("download") + private final List downloadBases; + + public VersionList(List versions, List downloadBases) { + this.versions = versions; + this.downloadBases = downloadBases; + } + } + + private static final class OptiFineVersion { + @SerializedName("name") + private final String version; + @SerializedName("filename") + private final String fileName; + @SerializedName("mcversion") + private final String gameVersion; + + public OptiFineVersion(String version, String fileName, String gameVersion) { + this.version = version; + this.fileName = fileName; + this.gameVersion = gameVersion; + } + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java index 48e0f31a2..cd21b3ad1 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java @@ -80,17 +80,17 @@ public final class OptiFineBMCLVersionList extends VersionList duplicates = new HashSet<>(); for (OptiFineVersion element : root) { - String version = element.getType() + "_" + element.getPatch(); - String mirror = "https://bmclapi2.bangbang93.com/optifine/" + toLookupVersion(element.getGameVersion()) + "/" + element.getType() + "/" + element.getPatch(); + String version = element.type + "_" + element.patch; + String mirror = apiRoot + "/optifine/" + toLookupVersion(element.gameVersion) + "/" + element.type + "/" + element.patch; if (!duplicates.add(mirror)) continue; - boolean isPre = element.getPatch() != null && (element.getPatch().startsWith("pre") || element.getPatch().startsWith("alpha")); + boolean isPre = element.patch != null && (element.patch.startsWith("pre") || element.patch.startsWith("alpha")); - if (StringUtils.isBlank(element.getGameVersion())) + if (StringUtils.isBlank(element.gameVersion)) continue; - String gameVersion = VersionNumber.normalize(fromLookupVersion(element.getGameVersion())); + String gameVersion = VersionNumber.normalize(fromLookupVersion(element.gameVersion)); versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, Collections.singletonList(mirror), isPre)); } } finally { @@ -103,68 +103,19 @@ public final class OptiFineBMCLVersionList extends VersionList