Beispiel #1
0
        /// <summary>
        /// Parses the update.xml into ApplicationUpdateXml object
        /// </summary>
        /// <param name="location">Uri of update.xml on server</param>
        /// <param name="appID">The application's ID</param>
        /// <returns>The ApplicationUpdateXml object with the data, or null of any errors</returns>
        public static ApplicationUpdateXml Parse(Uri location)
        {
            Version version = null;
            string  launchArgs = "", md5 = "";
            List <UpdateApplication> applications = new List <UpdateApplication>();

            ServicePointManager.ServerCertificateValidationCallback = (s, ce, ch, ssl) => true;
            XmlDocument doc = new XmlDocument();

            try
            {
                // Load the document
                doc.Load(location.AbsoluteUri);

                // Gets the appId's node with the update info
                // This allows you to store all program's update nodes in one file
                XmlNode updateNode = doc.DocumentElement.SelectSingleNode("//update");

                // If the node doesn't exist, there is no update
                if (updateNode == null)
                {
                    return(null);
                }

                // Parse data
                version = Version.Parse(updateNode["version"].InnerText);

                md5 = updateNode["md5"].InnerText;

                foreach (XmlNode application in doc.DocumentElement.SelectNodes("//update//application"))
                {
                    List <UpdateFile> files = new List <UpdateFile>();
                    string            type  = application["type"].InnerText;

                    foreach (XmlNode file in application.SelectSingleNode("files").SelectNodes("file"))
                    {
                        files.Add(new UpdateFile()
                        {
                            Name = file["name"].InnerText, destination = file["destination"].InnerText, md5 = file["md5"].InnerText
                        });
                    }

                    applications.Add(new UpdateApplication()
                    {
                        Name = application.Attributes["appID"].InnerText, Type = type, Files = files
                    });
                }
                launchArgs = updateNode["launchArgs"].InnerText;

                return(new ApplicationUpdateXml(version, md5, applications, launchArgs));
            }
            catch (Exception ex)
            {
                UpdateEvents.WriteEntry(ex.ToString());
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks the Uri to make sure file exist
        /// </summary>
        /// <param name="location">The Uri of the update.xml</param>
        /// <returns>If the file exists</returns>
        public static bool ExistsOnServer(Uri location)
        {
            try
            {
                // Request the update.xml
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(location.AbsoluteUri);
                // Read for response
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                resp.Close();

                return(resp.StatusCode == HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                UpdateEvents.WriteEntry(ex.ToString());
                return(false);
            }
        }