Work on implementing quiet installing

Just got to work on hiding the bootstrapper dialog -- might have to rework how the bootstrapper class is instantiated.
This commit is contained in:
pizzaboxer 2022-11-20 14:17:50 +00:00
parent 9244234860
commit db762429cf
6 changed files with 54 additions and 18 deletions

View File

@ -17,6 +17,13 @@ namespace Bloxstrap
public partial class Bootstrapper public partial class Bootstrapper
{ {
#region Properties #region Properties
// https://learn.microsoft.com/en-us/windows/win32/msi/error-codes
public const int ERROR_SUCCESS = 0;
public const int ERROR_INSTALL_USEREXIT = 1602;
public const int ERROR_INSTALL_FAILURE = 1603;
public const int ERROR_PRODUCT_UNINSTALLED = 1614;
// in case a new package is added, you can find the corresponding directory // in case a new package is added, you can find the corresponding directory
// by opening the stock bootstrapper in a hex editor // by opening the stock bootstrapper in a hex editor
// TODO - there ideally should be a less static way to do this that's not hardcoded? // TODO - there ideally should be a less static way to do this that's not hardcoded?
@ -91,7 +98,7 @@ namespace Bloxstrap
// this is called from BootstrapperStyleForm.SetupDialog() // this is called from BootstrapperStyleForm.SetupDialog()
public async Task Run() public async Task Run()
{ {
if (LaunchCommandLine == "-uninstall") if (Program.IsUninstall)
{ {
Uninstall(); Uninstall();
return; return;
@ -122,6 +129,7 @@ namespace Bloxstrap
Program.SettingsManager.Save(); Program.SettingsManager.Save();
if (!Program.IsQuiet)
await StartRoblox(); await StartRoblox();
Program.Exit(); Program.Exit();
@ -239,7 +247,7 @@ namespace Bloxstrap
{ {
if (!Dialog.CancelEnabled) if (!Dialog.CancelEnabled)
{ {
Program.Exit(); Program.Exit(ERROR_INSTALL_USEREXIT);
return; return;
} }
@ -254,7 +262,7 @@ namespace Bloxstrap
} }
catch (Exception) { } catch (Exception) { }
Program.Exit(); Program.Exit(ERROR_INSTALL_USEREXIT);
} }
#endregion #endregion

View File

@ -61,6 +61,9 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
public void SetupDialog() public void SetupDialog()
{ {
if (Program.IsQuiet)
this.Hide();
this.Text = Program.ProjectName; this.Text = Program.ProjectName;
this.Icon = Program.Settings.BootstrapperIcon.GetIcon(); this.Icon = Program.Settings.BootstrapperIcon.GetIcon();
@ -107,7 +110,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
public virtual void ShowError(string message) public virtual void ShowError(string message)
{ {
Program.ShowMessageBox($"An error occurred while starting Roblox\n\nDetails: {message}", MessageBoxIcon.Error); Program.ShowMessageBox($"An error occurred while starting Roblox\n\nDetails: {message}", MessageBoxIcon.Error);
Program.Exit(); Program.Exit(Bootstrapper.ERROR_INSTALL_FAILURE);
} }
public virtual void CloseDialog() public virtual void CloseDialog()
@ -127,7 +130,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
); );
if (result != DialogResult.OK) if (result != DialogResult.OK)
Environment.Exit(0); Environment.Exit(Bootstrapper.ERROR_INSTALL_USEREXIT);
} }
public void ButtonCancel_Click(object? sender, EventArgs e) public void ButtonCancel_Click(object? sender, EventArgs e)

View File

@ -41,7 +41,7 @@
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.Text = "VistaDialog"; this.Text = "VistaDialog";
this.WindowState = System.Windows.Forms.FormWindowState.Minimized; this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Load += new System.EventHandler(this.TestDialog_Load); this.Load += new System.EventHandler(this.VistaDialog_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
} }

View File

@ -101,7 +101,9 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
successDialog.Buttons[0].Click += (sender, e) => Program.Exit(); successDialog.Buttons[0].Click += (sender, e) => Program.Exit();
if (!Program.IsQuiet)
Dialog.Navigate(successDialog); Dialog.Navigate(successDialog);
Dialog = successDialog; Dialog = successDialog;
} }
} }
@ -129,9 +131,11 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
} }
}; };
errorDialog.Buttons[0].Click += (sender, e) => Program.Exit(); errorDialog.Buttons[0].Click += (sender, e) => Program.Exit(Bootstrapper.ERROR_INSTALL_FAILURE);
if (!Program.IsQuiet)
Dialog.Navigate(errorDialog); Dialog.Navigate(errorDialog);
Dialog = errorDialog; Dialog = errorDialog;
} }
} }
@ -152,8 +156,9 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs
} }
private void TestDialog_Load(object sender, EventArgs e) private void VistaDialog_Load(object sender, EventArgs e)
{ {
if (!Program.IsQuiet)
TaskDialog.ShowDialog(Dialog); TaskDialog.ShowDialog(Dialog);
} }
} }

