2022-01-18 18:43:39 +01:00
|
|
|
package io.gitlab.jfronny.inceptum.model.inceptum.install.steps;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2022-01-18 18:43:39 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.model.inceptum.install.SetupStepInfo;
|
|
|
|
import io.gitlab.jfronny.inceptum.model.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;
|
2022-01-18 18:43:39 +01:00
|
|
|
import io.gitlab.jfronny.inceptum.util.MetaHolder;
|
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;
|
2022-01-18 18:43:39 +01:00
|
|
|
import java.net.URISyntaxException;
|
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;
|
2021-10-29 23:16:03 +02:00
|
|
|
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
|
2021-10-29 23:16:03 +02:00
|
|
|
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)) {
|
2021-10-29 23:16:03 +02:00
|
|
|
if (stopThread.get()) return;
|
2022-01-18 18:43:39 +01:00
|
|
|
Path path = MetaHolder.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);
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.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")) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.info("Not a valid URL for a jar: " + artifact.url);
|
2021-10-30 16:12:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-18 18:43:39 +01:00
|
|
|
try {
|
|
|
|
Utils.downloadFile(artifact.url, artifact.sha1, path);
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
throw new IOException("Could not download library", e);
|
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
}
|
|
|
|
if (artifact.isNative) {
|
2021-10-30 19:26:59 +02:00
|
|
|
currentState.set("Extracting natives");
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.LOGGER.info(currentState.get());
|
2021-11-02 16:44:26 +01:00
|
|
|
try (FileSystem libFs = Utils.openZipFile(path, false)) {
|
2022-01-18 18:43:39 +01:00
|
|
|
Utils.copyContent(libFs.getPath("."), MetaHolder.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-30 14:22:07 +02:00
|
|
|
}
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|