public IEnumerator CheckUpdate(bool repairClient, StartupUI startUI) { m_svrVerInfo = null; //获取当前的版本 string fullUrl = DPlatform.GetCheckVersionUrl(repairClient); BLogger.Info("version check:{0}", fullUrl); WWWEx wwwEx = WWWEx.Init(15f); yield return(StartCoroutine(wwwEx.Request(fullUrl))); if (wwwEx.isTimeOut) { AssetVersionMgr.Instance.error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_TIMEOUT); BLogger.Warning("url reueqest timeout: {0}", fullUrl); yield break; } WWW www = wwwEx.result; if (www.error != null) { BLogger.Warning("check version update error: " + www.error); string wwwerror = www.error; www.Dispose(); AssetVersionMgr.Instance.error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_WWW_ERROR, wwwerror); yield break; } if (startUI != null) { startUI.ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_GAME_ETNERING)); } Dictionary <string, object> verJson = (Dictionary <string, object>)MiniJSON.Json.Deserialize(www.text); if (verJson == null || verJson.Count == 0) { BLogger.Warning("parse version json data error: {0}", www.text); AssetVersionMgr.Instance.error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_JSON_ERROR, 1); // DBugly.ReportException("json data error", "request error url:" + fullUrl, "parse version json data error: " + www.text); www.Dispose(); yield break; } try { m_svrVerInfo = ParseVerInfo(verJson); } catch (Exception e) { BLogger.Warning("parse ver info failed:{0}", e.ToString()); DBugly.ReportException("parse ver info", "request error url:" + fullUrl, "parse ver info failed: " + e.ToString()); AssetVersionMgr.Instance.error = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECK_UPDATE_JSON_ERROR, 2); m_svrVerInfo = null; } www.Dispose(); }
public IEnumerator BeginUpdateAsset(string urlPath, StartupUI ui) { yield return(null); float downLoadFileCnt = 0; float downLoadSize = 0; float totalSize = GetToUpdateSize(); if (totalSize < 1) { totalSize = 1; } List <string> listDownloadFile = new List <string>(); string downCompressDir = GetDownloadCompressDir();//downTempDir + "../cdowndir/"; Crc32 crc = new Crc32(); ui.ShowProgressBar(true); ui.ShowDownInfo(downLoadSize, totalSize, true, 0, true); foreach (KeyValuePair <string, AssetMd5FileInfo> kv in m_downAssetMd5Dict) { // showInfo("正在下载资源包: " + string.Format("({0})", AssetUpdater.Instance.NewVersion), null); ui.ShowDownInfo(downLoadSize, totalSize, true, 0); string destFilePath = downTempDir + kv.Key; ///检查文件是否已经下载到本地了 if (kv.Value.m_crc > 0 && AssetBundleUtil.IsFileExist(destFilePath)) { if (CheckFileCrc(crc, destFilePath, kv.Value.m_crc)) { listDownloadFile.Add(kv.Key); kv.Value.m_downLoad = true; downLoadFileCnt++; downLoadSize += kv.Value.m_contentSize; ui.SetProgress((uint)downLoadSize, (uint)totalSize); ui.ShowDownInfo(downLoadSize, totalSize, true, 0); continue; } } ui.BeginDownload(); //begin download string url = urlPath + "/" + kv.Key; WWW www = new WWW(url); yield return(www); //有错误,返回失败 if (www.error != null) { m_error = string.Format(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_ASSET_DOWNLOAD_FAILED, www.error, kv.Key)); BLogger.Warning("download file:{0} failed:{1}", kv.Key, www.error); yield break; } if (!ExtractAndWriteDownFile(downCompressDir, downTempDir, kv.Key, www.bytes)) { string text = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_DECOMPRESS_FAILED); if (!string.IsNullOrEmpty(text)) { m_error = string.Format(text, kv.Key); } else { m_error = string.Format("解压文件{0}失败,请点击重试!", kv.Key); } yield break; } //比较下下载的文件crc,避免一些cdn不同步导致的下载不全的问题 if (kv.Value.m_crc > 0 && !CheckFileCrc(crc, downTempDir + kv.Key, kv.Value.m_crc)) { BLogger.Error("check file crc error: {0}", kv.Key); string text = StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_CHECKCRC_FAILED); if (!string.IsNullOrEmpty(text)) { m_error = string.Format(text, kv.Key); } else { m_error = string.Format("文件({0})校验错误,请点击重试!", kv.Key); } yield break; } listDownloadFile.Add(kv.Key); kv.Value.m_downLoad = true; downLoadSize += www.bytes.Length; ui.SetProgress((uint)downLoadSize, (uint)totalSize); downLoadFileCnt++; ui.ShowDownInfo(downLoadSize, totalSize, true, www.bytes.Length); www.Dispose(); } ui.ShowDownInfo(0, 0, false, 0); ///如果已经下载完了,那么开始copy到目标目录中 ///先copyindex 文件,md5最后copy foreach (string indexFile in m_downIndexList) { listDownloadFile.Add(indexFile); } listDownloadFile.Add(AssetBundleUtil.MD5HASH_FILE_ROOT_NAME); //开始copy数据 //uiSlider.gameObject.SetActive(false); //开始copy数据 string fromDir = downTempDir; string destDir = AssetBundleUtil.GetExternAssetBundleDir(); int copyDownFile = 0; foreach (string downFile in listDownloadFile) { byte[] content = AssetBundleUtil.ReadFile(fromDir + downFile); bool ret = AssetBundleUtil.WriteToFile(destDir, downFile, content); if (!ret) { m_error = "copy file failed: " + destDir + downFile; yield break; } int percent = copyDownFile * 100 / listDownloadFile.Count; copyDownFile++; ui.ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_ASSET_INSTALL_PROGRESS, percent)); ui.SetProgress((uint)copyDownFile * 100, (uint)listDownloadFile.Count); //判断资源是否是脚本文件 if (downFile.IndexOf(".dll.bytes") >= 0) { BLogger.Info("download script file: {0}", downFile); m_scriptUpdate = true; } yield return(null); } ui.ShowProgressBar(false); ui.ShowText(StartupTextConfigMgr.Instance.GetText(StartupTextDefine.ID_STARTUP_UPDATE_ASSET_SUCCESS)); }