2021-10-27 22:00:08 +02:00
|
|
|
package io.gitlab.jfronny.glaunch.install.steps;
|
|
|
|
|
|
|
|
import io.gitlab.jfronny.glaunch.GLaunch;
|
|
|
|
import io.gitlab.jfronny.glaunch.install.SetupStepInfo;
|
|
|
|
import io.gitlab.jfronny.glaunch.install.Step;
|
|
|
|
import io.gitlab.jfronny.glaunch.model.VersionInfo;
|
|
|
|
import io.gitlab.jfronny.glaunch.util.Utils;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-10-28 20:19:09 +02:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
public class DownloadLibrariesStep implements Step {
|
|
|
|
@Override
|
|
|
|
public void execute(SetupStepInfo info) throws IOException {
|
2021-10-28 20:19:09 +02:00
|
|
|
for (VersionInfo.Library library : info.version().libraries) {
|
|
|
|
if (library.rules != null && !library.rules.allow()) continue;
|
|
|
|
if (library.downloads.classifiers != null && library.natives != null && library.natives.containsKey(Utils.OS)) {
|
|
|
|
downloadLib(library.downloads.classifiers.get(library.natives.get(Utils.OS)));
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
2021-10-28 20:19:09 +02:00
|
|
|
if (library.downloads.artifact == null) {
|
|
|
|
GLaunch.LOGGER.info("Null library artifact @ " + library.name);
|
|
|
|
continue;
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
2021-10-28 20:19:09 +02:00
|
|
|
downloadLib(library.downloads.artifact);
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 20:19:09 +02:00
|
|
|
private void downloadLib(VersionInfo.Library.Downloads.Artifact artifact) throws IOException {
|
|
|
|
Path path = GLaunch.LIBRARIES_DIR.resolve(artifact.path);
|
|
|
|
if (Files.exists(path)) return;
|
2021-10-27 22:00:08 +02:00
|
|
|
//TODO allow maven-like download for fabric
|
2021-10-28 20:19:09 +02:00
|
|
|
GLaunch.LOGGER.info("Downloading library: " + artifact.path);
|
|
|
|
if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent());
|
|
|
|
Utils.downloadFile(artifact.url, artifact.sha1, path);
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|