public AssetbundleJsonMap GetJson(byte[] bytes) { string md2data = FileUtils.ReadStringFromBytes(bytes, false); AssetbundleJsonMap json = LitJson.JsonMapper.ToObject <AssetbundleJsonMap>(md2data); return(json); }
public List <AssetbundleJsonData> CompareMD(AssetbundleJsonMap cdn, AssetbundleJsonMap map2) { List <AssetbundleJsonData> updateFiles = new List <AssetbundleJsonData>(); //long length = 0; for (int i = 0; i < cdn.arrayRes.Length; i++) { AssetbundleJsonData data = cdn.arrayRes[i]; AssetbundleJsonData local = map2.GetJsonData(data.resName); if (local == null) { //length += data.length; updateFiles.Add(data); } else if (data.hashCode == local.hashCode) { } else { updateFiles.Add(data); //length += data.length; } } return(updateFiles); }
void CheckMD(byte[] data) { //read cdn string cdnMDstring = FileUtils.ReadStringFromBytes(data, false); if (!string.IsNullOrEmpty(cdnMDstring)) { cdnMapHash = JsonMapper.ToObject <AssetbundleJsonMap>(cdnMDstring); } else { cdnMapHash = new AssetbundleJsonMap(); } //read presistent AssetbundleJsonMap cacheMapHash = LoadMDFromPersistent(); AssetbundleJsonMap streamingMapHash = LoadMDFromStreaming(); if (cacheMapHash == null && streamingMapHash == null)//直接更新资源 { tip = " 缓存目录和流媒体目录都 不存在MD文件 "; Debug.LogError(tip); updates = new List <AssetbundleJsonData>(); updates.AddRange(cdnMapHash.arrayRes); } if (cacheMapHash == null && streamingMapHash != null) { tip = " 流媒体目录 存在MD文件 "; Debug.LogError(tip); updates = CompareMD(cdnMapHash, streamingMapHash); } if (cacheMapHash != null && streamingMapHash == null) { tip = " 缓存目录 存在MD文件 "; Debug.LogError(tip); updates = CompareMD(cdnMapHash, cacheMapHash); } //以缓存目录为准 //why? //因为第一步比较MD2的过程中,已经把资源过旧的问题排除了 //出现这种情况,只可能是缓存目录是最新的资源 if (cacheMapHash != null && streamingMapHash != null) { tip = " 缓存目录和流媒体目录都 存在MD文件 "; Debug.LogError(tip); updates = CompareMD(cdnMapHash, cacheMapHash); } SuperBoBo.EventManager.Instance.FireEvent(UpdateEvent.Updater_DownloadMDDone); }
private void OnMd2Finish(WWW www) { j2 = GetJson(www.bytes); updates = CompareMD(j2, j1); deletes = DeleteMD(j2, j1); adds = AddMD(j2, j1); updates.Sort(Sort); adds.Sort(Sort); deletes.Sort(Sort); }
//[MenuItem("Tools/程序狗专用/Res/MD5")] public static void GenMD5() { FileUtilTool.DelFile(mdFile); string fresfolder = resFolder.Replace("\\", "/"); List <AssetbundleJsonData> data = GetMD5ForFolder(resFolder, fresfolder); AssetbundleJsonMap map = new AssetbundleJsonMap(); map.arrayRes = data.ToArray(); string jsonStr = JsonMapper.ToJson(map); FileUtilTool.WriteFile(mdFile, jsonStr); }
public List <AssetbundleJsonData> AddMD(AssetbundleJsonMap cdn, AssetbundleJsonMap map2) { List <AssetbundleJsonData> updateFiles = new List <AssetbundleJsonData>(); foreach (var k in cdn.arrayRes) { bool find = false; foreach (var j in map2.arrayRes) { if (k.resName == j.resName) { find = true; break; } } if (!find) { updateFiles.Add(k); } } return(updateFiles); }
AssetbundleJsonMap LoadMDFromPersistent() { //read presistent string mdCache = ""; AssetbundleJsonMap cacheMapHash = null; try { FileUtils.ReadFileInPersistent(mdFile, ref mdCache, false); if (!string.IsNullOrEmpty(mdCache)) { cacheMapHash = JsonMapper.ToObject <AssetbundleJsonMap>(mdCache); } } catch (System.Exception e) { Debug.LogError(e.ToString()); mdCache = ""; cacheMapHash = null; } return(cacheMapHash); }
AssetbundleJsonMap LoadMDFromStreaming() { //read streaming string mdStreaming = ""; AssetbundleJsonMap streamingMapHash = null; try { mdStreaming = FileUtils.ReadStringFromStreaming(mdFile, false); if (!string.IsNullOrEmpty(mdStreaming)) { streamingMapHash = JsonMapper.ToObject <AssetbundleJsonMap>(mdStreaming); } } catch (System.Exception e) { Debug.LogError(e.ToString()); mdStreaming = ""; streamingMapHash = null; } return(streamingMapHash); }
private void OnMd1Finish(WWW www) { j1 = GetJson(www.bytes); }