/// <summary> /// 对比MD5 获取那些文件需要更新下载 /// </summary> protected virtual void CheckLocalAbundleNeedUpdateRecord() { Debug.LogInfor("GetNeedUpdateRecourRecord"); m_IsDownLoadServerConfigure = true; if (m_LocalAssetRecord == null || m_LocalAssetRecord.AllAssetRecordsDic.Count == 0) { foreach (var item in m_ServerAssetRecord.AllAssetRecordsDic) { RecordNeedUpdateAssetState(GetAssetDownLoadPath(item.Key), item.Value.m_ByteSize, true); TotalNeedDownLoadCount += item.Value.m_ByteSize; } } //第一次则全量更新 else { HotAssetBaseInfor checkABInfor = null; foreach (var item in m_ServerAssetRecord.AllAssetRecordsDic) { if (m_LocalAssetRecord.AllAssetRecordsDic.TryGetValue(item.Key, out checkABInfor) && (item.Value.m_MD5Code == checkABInfor.m_MD5Code)) { continue; } //资源的MD5 信息一致说明不需要更新 else { RecordNeedUpdateAssetState(GetAssetDownLoadPath(item.Key), item.Value.m_ByteSize, true); TotalNeedDownLoadCount += item.Value.m_ByteSize; } //记录需要下载更新的资源 } } //逐条比对 获取需要更新的资源列表 m_IsCompleteMD5 = true; Debug.LogInfor("TotalNeedDownLoadCount=" + TotalNeedDownLoadCount); if (m_CompleteCheckAssetStateAct != null) { m_CompleteCheckAssetStateAct(TotalNeedDownLoadCount); } }
/// <summary> /// 更新本地的配置文件 防止由于意外下载完成一半而导致部分 Asset 已经更新但是配置文件没有更新的问题 /// </summary> /// <param name="forceRecord">是否忽略下载的文件个数限制</param> protected virtual void UpdateLocalRecordConfigureText() { 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; }//服务器的配置文件不存在 m_IsUpdateRecorded = true; if (m_LocalAssetRecord == null) { m_LocalAssetRecord = new HotAssetBaseRecordInfor(); } #region 对比更新本地配置文件数据 HotAssetBaseInfor bundleInfor = null; List <string> allNewRecordKeys = new List <string>(); foreach (var abundleRecord in m_AllCompleteDownLoadAssetDic) { if (abundleRecord.Value) { continue; //已经被记录到本地了 } if (m_LocalAssetRecord.AllAssetRecordsDic.TryGetValue(abundleRecord.Key, out bundleInfor)) { if (bundleInfor.m_MD5Code != m_ServerAssetRecord.AllAssetRecordsDic[abundleRecord.Key].m_MD5Code) { // Debug.LogInfor("Need Update AssetBundle :" + abundleRecord.Key); m_LocalAssetRecord.AllAssetRecordsDic[abundleRecord.Key] = m_ServerAssetRecord.AllAssetRecordsDic[abundleRecord.Key]; allNewRecordKeys.Add(abundleRecord.Key); continue; } } else { //Debug.LogInfor("New Add AssetBundle :: " + abundleRecord.Key); if (m_ServerAssetRecord.AllAssetRecordsDic.ContainsKey(abundleRecord.Key)) { m_LocalAssetRecord.AllAssetRecordsDic.Add(abundleRecord.Key, m_ServerAssetRecord.AllAssetRecordsDic[abundleRecord.Key]); allNewRecordKeys.Add(abundleRecord.Key); } continue; } } for (int dex = 0; dex < allNewRecordKeys.Count; ++dex) { m_AllCompleteDownLoadAssetDic[allNewRecordKeys[dex]] = true; } allNewRecordKeys.Clear(); #endregion string localConfigureFilePath = m_LocalAssetConfigurePath + m_LocalAssetConfigureFileName; Debug.LogEditorInfor("localConfigureFilePath=" + localConfigureFilePath); UpdateLocalRecordFile(localConfigureFilePath, JsonMapper.ToJson(m_LocalAssetRecord)); }