Ejemplo n.º 1
0
        public static bool DownloadAll(out Downloader handler)
        {
            var bundles = new List <BundleRef>();

            for (var i = 0; i < serverVersions.bundles.Count; i++)
            {
                var bundle = serverVersions.bundles[i];
                if (IsNew(bundle))
                {
                    bundles.Add(bundle);
                }
            }

            if (bundles.Count > 0)
            {
                var downloader = new Downloader();
                foreach (var item in bundles)
                {
                    downloader.AddDownload(GetDownloadURL(item.name), updatePath + item.name, item.crc, item.len);
                }
                Downloaders.Add(downloader);
                handler = downloader;
                return(true);
            }

            handler = null;
            return(false);
        }
Ejemplo n.º 2
0
        public static bool DownloadAll(string[] patches, out Downloader handler)
        {
            if (updateAll)
            {
                return(DownloadAll(out handler));
            }

            var bundles = new List <BundleRef>();

            foreach (var patch in patches)
            {
                var saved = PlayerPrefs.GetString(patch, string.Empty);
                if (!saved.Equals(currentVersions.ver))
                {
                    var newFiles = GetNewFiles(patch);
                    foreach (var file in newFiles)
                    {
                        if (!bundles.Exists(x => x.name.Equals(file.name)))
                        {
                            bundles.Add(file);
                        }
                    }
                }
            }

            if (bundles.Count > 0)
            {
                var downloader = new Downloader();
                foreach (var item in bundles)
                {
                    downloader.AddDownload(GetDownloadURL(item.name), updatePath + item.name, item.crc, item.len);
                }
                Downloaders.Add(downloader);
                handler             = downloader;
                handler.onFinished += () =>
                {
                    foreach (var item in patches)
                    {
                        PlayerPrefs.SetString(item, currentVersions.ver);
                    }
                };
                return(true);
            }

            handler = null;
            return(false);
        }
Ejemplo n.º 3
0
        public static bool DownloadAll(string[] patches, out Downloader handler)
        {
            if (updateAll)
            {
                return(DownloadAll(out handler));
            }

            var bundles = new List <BundleRef>();

            foreach (var patch in patches)
            {
                var newFiles = GetNewFiles(patch);
                foreach (var file in newFiles)
                {
                    if (!bundles.Exists(x => x.name.Equals(file.name)))
                    {
                        bundles.Add(file);
                    }
                }
            }

            if (bundles.Count > 0)
            {
                var downloader = new Downloader();
                foreach (var item in bundles)
                {
                    downloader.AddDownload(GetDownloadURL(item.name), updatePath + item.name, item.crc, item.len);
                }
                Downloaders.Add(downloader);
                handler = downloader;
                return(true);
            }

            handler = null;
            return(false);
        }
Ejemplo n.º 4
0
 private void AddDownload(VFile item)
 {
     _downloader.AddDownload(GetDownloadURL(item.name), item.name, _savePath + item.name, item.hash, item.len);
 }
Ejemplo n.º 5
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;
            }
        }