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();
}
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));
}
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));
}
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)));
});
}
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());
}
Aggregations