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);
                }
            }
        }
Exemple #2
0
        protected IEnumerator DeleteOldAsset(UpdateList needDeleteLst)
        {
            base.Event.Trigger(AutoUpdateEvents.ON_DELETE_DISK_OLD_FILE_START);

            IFile file;
            foreach (UpdateListField field in needDeleteLst)
            {
                file = IO.File(Env.AssetPath + field.Path);
                if (file.Exists)
                {
                    base.Event.Trigger(AutoUpdateEvents.ON_DELETE_DISK_OLD_FIELD_ACTION);
                    file.Delete();
                }

            }

            yield return null;

            base.Event.Trigger(AutoUpdateEvents.ON_DELETE_DISK_OLD_FILE_END);
        }
        /// <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 #4
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);
        }
Exemple #5
0
        protected IEnumerator UpdateAssetFromUrl(UpdateList needUpdateLst, string downloadUrl)
        {
            updateNum = 0;
            needUpdateNum = needUpdateLst.Count();
            string savePath, downloadPath, saveDir;
            base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_START);
            foreach (UpdateListField field in needUpdateLst)
            {
                downloadPath = downloadUrl + field.Path;
                savePath = Env.AssetPath + field.Path;

                saveDir = savePath.Substring(0, savePath.LastIndexOf('/'));

                updateNum++;
                base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_ACTION);

                using (UnityWebRequest request = UnityWebRequest.Get(downloadPath))
                {
                    yield return request.Send();
                    if (request.isError || request.responseCode != 200)
                    {
                        base.Event.Trigger(AutoUpdateEvents.ON_UPDATE_FILE_FAILD);
                        yield break;
                    }
                    IO.Directory(saveDir).Create();
                    IO.CreateFile(savePath , request.downloadHandler.data, 0, request.downloadHandler.data.Length);
                }

            }

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