示例#1
0
        /// <summary>
        /// 反序列化
        /// </summary>
        public static PatchManifest Deserialize(string jsonData)
        {
            PatchManifest patchManifest = JsonUtility.FromJson <PatchManifest>(jsonData);

            foreach (var element in patchManifest.ElementList)
            {
                patchManifest.Elements.Add(element.Name, element);
            }
            foreach (var variant in patchManifest.VariantList)
            {
                patchManifest.Variants.Add(variant.Name, variant);
            }
            return(patchManifest);
        }
        private static string[] GetDepends(PatchManifest patchManifest, PatchBundle patchBundle)
        {
            List <string> result = new List <string>(patchBundle.DependIDs.Length);

            foreach (var dependID in patchBundle.DependIDs)
            {
                if (dependID >= 0 && dependID < patchManifest.BundleList.Count)
                {
                    var dependPatchBundle = patchManifest.BundleList[dependID];
                    result.Add(dependPatchBundle.BundleName);
                }
                else
                {
                    throw new Exception($"Invalid depend id : {dependID} : {patchBundle.BundleName}");
                }
            }
            return(result.ToArray());
        }
示例#3
0
        /// <summary>
        /// 反序列化
        /// </summary>
        public static PatchManifest Deserialize(string jsonData)
        {
            PatchManifest patchManifest = JsonUtility.FromJson <PatchManifest>(jsonData);

            // 构建资源包集合
            foreach (var patchBundle in patchManifest.BundleList)
            {
                // 前置准备工作
                patchBundle.ParseFlagsValue();
                patchBundle.Depends = GetDepends(patchManifest, patchBundle);

                // 添加到字典集合
                patchManifest.Bundles.Add(patchBundle.BundleName, patchBundle);

                // 构建资源映射集合
                UpdateAssetMap(patchManifest, patchBundle);
            }

            return(patchManifest);
        }
示例#4
0
        private string GetVariantManifestPath(PatchManifest patchManifest, string manifestPath)
        {
            if (_variantCollector == null)
            {
                return(manifestPath);
            }

            if (patchManifest.Elements.TryGetValue(manifestPath, out PatchElement element))
            {
                // 如果是变体资源
                string variant = element.GetFirstVariant();
                if (string.IsNullOrEmpty(variant) == false)
                {
                    manifestPath = _variantCollector.TryGetVariantManifestPath(manifestPath, variant);
                }
                return(manifestPath);
            }
            else
            {
                MotionLog.Warning($"Not found element in patch manifest : {manifestPath}");
                return(manifestPath);
            }
        }
示例#5
0
        /// <summary>
        /// 反序列化
        /// </summary>
        public static PatchManifest Deserialize(string jsonData)
        {
            PatchManifest patchManifest = JsonUtility.FromJson <PatchManifest>(jsonData);

            foreach (var element in patchManifest.ElementList)
            {
                patchManifest.Elements.Add(element.BundleName, element);
                foreach (var assetPath in element.AssetPaths)
                {
                    if (patchManifest.AssetsMap.ContainsKey(assetPath))
                    {
                        throw new Exception($"Asset path have existed : {assetPath}");
                    }
                    patchManifest.AssetsMap.Add(assetPath, element);
                }
            }

            foreach (var variant in patchManifest.VariantList)
            {
                patchManifest.Variants.Add(variant.BundleName, variant);
            }

            return(patchManifest);
        }
示例#6
0
 public void ParseRemotePatchManifest(string content)
 {
     _localPatchManifest = PatchManifest.Deserialize(content);
 }
示例#7
0
        /// <summary>
        /// 异步初始化
        /// </summary>
        public IEnumerator InitializeAsync()
        {
            MotionLog.Log($"Beginning to initialize patch manager.");

            // 加载缓存
            _cache = PatchCache.LoadCache();

            // 检测沙盒被污染
            // 注意:在覆盖安装的时候,会保留沙盒目录里的文件,所以需要强制清空
            {
                // 如果是首次打开,记录APP版本号
                if (PatchHelper.CheckSandboxCacheFileExist() == false)
                {
                    _cache.CacheAppVersion = Application.version;
                    _cache.SaveCache();
                }
                else
                {
                    // 每次启动时比对APP版本号是否一致
                    if (_cache.CacheAppVersion != Application.version)
                    {
                        MotionLog.Warning($"Cache is dirty ! Cache version is {_cache.CacheAppVersion}, APP version is {Application.version}");
                        ClearCache();

                        // 重新写入最新的APP版本号
                        _cache.CacheAppVersion = Application.version;
                        _cache.SaveCache();
                    }
                }
            }

            // 加载APP内的补丁清单
            MotionLog.Log($"Load app patch manifest.");
            {
                string        filePath   = AssetPathHelper.MakeStreamingLoadPath(PatchDefine.PatchManifestFileName);
                string        url        = AssetPathHelper.ConvertToWWWPath(filePath);
                WebGetRequest downloader = new WebGetRequest(url);
                downloader.DownLoad();
                yield return(downloader);

                if (downloader.HasError())
                {
                    downloader.ReportError();
                    downloader.Dispose();
                    throw new System.Exception($"Fatal error : Failed download file : {url}");
                }

                // 解析补丁清单
                string jsonData = downloader.GetText();
                _appPatchManifest = PatchManifest.Deserialize(jsonData);
                downloader.Dispose();
            }

            // 加载沙盒内的补丁清单
            MotionLog.Log($"Load sandbox patch manifest.");
            if (PatchHelper.CheckSandboxPatchManifestFileExist())
            {
                string filePath = AssetPathHelper.MakePersistentLoadPath(PatchDefine.PatchManifestFileName);
                string jsonData = File.ReadAllText(filePath);
                _localPatchManifest = PatchManifest.Deserialize(jsonData);
            }
            else
            {
                _localPatchManifest = _appPatchManifest;
            }
        }
示例#8
0
        string[] IBundleServices.GetAllDependencies(string manifestPath)
        {
            PatchManifest patchManifest = _patcher.GetPatchManifest();

            return(patchManifest.GetAllDependencies(manifestPath));
        }
示例#9
0
        /// <summary>
        /// 序列化
        /// </summary>
        public static void Serialize(string savePath, PatchManifest obj)
        {
            string json = JsonUtility.ToJson(obj);

            FileUtility.CreateFile(savePath, json);
        }
示例#10
0
        string[] IBundleServices.GetAllDependencies(string bundleName)
        {
            PatchManifest patchManifest = _patcher.GetPatchManifest();

            return(patchManifest.GetAllDependencies(bundleName));
        }
示例#11
0
        string IBundleServices.GetAssetBundleName(string assetPath)
        {
            PatchManifest patchManifest = _patcher.GetPatchManifest();

            return(patchManifest.GetAssetBundleName(assetPath));
        }