Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace GME
- {
- class CheckUpdate
- {
- public static void Updater()
- {
- string downloadUrl = "";
- Version newVersion = null;
- string aboutUpdate = "";
- string xmlUrl = "http://www.example.com/update.xml";
- XmlTextReader reader = null;
- try
- {
- reader = new XmlTextReader(xmlUrl);
- reader.MoveToContent();
- string elementName = "";
- if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo"))
- {
- while (reader.Read())
- {
- if (reader.NodeType == XmlNodeType.Element)
- {
- elementName = reader.Name;
- }
- else
- {
- if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
- switch (elementName)
- {
- case "version":
- newVersion = new Version(reader.Value);
- break;
- case "url":
- downloadUrl = reader.Value;
- break;
- case "about":
- aboutUpdate = reader.Value;
- break;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- Environment.Exit(1);
- }
- finally
- {
- if (reader != null)
- reader.Close();
- }
- Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
- if (applicationVersion.CompareTo(newVersion) < 0)
- {
- string str = String.Format("New Update Found\n\nNewest version : {1} \nLog : {2} ", applicationVersion, newVersion, aboutUpdate);
- if (DialogResult.No != MessageBox.Show(str + "\n\nWould you like to download this update?", "Check for updates", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
- {
- try
- {
- Process.Start(downloadUrl);
- }
- catch { }
- return;
- }
- else
- {
- ;
- }
- }
- else
- {
- MessageBox.Show("No new updates found.", "Check for Updates", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement