Search in sources :

Example 1 with Memory

use of net.technicpack.utilslib.Memory in project LauncherV3 by TechnicPack.

the class Installer method internalInstallAndRun.

protected void internalInstallAndRun(final ResourceLoader resources, final ModpackModel pack, final String build, final boolean doFullInstall, final LauncherFrame frame, final DownloadListener listener, final boolean doLaunch) {
    runningThread = new Thread(new Runnable() {

        @Override
        public void run() {
            boolean everythingWorked = false;
            try {
                MojangVersion version = null;
                InstallTasksQueue<MojangVersion> tasksQueue = new InstallTasksQueue<MojangVersion>(listener, mirrorStore);
                MojangVersionBuilder versionBuilder = createVersionBuilder(pack, tasksQueue);
                if (!pack.isLocalOnly() && build != null && !build.isEmpty()) {
                    buildTasksQueue(tasksQueue, resources, pack, build, doFullInstall, versionBuilder);
                    version = installer.installPack(tasksQueue, pack, build);
                } else {
                    version = versionBuilder.buildVersionFromKey(null);
                    if (version != null)
                        pack.initDirectories();
                }
                if (doLaunch) {
                    if (version == null) {
                        throw new PackNotAvailableOfflineException(pack.getDisplayName());
                    }
                    JavaVersionRepository javaVersions = launcher.getJavaVersions();
                    Memory memoryObj = Memory.getClosestAvailableMemory(Memory.getMemoryFromId(settings.getMemory()), javaVersions.getSelectedVersion().is64Bit());
                    long memory = memoryObj.getMemoryMB();
                    String versionNumber = javaVersions.getSelectedVersion().getVersionNumber();
                    RunData data = pack.getRunData();
                    if (data != null && !data.isRunDataValid(memory, versionNumber)) {
                        FixRunDataDialog dialog = new FixRunDataDialog(frame, resources, data, javaVersions, memoryObj, !settings.shouldAutoAcceptModpackRequirements());
                        dialog.setVisible(true);
                        if (dialog.getResult() == FixRunDataDialog.Result.ACCEPT) {
                            memoryObj = dialog.getRecommendedMemory();
                            memory = memoryObj.getMemoryMB();
                            IJavaVersion recommendedJavaVersion = dialog.getRecommendedJavaVersion();
                            javaVersions.selectVersion(recommendedJavaVersion.getVersionNumber(), recommendedJavaVersion.is64Bit());
                            if (dialog.shouldRemember()) {
                                settings.setAutoAcceptModpackRequirements(true);
                            }
                        } else
                            return;
                    }
                    LaunchAction launchAction = settings.getLaunchAction();
                    if (launchAction == null || launchAction == LaunchAction.HIDE) {
                        launcherUnhider = new LauncherUnhider(settings, frame);
                    } else
                        launcherUnhider = null;
                    LaunchOptions options = new LaunchOptions(pack.getDisplayName(), packIconMapper.getImageLocation(pack).getAbsolutePath(), settings);
                    launcher.launch(pack, memory, options, launcherUnhider, version);
                    if (launchAction == null || launchAction == LaunchAction.HIDE) {
                        frame.setVisible(false);
                    } else if (launchAction == LaunchAction.NOTHING) {
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                frame.launchCompleted();
                            }
                        });
                    } else if (launchAction == LaunchAction.CLOSE) {
                        System.exit(0);
                    }
                }
                everythingWorked = true;
            } catch (InterruptedException e) {
                boolean cancelledByUser = false;
                synchronized (cancelLock) {
                    if (isCancelledByUser) {
                        cancelledByUser = true;
                        isCancelledByUser = false;
                    }
                }
                // Canceled by user
                if (!cancelledByUser) {
                    if (e.getCause() != null)
                        Utils.getLogger().info("Cancelled by exception.");
                    else
                        Utils.getLogger().info("Cancelled by code.");
                    e.printStackTrace();
                } else
                    Utils.getLogger().info("Cancelled by user.");
            } catch (PackNotAvailableOfflineException e) {
                JOptionPane.showMessageDialog(frame, e.getMessage(), resources.getString("launcher.installerror.unavailable"), JOptionPane.WARNING_MESSAGE);
            } catch (DownloadException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.download", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (ZipException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.unzip", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (CacheDeleteException e) {
                JOptionPane.showMessageDialog(frame, resources.getString("launcher.installerror.cache", pack.getDisplayName(), e.getMessage()), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (BuildInaccessibleException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(frame, e.getMessage(), resources.getString("launcher.installerror.title"), JOptionPane.WARNING_MESSAGE);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (!everythingWorked || !doLaunch) {
                    EventQueue.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            frame.launchCompleted();
                        }
                    });
                }
            }
        }
    }) {

        // /Interrupt is being called from a mysterious source, so unless this is a user-initiated cancel
        // /Let's print the stack trace of the interruptor.
        @Override
        public void interrupt() {
            boolean userCancelled = false;
            synchronized (cancelLock) {
                if (isCancelledByUser)
                    userCancelled = true;
            }
            if (!userCancelled) {
                Utils.getLogger().info("Mysterious interruption source.");
                try {
                    // I am a charlatan and a hack.
                    throw new Exception("Grabbing stack trace- this isn't necessarily an error.");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            super.interrupt();
        }
    };
    runningThread.start();
}
Also used : Memory(net.technicpack.utilslib.Memory) CacheDeleteException(net.technicpack.launchercore.exception.CacheDeleteException) JavaVersionRepository(net.technicpack.launchercore.launch.java.JavaVersionRepository) DownloadException(net.technicpack.launchercore.exception.DownloadException) RunData(net.technicpack.launchercore.modpacks.RunData) PackNotAvailableOfflineException(net.technicpack.launchercore.exception.PackNotAvailableOfflineException) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) LaunchAction(net.technicpack.launchercore.util.LaunchAction) MojangVersionBuilder(net.technicpack.minecraftcore.mojang.version.MojangVersionBuilder) BuildInaccessibleException(net.technicpack.launchercore.exception.BuildInaccessibleException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) InstallTasksQueue(net.technicpack.launchercore.install.InstallTasksQueue) BuildInaccessibleException(net.technicpack.launchercore.exception.BuildInaccessibleException) DownloadException(net.technicpack.launchercore.exception.DownloadException) ZipException(java.util.zip.ZipException) PackNotAvailableOfflineException(net.technicpack.launchercore.exception.PackNotAvailableOfflineException) CacheDeleteException(net.technicpack.launchercore.exception.CacheDeleteException) IOException(java.io.IOException) IJavaVersion(net.technicpack.launchercore.launch.java.IJavaVersion) FixRunDataDialog(net.technicpack.launcher.ui.components.FixRunDataDialog) LaunchOptions(net.technicpack.minecraftcore.launch.LaunchOptions)