View File

@ -53,7 +53,7 @@ namespace Bloxstrap.Helpers
public static async Task Check() public static async Task Check()
{ {
if (Environment.ProcessPath is null) if (Environment.ProcessPath is null || Program.IsUninstall || Program.IsQuiet && Program.IsFirstRun)
return; return;
if (!Program.IsFirstRun) if (!Program.IsFirstRun)
@ -86,7 +86,7 @@ namespace Bloxstrap.Helpers
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
Utilities.OpenWebsite($"https://github.com/{Program.ProjectRepository}/releases/latest"); Utilities.OpenWebsite($"https://github.com/{Program.ProjectRepository}/releases/latest");
Program.Exit(); Program.Exit(Bootstrapper.ERROR_INSTALL_USEREXIT);
} }
} }
} }

View File

@ -11,6 +11,8 @@ using Bloxstrap.Dialogs;
using System.Net.Http; using System.Net.Http;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using Newtonsoft.Json.Linq;
using System;
namespace Bloxstrap namespace Bloxstrap
{ {
@ -31,6 +33,8 @@ namespace Bloxstrap
public static string BaseDirectory = null!; public static string BaseDirectory = null!;
public static bool IsFirstRun { get; private set; } = false; public static bool IsFirstRun { get; private set; } = false;
public static bool IsQuiet { get; private set; } = false;
public static bool IsUninstall { get; private set; } = false;
public static string LocalAppData { get; private set; } = null!; public static string LocalAppData { get; private set; } = null!;
public static string StartMenu { get; private set; } = null!; public static string StartMenu { get; private set; } = null!;
@ -44,13 +48,16 @@ namespace Bloxstrap
// shorthand // shorthand
public static DialogResult ShowMessageBox(string message, MessageBoxIcon icon = MessageBoxIcon.None, MessageBoxButtons buttons = MessageBoxButtons.OK) public static DialogResult ShowMessageBox(string message, MessageBoxIcon icon = MessageBoxIcon.None, MessageBoxButtons buttons = MessageBoxButtons.OK)
{ {
if (IsQuiet)
return DialogResult.None;
return MessageBox.Show(message, ProjectName, buttons, icon); return MessageBox.Show(message, ProjectName, buttons, icon);
} }
public static void Exit() public static void Exit(int code = Bootstrapper.ERROR_SUCCESS)
{ {
SettingsManager.Save(); SettingsManager.Save();
Environment.Exit(0); Environment.Exit(code);
} }
/// <summary> /// <summary>
@ -69,6 +76,15 @@ namespace Bloxstrap
LocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); LocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
StartMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", ProjectName); StartMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", ProjectName);
if (args.Length > 0)
{
if (Array.IndexOf(args, "-quiet") != -1)
IsQuiet = true;
if (Array.IndexOf(args, "-uninstall") != -1)
IsUninstall = true;
}
// check if installed // check if installed
RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey($@"Software\{ProjectName}"); RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey($@"Software\{ProjectName}");
@ -76,6 +92,10 @@ namespace Bloxstrap
{ {
IsFirstRun = true; IsFirstRun = true;
Settings = SettingsManager.Settings; Settings = SettingsManager.Settings;
if (IsQuiet)
BaseDirectory = Path.Combine(LocalAppData, ProjectName);
else
new Preferences().ShowDialog(); new Preferences().ShowDialog();
} }
else else