-
Notifications
You must be signed in to change notification settings - Fork 37
/
SplashScreen.xaml.cs
54 lines (49 loc) · 1.56 KB
/
SplashScreen.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
using System;
using System.Windows;
using System.IO;
using System.Net;
using System.Windows.Threading;
using System.Net.Http;
namespace CanaryLauncherUpdate
{
public partial class SplashScreen : Window
{
static readonly HttpClient httpClient = new HttpClient();
DispatcherTimer timer = new DispatcherTimer();
string urlClient = "https://github.com/lucasgiovannibr/clientlauncherupdate/archive/refs/heads/main.zip";
string urlVersion = "https://raw.githubusercontent.com/lucasgiovannibr/clientlauncherupdate/main/version.txt";
string currentVersion = "";
string path = AppDomain.CurrentDomain.BaseDirectory.ToString();
public SplashScreen()
{
InitializeComponent();
timer.Tick += new EventHandler(timer_SplashScreen);
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
}
public async void timer_SplashScreen(object? sender, EventArgs e)
{
var requestCurrentVersion = new HttpRequestMessage(HttpMethod.Post, urlVersion);
var responseCurrentVersion = await httpClient.SendAsync(requestCurrentVersion);
currentVersion = await responseCurrentVersion.Content.ReadAsStringAsync();
if (currentVersion == null)
{
this.Close();
}
var requestClient = new HttpRequestMessage(HttpMethod.Post, urlClient);
var response = await httpClient.SendAsync(requestClient);
if (response.StatusCode == HttpStatusCode.NotFound)
{
this.Close();
}
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
MainWindow mainWindow = new MainWindow();
this.Close();
mainWindow.Show();
timer.Stop();
}
}
}