bootstrapper now uses appdata and asks if you want to delete old installs

This commit is contained in:
Thomas G 2022-07-10 14:01:03 +10:00
parent 83230fe5ab
commit c53ef735d6
2 changed files with 50 additions and 16 deletions

View File

@ -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

View File

@ -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!";
}
}