Ejemplo n.º 1
0
        public static Engine.Data.Setting GetNewSetting(DiDevice device, Engine.Data.Game game, MapTo mapTo)
        {
            // Create new setting for game/device.
            var newSetting = new Engine.Data.Setting();

            newSetting.InstanceGuid    = device.Instance.InstanceGuid;
            newSetting.InstanceName    = device.Instance.InstanceName;
            newSetting.ProductGuid     = device.Instance.ProductGuid;
            newSetting.ProductName     = device.Instance.ProductName;
            newSetting.DeviceType      = (int)device.Instance.Type;
            newSetting.FileName        = game.FileName;
            newSetting.FileProductName = game.FileProductName;
            newSetting.DateCreated     = DateTime.Now;
            newSetting.IsEnabled       = true;
            newSetting.MapTo           = (int)mapTo;
            return(newSetting);
        }
Ejemplo n.º 2
0
 void UpdateDevices()
 {
     lock (UpdateDevicesLock)
     {
         var devices = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToList();
         var deviceInstanceGuid = devices.Select(x => x.InstanceGuid).ToArray();
         var currentInstanceGuids = SettingManager.DiDevices.Select(x => x.InstanceGuid).ToArray();
         var removedDevices = SettingManager.DiDevices.Where(x => !deviceInstanceGuid.Contains(x.InstanceGuid)).ToArray();
         var addedDevices = devices.Where(x => !currentInstanceGuids.Contains(x.InstanceGuid)).ToArray();
         var updatedDevices = devices.Where(x => currentInstanceGuids.Contains(x.InstanceGuid)).ToArray();
         // Remove disconnected devices.
         for (int i = 0; i < removedDevices.Length; i++)
         {
             SettingManager.DiDevices.Remove(removedDevices[i]);
         }
         // Add connected devices.
         for (int i = 0; i < addedDevices.Length; i++)
         {
             var device = addedDevices[i];
             var di = new DiDevice();
             di.Instance = device;
             var state = new Joystick(Manager, device.InstanceGuid);
             di.Device = state;
             var classGuid = state.Properties.ClassGuid;
             // Must find better way to find Device than by Vendor ID and Product ID.
             var info = DeviceDetector.GetDevices(
                 classGuid,
                 JocysCom.ClassLibrary.Win32.DIGCF.DIGCF_ALLCLASSES,
                 null,
                 state.Properties.VendorId,
                 state.Properties.ProductId,
                 0
             );
             di.Info = info.FirstOrDefault();
             SettingManager.DiDevices.Add(di);
         }
         for (int i = 0; i < updatedDevices.Length; i++)
         {
             var device = updatedDevices[i];
             var currentDevice = SettingManager.DiDevices.First(x => x.InstanceGuid.Equals(device.InstanceGuid));
             var state = new Joystick(Manager, device.InstanceGuid);
             currentDevice.Device = state;
         }
     }
     var game = GetCurrentGame();
     if (game != null)
     {
         // Auto-configure new devices.
         AutoConfigure(game);
     }
 }