Search in sources :

Example 1 with Download

use of net.technicpack.minecraftcore.mojang.version.io.Download in project LauncherV3 by TechnicPack.

the class EnsureJavaRuntimeManifestTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
    JavaVersion wantedRuntime = version.getJavaVersion();
    if (wantedRuntime == null) {
        // Nothing to do here, this version doesn't have a Mojang JRE
        return;
    }
    final String runtimeName = wantedRuntime.getComponent();
    JavaRuntimes availableRuntimes = MojangUtils.getJavaRuntimes();
    if (availableRuntimes == null) {
        throw new DownloadException("Failed to get Mojang JRE information");
    }
    JavaRuntime runtime = availableRuntimes.getRuntimeForCurrentOS(runtimeName);
    Download manifest = runtime.getManifest();
    File output = new File(runtimesDirectory + File.separator + "manifests", runtimeName + ".json");
    (new File(output.getParent())).mkdirs();
    IFileVerifier fileVerifier = new SHA1FileVerifier(manifest.getSha1());
    if (!output.exists() || !fileVerifier.isFileValid(output)) {
        examineJavaQueue.addTask(new DownloadFileTask(manifest.getUrl(), output, fileVerifier));
    }
    examineJavaQueue.addTask(new InstallJavaRuntimeTask(modpack, runtimesDirectory, output, runtimeName, examineJavaQueue, downloadJavaQueue));
}
Also used : JavaRuntime(net.technicpack.minecraftcore.mojang.java.JavaRuntime) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) JavaVersion(net.technicpack.minecraftcore.mojang.version.io.JavaVersion) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) JavaRuntimes(net.technicpack.minecraftcore.mojang.java.JavaRuntimes) DownloadException(net.technicpack.launchercore.exception.DownloadException) Download(net.technicpack.minecraftcore.mojang.version.io.Download) File(java.io.File) DownloadFileTask(net.technicpack.launchercore.install.tasks.DownloadFileTask)

Example 2 with Download

use of net.technicpack.minecraftcore.mojang.version.io.Download in project LauncherV3 by TechnicPack.

the class InstallJavaRuntimeTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    String json = FileUtils.readFileToString(runtimeManifestFile, StandardCharsets.UTF_8);
    JavaRuntimeManifest manifest = MojangUtils.getGson().fromJson(json, JavaRuntimeManifest.class);
    if (manifest == null) {
        throw new DownloadException("The Java runtime manifest is invalid.");
    }
    // TODO: Check runtime isn't downloaded/installed outside of its directory
    // Create the runtime directory if it doesn't exist
    File runtimeRoot = new File(runtimesDirectory, runtimeName);
    runtimeRoot.mkdirs();
    // First, create the dirs
    manifest.getFiles().forEach((path, runtimeFile) -> {
        // We're only interested in the dirs for now
        if (runtimeFile.getType() == JavaRuntimeFileType.DIRECTORY) {
            File dir = new File(runtimeRoot, path);
            dir.mkdirs();
        }
    });
    // Then, download the files
    manifest.getFiles().forEach((path, runtimeFile) -> {
        // We're only interested in the files right now
        if (runtimeFile.getType() == JavaRuntimeFileType.FILE) {
            File target = new File(runtimeRoot, path);
            // Apparently the Mac Java 8 JRE spec doesn't have any directory entries, so we have to create them regardless
            target.getParentFile().mkdirs();
            Download download = runtimeFile.getDownloads().getRaw();
            IFileVerifier verifier = new SHA1FileVerifier(download.getSha1());
            EnsureFileTask ensureFileTask = new EnsureFileTask(target, verifier, null, download.getUrl(), downloadJavaQueue, null);
            ensureFileTask.setExecutable(runtimeFile.isExecutable());
            examineJavaQueue.addTask(ensureFileTask);
        }
    });
    // Then, create the links
    manifest.getFiles().forEach((path, runtimeFile) -> {
        // We're only interested in links right now
        if (runtimeFile.getType() == JavaRuntimeFileType.LINK) {
            File link = new File(runtimeRoot, path);
            File target = new File(link, runtimeFile.getTarget());
            // We add it to the download queue so it runs after all the files exist
            downloadJavaQueue.addTask(new EnsureLinkedFileTask(link, target));
        }
    });
}
Also used : EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) EnsureLinkedFileTask(net.technicpack.launchercore.install.tasks.EnsureLinkedFileTask) DownloadException(net.technicpack.launchercore.exception.DownloadException) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) JavaRuntimeManifest(net.technicpack.minecraftcore.mojang.java.JavaRuntimeManifest) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) File(java.io.File) Download(net.technicpack.minecraftcore.mojang.version.io.Download)

Aggregations

File (java.io.File)2 DownloadException (net.technicpack.launchercore.exception.DownloadException)2 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)2 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)2 Download (net.technicpack.minecraftcore.mojang.version.io.Download)2 InstallTasksQueue (net.technicpack.launchercore.install.InstallTasksQueue)1 DownloadFileTask (net.technicpack.launchercore.install.tasks.DownloadFileTask)1 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)1 EnsureLinkedFileTask (net.technicpack.launchercore.install.tasks.EnsureLinkedFileTask)1 JavaRuntime (net.technicpack.minecraftcore.mojang.java.JavaRuntime)1 JavaRuntimeManifest (net.technicpack.minecraftcore.mojang.java.JavaRuntimeManifest)1 JavaRuntimes (net.technicpack.minecraftcore.mojang.java.JavaRuntimes)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 JavaVersion (net.technicpack.minecraftcore.mojang.version.io.JavaVersion)1