From e43df7db1259de1107814d12bafb6ef32bfedbeb Mon Sep 17 00:00:00 2001 From: Sherkey <57581480+SherkeyXD@users.noreply.github.com> Date: Sat, 6 May 2023 17:11:37 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BB=8Ebluestacks.c?= =?UTF-8?q?onf=E4=B8=AD=E8=AF=BB=E5=8F=96=E6=A8=A1=E6=8B=9F=E5=99=A8?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/UI/SettingsViewModel.cs | 19 +++++++++++++++++-- src/Python/asst/emulator.py | 7 +++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index e181d6b58e..3354abe7ec 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -2225,14 +2225,14 @@ namespace MaaWpfGui.ViewModels.UI } private readonly string _bluestacksConfig = ConfigurationHelper.GetValue(ConfigurationKeys.BluestacksConfigPath, string.Empty); - private readonly string _bluestacksKeyWord = ConfigurationHelper.GetValue(ConfigurationKeys.BluestacksConfigKeyword, "bst.instance.Nougat64.status.adb_port"); + private string _bluestacksKeyWord = ConfigurationHelper.GetValue(ConfigurationKeys.BluestacksConfigKeyword, string.Empty); /// /// Tries to set Bluestack Hyper V address. /// public void TryToSetBlueStacksHyperVAddress() { - if (_bluestacksConfig.Length == 0) + if (String.IsNullOrEmpty(_bluestacksConfig)) { return; } @@ -2244,12 +2244,27 @@ namespace MaaWpfGui.ViewModels.UI } var all_lines = File.ReadAllLines(_bluestacksConfig); + + if (String.IsNullOrEmpty(_bluestacksKeyWord)) + { + foreach (var line in all_lines) + { + if (line.StartsWith("bst.installed_images")) + { + var images = line.Split('"')[1].Split(','); + _bluestacksKeyWord = "bst.instance." + images[0] + ".status.adb_port"; + break; + } + } + } + foreach (var line in all_lines) { if (line.StartsWith(_bluestacksKeyWord)) { var sp = line.Split('"'); ConnectAddress = "127.0.0.1:" + sp[1]; + break; } } } diff --git a/src/Python/asst/emulator.py b/src/Python/asst/emulator.py index 64df006e30..1416406934 100644 --- a/src/Python/asst/emulator.py +++ b/src/Python/asst/emulator.py @@ -3,15 +3,18 @@ import subprocess class Bluestacks: @staticmethod - def get_hyperv_port(conf_path=r"C:\ProgramData\BlueStacks_nxt\bluestacks.conf", instance_name="Pie64") -> int: + def get_hyperv_port(conf_path=r"C:\ProgramData\BlueStacks_nxt\bluestacks.conf", instance_name="Pie64", read_imageinfo_from_config=False) -> int: """ 获取Hyper-v版蓝叠的adb port :param conf_path: bluestacks.conf 的路径+文件名 :param instance_name: 多开的名称,在bluestacks.conf中以类似bst.instance..status.adb_port的形式出现,如Nougat64,Pie64,Pie64_1等 :return: adb端口 """ - with open(conf_path) as f: + with open(conf_path, encoding="UTF-8") as f: configs = dict(list(map(lambda line: line.replace('\n', '').split('='), f.readlines()))) + if read_imageinfo_from_config: + instances = [i.strip('"') for i in configs['bst.installed_images'].split(',')] + instance_name = instances[0] return int(configs[f'bst.instance.{instance_name}.status.adb_port'].replace('"', "")) @staticmethod