-
Notifications
You must be signed in to change notification settings - Fork 51
/
Updater.cs
79 lines (69 loc) · 2.94 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
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;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace AndroidSideloader
{
internal class Updater
{
public static string AppName { get; set; }
public static string Repository { get; set; }
private static readonly string RawGitHubUrl = "https://raw.githubusercontent.com/VRPirates/rookie";
private static readonly string GitHubUrl = "https://github.com/VRPirates/rookie";
public static readonly string LocalVersion = "2.22";
public static string currentVersion = string.Empty;
public static string changelog = string.Empty;
// Check if there is a new version of the sideloader
private static async Task<bool> IsUpdateAvailableAsync()
{
using (HttpClient client = new HttpClient())
{
try
{
currentVersion = await client.GetStringAsync($"{RawGitHubUrl}/master/version");
changelog = await client.GetStringAsync($"{RawGitHubUrl}/master/changelog.txt");
currentVersion = currentVersion.Trim();
}
catch (HttpRequestException)
{
return false;
}
}
return LocalVersion.Trim() != currentVersion;
}
// Call this to ask the user if they want to update
public static async Task Update()
{
if (await IsUpdateAvailableAsync())
{
UpdateForm upForm = new UpdateForm();
_ = upForm.ShowDialog();
}
}
// If the user wants to update
public static void doUpdate()
{
try
{
ADB.RunAdbCommandToString("kill-server");
using (WebClient fileClient = new WebClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Logger.Log($"Downloading update from {GitHubUrl}/releases/download/v{currentVersion}/{AppName}.exe to {AppName} v{currentVersion}.exe");
fileClient.DownloadFile($"{GitHubUrl}/releases/download/v{currentVersion}/{AppName}.exe", $"{AppName} v{currentVersion}.exe");
Logger.Log($"Starting {AppName} v{currentVersion}.exe");
Process.Start($"{AppName} v{currentVersion}.exe");
}
// Delete current version
AndroidSideloader.Utilities.GeneralUtilities.Melt();
}
catch (Exception ex)
{
// Handle specific exceptions that might occur during the update process
Logger.Log($"Update failed: {ex.Message}");
}
}
}
}