/
UpdateChecker.cs
60 lines (57 loc) · 1.89 KB
/
UpdateChecker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
namespace SwProjectInterface
{
class UpdateChecker
{
public static void start(string metaFileURL)
{
_UpdateChecker uc = new _UpdateChecker();
uc.URL = metaFileURL;
Thread t = new Thread(uc.start);
t.Start();
}
}
class _UpdateChecker
{
public string URL { get; set; }
public void start()
{
XmlDocument x = new XmlDocument();
try
{
x.Load(this.URL);
XmlNode root = x.DocumentElement;
if (root.Name != "swpi")
{
throw new XmlException();
}
string version = x.SelectSingleNode("descendant::version").InnerText;
string downloadURL = x.SelectSingleNode("descendant::URL").InnerText;
if (version == null || downloadURL == null)
{
throw new XmlException();
}
if (String.Compare(version, Assembly.GetExecutingAssembly().GetName().Version.ToString()) == 1)
{
DialogResult r = MessageBox.Show("New version of SwProjectInterface is available to download. Would you like to open download website?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (r == DialogResult.Yes)
{
Process.Start(downloadURL);
}
}
}
catch (Exception e)
{
//MessageBox.Show(e.Message);
}
}
}
}