XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

HaloPixelToolBox

【WinUI3】基于USB HID通讯的花再音响工具箱

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/HaloPixelToolBox

Fix crash when parsing invalid hex address in CloudMusicLyricsToolPageViewModel

Co-authored-by: XFEstudio <132526994+XFEstudio@users.noreply.github.com>

c39082e
copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
提交于

代码差异

1 个文件 +21 -2
Modified HaloPixelToolBox/HaloPixelToolBox/ViewModels/CloudMusicLyricsToolPageViewModel.cs +21 -2
@@ -34,6 +34,25 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
34 34
35 35 public ISettingService SettingService { get; } = ServiceManager.GetService<ISettingService>();
36 36
37 /// <summary>
38 /// Safely parse a hexadecimal address string to nint, returning 0 if parsing fails
39 /// </summary>
40 private static nint ParseHexAddress(string hexAddress)
41 {
42 if (string.IsNullOrWhiteSpace(hexAddress))
43 return 0;
44
45 try
46 {
47 return new nint(Convert.ToInt64(hexAddress, 16));
48 }
49 catch (Exception ex) when (ex is FormatException or OverflowException or ArgumentException)
50 {
51 Console.WriteLine($"[WARNING]无法解析内存地址 '{hexAddress}',使用默认值 0。错误:{ex.Message}");
52 return 0;
53 }
54 }
55
37 56 partial void OnEnableCloudMusicLyricsChanged(bool value) => CloudMusicLyricsProfile.EnableCloudMusicLyrics = value;
38 57
39 58 partial void OnUseInputedAddressChanged(bool value)
@@ -45,7 +64,7 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
45 64 partial void OnInputedAddressChanged(string value)
46 65 {
47 66 CloudMusicLyricsProfile.InputedAddress = value;
48 Reader.Address = value.IsNullOrWhiteSpace() ? 0 : new nint(Convert.ToInt64(value, 16));
67 Reader.Address = ParseHexAddress(value);
49 68 }
50 69
51 70 partial void OnSwitchBackWhenPauseChanged(bool value) => CloudMusicLyricsProfile.SwitchBackWhenPause = value;
@@ -58,7 +77,7 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
58 77 Reader = new CloudMusicLyricsReader
59 78 {
60 79 UseInputedAddress = UseInputedAddress,
61 Address = InputedAddress.IsNullOrWhiteSpace() ? 0 : new nint(Convert.ToInt64(InputedAddress, 16))
80 Address = ParseHexAddress(InputedAddress)
62 81 };
63 82 Console.WriteLine("准备启动网易云后台线程");
64 83 Task.Run(async () =>