public static void BuildResIndex() { string resPath = Application.streamingAssetsPath + "/Android/"; ///----------------------创建文件列表----------------------- string newFilePath = Application.streamingAssetsPath + "/resIndex.txt"; if (File.Exists(newFilePath)) { File.Delete(newFilePath); } files = ZFileUtil.GetAllFiles(resPath); FileStream fs = new FileStream(newFilePath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < files.Count; i++) { string file = files[i]; string ext = Path.GetExtension(file); if (file.EndsWith(".meta") || file.Contains(".DS_Store")) { continue; } string md5 = Util.md5file(file); string value = file.Replace(resPath, string.Empty); sw.WriteLine(value + "|" + md5); } sw.Close(); fs.Close(); Debug.Log("生成resIndex完毕!"); }
/// <summary> /// 复制版本信息到对应的路径 /// </summary> /// <param name="path"></param> public static void CopyVersionInfoToTarget(string tarPath) { string sourcePath = Application.streamingAssetsPath; Directory.CreateDirectory(tarPath); List <string> files = ZFileUtil.GetAllFiles(sourcePath); //获取所有文件 //将文件移到对应目录 foreach (var file in files) { string fName = Path.GetFileName(file); //文件名 string pathComb = file.Replace(sourcePath, ""); string targetFolder = tarPath + "/" + Path.GetDirectoryName(file).Replace(sourcePath, ""); if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } File.Copy(file, targetFolder + "/" + fName, true); } }
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); }