mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Download all libraries for every platform when building packs
This commit is contained in:
parent
d6ac0983de
commit
3981fe4ab2
@ -26,7 +26,6 @@ import com.skcraft.launcher.model.minecraft.ReleaseList;
|
||||
import com.skcraft.launcher.model.minecraft.Version;
|
||||
import com.skcraft.launcher.model.minecraft.VersionManifest;
|
||||
import com.skcraft.launcher.model.modpack.Manifest;
|
||||
import com.skcraft.launcher.util.Environment;
|
||||
import com.skcraft.launcher.util.HttpRequest;
|
||||
import com.skcraft.launcher.util.SimpleLogFormatter;
|
||||
import lombok.Getter;
|
||||
@ -178,52 +177,57 @@ public class PackageBuilder {
|
||||
loaderLibraries.addAll(result.getLoaderLibraries());
|
||||
installerLibraries.addAll(result.getProcessorLibraries());
|
||||
jarMavens.addAll(result.getJarMavens());
|
||||
} else {
|
||||
log.warning("Loader " + file.getName() + " was skipped due to missing metadata. " +
|
||||
"Is it really a loader JAR?");
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadLibraries(File librariesDir) throws IOException, InterruptedException {
|
||||
logSection("Downloading libraries...");
|
||||
|
||||
// TODO: Download libraries for different environments -- As of writing, this is not an issue
|
||||
Environment env = Environment.getInstance();
|
||||
|
||||
for (Library library : Iterables.concat(loaderLibraries, installerLibraries)) {
|
||||
Library.Artifact artifact = library.getArtifact(env);
|
||||
File outputPath = new File(librariesDir, artifact.getPath());
|
||||
library.ensureDownloadsExist();
|
||||
|
||||
if (!outputPath.exists()) {
|
||||
Files.createParentDirs(outputPath);
|
||||
boolean found = false;
|
||||
for (Library.Artifact artifact : library.getDownloads().getAllArtifacts()) {
|
||||
File outputPath = new File(librariesDir, artifact.getPath());
|
||||
|
||||
// Try just the URL, it might be a full URL to the file
|
||||
if (!artifact.getUrl().isEmpty()) {
|
||||
found = tryDownloadLibrary(library, artifact, artifact.getUrl(), outputPath);
|
||||
}
|
||||
if (!outputPath.exists()) {
|
||||
Files.createParentDirs(outputPath);
|
||||
boolean found = false;
|
||||
|
||||
// Look inside the loader JARs
|
||||
if (!found) {
|
||||
for (URL base : jarMavens) {
|
||||
found = tryFetchLibrary(library, new URL(base, artifact.getPath()), outputPath);
|
||||
if (found) break;
|
||||
// Try just the URL, it might be a full URL to the file
|
||||
if (!artifact.getUrl().isEmpty()) {
|
||||
found = tryDownloadLibrary(library, artifact, artifact.getUrl(), outputPath);
|
||||
}
|
||||
}
|
||||
|
||||
// Assume artifact URL is a maven repository URL and try that
|
||||
if (!found) {
|
||||
URL url = LauncherUtils.concat(url(artifact.getUrl()), artifact.getPath());
|
||||
found = tryDownloadLibrary(library, artifact, url.toString(), outputPath);
|
||||
}
|
||||
|
||||
// Try each repository if not found yet
|
||||
if (!found) {
|
||||
for (String baseUrl : mavenRepos) {
|
||||
found = tryDownloadLibrary(library, artifact, baseUrl + artifact.getPath(), outputPath);
|
||||
if (found) break;
|
||||
// Look inside the loader JARs
|
||||
if (!found) {
|
||||
for (URL base : jarMavens) {
|
||||
found = tryFetchLibrary(library, new URL(base, artifact.getPath()), outputPath);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
log.warning("!! Failed to download the library " + library.getName() + " -- this means your copy of the libraries will lack this file");
|
||||
// Assume artifact URL is a maven repository URL and try that
|
||||
if (!found) {
|
||||
URL url = LauncherUtils.concat(url(artifact.getUrl()), artifact.getPath());
|
||||
found = tryDownloadLibrary(library, artifact, url.toString(), outputPath);
|
||||
}
|
||||
|
||||
// Try each repository if not found yet
|
||||
if (!found) {
|
||||
for (String baseUrl : mavenRepos) {
|
||||
found = tryDownloadLibrary(library, artifact, baseUrl + artifact.getPath(),
|
||||
outputPath);
|
||||
if (found) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
log.warning("!! Failed to download the library " + library.getName() +
|
||||
" -- this means your copy of the libraries will lack this file");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ package com.skcraft.launcher.model.minecraft;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.skcraft.launcher.util.Environment;
|
||||
import lombok.Data;
|
||||
|
||||
@ -71,6 +72,12 @@ public class Library {
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureDownloadsExist() {
|
||||
if (getDownloads() == null) {
|
||||
setServerreq(true); // BACKWARDS COMPATIBILITY
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BACKWARDS COMPATIBILITY:
|
||||
* Some library definitions only come with a "name" key and don't trigger any other compatibility measures.
|
||||
@ -81,9 +88,7 @@ public class Library {
|
||||
* the library name and using that.
|
||||
*/
|
||||
public Artifact getArtifact(Environment environment) {
|
||||
if (getDownloads() == null) {
|
||||
setServerreq(true); // BACKWARDS COMPATIBILITY
|
||||
}
|
||||
ensureDownloadsExist();
|
||||
|
||||
String nativeString = getNativeString(environment);
|
||||
|
||||
@ -147,6 +152,18 @@ public class Library {
|
||||
public static class Downloads {
|
||||
private Artifact artifact;
|
||||
private Map<String, Artifact> classifiers;
|
||||
|
||||
public List<Artifact> getAllArtifacts() {
|
||||
List<Artifact> artifacts = Lists.newArrayList();
|
||||
|
||||
if (artifact != null)
|
||||
artifacts.add(artifact);
|
||||
|
||||
if (classifiers != null)
|
||||
artifacts.addAll(classifiers.values());
|
||||
|
||||
return artifacts;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user