Fix error when loading minecraft version pre 1.14 Fixes: #579

This commit is contained in:
Lukas Rieger (Blue) 2024-09-15 09:37:40 +02:00
parent 79fd4d0201
commit 56369c9143
No known key found for this signature in database
GPG Key ID: AA33883B1BBA03E6

View File

@ -39,7 +39,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.security.DigestInputStream;
@ -140,7 +141,7 @@ private static void download(VersionManifest.Version version, Path file) throws
FileHelper.createDirectories(file.toAbsolutePath().normalize().getParent());
try (
DigestInputStream in = new DigestInputStream(new URL(download.getUrl()).openStream(), MessageDigest.getInstance("SHA-1"));
DigestInputStream in = new DigestInputStream(new URI(download.getUrl()).toURL().openStream(), MessageDigest.getInstance("SHA-1"));
OutputStream out = Files.newOutputStream(file, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW, StandardOpenOption.TRUNCATE_EXISTING)
) {
in.transferTo(out);
@ -154,7 +155,7 @@ private static void download(VersionManifest.Version version, Path file) throws
}
downloadCompletedAndVerified = true;
} catch (NoSuchAlgorithmException | IOException ex) {
} catch (NoSuchAlgorithmException | IOException | URISyntaxException ex) {
Logger.global.logWarning("Failed to download '" + download.getUrl() + "': " + ex);
} finally {
if (!downloadCompletedAndVerified)
@ -200,7 +201,8 @@ private static VersionInfo loadVersionInfo(Path file) throws IOException {
}
}
throw new IOException("'" + file + "' does not contain a 'version.json'");
// no version.json found, assume 1.13 - 1.14.4
return new VersionInfo(4, 4);
}
}