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

53 lines
2.4 KiB
Java
Raw Normal View History

2021-10-29 22:50:42 +02:00
package io.gitlab.jfronny.inceptum.install.steps;
2021-10-27 22:00:08 +02:00
2021-10-29 22:50:42 +02:00
import io.gitlab.jfronny.inceptum.Inceptum;
import io.gitlab.jfronny.inceptum.install.SetupStepInfo;
import io.gitlab.jfronny.inceptum.install.Step;
2021-10-30 16:12:39 +02:00
import io.gitlab.jfronny.inceptum.model.inceptum.ArtifactInfo;
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
2021-10-30 19:26:59 +02:00
import io.gitlab.jfronny.inceptum.model.mojang.VersionInfo;
2021-10-29 22:50:42 +02:00
import io.gitlab.jfronny.inceptum.util.Utils;
import io.gitlab.jfronny.inceptum.util.VersionInfoLibraryResolver;
2021-10-27 22:00:08 +02:00
import java.io.IOException;
2021-10-30 16:12:39 +02:00
import java.nio.file.FileSystem;
2021-10-28 20:19:09 +02:00
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicBoolean;
2021-10-30 19:26:59 +02:00
import java.util.concurrent.atomic.AtomicReference;
2021-10-27 22:00:08 +02:00
public class DownloadLibrariesStep implements Step {
@Override
public void execute(SetupStepInfo info, AtomicBoolean stopThread) throws IOException {
2021-10-30 19:26:59 +02:00
execute(info.version(), stopThread, info.currentState());
}
public static void execute(VersionInfo version, AtomicBoolean stopThread, AtomicReference<String> currentState) throws IOException {
for (ArtifactInfo artifact : VersionInfoLibraryResolver.getRelevant(version)) {
if (stopThread.get()) return;
2021-10-29 22:50:42 +02:00
Path path = Inceptum.LIBRARIES_DIR.resolve(artifact.path);
2021-10-30 16:12:39 +02:00
if (!Files.exists(path)) {
2021-10-30 19:26:59 +02:00
currentState.set("Downloading library: " + artifact.path);
Inceptum.LOGGER.info(currentState.get());
2021-10-30 16:12:39 +02:00
if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent());
if (!artifact.url.endsWith(".jar")) {
Inceptum.LOGGER.info("Not a valid URL for a jar: " + artifact.url);
continue;
}
Utils.downloadFile(artifact.url, artifact.sha1, path);
}
if (artifact.isNative) {
2021-10-30 19:26:59 +02:00
currentState.set("Extracting natives");
Inceptum.LOGGER.info(currentState.get());
2021-11-02 16:44:26 +01:00
try (FileSystem libFs = Utils.openZipFile(path, false)) {
2021-11-11 20:11:20 +01:00
Utils.copyContent(libFs.getPath("."), Inceptum.NATIVES_DIR.resolve(InstanceMeta.getMinecraftVersion(version.id)));
2021-10-30 16:12:39 +02:00
}
catch (Throwable t) {
Files.delete(path);
throw new IOException("Could not extract native", t);
}
}
2021-10-27 22:00:08 +02:00
}
}
}