2022-09-04 21:21:24 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.launcher.system.install.steps;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.commons.io.JFiles;
|
|
|
|
import io.gitlab.jfronny.inceptum.common.*;
|
2022-09-18 19:28:26 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.common.api.GitlabApi;
|
|
|
|
import io.gitlab.jfronny.inceptum.common.api.MavenApi;
|
2022-09-04 21:21:24 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ArtifactInfo;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.install.Step;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.util.VersionInfoLibraryResolver;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.install.SetupStepInfo;
|
2021-10-27 22:00:08 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2022-01-18 18:43:39 +01:00
|
|
|
import java.net.URISyntaxException;
|
2022-09-04 21:21:24 +02:00
|
|
|
import java.nio.file.*;
|
2021-10-29 23:16:03 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
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());
|
|
|
|
}
|
|
|
|
|
2022-01-19 19:14:13 +01:00
|
|
|
public static void execute(VersionInfo version, AtomicBoolean stopThread, ProcessState currentState) throws IOException {
|
2021-10-30 19:26:59 +02:00
|
|
|
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)) {
|
2022-01-19 19:14:13 +01:00
|
|
|
currentState.updateStep("Downloading library: " + artifact.path);
|
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 {
|
2022-09-04 21:21:24 +02:00
|
|
|
Net.downloadFile(artifact.url, artifact.sha1, path);
|
2022-01-18 18:43:39 +01:00
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
throw new IOException("Could not download library", e);
|
|
|
|
}
|
2021-10-30 16:12:39 +02:00
|
|
|
}
|
|
|
|
if (artifact.isNative) {
|
2022-01-19 19:14:13 +01:00
|
|
|
currentState.updateStep("Extracting natives");
|
2021-11-02 16:44:26 +01:00
|
|
|
try (FileSystem libFs = Utils.openZipFile(path, false)) {
|
2022-09-18 15:15:30 +02:00
|
|
|
JFiles.copyRecursive(libFs.getPath("."), MetaHolder.NATIVES_DIR.resolve(InstanceMeta.getMinecraftVersion(version.id)));
|
2022-09-04 21:21:24 +02:00
|
|
|
} catch (Throwable t) {
|
2021-10-30 16:12:39 +02:00
|
|
|
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
|
|
|
}
|
2022-09-18 19:28:26 +02:00
|
|
|
|
|
|
|
String artifact = getLaunchWrapperArtifact();
|
|
|
|
if (!Files.exists(MetaHolder.LIBRARIES_DIR.resolve(MavenApi.mavenNotationToJarPath(artifact)))) {
|
|
|
|
try {
|
|
|
|
MavenApi.downloadLibrary(GitlabApi.PROJECT_MAVEN, artifact);
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
throw new IOException("Could not download launchwrapper", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getLaunchWrapperArtifact() {
|
|
|
|
return "io.gitlab.jfronny.inceptum:launchwrapper:" + (BuildMetadata.IS_PUBLIC ? BuildMetadata.VERSION : Updater.getUpdate().version);
|
2021-10-27 22:00:08 +02:00
|
|
|
}
|
|
|
|
}
|