Search in sources :

Example 1 with Downloader

use of kml.game.download.Downloader in project Krothium-Launcher by DarkLBP.

the class MainFX method launchGame.

/**
 * Downloads and launches the game
 */
@FXML
public final void launchGame() {
    progressPane.setVisible(true);
    playPane.setVisible(false);
    progressBar.setProgress(0);
    progressText.setText("");
    final Downloader d = kernel.getDownloader();
    final GameLauncher gl = kernel.getGameLauncher();
    // Keep track of the progress
    final TimerTask progressTask = new TimerTask() {

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

                @Override
                public void run() {
                    MainFX.this.progressBar.setProgress(d.getProgress());
                    MainFX.this.progressText.setText(Language.get(13) + ' ' + d.getCurrentFile() + "...");
                }
            });
        }
    };
    Thread runThread = new Thread(new Runnable() {

        @Override
        public void run() {
            // Begin download and game launch task
            try {
                Timer timer = new Timer();
                timer.schedule(progressTask, 0, 25);
                d.download();
                timer.cancel();
                timer.purge();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        progressText.setText(Language.get(78));
                        progressBar.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
                    }
                });
                gl.launch(MainFX.this);
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        progressPane.setVisible(false);
                        playPane.setVisible(true);
                        playButton.setText(Language.get(14));
                        playButton.setDisable(true);
                        profilePopupButton.setDisable(true);
                    }
                });
                if (!settings.getKeepLauncherOpen()) {
                    Platform.runLater(new Runnable() {

                        @Override
                        public void run() {
                            MainFX.this.stage.close();
                        }
                    });
                }
            } catch (DownloaderException e) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        kernel.showAlert(Alert.AlertType.ERROR, Language.get(83), Language.get(84));
                    }
                });
                console.print("Failed to perform game download task");
                e.printStackTrace(console.getWriter());
            } catch (GameLauncherException e) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        kernel.showAlert(Alert.AlertType.ERROR, Language.get(81), Language.get(82));
                    }
                });
                console.print("Failed to perform game launch task");
                e.printStackTrace(console.getWriter());
            }
        }
    });
    runThread.start();
}
Also used : DownloaderException(kml.exceptions.DownloaderException) Downloader(kml.game.download.Downloader) GameLauncher(kml.game.GameLauncher) GameLauncherException(kml.exceptions.GameLauncherException) FXML(javafx.fxml.FXML)

Aggregations

FXML (javafx.fxml.FXML)1 DownloaderException (kml.exceptions.DownloaderException)1 GameLauncherException (kml.exceptions.GameLauncherException)1 GameLauncher (kml.game.GameLauncher)1 Downloader (kml.game.download.Downloader)1