Exemple #1
0
        /// <summary>
        /// 和新的列表比对,筛选出需要更新的内容和需要删除的内容
        /// </summary>
        /// <param name="newLst"></param>
        /// <returns></returns>
        public void Comparison(UpdateList newLst , out UpdateList needUpdate , out UpdateList needDelete)
        {
            needUpdate = new UpdateList(this.path);
            needDelete = new UpdateList(string.Empty);
            UpdateListField oldField;
            foreach (UpdateListField newField in newLst)
            {
                oldField = this.FindPk(newField.Path);
                if (oldField != null)
                {
                    if (oldField.MD5 != newField.MD5)
                    {
                        needUpdate.Append(newField);
                    }
                }else
                {
                    needUpdate.Append(newField);
                }
            }

            foreach(UpdateListField old in this)
            {
                if(newLst.FindPk(old.Path) == null && old.Path != "/" + UpdateList.FILE_NAME)
                {
                    needDelete.Append(old);
                }
            }
        }
        /// <summary>
        /// 编译列表文件
        /// </summary>
        /// <param name="path">路径</param>
        protected static void BuildListFile(string path)
        {
            UpdateList lst = new UpdateList(path);
            IDirectory directory = CatLib.IO.IO.MakeDirectory(path);
            directory.Walk((file)=>{

                if (!file.Name.EndsWith(".meta"))
                {
                    string fullName = file.FileInfo.FullName.Standard();
                    string assetName = fullName.Substring(path.Length);
                    lst.Append(assetName, MD5.ParseFile(file.FileInfo), file.FileInfo.Length);
                }

            }, SearchOption.AllDirectories);
            lst.Save();
        }
Exemple #3
0
        /// <summary>
        /// 获取文件更新列表
        /// </summary>
        /// <returns></returns>
        protected IEnumerator UpdateList(string resUrl)
        {
            base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_START);
            resUrl = resUrl + "/" + Env.PlatformToName(Env.SwitchPlatform);
            UnityWebRequest request = UnityWebRequest.Get(resUrl + "/" + UpdateSystem.UpdateList.FILE_NAME);
            yield return request.Send();
            if (request.isError || request.responseCode != 200)
            {
                this.isUpdate = false;
                base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_LIST_FAILED);
                yield break;
            }

            base.Event.Trigger(AutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_START);

            var newLst = new UpdateList(request).SetPath(Env.AssetPath);

            UpdateList oldLst = new UpdateList(Env.AssetPath);

            IO.AssetPath.Create();

            IO.AssetPath.Walk((file) => {

                if (!file.FileInfo.FullName.Standard().EndsWith(".meta"))
                {
                    string fullName = file.FileInfo.FullName.Standard();
                    string assetName = fullName.Substring(Env.AssetPath.Length);
                    oldLst.Append(assetName, MD5.ParseFile(file.FileInfo), file.FileInfo.Length);
                }

            });

            base.Event.Trigger(AutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_END);

            UpdateList needUpdateLst, needDeleteLst;
            oldLst.Comparison(newLst, out needUpdateLst, out needDeleteLst);

            yield return this.DeleteOldAsset(needDeleteLst);

            yield return this.UpdateAssetFromUrl(needUpdateLst, resUrl);

            newLst.Save();

            base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_COMPLETE);
        }