private void TryAddDownFile(AssetMd5FileInfo info) { if (m_downAssetMd5Dict.ContainsKey(info.m_md5FilePath)) { BLogger.Warning("file[{0}] has exist in new asset", info.m_md5FilePath); } else { m_downAssetMd5Dict.Add(info.m_md5FilePath, info); } }
bool IsNeedUpdate(AssetMd5FileInfo newInfo) { //新增加的文件 if (!m_localAssetMd5Dict.ContainsKey(newInfo.m_md5FilePath)) { return(true); } //已经存在的,比较md5文件 AssetMd5FileInfo existFileInfo = m_localAssetMd5Dict[newInfo.m_md5FilePath]; if (existFileInfo.m_md5Content != newInfo.m_md5Content || existFileInfo.m_compress != newInfo.m_compress) { return(true); } return(false); }
public IEnumerator DownloadLatestIndex(string urlPath) { //清理数据 m_downIndexList.Clear(); m_downAssetMd5Dict.Clear(); m_latestAssetMd5Dict.Clear(); //清理文件 ReleaseUtil.DeleteFolder(downTempDir); //md5索引文件的总表 string urlMd5Root = urlPath + "/" + AssetBundleUtil.MD5HASH_FILE_ROOT_NAME; BLogger.Info("DownloadLatestIndex:{0}", urlMd5Root); WWW wwwRoot = new WWW(urlMd5Root); yield return(wwwRoot); if (wwwRoot.error != null) { BLogger.Warning("www request failed, Url:{0}, error:{1}", urlMd5Root, wwwRoot.error); m_error = String.Format(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_READ_LOCAL_FAILED, 1, wwwRoot.error)); wwwRoot.Dispose(); yield break; } List <AssetMd5FileInfo> listMd5Index = ParseAssetMd5List(urlMd5Root, wwwRoot.text); if (null == listMd5Index) { BLogger.Warning("ParseAssetMd5List, Url:{0}", urlMd5Root); m_error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_READ_LOCAL_FAILED_NO_ERRORCODE, 2); wwwRoot.Dispose(); yield break; } //临时目录写入root文件 bool ret = AssetBundleUtil.WriteToFile(downTempDir, AssetBundleUtil.MD5HASH_FILE_ROOT_NAME, wwwRoot.bytes); wwwRoot.Dispose(); if (!ret) { BLogger.Warning("Write root file failed"); m_error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_WRITE_FAILED, (downTempDir + AssetBundleUtil.MD5HASH_FILE_ROOT_NAME)); yield break; } ///记录最新的assetbundle所有信息 Dictionary <string, AssetMd5FileInfo> latestAssetInfo = m_latestAssetMd5Dict; Crc32 crc = new Crc32(); foreach (AssetMd5FileInfo indexFileInfo in listMd5Index) { BLogger.Info("new index file[{0}]", indexFileInfo.m_md5FilePath); //循环读取配置 //如果是内置资源的方式,则需要把所有的index文件给读取下来 if (IsNeedUpdate(indexFileInfo)) { m_downIndexList.Add(indexFileInfo.m_md5FilePath); string urlItem = urlPath + "/" + indexFileInfo.m_md5FilePath; WWW www = new WWW(urlItem); yield return(www); if (www.error != null) { BLogger.Warning("update [{0}] failed[{1}]", urlItem, www.error); m_error = String.Format("读取资源配置文件失败(3)[{0}]", www.error); yield break; } ret = AssetBundleUtil.WriteToFile(downTempDir, indexFileInfo.m_md5FilePath, www.bytes); if (!ret) { m_error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_WRITE_FAILED, (downTempDir + indexFileInfo.m_md5FilePath)); yield break; } //检查crc校验 if (indexFileInfo.m_crc != 0 && !CheckFileCrc(crc, downTempDir + indexFileInfo.m_md5FilePath, indexFileInfo.m_crc)) { m_error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_CRC_CHECK_FAILED, (downTempDir + indexFileInfo.m_md5FilePath)); yield break; } BLogger.Info("check index crc ok, index file: " + indexFileInfo.m_md5FilePath + ",expcect: " + indexFileInfo.m_crc); indexFileInfo.m_downLoad = true; List <AssetMd5FileInfo> listAsset = ParseAssetMd5List(urlItem, www.text); if (null == listAsset) { yield break; } www.Dispose(); //增加到待更新列表中 for (int i = 0; i < listAsset.Count; i++) { AssetMd5FileInfo eachAsset = listAsset[i]; m_latestAssetMd5Dict.Add(eachAsset.m_md5FilePath, eachAsset); } } } }