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.LoadVersions(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(); }
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); if (mb.isOk) { var versions = Versions.LoadVersions(path); yield return(UpdateCopy(versions, basePath)); } } else { Versions.LoadVersions(path); } } request.Dispose(); }
private IEnumerator CopyByFile(string basePath) { var path = basePath + Versions.Filename; if (!File.Exists(path)) { yield break; } var records = Versions.LoadVersions(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); } }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename)); request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename); 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; // yield break; } request.Dispose(); _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); }
private IEnumerator Checking() { if (!Directory.Exists(_savePath)) { Directory.CreateDirectory(_savePath); } if (_step == Step.Wait) { yield return(RequestVFS()); _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(); } } }
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) { Debug.Log("将资源解压到本地"); this.Step = Step.Coping; } else { Versions.LoadVersions(path); this.Step = Step.Versions; } } else { this.Step = Step.Versions; } request.Dispose(); }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); var request = UnityWebRequest.Get(GetDownloadURL(Versions.Filename)); request.downloadHandler = new DownloadHandlerFile(_savePath + Versions.Filename); 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(); } yield break; // yield break; } request.Dispose(); try { _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); } catch (Exception e) { Debug.LogException(e); MessageBox.Show("提示", "版本文件加载失败", "重试", "退出").onComplete += delegate(MessageBox.EventId id) { if (id == MessageBox.EventId.Ok) { StartUpdate(); } else { Quit(); } }; } }
public static void CopyAssetBundlesTo(string path, bool vfs = true) { #if UNITY_IPHONE vfs = false; #endif if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var versions = new List <VFile>(); if (!vfs) { versions.AddRange(Versions.LoadVersions(outputPath + "/" + Versions.Filename)); versions.Add(new VFile() { name = Versions.Filename }); versions.RemoveAt(versions.FindIndex(file => file.name.Equals(Versions.Dataname))); } else { versions.Add(new VFile() { name = Versions.Filename }); versions.Add(new VFile() { name = Versions.Dataname }); } foreach (var item in versions) { var src = outputPath + "/" + item.name; var dest = path + "/" + item.name; if (File.Exists(src)) { File.Copy(src, dest, true); } } AssetDatabase.Refresh(); }
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(); } } }
private IEnumerator RequestVersions() { OnMessage("正在获取版本信息..."); if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.LogError("请检查网络连接状态"); 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)) { Debug.LogError($"获取服务器版本失败:{error}"); yield break; } try { _versions = Versions.LoadVersions(_savePath + Versions.Filename, true); if (_versions.Count > 0) { PrepareDownloads(); this.Step = Step.Prepared; } else { OnComplete(); } } catch (Exception e) { Debug.LogException(e); Debug.LogError("版本文件加载失败"); } }
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 { var v1 = Versions.LoadVersion(_savePath + Versions.Filename); //网络版本文件 var v2 = Versions.LoadVersion(_savePath + Versions.Filename + ".tmp"); //本地临时文件 if (v2 > v1) { //如果本地版本高于网络版本,就别更新了 OnComplete(); yield break; } //网络版本高于或者等于本地版本,则检查更新 _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); } 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.LoadVersions(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(); }
public static async void CopyAssetBundlesTo(string path) { var prefix = $"JEngine.Editor.Setting.{Application.productName}"; var jump = PlayerPrefs.GetString($"{prefix}.JumpStartUpScene", "1") == "1"; var scene = SceneManager.GetActiveScene(); if (scene.path != Setting.StartUpScenePath) { if (!jump) { Debug.LogError("请前往启动场景进行该操作,或在JEngine面板配置启动场景"); return; } string name = Setting.StartUpScenePath; scene = EditorSceneManager.OpenScene(name, OpenSceneMode.Additive); while (!scene.isLoaded) { await Task.Delay(10); } } bool vfs = Object.FindObjectOfType <Updater>().enableVFS; EditorSceneManager.CloseScene(scene, true); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var versions = new List <VFile>(); if (!vfs) { versions.AddRange(Versions.LoadVersions(outputPath + "/" + Versions.Filename)); versions.Add(new VFile() { name = Versions.Filename }); versions.RemoveAt(versions.FindIndex(file => file.name.Equals(Versions.Dataname))); } else { versions.Add(new VFile() { name = Versions.Filename }); versions.Add(new VFile() { name = Versions.Dataname }); } foreach (var item in versions) { var src = outputPath + "/" + item.name; var dest = path + "/" + item.name; if (File.Exists(src)) { File.Copy(src, dest, true); } } AssetDatabase.Refresh(); }