Example #1
0
        public virtual bool Initialize(XmlDocument Map)
        {
            try
            {
                m_Remapping = false;
                m_Mapper.Clear();

                var Node = Map.SelectSingleNode("/ScpMapper");

                m_Description = Node.SelectSingleNode("Description").FirstChild.Value;
                m_Version     = Node.SelectSingleNode("Version").FirstChild.Value;
                m_Active      = Node.SelectSingleNode("Active").FirstChild.Value;

                foreach (XmlNode ProfileNode in Node.SelectNodes("Mapping/Profile"))
                {
                    var Name = ProfileNode.SelectSingleNode("Name").FirstChild.Value;
                    var Type = ProfileNode.SelectSingleNode("Type").FirstChild.Value;

                    var Qualifier = string.Empty;

                    var QualifierNode = ProfileNode.SelectSingleNode("Value");

                    if (QualifierNode.HasChildNodes)
                    {
                        Qualifier = QualifierNode.FirstChild.Value;
                    }


                    var Profile = new Profile(Name == m_Active, Name, Type, Qualifier);

                    foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS3/Button"))
                    {
                        foreach (XmlNode Item in Mapping.ChildNodes)
                        {
                            var Target = (Ds3Button)Enum.Parse(typeof(Ds3Button), Item.ParentNode.Name);
                            var Mapped = (Ds3Button)Enum.Parse(typeof(Ds3Button), Item.Value);

                            Profile.Ds3Button[Target] = Mapped;
                        }
                    }

                    foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS3/Axis"))
                    {
                        foreach (XmlNode Item in Mapping.ChildNodes)
                        {
                            var Target = (Ds3Axis)Enum.Parse(typeof(Ds3Axis), Item.ParentNode.Name);
                            var Mapped = (Ds3Axis)Enum.Parse(typeof(Ds3Axis), Item.Value);

                            Profile.Ds3Axis[Target] = Mapped;
                        }
                    }

                    foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS4/Button"))
                    {
                        foreach (XmlNode Item in Mapping.ChildNodes)
                        {
                            var Target = (Ds4Button)Enum.Parse(typeof(Ds4Button), Item.ParentNode.Name);
                            var Mapped = (Ds4Button)Enum.Parse(typeof(Ds4Button), Item.Value);

                            Profile.Ds4Button[Target] = Mapped;
                        }
                    }

                    foreach (XmlNode Mapping in ProfileNode.SelectSingleNode("DS4/Axis"))
                    {
                        foreach (XmlNode Item in Mapping.ChildNodes)
                        {
                            var Target = (Ds4Axis)Enum.Parse(typeof(Ds4Axis), Item.ParentNode.Name);
                            var Mapped = (Ds4Axis)Enum.Parse(typeof(Ds4Axis), Item.Value);

                            Profile.Ds4Axis[Target] = Mapped;
                        }
                    }

                    m_Mapper[Profile.Name] = Profile;
                }

                var Mappings = m_Mapper[m_Active].Ds3Button.Count + m_Mapper[m_Active].Ds3Axis.Count +
                               m_Mapper[m_Active].Ds4Button.Count + m_Mapper[m_Active].Ds4Axis.Count;
                Log.DebugFormat("## Mapper.Initialize() - Profiles [{0}] Active [{1}] Mappings [{2}]", m_Mapper.Count,
                                m_Active, Mappings);

                m_Remapping = true;
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error in XML Initialize: {0}", ex);
            }

            return(m_Remapping);
        }