From db762429cf33f79a94de4caed02817a1789c083c Mon Sep 17 00:00:00 2001 From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com> Date: Sun, 20 Nov 2022 14:17:50 +0000 Subject: [PATCH] Work on implementing quiet installing Just got to work on hiding the bootstrapper dialog -- might have to rework how the bootstrapper class is instantiated. --- Bloxstrap/Bootstrapper.cs | 16 ++++++++--- .../BootstrapperDialogForm.cs | 7 +++-- .../VistaDialog.Designer.cs | 2 +- .../BootstrapperDialogs/VistaDialog.cs | 15 ++++++---- Bloxstrap/Helpers/Updater.cs | 4 +-- Bloxstrap/Program.cs | 28 ++++++++++++++++--- 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index e2b20aa..7e8f66c 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -17,6 +17,13 @@ namespace Bloxstrap public partial class Bootstrapper { #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 // 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? @@ -91,7 +98,7 @@ namespace Bloxstrap // this is called from BootstrapperStyleForm.SetupDialog() public async Task Run() { - if (LaunchCommandLine == "-uninstall") + if (Program.IsUninstall) { Uninstall(); return; @@ -122,7 +129,8 @@ namespace Bloxstrap Program.SettingsManager.Save(); - await StartRoblox(); + if (!Program.IsQuiet) + await StartRoblox(); Program.Exit(); } @@ -239,7 +247,7 @@ namespace Bloxstrap { if (!Dialog.CancelEnabled) { - Program.Exit(); + Program.Exit(ERROR_INSTALL_USEREXIT); return; } @@ -254,7 +262,7 @@ namespace Bloxstrap } catch (Exception) { } - Program.Exit(); + Program.Exit(ERROR_INSTALL_USEREXIT); } #endregion diff --git a/Bloxstrap/Dialogs/BootstrapperDialogs/BootstrapperDialogForm.cs b/Bloxstrap/Dialogs/BootstrapperDialogs/BootstrapperDialogForm.cs index 8e28406..adac9b6 100644 --- a/Bloxstrap/Dialogs/BootstrapperDialogs/BootstrapperDialogForm.cs +++ b/Bloxstrap/Dialogs/BootstrapperDialogs/BootstrapperDialogForm.cs @@ -61,6 +61,9 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs public void SetupDialog() { + if (Program.IsQuiet) + this.Hide(); + this.Text = Program.ProjectName; this.Icon = Program.Settings.BootstrapperIcon.GetIcon(); @@ -107,7 +110,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs public virtual void ShowError(string message) { 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() @@ -127,7 +130,7 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs ); if (result != DialogResult.OK) - Environment.Exit(0); + Environment.Exit(Bootstrapper.ERROR_INSTALL_USEREXIT); } public void ButtonCancel_Click(object? sender, EventArgs e) diff --git a/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.Designer.cs b/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.Designer.cs index 8f1d397..e2d27d5 100644 --- a/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.Designer.cs +++ b/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.Designer.cs @@ -41,7 +41,7 @@ this.ShowInTaskbar = false; this.Text = "VistaDialog"; 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); } diff --git a/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.cs b/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.cs index c49a6f4..e1e8e0a 100644 --- a/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.cs +++ b/Bloxstrap/Dialogs/BootstrapperDialogs/VistaDialog.cs @@ -101,7 +101,9 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs successDialog.Buttons[0].Click += (sender, e) => Program.Exit(); - Dialog.Navigate(successDialog); + if (!Program.IsQuiet) + Dialog.Navigate(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; } } @@ -152,9 +156,10 @@ namespace Bloxstrap.Dialogs.BootstrapperDialogs } - private void TestDialog_Load(object sender, EventArgs e) + private void VistaDialog_Load(object sender, EventArgs e) { - TaskDialog.ShowDialog(Dialog); + if (!Program.IsQuiet) + TaskDialog.ShowDialog(Dialog); } } } diff --git a/Bloxstrap/Helpers/Updater.cs b/Bloxstrap/Helpers/Updater.cs index a6a8695..c3964aa 100644 --- a/Bloxstrap/Helpers/Updater.cs +++ b/Bloxstrap/Helpers/Updater.cs @@ -53,7 +53,7 @@ namespace Bloxstrap.Helpers public static async Task Check() { - if (Environment.ProcessPath is null) + if (Environment.ProcessPath is null || Program.IsUninstall || Program.IsQuiet && Program.IsFirstRun) return; if (!Program.IsFirstRun) @@ -86,7 +86,7 @@ namespace Bloxstrap.Helpers if (result == DialogResult.Yes) { Utilities.OpenWebsite($"https://github.com/{Program.ProjectRepository}/releases/latest"); - Program.Exit(); + Program.Exit(Bootstrapper.ERROR_INSTALL_USEREXIT); } } } diff --git a/Bloxstrap/Program.cs b/Bloxstrap/Program.cs index 3292d79..2697786 100644 --- a/Bloxstrap/Program.cs +++ b/Bloxstrap/Program.cs @@ -11,6 +11,8 @@ using Bloxstrap.Dialogs; using System.Net.Http; using System.Net; using System.Reflection; +using Newtonsoft.Json.Linq; +using System; namespace Bloxstrap { @@ -31,6 +33,8 @@ namespace Bloxstrap public static string BaseDirectory = null!; 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 StartMenu { get; private set; } = null!; @@ -44,13 +48,16 @@ namespace Bloxstrap // shorthand 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); } - public static void Exit() + public static void Exit(int code = Bootstrapper.ERROR_SUCCESS) { SettingsManager.Save(); - Environment.Exit(0); + Environment.Exit(code); } /// @@ -69,14 +76,27 @@ namespace Bloxstrap LocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); StartMenu = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", ProjectName); - // check if installed + if (args.Length > 0) + { + if (Array.IndexOf(args, "-quiet") != -1) + IsQuiet = true; + + if (Array.IndexOf(args, "-uninstall") != -1) + IsUninstall = true; + } + + // check if installed RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey($@"Software\{ProjectName}"); if (registryKey is null) { IsFirstRun = true; Settings = SettingsManager.Settings; - new Preferences().ShowDialog(); + + if (IsQuiet) + BaseDirectory = Path.Combine(LocalAppData, ProjectName); + else + new Preferences().ShowDialog(); } else {