//按指定版本路径读取索引文件,将每一条内容存入缓存字典中。目前仅用于版本对比 public static void ReadIndexCacheFile(string path) { Define.IndexDicCache.Clear(); MsgPack msgpack = new MsgPack(); FileStream fs = new FileStream(path, FileMode.Open); msgpack.DecodeFromStream(fs); fs.Close(); if (msgpack.children.Count == 1) { msgpack = msgpack.children[0]; } for (int i = 0; i < msgpack.children.Count; i++) { IndexInfo info = new IndexInfo(); MsgPack item = msgpack.children[i]; info.name = item.name; info.identifier = item.children[0].AsString; info.url = item.children[1].AsString; info.size = item.children[2].AsString; Define.IndexDicCache.Add(info.name, info); } if (Define.IndexDicCache.Count > 0) { Define.IndexDicCache = Define.IndexDicCache.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); } }
//按指定版本路径读取索引文件,将每一条内容存入字典中。 public static bool ReadIndexFile(string path) { Define.IndexDic.Clear(); // 首先清理字典 MsgPack msgpack = new MsgPack(); FileStream fs = new FileStream(path, FileMode.Open); msgpack.DecodeFromStream(fs); fs.Close(); if (msgpack.children.Count != 1) { return(false); } msgpack = msgpack.children[0]; foreach (MsgPack item in msgpack.children) { if (item.children.Count < 3) // 如果小于3则说明发生错误,需重新下载。一种常见原因是文件本身在下载过程中发生缺失。 { return(false); } IndexInfo info = new IndexInfo { name = item.name, identifier = item.children[0].AsString, url = item.children[1].AsString, size = item.children[2].AsString }; Define.IndexDic.Add(info.name, info); } if (Define.IndexDic.Count > 0) { Define.IndexDic = Define.IndexDic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); } return(true); }
public T Deserialize(Stream input) { msgpack = new MsgPack(); msgpack.DecodeFromStream(input); return(Decode()); }