From e2d3ac847dc100b7371264301d304c285cbe7cd2 Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 8 Sep 2026 12:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=20zip=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E5=BF=BD=E7=95=A5=20local=20file=20header=20(#6834)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/util/io/CompressingUtils.java | 21 +++---------------- .../hmcl/util/tree/ArchiveFileTree.java | 4 ++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java index b90ca929f5..4686ca2f5a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/CompressingUtils.java @@ -19,16 +19,13 @@ package org.jackhuang.hmcl.util.io; import kala.compress.archivers.zip.ZipArchiveEntry; import kala.compress.archivers.zip.ZipArchiveReader; -import kala.compress.utils.BufferedDataInputSeekableChannel; import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.platform.OperatingSystem; import org.jackhuang.hmcl.util.tree.ZipFileTree; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.CharBuffer; -import java.nio.channels.SeekableByteChannel; import java.nio.charset.*; import java.nio.file.*; import java.nio.file.spi.FileSystemProvider; @@ -131,18 +128,6 @@ public final class CompressingUtils { throw new IOException("Cannot find suitable encoding for the zip."); } - private static BufferedDataInputSeekableChannel openBufferedChannel(Path zipFile) throws IOException { - SeekableByteChannel channel = Files.newByteChannel(zipFile); - - try { - return new BufferedDataInputSeekableChannel(channel, 8192, ByteOrder.LITTLE_ENDIAN); - } catch (Throwable e) { - IOUtils.closeQuietly(channel, e); - throw e; - } - - } - public static ZipFileTree openZipTree(Path zipFile) throws IOException { return new ZipFileTree(openZipFile(zipFile)); } @@ -152,14 +137,14 @@ public final class CompressingUtils { } public static ZipArchiveReader openZipFile(Path zipFile, Charset charset) throws IOException { - return new ZipArchiveReader(openBufferedChannel(zipFile), charset); + return new ZipArchiveReader(zipFile, charset, true, true); } public static ZipArchiveReader openZipFileWithPossibleEncoding(Path zipFile, Charset possibleEncoding) throws IOException { if (possibleEncoding == null) possibleEncoding = StandardCharsets.UTF_8; - ZipArchiveReader zipReader = new ZipArchiveReader(openBufferedChannel(zipFile)); + ZipArchiveReader zipReader = new ZipArchiveReader(zipFile, possibleEncoding, true, true); Charset suitableEncoding; try { @@ -176,7 +161,7 @@ public final class CompressingUtils { } zipReader.close(); - return new ZipArchiveReader(openBufferedChannel(zipFile), suitableEncoding); + return new ZipArchiveReader(zipFile, suitableEncoding, true, true); } public static final class Builder { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ArchiveFileTree.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ArchiveFileTree.java index 57db1c5e6a..23cffa83f4 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ArchiveFileTree.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ArchiveFileTree.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.util.tree; import kala.compress.archivers.ArchiveEntry; -import kala.compress.archivers.zip.ZipArchiveReader; +import org.jackhuang.hmcl.util.io.CompressingUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.UnmodifiableView; @@ -44,7 +44,7 @@ public abstract class ArchiveFileTree implements Clos String name = namePath.toString(); if (name.endsWith(".jar") || name.endsWith(".zip")) { - return new ZipFileTree(new ZipArchiveReader(file)); + return CompressingUtils.openZipTree(file); } else if (name.endsWith(".tar") || name.endsWith(".tar.gz") || name.endsWith(".tgz")) { return TarFileTree.open(file); } else {