diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java index b077df86c..58219ca05 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/LibraryDownloadTask.java @@ -142,14 +142,6 @@ public class LibraryDownloadTask extends Task { library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null) .setCacheRepository(cacheRepository) .setCaching(true); - task.addIntegrityCheckHandler((file, dest) -> { - String ext = FileUtils.getExtension(dest).toLowerCase(); - if (ext.equals("jar")) { - try (JarFile jarFile = new JarFile(file.toFile())) { - jarFile.getManifest(); - } - } - }); xz = false; } } catch (IOException e) { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java index 4dc73bb3e..7952e6d38 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java @@ -31,6 +31,7 @@ import java.io.RandomAccessFile; import java.math.BigInteger; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.security.MessageDigest; @@ -155,6 +156,8 @@ public class FileDownloadTask extends Task { this.integrityCheck = integrityCheck; this.retry = retry; + this.addIntegrityCheckHandler(ZIP_INTEGRITY_CHECK_HANDLER); + setName(file.getName()); setExecutor(Schedulers.io()); } @@ -254,6 +257,8 @@ public class FileDownloadTask extends Task { repeat--; continue; } + } else if (con.getResponseCode() / 100 == 4) { + } else if (con.getResponseCode() / 100 != 2) { throw new ResponseCodeException(url, con.getResponseCode()); } @@ -405,4 +410,13 @@ public class FileDownloadTask extends Task { */ void checkIntegrity(Path filePath, Path destinationPath) throws IOException; } + + public static final IntegrityCheckHandler ZIP_INTEGRITY_CHECK_HANDLER = (filePath, destinationPath) -> { + String ext = FileUtils.getExtension(destinationPath).toLowerCase(); + if (ext.equals("zip") || ext.equals("jar")) { + try (FileSystem ignored = CompressingUtils.createReadOnlyZipFileSystem(filePath)) { + // test for zip format + } + } + }; }