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

HaloPixelToolBox

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

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

XFEstudio/HaloPixelToolBox

修复部分网易云地址解析问题 添加日志功能

6ebcd40
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

9 个文件 +94 -25
Modified HaloPixelToolBox/HaloPixelToolBox.Core/HaloPixelToolBox.Core.csproj +1 -0
@@ -11,6 +11,7 @@
11 11 <PackageReference Include="HidSharp" Version="2.6.4" />
12 12 <PackageReference Include="XFEExtension.NetCore" Version="3.3.*" />
13 13 <PackageReference Include="XFEExtension.NetCore.MemoryEditor" Version="2.1.0" />
14 <PackageReference Include="XFEExtension.NetCore.XFEConsole" Version="1.1.2" />
14 15 </ItemGroup>
15 16
16 17 </Project>
Modified HaloPixelToolBox/HaloPixelToolBox.Core/Models/MyModel.cs +4 -5
@@ -1,7 +1,6 @@
1 namespace HaloPixelToolBox.Core.Models
1 namespace HaloPixelToolBox.Core.Models;
2
3 public class MyModel
2 4 {
3 public class MyModel
4 {
5 public int MyProperty { get; set; }
6 }
5 public int MyProperty { get; set; }
7 6 }
Modified HaloPixelToolBox/HaloPixelToolBox.Core/Utilities/CloudLyricsReader.cs +26 -2
@@ -14,9 +14,9 @@ public class CloudMusicLyricsReader
14 14 {
15 15 if (GetCloudMusicLyricsProcess() is Process process)
16 16 {
17 Console.WriteLine($"[DEBUG]已找到进程:{process.ProcessName}({process.Id}|{process.Id:X}) - {process.MainWindowTitle}");
17 18 Editor.CurrentProcess = process;
18 Address = Editor.ResolvePointerAddress("cloudmusic.dll", 0x01CE4A50, 0xE0, 0x8, 0x120, 0x8, 0x0);
19 return true;
19 return ReresolveAddress();
20 20 }
21 21 else
22 22 {
@@ -35,6 +35,30 @@ public class CloudMusicLyricsReader
35 35 else return false;
36 36 }
37 37
38 public bool ReresolveAddress()
39 {
40 try
41 {
42 var address = Editor.ResolvePointerAddress("cloudmusic.dll", 0x01CEBD70, 0xE0, 0x8, 0x120, 0x8, 0x0);
43 Console.WriteLine($"[DEBUG]读取到的地址:{address}");
44 if (address != 0)
45 {
46 Address = address;
47 return true;
48 }
49 else
50 {
51 return false;
52 }
53 }
54 catch (Exception ex)
55 {
56 Console.WriteLine($"[ERROR]{ex.Message}");
57 Console.WriteLine($"[TRACE]{ex.StackTrace}");
58 return false;
59 }
60 }
61
38 62 public static int GetValidLength(byte[] buffer)
39 63 {
40 64 int length = 0;
Modified HaloPixelToolBox/HaloPixelToolBox/App.xaml.cs +25 -0
@@ -1,4 +1,6 @@
1 1 using HaloPixelToolBox.Profiles.CrossVersionProfiles;
2 using HaloPixelToolBox.Utilities;
3 using XFEExtension.NetCore.FileExtension;
2 4 using XFEExtension.NetCore.WinUIHelper.Interface.Services;
3 5 using XFEExtension.NetCore.WinUIHelper.Utilities;
4 6 using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
@@ -22,7 +24,10 @@ namespace HaloPixelToolBox
22 24 /// </summary>
23 25 public App()
24 26 {
27 XFEConsole.UseXFEConsoleLog();
28 Console.WriteLine("正在初始化应用程序...");
25 29 this.InitializeComponent();
30 Console.WriteLine("应用程序初始化完成");
26 31 AppThemeHelper.Theme = SystemProfile.Theme;
27 32 PageManager.RegisterPage(typeof(AppShellPage));
28 33 PageManager.RegisterPage(typeof(CloudMusicLyricsToolPage));
@@ -36,6 +41,8 @@ namespace HaloPixelToolBox
36 41 if (ServiceManager.GetService<IMessageService>() is IMessageService messageService)
37 42 {
38 43 messageService.ShowMessage(e.Message, "发生错误", InfoBarSeverity.Error);
44 Console.WriteLine($"[ERROR]{e.Message}");
45 Console.WriteLine($"[TRACE]{e.Exception.StackTrace}");
39 46 e.Handled = true;
40 47 }
41 48 }
@@ -46,9 +53,27 @@ namespace HaloPixelToolBox
46 53 /// <param name="args">Details about the launch request and process.</param>
47 54 protected override void OnLaunched(LaunchActivatedEventArgs args)
48 55 {
56 MainWindow.Closed += MainWindow_Closed;
49 57 MainWindow.Content = new AppShellPage();
50 58 MainWindow.Activate();
51 59 AppThemeHelper.MainWindow = MainWindow;
52 60 }
61
62 private void MainWindow_Closed(object sender, WindowEventArgs args)
63 {
64 Console.WriteLine("正在退出...");
65 Console.WriteLine("正在保存日志...");
66 var logs = Directory.GetFiles(AppPath.LogDictionary);
67 if (logs.Length > 10)
68 {
69 foreach (var log in logs.OrderByDescending(x => x).Skip(10))
70 {
71 File.Delete(log);
72 }
73 }
74 XFEConsole.Log.Export().WriteIn($@"{AppPath.LogDictionary}\{DateTime.Now:yyyy-M-d_HH-mm-ss}.log");
75 Console.WriteLine("日志保存成功");
76 Current.Exit();
77 }
53 78 }
54 79 }
Modified HaloPixelToolBox/HaloPixelToolBox/HaloPixelToolBox.csproj +1 -1
@@ -9,7 +9,7 @@
9 9 <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
10 10 <PublishProfile>win-$(Platform).pubxml</PublishProfile>
11 11 <UseWinUI>true</UseWinUI>
12 <Version>1.0.0</Version>
12 <Version>1.0.1</Version>
13 13 <EnableMsixTooling>true</EnableMsixTooling>
14 14 <WindowsPackageType>None</WindowsPackageType>
15 15 <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
Modified HaloPixelToolBox/HaloPixelToolBox/Utilities/AppPath.cs +11 -4
@@ -1,6 +1,13 @@
1 namespace HaloPixelToolBox.Utilities
1 using XFEExtension.NetCore.AutoPath;
2 using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
3
4 namespace HaloPixelToolBox.Utilities;
5
6 public partial class AppPath
2 7 {
3 public partial class AppPath
4 {
5 }
8 /// <summary>
9 /// 应用程序日志路径
10 /// </summary>
11 [AutoPath]
12 private static readonly string logDictionary = $@"{AppPathHelper.AppLocalData}\Log";
6 13 }
Modified HaloPixelToolBox/HaloPixelToolBox/ViewModels/CloudMusicLyricsToolPageViewModel.cs +13 -11
@@ -24,25 +24,23 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
24 24 {
25 25 Task.Run(async () =>
26 26 {
27 Console.WriteLine("正在搜索花再设备...");
27 28 while (!DeviceReady)
28 29 {
29 AutoNavigationParameterService.CurrentPage?.DispatcherQueue.TryEnqueue(() =>
30 {
31 DeviceReady = Device.Initialize();
32 });
30 DeviceReady = Device.Initialize();
33 31 await Task.Delay(500);
34 32 }
33 Console.WriteLine("花再设备已连接");
35 34 }),
36 35 Task.Run(async () =>
37 36 {
37 Console.WriteLine("正在搜索云音乐...");
38 38 while (!CloudMusicReady)
39 39 {
40 AutoNavigationParameterService.CurrentPage?.DispatcherQueue.TryEnqueue(() =>
41 {
42 CloudMusicReady = Reader.Initialize();
43 });
40 CloudMusicReady = Reader.Initialize();
44 41 await Task.Delay(500);
45 42 }
43 Console.WriteLine("云音乐已准备就绪");
46 44 }),
47 45 Task.Run(async () =>
48 46 {
@@ -52,6 +50,7 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
52 50 {
53 51 if (DeviceReady && CloudMusicReady && EnableCloudMusicLyrics)
54 52 {
53 Console.WriteLine("[DEBUG]设备均在线,准备进入主循环");
55 54 string lastRead = string.Empty;
56 55 while (true)
57 56 {
@@ -63,22 +62,25 @@ public partial class CloudMusicLyricsToolPageViewModel : ServiceBaseViewModelBas
63 62 {
64 63 lastRead = lyrics;
65 64 Device.ShowText(lyrics);
65 Console.WriteLine($"已读取到歌词:{lyrics}");
66 66 }
67 Console.WriteLine(lyrics);
68 67 await Task.Delay(50);
69 68 }
70 69 catch(Exception ex)
71 70 {
72 Console.WriteLine(ex);
71 Console.WriteLine($"[ERROR]{ex.Message}");
72 Console.WriteLine($"[TRACE]{ex.StackTrace}");
73 73 }
74 74 }
75 Console.WriteLine($"[DEBUG]主循环已退出");
75 76 }
76 77 Console.WriteLine(DeviceReady && CloudMusicReady && EnableCloudMusicLyrics);
77 78 await Task.Delay(500);
78 79 }
79 80 catch (Exception ex)
80 81 {
81 Console.WriteLine(ex);
82 Console.WriteLine($"[ERROR]{ex.Message}");
83 Console.WriteLine($"[TRACE]{ex.StackTrace}");
82 84 }
83 85 }
84 86 })
Modified HaloPixelToolBox/HaloPixelToolBox/ViewModels/SettingPageViewModel.cs +7 -2
@@ -1,9 +1,10 @@
1 using System.Reflection;
2 using CommunityToolkit.Mvvm.ComponentModel;
1 using CommunityToolkit.Mvvm.ComponentModel;
3 2 using CommunityToolkit.Mvvm.Input;
4 3 using HaloPixelToolBox.Core.Utilities.Helpers;
5 4 using HaloPixelToolBox.Profiles.CrossVersionProfiles;
5 using HaloPixelToolBox.Utilities;
6 6 using Microsoft.Win32;
7 using System.Reflection;
7 8 using XFEExtension.NetCore.FileExtension;
8 9 using XFEExtension.NetCore.WinUIHelper.Interface.Services;
9 10 using XFEExtension.NetCore.WinUIHelper.Utilities;
@@ -24,6 +25,10 @@ namespace HaloPixelToolBox.ViewModels
24 25 [ObservableProperty]
25 26 string appDataSize = FileHelper.GetDirectorySize(new(AppPathHelper.AppLocalData)).FileSize();
26 27 [ObservableProperty]
28 string appLogDirectory = AppPath.LogDictionary;
29 [ObservableProperty]
30 string appLogSize = FileHelper.GetDirectorySize(new(AppPath.LogDictionary)).FileSize();
31 [ObservableProperty]
27 32 private string currentVersion = Assembly.GetEntryAssembly()?.GetName().Version is Version version ? version.ToString(3) : "无法获取版本信息";
28 33 public ISettingService SettingService { get; set; } = ServiceManager.GetService<ISettingService>();
29 34 public IDialogService DialogService { get; set; } = ServiceManager.GetService<IDialogService>();
Modified HaloPixelToolBox/HaloPixelToolBox/Views/SettingPage.xaml +6 -0
@@ -56,6 +56,12 @@
56 56 <Button Grid.Column="1" Content="清除缓存" Command="{x:Bind ViewModel.ClearCacheCommand}"/>
57 57 </Grid>
58 58 </controls:SettingsCard>
59 <controls:SettingsCard Header="程序日志" Description="{x:Bind ViewModel.AppLogDirectory, Mode=OneWay}" IsClickEnabled="True" Command="{x:Bind ViewModel.OpenPathCommand}" CommandParameter="{x:Bind ViewModel.AppLogDirectory, Mode=OneWay}">
60 <controls:SettingsCard.ActionIcon>
61 <FontIcon Glyph="&#xE8A7;"/>
62 </controls:SettingsCard.ActionIcon>
63 <TextBlock Style="{ThemeResource CaptionTextBlockStyle}" Text="{x:Bind ViewModel.AppLogSize, Mode=OneWay}" VerticalAlignment="Center"/>
64 </controls:SettingsCard>
59 65 <TextBlock Text="关于" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"/>
60 66 <controls:SettingsExpander Header="花再工具箱" Description="© 2025 XFEstudio 保留所有权利">
61 67 <controls:SettingsExpander.HeaderIcon>