From fa0f3317f2638dc4d3d7ebb2a0f031fe42e1b468 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:52:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A1=AB=E5=86=99=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E8=B7=AF=E5=BE=84=E6=97=B6=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConnectSettingsUserControlModel.cs | 199 +++++++++--------- 1 file changed, 104 insertions(+), 95 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs index d5bcae4366..362c423011 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs @@ -268,61 +268,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase if (value) { - MessageBoxHelper.Show(LocalizationHelper.GetString("MuMu12ExtrasEnabledTip")); - - // 读取mumu注册表地址 并填充GUI - if (string.IsNullOrEmpty(EmulatorPath)) - { - try - { - string[] possibleUninstallKeys = - [ - @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MuMuPlayer-12.0", - @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MuMuPlayer" - ]; - - const string UninstallExeName = @"\uninstall.exe"; - string? uninstallString = null; - foreach (var keyPath in possibleUninstallKeys) - { - using var driverKey = Registry.LocalMachine.OpenSubKey(keyPath); - if (driverKey == null) - { - continue; - } - - uninstallString = driverKey.GetValue("UninstallString") as string; - if (!string.IsNullOrEmpty(uninstallString) && uninstallString.Contains(UninstallExeName)) - { - break; - } - } - - if (string.IsNullOrEmpty(uninstallString)) - { - EmulatorPath = string.Empty; - return; - } - - if (string.IsNullOrEmpty(uninstallString) || !uninstallString.Contains(UninstallExeName)) - { - EmulatorPath = string.Empty; - return; - } - - var match = Regex.Match(uninstallString, - $""" - ^"(.*?){Regex.Escape(UninstallExeName)} - """, - RegexOptions.IgnoreCase); - EmulatorPath = match.Success ? match.Groups[1].Value : string.Empty; - } - catch (Exception e) - { - _logger.Warning("An error occurred: {EMessage}", e.Message); - EmulatorPath = string.Empty; - } - } + AutoDetectEmulatorPath(); } Instances.AsstProxy.Connected = false; @@ -330,6 +276,61 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase } } + private void AutoDetectEmulatorPath() + { + MessageBoxHelper.Show(LocalizationHelper.GetString("MuMu12ExtrasEnabledTip")); + + // 读取mumu注册表地址 并填充GUI + if (!string.IsNullOrEmpty(EmulatorPath)) + { + return; + } + + try + { + string[] possibleUninstallKeys = + [ + @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MuMuPlayer-12.0", + @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MuMuPlayer" + ]; + + const string UninstallExeName = @"\uninstall.exe"; + string? uninstallString = null; + foreach (var keyPath in possibleUninstallKeys) + { + using var driverKey = Registry.LocalMachine.OpenSubKey(keyPath); + if (driverKey == null) + { + continue; + } + + uninstallString = driverKey.GetValue("UninstallString") as string; + if (!string.IsNullOrEmpty(uninstallString) && uninstallString.Contains(UninstallExeName)) + { + break; + } + } + + if (string.IsNullOrEmpty(uninstallString) || string.IsNullOrEmpty(uninstallString) || !uninstallString.Contains(UninstallExeName)) + { + EmulatorPath = string.Empty; + return; + } + + var match = Regex.Match(uninstallString, + $""" + ^"(.*?){Regex.Escape(UninstallExeName)} + """, + RegexOptions.IgnoreCase); + EmulatorPath = match.Success ? match.Groups[1].Value : string.Empty; + } + catch (Exception e) + { + _logger.Warning("An error occurred: {EMessage}", e.Message); + EmulatorPath = string.Empty; + } + } + private static readonly string _configuredPath = ConfigurationHelper.GetValue(ConfigurationKeys.MuMu12EmulatorPath, @"C:\Program Files\Netease\MuMuPlayer-12.0"); private string _emulatorPath = Directory.Exists(_configuredPath) ? _configuredPath : string.Empty; @@ -344,7 +345,8 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase if (_enable && !string.IsNullOrEmpty(value) && !Directory.Exists(value)) { MessageBoxHelper.Show("MuMu Emulator 12 Path Not Found"); - value = string.Empty; + AutoDetectEmulatorPath(); + return; } Instances.AsstProxy.Connected = false; @@ -439,43 +441,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase if (value) { - MessageBoxHelper.Show(LocalizationHelper.GetString("LdExtrasEnabledTip")); - - // 读取 LD 注册表地址 并填充GUI - if (string.IsNullOrEmpty(EmulatorPath)) - { - try - { - string[] possiblePaths = - [ - @"Software\leidian\ldplayer9", // 原版路径优先 - @"Software\mrfz\mrfz" - ]; - - const string InstallDirValueName = "InstallDir"; - - foreach (var regPath in possiblePaths) - { - using var driverKey = Registry.CurrentUser.OpenSubKey(regPath); - if (driverKey == null) - { - continue; - } - - var installDir = driverKey.GetValue(InstallDirValueName) as string; - if (!string.IsNullOrEmpty(installDir)) - { - EmulatorPath = installDir; - break; - } - } - } - catch (Exception e) - { - _logger.Warning("An error occurred: {EMessage}", e.Message); - EmulatorPath = string.Empty; - } - } + AutoDetectEmulatorPath(); } Instances.AsstProxy.Connected = false; @@ -483,6 +449,49 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase } } + private void AutoDetectEmulatorPath() + { + MessageBoxHelper.Show(LocalizationHelper.GetString("LdExtrasEnabledTip")); + + // 读取 LD 注册表地址 并填充GUI + if (!string.IsNullOrEmpty(EmulatorPath)) + { + return; + } + + try + { + string[] possiblePaths = + [ + @"Software\leidian\ldplayer9", // 原版路径优先 + @"Software\mrfz\mrfz" + ]; + + const string InstallDirValueName = "InstallDir"; + + foreach (var regPath in possiblePaths) + { + using var driverKey = Registry.CurrentUser.OpenSubKey(regPath); + if (driverKey == null) + { + continue; + } + + var installDir = driverKey.GetValue(InstallDirValueName) as string; + if (!string.IsNullOrEmpty(installDir)) + { + EmulatorPath = installDir; + break; + } + } + } + catch (Exception e) + { + _logger.Warning("An error occurred: {EMessage}", e.Message); + EmulatorPath = string.Empty; + } + } + private static readonly string _configuredPath = ConfigurationHelper.GetValue(ConfigurationKeys.LdPlayerEmulatorPath, @"C:\leidian\LDPlayer9"); private string _emulatorPath = Directory.Exists(_configuredPath) ? _configuredPath : string.Empty; @@ -497,7 +506,8 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase if (_enable && !string.IsNullOrEmpty(value) && !Directory.Exists(value)) { MessageBoxHelper.Show("LD Emulator Path Not Found"); - value = string.Empty; + AutoDetectEmulatorPath(); + return; } Instances.AsstProxy.Connected = false; @@ -550,7 +560,6 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase var emulatorPath = $@"{EmulatorPath}\ldconsole.exe"; if (!File.Exists(emulatorPath)) { - MessageBoxHelper.Show("LD Emulator Path Not Found"); return 0; }