From d8dbbc5fbd4998b0de0e979e25ba231bbbfd3f22 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Tue, 21 Nov 2023 21:25:59 +0800 Subject: [PATCH] cpu Affinity --- lib/ui/home/home_ui_model.dart | 25 ++++++++++++++++++-- lib/ui/home/login/login_dialog_ui_model.dart | 6 +++-- lib/ui/settings/settings_ui.dart | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index a880bc3..1f7b4fe 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -526,11 +526,32 @@ class HomeUIModel extends BaseUIModel { return (map["status"] == "ok" || map["status"] == "operational"); } - doLaunchGame(String launchExe, List args, String installPath) async { + doLaunchGame(String launchExe, List args, String installPath, + int? processorAffinity) async { _isGameRunning[installPath] = true; notifyListeners(); try { - await Process.run(launchExe, args); + if (processorAffinity == null) { + ProcessResult result = await Process.run(launchExe, args); + dPrint('Exit code: ${result.exitCode}'); + dPrint('stdout: ${result.stdout}'); + dPrint('stderr: ${result.stderr}'); + } else { + ProcessResult result = await Process.run("cmd.exe", [ + '/C', + 'Start', + '"StarCitizen"', + '/High', + '/Affinity', + '$processorAffinity', + launchExe, + ...args + ]); + dPrint('Exit code: ${result.exitCode}'); + dPrint('stdout: ${result.stdout}'); + dPrint('stderr: ${result.stderr}'); + } + final launchFile = File("$installPath\\loginData.json"); if (await launchFile.exists()) { await launchFile.delete(); diff --git a/lib/ui/home/login/login_dialog_ui_model.dart b/lib/ui/home/login/login_dialog_ui_model.dart index dffc44b..960a706 100644 --- a/lib/ui/home/login/login_dialog_ui_model.dart +++ b/lib/ui/home/login/login_dialog_ui_model.dart @@ -228,11 +228,13 @@ class LoginDialogModel extends BaseUIModel { await SystemHelper.getCpuAffinity(inputGameLaunchECore); // TODO 更新启动方式 - homeUIModel.doLaunchGame( '$installPath\\$executable', ["-no_login_dialog", ...launchOptions.toString().split(" ")], - installPath); + installPath, + processorAffinity); + await Future.delayed(const Duration(seconds: 1)); + Navigator.pop(context!); } String getChannelID() { diff --git a/lib/ui/settings/settings_ui.dart b/lib/ui/settings/settings_ui.dart index 11b2f4c..6d5f1d1 100644 --- a/lib/ui/settings/settings_ui.dart +++ b/lib/ui/settings/settings_ui.dart @@ -19,7 +19,7 @@ class SettingUI extends BaseUI { onTap: model.onResetAutoLogin), const SizedBox(height: 12), makeSettingsItem(const Icon(FontAwesomeIcons.microchip), - "启动游戏时忽略能效核心( 适用于Intel 12 ~ 14th处理器 )", + "启动游戏时忽略能效核心( 适用于Intel 12+ 处理器 )", subTitle: "已设置的核心数量:${model.inputGameLaunchECore} ( 设置需要忽略的处理器的能效心数量,盒子将在使用启动游戏功能时为您修改游戏所运行的CPU参数,当为 0 时不启用此功能 )", onTap: model.setGameLaunchECore),