From 4739feb8ff6f19e54c668812b42eae65c9703419 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Sun, 27 Jul 2025 16:45:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20mumu=20emulator-xx?= =?UTF-8?q?xx=20=E6=A0=BC=E5=BC=8F=E5=9C=B0=E5=9D=80=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Helper/EmulatorHelper.cs | 31 +++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/MaaWpfGui/Helper/EmulatorHelper.cs b/src/MaaWpfGui/Helper/EmulatorHelper.cs index 2138cf95b9..00f1930edb 100644 --- a/src/MaaWpfGui/Helper/EmulatorHelper.cs +++ b/src/MaaWpfGui/Helper/EmulatorHelper.cs @@ -76,11 +76,36 @@ public class EmulatorHelper { emuIndex = int.TryParse(SettingsViewModel.ConnectSettings.MuMuEmulator12Extras.Index, out var indexParse) ? indexParse : 0; } - else + else if (address.Contains(':')) { string portStr = address.Split(':')[1]; - int port = int.Parse(portStr); - emuIndex = (port - 16384) / 32; + if (int.TryParse(portStr, out int port)) + { + emuIndex = (port - 16384) / 32; + } + else + { + _logger.Error("Failed to parse port from address {Address}", address); + return false; + } + } + else if (address.StartsWith("emulator-", StringComparison.OrdinalIgnoreCase)) + { + string[] parts = address.Split('-'); + if (parts.Length >= 2 && int.TryParse(parts[1], out int port)) + { + emuIndex = (port - 5554) / 2; + } + else + { + _logger.Error("Failed to parse port from emulator style address {Address}", address); + return false; + } + } + else + { + _logger.Error("Unsupported address format: {Address}", address); + return false; } // 尝试找到正在运行的模拟器进程