} // loadTemplate public XElement GetXMLElement(string name) { XElement el = null; if (_template != null) { el = _template.Element(name); } if (el == null) { el = XmlRoot.Element(name); } return(el); } // getXMLElement
public bool LoadLocalUpdateCollection() { try { if (File.Exists(Paths.Files + "LocalUpdate.xml")) { //await Task.Delay(0); XDocument RemoteXML = XDocument.Load(Paths.Files + "LocalUpdate.xml"); UpdateCollection tUpdateColleciton = new UpdateCollection(); foreach (object UO in (from XmlRoot in RemoteXML.Element("update").Elements("file") select new UpdateObject { localpath = (string)XmlRoot.Element("localpath"), remotepath = (string)XmlRoot.Element("remotepath"), version = (string)XmlRoot.Element("version"), name = (string)XmlRoot.Element("name") //replaceoriginal = (bool)XmlRoot.Element("localpath").Attribute("replaceoriginal") } ) ) { if (File.Exists(((UpdateObject)UO).localpath.Replace("_temp", ""))) { tUpdateColleciton.AddObject((UpdateObject)UO); } } _LocalUpdateCollection = tUpdateColleciton; return(true); } else { return(true); } } catch (Exception) { this._Form.AddToDetails("There was an issue loading the local updates, try restarting. You can play the game normally still."); return(false); } }
} // getXMLAttribute public XAttribute GetXMLAttribute(string parent, string name) { XAttribute att = null; if (_template != null) { var p = _template.Element(parent); if (p != null) { att = p.Attribute(name); } } if (att == null) { var p = XmlRoot.Element(parent); if (p != null) { att = p.Attribute(name); } } return(att); } // getXMLAttribute
} // getXMLElement public XElement GetXMLElement(string parent, string name) { XElement el = null; if (_template != null) { var p = _template.Element(parent); if (p != null) { el = p.Element(name); } } if (el == null) { var p = XmlRoot.Element(parent); if (p != null) { el = p.Element(name); } } return(el); } // getXMLElement
public bool LoadRemoteUpdateCollection() { try { this._Form.AddToDetails("Downloading remote update XML file...."); if (File.Exists(Paths.Files + "RemoteUpdate.xml")) { File.Delete(Paths.Files + "RemoteUpdate.xml"); } WebClient Client = new WebClient(); bool _isDownloading = false; Client.DownloadFileCompleted += (s, e) => { this._Form.UpdateProgress(100); this._Form.AddToDetails("Download Complete."); Client.Dispose(); Client = null; _isDownloading = false; }; Client.DownloadProgressChanged += (s, e) => { this._Form.UpdateProgress(e.ProgressPercentage); }; try { Client.DownloadFileAsync(new Uri(Paths.RemoteUpdateXML), Paths.Files + "RemoteUpdate.xml"); _isDownloading = true; } catch (Exception) { throw new Exception("Error"); } //await Task.Run(() => //{ while (_isDownloading) { } // }); XDocument RemoteXML = XDocument.Load(Paths.Files + "RemoteUpdate.xml"); UpdateCollection tUpdateColleciton = new UpdateCollection(); //replaceoriginal = (XmlRoot.Element("localpath").HasAttributes) ? ((XmlRoot.Element("localpath").Attribute("replaceoriginal") != null) ? true : false) : false foreach (object UO in (from XmlRoot in RemoteXML.Element("update").Elements("file") select new UpdateObject { localpath = (string)XmlRoot.Element("localpath"), remotepath = (string)XmlRoot.Element("remotepath"), version = (string)XmlRoot.Element("version"), name = (string)XmlRoot.Element("name") } ) ) { tUpdateColleciton.AddObject((UpdateObject)UO); } _RemoteUpdateCollection = tUpdateColleciton; return(true); } catch (Exception) { this._Form.AddToDetails("There was an issue loading the remote updates, try restarting. You can play the game normally still."); return(false); } }