private void UpdateResVer(string newVer) { if (!string.IsNullOrEmpty(newVer)) { this.curVerStr = newVer; } FileExt.WriteAllText(_resVerPath, curVerStr); }
public static void GenLastestPatchInfo(Version lastestVer) { //最新版本资源,无需生成补丁包 var patchInfo = new PatchInfo { version = lastestVer.ToString(), nextVer = lastestVer.ToString(), }; string jsonPath = string.Format("{0}/{1}_{2}.json", PatchExportPath, ResourceModuleConfig.PatchInfoPrefix, lastestVer); FileExt.SaveJsonObj(patchInfo, jsonPath, false, true); }
public static FileExt WriteFileAsync(string path, byte[] bytes, OnLoadFinish finishCallback, OnError errorCallback = null) { if (bytes == null) { return(null); } FileExt asynLoader = new FileExt(); asynLoader.AsyncBeginWriteFile(path, bytes, finishCallback, errorCallback); return(asynLoader); }
private void _DownloadRes(PatchInfo patchInfo) { var patchZipUrl = $"{this._remoteRoot}/{patchInfo.fileName}?{DateTime.Now.Ticks}"; var savePath = ResManager.DocumentDirPath + patchInfo.fileName; DownloadHandlerFileRange downloadHandler = null; WebRequestMgr.DownloadFile(patchZipUrl, savePath, (e) => { downloadHandler = e.downloadHandler as DownloadHandlerFileRange; onMsg("开始下载..."); onProgress(0f); }, (request) => { onMsg("解压补丁包..."); onProgress(0.8f); ZipTool.UncompressFile(savePath, ResManager.DocumentBundlePath); FileExt.DeleteFile(savePath); UpdateResVer(patchInfo.nextVer); needReload = true; //更新完毕再重新拉取最新patchInfo FetchPatchInfo(); }, (request) => { UpdateResVer(null); onMsg("下载补丁包失败,忽略更新"); onProgress(1f); onFinish(); }, (asyncOp) => { if (downloadHandler != null) { long totalSize = downloadHandler.FileSize; long curSize = downloadHandler.DownloadedSize; onMsg($"下载补丁包中...({curSize}/{totalSize})({downloadHandler.DownloadProgress * 100}%)"); } else { onMsg($"下载补丁包中...({asyncOp.webRequest.downloadedBytes}/{patchInfo.fileSize})"); } onProgress(asyncOp.progress * 0.8f); }); }
public static FileExt ReadFileAsync(string path, OnLoadFinish finishCallback, OnError errorCallback = null) { if (IsExist(path)) { FileExt asynLoader = new FileExt(); asynLoader.AsyncBeginReadFile(path, finishCallback, errorCallback); return(asynLoader); } if (errorCallback != null) { errorCallback(path, "Error: Could not find file " + path); } else { Debug.LogError("Error: Could not find file " + path); } return(null); }
public GamePatcher(string remoteRoot) { _platformName = ResManager.BuildPlatformName; _remoteRoot = remoteRoot + "/" + _platformName; _resVerPath = ResManager.DocumentDirPath + ResManager.BundlePathRoot + ResourceModuleConfig.ResVerFileName; if (ResManager.IsEdiotrMode) { var path = ResourceModuleConfig.BundleResoucesDir + "/" + ResManager.BuildPlatformName + "_" + ResourceModuleConfig.ResVerFileName; this.curVerStr = FileExt.ReadAllText(path); } else { var path = ResManager.BundlePathRoot + ResourceModuleConfig.ResVerFileName; this.curVerStr = ResManager.ReadAllText(path); } Debug.Log($"GamePatcher Init:\nresVer:{curVerStr}\nresVerPath:{_resVerPath}\nremoteRoot:{remoteRoot}"); }
private bool CheckPackageVer(Action onPackageReinstall) { var path = ResManager.BundlePathRoot + ResourceModuleConfig.ResVerFileName; var packageResVer = ResManager.LoadTextFromStreamingAssets(path); var resVerCode = new Version(this.curVerStr); var packageVerCode = new Version(packageResVer); Debug.Log($"__check_package_ver:{packageVerCode}, {resVerCode}"); if (packageVerCode > resVerCode) { Debug.Log($"!!!package_resVer > resVer:{packageVerCode} {resVerCode}"); FileExt.DeleteDirectory(ResManager.DocumentDirPath + this._platformName, true); if (onPackageReinstall != null) { onPackageReinstall(); } return(false); } return(true); }
public static bool GenPatchPackages(string oldResDir, string newResDir) { if (!Directory.Exists(oldResDir) || !Directory.Exists(newResDir)) { return(false); } var oldResVer = GetResVersion(oldResDir); var newResVer = GetResVersion(newResDir); if (oldResVer == null || newResVer == null) { Debug.LogError("资源版本信息加载失败"); return(false); } if (oldResVer > newResVer) { Debug.LogErrorFormat("oldResVer > newResVer:{0} {1}", oldResVer, newResVer); return(false); } else if (oldResVer == newResVer) { //最新版本资源,无需生成补丁包 GenLastestPatchInfo(newResVer); return(true); } string platformName = ResManager.GetBuildPlatformName(); var oldManifest = LoadAssetBundleManifest(oldResDir + "/" + platformName); var newManifest = LoadAssetBundleManifest(newResDir + "/" + platformName); var oldBundleNames = oldManifest.GetAllAssetBundles(); var newBundleNames = newManifest.GetAllAssetBundles(); var allNameSet = new HashSet <string>(oldBundleNames); allNameSet.UnionWith(newBundleNames); var patchedNames = new List <string>(); var sb = new StringBuilder(); int index = 0; foreach (var bundleName in allNameSet) { string oldResPath = oldResDir + "/" + bundleName; string newResPath = newResDir + "/" + bundleName; bool oldResExists = File.Exists(oldResPath); bool newResExists = File.Exists(newResPath); if (oldResExists && newResExists) { //新旧版本都存在的,读取Bundle的Hash和CRC判断 var oldHash = oldManifest.GetAssetBundleHash(bundleName); var newHash = newManifest.GetAssetBundleHash(bundleName); if (oldHash != newHash) { patchedNames.Add(bundleName); sb.AppendFormat("[Patched] 新旧Hash值不一致:{0}\n{1}\n{2}\n\n", bundleName, oldHash, newHash); } else { uint oldCRC; uint newCRC; BuildPipeline.GetCRCForAssetBundle(oldResPath, out oldCRC); BuildPipeline.GetCRCForAssetBundle(newResPath, out newCRC); if (oldCRC != newCRC) { patchedNames.Add(bundleName); sb.AppendFormat("[Patched] 新旧CRC值不一致:{0}\n{1}\n{2}\n\n", bundleName, oldCRC, newCRC); } else { sb.AppendFormat("[ignored] 资源未变更:{0}\n{1}\n{2}\n\n", bundleName, newHash, newCRC); } } } else if (!oldResExists && newResExists) { patchedNames.Add(bundleName); sb.AppendFormat("[Patched] 新增版本资源:{0}\n\n", bundleName); } else if (oldResExists) { sb.AppendFormat("[ignored] 新版本资源被移除或者BundleName变更:{0}\n\n", bundleName); } else { throw new Exception(string.Format("[Error] Backup目录文件被异常删除:{0}\n\n", newResPath)); } index++; EditorUtility.DisplayProgressBar("对比Bundle包版本信息", String.Format(" {0} / {1} ", index, allNameSet.Count), index / (float)allNameSet.Count); } Debug.Log(sb); if (patchedNames.Count > 0) { string patchDir = string.Format("{0}/patch_{1}_{2}", PatchExportPath, oldResVer, newResVer); EditorUtility.DisplayProgressBar("生成补丁包中", patchDir, 0); if (Directory.Exists(patchDir)) { Directory.Delete(patchDir, true); } //AssetBundleManifest也需要拷贝 Dictionary <string, string> fileHash = new Dictionary <string, string>(); patchedNames.Add(ResManager.GetBuildPlatformName()); foreach (var patchedName in patchedNames) { string patchFile = patchDir + "/" + patchedName; CopyFile(newResDir + "/" + patchedName, patchFile); fileHash[patchedName] = SHA256Hashing.HashFile(patchFile); } string zipFile = patchDir + ".zip"; ZipTool.CompressFolder(zipFile, patchDir); string zipHash = MD5Hashing.HashFile(zipFile); long fileSize = new FileInfo(zipFile).Length; string finalZipFile = string.Format("{0}-{1}.zip", patchDir, zipHash); if (File.Exists(finalZipFile)) { File.Delete(finalZipFile); } File.Move(zipFile, finalZipFile); var patchInfo = new PatchInfo { version = oldResVer.ToString(), nextVer = newResVer.ToString(), hash = zipHash, fileSize = fileSize, fileName = Path.GetFileName(finalZipFile), fileHash = fileHash, }; string jsonPath = string.Format("{0}/{1}_{2}.json", PatchExportPath, ResourceModuleConfig.PatchInfoPrefix, oldResVer); FileExt.SaveJsonObj(patchInfo, jsonPath, false, true); Directory.Delete(patchDir, true); Debug.Log("Build Patch Package:" + finalZipFile); } else { Debug.Log("Build Patch Package Skip!!!"); } EditorUtility.ClearProgressBar(); return(true); }