コード例 #1
0
        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);
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        public IEnumerator Download(ProcedureSystem system)
        {
            // 注意:等所有文件下载完毕后,再替换版本文件
            int            newResourceVersion = PatchManager.Instance.GameVersion.Revision;
            string         url      = PatchManager.MakeWebDownloadURL(newResourceVersion.ToString(), PatchDefine.StrPatchFileName);
            string         savePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.StrPatchFileName);
            WebFileRequest download = new WebFileRequest(url, savePath);

            yield return(download.DownLoad());

            if (download.States != EWebRequestStates.Succeed)
            {
                download.Dispose();
                system.Switch((int)EPatchStates.PatchError);
                yield break;
            }
            else
            {
                PatchManager.Log(ELogType.Log, "Download web files is finish.");
                download.Dispose();
                system.SwitchNext();
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        public override void Update()
        {
            // 如果资源文件加载完毕
            if (States == ELoaderStates.Success || States == ELoaderStates.Fail)
            {
                UpdateAllProvider();
                return;
            }

            if (States == ELoaderStates.None)
            {
                // 检测加载地址是否为空
                if (string.IsNullOrEmpty(BundleInfo.LocalPath))
                {
                    States = ELoaderStates.Fail;
                    return;
                }

                if (string.IsNullOrEmpty(BundleInfo.RemoteURL))
                {
                    States = ELoaderStates.CheckDepends;
                }
                else
                {
                    States = ELoaderStates.Download;
                }
            }

            // 1. 从服务器下载
            if (States == ELoaderStates.Download)
            {
                _downloader = new WebFileRequest(BundleInfo.RemoteURL, BundleInfo.LocalPath);
                _downloader.DownLoad();
                States = ELoaderStates.CheckDownload;
            }

            // 2. 检测服务器下载结果
            if (States == ELoaderStates.CheckDownload)
            {
                if (_downloader.IsDone() == false)
                {
                    return;
                }

                if (_downloader.HasError())
                {
                    _downloader.ReportError();
                    States = ELoaderStates.Fail;
                }
                else
                {
                    // 校验文件完整性
                    if (AssetSystem.BundleServices.CheckContentIntegrity(BundleInfo.BundleName) == false)
                    {
                        MotionLog.Error($"Check download content integrity is failed : {BundleInfo.BundleName}");
                        States = ELoaderStates.Fail;
                    }
                    else
                    {
                        States = ELoaderStates.CheckDepends;
                    }
                }

                // 释放网络资源下载器
                if (_downloader != null)
                {
                    _downloader.Dispose();
                    _downloader = null;
                }
            }

            // 3. 检测所有依赖完成状态
            if (States == ELoaderStates.CheckDepends)
            {
                foreach (var dpLoader in _depends)
                {
                    if (dpLoader.IsDone() == false)
                    {
                        return;
                    }
                }
                States = ELoaderStates.LoadFile;
            }

            // 4. 加载AssetBundle
            if (States == ELoaderStates.LoadFile)
            {
#if UNITY_EDITOR
                // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
                if (System.IO.File.Exists(BundleInfo.LocalPath) == false)
                {
                    MotionLog.Warning($"Not found assetBundle file : {BundleInfo.LocalPath}");
                    States = ELoaderStates.Fail;
                    return;
                }
#endif

                // Load assetBundle file
                if (BundleInfo.IsEncrypted)
                {
                    if (AssetSystem.DecryptServices == null)
                    {
                        throw new Exception($"{nameof(AssetBundleLoader)} need IDecryptServices : {BundleInfo.BundleName}");
                    }

                    EDecryptMethod decryptType = AssetSystem.DecryptServices.DecryptType;
                    if (decryptType == EDecryptMethod.GetDecryptOffset)
                    {
                        ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleInfo);
                        _cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath, 0, offset);
                    }
                    else if (decryptType == EDecryptMethod.GetDecryptBinary)
                    {
                        byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleInfo);
                        _cacheRequest = AssetBundle.LoadFromMemoryAsync(binary);
                    }
                    else
                    {
                        throw new NotImplementedException($"{decryptType}");
                    }
                }
                else
                {
                    _cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath);
                }
                States = ELoaderStates.CheckFile;
            }

            // 5. 检测AssetBundle加载结果
            if (States == ELoaderStates.CheckFile)
            {
                if (_cacheRequest.isDone == false)
                {
                    return;
                }
                CacheBundle = _cacheRequest.assetBundle;

                // Check error
                if (CacheBundle == null)
                {
                    MotionLog.Warning($"Failed to load assetBundle file : {BundleInfo.BundleName}");
                    States = ELoaderStates.Fail;
                }
                else
                {
                    States = ELoaderStates.Success;
                }
            }
        }
コード例 #6
0
        public IEnumerator Download(ProcedureSystem system)
        {
            // 检测磁盘空间不足
            // TODO 检测磁盘空间不足

            // 计算下载文件的总大小
            int  totalDownloadCount  = PatchManager.Instance.DownloadList.Count;
            long totalDownloadSizeKB = 0;

            foreach (var element in PatchManager.Instance.DownloadList)
            {
                totalDownloadSizeKB += element.SizeKB;
            }

            // 开始下载列表里的所有资源
            PatchManager.Log(ELogType.Log, $"Begine download web files : {PatchManager.Instance.DownloadList.Count}");
            long currentDownloadSizeKB = 0;
            int  currentDownloadCount  = 0;

            foreach (var element in PatchManager.Instance.DownloadList)
            {
                // 注意:资源版本号只用于确定下载路径
                string url      = PatchManager.MakeWebDownloadURL(element.Version.ToString(), element.Name);
                string savePath = AssetPathHelper.MakePersistentLoadPath(element.Name);
                element.SavePath = savePath;
                PatchManager.CreateFileDirectory(savePath);

                // 创建下载器
                WebFileRequest download = new WebFileRequest(url, savePath);
                yield return(download.DownLoad());                //文件依次加载(在一个文件加载完毕后加载下一个)

                PatchManager.Log(ELogType.Log, $"Web file is done : {url}");

                // 检测是否下载失败
                if (download.States != EWebRequestStates.Succeed)
                {
                    _system.Switch((int)EPatchStates.PatchError);
                    PatchManager.SendWebFileDownloadFailedMsg(url);
                    yield break;
                }

                // 立即释放加载器
                download.Dispose();
                currentDownloadCount++;
                currentDownloadSizeKB += element.SizeKB;
                PatchManager.SendDownloadFilesProgressMsg(totalDownloadCount, currentDownloadCount, totalDownloadSizeKB, currentDownloadSizeKB);
            }

            // 验证下载文件的MD5
            foreach (var element in PatchManager.Instance.DownloadList)
            {
                string md5 = HashUtility.FileMD5(element.SavePath);
                if (md5 != element.MD5)
                {
                    _system.Switch((int)EPatchStates.PatchError);
                    PatchManager.Log(ELogType.Error, $"Web file md5 verification error : {element.Name}");
                    PatchManager.SendWebFileMD5VerifyFailedMsg(element.Name);
                    yield break;
                }
            }

            // 最后清空下载列表
            PatchManager.Instance.DownloadList.Clear();
            _system.SwitchNext();
        }