Example 2 with Memory

use of net.technicpack.utilslib.Memory in project LauncherV3 by TechnicPack.

the class OptionsDialog method rebuildMemoryList.

private void rebuildMemoryList() {
    for (ActionListener listener : memSelect.getActionListeners()) memSelect.removeActionListener(listener);
    Container parent = null;
    if (memSelect.getParent() != null) {
        parent = memSelect.getParent();
        parent.remove(memSelect);
        if (ramWarning != null) {
            parent.remove(ramWarning);
            ramWarning = null;
        }
    }
    memSelect.removeAllItems();
    long maxMemory = Memory.getAvailableMemory(javaVersions.getSelectedVersion().is64Bit());
    for (int i = 0; i < Memory.memoryOptions.length; i++) {
        if (Memory.memoryOptions[i].getMemoryMB() <= maxMemory)
            memSelect.addItem(Memory.memoryOptions[i]);
    }
    Memory currentMem = Memory.getMemoryFromId(settings.getMemory());
    Memory availableMem = Memory.getClosestAvailableMemory(currentMem, javaVersions.getSelectedVersion().is64Bit());
    if (currentMem.getMemoryMB() != availableMem.getMemoryMB()) {
        settings.setMemory(availableMem.getSettingsId());
        settings.save();
    }
    memSelect.setSelectedItem(availableMem);
    memSelect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            changeMemory();
        }
    });
    if (parent != null) {
        boolean is64Bit = true;
        boolean has64Bit = true;
        if (javaVersions.getBest64BitVersion() == null) {
            has64Bit = false;
        }
        if (!javaVersions.getSelectedVersion().is64Bit()) {
            is64Bit = false;
        }
        if (is64Bit) {
            parent.add(memSelect, new GridBagConstraints(1, 1, 6, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 16, 8, 80), 0, 16));
        } else {
            parent.add(memSelect, new GridBagConstraints(1, 1, 5, 1, 5, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 16, 8, 0), 0, 16));
            JToolTip toolTip = new JToolTip();
            toolTip.setBackground(LauncherFrame.COLOR_FOOTER);
            toolTip.setForeground(LauncherFrame.COLOR_GREY_TEXT);
            toolTip.setBorder(BorderFactory.createCompoundBorder(new LineBorder(LauncherFrame.COLOR_GREY_TEXT), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
            toolTip.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14));
            String text = null;
            Icon icon = null;
            if (has64Bit) {
                text = resources.getString("launcheroptions.java.use64bit");
                icon = resources.getIcon("danger_icon.png");
            } else {
                text = resources.getString("launcheroptions.java.get64bit");
                icon = resources.getIcon("warning_icon.png");
            }
            ramWarning = new TooltipWarning(icon, toolTip);
            ((TooltipWarning) ramWarning).setToolTipText(text);
            parent.add(ramWarning, new GridBagConstraints(6, 1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 8, 8, 80), 0, 0));
        }
        repaint();
    }
}
Also used : Memory(net.technicpack.utilslib.Memory) ActionEvent(java.awt.event.ActionEvent) LineBorder(javax.swing.border.LineBorder) TooltipWarning(net.technicpack.ui.controls.TooltipWarning) ActionListener(java.awt.event.ActionListener)

Aggregations

Memory (net.technicpack.utilslib.Memory)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 IOException (java.io.IOException)1 ZipException (java.util.zip.ZipException)1 LineBorder (javax.swing.border.LineBorder)1 FixRunDataDialog (net.technicpack.launcher.ui.components.FixRunDataDialog)1 BuildInaccessibleException (net.technicpack.launchercore.exception.BuildInaccessibleException)1 CacheDeleteException (net.technicpack.launchercore.exception.CacheDeleteException)1 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 PackNotAvailableOfflineException (net.technicpack.launchercore.exception.PackNotAvailableOfflineException)1 InstallTasksQueue (net.technicpack.launchercore.install.InstallTasksQueue)1 IJavaVersion (net.technicpack.launchercore.launch.java.IJavaVersion)1 JavaVersionRepository (net.technicpack.launchercore.launch.java.JavaVersionRepository)1 RunData (net.technicpack.launchercore.modpacks.RunData)1 LaunchAction (net.technicpack.launchercore.util.LaunchAction)1 LaunchOptions (net.technicpack.minecraftcore.launch.LaunchOptions)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 MojangVersionBuilder (net.technicpack.minecraftcore.mojang.version.MojangVersionBuilder)1 TooltipWarning (net.technicpack.ui.controls.TooltipWarning)1