예제 #1
0
 public JoyAssgn(JoyAssgn otherInstance)
 {
     this.productGUID  = otherInstance.productGUID;
     this.productName  = otherInstance.productName;
     this.instanceGUID = otherInstance.instanceGUID;
     for (int i = 0; i < this.axis.Length; i++)
     {
         this.axis[i] = otherInstance.axis[i].Clone();
     }
     for (int i = 0; i < this.pov.Length; i++)
     {
         this.pov[i] = otherInstance.pov[i].Clone();
     }
     for (int i = 0; i < this.dx.Length; i++)
     {
         this.dx[i] = otherInstance.dx[i].Clone();
     }
 }
예제 #2
0
 public JoyAssgn(JoyAssgn otherInstance)
 {
     productGUID  = otherInstance.productGUID;
     productName  = otherInstance.productName;
     instanceGUID = otherInstance.instanceGUID;
     for (int i = 0; i < axis.Length; i++)
     {
         axis[i] = otherInstance.axis[i].Clone();
     }
     for (int i = 0; i < pov.Length; i++)
     {
         pov[i] = otherInstance.pov[i].Clone();
     }
     for (int i = 0; i < dx.Length; i++)
     {
         dx[i] = otherInstance.dx[i].Clone();
     }
 }
        /// <summary>
        /// Get Devices.
        /// </summary>
        public DeviceControl(AppRegInfo appReg)
        {
            // Make Joystick Instances.
            this.devList   = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
            this.joyStick  = new Device[devList.Count];
            this.joyAssign = new JoyAssgn[devList.Count];

            System.Xml.Serialization.XmlSerializer serializer;
            System.IO.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 exsisting .xml files.
                if (File.Exists(fileName))
                {
                    serializer   = new System.Xml.Serialization.XmlSerializer(typeof(JoyAssgn));
                    sr           = new System.IO.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 System.IO.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.Count(); 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.Count(), joyStick[ii].Caps.NumberPointOfViews, ii);
                    }
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
                System.Console.WriteLine(ex.Message);

                System.IO.StreamWriter sw = new System.IO.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(JoyAssgn.AxAssgn));
            fileName   = appReg.GetInstallDir() + "/User/Config/Setup.v100.Mousewheel.xml";
            if (File.Exists(fileName))
            {
                sr = new System.IO.StreamReader(fileName, new System.Text.UTF8Encoding(false));
                mouseWheelAssign = (JoyAssgn.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 System.IO.StreamReader(fileName, new System.Text.UTF8Encoding(false));
                throttlePos = (ThrottlePosition)serializer.Deserialize(sr);
                sr.Close();
            }
        }