Inceptum/src/main/java/io/gitlab/jfronny/glaunch/install/steps/DownloadLibrariesStep.java

37 lines
1.4 KiB
Java
Raw Normal View History

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.Rules;
import io.gitlab.jfronny.glaunch.model.VersionInfo;
import io.gitlab.jfronny.glaunch.util.Utils;
import java.io.IOException;
public class DownloadLibrariesStep implements Step {
@Override
public void execute(SetupStepInfo info) throws IOException {
//TODO feedback
2021-10-27 22:07:07 +02:00
mainLoop: for (VersionInfo.Library library : info.version().libraries) {
2021-10-27 22:00:08 +02:00
for (Rules rule : library.rules) {
if (!rule.allow()) continue mainLoop;
}
if (library.classifiers != null) {
downloadLib(switch (Utils.getOs()) {
case "osx" -> library.classifiers.nativesMacos;
case "windows" -> library.classifiers.nativesWindows;
case "linux" -> library.classifiers.nativesLinux;
default -> throw new RuntimeException("Not a valid OS");
});
}
downloadLib(library.artifact);
}
}
private void downloadLib(VersionInfo.Library.Artifact artifact) throws IOException {
//TODO allow maven-like download for fabric
Utils.downloadFile(artifact.url, artifact.sha1, GLaunch.LIBRARIES_DIR.resolve(artifact.path));
}
}