From faec46347807b9b10d244215963875967491cc95 Mon Sep 17 00:00:00 2001 From: xkeyC <3334969096@qq.com> Date: Tue, 21 Nov 2023 01:05:20 +0800 Subject: [PATCH] update Cpu Affinity --- lib/common/helper/system_helper.dart | 13 ++++++++ lib/common/utils/base_utils.dart | 34 ++++++++++++++++++++ lib/ui/home/home_ui_model.dart | 3 +- lib/ui/home/login/login_dialog_ui.dart | 6 ++-- lib/ui/home/login/login_dialog_ui_model.dart | 16 ++++++--- lib/ui/settings/settings_ui.dart | 13 ++++++-- lib/ui/settings/settings_ui_model.dart | 24 ++++++++++++++ lib/ui/tools/tools_ui_model.dart | 3 +- 8 files changed, 99 insertions(+), 13 deletions(-) diff --git a/lib/common/helper/system_helper.dart b/lib/common/helper/system_helper.dart index b898783..d626792 100644 --- a/lib/common/helper/system_helper.dart +++ b/lib/common/helper/system_helper.dart @@ -201,4 +201,17 @@ foreach ($adapter in $adapterMemory) { } catch (_) {} return totalSize; } + + static Future getNumberOfLogicalProcessors() async { + final cpuNumberResult = await Process.run(powershellPath, + ["(Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors"]); + if (cpuNumberResult.exitCode != 0) return 0; + return int.tryParse(cpuNumberResult.stdout.toString().trim()) ?? 0; + } + + static Future getCpuAffinity(int eCoreCount) async { + final cpuNumber = await getNumberOfLogicalProcessors(); + if (cpuNumber == 0) return null; + return (1 << cpuNumber) - (1 << eCoreCount); + } } diff --git a/lib/common/utils/base_utils.dart b/lib/common/utils/base_utils.dart index 2bdd774..1a4b1e7 100644 --- a/lib/common/utils/base_utils.dart +++ b/lib/common/utils/base_utils.dart @@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'dart:ui' as ui; +import 'package:flutter/services.dart'; + void dPrint(src) { if (kDebugMode) { print(src); @@ -58,6 +60,38 @@ Future showConfirmDialogs( return r == true; } +Future showInputDialogs(BuildContext context, + {required String title, + required String content, + BoxConstraints? constraints, + String? initialValue, + List? inputFormatters}) async { + String? userInput; + constraints ??= + BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .38); + final ok = await showConfirmDialogs( + context, + title, + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (content.isNotEmpty) Text(content), + const SizedBox(height: 6), + TextFormBox( + initialValue: initialValue, + onChanged: (str) { + userInput = str; + }, + inputFormatters: inputFormatters, + ), + ], + ), + constraints: constraints); + if (ok == true) return userInput; + return null; +} + Future showBaseDialog(BuildContext context, {required String title, required Widget content, diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index 1f9b4df..a880bc3 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -134,8 +134,7 @@ class HomeUIModel extends BaseUIModel { return; } scInstallPaths = await SCLoggerHelper.getGameInstallPath(listData, - withVersion: ["LIVE", "PTU", "EPTU", "TECH-PREVIEW"], - checkExists: true); + withVersion: ["LIVE", "PTU", "EPTU"], checkExists: true); if (scInstallPaths.isNotEmpty) { scInstalledPath = scInstallPaths.first; } diff --git a/lib/ui/home/login/login_dialog_ui.dart b/lib/ui/home/login/login_dialog_ui.dart index bada6ec..a563bb3 100644 --- a/lib/ui/home/login/login_dialog_ui.dart +++ b/lib/ui/home/login/login_dialog_ui.dart @@ -49,7 +49,7 @@ class LoginDialog extends BaseUI { color: Colors.white.withOpacity(.6), ), ) - ] else if (model.loginStatus == 2) ...[ + ] else if (model.loginStatus == 2 || model.loginStatus == 3) ...[ Center( child: Column( children: [ @@ -76,7 +76,9 @@ class LoginDialog extends BaseUI { fontSize: 24, fontWeight: FontWeight.bold), ), const SizedBox(height: 32), - const Text("正在为您启动游戏..."), + Text(model.loginStatus == 2 + ? "正在为您启动游戏..." + : "正在等待优化CPU参数..."), const SizedBox(height: 12), const ProgressRing(), ], diff --git a/lib/ui/home/login/login_dialog_ui_model.dart b/lib/ui/home/login/login_dialog_ui_model.dart index 469efb0..dffc44b 100644 --- a/lib/ui/home/login/login_dialog_ui_model.dart +++ b/lib/ui/home/login/login_dialog_ui_model.dart @@ -7,6 +7,7 @@ import 'package:hive/hive.dart'; import 'package:jwt_decode/jwt_decode.dart'; import 'package:local_auth/local_auth.dart'; import 'package:starcitizen_doctor/base/ui_model.dart'; +import 'package:starcitizen_doctor/common/helper/system_helper.dart'; import 'package:starcitizen_doctor/common/win32/credentials.dart'; import 'package:starcitizen_doctor/ui/home/home_ui_model.dart'; import 'package:starcitizen_doctor/ui/home/webview/webview.dart'; @@ -217,12 +218,21 @@ class LoginDialogModel extends BaseUIModel { await launchFile.writeAsString(json.encode(launchData)); notifyListeners(); await Future.delayed(const Duration(seconds: 1)); + + await Future.delayed(const Duration(seconds: 3)); + final confBox = await Hive.openBox("app_conf"); + final inputGameLaunchECore = int.tryParse( + confBox.get("gameLaunch_eCore_count", defaultValue: "0")) ?? + 0; + final processorAffinity = + await SystemHelper.getCpuAffinity(inputGameLaunchECore); + + // TODO 更新启动方式 + homeUIModel.doLaunchGame( '$installPath\\$executable', ["-no_login_dialog", ...launchOptions.toString().split(" ")], installPath); - await Future.delayed(const Duration(seconds: 3)); - Navigator.pop(context!); } String getChannelID() { @@ -232,8 +242,6 @@ class LoginDialogModel extends BaseUIModel { return "PTU"; } else if (installPath.endsWith("\\EPTU")) { return "EPTU"; - } else if (installPath.endsWith("\\TECH-PREVIEW")) { - return "TECH-PREVIEW"; } return "LIVE"; } diff --git a/lib/ui/settings/settings_ui.dart b/lib/ui/settings/settings_ui.dart index 559df34..11b2f4c 100644 --- a/lib/ui/settings/settings_ui.dart +++ b/lib/ui/settings/settings_ui.dart @@ -1,3 +1,4 @@ +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:starcitizen_doctor/base/ui.dart'; import 'package:starcitizen_doctor/common/conf.dart'; import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart'; @@ -11,12 +12,18 @@ class SettingUI extends BaseUI { margin: const EdgeInsets.all(16), child: Column( children: [ - if (AppConf.isMSE) + if (AppConf.isMSE) ...[ makeSettingsItem(const Icon(FluentIcons.reset_device), "重置自动密码填充", subTitle: "启用:${model.isEnableAutoLogin ? "已启用" : "已禁用"} 设备支持:${model.isDeviceSupportWinHello ? "支持" : "不支持"} 邮箱:${model.autoLoginEmail} 密码:${model.isEnableAutoLoginPwd ? "已加密保存" : "未保存"}", - onTap: model.onResetAutoLogin) - else + onTap: model.onResetAutoLogin), + const SizedBox(height: 12), + makeSettingsItem(const Icon(FontAwesomeIcons.microchip), + "启动游戏时忽略能效核心( 适用于Intel 12 ~ 14th处理器 )", + subTitle: + "已设置的核心数量:${model.inputGameLaunchECore} ( 设置需要忽略的处理器的能效心数量,盒子将在使用启动游戏功能时为您修改游戏所运行的CPU参数,当为 0 时不启用此功能 )", + onTap: model.setGameLaunchECore), + ] else const Text("暂无设置项"), ], ), diff --git a/lib/ui/settings/settings_ui_model.dart b/lib/ui/settings/settings_ui_model.dart index e4541fa..12f5260 100644 --- a/lib/ui/settings/settings_ui_model.dart +++ b/lib/ui/settings/settings_ui_model.dart @@ -1,3 +1,4 @@ +import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; import 'package:local_auth/local_auth.dart'; import 'package:starcitizen_doctor/base/ui_model.dart'; @@ -10,6 +11,7 @@ class SettingUIModel extends BaseUIModel { String autoLoginEmail = "-"; bool isEnableAutoLogin = false; bool isEnableAutoLoginPwd = false; + String inputGameLaunchECore = "0"; @override loadData() async { @@ -18,6 +20,7 @@ class SettingUIModel extends BaseUIModel { notifyListeners(); if (AppConf.isMSE) { _updateAutoLoginAccount(); + _updateGameLaunchECore(); } } @@ -41,4 +44,25 @@ class SettingUIModel extends BaseUIModel { userBox.get("account_pwd_encrypted", defaultValue: "") != ""; notifyListeners(); } + + Future setGameLaunchECore() async { + final userBox = await Hive.openBox("app_conf"); + final defaultInput = + userBox.get("gameLaunch_eCore_count", defaultValue: "0"); + final input = await showInputDialogs(context!, + title: "请输入要忽略的 CPU 核心数", + content: "", + initialValue: defaultInput, + inputFormatters: [FilteringTextInputFormatter.digitsOnly]); + if (input == null) return; + userBox.put("gameLaunch_eCore_count", input); + reloadData(); + } + + Future _updateGameLaunchECore() async { + final userBox = await Hive.openBox("app_conf"); + inputGameLaunchECore = + userBox.get("gameLaunch_eCore_count", defaultValue: "0"); + notifyListeners(); + } } diff --git a/lib/ui/tools/tools_ui_model.dart b/lib/ui/tools/tools_ui_model.dart index 163a400..d3ef9bb 100644 --- a/lib/ui/tools/tools_ui_model.dart +++ b/lib/ui/tools/tools_ui_model.dart @@ -186,8 +186,7 @@ class ToolsUIModel extends BaseUIModel { return; } scInstallPaths = await SCLoggerHelper.getGameInstallPath(listData, - checkExists: false, - withVersion: ["LIVE", "PTU", "EPTU", "TECH-PREVIEW"]); + checkExists: false, withVersion: ["LIVE", "PTU", "EPTU"]); if (scInstallPaths.isNotEmpty) { scInstalledPath = scInstallPaths.first; }