Esempio n. 1
0
        private void ScanJoysticks()
        {
            List <ControllerDevice> removedDevices = new List <ControllerDevice>();
            List <ControllerDevice> addedDevices   = new List <ControllerDevice>(); //_directInput.GetDevices().ToList().ConvertAll(device => new ControllerDevice(_directInput, device));

            List <DeviceInstance> oldDeviceInstances   = _devices.ToList().ConvertAll(d => d.DeviceInstance);
            List <DeviceInstance> foundDeviceInstances = _directInput.GetDevices().ToList();

            //List<DeviceInstance> removedDeviceInstances = oldDeviceInstances.Except(foundDeviceInstances).Where(d => !IsSupported(d)).ToList();

            foreach (DeviceInstance deviceInstance in foundDeviceInstances)
            {
                if (_devices.Where(d => d.DeviceInstance.InstanceGuid == deviceInstance.InstanceGuid).Count() == 0)
                {
                    if (ShowAllDevicesCheckBox.Checked == true || SupportedDevices.ContainsKey(ControllerDevice.ProductGuidToUSBID(deviceInstance.ProductGuid)))
                    {
                        addedDevices.Add(new ControllerDevice(_directInput, deviceInstance));
                    }
                }
            }

            foreach (ControllerDevice device in _devices)
            {
                bool match = false;
                if (SupportedDevices.ContainsKey(device.UsbId) || ShowAllDevicesCheckBox.Checked)
                {
                    match = foundDeviceInstances.ConvertAll(d => d.InstanceGuid.ToString()).Contains(device.Guid);
                }
                if (!match)
                {
                    // Remove device
                    removedDevices.Add(device);
                }
            }

            foreach (ControllerDevice device in removedDevices)
            {
                RemoveDevice(device);
            }

            foreach (ControllerDevice device in addedDevices)
            {
                AddDevice(device);
            }
        }
Esempio n. 2
0
 private bool IsSupported(DeviceInstance deviceInstance)
 {
     return(IsSupported(ControllerDevice.ProductGuidToUSBID(deviceInstance.ProductGuid)));
 }