diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index b473996..569cd76 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -9,9 +9,10 @@ using System.Threading.Tasks; using System.Windows; using Microsoft.Win32; -using Bloxstrap.Models; +using Bloxstrap.Dialogs; using Bloxstrap.Enums; using Bloxstrap.Helpers; +using Bloxstrap.Models; using Bloxstrap.Views; namespace Bloxstrap @@ -56,6 +57,7 @@ namespace Bloxstrap { Settings.Save(); State.Save(); + Debug.WriteLine($"[App] Terminating with exit code {code}"); Environment.Exit(code); } @@ -169,17 +171,19 @@ namespace Bloxstrap DeployManager.Channel = Settings.Prop.Channel; + // start bootstrapper and show the bootstrapper modal if we're not running silently Bootstrapper bootstrapper = new Bootstrapper(commandLine); + IBootstrapperDialog? dialog = null; - if (IsQuiet) + if (!IsQuiet) { - //Task bootstrappertask = new Task(() => bootstrapper.Run()); - Task.Run(() => bootstrapper.Run()).Wait(); - } - else - { - Settings.Prop.BootstrapperStyle.Show(bootstrapper); + dialog = Settings.Prop.BootstrapperStyle.GetNew(); + bootstrapper.Dialog = dialog; } + + Task bootstrapperTask = Task.Run(() => bootstrapper.Run()); + dialog?.ShowBootstrapper(); + bootstrapperTask.Wait(); } Terminate(); diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index bebdea5..4e14ac5 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -294,7 +294,7 @@ namespace Bloxstrap return; // keep bloxstrap open in the background - Dialog?.HideBootstrapper(); + Dialog?.CloseBootstrapper(); await gameClient.WaitForExitAsync(); richPresence?.Dispose(); diff --git a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs index 6ec3ee1..e1e6f70 100644 --- a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs +++ b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs @@ -10,10 +10,6 @@ namespace Bloxstrap.Dialogs { public class BootstrapperDialogForm : Form, IBootstrapperDialog { - public Bootstrapper? Bootstrapper { get; set; } - - protected override bool ShowWithoutActivation => App.IsQuiet; - protected virtual string _message { get; set; } = "Please wait..."; protected virtual ProgressBarStyle _progressStyle { get; set; } protected virtual int _progressValue { get; set; } @@ -67,11 +63,6 @@ namespace Bloxstrap.Dialogs } } - public BootstrapperDialogForm(Bootstrapper? bootstrapper = null) - { - Bootstrapper = bootstrapper; - } - public void ScaleWindow() { this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size); @@ -88,63 +79,19 @@ namespace Bloxstrap.Dialogs { this.Text = App.ProjectName; this.Icon = App.Settings.Prop.BootstrapperIcon.GetIcon(); - - if (Bootstrapper is null) - { - Message = "Style preview - Click Cancel to close"; - CancelEnabled = true; - } - else - { - Bootstrapper.Dialog = this; - Task.Run(RunBootstrapper); - } } + public void ShowBootstrapper() => this.ShowDialog(); - public async void RunBootstrapper() - { - if (Bootstrapper is null) - return; - -#if DEBUG - await Bootstrapper.Run(); -#else - try - { - await Bootstrapper.Run(); - } - catch (Exception ex) - { - // string message = String.Format("{0}: {1}", ex.GetType(), ex.Message); - string message = ex.ToString(); - ShowError(message); - } -#endif - - App.Terminate(); - } - - public void ShowAsPreview() - { - this.ShowDialog(); - } - - public void ShowAsBootstrapper() - { - System.Windows.Forms.Application.Run(this); - } - - public virtual void HideBootstrapper() + public virtual void CloseBootstrapper() { if (this.InvokeRequired) { - this.Invoke(HideBootstrapper); + this.Invoke(CloseBootstrapper); } else { - this.Opacity = 0; - this.ShowInTaskbar = false; + this.Close(); } } @@ -174,10 +121,7 @@ namespace Bloxstrap.Dialogs public void ButtonCancel_Click(object? sender, EventArgs e) { - if (Bootstrapper is null) - this.Close(); - else - Task.Run(() => Bootstrapper.CancelButtonClicked()); + this.Close(); } } } diff --git a/Bloxstrap/Dialogs/IBootstrapperDialog.cs b/Bloxstrap/Dialogs/IBootstrapperDialog.cs index 0887dff..eff0e7b 100644 --- a/Bloxstrap/Dialogs/IBootstrapperDialog.cs +++ b/Bloxstrap/Dialogs/IBootstrapperDialog.cs @@ -4,17 +4,13 @@ namespace Bloxstrap.Dialogs { public interface IBootstrapperDialog { - Bootstrapper? Bootstrapper { get; set; } - string Message { get; set; } ProgressBarStyle ProgressStyle { get; set; } int ProgressValue { get; set; } bool CancelEnabled { get; set; } - void RunBootstrapper(); - void ShowAsPreview(); - void ShowAsBootstrapper(); - void HideBootstrapper(); + void ShowBootstrapper(); + void CloseBootstrapper(); void ShowSuccess(string message); void ShowError(string message); void PromptShutdown(); diff --git a/Bloxstrap/Dialogs/LegacyDialog2009.cs b/Bloxstrap/Dialogs/LegacyDialog2009.cs index 705380e..684870b 100644 --- a/Bloxstrap/Dialogs/LegacyDialog2009.cs +++ b/Bloxstrap/Dialogs/LegacyDialog2009.cs @@ -32,7 +32,7 @@ namespace Bloxstrap.Dialogs set => this.buttonCancel.Enabled = value; } - public LegacyDialog2009(Bootstrapper? bootstrapper = null) : base(bootstrapper) + public LegacyDialog2009() { InitializeComponent(); diff --git a/Bloxstrap/Dialogs/LegacyDialog2011.cs b/Bloxstrap/Dialogs/LegacyDialog2011.cs index ca27498..1c21c5b 100644 --- a/Bloxstrap/Dialogs/LegacyDialog2011.cs +++ b/Bloxstrap/Dialogs/LegacyDialog2011.cs @@ -33,7 +33,7 @@ namespace Bloxstrap.Dialogs set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value; } - public LegacyDialog2011(Bootstrapper? bootstrapper = null) : base(bootstrapper) + public LegacyDialog2011() { InitializeComponent(); diff --git a/Bloxstrap/Dialogs/ProgressDialog.cs b/Bloxstrap/Dialogs/ProgressDialog.cs index a7316ca..a1ec9ec 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) : base(bootstrapper) + public ProgressDialog() { InitializeComponent(); diff --git a/Bloxstrap/Dialogs/VistaDialog.cs b/Bloxstrap/Dialogs/VistaDialog.cs index fdde6d7..bbc9f97 100644 --- a/Bloxstrap/Dialogs/VistaDialog.cs +++ b/Bloxstrap/Dialogs/VistaDialog.cs @@ -60,7 +60,7 @@ namespace Bloxstrap.Dialogs set => Dialog.Buttons[0].Enabled = value; } - public VistaDialog(Bootstrapper? bootstrapper = null) : base(bootstrapper) + public VistaDialog() { InitializeComponent(); @@ -102,9 +102,7 @@ namespace Bloxstrap.Dialogs successDialog.Buttons[0].Click += (sender, e) => App.Terminate(); - if (!App.IsQuiet) - Dialog.Navigate(successDialog); - + Dialog.Navigate(successDialog); Dialog = successDialog; } } @@ -134,33 +132,29 @@ namespace Bloxstrap.Dialogs errorDialog.Buttons[0].Click += (sender, e) => App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE); - if (!App.IsQuiet) - Dialog.Navigate(errorDialog); + Dialog.Navigate(errorDialog); Dialog = errorDialog; } } - public override void HideBootstrapper() + public override void CloseBootstrapper() { if (this.InvokeRequired) { - this.Invoke(HideBootstrapper); + this.Invoke(CloseBootstrapper); } else { - if (Dialog.BoundDialog is null) - return; - - Dialog.BoundDialog.Close(); + Dialog.BoundDialog?.Close(); + base.CloseBootstrapper(); } } private void VistaDialog_Load(object sender, EventArgs e) { - if (!App.IsQuiet) - TaskDialog.ShowDialog(Dialog); + TaskDialog.ShowDialog(Dialog); } } } diff --git a/Bloxstrap/Enums/BootstrapperStyle.cs b/Bloxstrap/Enums/BootstrapperStyle.cs index fc9f7ba..9fadd0f 100644 --- a/Bloxstrap/Enums/BootstrapperStyle.cs +++ b/Bloxstrap/Enums/BootstrapperStyle.cs @@ -14,28 +14,16 @@ namespace Bloxstrap.Enums public static class BootstrapperStyleEx { - public static void Show(this BootstrapperStyle bootstrapperStyle, Bootstrapper? bootstrapper = null) + public static IBootstrapperDialog GetNew(this BootstrapperStyle bootstrapperStyle) { - IBootstrapperDialog dialog = bootstrapperStyle switch + return bootstrapperStyle switch { - BootstrapperStyle.VistaDialog => new VistaDialog(bootstrapper), - BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(bootstrapper), - BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(bootstrapper), - BootstrapperStyle.ProgressDialog => new ProgressDialog(bootstrapper), - _ => new ProgressDialog(bootstrapper) + BootstrapperStyle.VistaDialog => new VistaDialog(), + BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(), + BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(), + BootstrapperStyle.ProgressDialog => new ProgressDialog(), + _ => new ProgressDialog() }; - - if (bootstrapper is null) - { - dialog.ShowAsPreview(); - } - else - { - if (App.IsQuiet) - dialog.HideBootstrapper(); - - dialog.ShowAsBootstrapper(); - } } } } diff --git a/Bloxstrap/ViewModels/BootstrapperViewModel.cs b/Bloxstrap/ViewModels/BootstrapperViewModel.cs index 1420644..da73f0f 100644 --- a/Bloxstrap/ViewModels/BootstrapperViewModel.cs +++ b/Bloxstrap/ViewModels/BootstrapperViewModel.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using Bloxstrap.Dialogs; using Bloxstrap.Enums; using Bloxstrap.Views; using CommunityToolkit.Mvvm.Input; @@ -20,7 +21,14 @@ namespace Bloxstrap.ViewModels public ICommand PreviewBootstrapperCommand => new RelayCommand(PreviewBootstrapper); - private void PreviewBootstrapper() => App.Settings.Prop.BootstrapperStyle.Show(); + private void PreviewBootstrapper() + { + IBootstrapperDialog dialog = App.Settings.Prop.BootstrapperStyle.GetNew(); + dialog.Message = "Style preview - Click Cancel to close"; + dialog.CancelEnabled = true; + dialog.ShowBootstrapper(); + } + public BootstrapperViewModel(Page page) {