Esempio n. 1
0
        /// <summary>
        /// Access this only inside Timer_Click!
        /// </summary>
        bool RefreshCurrentInstances(bool forceReload = false)
        {
            // If you encounter "LoaderLock was detected" Exception when debugging then:
            // Make sure that you have reference to Microsoft.Directx.dll.
            bool instancesChanged = false;

            DeviceInstance[] devices = null;
            //var types = DeviceType.Driving | DeviceType.Flight | DeviceType.Gamepad | DeviceType.Joystick | DeviceType.FirstPerson;
            if (forceRecountDevices || forceReload)
            {
                devices = GetDevices();
                // Sore device instances and their order here.
                deviceInstancesNew  = string.Join(",", devices.Select(x => x == null ? "" : x.InstanceGuid.ToString()));
                forceRecountDevices = false;
            }
            //Populate All devices
            if (deviceInstancesNew != deviceInstancesOld)
            {
                deviceInstancesOld = deviceInstancesNew;
                if (devices == null)
                {
                    devices = GetDevices();
                }
                var instances = devices;
                // Dispose from previous list of devices.
                for (int i = 0; i < 4; i++)
                {
                    if (diDevices[i] != null)
                    {
                        // Dispose current device.
                        diDevices[i].Unacquire();
                        diDevices[i].Dispose();
                    }
                }
                // Create new list of devices.
                for (int i = 0; i < 4; i++)
                {
                    diDevices[i] = instances[i] == null
                                                ? null
                                                : new Joystick(Manager, instances[i].InstanceGuid);
                }
                SettingsDatabasePanel.BindDevices(instances);
                SettingsDatabasePanel.BindFiles();
                for (int i = 0; i < 4; i++)
                {
                    // Backup old instance.
                    diInstancesOld[i] = diInstances[i];
                    // Assign new instance.
                    diInstances[i] = instances[i];
                }
                instancesChanged = true;
            }
            // Return true if instances changed.
            return(instancesChanged);
        }
Esempio n. 2
0
        /// <summary>
        /// Access this only insite Timer_Click!
        /// </summary>
        bool RefreshCurrentInstances()
        {
            // If you encounter "LoaderLock was detected" Exception when debugging then:
            // Make sure that you have reference to Microsoft.Directx.dll.
            bool instancesChanged          = false;
            IList <DeviceInstance> devices = null;

            //var types = DeviceType.Driving | DeviceType.Flight | DeviceType.Gamepad | DeviceType.Joystick | DeviceType.FirstPerson;
            if (forceRecountDevices)
            {
                devices             = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices);
                deviceCount         = devices.Count;
                forceRecountDevices = false;
            }
            //Populate All devices
            if (deviceCount != _diCount)
            {
                _diCount = deviceCount;
                if (devices == null)
                {
                    devices = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices);
                }
                var instances = devices;
                // Dispose from previous list of devices.
                for (int i = 0; i < diDevices.Count; i++)
                {
                    // Dispose current device.
                    diDevices[i].Unacquire();
                    diDevices[i].Dispose();
                }
                diDevices.Clear();
                // Create new list of devices.
                for (int i = 0; i < instances.Count; i++)
                {
                    var ig     = instances[i].InstanceGuid;
                    var device = new Joystick(Manager, ig);
                    //device.SetCooperativeLevel(this, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
                    //device.Acquire();
                    diDevices.Add(device);
                }
                SettingsDatabasePanel.BindDevices(instances);
                SettingsDatabasePanel.BindFiles();
                // Assign new list of instances.
                diInstancesOld.Clear();
                diInstancesOld.AddRange(diInstances.ToArray());
                diInstances.Clear();
                diInstances.AddRange(instances.ToArray());
                instancesChanged = true;
            }
            // Return true if instances changed.
            return(instancesChanged);
        }