private WebFileRequest CreateDownloader(PatchBundle element) { // 注意:资源版本号只用于确定下载路径 string url = _patcher.GetWebDownloadURL(element.Version.ToString(), element.Hash); string savePath = PatchHelper.MakeSandboxCacheFilePath(element.Hash); FileUtility.CreateFileDirectory(savePath); // 创建下载器 MotionLog.Log($"Beginning to download web file : {url}"); WebFileRequest download = new WebFileRequest(url, savePath); download.UserData = element; download.DownLoad(); return(download); }
private IEnumerator Download() { // 从网络上解析最新的补丁清单 int newResourceVersion = _patcher.RequestedResourceVersion; string url = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestBytesFileName); WebDataRequest download = new WebDataRequest(url); yield return(download.DownLoad()); // Check fatal if (download.States != EWebRequestStates.Success) { download.Dispose(); PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg(); yield break; } MotionLog.Log($"Parse web patch manifest."); _patcher.ParseWebPatchManifest(download.GetData()); download.Dispose(); _patcher.SwitchNext(); }
private IEnumerator Download() { // 注意:等所有文件下载完毕后,下载并替换补丁清单 int newResourceVersion = _patcher.RequestedResourceVersion; string url = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestFileName); string savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName); WebFileRequest download = new WebFileRequest(url, savePath); yield return(download.DownLoad()); if (download.States != EWebRequestStates.Success) { download.Dispose(); PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg(); yield break; } else { PatchHelper.Log(ELogLevel.Log, "Web patch manifest is download."); download.Dispose(); _patcher.SwitchNext(); } }
private IEnumerator Download() { // 从远端下载最新的补丁清单 int newResourceVersion = _patcher.RequestedResourceVersion; string url = _patcher.GetWebDownloadURL(newResourceVersion.ToString(), PatchDefine.PatchManifestFileName); WebGetRequest download = new WebGetRequest(url); download.DownLoad(); yield return(download); // Check fatal if (download.HasError()) { download.ReportError(); download.Dispose(); PatchEventDispatcher.SendWebPatchManifestDownloadFailedMsg(); yield break; } // 解析远端下载的补丁清单 _patcher.ParseRemotePatchManifest(download.GetText()); download.Dispose(); _patcher.SwitchNext(); }
private IEnumerator Download() { // 注意:开发者需要在下载前检测磁盘空间不足 // 计算下载文件的总大小 int totalDownloadCount = _patcher.DownloadList.Count; long totalDownloadSizeBytes = 0; foreach (var element in _patcher.DownloadList) { totalDownloadSizeBytes += element.SizeBytes; } // 开始下载列表里的所有资源 PatchHelper.Log(ELogLevel.Log, $"Begine download web files : {_patcher.DownloadList.Count}"); long currentDownloadSizeBytes = 0; int currentDownloadCount = 0; foreach (var element in _patcher.DownloadList) { // 注意:资源版本号只用于确定下载路径 string url = _patcher.GetWebDownloadURL(element.Version.ToString(), element.Name); string savePath = AssetPathHelper.MakePersistentLoadPath(element.Name); element.SavePath = savePath; FileUtility.CreateFileDirectory(savePath); // 创建下载器 WebFileRequest download = new WebFileRequest(url, savePath); yield return(download.DownLoad()); //文件依次加载(在一个文件加载完毕后加载下一个) PatchHelper.Log(ELogLevel.Log, $"Web file is download : {savePath}"); // 检测是否下载失败 if (download.States != EWebRequestStates.Success) { PatchEventDispatcher.SendWebFileDownloadFailedMsg(url, element.Name); yield break; } // 立即释放加载器 download.Dispose(); currentDownloadCount++; currentDownloadSizeBytes += element.SizeBytes; PatchEventDispatcher.SendDownloadFilesProgressMsg(totalDownloadCount, currentDownloadCount, totalDownloadSizeBytes, currentDownloadSizeBytes); } // 验证下载文件的大小 if (_patcher.CheckLevel == ECheckLevel.CheckSize) { foreach (var element in _patcher.DownloadList) { long fileSize = FileUtility.GetFileSize(element.SavePath); if (fileSize != element.SizeBytes) { PatchHelper.Log(ELogLevel.Error, $"Web file size check failed : {element.Name}"); PatchEventDispatcher.SendWebFileCheckFailedMsg(element.Name); yield break; } } } // 验证下载文件的MD5 if (_patcher.CheckLevel == ECheckLevel.CheckMD5) { foreach (var element in _patcher.DownloadList) { string md5 = HashUtility.FileMD5(element.SavePath); if (md5 != element.MD5) { PatchHelper.Log(ELogLevel.Error, $"Web file md5 check failed : {element.Name}"); PatchEventDispatcher.SendWebFileCheckFailedMsg(element.Name); yield break; } } } // 最后清空下载列表 _patcher.DownloadList.Clear(); _patcher.SwitchNext(); }