Skip to content

Commit 6931e5b

Browse files
committed
Merge branch 'feature2717/official-optifine-download-channel' of https://github.com/burningtnt/HMCL into prs
2 parents 1d6c0b5 + e8a4780 commit 6931e5b

9 files changed

Lines changed: 108 additions & 64 deletions

File tree

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ download.failed.no_code=Failed to download
342342
download.failed.refresh=Failed to fetch version list. Please click here to retry.
343343
download.game=New Game
344344
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
345-
download.provider.mojang=Official (OptiFine is provided by BMCLAPI)
345+
download.provider.mojang=Official (OptiFine is provided by OF-302)
346346
download.provider.official=From Official Sources
347347
download.provider.balanced=From Fastest Available
348348
download.provider.mirror=From Mirror

HMCL/src/main/resources/assets/lang/I18N_es.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ download.failed.no_code=No se ha podido descargar
343343
download.failed.refresh=No se ha podido obtener la lista de versiones. Por favor, haga clic aquí para volver a intentarlo.
344344
download.game=Nuevo juego
345345
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
346-
download.provider.mojang=Oficial (OptiFine es proporcionado por BMCLAPI)
346+
download.provider.mojang=Oficial (OptiFine es proporcionado por OF-302)
347347
download.provider.official=De fuentes oficiales
348348
download.provider.balanced=De la fuente más rápida disponible
349349
download.provider.mirror=Desde espejo

HMCL/src/main/resources/assets/lang/I18N_ja.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ download.failed.empty=候補者なし。戻るにはここをクリックして
297297
download.failed.refresh=バージョンリストをダウンロードできません。ここをクリックして再試行してください。
298298
download.game=ゲームのダウンロード
299299
download.provider.bmclapi=BMCLAPI(ミラーソース)
300-
download.provider.mojang=Mojang(OptiFineはBMCLAPIにより提供されます) 推奨
300+
download.provider.mojang=Mojang(OptiFineはOF-302により提供されます) 推奨
301301
download.provider.official=公式ソースからロード
302302
download.provider.balanced=mcbbsのソースからロード
303303
download.provider.mirror=ミラーソースからロード

