67 lines
3.1 KiB
Java
67 lines
3.1 KiB
Java
package io.gitlab.jfronny.inceptum.launcher.system.setup.steps;
|
|
|
|
import io.gitlab.jfronny.commons.io.JFiles;
|
|
import io.gitlab.jfronny.inceptum.common.*;
|
|
import io.gitlab.jfronny.inceptum.common.api.MavenApi;
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ArtifactInfo;
|
|
import io.gitlab.jfronny.inceptum.launcher.model.mojang.VersionInfo;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.setup.Step;
|
|
import io.gitlab.jfronny.inceptum.launcher.util.*;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.setup.SetupStepInfo;
|
|
import org.xml.sax.SAXException;
|
|
|
|
import javax.xml.stream.XMLStreamException;
|
|
import java.io.IOException;
|
|
import java.net.URISyntaxException;
|
|
import java.nio.file.*;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
public class DownloadLibrariesStep implements Step {
|
|
@Override
|
|
public void execute(SetupStepInfo info, AtomicBoolean stopThread) throws IOException {
|
|
execute(info.version(), stopThread, info.currentState());
|
|
}
|
|
|
|
public static void execute(VersionInfo version, AtomicBoolean stopThread, ProcessState currentState) throws IOException {
|
|
for (ArtifactInfo artifact : VersionInfoLibraryResolver.getRelevant(version)) {
|
|
if (stopThread.get()) return;
|
|
Path path = MetaHolder.LIBRARIES_DIR.resolve(artifact.path);
|
|
if (!Files.exists(path)) {
|
|
currentState.updateStep("Downloading library: " + artifact.path);
|
|
if (!Files.exists(path.getParent())) Files.createDirectories(path.getParent());
|
|
if (!artifact.url.endsWith(".jar")) {
|
|
Utils.LOGGER.info("Not a valid URL for a jar: " + artifact.url);
|
|
continue;
|
|
}
|
|
try {
|
|
Net.downloadFile(artifact.url, artifact.sha1, path);
|
|
} catch (URISyntaxException e) {
|
|
throw new IOException("Could not download library", e);
|
|
}
|
|
}
|
|
if (artifact.isNative) {
|
|
currentState.updateStep("Extracting natives");
|
|
try (FileSystem libFs = Utils.openZipFile(path, false)) {
|
|
JFiles.copyRecursive(libFs.getPath("."), MetaHolder.NATIVES_DIR.resolve(GameVersionParser.getGameVersion(version.id)));
|
|
} catch (Throwable t) {
|
|
Files.delete(path);
|
|
throw new IOException("Could not extract native", t);
|
|
}
|
|
}
|
|
}
|
|
|
|
String artifact = getLaunchWrapperArtifact();
|
|
if (!Files.exists(MetaHolder.LIBRARIES_DIR.resolve(MavenApi.mavenNotationToJarPath(artifact)))) {
|
|
try {
|
|
MavenApi.downloadLibrary(Updater.PROJECT_MAVEN, MavenApi.getPom(Updater.PROJECT_MAVEN, artifact));
|
|
} catch (URISyntaxException | XMLStreamException | SAXException 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);
|
|
}
|
|
}
|