|
1 | | -using System; |
2 | | -using Buttplug.Core; |
3 | | -using MadWizard.WinUSBNet; |
4 | | -using Microsoft.Win32; |
5 | | - |
6 | | -namespace Buttplug.Server.Managers.WinUSBManager |
7 | | -{ |
8 | | - public class WinUSBManager : DeviceSubtypeManager |
9 | | - { |
10 | | - public WinUSBManager(IButtplugLogManager aLogManager) |
11 | | - : base(aLogManager) |
12 | | - { |
13 | | - BpLogger.Info("Loading WinUSB Manager"); |
14 | | - } |
15 | | - |
16 | | - public override void StartScanning() |
17 | | - { |
18 | | - BpLogger.Info("WinUSBManager start scanning"); |
19 | | - var deviceKey = |
20 | | - Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB\VID_0B49&PID_064F"); |
21 | | - if (deviceKey == null) |
22 | | - { |
23 | | - BpLogger.Debug("No TranceVibrator Devices found in registry."); |
24 | | - InvokeScanningFinished(); |
25 | | - return; |
26 | | - } |
27 | | - |
28 | | - var deviceKeyNames = deviceKey.GetSubKeyNames(); |
29 | | - if (deviceKeyNames.Length == 0) |
30 | | - { |
31 | | - BpLogger.Debug("No TranceVibrator Devices with drivers found in registry."); |
32 | | - InvokeScanningFinished(); |
33 | | - return; |
34 | | - } |
35 | | - |
36 | | - var deviceSubKey = deviceKey.OpenSubKey(deviceKeyNames[0]); |
37 | | - if (deviceSubKey == null) |
38 | | - { |
39 | | - BpLogger.Debug("No TranceVibrator Devices with drivers subkeys found in registry."); |
40 | | - InvokeScanningFinished(); |
41 | | - return; |
42 | | - } |
43 | | - |
44 | | - var deviceParameters = deviceSubKey.OpenSubKey("Device Parameters"); |
45 | | - if (deviceParameters == null) |
46 | | - { |
47 | | - BpLogger.Debug("No TranceVibrator Devices with drivers parameters found in registry."); |
48 | | - InvokeScanningFinished(); |
49 | | - return; |
50 | | - } |
51 | | - |
52 | | - var deviceGUID = (string[])deviceParameters.GetValue("DeviceInterfaceGUIDs", string.Empty); |
53 | | - if (deviceGUID == null || deviceGUID.ToString().Length == 0) |
54 | | - { |
55 | | - BpLogger.Debug("No TranceVibrator Devices Driver GUIDs found in registry."); |
56 | | - InvokeScanningFinished(); |
57 | | - return; |
58 | | - } |
59 | | - |
60 | | - // Only valid for our Trancevibrator install |
61 | | - var devices = USBDevice.GetDevices(deviceGUID[0]); |
62 | | - if (devices == null || devices.Length == 0) |
63 | | - { |
64 | | - BpLogger.Error("No USB Device found!"); |
65 | | - InvokeScanningFinished(); |
66 | | - return; |
67 | | - } |
68 | | - |
69 | | - uint index = 0; |
70 | | - foreach (var deviceinfo in devices) |
71 | | - { |
72 | | - var device = new USBDevice(deviceinfo); |
73 | | - BpLogger.Debug($"Found TranceVibrator Device"); |
74 | | - var tvDevice = new RezTranceVibratorDevice(LogManager, device, index); |
75 | | - index += 1; |
76 | | - InvokeDeviceAdded(new DeviceAddedEventArgs(tvDevice)); |
77 | | - } |
78 | | - |
79 | | - InvokeScanningFinished(); |
80 | | - } |
81 | | - |
82 | | - public override void StopScanning() |
83 | | - { |
84 | | - // noop |
85 | | - } |
86 | | - |
87 | | - public override bool IsScanning() |
88 | | - { |
89 | | - // noop |
90 | | - return false; |
91 | | - } |
92 | | - } |
93 | | -} |
| 1 | +using System; |
| 2 | +using Buttplug.Core; |
| 3 | +using MadWizard.WinUSBNet; |
| 4 | +using Microsoft.Win32; |
| 5 | + |
| 6 | +namespace Buttplug.Server.Managers.WinUSBManager |
| 7 | +{ |
| 8 | + public class WinUSBManager : DeviceSubtypeManager |
| 9 | + { |
| 10 | + public WinUSBManager(IButtplugLogManager aLogManager) |
| 11 | + : base(aLogManager) |
| 12 | + { |
| 13 | + BpLogger.Info("Loading WinUSB Manager"); |
| 14 | + } |
| 15 | + |
| 16 | + public override void StartScanning() |
| 17 | + { |
| 18 | + BpLogger.Info("WinUSBManager start scanning"); |
| 19 | + var deviceKey = |
| 20 | + Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB\VID_0B49&PID_064F"); |
| 21 | + if (deviceKey == null) |
| 22 | + { |
| 23 | + BpLogger.Debug("No TranceVibrator Devices found in registry."); |
| 24 | + InvokeScanningFinished(); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + var deviceKeyNames = deviceKey.GetSubKeyNames(); |
| 29 | + if (deviceKeyNames.Length == 0) |
| 30 | + { |
| 31 | + BpLogger.Debug("No TranceVibrator Devices with drivers found in registry."); |
| 32 | + InvokeScanningFinished(); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + var deviceSubKey = deviceKey.OpenSubKey(deviceKeyNames[0]); |
| 37 | + if (deviceSubKey == null) |
| 38 | + { |
| 39 | + BpLogger.Debug("No TranceVibrator Devices with drivers subkeys found in registry."); |
| 40 | + InvokeScanningFinished(); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + var deviceParameters = deviceSubKey.OpenSubKey("Device Parameters"); |
| 45 | + if (deviceParameters == null) |
| 46 | + { |
| 47 | + BpLogger.Debug("No TranceVibrator Devices with drivers parameters found in registry."); |
| 48 | + InvokeScanningFinished(); |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + var deviceRegistryObject = deviceParameters.GetValue("DeviceInterfaceGUIDs", string.Empty); |
| 53 | + string deviceGuid = ""; |
| 54 | + if (deviceRegistryObject == null) |
| 55 | + { |
| 56 | + BpLogger.Debug("No TranceVibrator Devices Driver GUIDs found in registry."); |
| 57 | + InvokeScanningFinished(); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + try |
| 62 | + { |
| 63 | + var guidStrings = (string[])deviceRegistryObject; |
| 64 | + deviceGuid = guidStrings[0]; |
| 65 | + } |
| 66 | + catch (Exception) |
| 67 | + { |
| 68 | + try |
| 69 | + { |
| 70 | + // Some versions of Zadig, the registry key writes as a string, not a string array? |
| 71 | + deviceGuid = (string)deviceRegistryObject; |
| 72 | + } |
| 73 | + catch (Exception) |
| 74 | + { |
| 75 | + BpLogger.Error("Cannot cast device GUID from registry value, cannot connect to Trancevibe."); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + if (deviceGuid.Length == 0) |
| 80 | + { |
| 81 | + BpLogger.Error("Cannot find device GUID from registry value, cannot connect to Trancevibe."); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + // Only valid for our Trancevibrator install |
| 86 | + var devices = USBDevice.GetDevices(deviceGuid); |
| 87 | + if (devices == null || devices.Length == 0) |
| 88 | + { |
| 89 | + BpLogger.Error("No USB Device found!"); |
| 90 | + InvokeScanningFinished(); |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + uint index = 0; |
| 95 | + foreach (var deviceinfo in devices) |
| 96 | + { |
| 97 | + var device = new USBDevice(deviceinfo); |
| 98 | + BpLogger.Debug($"Found TranceVibrator Device"); |
| 99 | + var tvDevice = new RezTranceVibratorDevice(LogManager, device, index); |
| 100 | + index += 1; |
| 101 | + InvokeDeviceAdded(new DeviceAddedEventArgs(tvDevice)); |
| 102 | + } |
| 103 | + |
| 104 | + InvokeScanningFinished(); |
| 105 | + } |
| 106 | + |
| 107 | + public override void StopScanning() |
| 108 | + { |
| 109 | + // noop |
| 110 | + } |
| 111 | + |
| 112 | + public override bool IsScanning() |
| 113 | + { |
| 114 | + // noop |
| 115 | + return false; |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments