forked from Just2good/TFT-Overlay
-
Notifications
You must be signed in to change notification settings - Fork 39
/
App.xaml.cs
55 lines (51 loc) · 2.51 KB
/
App.xaml.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
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows;
using TFT_Overlay.Properties;
namespace TFT_Overlay
{
public partial class App : Application
{
private void AutoUpdater(object sender, StartupEventArgs e)
{
string currentVersion = Version.version;
using (WebClient client = new WebClient())
{
try
{
string htmlCode = client.DownloadString("https://raw.githubusercontent.com/jtborn/TFT-Overlay/master/Version.cs");
int versionFind = htmlCode.IndexOf("public static string version = ");
string version = htmlCode.Substring(versionFind + 32, 5);
if (currentVersion != version && Settings.Default.AutoUpdate)
{
var result = MessageBox.Show($"A new update is available.\nWould you like to download V{version}?", "TFT Overlay Update Available", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
string link = "https://github.com/jtborn/TFT-Overlay/releases/download/V" + version + "/TFT.Overlay.V" + version + ".zip";
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
client.DownloadFile(new Uri(link), "TFTOverlay.zip");
var res = MessageBox.Show("The zip file was downloaded to your local directory, please extract and use the updated version instead.\nDo you want to open your local directory?",
"Success", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (res == MessageBoxResult.Yes)
{
Process.Start(Directory.GetCurrentDirectory());
}
}
else if (result == MessageBoxResult.No)
{
Settings.FindAndUpdate("AutoUpdate", false);
}
}
}
catch (WebException ex)
{
Console.WriteLine(ex);
MessageBox.Show(ex.ToString(), "An error occured", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
}