diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLModpackProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLModpackProvider.java index c95192f3db..f8c55f6708 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLModpackProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLModpackProvider.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.game; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.mod.MismatchedModpackTypeException; import org.jackhuang.hmcl.mod.Modpack; @@ -64,7 +64,7 @@ public Task createUpdateTask(DefaultDependencyManager dependencyManager, Stri } @Override - public Modpack readManifest(ZipFile file, Path path, Charset encoding) throws IOException, JsonParseException { + public Modpack readManifest(ZipArchiveReader file, Path path, Charset encoding) throws IOException, JsonParseException { String manifestJson = CompressingUtils.readTextZipEntry(file, "modpack.json"); Modpack manifest = JsonUtils.fromNonNullJson(manifestJson, HMCLModpack.class).setEncoding(encoding); String gameJson = CompressingUtils.readTextZipEntry(file, "minecraft/pack.json"); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java index 78b96db501..19349c445b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.game; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.mod.*; import org.jackhuang.hmcl.mod.curse.CurseModpackProvider; import org.jackhuang.hmcl.mod.mcbbs.McbbsModpackManifest; @@ -83,7 +83,7 @@ public static boolean isFileModpackByExtension(File file) { } public static Modpack readModpackManifest(Path file, Charset charset) throws UnsupportedModpackException, ManuallyCreatedModpackException { - try (ZipFile zipFile = CompressingUtils.openZipFile(file, charset)) { + try (ZipArchiveReader zipFile = CompressingUtils.openZipFile(file, charset)) { // Order for trying detecting manifest is necessary here. // Do not change to iterating providers. for (ModpackProvider provider : new ModpackProvider[]{ diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInstallTask.java b/HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInstallTask.java index b26c674d5c..f1ca54a914 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInstallTask.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInstallTask.java @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.java; -import org.apache.commons.compress.archivers.ArchiveEntry; +import kala.compress.archivers.ArchiveEntry; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.util.DigestUtils; import org.jackhuang.hmcl.util.Hex; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java index 02dbbb844a..d2c5373445 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java @@ -5,7 +5,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import org.apache.commons.compress.utils.BoundedInputStream; +import kala.compress.utils.BoundedInputStream; import org.jackhuang.hmcl.util.io.FileUtils; import java.io.*; diff --git a/HMCLCore/build.gradle.kts b/HMCLCore/build.gradle.kts index c25db1c3ee..b1eb5de3de 100644 --- a/HMCLCore/build.gradle.kts +++ b/HMCLCore/build.gradle.kts @@ -3,6 +3,10 @@ plugins { } dependencies { + val kalaCompressVersion = "1.27.1-1" + + api("org.glavo.kala:kala-compress-archivers-zip:$kalaCompressVersion") + api("org.glavo.kala:kala-compress-archivers-tar:$kalaCompressVersion") api("org.glavo:simple-png-javafx:0.3.0") api("com.google.code.gson:gson:2.11.0") api("com.moandjiezana.toml:toml4j:0.7.2") @@ -11,7 +15,6 @@ dependencies { api("org.jenkins-ci:constant-pool-scanner:1.2") api("com.github.steveice10:opennbt:1.5") api("org.nanohttpd:nanohttpd:2.3.1") - api("org.apache.commons:commons-compress:1.25.0") api("org.jsoup:jsoup:1.18.1") compileOnlyApi("org.jetbrains:annotations:24.1.0") diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaInfo.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaInfo.java index d23f5a46a9..89f1863261 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaInfo.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaInfo.java @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.java; -import org.apache.commons.compress.archivers.ArchiveEntry; +import kala.compress.archivers.ArchiveEntry; import org.jackhuang.hmcl.util.KeyValuePairProperties; import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.platform.Architecture; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModpackProvider.java index 5b340edf97..cd76718bba 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModpackProvider.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.mod; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.game.LaunchOptions; import org.jackhuang.hmcl.task.Task; @@ -44,7 +44,7 @@ public interface ModpackProvider { * @throws JsonParseException if the manifest.json is missing or malformed. * @return the manifest. */ - Modpack readManifest(ZipFile zipFile, Path file, Charset encoding) throws IOException, JsonParseException; + Modpack readManifest(ZipArchiveReader zipFile, Path file, Charset encoding) throws IOException, JsonParseException; default void injectLaunchOptions(String modpackConfigurationJson, LaunchOptions.Builder builder) { } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseModpackProvider.java index 3893856e6c..e0a354ab42 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseModpackProvider.java @@ -18,8 +18,8 @@ package org.jackhuang.hmcl.mod.curse; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.mod.MismatchedModpackTypeException; import org.jackhuang.hmcl.mod.Modpack; @@ -57,7 +57,7 @@ public Task createUpdateTask(DefaultDependencyManager dependencyManager, Stri } @Override - public Modpack readManifest(ZipFile zip, Path file, Charset encoding) throws IOException, JsonParseException { + public Modpack readManifest(ZipArchiveReader zip, Path file, Charset encoding) throws IOException, JsonParseException { CurseManifest manifest = JsonUtils.fromNonNullJson(CompressingUtils.readTextZipEntry(zip, "manifest.json"), CurseManifest.class); String description = "No description"; try { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/mcbbs/McbbsModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/mcbbs/McbbsModpackProvider.java index 6a7ab07281..cfc6216546 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/mcbbs/McbbsModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/mcbbs/McbbsModpackProvider.java @@ -18,8 +18,8 @@ package org.jackhuang.hmcl.mod.mcbbs; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.game.LaunchOptions; import org.jackhuang.hmcl.mod.*; @@ -70,7 +70,7 @@ private static Modpack fromManifestFile(InputStream json, Charset encoding) thro } @Override - public Modpack readManifest(ZipFile zip, Path file, Charset encoding) throws IOException, JsonParseException { + public Modpack readManifest(ZipArchiveReader zip, Path file, Charset encoding) throws IOException, JsonParseException { ZipArchiveEntry mcbbsPackMeta = zip.getEntry("mcbbs.packmeta"); if (mcbbsPackMeta != null) { return fromManifestFile(zip.getInputStream(mcbbsPackMeta), encoding); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackProvider.java index 30b33559e6..a14bac5266 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthModpackProvider.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.mod.modrinth; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.mod.MismatchedModpackTypeException; import org.jackhuang.hmcl.mod.Modpack; @@ -55,7 +55,7 @@ public Task createUpdateTask(DefaultDependencyManager dependencyManager, Stri } @Override - public Modpack readManifest(ZipFile zip, Path file, Charset encoding) throws IOException, JsonParseException { + public Modpack readManifest(ZipArchiveReader zip, Path file, Charset encoding) throws IOException, JsonParseException { ModrinthManifest manifest = JsonUtils.fromNonNullJson(CompressingUtils.readTextZipEntry(zip, "modrinth.index.json"), ModrinthManifest.class); return new Modpack(manifest.getName(), "", manifest.getVersionId(), manifest.getGameVersion(), manifest.getSummary(), encoding, manifest) { @Override diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCManifest.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCManifest.java index 7773d8fa4b..3fecb7ebde 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCManifest.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCManifest.java @@ -18,8 +18,8 @@ package org.jackhuang.hmcl.mod.multimc; import com.google.gson.annotations.SerializedName; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.util.Immutable; import org.jackhuang.hmcl.util.gson.JsonUtils; @@ -55,7 +55,7 @@ public List getComponents() { * @throws IOException if zip file is malformed * @throws com.google.gson.JsonParseException if manifest is malformed. */ - public static MultiMCManifest readMultiMCModpackManifest(ZipFile zipFile, String rootEntryName) throws IOException { + public static MultiMCManifest readMultiMCModpackManifest(ZipArchiveReader zipFile, String rootEntryName) throws IOException { ZipArchiveEntry mmcPack = zipFile.getEntry(rootEntryName + "mmc-pack.json"); if (mmcPack == null) return null; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackProvider.java index a66716c03b..6e4b22c481 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/multimc/MultiMCModpackProvider.java @@ -17,8 +17,8 @@ */ package org.jackhuang.hmcl.mod.multimc; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.mod.MismatchedModpackTypeException; import org.jackhuang.hmcl.mod.Modpack; @@ -33,7 +33,6 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Enumeration; import java.util.stream.Stream; public final class MultiMCModpackProvider implements ModpackProvider { @@ -71,14 +70,12 @@ public static Path getRootPath(Path root) throws IOException { } } - private static String getRootEntryName(ZipFile file) throws IOException { + private static String getRootEntryName(ZipArchiveReader file) throws IOException { final String instanceFileName = "instance.cfg"; if (file.getEntry(instanceFileName) != null) return ""; - Enumeration entries = file.getEntries(); - while (entries.hasMoreElements()) { - ZipArchiveEntry entry = entries.nextElement(); + for (ZipArchiveEntry entry : file.getEntries()) { String entryName = entry.getName(); int idx = entryName.indexOf('/'); @@ -92,7 +89,7 @@ private static String getRootEntryName(ZipFile file) throws IOException { } @Override - public Modpack readManifest(ZipFile modpackFile, Path modpackPath, Charset encoding) throws IOException { + public Modpack readManifest(ZipArchiveReader modpackFile, Path modpackPath, Charset encoding) throws IOException { String rootEntryName = getRootEntryName(modpackFile); MultiMCManifest manifest = MultiMCManifest.readMultiMCModpackManifest(modpackFile, rootEntryName); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/server/ServerModpackProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/server/ServerModpackProvider.java index 4c4c28d0a0..2e16faa8f5 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/server/ServerModpackProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/server/ServerModpackProvider.java @@ -18,7 +18,7 @@ package org.jackhuang.hmcl.mod.server; import com.google.gson.JsonParseException; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.download.DefaultDependencyManager; import org.jackhuang.hmcl.mod.MismatchedModpackTypeException; import org.jackhuang.hmcl.mod.Modpack; @@ -55,7 +55,7 @@ public Task createUpdateTask(DefaultDependencyManager dependencyManager, Stri } @Override - public Modpack readManifest(ZipFile zip, Path file, Charset encoding) throws IOException, JsonParseException { + public Modpack readManifest(ZipArchiveReader zip, Path file, Charset encoding) throws IOException, JsonParseException { String json = CompressingUtils.readTextZipEntry(zip, "server-manifest.json"); ServerModpackManifest manifest = JsonUtils.fromNonNullJson(json, ServerModpackManifest.class); return manifest.toModpack(encoding); 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 a104441d1c..00f61ac71b 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 @@ -17,8 +17,8 @@ */ package org.jackhuang.hmcl.util.io; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import org.jackhuang.hmcl.util.Lang; import org.jackhuang.hmcl.util.platform.OperatingSystem; @@ -54,19 +54,16 @@ private static CharsetDecoder newCharsetDecoder(Charset charset) { } public static boolean testEncoding(Path zipFile, Charset encoding) throws IOException { - try (ZipFile zf = openZipFile(zipFile, encoding)) { + try (ZipArchiveReader zf = openZipFile(zipFile, encoding)) { return testEncoding(zf, encoding); } } - public static boolean testEncoding(ZipFile zipFile, Charset encoding) throws IOException { - Enumeration entries = zipFile.getEntries(); + public static boolean testEncoding(ZipArchiveReader zipFile, Charset encoding) throws IOException { CharsetDecoder cd = newCharsetDecoder(encoding); CharBuffer cb = CharBuffer.allocate(32); - while (entries.hasMoreElements()) { - ZipArchiveEntry entry = entries.nextElement(); - + for (ZipArchiveEntry entry : zipFile.getEntries()) { if (entry.getGeneralPurposeBit().usesUTF8ForNames()) continue; cd.reset(); @@ -88,12 +85,12 @@ public static boolean testEncoding(ZipFile zipFile, Charset encoding) throws IOE } public static Charset findSuitableEncoding(Path zipFile) throws IOException { - try (ZipFile zf = openZipFile(zipFile, StandardCharsets.UTF_8)) { + try (ZipArchiveReader zf = openZipFile(zipFile, StandardCharsets.UTF_8)) { return findSuitableEncoding(zf); } } - public static Charset findSuitableEncoding(ZipFile zipFile) throws IOException { + public static Charset findSuitableEncoding(ZipArchiveReader zipFile) throws IOException { if (testEncoding(zipFile, StandardCharsets.UTF_8)) return StandardCharsets.UTF_8; if (OperatingSystem.NATIVE_CHARSET != StandardCharsets.UTF_8 && testEncoding(zipFile, OperatingSystem.NATIVE_CHARSET)) return OperatingSystem.NATIVE_CHARSET; @@ -133,12 +130,12 @@ public static Charset findSuitableEncoding(ZipFile zipFile) throws IOException { throw new IOException("Cannot find suitable encoding for the zip."); } - public static ZipFile openZipFile(Path zipFile) throws IOException { - return new ZipFile(Files.newByteChannel(zipFile)); + public static ZipArchiveReader openZipFile(Path zipFile) throws IOException { + return new ZipArchiveReader(Files.newByteChannel(zipFile)); } - public static ZipFile openZipFile(Path zipFile, Charset charset) throws IOException { - return new ZipFile(Files.newByteChannel(zipFile), charset.name()); + public static ZipArchiveReader openZipFile(Path zipFile, Charset charset) throws IOException { + return new ZipArchiveReader(zipFile, charset); } public static final class Builder { @@ -234,7 +231,7 @@ public static FileSystem createZipFileSystem(Path zipFile, boolean create, boole * @return the plain text content of given file. */ public static String readTextZipEntry(File zipFile, String name) throws IOException { - try (ZipFile s = new ZipFile(zipFile)) { + try (ZipArchiveReader s = new ZipArchiveReader(zipFile.toPath())) { return readTextZipEntry(s, name); } } @@ -247,7 +244,7 @@ public static String readTextZipEntry(File zipFile, String name) throws IOExcept * @throws IOException if the file is not a valid zip file. * @return the plain text content of given file. */ - public static String readTextZipEntry(ZipFile zipFile, String name) throws IOException { + public static String readTextZipEntry(ZipArchiveReader zipFile, String name) throws IOException { return IOUtils.readFullyAsString(zipFile.getInputStream(zipFile.getEntry(name))); } @@ -260,7 +257,7 @@ public static String readTextZipEntry(ZipFile zipFile, String name) throws IOExc * @return the plain text content of given file. */ public static String readTextZipEntry(Path zipFile, String name, Charset encoding) throws IOException { - try (ZipFile s = openZipFile(zipFile, encoding)) { + try (ZipArchiveReader s = openZipFile(zipFile, encoding)) { return IOUtils.readFullyAsString(s.getInputStream(s.getEntry(name))); } } 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 ff744e79fd..33a674c3f8 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 @@ -17,8 +17,8 @@ */ package org.jackhuang.hmcl.util.tree; -import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.ArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import java.io.Closeable; import java.io.IOException; @@ -39,7 +39,7 @@ public abstract class ArchiveFileTree implements Clos String name = namePath.toString(); if (name.endsWith(".jar") || name.endsWith(".zip")) { - return new ZipFileTree(new ZipFile(file)); + return new ZipFileTree(new ZipArchiveReader(file)); } else if (name.endsWith(".tar") || name.endsWith(".tar.gz") || name.endsWith(".tgz")) { return TarFileTree.open(file); } else { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/TarFileTree.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/TarFileTree.java index bffa40eefa..152869cb6a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/TarFileTree.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/TarFileTree.java @@ -18,8 +18,8 @@ package org.jackhuang.hmcl.util.tree; -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarFile; +import kala.compress.archivers.tar.TarArchiveEntry; +import kala.compress.archivers.tar.TarArchiveReader; import org.jackhuang.hmcl.util.io.IOUtils; import java.io.*; @@ -31,19 +31,19 @@ /** * @author Glavo */ -public final class TarFileTree extends ArchiveFileTree { +public final class TarFileTree extends ArchiveFileTree { public static TarFileTree open(Path file) throws IOException { String fileName = file.getFileName().toString(); if (fileName.endsWith(".tar.gz") || fileName.endsWith(".tgz")) { Path tempFile = Files.createTempFile("hmcl-", ".tar"); - TarFile tarFile; + TarArchiveReader tarFile; try (GZIPInputStream input = new GZIPInputStream(Files.newInputStream(file)); OutputStream output = Files.newOutputStream(tempFile, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) ) { IOUtils.copyTo(input, output); - tarFile = new TarFile(tempFile.toFile()); + tarFile = new TarArchiveReader(tempFile); } catch (Throwable e) { try { Files.deleteIfExists(tempFile); @@ -55,14 +55,14 @@ public static TarFileTree open(Path file) throws IOException { return new TarFileTree(tarFile, tempFile); } else { - return new TarFileTree(new TarFile(file), null); + return new TarFileTree(new TarArchiveReader(file), null); } } private final Path tempFile; private final Thread shutdownHook; - public TarFileTree(TarFile file, Path tempFile) throws IOException { + public TarFileTree(TarArchiveReader file, Path tempFile) throws IOException { super(file); this.tempFile = tempFile; try { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ZipFileTree.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ZipFileTree.java index 70e2d3a826..ba81883622 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ZipFileTree.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/tree/ZipFileTree.java @@ -17,23 +17,21 @@ */ package org.jackhuang.hmcl.util.tree; -import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; -import org.apache.commons.compress.archivers.zip.ZipFile; +import kala.compress.archivers.zip.ZipArchiveEntry; +import kala.compress.archivers.zip.ZipArchiveReader; import java.io.IOException; import java.io.InputStream; -import java.util.Enumeration; /** * @author Glavo */ -public final class ZipFileTree extends ArchiveFileTree { - public ZipFileTree(ZipFile file) throws IOException { +public final class ZipFileTree extends ArchiveFileTree { + public ZipFileTree(ZipArchiveReader file) throws IOException { super(file); try { - Enumeration entries = file.getEntries(); - while (entries.hasMoreElements()) { - addEntry(entries.nextElement()); + for (ZipArchiveEntry zipArchiveEntry : file.getEntries()) { + addEntry(zipArchiveEntry); } } catch (Throwable e) { try {