Search in sources :

Example 1 with ExtractRulesFileFilter

use of net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter 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)1 EnsureFileTask (net.technicpack.launchercore.install.tasks.EnsureFileTask)1 IFileVerifier (net.technicpack.launchercore.install.verifiers.IFileVerifier)1 MD5FileVerifier (net.technicpack.launchercore.install.verifiers.MD5FileVerifier)1 SHA1FileVerifier (net.technicpack.launchercore.install.verifiers.SHA1FileVerifier)1 ValidZipFileVerifier (net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier)1 ExtractRulesFileFilter (net.technicpack.minecraftcore.mojang.version.ExtractRulesFileFilter)1