mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
feat: Python添加Hyperv蓝叠的端口获取与模拟器启动函数
This commit is contained in:
33
src/Python/asst/emulator.py
Normal file
33
src/Python/asst/emulator.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
class Bluestacks:
|
||||
@staticmethod
|
||||
def get_hyperv_port(conf_path=r"C:\ProgramData\BlueStacks_nxt\bluestacks.conf", instance_name="Pie64") -> int:
|
||||
""" 获取Hyper-v版蓝叠的adb port
|
||||
|
||||
:param conf_path: bluestacks.conf 的路径+文件名
|
||||
:param instance_name: 多开的名称,在bluestacks.conf中以类似bst.instance.<instance_name>.status.adb_port的形式出现,如Nougat64,Pie64,Pie64_1等
|
||||
:return: adb端口
|
||||
"""
|
||||
with open(conf_path) as f:
|
||||
configs = dict(list(map(lambda line: line.replace('\n', '').split('='), f.readlines())))
|
||||
return int(configs[f'bst.instance.{instance_name}.status.adb_port'].replace('"', ""))
|
||||
|
||||
@staticmethod
|
||||
def launch_emulator_win(emulator_path=r'C:\Program Files\BlueStacks_nxt\HD-Player.exe', post_delay=30, arg_instance=None):
|
||||
""" 启动模拟器
|
||||
如需管理员权限启动模拟器则以管理员权限执行Python脚本
|
||||
|
||||
:param emulator_path: 模拟器可执行文件路径+文件名
|
||||
:param post_delay: 启动后的等待时间(s)
|
||||
:param arg_instance: 多开实例名,获取方式见get_hyperv_port注释。默认则置空。
|
||||
:return: 模拟器进程
|
||||
"""
|
||||
args = [emulator_path]
|
||||
if arg_instance:
|
||||
args += ["--instance", arg_instance]
|
||||
emulator_proc = subprocess.Popen(args)
|
||||
time.sleep(post_delay)
|
||||
return emulator_proc
|
||||
|
||||
@@ -5,6 +5,7 @@ import time
|
||||
from asst.asst import Asst
|
||||
from asst.utils import Message, Version
|
||||
from asst.updater import Updater
|
||||
from asst.emulator import Bluestacks
|
||||
|
||||
|
||||
@Asst.CallBackType
|
||||
@@ -37,6 +38,12 @@ if __name__ == "__main__":
|
||||
# 暂停下干员
|
||||
# asst.set_instance_option(InstanceOptionType.deployment_with_pause, '1')
|
||||
|
||||
# 启动模拟器。例如启动蓝叠模拟器的多开Pie64_1,并等待30s
|
||||
# Bluestacks.launch_emulator_win(r'C:\Program Files\BlueStacks_nxt\HD-Player.exe', 30, "Pie64_1")
|
||||
|
||||
# 获取Hyper-v蓝叠的adb port
|
||||
# port = Bluestacks.get_hyperv_port(r"C:\ProgramData\BlueStacks_nxt\bluestacks.conf", "Pie64_1")
|
||||
|
||||
# 请自行配置 adb 环境变量,或修改为 adb 可执行程序的路径
|
||||
if asst.connect('adb.exe', '127.0.0.1:5555'):
|
||||
print('连接成功')
|
||||
|
||||
Reference in New Issue
Block a user