Search in sources :

Example 6 with IFileVerifier

use of net.technicpack.launchercore.install.verifiers.IFileVerifier 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)

Example 7 with IFileVerifier

use of net.technicpack.launchercore.install.verifiers.IFileVerifier in project LauncherV3 by TechnicPack.

the class QueryUpdateStream method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    try {
        StreamVersion version = updateStream.getStreamVersion(relauncher.getStreamName());
        if (version == null || version.getBuild() == 0)
            return;
        for (LauncherResource resource : version.getResources()) {
            IFileVerifier verifier = new MD5FileVerifier(resource.getMd5());
            File downloadFile = new File(new File(directories.getAssetsDirectory(), "launcher"), resource.getFilename());
            if (!downloadFile.exists() || !verifier.isFileValid(downloadFile))
                downloadTasks.addTask(new DownloadFileTask(resource.getUrl(), downloadFile, verifier, resource.getFilename()));
        }
        if (version.getBuild() == relauncher.getCurrentBuild() || (relauncher.getStreamName().startsWith("beta") && version.getBuild() <= relauncher.getCurrentBuild()))
            return;
        String updateUrl = null;
        String runningPath = relauncher.getRunningPath();
        if (runningPath == null) {
            throw new DownloadException("Could not load a running path for currently-executing launcher.");
        }
        if (runningPath.endsWith(".exe"))
            updateUrl = version.getExeUrl();
        else
            updateUrl = version.getJarUrl();
        downloadTasks.addTask(new DownloadUpdate(updateUrl, relauncher, postDownloadTasks));
    } catch (RestfulAPIException ex) {
        return;
    }
}
Also used : LauncherResource(net.technicpack.autoupdate.io.LauncherResource) RestfulAPIException(net.technicpack.rest.RestfulAPIException) DownloadException(net.technicpack.launchercore.exception.DownloadException) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) File(java.io.File) DownloadFileTask(net.technicpack.launchercore.install.tasks.DownloadFileTask) StreamVersion(net.technicpack.autoupdate.io.StreamVersion) MD5FileVerifier(net.technicpack.launchercore.install.verifiers.MD5FileVerifier)

Aggregations

File (java.io.File)7 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)7 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)5 MD5FileVerifier (net.technicpack.launchercore.install.verifiers.MD5FileVerifier)4 DownloadException (net.technicpack.launchercore.exception.DownloadException)3 InstallTasksQueue (net.technicpack.launchercore.install.InstallTasksQueue)3 DownloadFileTask (net.technicpack.launchercore.install.tasks.DownloadFileTask)3 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)3 ValidZipFileVerifier (net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier)3 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)3 Download (net.technicpack.minecraftcore.mojang.version.io.Download)2 LauncherResource (net.technicpack.autoupdate.io.LauncherResource)1 StreamVersion (net.technicpack.autoupdate.io.StreamVersion)1 EnsureLinkedFileTask (net.technicpack.launchercore.install.tasks.EnsureLinkedFileTask)1 ValidJsonFileVerifier (net.technicpack.launchercore.install.verifiers.ValidJsonFileVerifier)1 ModpackZipFilter (net.technicpack.minecraftcore.install.ModpackZipFilter)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 ExtractRulesFileFilter (net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter)1