private DirectInputDevice([NotNull] SlimDX.DirectInput.DirectInput directInput, [NotNull] DeviceInstance device, int index) {
Device = device;
DisplayName = device.InstanceName;
Id = GuidToString(device.ProductGuid);
Index = index;
OriginalIniIds = new List<int>();
_joystick = new Joystick(directInput, Device.InstanceGuid);
if (Application.Current.MainWindow != null) {
try {
_joystick.SetCooperativeLevel(new WindowInteropHelper(Application.Current.MainWindow).Handle,
CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
} catch (Exception e) {
Logging.Warning("Can’t set cooperative level: " + e);
}
}
var capabilities = _joystick.Capabilities;
_buttonsCount = capabilities.ButtonCount;
Buttons = Enumerable.Range(0, _buttonsCount).Select(x => new DirectInputButton(this, x)).ToArray();
Axles = Enumerable.Range(0, 8).Select(x => new DirectInputAxle(this, x)).ToArray();
}