private IInputDevice CreateDevice(DeviceInstance deviceInstance)
 {
     try
     {
         if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid))
         {
             return(null);
         }
         var joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
         if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1)
         {
             joystick.Dispose();
             return(null);
         }
         joystick.Properties.BufferSize = 128;
         var device = new DirectInputDevice(joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName,
                                            deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, deviceInstance.IsHumanInterfaceDevice);
         return(device);
     }
     catch (Exception ex)
     {
         logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString());
         return(null);
     }
 }
Example #2
0
 private IInputDevice CreateDevice(DeviceInstance deviceInstance, List <string> uniqueIds)
 {
     try
     {
         if (!directInput.IsDeviceAttached(deviceInstance.InstanceGuid))
         {
             return(null);
         }
         var joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
         if (joystick.Capabilities.AxeCount < 1 && joystick.Capabilities.ButtonCount < 1)
         {
             joystick.Dispose();
             return(null);
         }
         bool   isHid         = deviceInstance.IsHumanInterfaceDevice;
         string interfacePath = null;
         string uniqueIdBase;
         string hardwareId = null;
         if (isHid)
         {
             if (ignoredDeviceService.IsIgnored(joystick.Properties.InterfacePath))
             {
                 joystick.Dispose();
                 return(null);
             }
             interfacePath = joystick.Properties.InterfacePath;
             uniqueIdBase  = interfacePath;
             hardwareId    = IdHelper.GetHardwareId(interfacePath);
         }
         else
         {
             uniqueIdBase = string.Join(":", deviceInstance.ProductGuid.ToString(), deviceInstance.InstanceGuid.ToString());
         }
         string uniqueId = IdHelper.GetUniqueId(uniqueIdBase);
         if (uniqueIds.Any(uid => uid == uniqueId))
         {
             notificationService.Add(Notifications.DirectInputInstanceIdDuplication, new[] { uniqueId }, NotificationTypes.Warning);
         }
         uniqueIds.Add(uniqueId);
         if (currentDevices.Any(d => d.UniqueId == uniqueId))
         {
             joystick.Dispose();
             return(null);
         }
         joystick.Properties.BufferSize = 128;
         return(new DirectInputDevice(inputConfigManager, joystick, deviceInstance.InstanceGuid.ToString(), deviceInstance.ProductName,
                                      deviceInstance.ForceFeedbackDriverGuid != Guid.Empty, uniqueId, hardwareId, interfacePath));
     }
     catch (Exception ex)
     {
         logger.Error("Failed to create device " + deviceInstance.InstanceGuid + " " + deviceInstance.InstanceName + ex.ToString());
         return(null);
     }
 }