HMCL/src/main/resources/assets/lang/I18N_ru.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ download.failed.no_code=Не удалось скачать
344344
download.failed.refresh=Не удалось получить список версий. Нажмите здесь, чтобы повторить попытку.
345345
download.game=Новая игра
346346
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
347-
download.provider.mojang=Официальный (OptiFine предоставляется BMCLAPI)
347+
download.provider.mojang=Официальный (OptiFine предоставляется OF-302)
348348
download.provider.official=Из официальных источников
349349
download.provider.balanced=Из самых быстрых доступных
350350
download.provider.mirror=Из зеркала

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ download.failed.no_code=下載失敗
344344
download.failed.refresh=載入版本清單失敗,按一下此處重試。
345345
download.game=新遊戲
346346
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com/)
347-
download.provider.mojang=官方伺服器 (OptiFine 由 BMCLAPI 提供)
347+
download.provider.mojang=官方伺服器 (OptiFine 由 OF-302 提供)
348348
download.provider.official=盡量使用官方源 (最新,但可能載入慢)
349349
download.provider.balanced=選取載入速度快的下載源 (平衡,但可能不是最新)
350350
download.provider.mirror=盡量使用鏡像源 (載入快,但可能不是最新)

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ download.failed.no_code=下载失败
352352
download.failed.refresh=[加载版本列表失败,点击此处重试]\n(你可以点击右上角帮助按钮进行求助)
353353
download.game=新游戏
354354
download.provider.bmclapi=BMCLAPI (bangbang93, https://bmclapi2.bangbang93.com)
355-
download.provider.mojang=官方 (OptiFine 自动安装使用 BMCLAPI 下载源)
355+
download.provider.mojang=官方 (OptiFine 自动安装使用 OF-302 下载源)
356356
download.provider.official=尽量使用官方源 (最新,但可能加载慢)
357357
download.provider.balanced=选择加载速度快的下载源 (平衡,但可能不是最新)
358358
download.provider.mirror=尽量使用镜像源 (加载快,但可能不是最新)

HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.jackhuang.hmcl.download.game.GameVersionList;
2424
import org.jackhuang.hmcl.download.liteloader.LiteLoaderVersionList;
2525
import org.jackhuang.hmcl.download.neoforge.NeoForgeOfficialVersionList;
26-
import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList;
26+
import org.jackhuang.hmcl.download.optifine.OptiFine302VersionList;
2727
import org.jackhuang.hmcl.download.quilt.QuiltAPIVersionList;
2828
import org.jackhuang.hmcl.download.quilt.QuiltVersionList;
2929

@@ -38,7 +38,7 @@ public class MojangDownloadProvider implements DownloadProvider {
3838
private final ForgeVersionList forge;
3939
private final NeoForgeOfficialVersionList neoforge;
4040
private final LiteLoaderVersionList liteLoader;
41-
private final OptiFineBMCLVersionList optifine;
41+
private final OptiFine302VersionList optifine;
4242
private final QuiltVersionList quilt;
4343
private final QuiltAPIVersionList quiltApi;
4444

@@ -52,7 +52,7 @@ public MojangDownloadProvider() {
5252
this.forge = new ForgeVersionList(this);
5353
this.neoforge = new NeoForgeOfficialVersionList(this);
5454
this.liteLoader = new LiteLoaderVersionList(this);
55-
this.optifine = new OptiFineBMCLVersionList(apiRoot);
55+
this.optifine = new OptiFine302VersionList("https://hmcl-dev.github.io/metadata/optifine/");
5656
this.quilt = new QuiltVersionList(this);
5757
this.quiltApi = new QuiltAPIVersionList(this);
5858
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Hello Minecraft! Launcher
3+
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package org.jackhuang.hmcl.download.optifine;
19+
20+
import com.google.gson.annotations.SerializedName;
21+
import com.google.gson.reflect.TypeToken;
22+
import org.jackhuang.hmcl.download.VersionList;
23+
import org.jackhuang.hmcl.util.io.HttpRequest;
24+
import org.jackhuang.hmcl.util.versioning.VersionNumber;
25+
26+
import java.util.List;
27+
import java.util.concurrent.CompletableFuture;
28+
import java.util.stream.Collectors;
29+
30+
/**
31+
* @author huangyuhui
32+
*/
33+
public final class OptiFine302VersionList extends VersionList<OptiFineRemoteVersion> {
34+
private final String versionListURL;
35+
36+
public OptiFine302VersionList(String versionListURL) {
37+
this.versionListURL = versionListURL;
38+
}
39+
40+
@Override
41+
public boolean hasType() {
42+
return true;
43+
}
44+
45+
@Override
46+
public CompletableFuture<?> refreshAsync() {
47+
return HttpRequest.GET(versionListURL).getJsonAsync(TypeToken.get(OptiFine302VersionList.VersionList.class)).thenAcceptAsync(root -> {
48+
lock.writeLock().lock();
49+
50+
try {
51+
versions.clear();
52+
for (OptiFineVersion element : root.versions) {
53+
String gameVersion = VersionNumber.normalize(element.gameVersion);
54+
versions.put(gameVersion, new OptiFineRemoteVersion(
55+
gameVersion, element.version,
56+
root.downloadBases.stream().map(u -> u + element.fileName).collect(Collectors.toList()),
57+
element.fileName.startsWith("pre")
58+
));
59+
}
60+
} finally {
61+
lock.writeLock().unlock();
62+
}
63+
});
64+
}
65+
66+
private static final class VersionList {
67+
@SerializedName("file")
68+
private final List<OptiFineVersion> versions;
69+
70+
@SerializedName("download")
71+
private final List<String> downloadBases;
72+
73+
public VersionList(List<OptiFineVersion> versions, List<String> downloadBases) {
74+
this.versions = versions;
75+
this.downloadBases = downloadBases;
76+
}
77+
}
78+
79+
private static final class OptiFineVersion {
80+
@SerializedName("name")
81+
private final String version;
82+
@SerializedName("filename")
83+
private final String fileName;
84+
@SerializedName("mcversion")
85+
private final String gameVersion;
86+
87+
public OptiFineVersion(String version, String fileName, String gameVersion) {
88+
this.version = version;
89+
this.fileName = fileName;
90+
this.gameVersion = gameVersion;
91+
}
92+
}
93+
}

HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ public CompletableFuture<?> refreshAsync() {
7979
versions.clear();
8080
Set<String> duplicates = new HashSet<>();
8181
for (OptiFineVersion element : root) {
82-
String version = element.getType() + "_" + element.getPatch();
83-
String mirror = "https://bmclapi2.bangbang93.com/optifine/" + toLookupVersion(element.getGameVersion()) + "/" + element.getType() + "/" + element.getPatch();
82+
String version = element.type + "_" + element.patch;
83+
String mirror = apiRoot + "/optifine/" + toLookupVersion(element.gameVersion) + "/" + element.type + "/" + element.patch;
8484
if (!duplicates.add(mirror))
8585
continue;
8686

87-
boolean isPre = element.getPatch() != null && (element.getPatch().startsWith("pre") || element.getPatch().startsWith("alpha"));
87+
boolean isPre = element.patch != null && (element.patch.startsWith("pre") || element.patch.startsWith("alpha"));
8888

89-
if (StringUtils.isBlank(element.getGameVersion()))
89+
if (StringUtils.isBlank(element.gameVersion))
9090
continue;
9191

92-
String gameVersion = VersionNumber.normalize(fromLookupVersion(element.getGameVersion()));
92+
String gameVersion = VersionNumber.normalize(fromLookupVersion(element.gameVersion));
9393
versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, Collections.singletonList(mirror), isPre));
9494
}
9595
} finally {
@@ -102,68 +102,19 @@ public CompletableFuture<?> refreshAsync() {
102102
* @author huangyuhui
103103
*/
104104
private static final class OptiFineVersion {
105-
106-
@SerializedName("dl")
107-
private final String downloadLink;
108-
109-
@SerializedName("ver")
110-
private final String version;
111-
112-
@SerializedName("date")
113-
private final String date;
114-
115105
@SerializedName("type")
116106
private final String type;
117107

118108
@SerializedName("patch")
119109
private final String patch;
120110

121-
@SerializedName("mirror")
122-
private final String mirror;
123-
124111
@SerializedName("mcversion")
125112
private final String gameVersion;
126113

127-
public OptiFineVersion() {
128-
this(null, null, null, null, null, null, null);
129-
}
130-
131-
public OptiFineVersion(String downloadLink, String version, String date, String type, String patch, String mirror, String gameVersion) {
132-
this.downloadLink = downloadLink;
133-
this.version = version;
134-
this.date = date;
114+
public OptiFineVersion(String type, String patch, String gameVersion) {
135115
this.type = type;
136116
this.patch = patch;
137-
this.mirror = mirror;
138117
this.gameVersion = gameVersion;
139118
}
140-
141-
public String getDownloadLink() {
142-
return downloadLink;
143-
}
144-
145-
public String getVersion() {
146-
return version;
147-
}
148-
149-
public String getDate() {
150-
return date;
151-
}
152-
153-
public String getType() {
154-
return type;
155-
}
156-
157-
public String getPatch() {
158-
return patch;
159-
}
160-
161-
public String getMirror() {
162-
return mirror;
163-
}
164-
165-
public String getGameVersion() {
166-
return gameVersion;
167-
}
168119
}
169120
}

0 commit comments

Comments
 (0)