Search in sources :

Example 1 with ModpackModel

use of net.technicpack.launchercore.modpacks.ModpackModel in project LauncherV3 by TechnicPack.

the class ModpackBanner method setModpack.

public void setModpack(ModpackModel modpack) {
    currentModpack = modpack;
    modpackName.setText(modpack.getDisplayName());
    modpackOptions.setVisible(!modpack.isLocalOnly() || modpack.getInstalledVersion() != null);
    Version packVersion = modpack.getInstalledVersion();
    if (packVersion == null) {
        updateReady.setVisible(false);
        versionText.setVisible(false);
        installedVersion.setVisible(false);
    } else {
        updateReady.setVisible(modpack.hasRecommendedUpdate());
        versionText.setVisible(true);
        installedVersion.setVisible(true);
        installedVersion.setText(packVersion.getVersion());
    }
    ImageJob<ModpackModel> job = iconRepo.startImageJob(modpack);
    job.addJobListener(this);
    BufferedImage icon = job.getImage();
    if (icon.getWidth() > 50 || icon.getHeight() > 50)
        icon = ImageUtils.scaleImage(icon, 50, 50);
    modpackIcon.setIcon(new ImageIcon(icon));
    rebuildTags(modpack);
}
Also used : Version(net.technicpack.launchercore.install.Version) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ModpackModel

use of net.technicpack.launchercore.modpacks.ModpackModel in project LauncherV3 by TechnicPack.

the class LauncherFrame method initComponents.

