Search in sources :

Example 1 with PlatformInfo

use of se.light.assembly64.model.PlatformInfo in project assembly64fx by freabemania.

the class Main method start.

@Override
public void start(Stage splashStage) {
    GlobalRepoService.getInstance().put("main", this);
    try {
        PlatformInfo platformInfo = platformInfoService.getPlatformInfo(platformInfoService.getPlaformPrefix());
        if (platformInfo.isNewerAvailable(version)) {
            try {
                UpgradeController upgradeDialog = GuiUtils.noShowDialog("upgrade.fxml", true, true, "New version available", splashStage, platformInfo);
                upgradeDialog.getStage().showAndWait();
                UpgradeOptions upgradeChoice = upgradeDialog.getUpgradeChoice();
                if (upgradeChoice == UpgradeOptions.DOWNLOAD) {
                    this.getHostServices().showDocument("http://hackerswithstyle.ddns.net/assembly/download.html");
                    ReturningTask<Void> exitWithDelay = () -> {
                        try {
                            Thread.sleep(500);
                            System.exit(1);
                        } catch (Exception e) {
                        }
                        return null;
                    };
                    ExecutorUtil.executeAsyncWithRetry(exitWithDelay);
                } else if (upgradeChoice == UpgradeOptions.UPGRADE) {
                    Autoupgrade.getInstance().doUpgrade();
                    return;
                }
            } catch (Exception e) {
                LOGGER.info("Unable to startup", e);
            }
        }
    } catch (Exception e) {
        OfflineController offlineController = (OfflineController) GuiUtils.showDialogBare("assemblyOffline.fxml", "Ooops :-/", new Object[] {});
        if (offlineController.openSidify()) {
            GuiUtils.showDialog("sidifyMain.fxml", true, "Sidify Heroium", new Object[] { Boolean.FALSE });
            return;
        } else {
            System.exit(1);
        }
    }
    GuiUtils.showDialog("authLogin.fxml", "Login to Assembly", new Object[] {});
    List<String> inputParams = getParameters().getRaw();
    if (platformInfoService.isWin() && inputParams.size() == 1) {
        File f = new File(inputParams.get(0));
        if (f.exists()) {
            launchViceOrImageView(f);
            System.exit(1);
        }
    }
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    maxHeight = bounds.getHeight() - 150;
    if (maxHeight > 700) {
        maxHeight = 700;
    }
    try {
        // Utils.getInstance().assertFolders();
        if (isAppActive()) {
            GenericMessageDialogController.withErrorProps("Another instance of", "Assembly64 is already active!").withExitAfterOk().showAndWait();
        }
        if (localDbService.getLocalDB().containsKey("uid")) {
            Analytics.sendEvent("application", "startup_existing_user_" + platformInfoService.getPlaformPrefix());
        } else {
            Analytics.sendEvent("application", "startup_new_user_" + platformInfoService.getPlaformPrefix());
        }
        ImageView splash = new ImageView(new Image(getClass().getResourceAsStream("image-assemblysplash.png")));
        splashLayout = new VBox();
        splashLayout.getChildren().addAll(splash);
        Scene splashScene = new Scene(splashLayout, Color.TRANSPARENT);
        splashStage.setScene(splashScene);
        splashStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
        splashStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
        splashStage.initStyle(StageStyle.TRANSPARENT);
        splashStage.setAlwaysOnTop(true);
        splashStage.show();
        ExecutorUtil.executeAsyncWithRetry(() -> {
            try {
                artifactsService.updateChecksumInPrivateFolder();
            } catch (Exception e) {
                LOGGER.error("Unable to update checksum", e);
            }
            return null;
        }, 5);
        ExecutorUtil.executeAsyncWithRetry(() -> {
            try {
                artifactsService.getArtifactsDb();
                refreshedArtifacts.set(true);
            } catch (Exception e) {
                LOGGER.error("Unable to get artifacts", e);
                Thread.sleep(1000);
                throw e;
            }
            return null;
        }, 5);
        ReturningTask<Void> continueTask = () -> {
            int retries = 0;
            while (retries < 5) {
                Thread.sleep(2000);
                if (refreshedArtifacts.get() == Boolean.TRUE) {
                    LOGGER.info("Got artifacts from server, ok to start");
                    break;
                }
                retries++;
            }
            if (refreshedArtifacts.get() == Boolean.FALSE) {
                Platform.runLater(() -> {
                    splashStage.close();
                });
                Platform.runLater(() -> {
                    GuiUtils.showDialog("assemblyOffline.fxml", "Ooops :-/", new Object[] {});
                    try {
                        Thread.sleep(10000);
                    } catch (Exception e) {
                    // TODO Auto-generated catch block
                    }
                });
            } else {
                FadeTransition fadeSplash2 = new FadeTransition(Duration.seconds(0.7), splashLayout);
                fadeSplash2.setFromValue(1.0);
                fadeSplash2.setToValue(0.0);
                fadeSplash2.setOnFinished(actionEvent -> {
                    splashStage.hide();
                    viewPrimary();
                });
                fadeSplash2.play();
            // }
            }
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(continueTask);
    } catch (Exception e) {
        GenericMessageDialogController.withErrorProps("Error", "Error when starting Assembly").withExitAfterOk().showAndWait();
    }
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) RandomAccessFile(java.io.RandomAccessFile) Scheduler(se.light.assembly64.Scheduler) TYPE(se.light.assembly64.model.GuiLocation.TYPE) LoggerFactory(org.slf4j.LoggerFactory) PathService(se.light.assembly64.service.PathService) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) FileLock(java.nio.channels.FileLock) Application(javafx.application.Application) ArtifactType(se.light.assembly64.model.ArtifactType) LogConfig(se.light.assembly64.LogConfig) ContextMenu(javafx.scene.control.ContextMenu) Type(se.light.assembly64.Support.Type) WindowEvent(javafx.stage.WindowEvent) WorkLocation(se.light.assembly64.model.WorkLocation) Pane(javafx.scene.layout.Pane) Rectangle2D(javafx.geometry.Rectangle2D) MenuItem(javafx.scene.control.MenuItem) ButtonType(se.light.assembly64.fx.GenericMessageDialogController.ButtonType) Set(java.util.Set) Screen(javafx.stage.Screen) Artifact(se.light.assembly64.model.Artifact) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) UserService(se.light.assembly64.service.UserService) Platform(javafx.application.Platform) Duration(javafx.util.Duration) List(java.util.List) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) Autoupgrade(se.light.assembly64.Autoupgrade) ReturningTask(se.light.assembly64.model.ReturningTask) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) GuiLocation(se.light.assembly64.model.GuiLocation) MouseEvent(javafx.scene.input.MouseEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) GenericMessageDialogController.heroesOnlyFeatureDialog(se.light.assembly64.fx.GenericMessageDialogController.heroesOnlyFeatureDialog) ArrayList(java.util.ArrayList) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) ViceService(se.light.assembly64.service.ViceService) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) FadeTransition(javafx.animation.FadeTransition) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Support.resolveInstallationExpandedKey(se.light.assembly64.Support.resolveInstallationExpandedKey) DirectoryChooser(javafx.stage.DirectoryChooser) Color(javafx.scene.paint.Color) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) MenuBar(javafx.scene.control.MenuBar) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) ArtifactsService(se.light.assembly64.service.ArtifactsService) File(java.io.File) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) PlatformInfo(se.light.assembly64.model.PlatformInfo) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Support.resolveLeafInInstallationExpandedKey(se.light.assembly64.Support.resolveLeafInInstallationExpandedKey) Image(javafx.scene.image.Image) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) FadeTransition(javafx.animation.FadeTransition) Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image) Scene(javafx.scene.Scene) PlatformInfo(se.light.assembly64.model.PlatformInfo) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) ImageView(javafx.scene.image.ImageView) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) VBox(javafx.scene.layout.VBox)

Aggregations

File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 FadeTransition (javafx.animation.FadeTransition)1 Application (javafx.application.Application)1 Platform (javafx.application.Platform)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1