Search in sources :

Example 1 with EnsureFileTask

use of net.technicpack.launchercore.install.tasks.EnsureFileTask in project LauncherV3 by TechnicPack.

the class CleanupAndExtractModpackTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    File modsDir = this.pack.getModsDir();
    if (modsDir != null && modsDir.exists()) {
        deleteMods(modsDir);
    }
    File coremodsDir = this.pack.getCoremodsDir();
    if (coremodsDir != null && coremodsDir.exists()) {
        deleteMods(coremodsDir);
    }
    // HACK - jamioflan is a big jerk who needs to put his mods in the dang mod directory!
    File flansDir = new File(this.pack.getInstalledDirectory(), "Flan");
    if (flansDir.exists()) {
        deleteMods(flansDir);
    }
    File packOutput = this.pack.getInstalledDirectory();
    IZipFileFilter zipFilter = new ModpackZipFilter(this.pack);
    for (Mod mod : modpack.getMods()) {
        String url = mod.getUrl();
        String md5 = mod.getMd5();
        String version = mod.getVersion();
        String name;
        if (version != null) {
            name = mod.getName() + "-" + version + ".zip";
        } else {
            name = mod.getName() + ".zip";
        }
        File cache = new File(this.pack.getCacheDir(), name);
        IFileVerifier verifier = null;
        if (md5 != null && !md5.isEmpty())
            verifier = new MD5FileVerifier(md5);
        else
            verifier = new ValidZipFileVerifier();
        checkModQueue.addTask(new EnsureFileTask(cache, verifier, packOutput, url, downloadModQueue, copyModQueue, zipFilter));
    }
    copyModQueue.addTask(new CleanupModpackCacheTask(this.pack, modpack));
}
Also used : EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) ModpackZipFilter(net.technicpack.minecraftcore.install.ModpackZipFilter) Mod(net.technicpack.rest.io.Mod) ValidZipFileVerifier(net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) File(java.io.File) IZipFileFilter(net.technicpack.utilslib.IZipFileFilter) MD5FileVerifier(net.technicpack.launchercore.install.verifiers.MD5FileVerifier)

Example 2 with EnsureFileTask

use of net.technicpack.launchercore.install.tasks.EnsureFileTask in project LauncherV3 by TechnicPack.

the class InstallMinecraftAssetsTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    String json = FileUtils.readFileToString(assetsIndex, StandardCharsets.UTF_8);
    JsonObject obj = MojangUtils.getGson().fromJson(json, JsonObject.class);
    if (obj == null) {
        throw new DownloadException("The assets json file was invalid.");
    }
    boolean isVirtual = false;
    if (obj.get(virtualField) != null)
        isVirtual = obj.get(virtualField).getAsBoolean();
    boolean mapToResources = false;
    if (obj.get(mapToResourcesField) != null)
        mapToResources = obj.get(mapToResourcesField).getAsBoolean();
    ((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAreAssetsVirtual(isVirtual);
    ((InstallTasksQueue<MojangVersion>) queue).getMetadata().setAssetsMapToResources(mapToResources);
    JsonObject allObjects = obj.get(objectsField).getAsJsonObject();
    if (allObjects == null) {
        throw new DownloadException("The assets json file was invalid.");
    }
    String assetsKey = ((InstallTasksQueue<MojangVersion>) queue).getMetadata().getAssetsKey();
    if (assetsKey == null || assetsKey.isEmpty())
        assetsKey = "legacy";
    for (Map.Entry<String, JsonElement> field : allObjects.entrySet()) {
        String friendlyName = field.getKey();
        JsonObject file = field.getValue().getAsJsonObject();
        String hash = file.get(hashField).getAsString();
        long size = file.get(sizeField).getAsLong();
        File location = new File(assetsDirectory + "/objects/" + hash.substring(0, 2), hash);
        String url = MojangUtils.getResourceUrl(hash);
        (new File(location.getParent())).mkdirs();
        File target = null;
        if (isVirtual)
            target = new File(assetsDirectory + "/virtual/" + assetsKey + '/' + friendlyName);
        else if (mapToResources)
            target = new File(modpack.getResourcesDir(), friendlyName);
        checkAssetsQueue.addTask(new EnsureFileTask(location, new FileSizeVerifier(size), null, url, hash, downloadAssetsQueue, copyAssetsQueue));
        if (target != null && !target.exists()) {
            (new File(target.getParent())).mkdirs();
            copyAssetsQueue.addTask(new CopyFileTask(location, target));
        }
    }
}
Also used : EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) JsonObject(com.google.gson.JsonObject) CopyFileTask(net.technicpack.launchercore.install.tasks.CopyFileTask) JsonElement(com.google.gson.JsonElement) DownloadException(net.technicpack.launchercore.exception.DownloadException) FileSizeVerifier(net.technicpack.launchercore.install.verifiers.FileSizeVerifier) Map(java.util.Map) File(java.io.File)

