From 82e4e90ae00d9dc6227baceaab1b0dd736ea426a Mon Sep 17 00:00:00 2001 From: 1zuna Date: Tue, 26 Dec 2023 18:20:24 +0100 Subject: [PATCH] release 1.0.8 --- .../liquidbounce/mcef/MCEFDownloader.java | 45 +++++++++++++++---- .../mcef/internal/MCEFDownloadListener.java | 4 ++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/mcef/MCEFDownloader.java b/src/main/java/net/ccbluex/liquidbounce/mcef/MCEFDownloader.java index 2fbc43e4..91251b3d 100644 --- a/src/main/java/net/ccbluex/liquidbounce/mcef/MCEFDownloader.java +++ b/src/main/java/net/ccbluex/liquidbounce/mcef/MCEFDownloader.java @@ -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/.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); @@ -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); @@ -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; diff --git a/src/main/java/net/ccbluex/liquidbounce/mcef/internal/MCEFDownloadListener.java b/src/main/java/net/ccbluex/liquidbounce/mcef/internal/MCEFDownloadListener.java index 2b1ecfce..6241d89e 100644 --- a/src/main/java/net/ccbluex/liquidbounce/mcef/internal/MCEFDownloadListener.java +++ b/src/main/java/net/ccbluex/liquidbounce/mcef/internal/MCEFDownloadListener.java @@ -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(); @@ -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() {