Пример #1
0
        /// <summary>
        /// 和新的列表比对,筛选出需要更新的内容和需要删除的内容
        /// </summary>
        /// <param name="newLst"></param>
        /// <returns></returns>
        public void Comparison(CUpdateList newLst, out CUpdateList needUpdate, out CUpdateList needDelete)
        {
            needUpdate = new CUpdateList(this.path);
            needDelete = new CUpdateList(string.Empty);
            CUpdateListField oldField;

            foreach (CUpdateListField newField in newLst)
            {
                oldField = this.FindPk(newField.Path);
                if (oldField != null)
                {
                    if (oldField.MD5 != newField.MD5)
                    {
                        needUpdate.Append(newField);
                    }
                }
                else
                {
                    needUpdate.Append(newField);
                }
            }

            foreach (CUpdateListField old in this)
            {
                if (newLst.FindPk(old.Path) == null && old.Path != "/" + CUpdateList.FILE_NAME)
                {
                    needDelete.Append(old);
                }
            }
        }
Пример #2
0
        protected IEnumerator UpdateAssetFromUrl(CUpdateList needUpdateLst, string downloadUrl)
        {
            updateNum     = 0;
            needUpdateNum = needUpdateLst.Count();
            string savePath, downloadPath, saveDir;

            base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_START);
            foreach (CUpdateListField field in needUpdateLst)
            {
                downloadPath = downloadUrl + field.Path;
                savePath     = CEnv.AssetPath + field.Path;

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

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

                using (UnityWebRequest request = UnityWebRequest.Get(downloadPath))
                {
                    yield return(request.Send());

                    if (request.isError || request.responseCode != 200)
                    {
                        base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_FAILD);
                        yield break;
                    }
                    CDirectory.CreateDir(saveDir);
                    CFile.Cover(savePath, request.downloadHandler.data, 0, request.downloadHandler.data.Length);
                }
            }

            base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_FILE_END);
        }
Пример #3
0
        /// <summary>
        /// 编译列表文件
        /// </summary>
        /// <param name="path">路径</param>
        protected static void BuildListFile(string path)
        {
            CUpdateList lst = new CUpdateList(path);

            path.Walk((file) => {
                if (!file.Standard().EndsWith(".meta"))
                {
                    string fullName  = file.Standard();
                    string assetName = fullName.Substring(path.Length);
                    lst.Append(assetName, CMD5.ParseFile(file), file.Length);
                }
            });
            lst.Save();
        }
Пример #4
0
        /// <summary>
        /// 获取文件更新列表
        /// </summary>
        /// <returns></returns>
        protected IEnumerator UpdateList(string resUrl)
        {
            base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_START);
            resUrl = resUrl + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform);
            UnityWebRequest request = UnityWebRequest.Get(resUrl + "/" + CUpdateList.FILE_NAME);

            yield return(request.Send());

            if (request.isError || request.responseCode != 200)
            {
                this.isUpdate = false;
                base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_LIST_FAILED);
                yield break;
            }

            base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_START);

            var newLst = new CUpdateList(request).SetPath(CEnv.AssetPath);

            CUpdateList oldLst = new CUpdateList(CEnv.AssetPath);

            CDirectory.CreateDir(CEnv.AssetPath);

            CDirectory.Walk(CEnv.AssetPath, (file) => {
                if (!file.Standard().EndsWith(".meta"))
                {
                    string fullName  = file.Standard();
                    string assetName = fullName.Substring(CEnv.AssetPath.Length);
                    oldLst.Append(assetName, CMD5.ParseFile(file), file.Length);
                }
            });

            base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_END);

            CUpdateList 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(CAutoUpdateEvents.ON_UPDATE_COMPLETE);
        }
Пример #5
0
        protected IEnumerator DeleteOldAsset(CUpdateList needDeleteLst)
        {
            base.Event.Trigger(CAutoUpdateEvents.ON_DELETE_DISK_OLD_FILE_START);

            string filePath;

            foreach (CUpdateListField field in needDeleteLst)
            {
                filePath = CEnv.AssetPath + field.Path;
                if (CFile.Exists(filePath))
                {
                    base.Event.Trigger(CAutoUpdateEvents.ON_DELETE_DISK_OLD_FIELD_ACTION);
                    CFile.Delete(filePath);
                }
            }

            yield return(null);

            base.Event.Trigger(CAutoUpdateEvents.ON_DELETE_DISK_OLD_FILE_END);
        }