-
Notifications
You must be signed in to change notification settings - Fork 0
/
Updater.cs
49 lines (46 loc) · 1.3 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
using System;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Text;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Reflection;
using System.Net.Http;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace esthar_practice
{
class Updater
{
static async public Task<bool> IsUpdateRequired()
{
string currentVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();
string apiUrl = "https://api.github.com/repos/brofar/esthar-practice/releases/latest";
using (var httpClient = new HttpClient())
{
string latestVersion = "";
httpClient.DefaultRequestHeaders.Add("User-Agent", "brofar/esthar-practice");
try
{
var result = await httpClient.GetStringAsync(apiUrl);
var json = JsonConvert.DeserializeObject<dynamic>(result);
latestVersion = json.tag_name;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine(string.Format("Current Version: {0}, Server Version: {1}", currentVersion, latestVersion));
if(currentVersion != latestVersion)
{
return true;
}
return false;
}
}
}
}