Search in sources :

Example 1 with VersionChecker

use of com.mucommander.VersionChecker in project mucommander by mucommander.

the class CheckVersionDialog method run.

/**
 * Checks for updates and notifies the user of the outcome.
 */
public void run() {
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    String message;
    String title;
    VersionChecker version;
    URL downloadURL = null;
    boolean downloadOption = false;
    String jarURL = null;
    try {
        LOGGER.debug("Checking for new version...");
        version = VersionChecker.getInstance();
        // A newer version is available
        if (version.isNewVersionAvailable()) {
            LOGGER.info("A new version is available!");
            title = Translator.get("version_dialog.new_version_title");
            // Checks if the current platform can open a new browser window
            downloadURL = new URL(version.getDownloadURL());
            downloadOption = DesktopManager.isOperationSupported(DesktopManager.BROWSE, new Object[] { downloadURL });
            // display the download URL.
            if (downloadOption) {
                message = Translator.get("version_dialog.new_version");
            } else {
                message = Translator.get("version_dialog.new_version_url", downloadURL.toString());
            }
            jarURL = version.getJarURL();
        } else // We're already running latest version
        {
            LOGGER.debug("No new version.");
            // we do not need to inform the user that he already has the latest version
            if (!userInitiated) {
                dispose();
                return;
            }
            title = Translator.get("version_dialog.no_new_version_title");
            message = Translator.get("version_dialog.no_new_version");
        }
    }// Check failed
     catch (Exception e) {
        // we do not need to inform the user that the check failed
        if (!userInitiated) {
            dispose();
            return;
        }
        title = Translator.get("version_dialog.not_available_title");
        message = Translator.get("version_dialog.not_available");
    }
    // Set title
    setTitle(title);
    List<DialogAction> actions = new ArrayList<>();
    actions.add(CheckVersionAction.OK);
    // 'Go to website' choice (if available)
    if (downloadOption) {
        actions.add(CheckVersionAction.GO_TO_WEBSITE);
    }
    // // 'Install and restart' choice (if available)
    // if(jarURL!=null) {
    // actionsV.add(new Integer(INSTALL_AND_RESTART_ACTION));
    // labelsV.add(Translator.get("version_dialog.install_and_restart"));
    // }
    init(new InformationPane(message, null, Font.PLAIN, InformationPane.INFORMATION_ICON), actions, 0);
    JCheckBox showNextTimeCheckBox = new JCheckBox(Translator.get("prefs_dialog.check_for_updates_on_startup"), MuConfigurations.getPreferences().getVariable(MuPreference.CHECK_FOR_UPDATE, MuPreferences.DEFAULT_CHECK_FOR_UPDATE));
    addComponent(showNextTimeCheckBox);
    setMinimumSize(MINIMUM_DIALOG_DIMENSION);
    // Show dialog and get user action
    DialogAction action = getActionValue();
    if (action == CheckVersionAction.GO_TO_WEBSITE) {
        try {
            DesktopManager.executeOperation(DesktopManager.BROWSE, new Object[] { downloadURL });
        } catch (Exception e) {
            InformationDialog.showErrorDialog(this);
        }
    } else if (action == CheckVersionAction.INSTALL_AND_RESTART) {
        ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("Installing new version"));
        SelfUpdateJob job = new SelfUpdateJob(progressDialog, mainFrame, FileFactory.getFile(jarURL));
        progressDialog.start(job);
    }
    // Remember user preference
    MuConfigurations.getPreferences().setVariable(MuPreference.CHECK_FOR_UPDATE, showNextTimeCheckBox.isSelected());
}
Also used : ArrayList(java.util.ArrayList) InformationPane(com.mucommander.ui.layout.InformationPane) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) URL(java.net.URL) JCheckBox(javax.swing.JCheckBox) Container(java.awt.Container) VersionChecker(com.mucommander.VersionChecker) BorderLayout(java.awt.BorderLayout) DialogAction(com.mucommander.ui.dialog.DialogAction) SelfUpdateJob(com.mucommander.job.impl.SelfUpdateJob)

Aggregations

VersionChecker (com.mucommander.VersionChecker)1 SelfUpdateJob (com.mucommander.job.impl.SelfUpdateJob)1 DialogAction (com.mucommander.ui.dialog.DialogAction)1 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)1 InformationPane (com.mucommander.ui.layout.InformationPane)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 JCheckBox (javax.swing.JCheckBox)1