/// <summary> /// 对比MD5 获取那些文件需要更新下载 /// </summary> protected virtual void CheckLocalAbundleNeedUpdateRecord() { Debug.LogInfor("GetNeedUpdateRecourRecord"); int totalNeedDownLoadSize = 0; m_IsDownLoadServerConfigure = true; HotAssetInfor checkABInfor = null; foreach (var item in m_ServerAssetRecord.m_AllAssetRecordsDic) { if (m_LocalAssetRecord != null && m_LocalAssetRecord.m_AllAssetRecordsDic.TryGetValue(item.Key, out checkABInfor)) { if (item.Value.m_MD5Code != checkABInfor.m_MD5Code) { // Debug.Log(" Need Update:: " + item.Key + " MD5=" + item.Value.m_MD5Code + ":::" + checkABInfor.m_MD5Code + " size==" + item.Value.m_ByteSize); RecordNeedUpdateAssetState(GetAssetDownLoadPath(item.Key), true); totalNeedDownLoadSize += item.Value.m_ByteSize; continue; } //资源MD5不一致 } else { //Debug.Log(" Need DownLoad:: " + item.Key+" size=="+item.Value.m_ByteSize); RecordNeedUpdateAssetState(GetAssetDownLoadPath(item.Key), true); totalNeedDownLoadSize += item.Value.m_ByteSize; }//新的资源 } m_IsCompleteMD5 = true; if (m_CompleteCheckAssetStateAct != null) { m_CompleteCheckAssetStateAct(totalNeedDownLoadSize); } }
/// <summary> /// 更新本地的配置文件 防止由于意外下载完成一半而导致部分 Asset 已经更新但是配置文件没有更新的问题 /// </summary> /// <param name="forceRecord">是否忽略下载的文件个数限制</param> protected virtual void UpdateLocalRecordConfigureText(bool forceRecord) { if (m_IsCompleteUpdate || m_AllCompleteDownLoadAssetDic.Count == 0) { //Debug.LogInfor("UpdateLocalRecordConfigureText No Need"); return; }//已经完成正常的更新流程 if (m_ServerAssetRecord == null) { Debug.LogError("UpdateLocalRecordConfigureText Fail ,Server Configure is Null"); return; }//服务器的配置文件不存在 if (forceRecord == false && m_TotalDownLoadAssetCount % S_DownLoadCoutToRecord != 0) { return; //避免频繁写入文件 } m_IsUpdateRecorded = true; if (m_LocalAssetRecord == null) { m_LocalAssetRecord = new HotAssetRecordInfor(); } #region 对比更新本地配置文件数据 HotAssetInfor bundleInfor = null; List <string> allNewRecordKeys = new List <string>(); foreach (var abundleRecord in m_AllCompleteDownLoadAssetDic) { if (abundleRecord.Value) { continue; //已经被记录到本地了 } if (m_LocalAssetRecord.m_AllAssetRecordsDic.TryGetValue(abundleRecord.Key, out bundleInfor)) { if (bundleInfor.m_MD5Code != m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key].m_MD5Code) { // Debug.LogInfor("Need Update AssetBundle :" + abundleRecord.Key); m_LocalAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key] = m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key]; allNewRecordKeys.Add(abundleRecord.Key); continue; } } else { //Debug.LogInfor("New Add AssetBundle :: " + abundleRecord.Key); if (m_ServerAssetRecord.m_AllAssetRecordsDic.ContainsKey(abundleRecord.Key)) { m_LocalAssetRecord.m_AllAssetRecordsDic.Add(abundleRecord.Key, m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key]); allNewRecordKeys.Add(abundleRecord.Key); } continue; } } for (int dex = 0; dex < allNewRecordKeys.Count; ++dex) { m_AllCompleteDownLoadAssetDic[allNewRecordKeys[dex]] = true; } allNewRecordKeys.Clear(); #endregion //***********更新本地配置文件 if (File.Exists(m_AssetSaveTopPath + m_AssetConfigurePath)) { File.Delete(m_AssetSaveTopPath + m_AssetConfigurePath); } File.WriteAllText(m_AssetSaveTopPath + m_AssetConfigurePath + ".txt", JsonMapper.ToJson(m_LocalAssetRecord)); //更新配置文件 }