//Save public bool SaveInfo() { string newName = "new_" + m_MapName; if (File.Exists(newName)) { File.Delete(newName); } FileStream fs = new FileStream(newName, FileMode.Create, FileAccess.Write); //写头 var tmpByte = CStructBytesFormat.StructToBytes <MapHead>(m_head); fs.Write(tmpByte, 0, tmpByte.Length); //写正文 for (int i = 0; i < m_NodeList.Count; i++) { //var tmp = CStructBytesFormat.StructToBytes<AccAttr>(m_playersAttrList[i]); var tmp = CStructBytesFormat.rawSerialize(m_NodeList[i]); fs.Write(tmp, 0, tmp.Length); } byte[] bBig = new byte[m_tail.Count]; m_tail.CopyTo(bBig); fs.Write(bBig, 0, bBig.Length); fs.Close(); return(true); }
//加载信息 public bool LoadInfo(string file) { m_NodeList.Clear(); m_tail.Clear(); if (!File.Exists(file)) { return(false); } m_MapName = file; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); int ret = 0; byte[] bytData = new byte[Marshal.SizeOf(m_head)]; ret = fs.Read(bytData, 0, Marshal.SizeOf(m_head)); m_head = CStructBytesFormat.BytesToStruct <MapHead>(bytData); while (ret > 0) { MapNode aa = new MapNode(); byte[] bytMapNodeData = new byte[Marshal.SizeOf(aa)]; ret = fs.Read(bytMapNodeData, 0, Marshal.SizeOf(aa)); if (ret <= 0) { break; } MapNode mapNode = CStructBytesFormat.BytesToStruct <MapNode>(bytMapNodeData); if (mapNode.unknow1 == 0) { m_NodeList.Add(mapNode); } else { byte[] bytTailData = new byte[ret]; Array.Copy(bytMapNodeData, 0, bytTailData, 0, ret); m_tail.AddRange(bytTailData); } } fs.Close(); return(true); }