in ScpDriverInstaller/MainWindow.xaml.cs [102:205]
private void OnUsbDeviceAddedOrRemoved()
{
var usbDevices = WdiWrapper.Instance.UsbDeviceList.ToList();
var supportedBluetoothDevices = IniConfig.Instance.BthDongleDriver.HardwareIds;
var regex = new Regex("VID_([0-9A-Z]{4})&PID_([0-9A-Z]{4})", RegexOptions.IgnoreCase);
// HidUsb devices
{
DualShockStackPanelHidUsb.Children.Clear();
_viewModel.InstallDs3ButtonEnabled = false;
foreach (
var usbDevice in
usbDevices.Where(
d => d.VendorId == _hidUsbDs3.VendorId
&& (d.ProductId == _hidUsbDs3.ProductId || d.ProductId == _hidUsbDs4.ProductId)
&& !string.IsNullOrEmpty(d.CurrentDriver)
&& d.CurrentDriver.Equals("HidUsb"))
)
{
DualShockStackPanelHidUsb.Children.Add(new TextBlock
{
Text = string.Format("Device #{0}: {1}", DualShockStackPanelHidUsb.Children.Count, usbDevice),
Tag = usbDevice,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 10)
});
_viewModel.InstallDs3ButtonEnabled = true;
}
}
// WinUsb devices
{
DualShockStackPanelWinUsb.Children.Clear();
foreach (
var usbDevice in
usbDevices.Where(
d => d.VendorId == _hidUsbDs3.VendorId
&& (d.ProductId == _hidUsbDs3.ProductId || d.ProductId == _hidUsbDs4.ProductId)
&& !string.IsNullOrEmpty(d.CurrentDriver)
&& d.CurrentDriver.Equals("WinUSB"))
)
{
DualShockStackPanelWinUsb.Children.Add(new TextBlock
{
Text = string.Format("Device #{0}: {1}", DualShockStackPanelWinUsb.Children.Count, usbDevice),
Tag = usbDevice,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 10)
});
}
}
// refresh devices filtering on supported Bluetooth hardware IDs and BTHUSB driver (uninitialized)
{
var uninitialized =
usbDevices.Where(
d =>
!string.IsNullOrEmpty(d.CurrentDriver) &&
d.CurrentDriver.Equals("BTHUSB") &&
supportedBluetoothDevices.Any(s => s.Contains(regex.Match(d.HardwareId).Value)));
BluetoothStackPanelDefault.Children.Clear();
_viewModel.InstallBthButtonEnabled = false;
foreach (var usbDevice in uninitialized)
{
BluetoothStackPanelDefault.Children.Add(new TextBlock
{
Text = string.Format("Device #{0}: {1}", BluetoothStackPanelDefault.Children.Count, usbDevice),
Tag = usbDevice,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 10)
});
_viewModel.InstallBthButtonEnabled = true;
}
}
// refresh devices filtering on supported Bluetooth hardware IDs and WinUSB driver (initialized)
{
var initialized =
usbDevices.Where(
d =>
!string.IsNullOrEmpty(d.CurrentDriver) &&
d.CurrentDriver.Equals("WinUSB") &&
supportedBluetoothDevices.Any(s => s.Contains(regex.Match(d.HardwareId).Value)));
BluetoothStackPanelWinUsb.Children.Clear();
foreach (var usbDevice in initialized)
{
BluetoothStackPanelWinUsb.Children.Add(new TextBlock
{
Text = string.Format("Device #{0}: {1}", BluetoothStackPanelWinUsb.Children.Count, usbDevice),
Tag = usbDevice,
VerticalAlignment = VerticalAlignment.Center,
Margin = new Thickness(10, 0, 0, 10)
});
}
}
}