/// <summary> /// @brief Get resource file data /// @param[in] pszFileName The resource file name which contain the path /// @param[in] pszMode The read mode of the file /// @param[out] pSize If get the file data succeed the it will be the data size,or it will be 0 /// @return if success,the pointer of data will be returned,or NULL is returned /// @warning If you get the file data succeed,you must delete it after used. /// </summary> /// <param name="pszFileName"></param> /// <param name="pszMode"></param> /// <param name="pSize"></param> /// <returns></returns> public static string getFileData(string pszFileName, string pszMode, UInt64 pSize) { ContentManager content = CCApplication.sharedApplication().content; CCContent data = content.Load <CCContent>(pszFileName); return(data.Content); }
public bool parse(string pszFile) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); CCContent data = CCApplication.sharedApplication().content.Load <CCContent>(pszFile); string str = data.Content; if (data == null) { return(false); } TextReader textReader = new StringReader(str); XmlReaderSettings setting = new XmlReaderSettings(); setting.DtdProcessing = DtdProcessing.Ignore; XmlReader xmlReader = XmlReader.Create(textReader, setting); int dataindex = 0; int Width = 0; int Height = 0;; while (xmlReader.Read()) { string name = xmlReader.Name; switch (xmlReader.NodeType) { case XmlNodeType.Element: string[] attrs = null; if (name == "map") { Width = ccUtils.ccParseInt(xmlReader.GetAttribute("width")); Height = ccUtils.ccParseInt(xmlReader.GetAttribute("height")); } if (xmlReader.HasAttributes) { attrs = new string[xmlReader.AttributeCount * 2]; xmlReader.MoveToFirstAttribute(); int i = 0; attrs[0] = xmlReader.Name; attrs[1] = xmlReader.Value; i += 2; while (xmlReader.MoveToNextAttribute()) { attrs[i] = xmlReader.Name; attrs[i + 1] = xmlReader.Value; i += 2; } // Move the reader back to the element node. xmlReader.MoveToElement(); } startElement(this, name, attrs); byte[] buffer = null; //read data content of tmx file if (name == "data") { if (attrs != null) { string encoding = ""; for (int i = 0; i < attrs.Length; i++) { if (attrs[i] == "encoding") { encoding = attrs[i + 1]; } } if (encoding == "base64") { int dataSize = (Width * Height * 4) + 1024; buffer = new byte[dataSize]; xmlReader.ReadElementContentAsBase64(buffer, 0, dataSize); } else { string value = xmlReader.ReadElementContentAsString(); buffer = Encoding.UTF8.GetBytes(value); } } textHandler(this, buffer, buffer.Length); endElement(this, name); } else if (name == "key" || name == "integer" || name == "real" || name == "string" || name == "true" || name == "false") // http://www.cocos2d-x.org/boards/17/topics/11355 { string value = xmlReader.ReadElementContentAsString(); buffer = Encoding.UTF8.GetBytes(value); textHandler(this, buffer, buffer.Length); endElement(this, name); } else { IXmlLineInfo info = (IXmlLineInfo)xmlReader; CCLog.Log("Failed to handle XML tag: " + name + " in " + info.LineNumber + "@" + info.LinePosition + ":" + pszFile); } break; case XmlNodeType.EndElement: endElement(this, xmlReader.Name); dataindex++; break; default: break; } } return(true); }
public bool parse(string pszFile) { #if WINDOWS_UWP #else // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); #endif CCContent cCContent = CCApplication.sharedApplication().content.Load <CCContent>(pszFile); string content = cCContent.Content; if (cCContent == null) { return(false); } TextReader stringReader = new System.IO.StringReader(content); XmlReaderSettings xmlReaderSetting = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Ignore }; XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSetting); int num = 0; int num1 = 0; int num2 = 0; while (xmlReader.Read()) { string name = xmlReader.Name; XmlNodeType nodeType = xmlReader.NodeType; if (nodeType == XmlNodeType.Element) { string[] value = null; if (name == "map") { num1 = ccUtils.ccParseInt(xmlReader.GetAttribute("width")); num2 = ccUtils.ccParseInt(xmlReader.GetAttribute("height")); } if (xmlReader.HasAttributes) { value = new string[xmlReader.AttributeCount * 2]; xmlReader.MoveToFirstAttribute(); int num3 = 0; value[0] = xmlReader.Name; value[1] = xmlReader.Value; num3 = num3 + 2; while (xmlReader.MoveToNextAttribute()) { value[num3] = xmlReader.Name; value[num3 + 1] = xmlReader.Value; num3 = num3 + 2; } xmlReader.MoveToElement(); } CCSAXParser.startElement(this, name, value); byte[] bytes = null; if (name == "data") { if (value != null) { string str = ""; for (int i = 0; i < (int)value.Length; i++) { if (value[i] == "encoding") { str = value[i + 1]; } } if (str != "base64") { string str1 = xmlReader.ReadElementContentAsString(); bytes = Encoding.UTF8.GetBytes(str1); } else { int num4 = num1 * num2 * 4 + 1024; bytes = new byte[num4]; xmlReader.ReadElementContentAsBase64(bytes, 0, num4); } } CCSAXParser.textHandler(this, bytes, (int)bytes.Length); CCSAXParser.endElement(this, name); } else if (name == "key" || name == "integer" || name == "real" || name == "string" || name == "true" || name == "false") { string str2 = xmlReader.ReadElementContentAsString(); bytes = Encoding.UTF8.GetBytes(str2); CCSAXParser.textHandler(this, bytes, (int)bytes.Length); CCSAXParser.endElement(this, name); } else { IXmlLineInfo xmlLineInfo = (IXmlLineInfo)xmlReader; object[] lineNumber = new object[] { "Failed to handle XML tag: ", name, " in ", xmlLineInfo.LineNumber, "@", xmlLineInfo.LinePosition, ":", pszFile }; CCLog.Log(string.Concat(lineNumber)); } } else if (nodeType == XmlNodeType.EndElement) { CCSAXParser.endElement(this, xmlReader.Name); num++; } } return(true); }
private void parseConfigFile(string controlFile) { CCContent data = CCApplication.sharedApplication().content.Load <CCContent>(controlFile); string pBuffer = data.Content; long nBufSize = data.Content.Length; Debug.Assert(pBuffer != null, "CCBMFontConfiguration::parseConfigFile | Open file error."); if (string.IsNullOrEmpty(pBuffer)) { return; } // parse spacing / padding string line; string strLeft = pBuffer; if (strLeft.StartsWith("<?xml")) { throw (new ArgumentException("FNT control file is XML, expecting it to be plain text.")); } // TDOO: Add an xml parser while (strLeft.Length > 0) { int pos = strLeft.IndexOf('\n'); if (pos != -1) { // the data is more than a line.get one line line = strLeft.Substring(0, pos); strLeft = strLeft.Substring(pos + 1); } else { // get the left data line = strLeft; strLeft = null; } if (line.StartsWith("info face")) { // XXX: info parsing is incomplete // Not needed for the Hiero editors, but needed for the AngelCode editor // [self parseInfoArguments:line]; this.parseInfoArguments(line); } // Check to see if the start of the line is something we are interested in if (line.StartsWith("common lineHeight")) { this.parseCommonArguments(line); } if (line.StartsWith("page id")) { this.parseImageFileName(line, controlFile); } if (line.StartsWith("chars c")) { // Ignore this line continue; } if (line.StartsWith("char")) { // Parse the current line and create a new CharDef ccBMFontDef characterDefinition = new ccBMFontDef(); this.parseCharacterDefinition(line, characterDefinition); // Add the CharDef returned to the charArray m_pBitmapFontArray.Add(characterDefinition.charID, characterDefinition); } if (line.StartsWith("kernings count")) { this.parseKerningCapacity(line); } if (line.StartsWith("kerning first")) { this.parseKerningEntry(line); } } }
protected virtual bool InitWithFNTFile(string fntFile) { string content = CCContent.LoadContentFile(fntFile); return(InitWithString(content, fntFile)); }
private void parseConfigFile(string controlFile) { string str; CCContent cCContent = CCApplication.sharedApplication().content.Load <CCContent>(controlFile); string content = cCContent.Content; int length = cCContent.Content.Length; if (string.IsNullOrEmpty(content)) { return; } string str1 = content; if (str1.StartsWith("<?xml")) { throw new ArgumentException("FNT control file is XML, expecting it to be plain text."); } while (str1.Length > 0) { int num = str1.IndexOf('\n'); if (num == -1) { str = str1; str1 = null; } else { str = str1.Substring(0, num); str1 = str1.Substring(num + 1); } if (str.StartsWith("info face")) { this.parseInfoArguments(str); } if (str.StartsWith("common lineHeight")) { this.parseCommonArguments(str); } if (str.StartsWith("page id")) { this.parseImageFileName(str, controlFile); } if (str.StartsWith("chars c")) { continue; } if (str.StartsWith("char")) { ccBMFontDef _ccBMFontDef = new ccBMFontDef(); this.parseCharacterDefinition(str, _ccBMFontDef); this.m_pBitmapFontArray.Add(_ccBMFontDef.charID, _ccBMFontDef); } if (str.StartsWith("kernings count")) { this.parseKerningCapacity(str); } if (!str.StartsWith("kerning first")) { continue; } this.parseKerningEntry(str); } }