From c53ef735d63b8596f2af6756c7b8a3d3e4eebee3 Mon Sep 17 00:00:00 2001 From: Thomas G <62822072+Thomasluigi07@users.noreply.github.com> Date: Sun, 10 Jul 2022 14:01:03 +1000 Subject: [PATCH] bootstrapper now uses appdata and asks if you want to delete old installs --- ARCHBLOXBootstrapper.sln | 2 +- Form1.cs | 64 ++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/ARCHBLOXBootstrapper.sln b/ARCHBLOXBootstrapper.sln index c8beeec..13b2dd4 100644 --- a/ARCHBLOXBootstrapper.sln +++ b/ARCHBLOXBootstrapper.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32516.85 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARCHBLOXBootstrapper", "ARCHBLOXBootstrapper.csproj", "{F7BD33B8-77AC-42BC-BEAE-DDA874DEA9FC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ARCHBLOXBootstrapper", "ARCHBLOXBootstrapper.csproj", "{F7BD33B8-77AC-42BC-BEAE-DDA874DEA9FC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Form1.cs b/Form1.cs index e6845f1..7a3df8a 100644 --- a/Form1.cs +++ b/Form1.cs @@ -8,6 +8,8 @@ using System.Drawing; using System.Linq; using System.Net; using System.Text; +using System.Security.Permissions; +using Microsoft.Win32; using System.Threading; using System.Threading.Tasks; using System.IO; @@ -15,35 +17,64 @@ using System.DirectoryServices; using System.Windows.Forms; namespace ARCHBLOXBootstrapper { + public partial class ARCHBLOX : Form { public bool IsCompleted = false; + public bool DontEvenBother = false; private static WebClient wc = new WebClient(); private static ManualResetEvent handle = new ManualResetEvent(true); public ARCHBLOX() { InitializeComponent(); + byte[] raw = wc.DownloadData("https://archblox.com/client/version.txt"); + string webData = Encoding.UTF8.GetString(raw); + string version_string = webData; + string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Archblx\", @"Versions\"); + string clientPath = Path.Combine(folderPath, version_string + @"\"); + string filePath = Path.Combine(clientPath, Path.GetFileName(@"https://archblox.com/client/" + version_string + ".zip")); + { + if (Directory.Exists(folderPath)) + { + DialogResult res = MessageBox.Show("Do you want to delete previous installs of ARCHBLOX?", "ARCHBLOX", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (res == DialogResult.Yes) + { + label2.Text = "Removing previous installs..."; + Directory.Delete(folderPath, true); + + } + } + } wc.DownloadProgressChanged += Client_DownloadProgressChanged; wc.DownloadFileCompleted += Client_DownloadFileCompleted; progressBar2.Style = ProgressBarStyle.Marquee; label2.Text = "Configuring ARCHBLOX..."; wc.DownloadProgressChanged += Client_DownloadProgressChanged; wc.DownloadFileCompleted += Client_DownloadFileCompleted; - 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)) + if (Directory.Exists(clientPath)) { - label2.Text = "Removing previous install..."; - Directory.Delete(folderPath, true); + DialogResult res = MessageBox.Show("The latest version of ARCHBLOX is already installed. Do you want to re-install it?", "ARCHBLOX", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (res == DialogResult.Yes) + { + label2.Text = "Removing previous install..."; + Directory.Delete(clientPath, true); + + } + if (res == DialogResult.No) + { + label2.Text = "Cancelled install."; + DontEvenBother = true; + Application.Exit(); + } + } + if (DontEvenBother == false) + { + Directory.CreateDirectory(clientPath); + wc.DownloadFileAsync(new Uri(@"https://archblox.com/client/" + version_string + ".zip"), filePath); + progressBar2.Style = ProgressBarStyle.Blocks; + handle.WaitOne(); } - Directory.CreateDirectory(folderPath); - wc.DownloadFileAsync(new Uri(@"https://archblox.com/client/" + version_string + ".zip"), filePath); - progressBar2.Style = ProgressBarStyle.Blocks; - handle.WaitOne(); } private void ARCHBLOX_Load(object sender, EventArgs e) @@ -58,10 +89,13 @@ namespace ARCHBLOXBootstrapper 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); + string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Archblx\", @"Versions\"); + string clientPath = Path.Combine(folderPath, version_string + @"\"); + string filePath = Path.Combine(clientPath, Path.GetFileName(@"https://archblox.com/client/" + version_string + ".zip")); + ZipFile.ExtractToDirectory(filePath, clientPath); + File.Delete(filePath); label2.Text = "ARCHBLOX has been installed!"; + } }