Search in sources :

Example 1 with ZipFileRetriever

use of net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever in project LauncherV3 by TechnicPack.

the class HandleVersionFileTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    MojangVersion version = versionBuilder.buildVersionFromKey(null);
    if (version == null) {
        throw new DownloadException("The version.json file was invalid.");
    }
    // if MC < 1.6, we inject LegacyWrapper
    // HACK
    boolean isLegacy = MojangUtils.isLegacyVersion(version.getId());
    if (isLegacy) {
        Library legacyWrapper = new Library();
        legacyWrapper.setName("net.technicpack:legacywrapper:1.2.1");
        legacyWrapper.setUrl("https://mirror.technicpack.net/Technic/lib/");
        version.addLibrary(legacyWrapper);
        version.setMainClass("net.technicpack.legacywrapper.Launch");
    }
    // In Forge 1.13+ and 1.12.2 > 2847, there's an installer jar, and the universal jar can't be used since it
    // doesn't have the required dependencies to actually launch the game.
    // So, for Forge 1.13+ we need to use ForgeWrapper to install Forge (it performs deobfuscation at install time).
    // For Forge 1.12.2 it launches directly, as long as we inject the universal jar (it won't launch at all if
    // you try running it through ForgeWrapper).
    final boolean hasModernForge = MojangUtils.hasModernForge(version);
    if (hasModernForge) {
        File profileJson = new File(pack.getBinDir(), "install_profile.json");
        ZipFileRetriever zipVersionRetriever = new ZipFileRetriever(new File(pack.getBinDir(), "modpack.jar"));
        MojangVersion profileVersion = new FileVersionBuilder(profileJson, zipVersionRetriever, null).buildVersionFromKey("install_profile");
        final String[] versionIdParts = version.getId().split("-", 3);
        final boolean is1_12_2 = versionIdParts[0].equals("1.12.2");
        for (Library library : profileVersion.getLibrariesForOS()) {
            if (library.isForge()) {
                // For Forge 1.12.2 > 2847, we have to inject the universal jar as a dependency
                if (is1_12_2) {
                    library.setName(library.getName() + ":universal");
                    library.setUrl("https://files.minecraftforge.net/maven/");
                    // Add the mutated library
                    version.addLibrary(library);
                    checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                }
                // We normally skip Forge because Forge specifies itself as a dependency, for some reason
                continue;
            }
            checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
        }
        // For Forge 1.13+, we inject our ForgeWrapper as a dependency and launch it through that
        if (!is1_12_2) {
            Library forgeWrapper = new Library();
            // TODO: add hash validation
            forgeWrapper.setName("io.github.zekerzhayard:ForgeWrapper:1.5.1");
            version.addLibrary(forgeWrapper);
            version.setMainClass("io.github.zekerzhayard.forgewrapper.installer.Main");
            for (Library library : version.getLibrariesForOS()) {
                if (library.isForge()) {
                    Library forgeLauncher = new Library();
                    forgeLauncher.setName(library.getName() + ":launcher");
                    forgeLauncher.setUrl("https://files.minecraftforge.net/maven/");
                    version.addLibrary(forgeLauncher);
                    checkLibraryQueue.addTask(new InstallVersionLibTask(forgeLauncher, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                    Library forgeUniversal = new Library();
                    forgeUniversal.setName(library.getName() + ":universal");
                    forgeUniversal.setUrl("https://files.minecraftforge.net/maven/");
                    checkLibraryQueue.addTask(new InstallVersionLibTask(forgeUniversal, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                    break;
                }
            }
        }
    }
    for (Library library : version.getLibrariesForOS()) {
        // or at least only do it if the users are sticking with modpack.jar
        if (library.isForge()) {
            continue;
        }
        if (isLegacy && library.getName().startsWith("net.minecraft:launchwrapper")) {
            continue;
        }
        // And version 2.16.0 for >= 1.12
        if (library.isLog4j()) {
            final String[] libNameParts = library.getName().split(":");
            // org.apache.logging.log4j:log4j-core:2.0-beta9
            // org.apache.logging.log4j    log4j-core        2.0-beta9
            // Determine what version we need
            String log4jVersion = "2.16.0";
            if (libNameParts[2].equals("2.0-beta9")) {
                log4jVersion = "2.0-beta9-fixed";
            }
            String sha1;
            int size;
            String artifactName = libNameParts[1];
            switch(log4jVersion) {
                case "2.16.0":
                    switch(artifactName) {
                        case "log4j-api":
                            sha1 = "f821a18687126c2e2f227038f540e7953ad2cc8c";
                            size = 301892;
                            break;
                        case "log4j-core":
                            sha1 = "539a445388aee52108700f26d9644989e7916e7c";
                            size = 1789565;
                            break;
                        case "log4j-slf4j18-impl":
                            sha1 = "0c880a059056df5725f5d8d1035276d9749eba6d";
                            size = 21249;
                            break;
                        default:
                            throw new RuntimeException("Unknown log4j artifact " + artifactName + ", cannot continue");
                    }
                    break;
                case "2.0-beta9-fixed":
                    switch(artifactName) {
                        case "log4j-api":
                            sha1 = "b61eaf2e64d8b0277e188262a8b771bbfa1502b3";
                            size = 107347;
                            break;
                        case "log4j-core":
                            sha1 = "677991ea2d7426f76309a73739cecf609679492c";
                            size = 677588;
                            break;
                        default:
                            throw new RuntimeException("Unknown log4j artifact " + artifactName + ", cannot continue");
                    }
                    break;
                default:
                    throw new RuntimeException("Unknown log4j version " + log4jVersion + ", cannot continue");
            }
            String url = String.format("https://mirror.technicpack.net/Technic/lib/org/apache/logging/log4j/%1$s/%2$s/%1$s-%2$s.jar", artifactName, log4jVersion);
            Library fixedLog4j = new Library();
            fixedLog4j.setName("org.apache.logging.log4j:" + artifactName + ":" + log4jVersion);
            Artifact artifact = new Artifact(url, sha1, size);
            Downloads downloads = new Downloads();
            downloads.setArtifact(artifact);
            fixedLog4j.setDownloads(downloads);
            // Add fixed lib
            version.addLibrary(fixedLog4j);
            checkLibraryQueue.addTask(new InstallVersionLibTask(fixedLog4j, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
            // Remove unpatched lib
            version.removeLibrary(library.getName());
            continue;
        }
        checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
    }
    queue.setMetadata(version);
}
Also used : FileVersionBuilder(net.technicpack.minecraftcore.mojang.version.builder.FileVersionBuilder) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) Artifact(net.technicpack.minecraftcore.mojang.version.io.Artifact) ZipFileRetriever(net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever) DownloadException(net.technicpack.launchercore.exception.DownloadException) Library(net.technicpack.minecraftcore.mojang.version.io.Library) Downloads(net.technicpack.minecraftcore.mojang.version.io.Downloads) File(java.io.File)

Example 2 with ZipFileRetriever

use of net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever in project LauncherV3 by TechnicPack.

the class Installer method createVersionBuilder.

private MojangVersionBuilder createVersionBuilder(ModpackModel modpack, InstallTasksQueue tasksQueue) {
    ZipFileRetriever zipVersionRetriever = new ZipFileRetriever(new File(modpack.getBinDir(), "modpack.jar"));
    HttpFileRetriever fallbackVersionRetriever = new HttpFileRetriever(TechnicConstants.technicVersions, tasksQueue.getDownloadListener());
    ArrayList<MojangVersionRetriever> fallbackRetrievers = new ArrayList<MojangVersionRetriever>(1);
    fallbackRetrievers.add(fallbackVersionRetriever);
    File versionJson = new File(modpack.getBinDir(), "version.json");
    // This always gets the version.json from the modpack.jar (it ignores "key"), cached as bin/version.json
    FileVersionBuilder zipVersionBuilder = new FileVersionBuilder(versionJson, zipVersionRetriever, fallbackRetrievers);
    // This gets the "key" from bin/$key.json if it exists, otherwise it downloads it from our repo into that location
    FileVersionBuilder webVersionBuilder = new FileVersionBuilder(modpack.getBinDir(), null, fallbackRetrievers);
    return new ChainVersionBuilder(zipVersionBuilder, webVersionBuilder);
}
Also used : ZipFileRetriever(net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever) FileVersionBuilder(net.technicpack.minecraftcore.mojang.version.builder.FileVersionBuilder) ArrayList(java.util.ArrayList) ChainVersionBuilder(net.technicpack.minecraftcore.mojang.version.chain.ChainVersionBuilder) File(java.io.File) HttpFileRetriever(net.technicpack.minecraftcore.mojang.version.builder.retrievers.HttpFileRetriever) MojangVersionRetriever(net.technicpack.minecraftcore.mojang.version.builder.MojangVersionRetriever)

Aggregations

File (java.io.File)2 FileVersionBuilder (net.technicpack.minecraftcore.mojang.version.builder.FileVersionBuilder)2 ZipFileRetriever (net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever)2 ArrayList (java.util.ArrayList)1 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 MojangVersionRetriever (net.technicpack.minecraftcore.mojang.version.builder.MojangVersionRetriever)1 HttpFileRetriever (net.technicpack.minecraftcore.mojang.version.builder.retrievers.HttpFileRetriever)1 ChainVersionBuilder (net.technicpack.minecraftcore.mojang.version.chain.ChainVersionBuilder)1 Artifact (net.technicpack.minecraftcore.mojang.version.io.Artifact)1 Downloads (net.technicpack.minecraftcore.mojang.version.io.Downloads)1 Library (net.technicpack.minecraftcore.mojang.version.io.Library)1