private void OnComplete() { if (enableVFS) { var dataPath = _savePath + Versions.Dataname; var downloads = _downloader.downloads; if (downloads.Count > 0 && File.Exists(dataPath)) { OnMessage("更新本地版本信息"); var files = new List <VFile>(downloads.Count); foreach (var download in downloads) { files.Add(new VFile { name = download.name, hash = download.hash, len = download.len, }); } var file = files[0]; if (!file.name.Equals(Versions.Dataname)) { Versions.UpdateDisk(dataPath, files); } } Versions.LoadDisk(dataPath); } OnProgress(1); OnMessage("更新完成"); var version = Versions.LoadVersion(_savePath + Versions.Filename); if (version > 0) { OnVersion("资源版本号: v" + Application.version + "res" + version.ToString()); } StartCoroutine(LoadGameScene()); }
private void PrepareDownloads() { if (enableVFS) { var path = string.Format("{0}{1}", _savePath, Versions.Dataname); if (!File.Exists(path)) { AddDownload(_versions[0]); return; } Versions.LoadDisk(path); } for (var i = 1; i < _versions.Count; i++) { var item = _versions[i]; if (Versions.IsNew(string.Format("{0}{1}", _savePath, item.name), item.len, item.hash)) { AddDownload(item); } } }
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(); } } }