forked from Fumo-Unlockers/Xbox-Achievement-Unlocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.cs
78 lines (75 loc) · 3.4 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.IO;
using static System.Windows.Forms.LinkLabel;
using Newtonsoft.Json.Linq;
using System.Net.Http;
namespace Xbox_Achievement_Unlocker
{
public partial class Updater : Form
{
public Updater()
{
InitializeComponent();
}
static HttpClientHandler handler = new HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
};
HttpClient client = new HttpClient(handler);
async void BTN_Yes_Click(object sender, EventArgs e)
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Host", "api.github.com");
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
var responseString = await client.GetStringAsync("https://api.github.com/repos/ItsLogic/Xbox-Achievement-unlocker/releases");
var Jsonresponse = (dynamic)(new JArray());
Jsonresponse = (dynamic)JArray.Parse(responseString);
WebClient webClient = new WebClient();
string sourceFile = Jsonresponse[0].assets[0].browser_download_url.ToString();
string destFile = @"XAU-new.exe";
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri(sourceFile), destFile);
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void DownloadCompleted(object sender, AsyncCompletedEventArgs e)
{
var path = Environment.ProcessPath.ToString();
string[] splitpath = path.Split("\\");
using (StreamWriter writer = new StreamWriter("XAU-Updater.bat"))
{
writer.WriteLine("@echo off");
writer.WriteLine("del \"" + Environment.ProcessPath + "\" ");
writer.WriteLine("del \"" + splitpath[splitpath.Count() - 1] + "\" ");
writer.WriteLine("ren XAU-new.exe \"" + splitpath[splitpath.Count() - 1] + "\" ");
writer.WriteLine("start \"\" " + "\"" + splitpath[splitpath.Count() - 1] + "\"");
writer.WriteLine("goto 2 > nul & del \"%~f0\"");
}
Process proc = new Process();
proc.StartInfo.FileName = "XAU-Updater.bat";
proc.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
proc.Start();
Application.Exit();
}
private void BTN_No_Click(object sender, EventArgs e)
{
Updater.ActiveForm.Close();
}
}
}