mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-22 23:23:43 +08:00
修复 Affinity 计算
This commit is contained in:
parent
e8a58a9c42
commit
3f637f4aef
@ -218,9 +218,26 @@ foreach ($adapter in $adapterMemory) {
|
||||
return int.tryParse(cpuNumberResult.stdout.toString().trim()) ?? 0;
|
||||
}
|
||||
|
||||
static Future<int?> getCpuAffinity(int eCoreCount) async {
|
||||
static Future<String?> getCpuAffinity(int eCoreCount) async {
|
||||
final cpuNumber = await getNumberOfLogicalProcessors();
|
||||
if (cpuNumber == 0) return null;
|
||||
return (1 << cpuNumber) - (1 << eCoreCount);
|
||||
if (cpuNumber == 0 || eCoreCount == 0 || eCoreCount > cpuNumber) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringBuffer sb = StringBuffer();
|
||||
for (var i = 0; i < cpuNumber; i++) {
|
||||
if (i < eCoreCount) {
|
||||
sb.write("0");
|
||||
} else {
|
||||
sb.write("1");
|
||||
}
|
||||
}
|
||||
final binaryString = sb.toString();
|
||||
int hexDigits = (binaryString.length / 4).ceil();
|
||||
dPrint("Affinity sb ==== $sb");
|
||||
return int.parse(binaryString, radix: 2)
|
||||
.toRadixString(16)
|
||||
.padLeft(hexDigits, '0')
|
||||
.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
@ -527,7 +527,7 @@ class HomeUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
doLaunchGame(String launchExe, List<String> args, String installPath,
|
||||
int? processorAffinity) async {
|
||||
String? processorAffinity) async {
|
||||
_isGameRunning[installPath] = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
@ -537,13 +537,14 @@ class HomeUIModel extends BaseUIModel {
|
||||
dPrint('stdout: ${result.stdout}');
|
||||
dPrint('stderr: ${result.stderr}');
|
||||
} else {
|
||||
dPrint("set Affinity === $processorAffinity ");
|
||||
ProcessResult result = await Process.run("cmd.exe", [
|
||||
'/C',
|
||||
'Start',
|
||||
'"StarCitizen"',
|
||||
'/High',
|
||||
'/Affinity',
|
||||
'$processorAffinity',
|
||||
processorAffinity,
|
||||
launchExe,
|
||||
...args
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user