//下载 private int downloadRemoteXml(string remoteUrl, string storeDir) { UpdateLog.INFO_LOG("下载resourceVersionXml " + remoteUrl); int ret = CodeDefine.RET_SUCCESS; if (string.IsNullOrEmpty(_remoteXmlName)) { UpdateLog.ERROR_LOG("downloadResourceVersion(): resourceXmlName == null || \"\".Equals(resourceXmlName)"); ret = CodeDefine.RET_FAIL_RES_XML_PATH_ERROR; return(ret); } string savePath = (storeDir + "/" + _remoteXmlName).Replace("\\", "/").Replace("//", "/"); if (!Directory.Exists(storeDir)) { Directory.CreateDirectory(storeDir); } if (File.Exists(savePath)) { File.Delete(savePath); Thread.Sleep(1); } ret = _fileDownload.DownloadUseBackCdn(savePath, remoteUrl, 0, false); if (ret < CodeDefine.RET_SUCCESS) { UpdateLog.ERROR_LOG("downloadResourceVersion(): resource file is not exist or download fail!"); ret = CodeDefine.RET_FAIL_DOWNLOAD_RES_XML; } return(ret); }
public int DownloadBaseRes(bool downloadAll) { int ret = CodeDefine.RET_FAIL; _needDownloadList = needDownloadBaseResList(); if (_needDownloadList.Count == 0) { UpdateLog.INFO_LOG("do not need download base res, the version is the latest one. : version = " + _localBaseResVersion); return(CodeDefine.RET_SUCCESS); } int currentState = 0; for (int i = 0; i < _needDownloadList.Count; i++) { currentState = int.Parse(_needDownloadList[i].ToVersion); var toDownloadModel = _needDownloadList[i]; string resourceUrl = toDownloadModel.ResourceUrl.Replace("\\", "/"); string resName = resourceUrl.Substring(resourceUrl.LastIndexOf("/") + 1); string storePath = System.IO.Path.Combine(_storeDir, resName); long downloadedSize = 0; if (checkFinishDownload(storePath, toDownloadModel, out downloadedSize)) { ret = CodeDefine.RET_SUCCESS; UpdateLog.INFO_LOG("分段资源已经下载好了: " + storePath); continue; } long totalSize = long.Parse(toDownloadModel.FileSize); long mapSize = long.Parse(toDownloadModel.Map_size); long needDownloadSize = totalSize - downloadedSize; UpdateLog.INFO_LOG("UpdateFlow: 需要下载基础资源 " + storePath + "totalSize = " + totalSize + " needDownloadSize=" + needDownloadSize); //后台下载不做提示 if (!_backDownload && !Pause((int)totalSize)) { return(CodeDefine.RET_SKIP_BY_CANCEL); } ret = _fileDownload.DownloadUseBackCdn(storePath, toDownloadModel.ResourceUrl, (int)totalSize, true); //失败、非all、非后台下载都中断 if (ret <= CodeDefine.RET_FAIL || !downloadAll || !_backDownload) { break; } } UpdateLog.DEBUG_LOG("下载base资源---"); return(ret); }
public override int Work() { if (!CheckLastFlowResult()) { return(LastFlowResult); } if (!CurrentRemoteData.EnableForceUpdate) { UpdateLog.DEBUG_LOG("Do not support force update client, skip download!!!"); return(CodeDefine.RET_SUCCESS); } UpdateLog.DEBUG_LOG("开始下载客户端+++"); int ret = CodeDefine.RET_INIT; var localXml = LocalXml; var remoteData = CurrentRemoteData; string appVersion = localXml.LocalAppVersion; string clientUrl = remoteData.ClientUrl.Replace("\\", "/"); string clientName = clientUrl.Substring(clientUrl.LastIndexOf("/") + 1); string clientPath = System.IO.Path.Combine(_storeDir, clientName); //远端有更高客户端版本,则检查下载 if (remoteData.AppVersion.CompareTo(appVersion) > 0) { if (_customDownClientFunc != null) { UpdateLog.DEBUG_LOG("使用外部方法下载客户端"); _customDownClientFunc(remoteData.ClientUrl, _storeDir); ret = CodeDefine.RET_SUCCESS; callClientDownloadFinish(true); } else { if (_ios) { callClientDownloadFinish(true); return(CodeDefine.RET_SKIP_BY_DOWNLOAD_APP); } int appSize = int.Parse(remoteData.AppSize); //下载前提醒,如果取消则直接退出当前流程 if (!Pause(appSize)) { return(CodeDefine.RET_SKIP_BY_CANCEL); } ApkStorePath = clientPath; ret = _fileDownload.DownloadUseBackCdn(clientPath, clientUrl, appSize, true); FileInfo clientFile = new FileInfo(clientPath); if (ret >= CodeDefine.RET_SUCCESS && clientFile.Length < appSize) { ret = CodeDefine.RET_FAIL_EXCEPTION_DOWNLOAD; UpdateLog.ERROR_LOG("download Client: size is not correct: " + clientFile.Length + " -> " + appSize); } callClientDownloadFinish(ret >= CodeDefine.RET_SUCCESS); } //下载成功则跳过后续流程 if (ret == CodeDefine.RET_SUCCESS) { ret = CodeDefine.RET_SKIP_BY_DOWNLOAD_APP; } UpdateLog.DEBUG_LOG("下载客户端结束"); } else { if (File.Exists(clientPath)) { File.Delete(clientPath); UpdateLog.DEBUG_LOG("删除已下载好的客户端!!!"); } ret = CodeDefine.RET_SUCCESS; } UpdateLog.DEBUG_LOG("开始下载客户端---"); return(ret); }