mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 13:17:00 +08:00
Opt: Add start/stop LDPlayer,NoxPlayer,BlueStack4,MEmuPlayer support. (#3867)
* Opt: Add start/stop LDPlayer,NoxPlayer,BlueStack4,MEmuPlayer support. * Upd: fixed. * fix * Upd: Bug fix. * Upd: fix * Upd: Add single_to_console method. * Upd: fix texts. --------- Co-authored-by: LmeSzinc <lmeszincsales@gmail.com>
This commit is contained in:
@@ -82,7 +82,7 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
"""
|
||||
Start a emulator without error handling
|
||||
"""
|
||||
exe = instance.emulator.path
|
||||
exe: str = instance.emulator.path
|
||||
if instance == Emulator.MuMuPlayer:
|
||||
# NemuPlayer.exe
|
||||
self.execute(exe)
|
||||
@@ -94,6 +94,9 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
if instance.MuMuPlayer12_id is None:
|
||||
logger.warning(f'Cannot get MuMu instance index from name {instance.name}')
|
||||
self.execute(f'"{exe}" -v {instance.MuMuPlayer12_id}')
|
||||
elif instance == Emulator.LDPlayerFamily:
|
||||
# LDPlayer.exe index=0
|
||||
self.execute(f'"{exe}" index={instance.LDPlayer_id}')
|
||||
elif instance == Emulator.NoxPlayerFamily:
|
||||
# Nox.exe -clone:Nox_1
|
||||
self.execute(f'"{exe}" -clone:{instance.name}')
|
||||
@@ -101,8 +104,11 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
# HD-Player.exe -instance Pie64
|
||||
self.execute(f'"{exe}" -instance {instance.name}')
|
||||
elif instance == Emulator.BlueStacks4:
|
||||
# BlueStacks\Client\Bluestacks.exe -vmname Android_1
|
||||
# Bluestacks.exe -vmname Android_1
|
||||
self.execute(f'"{exe}" -vmname {instance.name}')
|
||||
elif instance == Emulator.MEmuPlayer:
|
||||
# MEmu.exe MEmu_0
|
||||
self.execute(f'"{exe}" {instance.name}')
|
||||
else:
|
||||
raise EmulatorUnknown(f'Cannot start an unknown emulator instance: {instance}')
|
||||
|
||||
@@ -110,8 +116,7 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
"""
|
||||
Stop a emulator without error handling
|
||||
"""
|
||||
logger.hr('Emulator stop', level=2)
|
||||
exe = instance.emulator.path
|
||||
exe: str = instance.emulator.path
|
||||
if instance == Emulator.MuMuPlayer:
|
||||
# MuMu6 does not have multi instance, kill one means kill all
|
||||
# Has 4 processes
|
||||
@@ -141,26 +146,35 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
rf')'
|
||||
)
|
||||
elif instance == Emulator.MuMuPlayer12:
|
||||
# MuMu 12 has 2 processes:
|
||||
# E:\ProgramFiles\Netease\MuMuPlayer-12.0\shell\MuMuPlayer.exe -v 0
|
||||
# "C:\Program Files\MuMuVMMVbox\Hypervisor\MuMuVMMHeadless.exe" --comment MuMuPlayer-12.0-0 --startvm xxx
|
||||
# E:\Program Files\Netease\MuMu Player 12\shell\MuMuManager.exe api -v 1 shutdown_player
|
||||
if instance.MuMuPlayer12_id is None:
|
||||
logger.warning(f'Cannot get MuMu instance index from name {instance.name}')
|
||||
self.kill_process_by_regex(
|
||||
rf'('
|
||||
rf'MuMuVMMHeadless.exe.*--comment {instance.name}'
|
||||
rf'|MuMuPlayer.exe.*-v {instance.MuMuPlayer12_id}'
|
||||
rf')'
|
||||
)
|
||||
# There is also a shared service, no need to kill it
|
||||
# "C:\Program Files\MuMuVMMVbox\Hypervisor\MuMuVMMSVC.exe" --Embedding
|
||||
self.execute(f'"{Emulator.single_to_console(exe)}" api -v {instance.MuMuPlayer12_id} shutdown_player')
|
||||
elif instance == Emulator.LDPlayerFamily:
|
||||
# E:\Program Files\leidian\LDPlayer9\dnconsole.exe quit --index 0
|
||||
self.execute(f'"{Emulator.single_to_console(exe)}" quit --index {instance.LDPlayer_id}')
|
||||
elif instance == Emulator.NoxPlayerFamily:
|
||||
# Nox.exe -clone:Nox_1 -quit
|
||||
self.execute(f'"{exe}" -clone:{instance.name} -quit')
|
||||
elif instance == Emulator.BlueStacks5:
|
||||
# BlueStack has 2 processes
|
||||
# C:\Program Files\BlueStacks_nxt_cn\HD-Player.exe --instance Pie64
|
||||
# C:\Program Files\BlueStacks_nxt_cn\BstkSVC.exe -Embedding
|
||||
self.kill_process_by_regex(
|
||||
rf'('
|
||||
rf'HD-Player.exe.*"--instance" "{instance.name}"'
|
||||
rf')'
|
||||
)
|
||||
elif instance == Emulator.BlueStacks4:
|
||||
# E:\Program Files (x86)\BluestacksCN\bsconsole.exe quit --name Android
|
||||
self.execute(f'"{Emulator.single_to_console(exe)}" quit --name {instance.name}')
|
||||
elif instance == Emulator.MEmuPlayer:
|
||||
# F:\Program Files\Microvirt\MEmu\memuc.exe stop -n MEmu_0
|
||||
self.execute(f'"{Emulator.single_to_console(exe)}" stop -n {instance.name}')
|
||||
else:
|
||||
raise EmulatorUnknown(f'Cannot stop an unknown emulator instance: {instance}')
|
||||
|
||||
def _emulator_function_wrapper(self, func):
|
||||
def _emulator_function_wrapper(self, func: callable):
|
||||
"""
|
||||
Args:
|
||||
func (callable): _emulator_start or _emulator_stop
|
||||
@@ -312,10 +326,22 @@ class PlatformWindows(PlatformBase, EmulatorManager):
|
||||
|
||||
def emulator_stop(self):
|
||||
logger.hr('Emulator stop', level=1)
|
||||
return self._emulator_function_wrapper(self._emulator_stop)
|
||||
|
||||
for _ in range(3):
|
||||
# Stop
|
||||
if self._emulator_function_wrapper(self._emulator_stop):
|
||||
# Success
|
||||
return True
|
||||
else:
|
||||
# Failed to stop, start and stop again
|
||||
if self._emulator_function_wrapper(self._emulator_start):
|
||||
continue
|
||||
else:
|
||||
return False
|
||||
|
||||
logger.error('Failed to stop emulator 3 times, stopped')
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
self = PlatformWindows('alas')
|
||||
d = self.emulator_instance
|
||||
print(d)
|
||||
print(d)
|
||||
Reference in New Issue
Block a user