Search in sources :

Example 1 with Updater

use of com.github.mob41.osumer.updater.Updater in project osumer by mob41.

the class MainController method setConfiguration.

protected void setConfiguration(Configuration config) {
    this.config = config;
    updater = new Updater(config);
    checkingUpdate = false;
    annChecker = new AnnouncementChecker();
    checkingAnnouncements = false;
    ann = null;
    // TODO do freq check
    checkUpdate();
    checkAnnouncements();
}
Also used : Updater(com.github.mob41.osumer.updater.Updater) AnnouncementChecker(com.github.mob41.osumer.updater.AnnouncementChecker)

Example 2 with Updater

use of com.github.mob41.osumer.updater.Updater in project osumer by mob41.

the class UIFrame method checkUpdate.

public void checkUpdate() {
    if (checkingUpdate) {
        return;
    }
    checkingUpdate = true;
    Thread thread = new Thread() {

        public void run() {
            lblUpdateStatus.setForeground(Color.BLACK);
            lblUpdateStatus.setText("Checking for updates...");
            UpdateInfo verInfo = null;
            try {
                verInfo = getUpdateInfoByConfig();
            } catch (NoBuildsForVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No builds available for the new version. See dump.");
                checkingUpdate = false;
                return;
            } catch (NoSuchVersionException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("No current version in the selected branch. See dump.");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\nPlease try another update branch (snapshot, beta, stable).", "Version not available", JOptionPane.INFORMATION_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (NoSuchBuildNumberException e) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("This version has a invalid build number. See dump");
                JOptionPane.showMessageDialog(UIFrame.this, "We don't have build number greater or equal to " + Osumer.OSUMER_BUILD_NUM + " in version " + Osumer.OSUMER_VERSION + ".\n" + "If you are using a modified/development osumer,\n" + " you can just ignore this message.\n" + "If not, this might be the versions.json in GitHub goes wrong,\n" + " post a new issue about this.", "Build not available", JOptionPane.WARNING_MESSAGE);
                checkingUpdate = false;
                return;
            } catch (DebuggableException e) {
                e.printStackTrace();
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not connect to update server.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not connect to update server.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo == null) {
                lblUpdateStatus.setForeground(Color.RED);
                lblUpdateStatus.setText("Could not obtain update info.");
                JOptionPane.showMessageDialog(UIFrame.this, "Could not obtain update info.", "Error", JOptionPane.ERROR_MESSAGE);
                checkingUpdate = false;
                return;
            }
            if (verInfo.isThisVersion()) {
                lblUpdateStatus.setForeground(Color.BLACK);
                lblUpdateStatus.setText("You are running the latest version of osumer" + " (" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-" + verInfo.getBuildNum() + ")");
                checkingUpdate = false;
                return;
            }
            lblUpdateStatus.setForeground(new Color(0, 153, 0));
            lblUpdateStatus.setText((verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " available! New version: " + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum());
            int option;
            String desc = verInfo.getDescription();
            if (desc == null) {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.NO_OPTION);
            } else {
                option = JOptionPane.showOptionDialog(UIFrame.this, "New " + (verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + verInfo.getVersion() + "-" + Updater.getBranchStr(verInfo.getBranch()) + "-b" + verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?", "Update available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new String[] { "Yes", "No", "Description/Changelog" }, JOptionPane.NO_OPTION);
                if (option == 2) {
                    option = JOptionPane.showOptionDialog(UIFrame.this, new TextPanel(desc), "Update description/change-log", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, 0);
                }
            }
            if (option == JOptionPane.YES_OPTION) {
                /*
                    try {
                        Desktop.getDesktop().browse(new URI(verInfo.getWebLink()));
                    } catch (IOException | URISyntaxException e) {
                        DebugDump dump = new DebugDump(
                                verInfo.getWebLink(),
                                "Show option dialog of updating osumer or not",
                                "Set checkingUpdate to false",
                                "(End of function / thread)",
                                "Error when opening the web page",
                                false,
                                e);
                        DumpManager.getInstance().addDump(dump);
                        DebugDump.showDebugDialog(dump);
                    }
                    */
                try {
                    String updaterLink = Updater.getUpdaterLink();
                    if (updaterLink == null) {
                        System.out.println("No latest updater .exe defined! Falling back to legacy updater!");
                        updaterLink = Updater.LEGACY_UPDATER_JAR;
                    }
                    URL url;
                    try {
                        url = new URL(updaterLink);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    final String folder = System.getProperty("java.io.tmpdir");
                    final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
                    mgr.addQueue(new Queue("osumer Updater", new URLDownloader(folder, fileName, url), null, null, new QueueAction[] { new UpdaterRunAction(folder + fileName) }));
                    tab.setSelectedIndex(1);
                    new Thread() {

                        public void run() {
                            JOptionPane.showMessageDialog(UIFrame.this, "The web updater will be downloaded and started very soon.", "Notice", JOptionPane.INFORMATION_MESSAGE);
                        }
                    }.start();
                } catch (DebuggableException e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(null, "Error:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
                    checkingUpdate = false;
                }
            }
            checkingUpdate = false;
        }
    };
    thread.start();
}
Also used : NoSuchVersionException(com.github.mob41.osumer.exceptions.NoSuchVersionException) DebuggableException(com.github.mob41.organdebug.exceptions.DebuggableException) MalformedURLException(java.net.MalformedURLException) UpdaterRunAction(com.github.mob41.osumer.io.queue.actions.UpdaterRunAction) Color(java.awt.Color) QueueAction(com.github.mob41.osumer.io.queue.QueueAction) NoBuildsForVersionException(com.github.mob41.osumer.exceptions.NoBuildsForVersionException) URLDownloader(com.github.mob41.osumer.io.legacy.URLDownloader) URL(java.net.URL) SockThread(com.github.mob41.osumer.sock.SockThread) NoSuchBuildNumberException(com.github.mob41.osumer.exceptions.NoSuchBuildNumberException) Queue(com.github.mob41.osumer.io.queue.Queue) EventQueue(java.awt.EventQueue) UpdateInfo(com.github.mob41.osumer.updater.UpdateInfo)

Example 3 with Updater

use of com.github.mob41.osumer.updater.Updater in project osumer by mob41.

the class MainController method checkUpdate.

public void checkUpdate() {
    if (checkingUpdate) {
        return;
    }
    checkingUpdate = true;
    Thread thread = new Thread() {

        public void run() {
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    updateText.setText("Checking for updates...");
                }
            });
            UpdateInfo verInfo = null;
            try {
                verInfo = getUpdateInfoByConfig();
            } catch (NoBuildsForVersionException e) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        updateText.setText("No builds available for the new version. See dump.");
                    }
                });
                checkingUpdate = false;
                return;
            } catch (NoSuchVersionException e) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        updateText.setText("No current version in the selected branch. See dump.");
                        Alert alert = new Alert(AlertType.INFORMATION, "We don't have version " + Osumer.OSUMER_VERSION + " in the current update branch\n\n" + "Please try another update branch (snapshot, beta, stable).", ButtonType.OK);
                        alert.setHeaderText("osumer - Version not available");
                        alert.showAndWait();
                    }
                });
                checkingUpdate = false;
                return;
            } catch (NoSuchBuildNumberException e) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        updateText.setText("This version has a invalid build number. See dump");
                        Alert alert = new Alert(AlertType.WARNING, "We don't have build number greater or equal to " + Osumer.OSUMER_BUILD_NUM + " in version " + Osumer.OSUMER_VERSION + ".\n" + "If you are using a modified/development osumer,\n" + " you can just ignore this message.\n" + "If not, this might be the versions.json in GitHub goes wrong,\n" + " post a new issue about this.", ButtonType.OK);
                        alert.setHeaderText("osumer - Build not available");
                        alert.showAndWait();
                    }
                });
                checkingUpdate = false;
                return;
            } catch (WithDumpException e) {
                e.printStackTrace();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        updateText.setText("Could not connect to update server.");
                        Alert alert = new Alert(AlertType.ERROR, "Could not connect to update server.", ButtonType.OK);
                        alert.setHeaderText("osumer - Error Checking Update");
                        alert.showAndWait();
                    }
                });
                checkingUpdate = false;
                return;
            }
            final UpdateInfo _verInfo = verInfo;
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    if (_verInfo == null) {
                        updateText.setText("Could not obtain update info.");
                        Alert alert = new Alert(AlertType.ERROR, "Could not obtain update info.", ButtonType.OK);
                        alert.setHeaderText("osumer - Error Checking Update");
                        alert.showAndWait();
                        checkingUpdate = false;
                        return;
                    }
                    if (_verInfo.isThisVersion()) {
                        updateText.setText("Running the latest: " + " " + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum());
                        checkingUpdate = false;
                        return;
                    }
                    updateText.setText((_verInfo.isUpgradedVersion() ? "Upgrade" : "Update") + " now to " + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum());
                    Alert alert = new Alert(AlertType.INFORMATION, "", ButtonType.YES);
                    alert.getButtonTypes().add(ButtonType.NO);
                    alert.setHeaderText("Update available");
                    String desc = _verInfo.getDescription();
                    alert.setContentText("New " + (_verInfo.isUpgradedVersion() ? "upgrade" : "update") + " available! New version:\n" + _verInfo.getVersion() + "-" + Updater.getBranchStr(_verInfo.getBranch()) + "-b" + _verInfo.getBuildNum() + "\n\n" + "Do you want to update it now?");
                    ButtonType detailsBtn = new ButtonType("Details");
                    if (desc != null) {
                        alert.getButtonTypes().add(detailsBtn);
                    }
                    Alert detailsAlert = new Alert(AlertType.NONE, "", ButtonType.OK);
                    detailsAlert.setHeaderText("Change-log");
                    detailsAlert.setContentText(desc);
                    ButtonType result;
                    do {
                        alert.showAndWait();
                        result = alert.getResult();
                        if (result == detailsBtn) {
                            detailsAlert.showAndWait();
                        }
                    } while (result == detailsBtn);
                    if (result == ButtonType.YES) {
                        try {
                            String updaterLink = Updater.getUpdaterLink();
                            if (updaterLink == null) {
                                System.out.println("No latest updater .exe defined! Falling back to legacy updater!");
                                updaterLink = Updater.LEGACY_UPDATER_JAR;
                            }
                            URL url;
                            try {
                                url = new URL(updaterLink);
                            } catch (MalformedURLException e) {
                                e.printStackTrace();
                                Alert alert0 = new Alert(AlertType.ERROR, "Error:\n" + e, ButtonType.OK);
                                alert0.showAndWait();
                                return;
                            }
                            final String folder = System.getProperty("java.io.tmpdir");
                            final String fileName = "osumer_updater_" + Calendar.getInstance().getTimeInMillis() + ".exe";
                            FXMLLoader loader = new FXMLLoader();
                            loader.setLocation(AppMain.class.getResource("/view/ProgressDialogLayout.fxml"));
                            DialogPane progressPane = null;
                            try {
                                progressPane = (DialogPane) loader.load();
                            } catch (IOException e1) {
                                e1.printStackTrace();
                            }
                            ProgressDialogController progressController = loader.getController();
                            progressController.getHeaderText().setText("Update");
                            progressController.getStatusText().setText("Status: Initializing...");
                            progressController.getProgressBar().setProgress(-1);
                            boolean noClose = false;
                            Alert progressDialog = new Alert(AlertType.NONE);
                            progressDialog.initStyle(StageStyle.UTILITY);
                            progressDialog.initModality(Modality.APPLICATION_MODAL);
                            progressDialog.setTitle("");
                            progressDialog.setDialogPane(progressPane);
                            progressDialog.getButtonTypes().add(ButtonType.CANCEL);
                            Thread thread = new Thread() {

                                public void run() {
                                    Platform.runLater(new Runnable() {

                                        @Override
                                        public void run() {
                                            progressController.getStatusText().setText("Status: Downloading updater...");
                                        }
                                    });
                                    URLDownloader dwn = new URLDownloader(folder, fileName, url);
                                    dwn.download();
                                    while (dwn.getStatus() == OsuDownloader.DOWNLOADING) {
                                        if (this.isInterrupted()) {
                                            return;
                                        }
                                        int progress = (int) dwn.getProgress();
                                        Platform.runLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                progressController.getProgressBar().setProgress(progress / 100.0);
                                            }
                                        });
                                        try {
                                            Thread.sleep(50);
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                    Platform.runLater(new Runnable() {

                                        @Override
                                        public void run() {
                                            progressController.getProgressBar().setProgress(-1);
                                        }
                                    });
                                    if (dwn.getStatus() == OsuDownloader.ERROR) {
                                        Platform.runLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                progressController.getStatusText().setText("Status: Error when downloading updater. Please restart osumer.");
                                            }
                                        });
                                        System.out.println("Download failed.");
                                    } else if (dwn.getStatus() == OsuDownloader.COMPLETED) {
                                        String loc = folder + "\\" + fileName;
                                        Platform.runLater(new Runnable() {

                                            @Override
                                            public void run() {
                                                progressController.getStatusText().setText("Status: Download completed. Starting...");
                                            }
                                        });
                                        System.out.println("Download completed...");
                                        try {
                                            Thread.sleep(2000);
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                        try {
                                            Runtime.getRuntime().exec("cmd.exe /c " + loc + " -install");
                                        } catch (IOException e1) {
                                            e1.printStackTrace();
                                            DumpManager.addDump(new DebugDump(null, "(If[openFile] scope) (UI) Set status to lblStatus", "(Try scope) Open file loc using Desktop.getDesktop.open()", "(Try scope) Sleep 2000 ms (2 sec)", "Unable to open file", false, e1));
                                        }
                                        try {
                                            Thread.sleep(2000);
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                        Platform.exit();
                                        System.exit(0);
                                        return;
                                    }
                                }
                            };
                            thread.start();
                            progressDialog.showAndWait();
                        } catch (WithDumpException e) {
                            e.printStackTrace();
                            checkingUpdate = false;
                            Alert alert0 = new Alert(AlertType.ERROR, "Error:\n" + e, ButtonType.OK);
                            alert0.showAndWait();
                            return;
                        }
                    }
                    checkingUpdate = false;
                }
            });
        }
    };
    thread.start();
}
Also used : NoSuchVersionException(com.github.mob41.osumer.exceptions.NoSuchVersionException) MalformedURLException(java.net.MalformedURLException) WithDumpException(com.github.mob41.osumer.debug.WithDumpException) NoBuildsForVersionException(com.github.mob41.osumer.exceptions.NoBuildsForVersionException) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) URLDownloader(com.github.mob41.osumer.io.URLDownloader) URL(java.net.URL) DialogPane(javafx.scene.control.DialogPane) NoSuchBuildNumberException(com.github.mob41.osumer.exceptions.NoSuchBuildNumberException) Alert(javafx.scene.control.Alert) ButtonType(javafx.scene.control.ButtonType) DebugDump(com.github.mob41.osumer.debug.DebugDump) UpdateInfo(com.github.mob41.osumer.updater.UpdateInfo)

