Add a strict mode when download files, will be a bit slower but should help solve some issues.

This commit is contained in:
modmuss50
2021-03-18 14:38:29 +00:00
parent b4f6874613
commit c033246a9f
2 changed files with 17 additions and 5 deletions

View File

@@ -124,7 +124,7 @@ public class MinecraftAssetsProvider {
progressLogger.progress(String.format("%-30.30s", assetName) + " - " + sha1);
try {
HashedDownloadUtil.downloadIfInvalid(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, sha1, project.getLogger(), true);
HashedDownloadUtil.downloadIfInvalid(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, sha1, project.getLogger(), true, false);
} catch (IOException e) {
throw new RuntimeException("Failed to download: " + assetName, e);
}

View File

@@ -41,16 +41,27 @@ import net.fabricmc.loom.LoomGradlePlugin;
public class HashedDownloadUtil {
public static void downloadIfInvalid(URL from, File to, String expectedHash, Logger logger, boolean quiet) throws IOException {
downloadIfInvalid(from, to, expectedHash, logger, quiet, true);
}
public static void downloadIfInvalid(URL from, File to, String expectedHash, Logger logger, boolean quiet, boolean strict) throws IOException {
if (LoomGradlePlugin.refreshDeps) {
delete(to);
}
if (to.exists()) {
String sha1 = getSha1(to, logger);
if (strict) {
if (Checksum.equals(to, expectedHash)) {
// The hash matches the target file
return;
}
} else {
String sha1 = getSha1(to, logger);
if (expectedHash.equals(sha1)) {
// The hash in the sha1 file matches
return;
if (expectedHash.equals(sha1)) {
// The hash in the sha1 file matches
return;
}
}
}
@@ -62,6 +73,7 @@ public class HashedDownloadUtil {
if ((code < 200 || code > 299) && code != HttpURLConnection.HTTP_NOT_MODIFIED) {
//Didn't get what we expected
delete(to);
throw new IOException(connection.getResponseMessage() + " for " + from);
}