-
Notifications
You must be signed in to change notification settings - Fork 3
/
Updater.cs
81 lines (69 loc) · 2.7 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.Text;
using System.Diagnostics;
using System.Net;
using System.Windows.Forms;
using System.Net.Http;
using System.IO;
namespace VRL
{
class Updater
{
public static void Melt()
{
Process.Start(new ProcessStartInfo()
{
Arguments = "/C choice /C Y /N /D Y /T 5 & Del \"" + Application.ExecutablePath + "\"",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
FileName = "cmd.exe"
});
}
public static string AppName { get; set; }
public static string Repostory { get; set; }
private static string RawGitHubUrl;
private static string GitHubUrl;
static readonly public string LocalVersion = "2.0";
public static string currentVersion = string.Empty;
public static string changelog = string.Empty;
private static bool IsUpdateAvailable()
{
HttpClient client = new HttpClient();
try
{
currentVersion = client.GetStringAsync($"{RawGitHubUrl}/master/version").Result;
currentVersion = currentVersion.Replace("\n", "");
currentVersion = currentVersion.Replace("\r", "");
changelog = client.GetStringAsync($"{RawGitHubUrl}/master/changelog.txt").Result;
}
catch { return false; }
return LocalVersion != currentVersion;
}
public static void Update()
{
RawGitHubUrl = $"https://raw.githubusercontent.com/harryeffinpotter/Shortcut-Maker";
GitHubUrl = $"https://github.com/harryeffinpotter/Shortcut-Maker";
if (IsUpdateAvailable())
doUpdate();
}
private static void doUpdate()
{
DialogResult dialogResult = MessageBox.Show($"There is a new update, you have version {LocalVersion}, do you want to update?\nCHANGELOG\n{changelog}", $"Version {currentVersion} is available", MessageBoxButtons.YesNo);
if (dialogResult != DialogResult.Yes)
return;
try
{
using (var fileClient = new WebClient())
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
fileClient.DownloadFile($"{GitHubUrl}/releases/download/v{currentVersion}/{AppName}.exe", $"{AppName} v{currentVersion}.exe");
}
Melt();
Process.Start($"{AppName} v{currentVersion}.exe");
}
catch { }
Environment.Exit(0);
}
}
}