Search in sources :

Example 1 with RestfulAPIException

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

use of net.technicpack.rest.RestfulAPIException in project LauncherV3 by TechnicPack.

the class InitialV3Migrator method migrate.

@Override
public void migrate(TechnicSettings settings, IInstalledPackRepository packStore, LauncherDirectories directories, IUserStore<MojangUser> users) {
    // A fresh install/upgrade from v2 shouldn't show the latest news as being new
    int maxNewsId = 0;
    try {
        for (NewsArticle article : platformApi.getNews().getArticles()) {
            int newsId = article.getId();
            if (newsId > maxNewsId)
                maxNewsId = newsId;
        }
        settings.setLatestNewsArticle(maxNewsId);
    } catch (RestfulAPIException ex) {
    // Just kill the exception & go with ID 0
    }
    List<ModpackModel> deletePacks = new LinkedList<ModpackModel>();
    for (String packName : packStore.getPackNames()) {
        InstalledPack pack = packStore.getInstalledPacks().get(packName);
        ModpackModel model = new ModpackModel(pack, null, packStore, directories);
        if (!model.getInstalledDirectory().exists()) {
            deletePacks.add(model);
        }
    }
    for (ModpackModel deletePack : deletePacks) {
        deletePack.delete();
    }
    packStore.save();
}
Also used : InstalledPack(net.technicpack.launchercore.modpacks.InstalledPack) RestfulAPIException(net.technicpack.rest.RestfulAPIException) NewsArticle(net.technicpack.platform.io.NewsArticle) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) LinkedList(java.util.LinkedList)

Aggregations

RestfulAPIException (net.technicpack.rest.RestfulAPIException)2 LinkedList (java.util.LinkedList)1 ModpackWidget (net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)1 InstalledPack (net.technicpack.launchercore.modpacks.InstalledPack)1 ModpackModel (net.technicpack.launchercore.modpacks.ModpackModel)1 CombinedPackInfo (net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo)1 NewsArticle (net.technicpack.platform.io.NewsArticle)1 PlatformPackInfo (net.technicpack.platform.io.PlatformPackInfo)1 PackInfo (net.technicpack.rest.io.PackInfo)1 ISolderPackApi (net.technicpack.solder.ISolderPackApi)1