示例#1
0
        private IEnumerator Checking()
        {
            if (!Directory.Exists(_savePath))
            {
                Directory.CreateDirectory(_savePath);
            }

            this.Step = Step.Copy;

            if (this.Step == Step.Copy)
            {
                yield return(RequestCopy());
            }

            if (this.Step == Step.Coping)
            {
                var path     = _savePath + Versions.Filename + ".tmp";
                var versions = Versions.LoadVersions(path);
                var basePath = GetStreamingAssetsPath() + "/";
                yield return(UpdateCopy(versions, basePath));

                this.Step = Step.Versions;
            }

            if (this.Step == Step.Versions)
            {
                yield return(RequestVersions());
            }

            if (this.Step == Step.Prepared)
            {
                OnMessage("正在检查版本信息...");
                var totalSize = _downloader.size;
                if (totalSize > 0)
                {
                    Debug.Log($"发现内容更新,总计需要下载 {Downloader.GetDisplaySize(totalSize)} 内容");
                    _downloader.StartDownload();
                    this.Step = Step.Download;
                }
                else
                {
                    OnComplete();
                }
            }
        }
示例#2
0
        private IEnumerator Checking()
        {
            if (!Directory.Exists(_savePath))
            {
                Directory.CreateDirectory(_savePath);
            }

            if (_step == Step.Wait)
            {
                enableVFS = true;
#if UNITY_IPHONE
                enableVFS = false;
#endif
                _step = Step.Copy;
            }

            if (_step == Step.Copy)
            {
                yield return(RequestCopy());
            }

            if (_step == Step.Coping)
            {
                var path     = _savePath + Versions.Filename + ".tmp";
                var versions = Versions.LoadVersions(path);
                var basePath = GetBasePath();
                yield return(UpdateCopy(versions, basePath));

                _step = Step.Versions;
            }

            if (_step == Step.Versions)
            {
                yield return(RequestVersions());
            }

            if (_step == Step.Prepared)
            {
                OnMessage("正在检查版本信息...");
                var totalSize = _downloader.size;
                if (totalSize > 0)
                {
                    var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize));
                    var mb   = MessageBox.Show("提示", tips, "下载", "退出");
                    yield return(mb);

                    if (mb.isOk)
                    {
                        _downloader.StartDownload();
                        _step = Step.Download;
                    }
                    else
                    {
                        Quit();
                    }
                }
                else
                {
                    OnComplete();
                }
            }
        }
示例#3
0
文件: Updater.cs 项目: Hengle/JEngine
 private void OnUpdate(long progress, long size, float speed)
 {
     OnMessage(string.Format("下载中...{0}/{1}, {2} 速度:{3}", progress, size,
                             Downloader.GetDisplaySize(progress), Downloader.GetDisplaySpeed(speed)));
     OnProgress(progress * 1f / size);
 }
示例#4
0
        private void Update()
        {
            switch (_step)
            {
            case Step.Wait:
                break;

            case Step.Version:
                _step = Step.Wait;
                OnMessage("正在获取版本信息...");
                if (!Directory.Exists(_savePath))
                {
                    Directory.CreateDirectory(_savePath);
                }
                if (Application.internetReachability == NetworkReachability.NotReachable)
                {
                    MessageBox.Show("提示", "请检查网络连接状态", "重试", "退出").onComplete = OnErrorAction;
                    return;
                }
                var request = Download(Versions.Filename);
                var oper    = request.SendWebRequest();
                oper.completed += delegate(AsyncOperation operation)
                {
                    if (!string.IsNullOrEmpty(request.error))
                    {
                        MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", request.error), "重试", "退出").onComplete = OnErrorAction;
                    }
                    else
                    {
                        try
                        {
                            Versions.serverVersion = Versions.LoadFullVersion(_savePath + Versions.Filename);
                            var newFiles = Versions.GetNewFiles(PatchId.Level1, _savePath);
                            if (newFiles.Count > 0)
                            {
                                foreach (var item in newFiles)
                                {
                                    _downloader.AddDownload(GetDownloadURL(item.name), item.name, _savePath + item.name, item.hash, item.len);
                                }
                                _step = Step.Prepared;
                            }
                            else
                            {
                                OnComplete();
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                            MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += OnErrorAction;
                        }
                    }
                };
                break;

            case Step.Prepared:
                OnMessage("正在检查版本信息...");
                _step = Step.Wait;
                var totalSize = _downloader.size;
                if (totalSize > 0)
                {
                    var tips = string.Format("发现内容更新,总计需要下载 {0} 内容", Downloader.GetDisplaySize(totalSize));
                    MessageBox.Show("提示", tips, "下载", "退出").onComplete += delegate(MessageBox.EventId id)
                    {
                        if (id == MessageBox.EventId.Ok)
                        {
                            _downloader.StartDownload();
                            _step = Step.Download;
                        }
                        else
                        {
                            Quit();
                        }
                    };
                }
                else
                {
                    OnComplete();
                }
                break;
            }
        }