// ///////////////////////////////////////////////
// End Action responses
// ///////////////////////////////////////////////
private void initComponents() {
    BorderLayout layout = new BorderLayout();
    getRootPane().getContentPane().setLayout(layout);
    // ///////////////////////////////////////////////////////////
    // HEADER
    // ///////////////////////////////////////////////////////////
    JPanel header = new JPanel();
    header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS));
    header.setBackground(COLOR_BLUE);
    header.setForeground(COLOR_WHITE_TEXT);
    header.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10));
    getRootPane().getContentPane().add(header, BorderLayout.PAGE_START);
    ImageIcon headerIcon = resources.getIcon("platform_icon_title.png");
    JButton headerLabel = new JButton(headerIcon);
    headerLabel.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 0));
    headerLabel.setContentAreaFilled(false);
    headerLabel.setFocusPainted(false);
    headerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    headerLabel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DesktopUtils.browseUrl("https://www.technicpack.net/");
        }
    });
    header.add(headerLabel);
    header.add(Box.createRigidArea(new Dimension(6, 0)));
    ActionListener tabListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            selectTab(e.getActionCommand());
        }
    };
    discoverTab = new HeaderTab(resources.getString("launcher.title.discover"), resources);
    header.add(discoverTab);
    discoverTab.setActionCommand(TAB_DISCOVER);
    discoverTab.addActionListener(tabListener);
    modpacksTab = new HeaderTab(resources.getString("launcher.title.modpacks"), resources);
    modpacksTab.setIsActive(true);
    modpacksTab.setHorizontalTextPosition(SwingConstants.LEADING);
    modpacksTab.addActionListener(tabListener);
    modpacksTab.setActionCommand(TAB_MODPACKS);
    header.add(modpacksTab);
    newsTab = new HeaderTab(resources.getString("launcher.title.news"), resources);
    newsTab.setLayout(null);
    newsTab.addActionListener(tabListener);
    newsTab.setActionCommand(TAB_NEWS);
    header.add(newsTab);
    CountCircle newsCircle = new CountCircle();
    newsCircle.setBackground(COLOR_RED);
    newsCircle.setForeground(COLOR_WHITE_TEXT);
    newsCircle.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16, Font.BOLD));
    newsTab.add(newsCircle);
    newsCircle.setBounds(10, 17, 25, 25);
    header.add(Box.createHorizontalGlue());
    JPanel rightHeaderPanel = new JPanel();
    rightHeaderPanel.setOpaque(false);
    rightHeaderPanel.setLayout(new BoxLayout(rightHeaderPanel, BoxLayout.PAGE_AXIS));
    rightHeaderPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    JPanel windowGadgetPanel = new JPanel();
    windowGadgetPanel.setOpaque(false);
    windowGadgetPanel.setLayout(new BoxLayout(windowGadgetPanel, BoxLayout.LINE_AXIS));
    windowGadgetPanel.setAlignmentX(RIGHT_ALIGNMENT);
    ImageIcon minimizeIcon = resources.getIcon("minimize.png");
    JButton minimizeButton = new JButton(minimizeIcon);
    minimizeButton.setBorder(BorderFactory.createEmptyBorder());
    minimizeButton.setContentAreaFilled(false);
    minimizeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    minimizeButton.setFocusable(false);
    minimizeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            minimizeWindow();
        }
    });
    windowGadgetPanel.add(minimizeButton);
    ImageIcon closeIcon = resources.getIcon("close.png");
    JButton closeButton = new JButton(closeIcon);
    closeButton.setBorder(BorderFactory.createEmptyBorder());
    closeButton.setContentAreaFilled(false);
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeWindow();
        }
    });
    closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    closeButton.setFocusable(false);
    windowGadgetPanel.add(closeButton);
    rightHeaderPanel.add(windowGadgetPanel);
    rightHeaderPanel.add(Box.createVerticalGlue());
    JButton launcherOptionsLabel = new JButton(resources.getString("launcher.title.options"));
    launcherOptionsLabel.setIcon(resources.getIcon("options_cog.png"));
    launcherOptionsLabel.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 14));
    launcherOptionsLabel.setForeground(COLOR_WHITE_TEXT);
    launcherOptionsLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    launcherOptionsLabel.setHorizontalTextPosition(SwingConstants.LEADING);
    launcherOptionsLabel.setAlignmentX(RIGHT_ALIGNMENT);
    launcherOptionsLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    launcherOptionsLabel.setBorder(BorderFactory.createEmptyBorder());
    launcherOptionsLabel.setContentAreaFilled(false);
    launcherOptionsLabel.setFocusPainted(false);
    launcherOptionsLabel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            openLauncherOptions();
        }
    });
    rightHeaderPanel.add(launcherOptionsLabel);
    header.add(rightHeaderPanel);
    // ///////////////////////////////////////////////////////////
    // CENTRAL AREA
    // ///////////////////////////////////////////////////////////
    centralPanel = new TintablePanel();
    centralPanel.setBackground(COLOR_CHARCOAL);
    centralPanel.setForeground(COLOR_WHITE_TEXT);
    centralPanel.setTintColor(COLOR_CENTRAL_BACK);
    getRootPane().getContentPane().add(centralPanel, BorderLayout.CENTER);
    centralPanel.setLayout(new BorderLayout());
    modpackPanel = new ModpackInfoPanel(resources, iconRepo, logoRepo, backgroundRepo, avatarRepo, discordApi, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            openModpackOptions((ModpackModel) e.getSource());
        }
    }, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshModpackOptions((ModpackModel) e.getSource());
        }
    });
    modpackSelector.setInfoPanel(modpackPanel);
    modpackSelector.setLauncherFrame(this);
    playButton = modpackPanel.getPlayButton();
    playButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof ModpackModel) {
                setupPlayButtonText((ModpackModel) e.getSource(), userModel.getCurrentUser());
            } else if (installer.isCurrentlyRunning()) {
                installer.cancel();
                setupPlayButtonText(modpackSelector.getSelectedPack(), userModel.getCurrentUser());
            } else {
                launchModpack();
            }
        }
    });
    modpackPanel.getDeleteButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(LauncherFrame.this, resources.getString("modpackoptions.delete.confirmtext"), resources.getString("modpackoptions.delete.confirmtitle"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                modpackSelector.getSelectedPack().delete();
                modpackSelector.forceRefresh();
            }
        }
    });
    infoSwap = new JPanel();
    infoLayout = new CardLayout();
    infoSwap.setLayout(infoLayout);
    infoSwap.setOpaque(false);
    newsInfoPanel = new NewsInfoPanel(resources, avatarRepo);
    infoSwap.add(discoverInfoPanel, "discover");
    JPanel newsHost = new JPanel();
    infoSwap.add(newsHost, "news");
    JPanel modpackHost = new JPanel();
    infoSwap.add(modpackHost, "modpacks");
    centralPanel.add(infoSwap, BorderLayout.CENTER);
    newsSelector = new NewsSelector(resources, newsInfoPanel, platformApi, avatarRepo, newsCircle, settings);
    newsHost.setLayout(new BorderLayout());
    newsHost.add(newsInfoPanel, BorderLayout.CENTER);
    newsHost.add(newsSelector, BorderLayout.WEST);
    modpackHost.setLayout(new BorderLayout());
    modpackHost.add(modpackPanel, BorderLayout.CENTER);
    modpackHost.add(modpackSelector, BorderLayout.WEST);
    footer = new TintablePanel();
    footer.setTintColor(COLOR_CENTRAL_BACK);
    footer.setBackground(COLOR_FOOTER);
    footer.setLayout(new BoxLayout(footer, BoxLayout.LINE_AXIS));
    footer.setForeground(COLOR_WHITE_TEXT);
    footer.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 12));
    userWidget = new UserWidget(resources, skinRepository);
    userWidget.setMaximumSize(userWidget.getPreferredSize());
    footer.add(userWidget);
    JLabel dashText = new JLabel("| ");
    dashText.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    dashText.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15));
    footer.add(dashText);
    JButton logout = new JButton(resources.getString("launcher.user.logout"));
    logout.setBorder(BorderFactory.createEmptyBorder());
    logout.setContentAreaFilled(false);
    logout.setFocusable(false);
    logout.setForeground(LauncherFrame.COLOR_WHITE_TEXT);
    logout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    logout.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15));
    logout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            logout();
        }
    });
    footer.add(logout);
    installProgress = new ProgressBar();
    installProgress.setForeground(Color.white);
    installProgress.setBackground(LauncherFrame.COLOR_GREEN);
    installProgress.setBorder(BorderFactory.createEmptyBorder(5, 45, 4, 45));
    installProgress.setIcon(resources.getIcon("download_icon.png"));
    installProgress.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 12));
    installProgress.setVisible(false);
    footer.add(installProgress);
    installProgressPlaceholder = Box.createHorizontalGlue();
    footer.add(installProgressPlaceholder);
    JButton buildCtrl = new JButton(resources.getIcon("apex-logo.png"));
    buildCtrl.setBorder(BorderFactory.createEmptyBorder());
    buildCtrl.setContentAreaFilled(false);
    buildCtrl.setHorizontalTextPosition(SwingConstants.RIGHT);
    buildCtrl.setHorizontalAlignment(SwingConstants.RIGHT);
    buildCtrl.setFocusable(false);
    buildCtrl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    buildCtrl.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DesktopUtils.browseUrl("https://apexminecrafthosting.com/partners/technic");
        }
    });
    footer.add(buildCtrl);
    getRootPane().getContentPane().add(footer, BorderLayout.PAGE_END);
    if (resources.hasResource("teaser.png")) {
        getRootPane().setGlassPane(new SplatPane(modpacksTab, resources.getIcon("teaser.png"), JLabel.SOUTH, 5, 0));
        getRootPane().getGlassPane().setVisible(true);
    }
}
Also used : CountCircle(net.technicpack.ui.controls.feeds.CountCircle) SplatPane(net.technicpack.ui.controls.SplatPane) NewsInfoPanel(net.technicpack.launcher.ui.components.news.NewsInfoPanel) NewsSelector(net.technicpack.launcher.ui.components.news.NewsSelector) ModpackInfoPanel(net.technicpack.launcher.ui.components.modpacks.ModpackInfoPanel) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) TintablePanel(net.technicpack.ui.controls.TintablePanel) ProgressBar(net.technicpack.ui.controls.installation.ProgressBar)

