コード例 #1
0
        /// <summary>
        /// Load a Cry Binary XML buffer into memory and return the NodeRef for the root element
        /// </summary>
        /// <param name="filename">The byte buffer to read</param>
        /// <param name="result">Read result</param>
        /// <returns>The NodeRef of the root element or NULL</returns>
        public CryXmlNodeRef LoadFromBuffer(byte[] binBuffer, out EResult result)
        {
            m_errorDescription = "";
            result             = EResult.Error;

            UInt32 fileSize = ( UInt32 )binBuffer.Length;

            try {
                if (fileSize < CryXMLHeader.MySize( ))
                {
                    result = EResult.NotBinXml;
                    SetErrorDescription("File is not a binary XML file (file size is too small).");
                    return(null);
                }

                // read from binary file and map the content into the memory
                CryXmlBinContext pData = Create(binBuffer, out result);

                if (result != EResult.Success)
                {
                    return(null);                     // Well...
                }
                // Return first node
                CryXmlNodeRef n = pData.pBinaryNodes[0];
                return(n);
            } catch {
                result = EResult.NotBinXml;
                SetErrorDescription("Exception in buffer reader");
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Processes a node and it's children
        /// </summary>
        /// <param name="nodeRef">The node to process</param>
        /// <param name="level">The depth of the node to indent the XML text</param>
        private void DoNode(CryXmlNodeRef nodeRef, int level)
        {
            string tabs = "".PadRight(level, '\t'); // level is depth - will be left padded with Tabs on Add()
            string xml  = "";

            IXmlNode node = nodeRef;

            // first gather and handle the attributes
            string attr = DoAttribute(nodeRef);

            xml = string.Format("<{0} {1} ", node.getTag( ), attr);

            // then do some formatting dependent of child nodes to be printed
            if (node.getChildCount( ) < 1)
            {
                // no child - close with end tag immediately
                xml += string.Format("/>"); m_doc.Add(tabs + xml); // add line w/o NL
            }
            else
            {
                // with children - close tag only
                xml += string.Format(">"); m_doc.Add(tabs + xml); // add line w/o NL

                // do the children
                for (int cc = 0; cc < node.getChildCount( ); cc++)
                {
                    CryXmlNodeRef childRef = node.getChild(cc);
                    DoNode(childRef, level + 1);                                        // recursion
                }
                xml = string.Format("</{0}>\n", node.getTag( )); m_doc.Add(tabs + xml); // add line with NL to space them
            }
        }
コード例 #3
0
        public bool Equals(CryXmlNodeRef objP)
        {
            // If parameter is null return false:
            if (( object )objP == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(p == objP.p);
        }
コード例 #4
0
ファイル: CryXmlBinNode.cs プロジェクト: zodsoft/SCJMapper-V2
        // Get parent XML node.
        public override CryXmlNodeRef getParent( )
        {
            CryXMLNode pNode = _node( );

            if (pNode.nParentIndex != ( CryXMLNodeIndex )(-1)) // murks..
            {
                CryXmlNodeRef n = m_pData.pBinaryNodes[pNode.nParentIndex];
                return(n);
            }
            // has no parent i.e. toplevel
            return(this);
        }
コード例 #5
0
ファイル: CryXmlBinNode.cs プロジェクト: zodsoft/SCJMapper-V2
        // Get XML Node child nodes.
        public override CryXmlNodeRef getChild(int i)
        {
            CryXMLNode pNode = _node( );

            if (i < 0 || i > ( int )pNode.nChildCount)
            {
                return(null);
            }
            CryXmlNodeRef n = m_pData.pBinaryNodes[m_pData.pChildIndices[pNode.nFirstChildIndex + i]];

            return(n);
        }
コード例 #6
0
        /// <summary>
        /// Processes all attributed of a node
        /// </summary>
        /// <param name="nodeRef">The node to process</param>
        /// <returns>an string containing all attributes in XML compatible format ( key="value" )</returns>
        private string DoAttribute(CryXmlNodeRef nodeRef)
        {
            IXmlNode node = nodeRef;
            string   xml  = "";

            // collect all attributes into one line
            for (int ac = 0; ac < node.getNumAttributes( ); ac++)
            {
                string key = ""; string value = "";
                node.getAttributeByIndex(ac, out key, out value);
                xml += string.Format(" {0}=\"{1}\" ", key, value);
            }
            return(xml);
        }
コード例 #7
0
ファイル: CryXmlBinNode.cs プロジェクト: zodsoft/SCJMapper-V2
        // Find node with specified tag.
        public override CryXmlNodeRef findChild(string tag)
        {
            CryXMLNode      pNode      = _node( );
            CryXMLNodeIndex nFirst     = pNode.nFirstChildIndex;
            CryXMLNodeIndex nAfterLast = pNode.nFirstChildIndex + pNode.nChildCount;

            for (CryXMLNodeIndex i = nFirst; i < nAfterLast; i++)
            {
                string sChildTag = _string(m_pData.pNodes[m_pData.pChildIndices[i]].nTagStringOffset);
                if (tag == sChildTag)
                {
                    CryXmlNodeRef n = m_pData.pBinaryNodes[m_pData.pChildIndices[i]];
                    return(n);
                }
            }
            return(null);
        }
コード例 #8
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            CryXmlNodeRef objP = obj as CryXmlNodeRef;

            if ((System.Object)p == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(p == objP.p);
        }
コード例 #9
0
        /// <summary>
        /// Load a Cry Binary XML file into memory and return the NodeRef for the root element
        /// </summary>
        /// <param name="filename">The file to read</param>
        /// <param name="result">Read result</param>
        /// <returns>The NodeRef of the root element or NULL</returns>
        public CryXmlNodeRef LoadFromFile(string filename, out EResult result)
        {
            m_errorDescription = "";
            result             = EResult.Error;

            if (!File.Exists(filename))
            {
                SetErrorDescription("Can't open file (file not found).");
                return(null);
            }

            using (BinaryReader binReader = new BinaryReader(File.Open(filename, FileMode.Open))) {
                try {
                    UInt32 fileSize = ( UInt32 )binReader.BaseStream.Length;

                    if (fileSize < CryXMLHeader.MySize( ))
                    {
                        result = EResult.NotBinXml;
                        SetErrorDescription("File is not a binary XML file (file size is too small).");
                        return(null);
                    }

                    // read from binary file and map the content into the memory
                    CryXmlBinContext pData = Create(binReader, fileSize, out result);

                    if (result != EResult.Success)
                    {
                        return(null);                   // Well...
                    }
                    // Return first node
                    CryXmlNodeRef n = pData.pBinaryNodes[0];
                    return(n);
                } catch {
                    result = EResult.NotBinXml;
                    SetErrorDescription("Exception in BinaryReader.");
                    return(null);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Processes a CryXmlNodeRef to derive the XML formatted structure
        ///  Note: the created XML text can be retrieved through the XML property of this object
        /// </summary>
        /// <param name="rootRef">The node to start from</param>
        public void BuildXML(CryXmlNodeRef rootRef)
        {
            m_doc.Clear( );

            DoNode(rootRef, 0);
        }
コード例 #11
0
 public CryXmlNodeRef(CryXmlNodeRef p_)
 {
     p = p_.p;
 }