//把字节流转为manifest对象 public static ManifestInfo GetManifestFromBytes(byte[] bytes) { ManifestInfo manifestInfo = null; try { //System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes.Uncompress()); System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.BinaryReader br = new System.IO.BinaryReader(ms); br.BaseStream.Position = 0; manifestInfo = new ManifestInfo(); manifestInfo.version = br.ReadString(); uint num = br.ReadUInt32(); AssetInfo assetInfo; while (num-- > 0) { List <string> fileNameList = new List <string>(); string subPath = br.ReadString(); long length = br.ReadInt64(); long createDate = br.ReadInt64(); string md5 = br.ReadString(); string suffix = br.ReadString(); uint fileNameNum = br.ReadUInt32(); while (fileNameNum-- > 0) { fileNameList.Add(br.ReadString()); } assetInfo = new AssetInfo(subPath, length, createDate, md5, suffix, fileNameList); manifestInfo.assetDic.Add(assetInfo.SubPath, assetInfo); } br.Close(); ms.Close(); ms.Dispose(); return(manifestInfo); } catch (Exception e) { Debugger.LogError("GetManifestFromBytes:" + e); } finally { } return(null); }
//把manifest文件信息保存在本地 public static void SaveManifest2Local(ManifestInfo manifestInfo) { try { string path = GetLocalManifestPath(); string dir = ResUtil.GetDirectoryByPath(path); if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } System.IO.File.WriteAllBytes(path, GetBytesFromManifest(manifestInfo)); } catch (Exception e) { Debugger.LogError("SaveManifest2Local:" + e); } finally { } }
//把manifest对象转为字节流 public static byte[] GetBytesFromManifest(ManifestInfo manifestInfo) { try { System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms); bw.Write(manifestInfo.version); bw.Write(manifestInfo.assetDic.Count); foreach (var kv in manifestInfo.assetDic) { bw.Write(kv.Value.SubPath); bw.Write(kv.Value.Length); bw.Write(kv.Value.CreateDate); bw.Write(kv.Value.md5); bw.Write(kv.Value.Suffix); bw.Write(kv.Value.FilePathList.Count); for (int i = 0, count = kv.Value.FilePathList.Count; i < count; i++) { bw.Write(kv.Value.FilePathList[i]); } } ms.Position = 0; int len = (int)ms.Length;//manifest文件不能超2GB byte[] bytes = new byte[len]; ms.Read(bytes, 0, len); bw.Close(); ms.Close(); ms.Dispose(); //return bytes.Compress(); return(bytes); } catch (Exception e) { Debugger.LogError("GetBytesFromManifest:" + e); } finally { } return(null); }