Skip to content

Commit

Permalink
Automatically check game.prefs on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Mar 18, 2023
1 parent 0a9a80e commit f248651
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 63 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/faforever/client/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ public void afterPropertiesSet() {
onLoggedIn();
}
});

try {
patchGamePrefsForMultiInstances();
} catch (Exception e) {
log.error("Game.prefs patch failed", e);
}
}

private Mono<GameBean> initializeGameBean(GameInfo gameInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.NumberFormat;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -174,8 +173,6 @@ public class SettingsController implements Controller<Node> {
public Button clearCacheButton;
public CheckBox gameDataCacheCheckBox;
public Spinner<Integer> gameDataCacheTimeSpinner;
public CheckBox allowReplayWhileInGameCheckBox;
public Button allowReplayWhileInGameButton;
public ComboBox<Level> logLevelComboBox;
public CheckBox mapAndModAutoUpdateCheckBox;
public ListView<CoturnServer> preferredCoturnListView;
Expand Down Expand Up @@ -235,7 +232,6 @@ public void initialize() {
initAutoChannelListView();
initPreferredCoturnListView();
initUnitDatabaseSelection();
initAllowReplaysWhileInGame();
initNotifyMeOnAtMention();
initGameDataCache();
initMapAndModAutoUpdate();
Expand Down Expand Up @@ -423,19 +419,6 @@ private void initNotifyMeOnAtMention() {
notifyAtMentionDescription.setText(i18n.get("settings.chat.notifyOnAtMentionOnly.description", "@" + username));
}

private void initAllowReplaysWhileInGame() {
ForgedAlliancePrefs forgedAlliancePrefs = preferences.getForgedAlliance();
allowReplayWhileInGameCheckBox.setSelected(forgedAlliancePrefs.isAllowReplaysWhileInGame());
JavaFxUtil.bindBidirectional(allowReplayWhileInGameCheckBox.selectedProperty(), forgedAlliancePrefs.allowReplaysWhileInGameProperty());
try {
gameService.isGamePrefsPatchedToAllowMultiInstances()
.thenAccept(isPatched -> allowReplayWhileInGameButton.setDisable(isPatched));
} catch (IOException e) {
log.warn("Failed evaluating if game.prefs file is patched for multiple instances", e);
allowReplayWhileInGameButton.setDisable(true);
}
}

private void configureStartTab() {
WindowPrefs mainWindow = preferences.getMainWindow();
startTabChoiceBox.setItems(FXCollections.observableArrayList(NavigationItem.values()));
Expand Down Expand Up @@ -655,21 +638,6 @@ public void onAddAutoChannel() {
channelTextField.clear();
}

public void onPatchGamePrefsForMultipleInstances() {
try {
gameService.patchGamePrefsForMultiInstances()
.thenRun(() -> JavaFxUtil.runLater(() -> allowReplayWhileInGameButton.setDisable(true)))
.exceptionally(throwable -> {
log.error("Game.prefs patch failed", throwable);
notificationService.addImmediateErrorNotification(throwable, "settings.fa.patchGamePrefsFailed");
return null;
});
} catch (Exception e) {
log.error("Game.prefs patch failed", e);
notificationService.addImmediateErrorNotification(e, "settings.fa.patchGamePrefsFailed");
}
}

public void onUpdateDebuggerClicked() {
DownloadFAFDebuggerTask downloadFAFDebuggerTask = applicationContext.getBean(DownloadFAFDebuggerTask.class);
taskService.submitTask(downloadFAFDebuggerTask).getFuture().exceptionally(throwable -> {
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,6 @@ chat.error.noHashTag = Channel Name must start with \# (Try \#{0})
game.gameStatus.hosting = Hosting
mod.idNumber = \#{0}
label.copy = copy
settings.fa.allowReplayWhileInGame = Allow watching replays while in game
settings.fa.patchGamePrefs = Patch Game.prefs
settings.fa.allowReplayWhileInGame.description = If you activate this functionality you can watch replays while being in game or in queue. Besides checking the box you will also need to activate this in your game.prefs file, if you click the button below we can do that for you. If it is disabled your game.prefs are already patched. Be aware that this will increase disk space usage.
settings.fa.patchGamePrefsFailed = Failed to patch the game.prefs file.
settings.fa.allowReplayWhileInGame.experimental = experimental
error.game.filesNotAccessible = Some files from the installed game could not be copied over to FAF but unless you recently modified game files in the installed version you probably do not care. We are still starting the game for you.
game.gameRunning = Game could not be started because an instance of Forged Alliance is already running.
replay.replayRunning = Replay could not be started because another replay is already running.
Expand Down
26 changes: 0 additions & 26 deletions src/main/resources/theme/settings/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -820,32 +820,6 @@
GridPane.columnSpan="2147483647" GridPane.rowIndex="1"/>
</children>
</GridPane>
<GridPane hgap="10.0" styleClass="setting-container">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
<ColumnConstraints minWidth="10.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" valignment="TOP" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label contentDisplay="RIGHT" maxWidth="1.7976931348623157E308"
styleClass="setting-title"
text="%settings.fa.allowReplayWhileInGame">
</Label>
<Button fx:id="allowReplayWhileInGameButton" minWidth="-Infinity"
mnemonicParsing="false"
onAction="#onPatchGamePrefsForMultipleInstances"
text="%settings.fa.patchGamePrefs" GridPane.rowIndex="2"/>
<CheckBox fx:id="allowReplayWhileInGameCheckBox"
GridPane.columnIndex="1"/>
<Label styleClass="setting-description"
text="%settings.fa.allowReplayWhileInGame.description"
GridPane.columnSpan="2147483647" GridPane.rowIndex="1"/>
</children>
</GridPane>
<GridPane styleClass="setting-container">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
Expand Down

0 comments on commit f248651

Please sign in to comment.