Fix #422
This commit is contained in:
@@ -64,8 +64,8 @@ public class BMCLAPIDownloadProvider implements DownloadProvider {
|
|||||||
return baseURL
|
return baseURL
|
||||||
.replace("https://launchermeta.mojang.com", "https://bmclapi2.bangbang93.com")
|
.replace("https://launchermeta.mojang.com", "https://bmclapi2.bangbang93.com")
|
||||||
.replace("https://launcher.mojang.com", "https://bmclapi2.bangbang93.com")
|
.replace("https://launcher.mojang.com", "https://bmclapi2.bangbang93.com")
|
||||||
.replace("https://libraries.minecraft.net", "https://bmclapi2.bangbang93.com/libraries")
|
.replace("https://libraries.minecraft.net", "http://bmclapi2.bangbang93.com/libraries")
|
||||||
.replaceFirst("https?://files\\.minecraftforge\\.net/maven", "https://bmclapi2.bangbang93.com/maven")
|
.replaceFirst("https?://files\\.minecraftforge\\.net/maven", "http://bmclapi2.bangbang93.com/maven")
|
||||||
.replace("http://dl.liteloader.com/versions/versions.json", "https://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json")
|
.replace("http://dl.liteloader.com/versions/versions.json", "https://bmclapi2.bangbang93.com/maven/com/mumfrey/liteloader/versions.json")
|
||||||
.replace("http://dl.liteloader.com/versions", "https://bmclapi2.bangbang93.com/maven")
|
.replace("http://dl.liteloader.com/versions", "https://bmclapi2.bangbang93.com/maven")
|
||||||
.replace("https://authlib-injector.yushi.moe", "https://bmclapi2.bangbang93.com/mirrors/authlib-injector");
|
.replace("https://authlib-injector.yushi.moe", "https://bmclapi2.bangbang93.com/mirrors/authlib-injector");
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import org.jackhuang.hmcl.util.NetworkUtils;
|
|||||||
import org.tukaani.xz.XZInputStream;
|
import org.tukaani.xz.XZInputStream;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
@@ -23,15 +26,15 @@ import static org.jackhuang.hmcl.util.DigestUtils.digest;
|
|||||||
import static org.jackhuang.hmcl.util.Hex.encodeHex;
|
import static org.jackhuang.hmcl.util.Hex.encodeHex;
|
||||||
|
|
||||||
public final class LibraryDownloadTask extends Task {
|
public final class LibraryDownloadTask extends Task {
|
||||||
private final FileDownloadTask xzTask;
|
private final LibraryDownloadTaskHelper helperTask;
|
||||||
private final FileDownloadTask task;
|
|
||||||
private final File jar;
|
private final File jar;
|
||||||
private final File xzFile;
|
private final File xzFile;
|
||||||
private final Library library;
|
private final Library library;
|
||||||
|
private boolean xz;
|
||||||
private boolean downloaded = false;
|
|
||||||
|
|
||||||
public LibraryDownloadTask(AbstractDependencyManager dependencyManager, File file, Library library) {
|
public LibraryDownloadTask(AbstractDependencyManager dependencyManager, File file, Library library) {
|
||||||
|
setSignificance(TaskSignificance.MODERATE);
|
||||||
|
|
||||||
if (library.is("net.minecraftforge", "forge"))
|
if (library.is("net.minecraftforge", "forge"))
|
||||||
library = library.setClassifier("universal");
|
library = library.setClassifier("universal");
|
||||||
|
|
||||||
@@ -42,20 +45,12 @@ public final class LibraryDownloadTask extends Task {
|
|||||||
|
|
||||||
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
|
xzFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".pack.xz");
|
||||||
|
|
||||||
xzTask = new FileDownloadTask(NetworkUtils.toURL(url + ".pack.xz"),
|
helperTask = new LibraryDownloadTaskHelper(file, url);
|
||||||
xzFile, null, 1);
|
|
||||||
xzTask.setSignificance(TaskSignificance.MINOR);
|
|
||||||
|
|
||||||
setSignificance(TaskSignificance.MODERATE);
|
|
||||||
|
|
||||||
task = new FileDownloadTask(NetworkUtils.toURL(url),
|
|
||||||
file,
|
|
||||||
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends Task> getDependents() {
|
public Collection<? extends Task> getDependents() {
|
||||||
return library.getChecksums() != null ? Collections.singleton(xzTask) : Collections.singleton(task);
|
return Collections.singleton(helperTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -66,19 +61,61 @@ public final class LibraryDownloadTask extends Task {
|
|||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
if (!isDependentsSucceeded()) {
|
if (!isDependentsSucceeded()) {
|
||||||
// Since FileDownloadTask wraps the actual exception with another IOException.
|
if (helperTask.task == null) {
|
||||||
// We should extract it letting the error message clearer.
|
// NetworkUtils.URLExists failed.
|
||||||
Throwable t = library.getChecksums() != null ? xzTask.getLastException() : task.getLastException();
|
throw new LibraryDownloadException(library, helperTask.getLastException());
|
||||||
if (t.getCause() != null && t.getCause() != t)
|
} else {
|
||||||
throw new LibraryDownloadException(library, t.getCause());
|
// Since FileDownloadTask wraps the actual exception with another IOException.
|
||||||
else
|
// We should extract it letting the error message clearer.
|
||||||
throw new LibraryDownloadException(library, t);
|
Throwable t = helperTask.task.getLastException();
|
||||||
|
if (t.getCause() != null && t.getCause() != t)
|
||||||
|
throw new LibraryDownloadException(library, t.getCause());
|
||||||
|
else
|
||||||
|
throw new LibraryDownloadException(library, t);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (xz) {
|
||||||
|
unpackLibrary(jar, FileUtils.readBytes(xzFile));
|
||||||
|
if (!checksumValid(jar, library.getChecksums()))
|
||||||
|
throw new IOException("Checksum failed for " + library);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LibraryDownloadTaskHelper extends Task {
|
||||||
|
private FileDownloadTask task;
|
||||||
|
private final File file;
|
||||||
|
private final String url;
|
||||||
|
|
||||||
|
public LibraryDownloadTaskHelper(File file, String url) {
|
||||||
|
this.file = file;
|
||||||
|
this.url = url;
|
||||||
|
|
||||||
|
setName(library.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (library.getChecksums() != null) {
|
@Override
|
||||||
unpackLibrary(jar, FileUtils.readBytes(xzFile));
|
public boolean isRelyingOnDependencies() {
|
||||||
if (!checksumValid(jar, library.getChecksums()))
|
return true;
|
||||||
throw new IOException("Checksum failed for " + library);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends Task> getDependencies() {
|
||||||
|
return Collections.singleton(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws Exception {
|
||||||
|
URL packXz = NetworkUtils.toURL(url + ".pack.xz");
|
||||||
|
if (NetworkUtils.URLExists(packXz)) {
|
||||||
|
task = new FileDownloadTask(packXz, xzFile, null);
|
||||||
|
xz = true;
|
||||||
|
} else {
|
||||||
|
task = new FileDownloadTask(NetworkUtils.toURL(url),
|
||||||
|
file,
|
||||||
|
library.getDownload().getSha1() != null ? new IntegrityCheck("SHA-1", library.getDownload().getSha1()) : null);
|
||||||
|
xz = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public abstract class Task {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String name = getClass().toString();
|
private String name = getClass().getName();
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util;
|
package org.jackhuang.hmcl.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UncheckedIOException;
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -156,4 +153,12 @@ public final class NetworkUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean URLExists(URL url) throws IOException {
|
||||||
|
try (InputStream stream = url.openStream()) {
|
||||||
|
return true;
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user