void GetDevices(out DeviceInfo[] offline, out DeviceInfo[] problem, out DeviceInfo[] unknown) { var devices = DeviceDetector.GetDevices(); offline = devices.Where(x => !x.IsPresent && x.IsRemovable && !x.Description.Contains("RAS Async Adapter")).ToArray(); problem = devices.Where(x => x.Status.HasFlag(DeviceNodeStatus.DN_HAS_PROBLEM)).Except(offline).ToArray(); unknown = devices.Where(x => x.Description.Contains("Unknown")).Except(offline).Except(problem).ToArray(); }
void UpdateDiDevices(DirectInput manager) { if (!UpdateDevicesPending) { return; } UpdateDevicesPending = false; // Make sure that interface handle is created, before starting device updates. UserDevice[] deleteDevices; // Add connected devices. var insertDevices = new List <UserDevice>(); // List of connected devices (can be a very long operation). var devices = new List <DeviceInstance>(); // Controllers. var controllerInstances = manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in controllerInstances) { devices.Add(item); } // Pointers. var pointerInstances = manager.GetDevices(DeviceClass.Pointer, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in pointerInstances) { devices.Add(item); } // Keyboards. var keyboardInstances = manager.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in keyboardInstances) { devices.Add(item); } if (Program.IsClosing) { return; } // List of connected devices. var deviceInstanceGuid = devices.Select(x => x.InstanceGuid).ToList(); // List of current devices. var uds = SettingsManager.UserDevices.ItemsToArraySyncronized(); var currentInstanceGuids = uds.Select(x => x.InstanceGuid).ToArray(); deleteDevices = uds.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(); // Must find better way to find Device than by Vendor ID and Product ID. DeviceInfo[] devInfos = null; DeviceInfo[] intInfos = null; if (addedDevices.Length > 0 || updatedDevices.Length > 0) { devInfos = DeviceDetector.GetDevices(); //var classes = devInfos.Select(x=>x.ClassDescription).Distinct().ToArray(); intInfos = DeviceDetector.GetInterfaces(); //var intclasses = intInfos.Select(x => x.ClassDescription).Distinct().ToArray(); } //Joystick = new Guid("6f1d2b70-d5a0-11cf-bfc7-444553540000"); //SysMouse = new Guid("6f1d2b60-d5a0-11cf-bfc7-444553540000"); //SysKeyboard = new Guid("6f1d2b61-d5a0-11cf-bfc7-444553540000"); for (int i = 0; i < addedDevices.Length; i++) { var device = addedDevices[i]; var ud = new UserDevice(); DeviceInfo hid; RefreshDevice(manager, ud, device, devInfos, intInfos, out hid); var isVirtual = false; if (hid != null) { DeviceInfo p = hid; do { p = devInfos.FirstOrDefault(x => x.DeviceId == p.ParentDeviceId); // If ViGEm hardware found then... if (p != null && VirtualDriverInstaller.ViGEmBusHardwareIds.Any(x => string.Compare(p.HardwareIds, x, true) == 0)) { isVirtual = true; break; } } while (p != null); } if (!isVirtual) { insertDevices.Add(ud); } } //if (insertDevices.Count > 0) //{ // CloudPanel.Add(CloudAction.Insert, insertDevices.ToArray(), true); //} for (int i = 0; i < updatedDevices.Length; i++) { var device = updatedDevices[i]; var ud = uds.First(x => x.InstanceGuid.Equals(device.InstanceGuid)); DeviceInfo hid; // Will refresh device and fill more values with new x360ce app if available. RefreshDevice(manager, ud, device, devInfos, intInfos, out hid); } if (Program.IsClosing) { return; } // Remove disconnected devices. for (int i = 0; i < deleteDevices.Length; i++) { lock (SettingsManager.UserDevices.SyncRoot) deleteDevices[i].IsOnline = false; } for (int i = 0; i < insertDevices.Count; i++) { var ud = insertDevices[i]; lock (SettingsManager.UserDevices.SyncRoot) SettingsManager.UserDevices.Items.Add(ud); } // Enable Test instances. TestDeviceHelper.EnableTestInstances(); RefreshDevicesCount++; var ev = DevicesUpdated; if (ev != null) { ev(this, new DInputEventArgs()); } // var game = CurrentGame; // if (game != null) // { // // Auto-configure new devices. // AutoConfigure(game); // } }
void UpdateDiDevices() { if (!UpdateDevicesEnabled) { return; } UpdateDevicesEnabled = false; // Make sure that interface handle is created, before starting device updates. UserDevice[] deleteDevices; // Add connected devices. var insertDevices = new List <UserDevice>(); var updateDevices = new List <KeyValuePair <UserDevice, DeviceInstance> >(); // List of connected devices (can be a very long operation). var devices = new List <DeviceInstance>(); // Controllers. var controllerInstances = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in controllerInstances) { devices.Add(item); } // Pointers. var pointerInstances = Manager.GetDevices(DeviceClass.Pointer, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in pointerInstances) { devices.Add(item); } // Keyboards. var keyboardInstances = Manager.GetDevices(DeviceClass.Keyboard, DeviceEnumerationFlags.AllDevices).ToList(); foreach (var item in keyboardInstances) { devices.Add(item); } if (Program.IsClosing) { return; } // List of connected devices. var deviceInstanceGuid = devices.Select(x => x.InstanceGuid).ToList(); // List of current devices. var currentInstanceGuids = SettingsManager.UserDevices.Items.Select(x => x.InstanceGuid).ToArray(); deleteDevices = SettingsManager.UserDevices.Items.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(); // Must find better way to find Device than by Vendor ID and Product ID. if (addedDevices.Length > 0) { //Joystick = new Guid("6f1d2b70-d5a0-11cf-bfc7-444553540000"); //SysMouse = new Guid("6f1d2b60-d5a0-11cf-bfc7-444553540000"); //SysKeyboard = new Guid("6f1d2b61-d5a0-11cf-bfc7-444553540000"); DeviceInfo[] devInfos = DeviceDetector.GetDevices(); DeviceInfo[] intInfos = null; // Controllers. var controllers = addedDevices .Where(x => x.Type != SharpDX.DirectInput.DeviceType.Mouse && x.Type != SharpDX.DirectInput.DeviceType.Keyboard) .Select(x => new Joystick(Manager, x.InstanceGuid)).ToArray(); // Get interfaces. var interfacePaths = controllers.Select(x => x.Properties.InterfacePath).ToArray(); intInfos = DeviceDetector.GetInterfaces(interfacePaths); for (int i = 0; i < addedDevices.Length; i++) { var device = addedDevices[i]; var ud = new UserDevice(); RefreshDevice(ud, device); DeviceInfo hid = null; DeviceInfo dev = null; if (device.IsHumanInterfaceDevice) { // Get interface info for added devices. hid = intInfos.FirstOrDefault(x => x.DevicePath == ud.Device.Properties.InterfacePath); // Get device info for added devices. dev = devInfos.FirstOrDefault(x => x.DeviceId == ud.HidDeviceId); } ud.LoadHidDeviceInfo(hid); ud.LoadDevDeviceInfo(dev); var isVirtual = false; if (hid != null) { DeviceInfo p = hid; do { p = DeviceDetector.GetParentDevice(Guid.Empty, JocysCom.ClassLibrary.Win32.DIGCF.DIGCF_ALLCLASSES, p.DeviceId); if (p != null && string.Compare(p.HardwareId, VirtualDriverInstaller.ViGEmBusHardwareId, true) == 0) { isVirtual = true; break; } } while (p != null); } if (!isVirtual) { insertDevices.Add(ud); } } } //if (insertDevices.Count > 0) //{ // CloudPanel.Add(CloudAction.Insert, insertDevices.ToArray(), true); //} for (int i = 0; i < updatedDevices.Length; i++) { var device = updatedDevices[i]; var di = SettingsManager.UserDevices.Items.First(x => x.InstanceGuid.Equals(device.InstanceGuid)); updateDevices.Add(new KeyValuePair <UserDevice, DeviceInstance>(di, device)); } if (Program.IsClosing) { return; } // Remove disconnected devices. for (int i = 0; i < deleteDevices.Length; i++) { deleteDevices[i].IsOnline = false; } for (int i = 0; i < insertDevices.Count; i++) { var ud = insertDevices[i]; SettingsManager.UserDevices.Items.Add(ud); } for (int i = 0; i < updateDevices.Count; i++) { var kv = updateDevices[i]; RefreshDevice(kv.Key, kv.Value); } // Enable Test instances. TestDeviceHelper.EnableTestInstances(); RefreshDevicesCount++; var ev = DevicesUpdated; if (ev != null) { ev(this, new DInputEventArgs()); } // var game = CurrentGame; // if (game != null) // { // // Auto-configure new devices. // AutoConfigure(game); // } }