using System.Collections.Concurrent;
using System.Text.Json;
using LogiBoardToolBox.Core.Onboard;
using LogiBoardToolBox.Core.Windows;
/// Passive, device-scoped observation. No mode, map, spy or flash writes.
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
internal static class WatchReceiverOutput
{
public static async Task RunAsync(LogitechDevice device, string folder)
{
if (device.Identity != "046D:C547:C972BA47:01") throw new InvalidOperationException("只观察已核对的目标鼠标。");
if (WindowsHidTransport.EnumerateLogitechDevices().Where(d => d.ProductId == device.Hid.ProductId).Select(d => d.CollectionGroup).Distinct().Count() != 1)
throw new InvalidOperationException("存在多个同型号接收器,停止以免采集其他设备。");
Directory.CreateDirectory(folder);
if (File.Exists(Path.Combine(folder, "armed.json"))) throw new IOException("观察目录已经使用。");
using var client = LogitechDiscovery.Open(device);
var memory = new OnboardMemory(client, device.Identity, device.Name);
var before = await memory.ReadAsync();
await OnboardMemory.SaveBackupAsync(before, Path.Combine(folder, "before.json"));
var spy = await client.GetFeatureAsync(0x8110); var onboard = await client.GetFeatureAsync(0x8100);
var notifications = new ConcurrentQueue