/// <summary> /// 获取XML字符串 /// </summary> /// <returns></returns> private static string getXMLStr() { string direName = StringUtil.getLastStr(bundlesDirePath); string manifestPath = bundlesDirePath + "/" + direName + ".manifest"; Dictionary<string, ManifestVO> voDic = new Dictionary<string, ManifestVO>(); //手动添加db ManifestVO manifestVO = new ManifestVO(); manifestVO.name = "db.assets"; voDic.Add(manifestVO.name, manifestVO); //手动添加modules manifestVO = new ManifestVO(); manifestVO.name = "modules.assets"; voDic.Add(manifestVO.name, manifestVO); string line; StreamReader fs; if (File.Exists(manifestPath)) { fs = new StreamReader(manifestPath); //获取总信息 while ((line = fs.ReadLine()) != null) { line = line.Replace("\n", ""); int index = line.IndexOf("Name:"); if (index >= 0) { ManifestVO vo = new ManifestVO(); vo.name = line.Substring(index + 6); fs.ReadLine(); while ((line = fs.ReadLine()) != null) { index = line.IndexOf("Dependency_"); if (index < 0) { break; } line = line.Replace("\n", ""); index = line.IndexOf(":"); if (string.IsNullOrEmpty(vo.deps)) { vo.deps = line.Substring(index + 2); } else { vo.deps = "," + line.Substring(index + 2); } } voDic.Add(vo.name, vo); } } fs.Close(); } //读取CRC和assets信息 foreach (string fileName in voDic.Keys) { ManifestVO vo = voDic[fileName]; int status = 0; fs = new StreamReader(bundlesDirePath + "/" + fileName + ".manifest"); while ((line = fs.ReadLine()) != null) { line = line.Replace("\n", ""); if (status == 0) { int index = line.IndexOf("CRC:"); if (index >= 0) { vo.crc = line.Substring(index + 5); status++; } } else if (status == 1) { int index = line.IndexOf("Assets:"); if (index >= 0) { vo.assets = ""; while ((line = fs.ReadLine()) != null && line.IndexOf("- ") == 0) { if (!string.IsNullOrEmpty(vo.assets)) { vo.assets += ","; } vo.assets += line.Substring(2); } } } } fs.Close(); } string allStr = ""; foreach (ManifestVO vo in voDic.Values) { allStr += "<" + vo.name + " crc=\"" + vo.crc + "\"" + " deps=\"" + vo.deps + "\"" + " assets=\"" + vo.assets + "\"" + "/>"; } return allStr; }
/// <summary> /// 解析数据 /// </summary> /// <param name="textAsset"></param> private void analysis(TextAsset textAsset) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(textAsset.text); XmlNodeList xmlNodeList = xmlDocument.SelectSingleNode("manifest").ChildNodes; dic = new Dictionary<string, ManifestVO>(); ManifestVO vo; XmlElement xmlelement; for(int i=0, len = xmlNodeList.Count; i<len; i++) { xmlelement = (XmlElement)xmlNodeList[i]; vo = new ManifestVO(); vo.name = xmlelement.LocalName; vo.assets = xmlelement.GetAttribute("assets"); vo.crc = xmlelement.GetAttribute("crc"); vo.deps = xmlelement.GetAttribute("deps"); dic.Add(vo.name, vo); } }