public static void WriteXml(XmlDocument xmlDoc, XmlNode node, List <BundleInfo> list, ref uint total_file_size) { if (list == null || xmlDoc == null || node == null) { return; } CPathTree parent = new CPathTree(); for (int nIdx = 0; nIdx < list.Count; ++nIdx) { total_file_size += list[nIdx].size; parent.InsertPathTree(list[nIdx]); } string path = ""; WriteXml(xmlDoc, node, parent, path); }
public void WriteXml(XmlDocument xmlDoc, XmlNode node) { if (node == null || data == null || xmlDoc == null) { return; } XmlNode child_node = null; int total_file_cnt = 0; uint total_file_size = 0; if (data.addList.Count > 0) { child_node = xmlDoc.CreateElement("new"); CPathTree.WriteXml(xmlDoc, child_node, data.addList, ref total_file_size); node.AppendChild(child_node); } if (data.modifiyList.Count > 0) { child_node = xmlDoc.CreateElement("modify"); CPathTree.WriteXml(xmlDoc, child_node, data.modifiyList, ref total_file_size); node.AppendChild(child_node); } if (data.deleteList.Count > 0) { uint total_file_size1 = 0; child_node = xmlDoc.CreateElement("delete"); CPathTree.WriteXml(xmlDoc, child_node, data.deleteList, ref total_file_size1); node.AppendChild(child_node); } total_file_cnt = data.addList.Count + data.modifiyList.Count; XmlAttribute attributeNode = xmlDoc.CreateAttribute("total_file_cnt"); attributeNode.Value = total_file_cnt.ToString(); node.Attributes.Append(attributeNode); attributeNode = xmlDoc.CreateAttribute("total_file_size"); attributeNode.Value = CPathTree.GetSizeDes(total_file_size); node.Attributes.Append(attributeNode); }
public void InsertPathTree(BundleInfo bundleInfo) { if (bundleInfo == null) { return; } total_file_cnt++; total_file_size += bundleInfo.size; string[] path_arr = bundleInfo.bundleName.Split('/'); if (path_arr == null || path_arr.Length < 2) { return; } // 构建目录树; CPathTree _iterator = this; CPathTree pathTree = null; for (int nIdx = 0; nIdx < path_arr.Length - 1; ++nIdx) { if (!_iterator.subPathTree.TryGetValue(path_arr[nIdx], out pathTree)) { pathTree = new CPathTree(); pathTree.path = path_arr[nIdx]; _iterator.subPathTree[path_arr[nIdx]] = pathTree; } _iterator = pathTree; } if (pathTree != null) { pathTree.size += bundleInfo.size; if (pathTree.data_list == null) { pathTree.data_list = new List <BundleInfo>(); } pathTree.data_list.Add(bundleInfo); } }
static void WriteXml(XmlDocument xmlDoc, XmlNode node, CPathTree pathTree, string path) { if (pathTree == null || xmlDoc == null || node == null) { return; } if (string.IsNullOrEmpty(path)) { path = pathTree.path; } else { path = path + "_" + pathTree.path; } XmlNode path_node = node; // 写入文件信息; XmlNode child_node = null; XmlAttribute attributeNode = null; if (pathTree.total_file_cnt > 0) { attributeNode = xmlDoc.CreateAttribute("total_file_cnt"); attributeNode.Value = pathTree.total_file_cnt.ToString(); path_node.Attributes.Append(attributeNode); attributeNode = xmlDoc.CreateAttribute("total_file_size"); attributeNode.Value = GetSizeDes(pathTree.total_file_size); path_node.Attributes.Append(attributeNode); } if (pathTree.data_list != null) { path_node = xmlDoc.CreateElement(path); node.AppendChild(path_node); node = path_node; attributeNode = xmlDoc.CreateAttribute("bundleSize"); attributeNode.Value = (1.0f * pathTree.size / 1024).ToString("F2") + "KB"; node.Attributes.Append(attributeNode); for (int nIdx = 0; nIdx < pathTree.data_list.Count; ++nIdx) { BundleInfo bundleInfo = pathTree.data_list[nIdx]; child_node = xmlDoc.CreateElement("file"); path_node.AppendChild(child_node); attributeNode = xmlDoc.CreateAttribute("bundleName"); attributeNode.Value = bundleInfo.bundleName; child_node.Attributes.Append(attributeNode); attributeNode = xmlDoc.CreateAttribute("size"); attributeNode.Value = (1.0f * bundleInfo.size / 1024).ToString("F2") + "KB"; child_node.Attributes.Append(attributeNode); } } if (pathTree.subPathTree.Count == 0) { return; } foreach (KeyValuePair <string, CPathTree> pairs in pathTree.subPathTree) { WriteXml(xmlDoc, path_node, pairs.Value, path); } }