/// <summary> /// 开始进行差异更新,下载当前最新版本的差异文件 /// </summary> IEnumerator StartDownDiffList(string version, int resId) { WWW remoteVersion = new WWW(AppConst.RemoteUpdatePath + resId + "/versionInfo.xml"); yield return(remoteVersion); if (remoteVersion.isDone) { if (string.IsNullOrEmpty(remoteVersion.error)) { remoteVersionVo = new VersionVo(remoteVersion.text, true); VersionVo curretnVo = GetCurrentVo(); remoteVersionVo.InitDifferDict(); //初始化所有版本的更新内容 Dictionary <string, VFStruct> updateDict = remoteVersionVo.GetDiffFromBeginVer(curretnVo.ResVersion); List <VFStruct> vfList = new List <VFStruct>(); foreach (KeyValuePair <string, VFStruct> dict in updateDict) { vfList.Add(dict.Value); } totalSize = remoteVersionVo.CalculateVFLSize(vfList); List <string> downedLs = GetDownedList(); //获取已经下载了的文件列表 //开始下载文件 for (int i = 0; i < vfList.Count; i++) { if (downedLs.Contains(vfList[i].file)) { Debug.Log("文件已下载:" + vfList[i].file); DownFileFinish(vfList[i]); continue; } else { StartDownFile(vfList[i]); while (!IsDownFinish(vfList[i].file)) { OnDownFinisCallByWWW(vfList[i]); yield return(new WaitForEndOfFrame()); } } } ResDownFinish(true); } else { Debug.LogError("下载更新列表失败:" + remoteVersion.error); ResDownFinish(false); } } }
private int tmpDownedCount = 0; //分帧计数器 /// <summary> /// 开始进行差异更新,下载当前最新版本的差异文件 /// </summary> IEnumerator StartDownDiffList() { WWW remoteVersion = new WWW(ApkInfoVo.GetRemoteVersionXmlPath); yield return(remoteVersion); if (remoteVersion.isDone) { if (string.IsNullOrEmpty(remoteVersion.error)) { remoteVersionVo = new VersionVo(remoteVersion.text, true); remoteVersionVo.InitDifferDict(); //初始化所有版本的更新内容 Dictionary <string, VFStruct> updateDict = remoteVersionVo.GetDiffFromBeginVer(currentVo.ResVersion); List <VFStruct> vfList = new List <VFStruct>(); foreach (KeyValuePair <string, VFStruct> dict in updateDict) { vfList.Add(dict.Value); } totalSize = remoteVersionVo.CalculateVFLSize(vfList); if (Application.internetReachability != NetworkReachability.ReachableViaCarrierDataNetwork) //如果是移动数据网络,则需要提示玩家 { Waiting(OnDownConfirm, "当前是移动数据网络,资源包大小为" + GetFormatFileSize(totalSize) + ",是否继续进行下载?"); } else { OnDownConfirm(); } } else { if (Application.internetReachability == NetworkReachability.NotReachable) { Waiting(CompareVersion, "网络连接失败,请检查网络"); } } } }
IEnumerator OnDowningFiles() { Dictionary <string, VFStruct> updateDict = remoteVersionVo.GetDiffFromBeginVer(currentVo.ResVersion); List <VFStruct> vfList = new List <VFStruct>(); foreach (KeyValuePair <string, VFStruct> dict in updateDict) { vfList.Add(dict.Value); } totalSize = remoteVersionVo.CalculateVFLSize(vfList); SetUpdateState(UpdateState.DOWN_RES_VERSION); SetProgress(0, totalSize); //开始下载文件 for (int i = 0; i < vfList.Count; i++) { string localFile = gameDataPath + vfList[i].file; //当前的本地文件 if (vfList[i].file == "versionInfo.xml") //忽略versionInfo.xml,不需要下载 { Debug.Log("文件已下载:" + vfList[i].file); DownFileFinish(vfList[i]); continue; } string fielDir = Path.GetDirectoryName(localFile); if (!Directory.Exists(fielDir)) { Directory.CreateDirectory(fielDir); } bool fileExist = File.Exists(localFile); //文件是否存在,如果不存在就必须要进行下载 if (fileExist) //如果文件存在,还需要判断md5 { string localMd5 = ZFileUtil.md5file(localFile); if (localMd5.Equals(vfList[i].md5)) { fileExist = true; } else { File.Delete(localFile); fileExist = false; } } if (!fileExist) //如果文件不存在,则需要进行下载 { StartDownFile(vfList[i]); while (!IsDownFinish(vfList[i].file)) { yield return(new WaitForEndOfFrame()); } DownFileFinish(vfList[i]); } else { Debug.Log("文件已下载:" + vfList[i].file); DownFileFinish(vfList[i]); tmpDownedCount++; //这里做个分帧循环,防止游戏检测重复已有资源的过程中导致卡顿 if (tmpDownedCount >= 20) { tmpDownedCount = 0; yield return(new WaitForEndOfFrame()); } } } ResDownFinish(true); }