Skip to content

Commit

Permalink
release 1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Dec 26, 2023
1 parent 2d03169 commit 82e4e90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/main/java/net/ccbluex/liquidbounce/mcef/MCEFDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,47 @@ public static MCEFDownloader newDownloader() throws IOException {

public void downloadJcef(final File directory) throws IOException {
var platformDirectory = new File(directory, MCEFPlatform.getPlatform().getNormalizedName());
var checksumFile = new File(directory, platform.getNormalizedName() + ".tar.gz.sha256.temp");
var checksumFile = new File(directory, platform.getNormalizedName() + ".tar.gz.sha256");

setupLibraryPath(directory, platformDirectory);

// We always download the checksum for the java-cef build
// We will compare this with mcef-libraries/<platform>.tar.gz.sha256
// If the contents of the files differ (or it doesn't exist locally), we know we need to redownload JCEF
var checksumMatches = compareChecksum(checksumFile);
boolean checksumMatches;
try {
checksumMatches = compareChecksum(checksumFile);
} catch (IOException e) {
MCEF.getLogger().error("Failed to compare checksum", e);

if (!checksumMatches || !platformDirectory.exists()) {
downloadJavaCefBuild(directory);
extractJavaCefBuild(directory);
// Assume checksum matches if we can't compare
checksumMatches = true;
}
var platformDirectoryExists = platformDirectory.exists();

MCEF.getLogger().info("Checksum matches: " + checksumMatches);
MCEF.getLogger().info("Platform directory exists: " + platformDirectoryExists);

if (!checksumMatches || !platformDirectoryExists) {
try {
MCEF.getLogger().info("Downloading JCEF...");
downloadJavaCefBuild(directory);

if (platformDirectoryExists && platformDirectory.delete()) {
MCEF.getLogger().info("Platform directory already present, deleting due to checksum mismatch");
}

MCEF.getLogger().info("Extracting JCEF...");
extractJavaCefBuild(directory);


} catch (Exception e) {
if (directory.exists() && directory.delete()) {
MCEF.getLogger().info("Failed to download JCEF, deleting directory due to exception");
}

throw new RuntimeException("Failed to download JCEF", e);
}
}

MCEFDownloadListener.INSTANCE.setDone(true);
Expand Down Expand Up @@ -114,8 +143,8 @@ private void downloadJavaCefBuild(File mcefLibrariesPath) throws IOException {
percentCompleteConsumer.setTask("Downloading JCEF");
var tarGzArchive = new File(mcefLibrariesPath, platform.getNormalizedName() + ".tar.gz");

if (tarGzArchive.exists()) {
tarGzArchive.delete();
if (tarGzArchive.exists() && tarGzArchive.delete()) {
MCEF.getLogger().info(".tar.gz archive already present, deleting due to checksum mismatch");
}

downloadFile(getJavaCefDownloadUrl(), tarGzArchive, percentCompleteConsumer);
Expand All @@ -135,7 +164,7 @@ private boolean compareChecksum(File checksumFile) throws IOException {

if (checksumFile.exists()) {
boolean sameContent = FileUtils.contentEquals(checksumFile, tempChecksumFile);
MCEF.getLogger().info("Checksums match: " + sameContent);

if (sameContent) {
tempChecksumFile.delete();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package net.ccbluex.liquidbounce.mcef.internal;

import net.ccbluex.liquidbounce.mcef.MCEF;

public class MCEFDownloadListener {

public static final MCEFDownloadListener INSTANCE = new MCEFDownloadListener();
Expand All @@ -31,6 +33,8 @@ public class MCEFDownloadListener {
public void setTask(String name) {
this.task = name;
this.percent = 0;

MCEF.getLogger().info("Task: " + name + " with progress " + (percent * 100) + " %");
}

public String getTask() {
Expand Down

0 comments on commit 82e4e90

Please sign in to comment.