Search in sources :

Example 1 with PlatformPackInfo

use of net.technicpack.platform.io.PlatformPackInfo 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 2 with PlatformPackInfo

use of net.technicpack.platform.io.PlatformPackInfo in project LauncherV3 by TechnicPack.

the class ModpackCachePlatformApi method pullAndCache.

private PlatformPackInfo pullAndCache(String packSlug) throws RestfulAPIException {
    PlatformPackInfo info = null;
    try {
        info = innerApi.getPlatformPackInfoForBulk(packSlug);
        if (info != null) {
            cache.put(packSlug, info);
            foreverCache.put(packSlug, info);
            saveForeverCache(info);
        }
    } finally {
        deadPacks.put(packSlug, info == null);
    }
    return info;
}
Also used : PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo)

Example 3 with PlatformPackInfo

use of net.technicpack.platform.io.PlatformPackInfo in project LauncherV3 by TechnicPack.

the class ModpackCachePlatformApi method loadForeverCache.

private PlatformPackInfo loadForeverCache(String packSlug) {
    File cacheFile = new File(new File(new File(directories.getAssetsDirectory(), "packs"), packSlug), "cache.json");
    if (!cacheFile.exists())
        return null;
    try {
        String packCache = FileUtils.readFileToString(cacheFile, StandardCharsets.UTF_8);
        PlatformPackInfo info = Utils.getGson().fromJson(packCache, PlatformPackInfo.class);
        if (info != null) {
            foreverCache.put(packSlug, info);
        }
        return info;
    } catch (IOException ex) {
        return null;
    } catch (JsonSyntaxException ex) {
        return null;
    }
}
Also used : PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) File(java.io.File)

Example 4 with PlatformPackInfo

use of net.technicpack.platform.io.PlatformPackInfo in project LauncherV3 by TechnicPack.

the class PlatformPackInfoRepository method getPlatformPackInfo.

protected PackInfo getPlatformPackInfo(String slug) {
    try {
        PackInfo info = null;
        PlatformPackInfo platformInfo = platform.getPlatformPackInfoForBulk(slug);
        info = getInfoFromPlatformInfo(platformInfo);
        return info;
    } catch (RestfulAPIException ex) {
        Utils.getLogger().log(Level.WARNING, "Unable to load platform pack " + slug, ex);
        return null;
    }
}
Also used : RestfulAPIException(net.technicpack.rest.RestfulAPIException) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) PackInfo(net.technicpack.rest.io.PackInfo) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) CombinedPackInfo(net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo) SolderPackInfo(net.technicpack.solder.io.SolderPackInfo)

Aggregations

PlatformPackInfo (net.technicpack.platform.io.PlatformPackInfo)4 CombinedPackInfo (net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo)2 RestfulAPIException (net.technicpack.rest.RestfulAPIException)2 PackInfo (net.technicpack.rest.io.PackInfo)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 File (java.io.File)1 IOException (java.io.IOException)1 ModpackWidget (net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)1 ISolderPackApi (net.technicpack.solder.ISolderPackApi)1 SolderPackInfo (net.technicpack.solder.io.SolderPackInfo)1