コード例 #1
0
        /// <summary>
        /// Get Devices.
        /// </summary>
        public DeviceControl(AppRegInfo appReg)
        {
            // Make Joystick Instances.
            devList   = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
            joyStick  = new Device[devList.Count];
            joyAssign = new JoyAssgn[devList.Count];

            System.Xml.Serialization.XmlSerializer serializer;
            StreamReader sr;
            string       fileName      = "";
            string       stockFileName = "";
            int          i             = 0;

            foreach (DeviceInstance dev in devList)
            {
                joyStick[i]  = new Device(dev.InstanceGuid);
                joyAssign[i] = new JoyAssgn();

                joyAssign[i].SetDeviceInstance(dev);
                int povnum = joyStick[i].Caps.NumberPointOfViews;
                joyStick.Count();

                fileName = appReg.GetInstallDir() + "/User/Config/Setup.v100." + joyAssign[i].GetProductName().Replace("/", "-")
                           + " {" + joyAssign[i].GetInstanceGUID().ToString().ToUpper() + "}.xml";

                // Load existing .xml files.
                if (File.Exists(fileName))
                {
                    serializer   = new System.Xml.Serialization.XmlSerializer(typeof(JoyAssgn));
                    sr           = new StreamReader(fileName, new System.Text.UTF8Encoding(false));
                    joyAssign[i] = (JoyAssgn)serializer.Deserialize(sr);
                    sr.Close();
                }
                else
                {
                    stockFileName = appReg.GetInstallDir() + "/User/Config/Setup.v100." + joyAssign[i].GetProductName().Replace("/", "-")
                                    + " {Stock}.xml";
                    if (File.Exists(stockFileName))
                    {
                        File.Copy(stockFileName, fileName);

                        serializer   = new System.Xml.Serialization.XmlSerializer(typeof(JoyAssgn));
                        sr           = new StreamReader(fileName, new System.Text.UTF8Encoding(false));
                        joyAssign[i] = (JoyAssgn)serializer.Deserialize(sr);
                        sr.Close();
                    }
                }
                joyAssign[i].SetDeviceInstance(dev);
                i += 1;
            }

            // Import stock BMS Setup if .xml save file for the joystick does not exist.
            try
            {
                for (int ii = 0; ii < joyAssign.Length; ii++)
                {
                    fileName = appReg.GetInstallDir() + "/User/Config/Setup.v100." + joyAssign[ii].GetProductName().Replace("/", "-")
                               + " {" + joyAssign[ii].GetInstanceGUID().ToString().ToUpper() + "}.xml";
                    if (File.Exists(fileName) == false)
                    {
                        joyAssign[ii].ImportStockSetup(appReg, joyStick.Length, joyStick[ii].Caps.NumberPointOfViews, ii);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                System.Console.WriteLine(ex.Message);

                StreamWriter sw = new StreamWriter(appReg.GetInstallDir() + "\\Error.txt", false, System.Text.Encoding.GetEncoding("shift_jis"));
                sw.Write(ex.Message);
                sw.Close();
            }

            // Load MouseWheel .xml file.
            serializer = new System.Xml.Serialization.XmlSerializer(typeof(AxAssgn));
            fileName   = appReg.GetInstallDir() + "/User/Config/Setup.v100.Mousewheel.xml";
            if (File.Exists(fileName))
            {
                sr = new StreamReader(fileName, new System.Text.UTF8Encoding(false));
                mouseWheelAssign = (AxAssgn)serializer.Deserialize(sr);
                sr.Close();
            }

            // Load ThrottlePosition .xml file.
            serializer = new System.Xml.Serialization.XmlSerializer(typeof(ThrottlePosition));
            fileName   = appReg.GetInstallDir() + "/User/Config/Setup.v100.throttlePosition.xml";
            if (File.Exists(fileName))
            {
                sr          = new StreamReader(fileName, new System.Text.UTF8Encoding(false));
                throttlePos = (ThrottlePosition)serializer.Deserialize(sr);
                sr.Close();
            }
        }