-
Notifications
You must be signed in to change notification settings - Fork 27
/
Updater.cs
50 lines (43 loc) · 1.59 KB
/
Updater.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
using System;
using System.Net;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading.Tasks;
namespace WebMCam
{
class Updater
{
private static string versionUrl = "https://raw.githubusercontent.com/thetarkus/WebMCam/master/VERSION";
private static string downloadPageUrl = "https://github.com/thetarkus/WebMCam/releases";
public static async Task CheckAsync(string oldVersionStr)
{
await Task.Run(() => Check(oldVersionStr));
}
public static void Check(string oldVersionStr)
{
try
{
var newVersionStr = new WebClient().DownloadString(new Uri(versionUrl)).Trim();
var newVersion = new Version(newVersionStr);
var oldVersion = new Version(oldVersionStr);
if(newVersion.CompareTo(oldVersion) > 0)
{
var result = MessageBox.Show(
string.Format(
"Version {0} is available for download. You are running version {1}." +
Environment.NewLine + "Would you like to be sent to the download page?",
newVersion, oldVersion
),
"New Version Available", MessageBoxButtons.YesNo, MessageBoxIcon.Question
);
if(result == DialogResult.Yes)
Process.Start(downloadPageUrl);
}
}
catch
{
/* Suppress */
}
}
}
}