public void InitVersionPanel(bool forceUpdate, string url) { OKCancelPanel panel = Director.LoadPrefab("OKCancelPanel", canvas).GetComponent <OKCancelPanel>(); if (loadingPanel != null) { loadingPanel.SetActive(false); } panel.gameObject.SetActive(true); panel.autoTranslate = false; //panel.gameObject.SetActive (false); if (forceUpdate) { panel.okText.text = "更新"; panel.cancelText.text = "关闭"; panel.onCancelHandler = () => { Application.Quit(); }; } else { panel.okText.text = "更新"; panel.cancelText.text = "取消"; panel.onCancelHandler = () => { panel.gameObject.SetActive(false); versionLoaded = true; }; } panel.description.text = "发现新版本,是否进行更新"; panel.onOKHandler = () => { Application.OpenURL(url); }; }
public static IEnumerator LoadConfig(string url, Action <int, int> loadedHandler = null, OKCancelPanel panel = null) { localConfig = null; remoteConfig = null; forceBreak = false; fileLoadedHandler = loadedHandler; Logger.Log(url); yield return(Request.ReadPersistent(url, str => Config.localConfig = XDocument.Parse(str).Root)); yield return(Request.ReadRemote(url, str => Config.remoteConfig = XDocument.Parse(str).Root)); string platform = GetPlatformName(); if (remoteConfig == null) { Debug.Log("remoteConfig = null"); } else if (localConfig == null) { Debug.Log("remoteConfig != null"); // var nodes = remoteConfig.Elements (); // int count = 0; // foreach (XElement node in nodes) // count++; // if (fileLoadedHandler != null) { // fileLoadedHandler.Invoke (0, count); // } // int index = 0; // foreach (XElement node in nodes) { // index++; // yield return Request.DownloadFile (node.Value.Replace ("{%platform%}", platform), node.Value.Replace ("{%platform%}", "")); // if (forceBreak) { // yield break; // } else { // if (fileLoadedHandler != null) { // fileLoadedHandler.Invoke (index, count); // } // } // } // //Debug.Log ("remoteConfig: " + remoteConfig.ToString ()); // File.WriteAllText (Path.Combine(Application.persistentDataPath, url), remoteConfig.ToString()); var nodes = remoteConfig.Element("all").Elements(); List <string> names = new List <string> (); foreach (XElement node in nodes) { names.Add(node.Value); } yield return(LoadFiles(names, url)); } else { string localVersion = Xml.Version(localConfig); string preVersion = Xml.Attribute(remoteConfig, "preversion"); string remoteVersion = Xml.Version(remoteConfig); float filesize = Xml.Float(remoteConfig, "size"); if (localVersion != remoteVersion) { if (panel != null && Application.internetReachability != NetworkReachability.ReachableViaLocalAreaNetwork && filesize > 3) { //if (panel != null && filesize > 3) { yield return(panel.Show(string.Format(I18n.Translate("not_in_wifi"), filesize.ToString() + "M"))); if (panel.isCancel) { yield break; } } var nodes = remoteConfig.Element("update").Elements(); List <string> updates = new List <string> (); foreach (XElement node in nodes) { updates.Add(node.Value); } int idx = url.IndexOf("/"); string path = idx == -1 ? url : url.Substring(0, idx); while (localVersion != preVersion) { Config.tempConfig = null; yield return(Request.ReadRemote(path + "/version/" + preVersion + ".xml", str => Config.tempConfig = XDocument.Parse(str).Root)); if (tempConfig == null) { var all = remoteConfig.Element("all").Elements(); updates = new List <string> (); foreach (XElement node in all) { updates.Add(node.Value); } break; } else { preVersion = Xml.Attribute(tempConfig, "preversion"); var updateNotes = tempConfig.Element("update").Elements(); foreach (XElement node in updateNotes) { Logger.Log(node.Value, "blue"); if (!updates.Contains(node.Value)) { updates.Add(node.Value); } } } } yield return(LoadFiles(updates, url));; } } }