mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
fix: not checking corruption of forge installer
This commit is contained in:
parent
3c716ea170
commit
6ca7a86189
@ -142,14 +142,6 @@ public class LibraryDownloadTask extends Task<Void> {
|
|||||||
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null)
|
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null)
|
||||||
.setCacheRepository(cacheRepository)
|
.setCacheRepository(cacheRepository)
|
||||||
.setCaching(true);
|
.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;
|
xz = false;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -31,6 +31,7 @@ import java.io.RandomAccessFile;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -155,6 +156,8 @@ public class FileDownloadTask extends Task<Void> {
|
|||||||
this.integrityCheck = integrityCheck;
|
this.integrityCheck = integrityCheck;
|
||||||
this.retry = retry;
|
this.retry = retry;
|
||||||
|
|
||||||
|
this.addIntegrityCheckHandler(ZIP_INTEGRITY_CHECK_HANDLER);
|
||||||
|
|
||||||
setName(file.getName());
|
setName(file.getName());
|
||||||
setExecutor(Schedulers.io());
|
setExecutor(Schedulers.io());
|
||||||
}
|
}
|
||||||
@ -254,6 +257,8 @@ public class FileDownloadTask extends Task<Void> {
|
|||||||
repeat--;
|
repeat--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} else if (con.getResponseCode() / 100 == 4) {
|
||||||
|
|
||||||
} else if (con.getResponseCode() / 100 != 2) {
|
} else if (con.getResponseCode() / 100 != 2) {
|
||||||
throw new ResponseCodeException(url, con.getResponseCode());
|
throw new ResponseCodeException(url, con.getResponseCode());
|
||||||
}
|
}
|
||||||
@ -405,4 +410,13 @@ public class FileDownloadTask extends Task<Void> {
|
|||||||
*/
|
*/
|
||||||
void checkIntegrity(Path filePath, Path destinationPath) throws IOException;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user