Example 3 with ModpackModel

use of net.technicpack.launchercore.modpacks.ModpackModel in project LauncherV3 by TechnicPack.

the class LauncherMain method startLauncher.

private static void startLauncher(final TechnicSettings settings, StartupParameters startupParameters, final LauncherDirectories directories, ResourceLoader resources, IBuildNumber buildNumber) {
    UIManager.put("ComboBox.disabledBackground", LauncherFrame.COLOR_FORMELEMENT_INTERNAL);
    UIManager.put("ComboBox.disabledForeground", LauncherFrame.COLOR_GREY_TEXT);
    System.setProperty("xr.load.xml-reader", "org.ccil.cowan.tagsoup.Parser");
    // Remove all log files older than a week
    new Thread(new Runnable() {

        @Override
        public void run() {
            Iterator<File> files = FileUtils.iterateFiles(new File(directories.getLauncherDirectory(), "logs"), new String[] { "log" }, false);
            while (files.hasNext()) {
                File logFile = files.next();
                if (logFile.exists() && (new DateTime(logFile.lastModified())).isBefore(DateTime.now().minusWeeks(1))) {
                    logFile.delete();
                }
            }
        }
    }).start();
    Utils.getLogger().info("OS: " + System.getProperty("os.name").toLowerCase(Locale.ENGLISH));
    Utils.getLogger().info("Identified as " + OperatingSystem.getOperatingSystem().getName());
    final SplashScreen splash = new SplashScreen(resources.getImage("launch_splash.png"), 0);
    Color bg = LauncherFrame.COLOR_FORMELEMENT_INTERNAL;
    splash.getContentPane().setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), 255));
    splash.pack();
    splash.setLocationRelativeTo(null);
    splash.setVisible(true);
    boolean loadedAether = false;
    try {
        if (Class.forName("org.apache.maven.repository.internal.MavenRepositorySystemUtils", false, ClassLoader.getSystemClassLoader()) != null) {
            loadedAether = true;
        }
    } catch (ClassNotFoundException ex) {
    // Aether is not loaded
    }
    if (!loadedAether) {
        File launcherAssets = new File(directories.getAssetsDirectory(), "launcher");
        File aether = new File(launcherAssets, "aether-dep.jar");
        try {
            Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
            m.setAccessible(true);
            m.invoke(ClassLoader.getSystemClassLoader(), aether.toURI().toURL());
        } catch (NoSuchMethodException ex) {
            ex.printStackTrace();
        } catch (InvocationTargetException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
    }
    JavaVersionRepository javaVersions = new JavaVersionRepository();
    (new InstalledJavaSource()).enumerateVersions(javaVersions);
    FileJavaSource javaVersionFile = FileJavaSource.load(new File(settings.getTechnicRoot(), "javaVersions.json"));
    javaVersionFile.enumerateVersions(javaVersions);
    javaVersions.selectVersion(settings.getJavaVersion(), settings.getJavaBitness());
    IUserStore<MojangUser> users = TechnicUserStore.load(new File(directories.getLauncherDirectory(), "users.json"));
    UserModel userModel = new UserModel(users, new AuthenticationService());
    MirrorStore mirrorStore = new MirrorStore(userModel);
    mirrorStore.addSecureMirror("mirror.technicpack.net", new JsonWebSecureMirror("http://mirror.technicpack.net/", "mirror.technicpack.net"));
    IModpackResourceType iconType = new IconResourceType();
    IModpackResourceType logoType = new LogoResourceType();
    IModpackResourceType backgroundType = new BackgroundResourceType();
    PackResourceMapper iconMapper = new PackResourceMapper(directories, resources.getImage("icon.png"), iconType);
    ImageRepository<ModpackModel> iconRepo = new ImageRepository<ModpackModel>(iconMapper, new PackImageStore(iconType, mirrorStore, userModel));
    ImageRepository<ModpackModel> logoRepo = new ImageRepository<ModpackModel>(new PackResourceMapper(directories, resources.getImage("modpack/ModImageFiller.png"), logoType), new PackImageStore(logoType, mirrorStore, userModel));
    ImageRepository<ModpackModel> backgroundRepo = new ImageRepository<ModpackModel>(new PackResourceMapper(directories, null, backgroundType), new PackImageStore(backgroundType, mirrorStore, userModel));
    ImageRepository<IUserType> skinRepo = new ImageRepository<IUserType>(new TechnicFaceMapper(directories, resources), new CrafatarFaceImageStore("http://crafatar.com/", mirrorStore));
    ImageRepository<AuthorshipInfo> avatarRepo = new ImageRepository<AuthorshipInfo>(new TechnicAvatarMapper(directories, resources), new WebAvatarImageStore(mirrorStore));
    HttpSolderApi httpSolder = new HttpSolderApi(settings.getClientId(), userModel);
    ISolderApi solder = new CachedSolderApi(directories, httpSolder, 60 * 60);
    HttpPlatformApi httpPlatform = new HttpPlatformApi("http://api.technicpack.net/", mirrorStore, buildNumber.getBuildNumber());
    IPlatformApi platform = new ModpackCachePlatformApi(httpPlatform, 60 * 60, directories);
    IPlatformSearchApi platformSearch = new HttpPlatformSearchApi("http://api.technicpack.net/", buildNumber.getBuildNumber());
    IInstalledPackRepository packStore = TechnicInstalledPackStore.load(new File(directories.getLauncherDirectory(), "installedPacks"));
    IAuthoritativePackSource packInfoRepository = new PlatformPackInfoRepository(platform, solder);
    ArrayList<IMigrator> migrators = new ArrayList<IMigrator>(1);
    migrators.add(new InitialV3Migrator(platform));
    SettingsFactory.migrateSettings(settings, packStore, directories, users, migrators);
    PackLoader packList = new PackLoader(directories, packStore, packInfoRepository);
    ModpackSelector selector = new ModpackSelector(resources, packList, new SolderPackSource("http://solder.technicpack.net/api/", solder), solder, platform, platformSearch, iconRepo);
    selector.setBorder(BorderFactory.createEmptyBorder());
    userModel.addAuthListener(selector);
    resources.registerResource(selector);
    DiscoverInfoPanel discoverInfoPanel = new DiscoverInfoPanel(resources, startupParameters.getDiscoverUrl(), platform, directories, selector);
    MinecraftLauncher launcher = new MinecraftLauncher(platform, directories, userModel, javaVersions);
    ModpackInstaller modpackInstaller = new ModpackInstaller(platform, settings.getClientId());
    Installer installer = new Installer(startupParameters, mirrorStore, directories, modpackInstaller, launcher, settings, iconMapper);
    IDiscordApi discordApi = new HttpDiscordApi("https://discordapp.com/api/");
    discordApi = new CacheDiscordApi(discordApi, 600, 60);
    final LauncherFrame frame = new LauncherFrame(resources, skinRepo, userModel, settings, selector, iconRepo, logoRepo, backgroundRepo, installer, avatarRepo, platform, directories, packStore, startupParameters, discoverInfoPanel, javaVersions, javaVersionFile, buildNumber, discordApi);
    userModel.addAuthListener(frame);
    ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            splash.dispose();
            if (settings.getLaunchToModpacks())
                frame.selectTab("modpacks");
        }
    };
    discoverInfoPanel.setLoadListener(listener);
    LoginFrame login = new LoginFrame(resources, settings, userModel, skinRepo);
    userModel.addAuthListener(login);
    userModel.addAuthListener(new IAuthListener() {

        @Override
        public void userChanged(Object user) {
            if (user == null)
                splash.dispose();
        }
    });
    userModel.initAuth();
    Utils.sendTracking("runLauncher", "run", buildNumber.getBuildNumber(), settings.getClientId());
}
Also used : MalformedURLException(java.net.MalformedURLException) DiscoverInfoPanel(net.technicpack.launcher.ui.components.discover.DiscoverInfoPanel) PackLoader(net.technicpack.launchercore.modpacks.PackLoader) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) HttpPlatformApi(net.technicpack.platform.http.HttpPlatformApi) LogoResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.LogoResourceType) DateTime(org.joda.time.DateTime) MirrorStore(net.technicpack.launchercore.mirror.MirrorStore) IAuthoritativePackSource(net.technicpack.launchercore.modpacks.sources.IAuthoritativePackSource) ImageRepository(net.technicpack.launchercore.image.ImageRepository) MojangUser(net.technicpack.minecraftcore.mojang.auth.MojangUser) BackgroundResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.BackgroundResourceType) PackResourceMapper(net.technicpack.launchercore.modpacks.resources.PackResourceMapper) AuthorshipInfo(net.technicpack.platform.io.AuthorshipInfo) IInstalledPackRepository(net.technicpack.launchercore.modpacks.sources.IInstalledPackRepository) CachedSolderApi(net.technicpack.solder.cache.CachedSolderApi) IMigrator(net.technicpack.launcher.settings.migration.IMigrator) LauncherFrame(net.technicpack.launcher.ui.LauncherFrame) Method(java.lang.reflect.Method) MinecraftLauncher(net.technicpack.minecraftcore.launch.MinecraftLauncher) FileJavaSource(net.technicpack.launchercore.launch.java.source.FileJavaSource) InvocationTargetException(java.lang.reflect.InvocationTargetException) IPlatformApi(net.technicpack.platform.IPlatformApi) IDiscordApi(net.technicpack.discord.IDiscordApi) WebAvatarImageStore(net.technicpack.launchercore.image.face.WebAvatarImageStore) ActionListener(java.awt.event.ActionListener) JsonWebSecureMirror(net.technicpack.launchercore.mirror.secure.rest.JsonWebSecureMirror) PackImageStore(net.technicpack.launchercore.modpacks.resources.PackImageStore) ModpackCachePlatformApi(net.technicpack.platform.cache.ModpackCachePlatformApi) File(java.io.File) HttpPlatformSearchApi(net.technicpack.platform.http.HttpPlatformSearchApi) PlatformPackInfoRepository(net.technicpack.platform.PlatformPackInfoRepository) Installer(net.technicpack.launcher.launch.Installer) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) IAuthListener(net.technicpack.launchercore.auth.IAuthListener) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) UserModel(net.technicpack.launchercore.auth.UserModel) SolderPackSource(net.technicpack.solder.SolderPackSource) ModpackInstaller(net.technicpack.launchercore.install.ModpackInstaller) CrafatarFaceImageStore(net.technicpack.launchercore.image.face.CrafatarFaceImageStore) SplashScreen(net.technicpack.ui.controls.installation.SplashScreen) ISolderApi(net.technicpack.solder.ISolderApi) LoginFrame(net.technicpack.launcher.ui.LoginFrame) ModpackSelector(net.technicpack.launcher.ui.components.modpacks.ModpackSelector) HttpSolderApi(net.technicpack.solder.http.HttpSolderApi) IconResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IconResourceType) InitialV3Migrator(net.technicpack.launcher.settings.migration.InitialV3Migrator) InstalledJavaSource(net.technicpack.launchercore.launch.java.source.InstalledJavaSource) IUserType(net.technicpack.launchercore.auth.IUserType) IPlatformSearchApi(net.technicpack.platform.IPlatformSearchApi) ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) HttpDiscordApi(net.technicpack.discord.HttpDiscordApi) CacheDiscordApi(net.technicpack.discord.CacheDiscordApi) IModpackResourceType(net.technicpack.launchercore.modpacks.resources.resourcetype.IModpackResourceType) AuthenticationService(net.technicpack.minecraftcore.mojang.auth.AuthenticationService)

