This commit is contained in:
Thomas G 2022-08-05 10:36:07 +10:00
parent 82b7984a63
commit 2fbbdd390e
5 changed files with 83 additions and 19 deletions

View File

@ -59,6 +59,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="URI_Maker.cs" />
<EmbeddedResource Include="Form2.resx">
<DependentUpon>Form2.cs</DependentUpon>
</EmbeddedResource>

View File

@ -9,11 +9,12 @@ using System.Threading;
using System.IO;
using System.Windows.Forms;
namespace ARCHBLOXBootstrapper_XP
{
{
public partial class ARCHBLOX : Form
{
// set up variables
public bool IsCompleted = false;
public bool exitafterarg = false;
public bool DontEvenBother = false;
private static WebClient wc = new WebClient();
private static ManualResetEvent handle = new ManualResetEvent(true);
@ -33,20 +34,33 @@ namespace ARCHBLOXBootstrapper_XP
public ARCHBLOX()
{
InitializeComponent();
// check for an internet connection first
try
{
wc.DownloadData("http://archblox.com/studio/version.txt");
}
catch
{
MessageBox.Show("An error occoured while starting ARCHBLOX Studio\n\nDetails: HttpOpenRequest failed for GET http://archblox.com/studio/version.txt, Error ID: 6", "ARCHBLOX", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(0);
}
// setup paths
byte[] raw = wc.DownloadData("http://archblox.com/studio/version.txt");
CreateShortcut();
string webData = Encoding.UTF8.GetString(raw);
string version_string = webData;
string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Archblx\", @"Studio\", @"Versions\");
string clientPath = Path.Combine(folderPath, version_string + @"\");
string filePath = Path.Combine(clientPath, Path.GetFileName(@"http://archblox.com/client/" + version_string + ".zip"));
string studioPath = Path.Combine(clientPath, "ArchbloxStudio.exe");
ARCHBLOXProtocol.ARCHBLOXURIProtocol.Register();
CreateShortcut();
// TODO: Make studio place launching URI.
if (Directory.Exists(clientPath) & System.IO.File.Exists(studioPath))
{
// studio exists, create shortcut and launch studio
label1.Text = "Launching Studio...";
DontEvenBother = true;
CreateShortcut();
var pProcess = new Process();
pProcess.StartInfo.FileName = studioPath;
pProcess.StartInfo.UseShellExecute = false;
@ -69,8 +83,6 @@ namespace ARCHBLOXBootstrapper_XP
wc.DownloadProgressChanged += Client_DownloadProgressChanged;
wc.DownloadFileCompleted += Client_DownloadFileCompleted;
progressBar2.Style = ProgressBarStyle.Marquee;
wc.DownloadProgressChanged += Client_DownloadProgressChanged;
wc.DownloadFileCompleted += Client_DownloadFileCompleted;
if (DontEvenBother == false)
{
// install studio
@ -79,7 +91,8 @@ namespace ARCHBLOXBootstrapper_XP
wc.DownloadFileAsync(new Uri(@"http://archblox.com/studio/" + version_string + ".zip"), filePath);
progressBar2.Style = ProgressBarStyle.Blocks;
handle.WaitOne();
} else
}
else
{
// close program
Thread.Sleep(3000);
@ -89,7 +102,7 @@ namespace ARCHBLOXBootstrapper_XP
private void ARCHBLOX_Load(object sender, EventArgs e)
{
// nothing
// nothing
}
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
@ -107,6 +120,7 @@ namespace ARCHBLOXBootstrapper_XP
Extensions.UnZip(filePath, clientPath);
System.IO.File.Delete(filePath);
label2.Text = "ARCHBLOX Studio has been installed!";
CreateShortcut();
var pProcess = new Process();
pProcess.StartInfo.FileName = studioPath;
pProcess.StartInfo.UseShellExecute = false;

View File

@ -69,35 +69,35 @@
// pictureBox2
//
this.pictureBox2.BackgroundImage = global::ARCHBLOXBootstrapper_XP.Properties.Resources.archblox1;
this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox2.Location = new System.Drawing.Point(3, 6);
this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.pictureBox2.Location = new System.Drawing.Point(18, 17);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(46, 46);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.Size = new System.Drawing.Size(35, 42);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox2.TabIndex = 0;
this.pictureBox2.TabStop = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(55, 6);
this.label2.Location = new System.Drawing.Point(58, 18);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(117, 13);
this.label2.Size = new System.Drawing.Size(237, 21);
this.label2.TabIndex = 1;
this.label2.Text = "Checking for updates...";
this.label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
// progressBar2
//
this.progressBar2.Location = new System.Drawing.Point(55, 29);
this.progressBar2.Location = new System.Drawing.Point(58, 51);
this.progressBar2.MarqueeAnimationSpeed = 10;
this.progressBar2.Name = "progressBar2";
this.progressBar2.Size = new System.Drawing.Size(217, 23);
this.progressBar2.Size = new System.Drawing.Size(287, 26);
this.progressBar2.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
this.progressBar2.TabIndex = 2;
//
// ARCHBLOX
//
this.ClientSize = new System.Drawing.Size(286, 59);
this.ClientSize = new System.Drawing.Size(362, 146);
this.Controls.Add(this.progressBar2);
this.Controls.Add(this.label2);
this.Controls.Add(this.pictureBox2);
@ -106,11 +106,10 @@
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ARCHBLOX";
this.Text = "ARCHBLOX Installer";
this.Text = "ARCHBLOX Studio";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@ -11,10 +11,17 @@ namespace ARCHBLOXBootstrapper_XP
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
{
foreach (string s in args)
{
ARCHBLOXProtocol.SharedVariables.Arguments = s;
}
}
Application.Run(new ARCHBLOX());
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Windows.Forms;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Text;
using System.Net;
using System.IO;
namespace ARCHBLOXProtocol
{
class SharedVariables
{
public static string Arguments = "";
};
internal static class ARCHBLOXURIProtocol
{
private static RegistryKey softwareClasses = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Classes", true);
internal static void Register()
{
// credit to p0s0 for helping me with this
if (softwareClasses.OpenSubKey("archbloxstudio") == null) {} else { softwareClasses.DeleteSubKeyTree("archbloxstudio"); }
RegistryKey key = softwareClasses.CreateSubKey("archbloxstudio");
key.SetValue("", "URL: archbloxstudio Protocol");
key.SetValue("URL Protocol", "");
RegistryKey key1 = key.CreateSubKey("DefaultIcon");
key1.SetValue("", ARCHBLOXBootstrapper_XP.Extensions.GetExecutablePath());
RegistryKey key2 = key.CreateSubKey("shell");
RegistryKey key3 = key2.CreateSubKey("open");
RegistryKey key4 = key3.CreateSubKey("command");
key4.SetValue("", "\"" + ARCHBLOXBootstrapper_XP.Extensions.GetExecutablePath() + "\" %1");
key.Close();
key1.Close();
key2.Close();
key3.Close();
key4.Close();
}
}
}