diff --git a/lib/common/helper/system_helper.dart b/lib/common/helper/system_helper.dart index 094b18e..ff13e5e 100644 --- a/lib/common/helper/system_helper.dart +++ b/lib/common/helper/system_helper.dart @@ -218,9 +218,26 @@ foreach ($adapter in $adapterMemory) { return int.tryParse(cpuNumberResult.stdout.toString().trim()) ?? 0; } - static Future getCpuAffinity(int eCoreCount) async { + static Future 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(); } } diff --git a/lib/ui/home/home_ui_model.dart b/lib/ui/home/home_ui_model.dart index 1f7b4fe..c36d1db 100644 --- a/lib/ui/home/home_ui_model.dart +++ b/lib/ui/home/home_ui_model.dart @@ -527,7 +527,7 @@ class HomeUIModel extends BaseUIModel { } doLaunchGame(String launchExe, List 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 ]);