Example 4 with ModpackModel

use of net.technicpack.launchercore.modpacks.ModpackModel 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)

Example 5 with ModpackModel

use of net.technicpack.launchercore.modpacks.ModpackModel in project LauncherV3 by TechnicPack.

the class LauncherFrame method launchModpack.

protected void launchModpack() {
    ModpackModel pack = modpackSelector.getSelectedPack();
    boolean requiresInstall = false;
    if (pack == null || (pack.getInstalledPack() == null && (pack.getPackInfo() == null || !pack.getPackInfo().isComplete())))
        return;
    if (pack.getInstalledDirectory() == null) {
        requiresInstall = true;
        pack.save();
        modpackSelector.forceRefresh();
    }
    if (requiresInstall) {
        try {
            if (pack.getPackInfo().shouldForceDirectory() && FilenameUtils.directoryContains(directories.getLauncherDirectory().getCanonicalPath(), pack.getInstalledDirectory().getCanonicalPath())) {
                JFileChooser chooser = new JFileChooser(directories.getLauncherDirectory());
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                chooser.setCurrentDirectory(directories.getLauncherDirectory());
                int result = chooser.showOpenDialog(this);
                if (result == JFileChooser.APPROVE_OPTION) {
                    File file = chooser.getSelectedFile();
                    if (file.list().length > 0) {
                        JOptionPane.showMessageDialog(this, resources.getString("modpackoptions.move.errortext"), resources.getString("modpackoptions.move.errortitle"), JOptionPane.WARNING_MESSAGE);
                        return;
                    } else if (FileUtils.directoryContains(directories.getLauncherDirectory(), file)) {
                        JOptionPane.showMessageDialog(this, resources.getString("launcher.launch.requiresmove"), resources.getString("launcher.launch.requiretitle"), JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    pack.setInstalledDirectory(file);
                }
            }
        } catch (IOException ex) {
            Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
    boolean forceInstall = false;
    Version installedVersion = pack.getInstalledVersion();
    // Force a full install (check cache, redownload, unzip files) if we have no current installation of this modpack
    if (installedVersion == null) {
        forceInstall = true;
        requiresInstall = true;
    } else if (pack.getBuild() != null && !pack.isLocalOnly()) {
        // Ask the user if they want to update to the newer version if:
        // 1- the pack build is RECOMMENDED & the recommended version is diff from the installed version
        // 2- the pack build is LATEST & the latest version is diff from the installed version
        // 3- the pack build is neither LATEST or RECOMMENDED & the pack build is diff from the installed version
        boolean requestInstall = false;
        if (pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED) && pack.getPackInfo().getRecommended() != null && !pack.getPackInfo().getRecommended().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;
        else if (pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST) && pack.getPackInfo().getLatest() != null && !pack.getPackInfo().getLatest().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;
        else if (!pack.getBuild().equalsIgnoreCase(InstalledPack.RECOMMENDED) && !pack.getBuild().equalsIgnoreCase(InstalledPack.LATEST) && !pack.getBuild().equalsIgnoreCase(installedVersion.getVersion()))
            requestInstall = true;
        // If the user says yes, update, then force a full install
        if (requestInstall) {
            int result = JOptionPane.showConfirmDialog(this, resources.getString("launcher.install.query"), resources.getString("launcher.install.query.title"), JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
            if (result == JOptionPane.YES_OPTION) {
                forceInstall = true;
            }
        }
    }
    // If we're forcing an install, then derive the installation build from the pack build
    // otherwise, just use the installed version
    String installBuild = null;
    if (forceInstall && !pack.isLocalOnly()) {
        installBuild = pack.getBuild();
        if (installBuild.equalsIgnoreCase(InstalledPack.RECOMMENDED))
            installBuild = pack.getPackInfo().getRecommended();
        else if (installBuild.equalsIgnoreCase(InstalledPack.LATEST))
            installBuild = pack.getPackInfo().getLatest();
    } else if (installedVersion != null)
        installBuild = installedVersion.getVersion();
    if (requiresInstall && installBuild != null && !installBuild.isEmpty()) {
        installer.justInstall(resources, pack, installBuild, forceInstall, this, installProgress);
    } else {
        installer.installAndRun(resources, pack, installBuild, forceInstall, this, installProgress);
    }
    installProgress.setVisible(true);
    installProgressPlaceholder.setVisible(false);
    userChanged(userModel.getCurrentUser());
    invalidate();
}
Also used : ModpackModel(net.technicpack.launchercore.modpacks.ModpackModel) Version(net.technicpack.launchercore.install.Version) IOException(java.io.IOException) File(java.io.File)

Aggregations

ModpackModel (net.technicpack.launchercore.modpacks.ModpackModel)6 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 File (java.io.File)2 Version (net.technicpack.launchercore.install.Version)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 CacheDiscordApi (net.technicpack.discord.CacheDiscordApi)1 HttpDiscordApi (net.technicpack.discord.HttpDiscordApi)1 IDiscordApi (net.technicpack.discord.IDiscordApi)1 Installer (net.technicpack.launcher.launch.Installer)1 IMigrator (net.technicpack.launcher.settings.migration.IMigrator)1 InitialV3Migrator (net.technicpack.launcher.settings.migration.InitialV3Migrator)1 LauncherFrame (net.technicpack.launcher.ui.LauncherFrame)1 LoginFrame (net.technicpack.launcher.ui.LoginFrame)1