Example #1
0
        /// <summary>
        /// Read an ActionMaps from XML - do some sanity check
        /// </summary>
        /// <param name="xml">the XML action fragment</param>
        /// <returns>True if an action was decoded</returns>
        public Boolean fromXML(String xml)
        {
            log.Debug("fromXML - Entry");

            CreateNewOptions( );        // Reset those options...
            m_options.InvertCheckList = m_invertCB;
            m_options.ResetInverter( ); // have to reset when reading a new mapping

            XmlReaderSettings settings = new XmlReaderSettings( );

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            XmlReader reader = XmlReader.Create(new StringReader(xml), settings);


            reader.Read( );

            if (reader.Name == "ActionMaps")
            {
                if (reader.HasAttributes)
                {
                    version = reader["version"];
                    if (version == "0")
                    {
                        version = ACM_VERSION;               // update from legacy to actual version
                    }
                    ignoreversion = reader["ignoreVersion"]; // could be either / or ..

                    // get the joystick mapping if there is one
                    for (int i = 0; i < JoystickCls.JSnum_MAX; i++)
                    {
                        jsN[i]     = reader[String.Format("js{0}", i + 1)];
                        jsNGUID[i] = reader[String.Format("js{0}G", i + 1)];
                    }
                }
                else
                {
                    return(false);
                }
            }

            reader.Read( ); // move to next element

            // could be actionmap OR (AC 0.9) deviceoptions OR options

            while (!reader.EOF) //!String.IsNullOrEmpty( x ) ) {

            {
                if (reader.Name == "actionmap")
                {
                    String       x   = reader.ReadOuterXml( );
                    ActionMapCls acm = new ActionMapCls( );
                    if (acm.fromXML(x))
                    {
                        this.Merge(acm); // merge list
                    }
                }
                else if (reader.Name == "CustomisationUIHeader")
                {
                    String x = reader.ReadOuterXml( );
                    m_uiCustHeader.fromXML(x);
                }
                else if (reader.Name == "deviceoptions")
                {
                    String x = reader.ReadOuterXml( );
                    m_deviceOptions.fromXML(x);
                }
                else if (reader.Name == "options")
                {
                    String x = reader.ReadOuterXml( );
                    m_options.fromXML(x);
                }
                else
                {
                    reader.Read( );
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Read an ActionMaps from XML - do some sanity check
        /// </summary>
        /// <param name="xml">the XML action fragment</param>
        /// <returns>True if an action was decoded</returns>
        public bool fromXML(string xml)
        {
            log.Debug("ActionMapsCls.fromXML - Entry");

            XmlReaderSettings settings = new XmlReaderSettings( );

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            XmlReader reader = XmlReader.Create(new StringReader(xml), settings);

            reader.Read( );
            // read the header element
            if (reader.Name == "ActionMaps")
            {
                if (reader.HasAttributes)
                {
                    version = reader["version"];
                    if (version == "0")
                    {
                        version = ACM_VERSION;         // update from legacy to actual version
                    }
                    // get the joystick mapping if there is one
                    for (int i = 0; i < JoystickCls.JSnum_MAX; i++)
                    {
                        jsN[i]     = reader[string.Format("js{0}", i + 1)];
                        jsNGUID[i] = reader[string.Format("js{0}G", i + 1)];
                    }
                }
                else
                {
                    return(false);
                }
            }

            // now handle the js assignment from the map
            // Reset with the found mapping
            DeviceInst.JoystickListRef.ResetJsNAssignment(jsNGUID);
            // Only now create the default optiontree for this map, containing included joysticks and the gamepad
            CreateNewOptions( );

            // now read the CIG content of the map
            reader.Read( ); // move to next element

            // could be actionmap OR (AC 0.9) deviceoptions OR options

            while (!reader.EOF) //!string.IsNullOrEmpty( x ) ) {

            {
                if (reader.Name.ToLowerInvariant( ) == "actionmap")
                {
                    string       x   = reader.ReadOuterXml( );
                    ActionMapCls acm = new ActionMapCls( );
                    if (acm.fromXML(x))
                    {
                        this.Merge(acm); // merge list
                    }
                }
                else if (reader.Name.ToLowerInvariant( ) == "customisationuiheader")
                {
                    string x = reader.ReadOuterXml( );
                    m_uiCustHeader.fromXML(x);
                }
                else if (reader.Name.ToLowerInvariant( ) == "deviceoptions")
                {
                    string x = reader.ReadOuterXml( );
                    m_deviceOptions.fromXML(x);
                }
                else if (reader.Name.ToLowerInvariant( ) == "options")
                {
                    string x = reader.ReadOuterXml( );
                    m_tuningOptions.fromXML(x);
                }
                else
                {
                    reader.Read( );
                }
            }
            return(true);
        }