-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLatestVersion.cs
More file actions
51 lines (47 loc) · 1.7 KB
/
Copy pathLatestVersion.cs
File metadata and controls
51 lines (47 loc) · 1.7 KB
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
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
using HtmlDocument = HtmlAgilityPack.HtmlDocument;
namespace MCEControl
{
class LatestVersion
{
public delegate void GotVersionInfo(object sender, Version version);
public static Version CurrentVersion
{
get { return new Version(Application.ProductVersion); }
}
public string ErrorMessage { get; private set; }
public Version LatestStableRelease { get; private set; }
public async void GetLatestStableVersionAsync(GotVersionInfo callback)
{
var client = new WebClient();
try
{
byte[] bytes =
await client.DownloadDataTaskAsync(
"http://mcec.codeplex.com/wikipage?title=Latest%20Stable%20Version%20Number");
var htmlDoc = new HtmlDocument();
htmlDoc.Load(new MemoryStream(bytes));
var div = htmlDoc.DocumentNode.SelectSingleNode("//*/div[@class='wikidoc']");
if (div != null)
LatestStableRelease = new Version(div.InnerText.Trim());
else
ErrorMessage = "Could not parse version data.";
}
catch (Exception e)
{
ErrorMessage = e.Message;
}
callback(this, LatestStableRelease);
}
// > 0 - Newer version available
// = 0 - Same version
// < 0 - Current version is newer
public int CompareVersions()
{
return CurrentVersion.CompareTo(LatestStableRelease);
}
}
}