public void OnUpdateFinish(IUpdateExecutor executor, UpdateInfo.ResInfo info, List <string> fileList, bool isNeedReload = false) { Debug.Log("update " + info.type + " finished, progress:" + (m_currIndex + 1) + "/" + m_updateCount); if (!m_isReload && isNeedReload) { m_isReload = true; } //flag file existed m_context.ResMd5Mgr.Set(info, true, fileList); m_currIndex++; bool allFinished = ((m_currIndex) == m_updateCount); if (allFinished) { //Version.Instance.SetVersion(VersionType.Resource, info.versionInfo.resVersion); if (m_updatefinishCB != null) { m_updatefinishCB(VersionType.Resource, info.versionInfo.resVersion); } m_delegate.OnUpdateSuccessed(GameUpdateSys.UpdateResult.Success, m_isReload); _UpdateFinished(); } }
protected virtual string GetDownloadUrl(UpdateInfo.ResInfo info, GameUpdateSys.UpdateContext context) { string version = context.BaseVersion; if (info.versionInfo != null && !string.IsNullOrEmpty(info.versionInfo.resVersion)) { version = info.versionInfo.downloadVersion; } var url = ""; if (!string.IsNullOrEmpty(info.packageName)) { url = GameUpdateSys.UPDATE_URL + version + "/" + ((int)info.versionInfo.basePlatform) + "/" + info.versionInfo.resVersion + "/" + info.packageName + ".zip"; } else { url = GameUpdateSys.UPDATE_URL + version + "/" + ((int)info.versionInfo.basePlatform) + "/" + info.versionInfo.resVersion + "/" + info.type + ".zip"; } if (!GameUpdateSys.RELEASE) { url += "?" + Random.Range(0, 9999999); } return(url); }
public void CheckNeedUpdate(List <UpdateInfo.ResInfo> list, UpdateInfo.ResInfo info) { if (string.IsNullOrEmpty(info.type)) { return; } list.Add(info); }
public void AddResInfo(UpdateInfo.ResInfo info) { if (ResInfoList == null) { ResInfoList = new List <UpdateInfo.ResInfo>(); } ResInfoList.Add(info); }
protected virtual string GetDownloadPath(UpdateInfo.ResInfo info, GameUpdateSys.UpdateContext context) { if (!string.IsNullOrEmpty(info.packageName)) { return(DWTools.CachePath + "/" + info.packageName + ".zip"); } else { return(DWTools.CachePath + "/" + info.type + ".zip"); } }
private void AddResInfo(List <UpdateInfo.ResInfo> list, UpdateInfo.ResInfo info) { //TODO Filter logic here if (m_filter != null) { m_filter.CheckNeedUpdate(list, info); } else { list.Add(info); } }
public void UpdateStateNotice(UpdateInfo.ResInfo res, UpdateProgressInfo.Phase downloadState, int totalSize, int curSize) { var data = new UpdateProgressInfo(); data.totalCount = m_updateCount; data.curIndex = m_currIndex; data.totalSize = totalSize; data.curSize = curSize; data.phase = downloadState; data.resInfo = res; if (m_delegate != null) { m_delegate.OnUpdateProgress(data); } }
/// <summary> /// 更多的检测 因为文件放进来Cache 更容易被删掉 /// </summary> /// <param name="resInfo"></param> /// <returns></returns> public bool IsResourceExisted(UpdateInfo.ResInfo resInfo) { var key = GetKeyForRes(resInfo); var zipInfo = Get(key); if (!DWTools.JsonDataContainsKey(zipInfo, "md5")) { return(false); } if (!resInfo.md5.Equals(zipInfo["md5"].ToString())) { return(false); } if (!DWTools.JsonDataContainsKey(zipInfo, "fileList")) { return(false); } var fileList = zipInfo["fileList"]; JsonData data = JsonMapper.ToObject(fileList.ToString()); if (data.IsArray) { for (int fi = 0; fi < data.Count; fi++) { var str = data[fi].ToString(); //如果这个更新需要的文件不存在 那么就需要更新 if (!File.Exists(str)) { return(false); } } } else { return(true); } return(true); }
public void OnUpdateError(IUpdateExecutor executor, ErrorCode errCode, UpdateInfo.ResInfo info) { m_delegate.OnUpdateError(errCode); _UpdateFinished(); }
public IEnumerator GetUpdateCoroutine(UpdateInfo.ResInfo info, GameUpdateSys.UpdateContext context, IUpdateExecutorDelegate del) { Debug.LogWarning("begin update:" + GetUpdateType()); if (info == null) { Debug.LogError("info is null"); del.OnUpdateError(this, GameUpdateSys.ErrorCode.InvalidConfig, info); yield break; } if (string.IsNullOrEmpty(info.md5) || info.size <= 0) { Debug.LogError("invalid res update info"); del.OnUpdateError(this, GameUpdateSys.ErrorCode.InvalidConfig, info); } bool updateSucc = false; var path = GetDownloadPath(info, context); var url = GetDownloadUrl(info, context); int retryCount = 0; List <string> fileList = null; bool downLoadSucc = false; while (retryCount++ < context.DownloadRetryMaxCount && !downLoadSucc) { Debug.Log("download to path:" + path); Debug.Log("download from url:" + url); CDownLoadFile downLoadFile = new CDownLoadFile(path, url, info.md5); if (del != null) { del.UpdateStateNotice(info, UpdateProgressInfo.Phase.Downloading, (int)info.size, 0); } ThreadPool.QueueUserWorkItem((object state) => { downLoadFile.BeginDownLoad(); }); while (downLoadFile.m_downLoadStatus == CDownLoadFile.EnumDownLoadStatus.EDLS_NONE) { if (del != null) { del.UpdateStateNotice(info, UpdateProgressInfo.Phase.Downloading, (int)info.size, (int)downLoadFile.m_hasDownLoadBits); } yield return(null); } if (downLoadFile.m_downLoadStatus != CDownLoadFile.EnumDownLoadStatus.EDLS_SUCCESS) { Debug.LogError("download error:" + downLoadFile.m_downLoadStatus); if (retryCount >= context.DownloadRetryMaxCount) { del.OnUpdateError(this, GameUpdateSys.ErrorCode.DownloadResourceFailed, info); yield break; } else { Debug.Log("retry download"); } continue; } else { downLoadSucc = true; } var unzipDir = GetUnzipDir(); Debug.Log("begin unzip, to dir:" + unzipDir); CUnzipFile unzip = new CUnzipFile(unzipDir, path, downLoadFile.m_hasDownLoadBits); if (del != null) { del.UpdateStateNotice(info, UpdateProgressInfo.Phase.Unpacking, (int)downLoadFile.m_hasDownLoadBits, 0); } ThreadPool.QueueUserWorkItem((object state) => { unzip.BeginUnzip(); }); while (unzip.m_unzipState == CUnzipFile.EnumUnzipStatus.EUS_NONE) { //TODO notify progress if (del != null) { del.UpdateStateNotice(info, UpdateProgressInfo.Phase.Unpacking, (int)downLoadFile.m_hasDownLoadBits, (int)(unzip.m_rate * downLoadFile.m_hasDownLoadBits)); } yield return(null); } switch (unzip.m_unzipState) { case CUnzipFile.EnumUnzipStatus.EUS_SUCCESS: { Debug.Log("unzip successed"); updateSucc = true; fileList = unzip.m_unpackFileList; break; } default: updateSucc = false; break; } } if (updateSucc) { del.OnUpdateFinish(this, info, fileList, this.IsNeedReloadDLL()); } else { del.OnUpdateError(this, GameUpdateSys.ErrorCode.DownloadResourceFailed, info); } }
public void Set(UpdateInfo.ResInfo info, bool autoSave = true, List <string> fileList = null) { var key = GetKeyForRes(info); Set(key, info.md5, autoSave, fileList); }
protected virtual string GetKeyForRes(UpdateInfo.ResInfo resInfo) { return(resInfo.versionInfo.resVersion + "-" + resInfo.type); }