static void pack_all(BuildTarget buildTarget) { XPack pack = new XPack(); pack.setInfo(buildTarget); try { System.IO.Directory.Delete(pack.targetDir, true); } catch (System.Exception e) { XDebug.LogError(e.Message); } XDebug.Log("开始打包"); foreach (var item in instance._packItems) { if (item.type == XPackItem.XPackType.File) { string path = item.path; pack.pack(path); } else if (item.type == XPackItem.XPackType.DirFiles) { pack.packdirfiles(item.path, item.searchPattern, item.searchOption); } else if (item.type == XPackItem.XPackType.Dir) { pack.packdir(item.path, item.searchPattern, item.searchOption); } } pack.packluadir("lua/", luaJit); AssetBundleManifest manifest = pack.packAll(); XPackInfo info = new XPackInfo(); info.parseManifest(manifest, pack.targetDir); info._version = version; info._firstVersion = version; info.saveFile(pack.targetDir + "Assets/version.json"); XVer ver = new XVer { ver = version, ab = pack.getWebDir(webPublishUrl), remoteLogUrl = remoteLogURL, isRemoteLog = isRemoteLog }; ver.saveFile(pack.targetDir + "Assets/ver.json"); XDebug.Log("打包结束"); }
// 更新流程 public IEnumerator updateVersion(string publishUrl) { // 转化下平台接口 publishUrl = getPlatformPublishUrl(publishUrl); // 切换进度条 XLoading.instance.beginShow(0, this); string urlver = XUtil.getUrl(publishUrl, "ver.json"); WWW wwwver = new WWW(urlver); _www = wwwver; _wwwinfo = "获取" + urlver + "中"; yield return(wwwver); XVer ver = new XVer(); if (!string.IsNullOrEmpty(wwwver.error) || !ver.load(wwwver.text)) { XDebug.LogError("远程版本文件" + urlver + wwwver.error); wwwver.Dispose(); _www = null; _status = XUpdateStatus.FAIL; yield break; } wwwver.Dispose(); XDebug.Log("更新开始远程版本号:v" + ver.ver + "当前版本号:v" + XLoad.instance.localver); if (ver.ver != XLoad.instance.localver) { string urlversion = XUtil.getUrl(ver.ab, "v" + ver.ver + "/assets/version.json"); WWW wwwWebInfo = new WWW(urlversion); _www = wwwWebInfo; _wwwinfo = "获取" + urlversion + "中"; yield return(wwwWebInfo); XPackInfo webInfo = new XPackInfo(); if (!string.IsNullOrEmpty(wwwWebInfo.error) || !webInfo.load(wwwWebInfo.text)) { XDebug.LogError("远程版本文件" + urlver + wwwWebInfo.error); wwwWebInfo.Dispose(); _www = null; _status = XUpdateStatus.FAIL; yield break; } wwwWebInfo.Dispose(); Dictionary <string, XBundleInfo> modify = XLoad.instance._info.compareWebList(webInfo); uint allsize = 0; int filecount = modify.Count; foreach (var bd in modify) { allsize += (uint)(bd.Value.fileSize); } if (filecount <= 0) { XDebug.Log("文件一样无需更新修改版本号"); XLoad.instance._info._version = ver.ver; // 保存文件 XLoad.instance._info.saveFile(XLoad.getABDataWritePath("assets/version.json")); _status = XUpdateStatus.SUCESS; // todo 修改版本号 yield break; } XDebug.Log(string.Format("一共{0}个文件,大小需要更新{1}", filecount, XUtil.getSizeString(allsize))); // 更新目录 this.oldver = XLoad.instance.localver; this.newver = ver.ver; string updateDirName = getUpdateDirName(); string updateFileName = getUpdateFileName("update.json"); if (XUtil.isExistDirectory(updateDirName) && XUtil.isExistFile(updateFileName)) { if (!loadFile(updateFileName)) { alreadyDownloadDict.Clear(); XUtil.clearDirectory(updateDirName); } } int fileno = 0; foreach (var bd in modify) { fileno++; string ufilename = getUpdateFileName(bd.Key, bd.Value.isDirectory); if (alreadyDownloadDict.ContainsKey(bd.Key)) { XBundleInfo bundleInfo = alreadyDownloadDict[bd.Key]; if (bundleInfo.fileSize == bd.Value.fileSize && bundleInfo.hash == bd.Value.hash && XUtil.isExistFile(ufilename)) { XDebug.Log("文件已下载完毕,跳过" + ufilename); continue; } } if (XUtil.isExistFile(ufilename)) { XUtil.deleteFile(ufilename); } string webufile = getUpdateWebName(ver.ab, "v" + ver.ver + "/" + bd.Key, bd.Value.isDirectory); WWW wwwufile = new WWW(webufile); _www = wwwufile; _wwwinfo = string.Format("下载({0}/{1}){2}", fileno, filecount, bd.Key); yield return(wwwufile); if (!string.IsNullOrEmpty(wwwufile.error)) { XDebug.LogError("远程文件" + webufile + wwwufile.error); wwwufile.Dispose(); _www = null; _status = XUpdateStatus.FAIL; yield break; } if (!XUtil.writeFileAllBytes(ufilename, wwwufile.bytes)) { XDebug.LogError("写入文件失败" + ufilename); wwwufile.Dispose(); _www = null; _status = XUpdateStatus.FAIL; yield break; } alreadyDownloadDict[bd.Key] = bd.Value; // 保存一下记录 saveFile(updateFileName); wwwufile.Dispose(); _www = null; } // 已经成功了,拷贝文件到目标文件 _wwwinfo = "拷贝文件中"; foreach (var bd in modify) { string ufilename = getUpdateFileName(bd.Key, bd.Value.isDirectory); string dfilename = XLoad.getABDataWritePath(bd.Key, bd.Value.isDirectory); if (!XUtil.copyFile(ufilename, dfilename)) { XDebug.LogError("拷贝文件失败" + ufilename); _status = XUpdateStatus.FAIL; break; } XLoad.instance._info.addBundle(bd.Key, bd.Value); } _wwwinfo = "重新生成版本文件"; XLoad.instance._info.callDependAllSize(); // 变更版本 XLoad.instance._info._version = ver.ver; // 保存文件 if (!XLoad.instance._info.saveFile(XLoad.getABDataWritePath("assets/version.json"))) { _status = XUpdateStatus.FAIL; yield break; } _status = XUpdateStatus.SUCESS; } else { // XDebug.Log("版本一致没有什么不同无需更新"); _status = XUpdateStatus.SUCESS; } }