Skip to content

Commit d82971a

Browse files
committed
release: 1.3.5
multiple host support
1 parent 03ed158 commit d82971a

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

src/main/java/net/ccbluex/liquidbounce/mcef/MCEFResourceManager.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ public class MCEFResourceManager {
4747
private static final String JAVA_CEF_CHECKSUM_DOWNLOAD_URL =
4848
"${host}/mcef-cef/${java-cef-commit}/${platform}/checksum";
4949

50-
private final String host;
50+
private final String[] hosts;
5151
private final String javaCefCommitHash;
5252
private final MCEFPlatform platform;
5353
public final MCEFProgressTracker progressTracker = new MCEFProgressTracker();
54+
public int hostCounter = 0;
5455

5556
private final File commitDirectory;
5657
private final File platformDirectory;
5758

58-
private MCEFResourceManager(String host, String javaCefCommitHash, MCEFPlatform platform, File directory) {
59-
this.host = host;
59+
private MCEFResourceManager(String[] hosts, String javaCefCommitHash, MCEFPlatform platform, File directory) {
60+
this.hosts = hosts;
6061
this.javaCefCommitHash = javaCefCommitHash;
6162
this.platform = platform;
6263
this.commitDirectory = new File(directory, javaCefCommitHash);
@@ -75,7 +76,7 @@ static MCEFResourceManager newResourceManager() throws IOException {
7576
MCEF.INSTANCE.getLogger().info("JCEF Commit: " + javaCefCommit);
7677
var settings = MCEF.INSTANCE.getSettings();
7778

78-
return new MCEFResourceManager(settings.getDownloadMirror(), javaCefCommit,
79+
return new MCEFResourceManager(settings.getHosts().toArray(new String[0]), javaCefCommit,
7980
MCEFPlatform.getPlatform(), settings.getLibrariesDirectory());
8081
}
8182

@@ -90,6 +91,11 @@ public boolean requiresDownload() throws IOException {
9091

9192
var checksumFile = new File(commitDirectory, platform.getNormalizedName() + ".tar.gz.sha256");
9293

94+
// If checksum file doesn't exist, we need to download JCEF
95+
if (!checksumFile.exists()) {
96+
return true;
97+
}
98+
9399
// We always download the checksum for the java-cef build
94100
// We will compare this with <platform>.tar.gz.sha256
95101
// If the contents of the files differ (or it doesn't exist locally), we know we need to redownload JCEF
@@ -104,14 +110,14 @@ public boolean requiresDownload() throws IOException {
104110
}
105111
var platformDirectoryExists = platformDirectory.exists();
106112

107-
MCEF.INSTANCE.getLogger().info("Checksum matches: " + checksumMatches);
108-
MCEF.INSTANCE.getLogger().info("Platform directory exists: " + platformDirectoryExists);
113+
MCEF.INSTANCE.getLogger().info("Checksum matches: {}", checksumMatches);
114+
MCEF.INSTANCE.getLogger().info("Platform directory exists: {}", platformDirectoryExists);
109115

110116
return !checksumMatches || !platformDirectoryExists;
111117
}
112118

113119
public void downloadJcef() throws IOException {
114-
var retry = 0;
120+
hostCounter = 0;
115121

116122
while (true) {
117123
try {
@@ -126,19 +132,26 @@ public void downloadJcef() throws IOException {
126132
}
127133
}
128134

129-
// Checksum file should have been created by [compareChecksum] call in [requiresDownload]
130-
// However if not, we either attempt to download it again.
131-
if (!checksumFile.exists()) {
135+
if (checksumFile.exists()) {
132136
try {
133-
downloadFile(getJavaCefChecksumDownloadUrl(), checksumFile, progressTracker);
137+
FileUtils.forceDelete(checksumFile);
134138
} catch (Exception e) {
135-
MCEF.INSTANCE.getLogger().error("Failed to download checksum file", e);
136-
throw e;
139+
MCEF.INSTANCE.getLogger().warn("Failed to delete existing .tar.gz file", e);
137140
}
138141
}
139142

143+
// Download checksum file
144+
MCEF.INSTANCE.getLogger().info("Downloading checksum file... [{}/{}]", hostCounter + 1, hosts.length);
145+
progressTracker.setTask("Downloading Checksum");
146+
try {
147+
downloadFile(getJavaCefChecksumDownloadUrl(), checksumFile, progressTracker);
148+
} catch (Exception e) {
149+
MCEF.INSTANCE.getLogger().error("Failed to download checksum file", e);
150+
throw e;
151+
}
152+
140153
// Download JCEF from file hosting
141-
MCEF.INSTANCE.getLogger().info("Downloading JCEF...");
154+
MCEF.INSTANCE.getLogger().info("Downloading JCEF... [{}/{}]", hostCounter + 1, hosts.length);
142155
progressTracker.setTask("Downloading JCEF");
143156
downloadFile(getJavaCefDownloadUrl(), tarGzArchive, progressTracker);
144157

@@ -173,10 +186,9 @@ public void downloadJcef() throws IOException {
173186
break;
174187
} catch (Exception e) {
175188
MCEF.INSTANCE.getLogger().error("Failed to download and extract JCEF", e);
176-
retry++;
177189

178-
// Retry up to 3 times
179-
if (retry >= 3) {
190+
hostCounter++;
191+
if (hostCounter >= hosts.length) {
180192
throw e;
181193
}
182194
}
@@ -185,8 +197,8 @@ public void downloadJcef() throws IOException {
185197
progressTracker.done();
186198
}
187199

188-
public String getHost() {
189-
return host;
200+
public String[] getHosts() {
201+
return hosts;
190202
}
191203

192204
public String getJavaCefDownloadUrl() {
@@ -199,7 +211,7 @@ public String getJavaCefChecksumDownloadUrl() {
199211

200212
private String formatURL(String url) {
201213
return url
202-
.replace("${host}", host)
214+
.replace("${host}", hosts[hostCounter])
203215
.replace("${java-cef-commit}", javaCefCommitHash)
204216
.replace("${platform}", platform.getNormalizedName());
205217
}

src/main/java/net/ccbluex/liquidbounce/mcef/MCEFSettings.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626

2727
public class MCEFSettings {
2828

29-
private String downloadMirror = "https://api.liquidbounce.net/api/v3/resource";
29+
private List<String> hosts = Arrays.asList(
30+
// Cloudflare Certificate
31+
"https://api.liquidbounce.net/api/v3/resource",
32+
// Let's Encrypt Certificate
33+
"https://api.ccbluex.net/api/v3/resource",
34+
// No SSL
35+
"http://nossl.api.liquidbounce.net/api/v3/resource"
36+
);
3037
private String userAgent = null;
3138
private List<String> cefSwitches = Arrays.asList(
3239
"--autoplay-policy=no-user-gesture-required",
@@ -37,12 +44,20 @@ public class MCEFSettings {
3744
private File cacheDirectory = null;
3845
private File librariesDirectory = null;
3946

40-
public String getDownloadMirror() {
41-
return downloadMirror;
47+
public List<String> getHosts() {
48+
return hosts;
49+
}
50+
51+
public void setHosts(List<String> hosts) {
52+
this.hosts = hosts;
53+
}
54+
55+
public void appendHosts(String... hosts) {
56+
this.hosts.addAll(Arrays.asList(hosts));
4257
}
4358

44-
public void setDownloadMirror(String downloadMirror) {
45-
this.downloadMirror = downloadMirror;
59+
public void removeHosts(String... hosts) {
60+
this.hosts.removeAll(Arrays.asList(hosts));
4661
}
4762

4863
public String getUserAgent() {

0 commit comments

Comments
 (0)