/// <summary> /// 检查是否有资源需要更新; /// </summary> public static void CheckResVersion() { if (!m_isDownLoadOpen) { return; } foreach (KeyValuePair <string, DownLoadAssetInfo> kv in m_dicDownLoadInfo) { if (kv.Value == null) { Debug.LogError("WWWDownLoaderConfig CheckResVersion, kv.Value can not be null. Key : " + kv.Key); continue; } bool hasContains = true; foreach (KeyValuePair <string, KeyValuePairConfigHelper> kvLocal in m_dicLocalResVerReader) { KeyValuePairConfigHelper gtHelper = kvLocal.Value; if (gtHelper != null) { if (gtHelper.CheckHasResVersion(kv.Key)) { string strMD5 = gtHelper.GetNodeMD5(kv.Key); //本地没有配置,返回为空; if (kv.Value.m_strMD5.Equals(strMD5)) //如果MD5不相同,就是需要更新替换的资源; { hasContains = false; } } } else { Debug.LogError("WWWDownLoaderConfig CheckResVersion, gtHelper can not be null. " + kv.Key); } } if (hasContains) { if (!m_dicUpdateRes.ContainsKey(kv.Key)) { m_dicUpdateRes.Add(kv.Key, kv.Value.m_strMD5); } else { // 有一种可能触发的情况: CheckResVersion有2次 一次版本文件的Check,一次Res内容的Check. // 如果 第一次版本文件的流程结束后,kv.Key没有更新(从Dic中移除),就会出现这个Log. // 表示,这个版本文件 没有更新成功。 or 服务器的版本文件中存在这个 版本.json 但是客户端代码里的 json列表里面没有这个文件; Debug.LogError("WWWDownLoaderConfig CheckResVersion, m_dicUpdateRes ContainsKey " + kv.Key); } } } }
/// <summary> /// 解析客户端资源MD5配置; /// </summary> static public void ParseServerResourcesConfig(string strBelongConfig, string strData) { if (string.IsNullOrEmpty(strData)) { Debug.LogError("WWWDownLoaderManage ParseServerResourcesConfig,Config Data can not be null"); return; } KeyValuePairConfigHelper kvpHelper = new KeyValuePairConfigHelper(); kvpHelper.LoadConfig(strData, CommonValue.ResDir + strBelongConfig); if (kvpHelper.SelectHeadNode()) { while (true) { DownLoadAssetInfo downLoadInfo = new DownLoadAssetInfo(); downLoadInfo.m_strName = kvpHelper.GetNodeKey(); downLoadInfo.m_strMD5 = kvpHelper.GetNodeMD5(); downLoadInfo.m_nSize = Convert.ToInt64(kvpHelper.GetNodeSize()); downLoadInfo.m_strBelongConfig = strBelongConfig; if (m_dicDownLoadInfo.ContainsKey(downLoadInfo.m_strName)) { Debug.LogError("WWWDownLoaderManage ParseServerJson,Same Key : " + downLoadInfo.m_strName); } else { m_dicDownLoadInfo.Add(downLoadInfo.m_strName, downLoadInfo); } if (!kvpHelper.SelectNextNode()) { break;//结束读取循环; } } } }