Search in sources :

Example 1 with PackInfo

use of net.technicpack.rest.io.PackInfo in project LauncherV3 by TechnicPack.

the class PackLoadJob method run.

@Override
public void run() {
    int threadCount = 0;
    if (doLoadRepository)
        threadCount++;
    if (packSources != null)
        threadCount += packSources.size();
    Collection<Thread> threads = new ArrayList<Thread>(threadCount);
    if (doLoadRepository) {
        for (final String packName : packRepository.getPackNames()) {
            InstalledPack pack = packRepository.getInstalledPacks().get(packName);
            addPackThreadSafe(pack, null, -1);
        }
    }
    if (packSources != null) {
        for (final IPackSource packSource : packSources) {
            Thread packSourceThread = new Thread(packSource.getSourceName() + " Loading Thread") {

                @Override
                public void run() {
                    for (PackInfo info : packSource.getPublicPacks()) {
                        addPackThreadSafe(null, info, packSource.getPriority(info));
                    }
                }
            };
            threads.add(packSourceThread);
            packSourceThread.start();
        }
    }
    for (Thread thread : threads) {
        try {
            thread.join();
        } catch (InterruptedException ex) {
        }
    }
    refreshCompleteThreadSafe();
}
Also used : IPackSource(net.technicpack.launchercore.modpacks.sources.IPackSource) PackInfo(net.technicpack.rest.io.PackInfo) ArrayList(java.util.ArrayList)

Example 2 with PackInfo

use of net.technicpack.rest.io.PackInfo in project LauncherV3 by TechnicPack.

the class ModpackSelector method selectWidget.

protected void selectWidget(ModpackWidget widget) {
    if (selectedWidget != null)
        selectedWidget.setIsSelected(false);
    selectedWidget = widget;
    selectedWidget.setIsSelected(true);
    selectedWidget.getModpack().select();
    selectedWidget.scrollRectToVisible(new Rectangle(selectedWidget.getSize()));
    if (modpackInfoPanel != null)
        modpackInfoPanel.setModpack(widget.getModpack());
    final ModpackWidget refreshWidget = selectedWidget;
    Thread thread = new Thread("Modpack redownload " + selectedWidget.getModpack().getDisplayName()) {

        @Override
        public void run() {
            try {
                PlatformPackInfo updatedInfo = platformApi.getPlatformPackInfo(refreshWidget.getModpack().getName());
                PackInfo infoToUse = updatedInfo;
                if (updatedInfo != null && updatedInfo.hasSolder()) {
                    try {
                        ISolderPackApi solderPack = solderApi.getSolderPack(updatedInfo.getSolder(), updatedInfo.getName(), solderApi.getMirrorUrl(updatedInfo.getSolder()));
                        infoToUse = new CombinedPackInfo(solderPack.getPackInfo(), updatedInfo);
                    } catch (RestfulAPIException ex) {
                    }
                }
                if (infoToUse != null)
                    refreshWidget.getModpack().setPackInfo(infoToUse);
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        if (modpackInfoPanel != null)
                            modpackInfoPanel.setModpackIfSame(refreshWidget.getModpack());
                        if (refreshWidget.getModpack().hasRecommendedUpdate()) {
                            refreshWidget.setToolTipText(resources.getString("launcher.packselector.updatetip"));
                        } else {
                            refreshWidget.setToolTipText(null);
                        }
                        iconRepo.refreshRetry(refreshWidget.getModpack());
                        refreshWidget.updateFromPack(iconRepo.startImageJob(refreshWidget.getModpack()));
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                revalidate();
                                repaint();
                            }
                        });
                    }
                });
            } catch (RestfulAPIException ex) {
                ex.printStackTrace();
                return;
            }
        }
    };
    thread.start();
}
Also used : RestfulAPIException(net.technicpack.rest.RestfulAPIException) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) CombinedPackInfo(net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo) CombinedPackInfo(net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) PackInfo(net.technicpack.rest.io.PackInfo) ISolderPackApi(net.technicpack.solder.ISolderPackApi) ModpackWidget(net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)

Example 3 with PackInfo

use of net.technicpack.rest.io.PackInfo in project LauncherV3 by TechnicPack.

the class PackLoadJob method addPack.