Aggregations

NoBuildsForVersionException (com.github.mob41.osumer.exceptions.NoBuildsForVersionException)2 NoSuchBuildNumberException (com.github.mob41.osumer.exceptions.NoSuchBuildNumberException)2 NoSuchVersionException (com.github.mob41.osumer.exceptions.NoSuchVersionException)2 UpdateInfo (com.github.mob41.osumer.updater.UpdateInfo)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)1 DebugDump (com.github.mob41.osumer.debug.DebugDump)1 WithDumpException (com.github.mob41.osumer.debug.WithDumpException)1 URLDownloader (com.github.mob41.osumer.io.URLDownloader)1 URLDownloader (com.github.mob41.osumer.io.legacy.URLDownloader)1 Queue (com.github.mob41.osumer.io.queue.Queue)1 QueueAction (com.github.mob41.osumer.io.queue.QueueAction)1 UpdaterRunAction (com.github.mob41.osumer.io.queue.actions.UpdaterRunAction)1 SockThread (com.github.mob41.osumer.sock.SockThread)1 AnnouncementChecker (com.github.mob41.osumer.updater.AnnouncementChecker)1 Updater (com.github.mob41.osumer.updater.Updater)1 Color (java.awt.Color)1 EventQueue (java.awt.EventQueue)1 IOException (java.io.IOException)1