Search in sources :

Example 1 with IFileVerifier

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

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

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

the class InstallMinecraftIfNecessaryTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    super.runTask(queue);
    MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
    String url;
    GameDownloads dls = version.getDownloads();
    IFileVerifier verifier = null;
    if (dls != null) {
        url = dls.forClient().getUrl();
        verifier = new SHA1FileVerifier(dls.forClient().getSha1());
    } else {
        url = MojangUtils.getOldVersionDownload(this.minecraftVersion);
        Utils.getLogger().log(Level.SEVERE, "Using legacy Minecraft download! Version id = " + version.getId() + "; parent = " + version.getParentVersion());
        String md5 = Utils.getETag(url);
        if (md5 != null && !md5.isEmpty()) {
            verifier = new MD5FileVerifier(md5);
        } else {
            verifier = new ValidZipFileVerifier();
        }
    }
    File cache = new File(cacheDirectory, "minecraft_" + this.minecraftVersion + ".jar");
    if (!cache.exists() || !verifier.isFileValid(cache)) {
        String output = this.pack.getCacheDir() + File.separator + "minecraft.jar";
        Utils.downloadFile(url, cache.getName(), output, cache, verifier, this);
    }
    MojangUtils.copyMinecraftJar(cache, new File(this.pack.getBinDir(), "minecraft.jar"));
}
Also used : ValidZipFileVerifier(net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) GameDownloads(net.technicpack.minecraftcore.mojang.version.io.GameDownloads) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) File(java.io.File) MD5FileVerifier(net.technicpack.launchercore.install.verifiers.MD5FileVerifier)

Example 4 with IFileVerifier

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

the class EnsureAssetsIndexTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException {
    MojangVersion version = ((InstallTasksQueue<MojangVersion>) queue).getMetadata();
    String assetKey = version.getAssetsKey();
    if (assetKey == null || assetKey.isEmpty()) {
        assetKey = "legacy";
    }
    String assetsUrl;
    AssetIndex assetIndex = version.getAssetIndex();
    if (assetIndex != null) {
        assetsUrl = assetIndex.getUrl();
    } else {
        assetsUrl = MojangUtils.getAssetsIndex(assetKey);
    }
    File output = new File(assetsDirectory + File.separator + "indexes", assetKey + ".json");
    (new File(output.getParent())).mkdirs();
    IFileVerifier fileVerifier;
    if (assetIndex != null && assetIndex.getSha1() != null)
        fileVerifier = new SHA1FileVerifier(assetIndex.getSha1());
    else
        fileVerifier = new ValidJsonFileVerifier(MojangUtils.getGson());
    if (!output.exists() || !fileVerifier.isFileValid(output)) {
        downloadIndexQueue.addTask(new DownloadFileTask(assetsUrl, output, fileVerifier));
    }
    examineIndexQueue.addTask(new InstallMinecraftAssetsTask(modpack, assetsDirectory.getAbsolutePath(), output, checkAssetsQueue, downloadAssetsQueue, installAssetsQueue));
}
Also used : MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) AssetIndex(net.technicpack.minecraftcore.mojang.version.io.AssetIndex) IFileVerifier(net.technicpack.launchercore.install.verifiers.IFileVerifier) ValidJsonFileVerifier(net.technicpack.launchercore.install.verifiers.ValidJsonFileVerifier) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) SHA1FileVerifier(net.technicpack.launchercore.install.verifiers.SHA1FileVerifier) File(java.io.File) DownloadFileTask(net.technicpack.launchercore.install.tasks.DownloadFileTask)

Example 5 with IFileVerifier

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

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