Ejemplo n.º 1
0
        private IEnumerator CopyByRequest(string basePath)
        {
            var request = UnityWebRequest.Get(basePath + Versions.Filename);

            request.SendWebRequest();
            yield return(request);

            if (string.IsNullOrEmpty(request.error))
            {
                using (var stream = new MemoryStream(request.downloadHandler.data))
                {
                    var records = Versions.LoadRecords(stream);
                    for (var index = 0; index < records.Count; index++)
                    {
                        var item         = records[index];
                        var assetName    = item.name;
                        var assetRequest = UnityWebRequest.Get(basePath + assetName);
                        yield return(assetRequest.SendWebRequest());

                        if (string.IsNullOrEmpty(assetRequest.error))
                        {
                            File.WriteAllBytes(_savePath + assetName, assetRequest.downloadHandler.data);
                        }

                        assetRequest.Dispose();
                        OnMessage(string.Format("正在复制文件{0}/{1}", index, records.Count));
                        OnProgress(index * 1f / records.Count);
                    }
                }
            }

            request.Dispose();
        }
Ejemplo n.º 2
0
        private IEnumerator CopyByFile(string basePath)
        {
            var path = basePath + Versions.Filename;

            if (!File.Exists(path))
            {
                yield break;
            }
            var records = Versions.LoadRecords(path);

            for (var index = 0; index < records.Count; index++)
            {
                var item      = records[index];
                var assetName = item.name;
                var assetPath = basePath + assetName;
                if (File.Exists(assetPath))
                {
                    File.Copy(assetPath, _savePath + assetName, true);
                }

                OnMessage(string.Format("正在复制文件{0}/{1}", index, records.Count));
                OnProgress(index * 1f / records.Count);
                yield return(null);
            }
        }
Ejemplo n.º 3
0
        private IEnumerator Checking()
        {
            if (!Directory.Exists(_savePath))
            {
                Directory.CreateDirectory(_savePath);
            }

            yield return(ExtractAssetsIfNeed());

            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                var mb = MessageBox.Show("提示", "网络状态不可达,请联网后重试。", "重试", "退出");
                yield return(mb);

                if (mb.isOk)
                {
                    StartUpdate();
                }
                else
                {
                    Quit();
                    MessageBox.Dispose();
                }

                yield break;
            }

            OnMessage("正在获取服务器版本信息...");
            const string assetName = Versions.Filename;
            var          url       = downloadUrl + assetName;
            var          request   = UnityWebRequest.Get(url);

            yield return(request.SendWebRequest());

            if (!string.IsNullOrEmpty(request.error))
            {
                var mb = MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", request.error), "重试", "退出");
                yield return(mb);

                if (mb.isOk)
                {
                    StartUpdate();
                }
                else
                {
                    Quit();
                    MessageBox.Dispose();
                }

                yield break;
            }

            var path  = _savePath + assetName;
            var bytes = request.downloadHandler.text;

            File.WriteAllText(path, bytes);
            request.Dispose();
            OnMessage("正在加载版本信息...");
            if (!File.Exists(path))
            {
                yield break;
            }
            var records = Versions.LoadRecords(path);

            OnMessage("正在检查版本信息...");
            _serverRecords.Clear();
            _downloads.Clear();
            foreach (var item in records)
            {
                _serverRecords[item.name] = item;
                if (IsUpdate(item))
                {
                    AddDownload(item);
                }
            }

            if (_downloads.Count > 0)
            {
                var totalSize = 0L;
                foreach (var item in _downloads)
                {
                    totalSize += item.len;
                }

                const float bytesToMb = 1f / (1024 * 1024);
                var         tips      = string.Format("检查到有{0}个文件需要更新,总计需要下载{1:f2}(MB)内容", _downloads.Count, totalSize * bytesToMb);
                var         mb        = MessageBox.Show("提示", tips, "下载", "跳过");
                yield return(mb);

                if (mb.isOk)
                {
                    PrepareToDownload();
                    yield return(UpdateDownloads(bytesToMb, totalSize));
                }
            }

            OnComplete();
        }