Search in sources :

Example 1 with GameDirectoryChosenEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent in project downlords-faf-client by FAForever.

the class GamePathHandler method onGameDirectoryChosenEvent.

/**
 * Checks whether the chosen game path contains a ForgedAlliance.exe (either directly if the user selected the "bin"
 * directory, or in the "bin" sub folder). If the path is valid, it is stored in the preferences.
 */
@Subscribe
public void onGameDirectoryChosenEvent(GameDirectoryChosenEvent event) {
    Path path = event.getPath();
    if (path == null || !Files.isDirectory(path)) {
        notificationService.addNotification(new ImmediateNotification(i18n.get("gameChosen.invalidPath"), i18n.get("gameChosen.couldNotLocatedGame"), Severity.WARN));
        return;
    }
    if (!Files.isRegularFile(path.resolve(PreferencesService.FORGED_ALLIANCE_EXE)) && !Files.isRegularFile(path.resolve(PreferencesService.SUPREME_COMMANDER_EXE))) {
        onGameDirectoryChosenEvent(new GameDirectoryChosenEvent(path.resolve("bin")));
        return;
    }
    // At this point, path points to the "bin" directory
    Path gamePath = path.getParent();
    logger.info("Found game path at {}", gamePath);
    preferencesService.getPreferences().getForgedAlliance().setPath(gamePath);
    preferencesService.storeInBackground();
}
Also used : Path(java.nio.file.Path) GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with GameDirectoryChosenEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent in project downlords-faf-client by FAForever.

the class GamePathHandlerTest method testNotificationOnEmptyString.

@Test
public void testNotificationOnEmptyString() throws Exception {
    instance.onGameDirectoryChosenEvent(new GameDirectoryChosenEvent(Paths.get("")));
    verify(notificationService).addNotification(any(ImmediateNotification.class));
}
Also used : GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) Test(org.junit.Test)

Example 3 with GameDirectoryChosenEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent in project downlords-faf-client by FAForever.

the class GamePathHandlerTest method testNotificationOnNull.

@Test
public void testNotificationOnNull() throws Exception {
    instance.onGameDirectoryChosenEvent(new GameDirectoryChosenEvent(null));
    verify(notificationService).addNotification(any(ImmediateNotification.class));
}
Also used : GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) Test(org.junit.Test)

Example 4 with GameDirectoryChosenEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent in project downlords-faf-client by FAForever.

the class GameDirectoryRequiredHandler method onChooseGameDirectory.

@Subscribe
public void onChooseGameDirectory(GameDirectoryChooseEvent event) {
    runLater(() -> {
        DirectoryChooser directoryChooser = new DirectoryChooser();
        directoryChooser.setTitle(i18n.get("missingGamePath.chooserTitle"));
        File result = directoryChooser.showDialog(StageHolder.getStage().getScene().getWindow());
        logger.info("User selected game directory: {}", result);
        eventBus.post(new GameDirectoryChosenEvent(Optional.ofNullable(result).map(File::toPath).orElse(null)));
    });
}
Also used : GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser) Subscribe(com.google.common.eventbus.Subscribe)

Example 5 with GameDirectoryChosenEvent

use of com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent in project downlords-faf-client by FAForever.

the class GamePathHandler method detectGamePath.

private void detectGamePath() {
    for (Path path : USUAL_GAME_PATHS) {
        if (preferencesService.isGamePathValid(path.resolve("bin"))) {
            onGameDirectoryChosenEvent(new GameDirectoryChosenEvent(path));
            return;
        }
    }
    logger.info("Game path could not be detected");
    eventBus.post(new MissingGamePathEvent());
}
Also used : Path(java.nio.file.Path) GameDirectoryChosenEvent(com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent) MissingGamePathEvent(com.faforever.client.preferences.event.MissingGamePathEvent)

Aggregations

GameDirectoryChosenEvent (com.faforever.client.ui.preferences.event.GameDirectoryChosenEvent)5 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)3 Subscribe (com.google.common.eventbus.Subscribe)2 Path (java.nio.file.Path)2 Test (org.junit.Test)2 MissingGamePathEvent (com.faforever.client.preferences.event.MissingGamePathEvent)1 File (java.io.File)1 DirectoryChooser (javafx.stage.DirectoryChooser)1