Skip to content

Commit

Permalink
release 1.1.3
Browse files Browse the repository at this point in the history
- improved extraction
- fixed mouse handling
  • Loading branch information
1zun4 committed Mar 5, 2024
1 parent f85d573 commit 8e68642
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
11 changes: 4 additions & 7 deletions src/main/java/net/ccbluex/liquidbounce/mcef/MCEFBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.ccbluex.liquidbounce.mcef.listeners.MCEFCursorChangeListener;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefBrowserOsr;
import org.cef.callback.CefDragData;
Expand Down Expand Up @@ -436,11 +435,9 @@ public boolean onCursorChange(CefBrowser browser, int cursorType) {
public void setCursor(CefCursorType cursorType) {
var windowHandle = mc.getWindow().getHandle();

if (cursorType == CefCursorType.NONE || mc.mouse.isCursorLocked()) {
GLFW.glfwSetInputMode(windowHandle, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
} else {
GLFW.glfwSetInputMode(windowHandle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
GLFW.glfwSetCursor(windowHandle, MCEF.getGLFWCursorHandle(cursorType));
}
// We do not want to change the cursor state since Minecraft does this for us.
if (cursorType == CefCursorType.NONE) return;

GLFW.glfwSetCursor(windowHandle, MCEF.getGLFWCursorHandle(cursorType));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private boolean compareChecksum(File checksumFile) throws IOException {
return false;
}

private void extractJavaCefBuild(File mcefLibrariesPath) {
private void extractJavaCefBuild(File mcefLibrariesPath) throws IOException {
var tarGzArchive = new File(mcefLibrariesPath, platform.getNormalizedName() + ".tar.gz");

extractTarGz(tarGzArchive, mcefLibrariesPath, percentCompleteConsumer);
Expand All @@ -183,7 +183,7 @@ private void extractJavaCefBuild(File mcefLibrariesPath) {
}

private static void downloadFile(String urlString, File outputFile, MCEFDownloadListener percentCompleteConsumer) throws IOException {
MCEF.getLogger().info(urlString + " -> " + outputFile.getCanonicalPath());
MCEF.getLogger().debug("Downloading '" + urlString + "' to '" + outputFile.getCanonicalPath() + "'");

URL url = new URL(urlString);
URLConnection urlConnection = url.openConnection();
Expand All @@ -207,39 +207,36 @@ private static void downloadFile(String urlString, File outputFile, MCEFDownload
outputStream.close();
}

private static void extractTarGz(File tarGzFile, File outputDirectory, MCEFDownloadListener percentCompleteConsumer) {
private static void extractTarGz(File tarGzFile, File outputDirectory, MCEFDownloadListener percentCompleteConsumer)
throws IOException {
percentCompleteConsumer.setTask("Extracting");
outputDirectory.mkdirs();

long fileSize = tarGzFile.length();
long totalBytesRead = 0;

try (TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(tarGzFile)))) {
long totalBytesRead = 0;
long fileSizeEstimate = tarGzFile.length(); // Initial estimate for progress

TarArchiveEntry entry;
while ((entry = tarInput.getNextTarEntry()) != null) {
if (entry.isDirectory()) {
continue;
}

File outputFile = new File(outputDirectory, entry.getName());
outputFile.getParentFile().mkdirs();

try (OutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = tarInput.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
float percentComplete = (((float) totalBytesRead / fileSize) / 2.6158204f); // Roughly the compression ratio
percentCompleteConsumer.setProgress(percentComplete);
buffer = new byte[Math.max(4096, tarInput.available())];
if (!entry.isDirectory()) {
File outputFile = new File(outputDirectory, entry.getName());
outputFile.getParentFile().mkdirs();

try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
byte[] buffer = new byte[8192]; // Adjust buffer size for optimal I/O
int bytesRead;
while ((bytesRead = tarInput.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
float percentComplete = (float) totalBytesRead / fileSizeEstimate;
percentCompleteConsumer.setProgress(percentComplete);
}
}
}
}
} catch (IOException e) {
throw new RuntimeException("Failed to extract tar.gz", e);
} finally {
percentCompleteConsumer.setProgress(1.0f); // Ensure completion regardless of exceptions
}

percentCompleteConsumer.setProgress(1.0f);
}

}

0 comments on commit 8e68642

Please sign in to comment.