Пример #1
0
        public AssetUpdateDifferenceList Compare(AssetUpdateAssetList newAssetList, AssetUpdateAssetList oldAssetList)
        {
            if (oldAssetList == null || newAssetList == null)
            {
                return(this);
            }

            var oldDict = oldAssetList.GetDictByPath();
            var newDict = newAssetList.GetDictByPath();

            int maxCount = Math.Max(oldAssetList.fileItems.Length, newAssetList.fileItems.Length);

            for (int i = 0; i < maxCount; i++)
            {
                var oldItem = i < oldAssetList.fileItems.Length ? oldAssetList.fileItems[i] : null;
                var newItem = i < newAssetList.fileItems.Length ? newAssetList.fileItems[i] : null;

                if (newItem != null)
                {
                    if (oldDict.TryGetValue(newItem.filePath, out var sideOldItem))
                    {
                        //变更的
                        if (string.Compare(newItem.fileMd5, sideOldItem.fileMd5, true) != 0)
                        {
                            var item = new Item(newItem);

                            var modifyGroup = GetModifyGroup();
                            var modifyList  = modifyGroup.GetDict();
                            modifyList.Add(item.filePath, item);

                            modifyGroup.size += newItem.fileSize;
                        }
                    }
                    else //新增的
                    {
                        var item = new Item(newItem);

                        var addGroup = GetAddGroup();
                        var addList  = addGroup.GetDict();
                        addList.Add(item.filePath, item);

                        addGroup.size += newItem.fileSize;
                    }
                }

                if (oldItem != null)
                {
                    if (!newDict.ContainsKey(oldItem.filePath))     //移除的
                    {
                        var item = new Item(oldItem);

                        var removeGroup = GetRemoveGroup();
                        var removeList  = removeGroup.GetDict();
                        removeList.Add(item.filePath, item);

                        removeGroup.size += oldItem.fileSize;
                    }
                }
            }
            return(this);
        }
Пример #2
0
        ////////////////////////////

        protected IEnumerator OnUpdateAsset()
        {
            AssetUpdateAssetList newAssetList = new AssetUpdateAssetList(); //从服务器下载下来的资源列表
            AssetUpdateAssetList oldAssetList = new AssetUpdateAssetList();
            //从远端下载资源列表到本地
            bool isNetworkDownloadFinish = false;
            var  networkAssetList        = GetNetworkAssetPath();

            if (!File.Exists(networkAssetList))
            {
                var networkAssetListUrl = GetNetworkAssetUrl();
                var task = AssetDownloadManager.GetInstance().Download(new string[] { networkAssetListUrl }, new string[] { networkAssetList });
                task.onCompleted = (_) => { isNetworkDownloadFinish = true; };

                //等待下载结束
                while (!isNetworkDownloadFinish)
                {
                    yield return(null);
                }
            }

            if (File.Exists(assetFolderPath))
            {
                oldAssetList.Import(assetFolderPath);
            }
            else
            {
                onFinish?.Invoke(-1);
                yield break;
            }

            //读取本地资源列表
            var localAssetList = GetLocalAssetListPath();

            if (!File.Exists(localAssetList))
            {
                oldAssetList.Scan(assetFolderPath);
                oldAssetList.Export(localAssetList);
            }
            else
            {
                oldAssetList.Import(assetFolderPath);
            }

            //配置列表读取
            var networkConfigList            = GetNetworkConfigPath();
            AssetUpdateConfigList configList = null;

            if (File.Exists(networkConfigList))
            {
                configList = new AssetUpdateConfigList();
                configList.Import(networkConfigList);
            }


            //做资源对比
            AssetUpdateDifferenceList differenceList = new AssetUpdateDifferenceList();

            differenceList.Compare(newAssetList, oldAssetList);
            if (differenceList.IsVerify())  //资源一致,不需要更新
            {
                onFinish?.Invoke(0);
                yield break;
            }

            //差异表转成更新列表去更新
            AssetUpdateUpdateList assetUpdateUpdateList = new AssetUpdateUpdateList(updateDownloadUrl, downloadFolderPath, assetFolderPath);

            assetUpdateUpdateList.Convert(differenceList, configList);

            //启动更新
            bool isUpdateFinsin        = false;
            AssetUpdateUpdater updater = new AssetUpdateUpdater(assetUpdateUpdateList);

            updater.Update();
            updater.onFinish = () => { isUpdateFinsin = true; };

            while (!isUpdateFinsin)
            {
                yield return(null);
            }

            onFinish?.Invoke(1);
            yield break;
        }