Search in sources :

Example 1 with MD5FileVerifier

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

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

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

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

the class Installer method buildTasksQueue.

public void buildTasksQueue(InstallTasksQueue queue, ResourceLoader resources, ModpackModel modpack, String build, boolean doFullInstall, MojangVersionBuilder versionBuilder) throws CacheDeleteException, BuildInaccessibleException {
    PackInfo packInfo = modpack.getPackInfo();
    Modpack modpackData = packInfo.getModpack(build);
    if (modpackData.getGameVersion() == null)
        return;
    String minecraft = modpackData.getGameVersion();
    Version installedVersion = modpack.getInstalledVersion();
    TaskGroup examineModpackData = new TaskGroup(resources.getString("install.message.examiningmodpack"));
    TaskGroup verifyingFiles = new TaskGroup(resources.getString("install.message.verifyingfiles"));
    TaskGroup downloadingMods = new TaskGroup(resources.getString("install.message.downloadmods"));
    TaskGroup installingMods = new TaskGroup(resources.getString("install.message.installmods"));
    TaskGroup checkVersionFile = new TaskGroup(resources.getString("install.message.checkversionfile"));
    TaskGroup installVersionFile = new TaskGroup(resources.getString("install.message.installversionfile"));
    TaskGroup rundataTaskGroup = new TaskGroup(resources.getString("install.message.runData"));
    TaskGroup examineVersionFile = new TaskGroup(resources.getString("install.message.examiningversionfile"));
    TaskGroup grabLibs = new TaskGroup(resources.getString("install.message.grablibraries"));
    TaskGroup checkNonMavenLibs = new TaskGroup(resources.getString("install.message.nonmavenlibs"));
    TaskGroup installingLibs = new TaskGroup(resources.getString("install.message.installlibs"));
    TaskGroup installingMinecraft = new TaskGroup(resources.getString("install.message.installminecraft"));
    TaskGroup examineIndex = new TaskGroup(resources.getString("install.message.examiningindex"));
    TaskGroup verifyingAssets = new TaskGroup(resources.getString("install.message.verifyassets"));
    TaskGroup installingAssets = new TaskGroup(resources.getString("install.message.installassets"));
    TaskGroup examineJava = new TaskGroup("Examining Java runtime...");
    TaskGroup downloadJava = new TaskGroup("Downloading Java runtime...");
    queue.addTask(examineModpackData);
    queue.addTask(verifyingFiles);
    queue.addTask(downloadingMods);
    queue.addTask(installingMods);
    queue.addTask(checkVersionFile);
    queue.addTask(installVersionFile);
    queue.addTask(rundataTaskGroup);
    queue.addTask(examineVersionFile);
    queue.addTask(grabLibs);
    queue.addTask(checkNonMavenLibs);
    queue.addTask(installingLibs);
    queue.addTask(installingMinecraft);
    queue.addTask(examineIndex);
    queue.addTask(verifyingAssets);
    queue.addTask(installingAssets);
    queue.addTask(examineJava);
    queue.addTask(downloadJava);
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.OSX)
        queue.addTask(new CopyDylibJnilibTask(modpack));
    // Add FML libs
    String fmlLibsZip;
    File modpackFmlLibDir = new File(modpack.getInstalledDirectory(), "lib");
    HashMap<String, String> fmlLibs = new HashMap<>();
    switch(minecraft) {
        case "1.4":
        case "1.4.1":
        case "1.4.2":
        case "1.4.3":
        case "1.4.4":
        case "1.4.5":
        case "1.4.6":
        case "1.4.7":
            fmlLibsZip = "fml_libs.zip";
            break;
        case "1.5":
            fmlLibsZip = "fml_libs15.zip";
            fmlLibs.put("deobfuscation_data_1.5.zip", "dba6d410a91a855f3b84457c86a8132a");
            break;
        case "1.5.1":
            fmlLibsZip = "fml_libs15.zip";
            fmlLibs.put("deobfuscation_data_1.5.1.zip", "c4fc2fedba60d920e4c7f9a095b2b883");
            break;
        case "1.5.2":
            fmlLibsZip = "fml_libs15.zip";
            fmlLibs.put("deobfuscation_data_1.5.2.zip", "270d9775872cc9fa773389812cab91fe");
            break;
        default:
            fmlLibsZip = "";
    }
    if (!fmlLibsZip.isEmpty()) {
        verifyingFiles.addTask(new EnsureFileTask(new File(directories.getCacheDirectory(), fmlLibsZip), new ValidZipFileVerifier(), modpackFmlLibDir, TechnicConstants.technicFmlLibRepo + fmlLibsZip, installingLibs, installingLibs));
    }
    if (!fmlLibs.isEmpty()) {
        fmlLibs.forEach((name, md5) -> {
            MD5FileVerifier verifier = null;
            if (!md5.isEmpty())
                verifier = new MD5FileVerifier(md5);
            File cached = new File(directories.getCacheDirectory(), name);
            File target = new File(modpackFmlLibDir, name);
            if (!target.exists() || (verifier != null && !verifier.isFileValid(target))) {
                verifyingFiles.addTask(new EnsureFileTask(cached, verifier, null, TechnicConstants.technicFmlLibRepo + name, installingLibs, installingLibs));
                installingLibs.addTask(new CopyFileTask(cached, target));
            }
        });
    }
    if (doFullInstall) {
        // If we're installing a new version of modpack, then we need to get rid of the existing version.json
        File versionFile = new File(modpack.getBinDir(), "version.json");
        if (versionFile.exists()) {
            if (!versionFile.delete()) {
                throw new CacheDeleteException(versionFile.getAbsolutePath());
            }
        }
        // Remove bin/install_profile.json, which is used by ForgeWrapper to install Forge in Minecraft 1.13+
        // (and the latest few Forge builds in 1.12.2)
        File installProfileFile = new File(modpack.getBinDir(), "install_profile.json");
        if (installProfileFile.exists()) {
            if (!installProfileFile.delete()) {
                throw new CacheDeleteException(installProfileFile.getAbsolutePath());
            }
        }
        // Delete all other version JSON files in the bin dir
        File[] binFiles = modpack.getBinDir().listFiles();
        if (binFiles != null) {
            final Pattern minecraftVersionPattern = Pattern.compile("^[0-9]+(\\.[0-9]+)+\\.json$");
            for (File binFile : binFiles) {
                if (minecraftVersionPattern.matcher(binFile.getName()).matches()) {
                    if (!binFile.delete()) {
                        throw new CacheDeleteException(binFile.getAbsolutePath());
                    }
                }
            }
        }
        // Remove the runData file between updates/reinstall as well
        File runData = new File(modpack.getBinDir(), "runData");
        if (runData.exists()) {
            if (!runData.delete()) {
                throw new CacheDeleteException(runData.getAbsolutePath());
            }
        }
        // Remove the bin/modpack.jar file
        // This prevents issues when upgrading a modpack between a version that has a modpack.jar, and
        // one that doesn't. One example of this is updating BareBonesPack from a Forge to a Fabric build.
        File modpackJar = new File(modpack.getBinDir(), "modpack.jar");
        if (modpackJar.exists()) {
            if (!modpackJar.delete()) {
                throw new CacheDeleteException(modpackJar.getAbsolutePath());
            }
        }
        examineModpackData.addTask(new CleanupAndExtractModpackTask(modpack, modpackData, verifyingFiles, downloadingMods, installingMods));
    }
    if (doFullInstall)
        rundataTaskGroup.addTask(new WriteRundataFile(modpack, modpackData));
    else
        rundataTaskGroup.addTask(new CheckRundataFile(modpack, modpackData, rundataTaskGroup));
    checkVersionFile.addTask(new VerifyVersionFilePresentTask(modpack, minecraft, versionBuilder));
    examineVersionFile.addTask(new HandleVersionFileTask(modpack, directories, checkNonMavenLibs, grabLibs, installingLibs, installingLibs, versionBuilder));
    examineVersionFile.addTask(new EnsureAssetsIndexTask(directories.getAssetsDirectory(), modpack, installingMinecraft, examineIndex, verifyingAssets, installingAssets, installingAssets));
    examineJava.addTask(new EnsureJavaRuntimeManifestTask(directories.getRuntimesDirectory(), modpack, examineJava, downloadJava));
    if (doFullInstall || (installedVersion != null && installedVersion.isLegacy()))
        installingMinecraft.addTask(new InstallMinecraftIfNecessaryTask(modpack, minecraft, directories.getCacheDirectory()));
}
Also used : Pattern(java.util.regex.Pattern) Modpack(net.technicpack.rest.io.Modpack) HashMap(java.util.HashMap) CacheDeleteException(net.technicpack.launchercore.exception.CacheDeleteException) MD5FileVerifier(net.technicpack.launchercore.install.verifiers.MD5FileVerifier) ValidZipFileVerifier(net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier) IJavaVersion(net.technicpack.launchercore.launch.java.IJavaVersion) Version(net.technicpack.launchercore.install.Version) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) PackInfo(net.technicpack.rest.io.PackInfo) File(java.io.File)

Example 5 with MD5FileVerifier

use of net.technicpack.launchercore.install.verifiers.MD5FileVerifier 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)5 MD5FileVerifier (net.technicpack.launchercore.install.verifiers.MD5FileVerifier)5 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)4 ValidZipFileVerifier (net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier)4 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)2 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)2 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)2 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 LauncherResource (net.technicpack.autoupdate.io.LauncherResource)1 StreamVersion (net.technicpack.autoupdate.io.StreamVersion)1 CacheDeleteException (net.technicpack.launchercore.exception.CacheDeleteException)1 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 InstallTasksQueue (net.technicpack.launchercore.install.InstallTasksQueue)1 Version (net.technicpack.launchercore.install.Version)1 DownloadFileTask (net.technicpack.launchercore.install.tasks.DownloadFileTask)1 IJavaVersion (net.technicpack.launchercore.launch.java.IJavaVersion)1 ModpackZipFilter (net.technicpack.minecraftcore.install.ModpackZipFilter)1 ExtractRulesFileFilter (net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter)1 GameDownloads (net.technicpack.minecraftcore.mojang.version.io.GameDownloads)1