예제 #1
0
        private bool CheckContentIntegrity(string hash, string crc, long size)
        {
            string filePath = PatchHelper.MakeSandboxCacheFilePath(hash);

            if (File.Exists(filePath) == false)
            {
                return(false);
            }

            // 校验沙盒里的补丁文件
            if (_verifyLevel == EVerifyLevel.Size)
            {
                long fileSize = FileUtility.GetFileSize(filePath);
                return(fileSize == size);
            }
            else if (_verifyLevel == EVerifyLevel.CRC)
            {
                string fileCRC = HashUtility.FileCRC32(filePath);
                return(fileCRC == crc);
            }
            else
            {
                throw new NotImplementedException(_verifyLevel.ToString());
            }
        }
예제 #2
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);
        }
예제 #3
0
        private WebFileRequest CreateDownloader(PatchBundle patchBundle)
        {
            // 注意:资源版本号只用于确定下载路径
            string mainURL     = _patcherMgr.GetPatchDownloadURL(patchBundle.Version, patchBundle.Hash);
            string fallbackURL = _patcherMgr.GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
            string savePath    = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);

            FileUtility.CreateFileDirectory(savePath);

            // 创建下载器
            MotionLog.Log($"Beginning to download web file : {patchBundle.BundleName} URL : {mainURL}");
            WebFileRequest download = WebFileSystem.GetWebFileRequest(mainURL, fallbackURL, savePath, _failedTryAgain);

            download.UserData = patchBundle;
            return(download);
        }
예제 #4
0
        private bool CheckContentIntegrity(string md5, uint crc32, long size)
        {
            string filePath = PatchHelper.MakeSandboxCacheFilePath(md5);

            if (File.Exists(filePath) == false)
            {
                return(false);
            }

            // 校验沙盒里的补丁文件
            if (_verifyLevel == EVerifyLevel.Size)
            {
                long fileSize = FileUtility.GetFileSize(filePath);
                if (fileSize == size)
                {
                    return(true);
                }
            }
            else if (_verifyLevel == EVerifyLevel.MD5)
            {
                string fileHash = HashUtility.FileMD5(filePath);
                if (fileHash == md5)
                {
                    return(true);
                }
            }
            else if (_verifyLevel == EVerifyLevel.CRC32)
            {
                uint fileHash = HashUtility.FileCRC32(filePath);
                if (fileHash == crc32)
                {
                    return(true);
                }
            }
            else
            {
                throw new NotImplementedException(_verifyLevel.ToString());
            }
            return(false);
        }
예제 #5
0
        /// <summary>
        /// 获取AssetBundle的加载信息
        /// </summary>
        public AssetBundleInfo GetAssetBundleInfo(string bundleName)
        {
            if (_localPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle))
            {
                // 查询APP资源
                if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle appPatchBundle))
                {
                    if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash)
                    {
                        string          appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appPatchBundle.Hash);
                        AssetBundleInfo bundleInfo  = new AssetBundleInfo(bundleName, appLoadPath, appPatchBundle.Version, appPatchBundle.IsEncrypted);
                        return(bundleInfo);
                    }
                }

                // 查询缓存资源
                // 注意:如果沙盒内缓存文件不存在,那么将会从服务器下载
                string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
                if (_cache.Contains(patchBundle.Hash))
                {
                    AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, sandboxLoadPath, patchBundle.Version, patchBundle.IsEncrypted);
                    return(bundleInfo);
                }
                else
                {
                    string          remoteURL         = GetPatchDownloadURL(patchBundle.Version, patchBundle.Hash);
                    string          remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash);
                    AssetBundleInfo bundleInfo        = new AssetBundleInfo(bundleName, sandboxLoadPath, remoteURL, remoteFallbackURL, patchBundle.Version, patchBundle.IsEncrypted);
                    return(bundleInfo);
                }
            }
            else
            {
                MotionLog.Warning($"Not found bundle in patch manifest : {bundleName}");
                AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty);
                return(bundleInfo);
            }
        }
예제 #6
0
        /// <summary>
        /// 获取AssetBundle的加载信息
        /// </summary>
        public AssetBundleInfo GetAssetBundleInfo(string bundleName)
        {
            if (_localPatchManifest.Elements.TryGetValue(bundleName, out PatchElement element))
            {
                // 查询内置资源
                if (_appPatchManifest.Elements.TryGetValue(bundleName, out PatchElement appElement))
                {
                    if (appElement.IsDLC() == false && appElement.MD5 == element.MD5)
                    {
                        string          appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appElement.MD5);
                        AssetBundleInfo bundleInfo  = new AssetBundleInfo(bundleName, appLoadPath, string.Empty, appElement.Version, appElement.IsEncrypted);
                        return(bundleInfo);
                    }
                }

                // 查询缓存资源
                // 注意:如果沙盒内缓存文件不存在,那么将会从服务器下载
                string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(element.MD5);
                if (_cache.Contains(element.MD5))
                {
                    AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, sandboxLoadPath, string.Empty, element.Version, element.IsEncrypted);
                    return(bundleInfo);
                }
                else
                {
                    string          remoteURL  = GetWebDownloadURL(element.Version.ToString(), element.MD5);
                    AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, sandboxLoadPath, remoteURL, element.Version, element.IsEncrypted);
                    return(bundleInfo);
                }
            }
            else
            {
                MotionLog.Warning($"Not found element in patch manifest : {bundleName}");
                AssetBundleInfo bundleInfo = new AssetBundleInfo(bundleName, string.Empty);
                return(bundleInfo);
            }
        }