Skip to content

Commit

Permalink
Make high priority game optional (#2800)
Browse files Browse the repository at this point in the history
Fixes #2781
  • Loading branch information
micheljung committed Sep 24, 2022
1 parent a805b04 commit e941166
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.faforever.client.fa.Kernel32Ex.WindowsPriority;
import com.faforever.client.logging.LoggingService;
import com.faforever.client.player.PlayerService;
import com.faforever.client.preferences.ForgedAlliancePrefs;
import com.faforever.client.preferences.PreferencesService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -134,7 +135,8 @@ private LaunchCommandBuilder defaultLaunchCommand() {

@NotNull
private Process launch(List<String> launchCommand) throws IOException {
Path executeDirectory = preferencesService.getPreferences().getForgedAlliance().getExecutionDirectory();
ForgedAlliancePrefs prefs = preferencesService.getPreferences().getForgedAlliance();
Path executeDirectory = prefs.getExecutionDirectory();
if (executeDirectory == null) {
executeDirectory = getExecutablePath().getParent();
}
Expand All @@ -147,7 +149,9 @@ private Process launch(List<String> launchCommand) throws IOException {
log.info("Starting Forged Alliance with command: {} in directory: {}", processBuilder.command(), executeDirectory);

Process process = processBuilder.start();
ProcessUtils.setProcessPriority(process, WindowsPriority.HIGH_PRIORITY_CLASS);
if (prefs.isChangeProcessPriority()) {
ProcessUtils.setProcessPriority(process, WindowsPriority.HIGH_PRIORITY_CLASS);
}
return process;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class ForgedAlliancePrefs {
BooleanProperty showIceAdapterDebugWindow = new SimpleBooleanProperty(false);
ObservableSet<CoturnHostPort> preferredCoturnServers = FXCollections.observableSet();

/**
* Whether the game process' priority should be set to high after launch. Enabling this may cause issues with some
* antivirus programs, see <a href="https://github.com/FAForever/downlords-faf-client/issues/2781">#2781</a>.
*/
BooleanProperty changeProcessPriority = new SimpleBooleanProperty(false);

public Path getPreferencesFile() {
return preferencesFile.get();
}
Expand Down Expand Up @@ -204,4 +210,16 @@ public void setWarnNonAsciiVaultPath(boolean warnNonAsciiVaultPath) {
public BooleanProperty warnNonAsciiVaultPathProperty() {
return warnNonAsciiVaultPath;
}

public boolean isChangeProcessPriority() {
return changeProcessPriority.get();
}

public void setChangeProcessPriority(boolean changeProcessPriority) {
this.changeProcessPriority.set(changeProcessPriority);
}

public BooleanProperty changeProcessPriorityProperty() {
return changeProcessPriority;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class SettingsController implements Controller<Node> {
public Toggle defaultColorsToggle;
public CheckBox hideFoeToggle;
public CheckBox forceRelayToggle;
public CheckBox changeProcessPriorityToggle;
public TextField dataLocationTextField;
public TextField gameLocationTextField;
public TextField vaultLocationTextField;
Expand Down Expand Up @@ -309,6 +310,7 @@ private void bindGeneralPreferences() {
private void bindGamePreferences() {
ForgedAlliancePrefs forgedAlliancePrefs = preferencesService.getPreferences().getForgedAlliance();
forceRelayToggle.selectedProperty().bindBidirectional(forgedAlliancePrefs.forceRelayProperty());
changeProcessPriorityToggle.selectedProperty().bindBidirectional(forgedAlliancePrefs.changeProcessPriorityProperty());
gameLocationTextField.textProperty().bindBidirectional(forgedAlliancePrefs.installationPathProperty(), PATH_STRING_CONVERTER);
autoDownloadMapsToggle.selectedProperty().bindBidirectional(forgedAlliancePrefs.autoDownloadMapsProperty());
useFAFDebuggerToggle.selectedProperty().bindBidirectional(forgedAlliancePrefs.runFAWithDebuggerProperty());
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,8 @@ settings.notifications.position = Notification Position
settings.sounds.enable.description = Globally enable or disable all sounds.
settings.fa.autoDownloadMaps.description = Whether to download missing maps automatically.
settings.fa.forceRelay.description = Always use a relay server instead of trying to connect to peers directly. This results in slower connections but can solve connectivity issues.
settings.fa.changeProcessPriority = Use high process priority
settings.fa.changeProcessPriority.description = (Windows only) Set the game's process priority to "high". Some antivirus programs might not like this.
settings.fa.executableDecorator.description = How the client will execute the game executable. Leave it blank unless you know what you're doing.
settings.fa.executionDirectory.description = In which directory the game executable should be executed. Leave it blank unless you know what you're doing.
settings.chat.notifyOnAtMentionOnly.description = Only receive a chat notification if someone mentions you by using {0}.
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/theme/settings/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,27 @@
mnemonicParsing="false" GridPane.columnIndex="1"/>
</children>
</GridPane>
<GridPane hgap="10.0" styleClass="setting-container">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"
minWidth="10.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" valignment="TOP" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label contentDisplay="RIGHT" maxWidth="1.7976931348623157E308"
styleClass="setting-title" text="%settings.fa.changeProcessPriority"/>
<Label styleClass="setting-description"
text="%settings.fa.changeProcessPriority.description"
GridPane.columnSpan="2147483647" GridPane.hgrow="ALWAYS"
GridPane.rowIndex="1"/>
<CheckBox fx:id="changeProcessPriorityToggle" contentDisplay="GRAPHIC_ONLY"
mnemonicParsing="false" GridPane.columnIndex="1"/>
</children>
</GridPane>
<GridPane hgap="10.0" styleClass="setting-container">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"/>
Expand Down

0 comments on commit e941166

Please sign in to comment.