예제 #1
0
        public static ResUpdaterInfo GetUpdaterInfo(long lenght)
        {
            ResUpdaterInfo info = new ResUpdaterInfo();

            if (lenght < 1000)
            {
                info.Size   = lenght;
                info.Format = "B";
            }
            else if (lenght <= KB * 1000)
            {
                info.Size   = Math.Round(lenght / (float)KB, 1);
                info.Format = "KB";
            }
            else if (lenght <= MB * 1000)
            {
                info.Size   = Math.Round(lenght / (float)MB, 1);
                info.Format = "MB";
            }
            else
            {
                info.Size   = Math.Round(lenght / (float)GB, 1);
                info.Format = "GB";
            }
            return(info);
        }
예제 #2
0
        /// <summary>
        /// 资源检查完毕
        /// </summary>
        /// <param name="nextState"></param>
        /// <param name="info"></param>
        /// <param name="downloadAction"></param>
        public void CheckMd5Done(UpdateState nextState, ResUpdaterInfo info = null, Action downloadAction = null)
        {
            //if (nextState == UpdateState.Succeed)
            //{
            //    FinishWork(false);
            //}

            //if (nextState == UpdateState.DownloadRes && info != null)
            //{
            //    UpdateCurrentState(nextState);

            //    updateInfo = info;
            //    downloadCount = 0;

            //    // 获得下载大小,提示更新
            //    var content = string.Format(Localization.Get("update_xiazaitishi"), info.Size, info.Format);
            //    messageBoxUI.SetInformation(content, "", downloadAction, false, UpdateSkipedOrFailed);
            //    messageBoxUI.gameObject.SetActive(true);
            //}
        }
예제 #3
0
        /// <summary>
        /// 资源检查
        /// </summary>
        /// <param name="target"></param>
        /// <param name="isTargetLatest"></param>
        private void DoCheckResource(Dictionary <string, BundleMeta> target, bool isTargetLatest)
        {
            var downloadList = new Dictionary <string, BundleMeta>();
            var needDelFiles = new List <FileInfo>();

            foreach (var kv in target)
            {
                var fn   = kv.Key;
                var info = kv.Value;

                BundleMeta infoInStream;
                bool       inStream = StreamInfo.TryGetValue(fn, out infoInStream) && infoInStream.Equals(info);

                //当前stream里面有这个文件,并且size相同
                if (inStream)
                {
                    Res.resourcesInStreamWhenNotUseStreamVersion.Add(fn);
                }
                else
                {
                    FileInfo fi = new FileInfo(Application.persistentDataPath + fn);
                    if (fi.Exists)
                    {
                        //当文件存在,大小不同的时候,删除重新下载
                        if (fi.Length != info.size)
                        {
                            downloadList.Add(fn, info);
                            needDelFiles.Add(fi);
                        }
                        else if (isTargetLatest)
                        {
                            BundleMeta infoInPersistent;
                            bool       inPersistent = PersistentInfo.TryGetValue(fn, out infoInPersistent) && infoInPersistent.Equals(info);

                            //last版本,但是persitent里不存在或者info不同,删除重新下载
                            if (!inPersistent && GetMd5(fi) != info.md5)
                            {
                                downloadList.Add(fn, info);
                                needDelFiles.Add(fi);
                            }
                        }
                    }
                    else
                    {
                        downloadList.Add(fn, info);
                    }
                }
            }

            //不需要下载
            if (downloadList.Count == 0)
            {
                Updater.Reporter.CheckMd5Done(UpdateState.Succeed);
                Updater.DownloadRes.ReplaceLatestToCurrent();
                Debug.LogFormat("check md5 finish,without download");
            }
            else
            {
                long           length         = downloadList.Sum(bundleMeta => bundleMeta.Value.size);
                ResUpdaterInfo resUpdaterInfo = ResUpdaterUtil.GetUpdaterInfo(length);
                resUpdaterInfo.UpdateCount = downloadList.Count;

                Updater.Reporter.CheckMd5Done(UpdateState.DownloadRes, resUpdaterInfo, () =>
                {
                    Debug.LogFormat("check md5 finish,need download file count:{0}", downloadList.Count);

                    //删除不需要的文件
                    DeleteUnUseFiles(needDelFiles, target);
                    Updater.DownloadRes.Start(downloadList);
                });
            }
        }