private IEnumerator RequestCopy() { var v1 = Versions.LoadVersion(_savePath + Versions.Filename); var basePath = GetStreamingAssetsPath() + "/"; var request = UnityWebRequest.Get(basePath + Versions.Filename); var path = _savePath + Versions.Filename + ".tmp"; request.downloadHandler = new DownloadHandlerFile(path); yield return(request.SendWebRequest()); if (string.IsNullOrEmpty(request.error)) { var v2 = Versions.LoadVersion(path); if (v2 > v1) { var mb = MessageBox.Show("提示", "是否将资源解压到本地?", "解压", "跳过"); yield return(mb); _step = mb.isOk ? Step.Coping : Step.Versions; } else { Versions.LoadVersions(path); _step = Step.Versions; } } else { _step = Step.Versions; } request.Dispose(); }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); if (Application.internetReachability == NetworkReachability.NotReachable) { var mb = MessageBox.Show("提示", "请检查网络连接状态", "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); } yield break; } var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename)); request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename); yield return(request.SendWebRequest()); var error = request.error; request.Dispose(); if (!string.IsNullOrEmpty(error)) { var mb = MessageBox.Show("提示", string.Format("获取服务器版本失败:{0}", error), "重试", "退出"); yield return(mb); if (mb.isOk) { StartUpdate(); } else { Quit(); } yield break; } try { _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); if (_versions.Count > 0) { PrepareDownloads(); _step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += delegate(MessageBox.EventId id) { if (id == MessageBox.EventId.Ok) { StartUpdate(); } else { Quit(); } }; } }
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 = GetStreamingAssetsPath() + "/"; 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(); } } }