From 93ad0fb609a2a0b38ae8dd4174b115e4f0dafa87 Mon Sep 17 00:00:00 2001 From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com> Date: Fri, 10 Feb 2023 10:46:58 +0000 Subject: [PATCH] Rework dialog handling for better generic support preparation for FluentDIalog --- Bloxstrap/Bootstrapper.cs | 2 +- Bloxstrap/Dialogs/BootstrapperDialogForm.cs | 36 ++++++++++++++++----- Bloxstrap/Dialogs/IBootstrapperDialog.cs | 4 ++- Bloxstrap/Dialogs/LegacyDialog2009.cs | 4 +-- Bloxstrap/Dialogs/LegacyDialog2011.cs | 4 +-- Bloxstrap/Dialogs/ProgressDialog.cs | 4 +-- Bloxstrap/Dialogs/VistaDialog.cs | 8 ++--- Bloxstrap/Enums/BootstrapperStyle.cs | 11 +++---- Bloxstrap/Views/Pages/AboutPage.xaml | 2 +- 9 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 827c031..31fc182 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -286,7 +286,7 @@ namespace Bloxstrap return; // keep bloxstrap open in the background - Dialog.CloseDialog(); + Dialog.HideBootstrapper(); await gameClient.WaitForExitAsync(); richPresence?.Dispose(); diff --git a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs index 3139b30..6ec3ee1 100644 --- a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs +++ b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs @@ -67,6 +67,11 @@ namespace Bloxstrap.Dialogs } } + public BootstrapperDialogForm(Bootstrapper? bootstrapper = null) + { + Bootstrapper = bootstrapper; + } + public void ScaleWindow() { this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size); @@ -120,6 +125,29 @@ namespace Bloxstrap.Dialogs App.Terminate(); } + public void ShowAsPreview() + { + this.ShowDialog(); + } + + public void ShowAsBootstrapper() + { + System.Windows.Forms.Application.Run(this); + } + + public virtual void HideBootstrapper() + { + if (this.InvokeRequired) + { + this.Invoke(HideBootstrapper); + } + else + { + this.Opacity = 0; + this.ShowInTaskbar = false; + } + } + public virtual void ShowSuccess(string message) { App.ShowMessageBox(message, MessageBoxImage.Information); @@ -132,14 +160,6 @@ namespace Bloxstrap.Dialogs App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE); } - public virtual void CloseDialog() - { - if (this.InvokeRequired) - this.Invoke(CloseDialog); - else - this.Hide(); - } - public void PromptShutdown() { MessageBoxResult result = App.ShowMessageBox( diff --git a/Bloxstrap/Dialogs/IBootstrapperDialog.cs b/Bloxstrap/Dialogs/IBootstrapperDialog.cs index 6b85d07..0887dff 100644 --- a/Bloxstrap/Dialogs/IBootstrapperDialog.cs +++ b/Bloxstrap/Dialogs/IBootstrapperDialog.cs @@ -12,9 +12,11 @@ namespace Bloxstrap.Dialogs bool CancelEnabled { get; set; } void RunBootstrapper(); + void ShowAsPreview(); + void ShowAsBootstrapper(); + void HideBootstrapper(); void ShowSuccess(string message); void ShowError(string message); - void CloseDialog(); void PromptShutdown(); } } diff --git a/Bloxstrap/Dialogs/LegacyDialog2009.cs b/Bloxstrap/Dialogs/LegacyDialog2009.cs index 2d6b4b3..705380e 100644 --- a/Bloxstrap/Dialogs/LegacyDialog2009.cs +++ b/Bloxstrap/Dialogs/LegacyDialog2009.cs @@ -32,12 +32,10 @@ namespace Bloxstrap.Dialogs set => this.buttonCancel.Enabled = value; } - public LegacyDialog2009(Bootstrapper? bootstrapper = null) + public LegacyDialog2009(Bootstrapper? bootstrapper = null) : base(bootstrapper) { InitializeComponent(); - Bootstrapper = bootstrapper; - ScaleWindow(); SetupDialog(); } diff --git a/Bloxstrap/Dialogs/LegacyDialog2011.cs b/Bloxstrap/Dialogs/LegacyDialog2011.cs index 83ad947..ca27498 100644 --- a/Bloxstrap/Dialogs/LegacyDialog2011.cs +++ b/Bloxstrap/Dialogs/LegacyDialog2011.cs @@ -33,11 +33,9 @@ namespace Bloxstrap.Dialogs set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value; } - public LegacyDialog2011(Bootstrapper? bootstrapper = null) + public LegacyDialog2011(Bootstrapper? bootstrapper = null) : base(bootstrapper) { InitializeComponent(); - - Bootstrapper = bootstrapper; // have to convert icon -> bitmap since winforms scaling is poop this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetIcon().ToBitmap(); diff --git a/Bloxstrap/Dialogs/ProgressDialog.cs b/Bloxstrap/Dialogs/ProgressDialog.cs index b76bdee..a7316ca 100644 --- a/Bloxstrap/Dialogs/ProgressDialog.cs +++ b/Bloxstrap/Dialogs/ProgressDialog.cs @@ -34,7 +34,7 @@ namespace Bloxstrap.Dialogs set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value; } - public ProgressDialog(Bootstrapper? bootstrapper = null) + public ProgressDialog(Bootstrapper? bootstrapper = null) : base(bootstrapper) { InitializeComponent(); @@ -46,8 +46,6 @@ namespace Bloxstrap.Dialogs this.BackColor = Color.FromArgb(25, 27, 29); } - Bootstrapper = bootstrapper; - this.IconBox.BackgroundImage = App.Settings.Prop.BootstrapperIcon.GetBitmap(); SetupDialog(); diff --git a/Bloxstrap/Dialogs/VistaDialog.cs b/Bloxstrap/Dialogs/VistaDialog.cs index ff2cc01..fdde6d7 100644 --- a/Bloxstrap/Dialogs/VistaDialog.cs +++ b/Bloxstrap/Dialogs/VistaDialog.cs @@ -60,12 +60,10 @@ namespace Bloxstrap.Dialogs set => Dialog.Buttons[0].Enabled = value; } - public VistaDialog(Bootstrapper? bootstrapper = null) + public VistaDialog(Bootstrapper? bootstrapper = null) : base(bootstrapper) { InitializeComponent(); - Bootstrapper = bootstrapper; - Dialog = new TaskDialogPage() { Icon = new TaskDialogIcon(App.Settings.Prop.BootstrapperIcon.GetIcon()), @@ -143,11 +141,11 @@ namespace Bloxstrap.Dialogs } } - public override void CloseDialog() + public override void HideBootstrapper() { if (this.InvokeRequired) { - this.Invoke(CloseDialog); + this.Invoke(HideBootstrapper); } else { diff --git a/Bloxstrap/Enums/BootstrapperStyle.cs b/Bloxstrap/Enums/BootstrapperStyle.cs index 32f1c5f..fc9f7ba 100644 --- a/Bloxstrap/Enums/BootstrapperStyle.cs +++ b/Bloxstrap/Enums/BootstrapperStyle.cs @@ -16,7 +16,7 @@ namespace Bloxstrap.Enums { public static void Show(this BootstrapperStyle bootstrapperStyle, Bootstrapper? bootstrapper = null) { - Form dialog = bootstrapperStyle switch + IBootstrapperDialog dialog = bootstrapperStyle switch { BootstrapperStyle.VistaDialog => new VistaDialog(bootstrapper), BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(bootstrapper), @@ -27,17 +27,14 @@ namespace Bloxstrap.Enums if (bootstrapper is null) { - dialog.ShowDialog(); + dialog.ShowAsPreview(); } else { if (App.IsQuiet) - { - dialog.Opacity = 0; - dialog.ShowInTaskbar = false; - } + dialog.HideBootstrapper(); - Application.Run(dialog); + dialog.ShowAsBootstrapper(); } } } diff --git a/Bloxstrap/Views/Pages/AboutPage.xaml b/Bloxstrap/Views/Pages/AboutPage.xaml index 1aa010e..b2c00df 100644 --- a/Bloxstrap/Views/Pages/AboutPage.xaml +++ b/Bloxstrap/Views/Pages/AboutPage.xaml @@ -108,7 +108,7 @@ - +