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

Support downloading OptiFine from it's own maven. #2719

Open
wants to merge 9 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
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ download.failed.no_code=Failed to download %s
download.failed.refresh=Unable to fetch version list. Please click here to retry.
download.game=Game
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
download.provider.mojang=Mojang (OptiFine is provided by BMCLAPI)
download.provider.mojang=Mojang (OptiFine is provided by OF-302)
download.provider.official=From Official Sources
download.provider.balanced=From Fastest Available
download.provider.mirror=From Mirror
Expand Down
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ download.failed.empty=No hay versiones disponibles, por favor haga clic aquí pa
download.failed.refresh=No se ha podido obtener la lista de versiones. Por favor, haga clic aquí para volver a intentarlo.
download.game=Juego
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
download.provider.mojang=Mojang (OptiFine es proporcionado por BMCLAPI)
download.provider.mojang=Mojang (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
Expand Down
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,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=ミラーソースからロード
Expand Down
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ download.failed.empty=Версий нет. Нажмите здесь, чтобы
download.failed.refresh=Не удаётся получить список версий. Нажмите здесь, чтобы повторить попытку.
download.game=Игра
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
download.provider.mojang=Mojang (OptiFine is provided by BMCLAPI)
download.provider.mojang=Mojang (OptiFine is provided by OF-302)
download.provider.official=Из официальных источников
download.provider.balanced=Из самых быстрых доступных
download.provider.mirror=Из зеркала
Expand Down
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ download.failed.no_code=下載失敗: %s
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=儘量使用鏡像源(加載快,但可能不是最新)
Expand Down
2 changes: 1 addition & 1 deletion HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ download.failed.no_code=下载失败: %s
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=尽量使用镜像源(加载快,但可能不是最新)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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;

Expand All @@ -38,7 +38,7 @@ public class MojangDownloadProvider implements DownloadProvider {
private final ForgeBMCLVersionList 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;

Expand All @@ -52,7 +52,7 @@ public MojangDownloadProvider() {
this.forge = new ForgeBMCLVersionList(apiRoot);
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <[email protected]> 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 <https://www.gnu.org/licenses/>.
*/
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<OptiFineRemoteVersion> {
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).<OptiFine302VersionList.VersionList>getJsonAsync(new TypeToken<OptiFine302VersionList.VersionList>() {
}.getType()).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<OptiFineVersion> versions;

@SerializedName("download")
private final List<String> downloadBases;

public VersionList(List<OptiFineVersion> versions, List<String> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ public CompletableFuture<?> refreshAsync() {
versions.clear();
Set<String> 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 {
Expand All @@ -103,68 +103,19 @@ public CompletableFuture<?> refreshAsync() {
* @author huangyuhui
*/
private static final class OptiFineVersion {

@SerializedName("dl")
private final String downloadLink;

@SerializedName("ver")
private final String version;

@SerializedName("date")
private final String date;

@SerializedName("type")
private final String type;

@SerializedName("patch")
private final String patch;

@SerializedName("mirror")
private final String mirror;

@SerializedName("mcversion")
private final String gameVersion;

public OptiFineVersion() {
this(null, null, null, null, null, null, null);
}

public OptiFineVersion(String downloadLink, String version, String date, String type, String patch, String mirror, String gameVersion) {
this.downloadLink = downloadLink;
this.version = version;
this.date = date;
public OptiFineVersion(String type, String patch, String gameVersion) {
this.type = type;
this.patch = patch;
this.mirror = mirror;
this.gameVersion = gameVersion;
}

public String getDownloadLink() {
return downloadLink;
}

public String getVersion() {
return version;
}

public String getDate() {
return date;
}

public String getType() {
return type;
}

public String getPatch() {
return patch;
}

public String getMirror() {
return mirror;
}

public String getGameVersion() {
return gameVersion;
}
}
}