From 83230fe5ab7ebb588676505539a64ef40537010e Mon Sep 17 00:00:00 2001 From: Thomas G <62822072+Thomasluigi07@users.noreply.github.com> Date: Sat, 9 Jul 2022 22:01:54 +1000 Subject: [PATCH] it can actually download clients now wtf --- Form1.cs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Form1.cs b/Form1.cs index 55be0ad..e6845f1 100644 --- a/Form1.cs +++ b/Form1.cs @@ -17,6 +17,7 @@ namespace ARCHBLOXBootstrapper { public partial class ARCHBLOX : Form { + public bool IsCompleted = false; private static WebClient wc = new WebClient(); private static ManualResetEvent handle = new ManualResetEvent(true); @@ -29,11 +30,18 @@ namespace ARCHBLOXBootstrapper label2.Text = "Configuring ARCHBLOX..."; wc.DownloadProgressChanged += Client_DownloadProgressChanged; wc.DownloadFileCompleted += Client_DownloadFileCompleted; - string fileName = System.IO.Path.GetFileName(@"https://archblox.com/img/ARCHBLOXarched.png"); - string folderPath = Path.Combine(@"%LocalAppData%", @"\ARCHBLOX\"); - string filePath = Path.Combine(folderPath, "test.png"); + byte[] raw = wc.DownloadData("https://archblox.com/client/version.txt"); + string webData = Encoding.UTF8.GetString(raw); + string version_string = webData; + string folderPath = Path.Combine(@"C:\ARCHBLOX\", version_string + @"\"); + string filePath = Path.Combine(folderPath, Path.GetFileName(@"https://archblox.com/client/" + version_string + ".zip")); + if (Directory.Exists(folderPath)) + { + label2.Text = "Removing previous install..."; + Directory.Delete(folderPath, true); + } Directory.CreateDirectory(folderPath); - wc.DownloadFileAsync(new Uri(@"https://archblox.com/img/ARCHBLOXarched.png"), filePath); + wc.DownloadFileAsync(new Uri(@"https://archblox.com/client/" + version_string + ".zip"), filePath); progressBar2.Style = ProgressBarStyle.Blocks; handle.WaitOne(); } @@ -44,8 +52,17 @@ namespace ARCHBLOXBootstrapper } private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { - label2.Text = "ARCHBLOX has been installed!"; - handle.WaitOne(); + if (IsCompleted == false) + { + IsCompleted = true; + byte[] raw = wc.DownloadData("https://archblox.com/client/version.txt"); + string webData = Encoding.UTF8.GetString(raw); + string version_string = webData; + string folderPath = Path.Combine(@"C:\ARCHBLOX\", version_string + @"\"); + string filePath = Path.Combine(folderPath, Path.GetFileName(@"https://archblox.com/client/" + version_string + ".zip")); + ZipFile.ExtractToDirectory(filePath, folderPath); + label2.Text = "ARCHBLOX has been installed!"; + } } private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)