コード例 #1
0
ファイル: Config.cs プロジェクト: jason-cech/AltInput
        /// <summary>
        /// Process each input section from the config file
        /// </summary>
        void ParseInputs()
        {
            String InterfaceName, ClassName;
            AltDirectInputDevice Device;

            print("AltInput: (re)loading configuration");
            ini = null;
            DeviceList.Clear();
            DetectedList.Clear();
            if (!File.Exists(ini_path))
                return;

            ini = new IniFile(ini_path);
            iniVersion = new System.Version(ini.IniReadValue("global", "Version"));
            if (iniVersion != currentVersion)
                return;

            List<String> sections = ini.IniReadAllSections();
            // Remove the [global] and [___.Mode] sections from our list
            sections.RemoveAll(s => s.Equals("global"));
            foreach (var modeName in GameState.ModeName)
                sections.RemoveAll(s => s.EndsWith("." + modeName));

            foreach (var dev in directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices))
            {
                Joystick js = new Joystick(directInput, dev.InstanceGuid);
                DetectedList.Add("AltInput: Detected Controller '" + dev.InstanceName + "': " +
                    js.Capabilities.AxeCount + " Axes, " + js.Capabilities.ButtonCount + " Buttons, " +
                    js.Capabilities.PovCount + " POV(s)");

                foreach(var section in sections)
                {
                    if (dev.InstanceName.Contains(section))
                    {
                        InterfaceName = ini.IniReadValue(section, "Interface");
                        if ((InterfaceName == "") || (ini.IniReadValue(section, "Ignore") == "true"))
                            break;
                        if (InterfaceName != "DirectInput")
                        {
                            print("AltInput[" + section + "]: Only 'DirectInput' is supported for Interface type");
                            continue;
                        }
                        ClassName = ini.IniReadValue(section, "Class");
                        if (ClassName == "")
                            ClassName = "GameControl";
                        else if (ClassName != "GameControl")
                        {
                            print("AltInput[" + section + "]: '" + ClassName + "' is not an allowed Class value");
                            continue;   // ignore the device
                        }
                        // Only add this device if not already in our list
                        if (DeviceList.Where(item => ((AltDirectInputDevice)item).InstanceGuid == dev.InstanceGuid).Any())
                            continue;
                        Device = new AltDirectInputDevice(directInput, DeviceClass.GameControl, dev.InstanceGuid);
                        SetAttributes(Device, section);
                        DeviceList.Add(Device);
                        print("AltInput: Added controller '" + dev.InstanceName + "'");
                    }
                }
            }
        }