protected void addPack(final InstalledPack pack, final PackInfo packInfo, final int priority) {
    if (pack == null && packInfo == null || isCancelled)
        return;
    String name = (pack != null) ? pack.getName() : packInfo.getName();
    ModpackModel modpack = null;
    boolean newModpackModel = true;
    if (processedModpacks.containsKey(name)) {
        modpack = processedModpacks.get(name);
        newModpackModel = false;
        if (modpack.getInstalledPack() == null && pack != null) {
            modpack.setInstalledPack(pack, packRepository);
        }
        if (packInfo != null) {
            modpack.setPackInfo(packInfo);
            modpack.updatePriority(priority);
        }
    } else {
        modpack = new ModpackModel(pack, packInfo, packRepository, directories);
        modpack.updatePriority(priority);
        if (packInfo == null)
            modpack.setIsPlatform(false);
        processedModpacks.put(name, modpack);
    }
    if (modpack.getInstalledPack() == null && !doLoadRepository && packRepository.getInstalledPacks().containsKey(modpack.getName())) {
        modpack.setInstalledPack(packRepository.getInstalledPacks().get(modpack.getName()), packRepository);
    }
    Runnable fillDataMethod = null;
    if (modpack.getPackInfo() == null) {
        fillDataMethod = new Runnable() {

            @Override
            public void run() {
                PackInfo completeInfo = authoritativeSource.getPackInfo(pack);
                if (completeInfo != null) {
                    addPackThreadSafe(null, completeInfo, priority);
                }
            }
        };
    } else if (!modpack.getPackInfo().isComplete()) {
        fillDataMethod = new Runnable() {

            @Override
            public void run() {
                PackInfo completeInfo = authoritativeSource.getCompletePackInfo(packInfo);
                if (completeInfo != null) {
                    addPackThreadSafe(null, completeInfo, priority);
                }
            }
        };
    }
    if (fillDataMethod != null) {
        Thread thread = new Thread(fillDataMethod);
        thread.start();
    }
    if (modpack != null && tagBuilder != null)
        modpack.updateTags(tagBuilder);
    if (newModpackModel)
        container.addModpackToContainer(modpack);
    else
        container.replaceModpackInContainer(modpack);
}
Also used : PackInfo(net.technicpack.rest.io.PackInfo)

Example 4 with PackInfo

use of net.technicpack.rest.io.PackInfo 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 PackInfo

use of net.technicpack.rest.io.PackInfo in project LauncherV3 by TechnicPack.

the class SearchResultPackSource method getPublicPacks.

@Override
public // Get PlatformPackInfo objects for every result from the given search terms.
Collection<PackInfo> getPublicPacks() {
    resultPriorities.clear();
    // Get results from server
    SearchResultsData results = null;
    try {
        results = platformApi.getSearchResults(searchTerms);
    } catch (RestfulAPIException ex) {
        return Collections.emptySet();
    }
    ArrayList<PackInfo> resultPacks = new ArrayList<PackInfo>(results.getResults().length);
    int priority = 100;
    for (SearchResult result : results.getResults()) {
        resultPacks.add(new SearchResultPackInfo(result));
        resultPriorities.put(result.getSlug(), priority--);
    }
    return resultPacks;
}
Also used : RestfulAPIException(net.technicpack.rest.RestfulAPIException) PackInfo(net.technicpack.rest.io.PackInfo) SearchResult(net.technicpack.platform.io.SearchResult) SearchResultsData(net.technicpack.platform.io.SearchResultsData)

Aggregations

PackInfo (net.technicpack.rest.io.PackInfo)7 RestfulAPIException (net.technicpack.rest.RestfulAPIException)3 ArrayList (java.util.ArrayList)2 CombinedPackInfo (net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo)2 PlatformPackInfo (net.technicpack.platform.io.PlatformPackInfo)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 ModpackWidget (net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)1 CacheDeleteException (net.technicpack.launchercore.exception.CacheDeleteException)1 Version (net.technicpack.launchercore.install.Version)1 MD5FileVerifier (net.technicpack.launchercore.install.verifiers.MD5FileVerifier)1 ValidZipFileVerifier (net.technicpack.launchercore.install.verifiers.ValidZipFileVerifier)1 IJavaVersion (net.technicpack.launchercore.launch.java.IJavaVersion)1 IPackSource (net.technicpack.launchercore.modpacks.sources.IPackSource)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 SearchResult (net.technicpack.platform.io.SearchResult)1 SearchResultsData (net.technicpack.platform.io.SearchResultsData)1 Modpack (net.technicpack.rest.io.Modpack)1 ISolderPackApi (net.technicpack.solder.ISolderPackApi)1