Example 3 with EnsureFileTask

use of net.technicpack.launchercore.install.tasks.EnsureFileTask in project LauncherV3 by TechnicPack.

the class InstallVersionLibTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    super.runTask(queue);
    queue.refreshProgress();
    // Native classifier as in the library's downloads -> classifiers -> $nativeClassifier
    // (the mapping of which is taken from the library's natives map)
    String nativeClassifier = null;
    File extractDirectory = null;
    if (library.getNatives() != null) {
        nativeClassifier = library.getNatives().get(OperatingSystem.getOperatingSystem());
        if (nativeClassifier != null) {
            extractDirectory = new File(this.pack.getBinDir(), "natives");
        }
    }
    String path = library.getArtifactPath(nativeClassifier).replace("${arch}", JavaUtils.getJavaBitness());
    File cache = new File(directories.getCacheDirectory(), path);
    if (cache.getParentFile() != null) {
        cache.getParentFile().mkdirs();
    }
    IFileVerifier verifier;
    String sha1 = library.getArtifactSha1(nativeClassifier);
    if (sha1 != null && !sha1.isEmpty())
        verifier = new SHA1FileVerifier(sha1);
    else
        verifier = new ValidZipFileVerifier();
    // TODO: Add check based on size (so it fails early if the size is different)
    if (cache.exists() && verifier.isFileValid(cache) && extractDirectory == null)
        return;
    String url = null;
    // TODO: this causes verification to happen twice, for natives
    if (!cache.exists() || !verifier.isFileValid(cache)) {
        url = library.getDownloadUrl(path).replace("${arch}", JavaUtils.getJavaBitness());
        if (sha1 == null || sha1.isEmpty()) {
            String md5 = Utils.getETag(url);
            if (md5 != null && !md5.isEmpty()) {
                verifier = new MD5FileVerifier(md5);
            }
        }
    }
    IZipFileFilter filter = null;
    if (library.getExtract() != null)
        filter = new ExtractRulesFileFilter(library.getExtract());
    grabQueue.addTask(new EnsureFileTask(cache, verifier, extractDirectory, url, downloadLibraryQueue, copyLibraryQueue, filter));
}
Also used : ExtractRulesFileFilter(net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter) EnsureFileTask(net.technicpack.launchercore.install.tasks.EnsureFileTask) ValidZipFileVerifier(net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) File(java.io.File) MD5FileVerifier(net.technicpack.launchercore.install.verifiers.MD5FileVerifier)

Example 4 with EnsureFileTask

use of net.technicpack.launchercore.install.tasks.EnsureFileTask 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)4 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)4 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)3 DownloadException (net.technicpack.launchercore.exception.DownloadException)2 MD5FileVerifier (net.technicpack.launchercore.install.verifiers.MD5FileVerifier)2 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)2 ValidZipFileVerifier (net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Map (java.util.Map)1 CopyFileTask (net.technicpack.launchercore.install.tasks.CopyFileTask)1 EnsureLinkedFileTask (net.technicpack.launchercore.install.tasks.EnsureLinkedFileTask)1 FileSizeVerifier (net.technicpack.launchercore.install.verifiers.FileSizeVerifier)1 ModpackZipFilter (net.technicpack.minecraftcore.install.ModpackZipFilter)1 JavaRuntimeManifest (net.technicpack.minecraftcore.mojang.java.JavaRuntimeManifest)1 ExtractRulesFileFilter (net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 Download (net.technicpack.minecraftcore.mojang.version.io.Download)1 Mod (net.technicpack.rest.io.Mod)1 IZipFileFilter (net.technicpack.utilslib.IZipFileFilter)1