-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
79 lines (65 loc) · 2.99 KB
/
Program.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Text.Json;
using System.Text.Json.Nodes;
namespace LionsGate
{
class Program
{
private static readonly string latestReleaseUrl = "https://api.github.com/repos/Cat1Bot/LionsGate/releases/latest";
private static readonly string currentVersion = "0.9.7";
public static async Task Main(string[] args)
{
await CheckForUpdatesAsync();
var leagueProxy = new LeagueProxy();
await leagueProxy.Start();
Console.WriteLine(" [INFO] Starting RCS process...");
var process = leagueProxy.LaunchRCS(args);
if (process is null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" [ERROR] Failed to launch RCS process. Try running this app as administrator.");
Console.ResetColor();
leagueProxy.Stop();
return;
}
Console.WriteLine(" [INFO] Started RCS process.");
await process.WaitForExitAsync();
Console.WriteLine(" [INFO] RCS process exited");
leagueProxy.Stop();
}
public static async Task CheckForUpdatesAsync()
{
try
{
using var handler = new HttpClientHandler
{
UseCookies = false,
UseProxy = false,
Proxy = null,
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true,
CheckCertificateRevocationList = false
};
using var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent", $"LionsGate/{currentVersion}");
var response = await client.GetAsync(latestReleaseUrl);
var content = await response.Content.ReadAsStringAsync();
var release = JsonSerializer.Deserialize<JsonNode>(content);
var latestVersion = release?["tag_name"]?.ToString();
if (latestVersion is null)
return;
var githubVersion = new Version(latestVersion.Replace("v", ""));
var assemblyVersion = new Version(currentVersion.Replace("v", ""));
if (assemblyVersion.CompareTo(githubVersion) != -1)
return;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($" [IMPORTANT] A new version ({latestVersion}) is available! Visit https://github.com/Cat1Bot/LionsGate/releases to get the latest version.");
Console.ResetColor();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(" [WARN] Failed to check for updates: " + ex.Message);
Console.ResetColor();
}
}
}
}