mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Break down logic for bootstrapper/dialog handling
The functionality for how bootstrapper dialogs are handled has been broken down to be more relevant to the sections of code. Bootstrapper initialization and preview configuration are now handled by app startup and the preferences menu respectively, rather than all being handled in the dialog constructor. Next things to do are handle exceptions and cancellation.
This commit is contained in:
parent
287bb2b3f7
commit
ff8e68abb2
@ -9,9 +9,10 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
using Bloxstrap.Models;
|
using Bloxstrap.Dialogs;
|
||||||
using Bloxstrap.Enums;
|
using Bloxstrap.Enums;
|
||||||
using Bloxstrap.Helpers;
|
using Bloxstrap.Helpers;
|
||||||
|
using Bloxstrap.Models;
|
||||||
using Bloxstrap.Views;
|
using Bloxstrap.Views;
|
||||||
|
|
||||||
namespace Bloxstrap
|
namespace Bloxstrap
|
||||||
@ -56,6 +57,7 @@ namespace Bloxstrap
|
|||||||
{
|
{
|
||||||
Settings.Save();
|
Settings.Save();
|
||||||
State.Save();
|
State.Save();
|
||||||
|
Debug.WriteLine($"[App] Terminating with exit code {code}");
|
||||||
Environment.Exit(code);
|
Environment.Exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,17 +171,19 @@ namespace Bloxstrap
|
|||||||
|
|
||||||
DeployManager.Channel = Settings.Prop.Channel;
|
DeployManager.Channel = Settings.Prop.Channel;
|
||||||
|
|
||||||
|
// start bootstrapper and show the bootstrapper modal if we're not running silently
|
||||||
Bootstrapper bootstrapper = new Bootstrapper(commandLine);
|
Bootstrapper bootstrapper = new Bootstrapper(commandLine);
|
||||||
|
IBootstrapperDialog? dialog = null;
|
||||||
|
|
||||||
if (IsQuiet)
|
if (!IsQuiet)
|
||||||
{
|
{
|
||||||
//Task bootstrappertask = new Task(() => bootstrapper.Run());
|
dialog = Settings.Prop.BootstrapperStyle.GetNew();
|
||||||
Task.Run(() => bootstrapper.Run()).Wait();
|
bootstrapper.Dialog = dialog;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Settings.Prop.BootstrapperStyle.Show(bootstrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Task bootstrapperTask = Task.Run(() => bootstrapper.Run());
|
||||||
|
dialog?.ShowBootstrapper();
|
||||||
|
bootstrapperTask.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
Terminate();
|
Terminate();
|
||||||
|
@ -294,7 +294,7 @@ namespace Bloxstrap
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// keep bloxstrap open in the background
|
// keep bloxstrap open in the background
|
||||||
Dialog?.HideBootstrapper();
|
Dialog?.CloseBootstrapper();
|
||||||
await gameClient.WaitForExitAsync();
|
await gameClient.WaitForExitAsync();
|
||||||
|
|
||||||
richPresence?.Dispose();
|
richPresence?.Dispose();
|
||||||
|
@ -10,10 +10,6 @@ namespace Bloxstrap.Dialogs
|
|||||||
{
|
{
|
||||||
public class BootstrapperDialogForm : Form, IBootstrapperDialog
|
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 string _message { get; set; } = "Please wait...";
|
||||||
protected virtual ProgressBarStyle _progressStyle { get; set; }
|
protected virtual ProgressBarStyle _progressStyle { get; set; }
|
||||||
protected virtual int _progressValue { 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()
|
public void ScaleWindow()
|
||||||
{
|
{
|
||||||
this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size);
|
this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size);
|
||||||
@ -88,63 +79,19 @@ namespace Bloxstrap.Dialogs
|
|||||||
{
|
{
|
||||||
this.Text = App.ProjectName;
|
this.Text = App.ProjectName;
|
||||||
this.Icon = App.Settings.Prop.BootstrapperIcon.GetIcon();
|
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()
|
public virtual void CloseBootstrapper()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
if (this.InvokeRequired)
|
if (this.InvokeRequired)
|
||||||
{
|
{
|
||||||
this.Invoke(HideBootstrapper);
|
this.Invoke(CloseBootstrapper);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Opacity = 0;
|
this.Close();
|
||||||
this.ShowInTaskbar = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,10 +121,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
|
|
||||||
public void ButtonCancel_Click(object? sender, EventArgs e)
|
public void ButtonCancel_Click(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (Bootstrapper is null)
|
this.Close();
|
||||||
this.Close();
|
|
||||||
else
|
|
||||||
Task.Run(() => Bootstrapper.CancelButtonClicked());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,13 @@ namespace Bloxstrap.Dialogs
|
|||||||
{
|
{
|
||||||
public interface IBootstrapperDialog
|
public interface IBootstrapperDialog
|
||||||
{
|
{
|
||||||
Bootstrapper? Bootstrapper { get; set; }
|
|
||||||
|
|
||||||
string Message { get; set; }
|
string Message { get; set; }
|
||||||
ProgressBarStyle ProgressStyle { get; set; }
|
ProgressBarStyle ProgressStyle { get; set; }
|
||||||
int ProgressValue { get; set; }
|
int ProgressValue { get; set; }
|
||||||
bool CancelEnabled { get; set; }
|
bool CancelEnabled { get; set; }
|
||||||
|
|
||||||
void RunBootstrapper();
|
void ShowBootstrapper();
|
||||||
void ShowAsPreview();
|
void CloseBootstrapper();
|
||||||
void ShowAsBootstrapper();
|
|
||||||
void HideBootstrapper();
|
|
||||||
void ShowSuccess(string message);
|
void ShowSuccess(string message);
|
||||||
void ShowError(string message);
|
void ShowError(string message);
|
||||||
void PromptShutdown();
|
void PromptShutdown();
|
||||||
|
@ -32,7 +32,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
set => this.buttonCancel.Enabled = value;
|
set => this.buttonCancel.Enabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LegacyDialog2009(Bootstrapper? bootstrapper = null) : base(bootstrapper)
|
public LegacyDialog2009()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value;
|
set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LegacyDialog2011(Bootstrapper? bootstrapper = null) : base(bootstrapper)
|
public LegacyDialog2011()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value;
|
set => this.buttonCancel.Enabled = this.buttonCancel.Visible = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgressDialog(Bootstrapper? bootstrapper = null) : base(bootstrapper)
|
public ProgressDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
set => Dialog.Buttons[0].Enabled = value;
|
set => Dialog.Buttons[0].Enabled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VistaDialog(Bootstrapper? bootstrapper = null) : base(bootstrapper)
|
public VistaDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
@ -102,9 +102,7 @@ namespace Bloxstrap.Dialogs
|
|||||||
|
|
||||||
successDialog.Buttons[0].Click += (sender, e) => App.Terminate();
|
successDialog.Buttons[0].Click += (sender, e) => App.Terminate();
|
||||||
|
|
||||||
if (!App.IsQuiet)
|
Dialog.Navigate(successDialog);
|
||||||
Dialog.Navigate(successDialog);
|
|
||||||
|
|
||||||
Dialog = successDialog;
|
Dialog = successDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,33 +132,29 @@ namespace Bloxstrap.Dialogs
|
|||||||
|
|
||||||
errorDialog.Buttons[0].Click += (sender, e) => App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
|
errorDialog.Buttons[0].Click += (sender, e) => App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
|
||||||
|
|
||||||
if (!App.IsQuiet)
|
Dialog.Navigate(errorDialog);
|
||||||
Dialog.Navigate(errorDialog);
|
|
||||||
|
|
||||||
Dialog = errorDialog;
|
Dialog = errorDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void HideBootstrapper()
|
public override void CloseBootstrapper()
|
||||||
{
|
{
|
||||||
if (this.InvokeRequired)
|
if (this.InvokeRequired)
|
||||||
{
|
{
|
||||||
this.Invoke(HideBootstrapper);
|
this.Invoke(CloseBootstrapper);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Dialog.BoundDialog is null)
|
Dialog.BoundDialog?.Close();
|
||||||
return;
|
base.CloseBootstrapper();
|
||||||
|
|
||||||
Dialog.BoundDialog.Close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void VistaDialog_Load(object sender, EventArgs e)
|
private void VistaDialog_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!App.IsQuiet)
|
TaskDialog.ShowDialog(Dialog);
|
||||||
TaskDialog.ShowDialog(Dialog);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,28 +14,16 @@ namespace Bloxstrap.Enums
|
|||||||
|
|
||||||
public static class BootstrapperStyleEx
|
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.VistaDialog => new VistaDialog(),
|
||||||
BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(bootstrapper),
|
BootstrapperStyle.LegacyDialog2009 => new LegacyDialog2009(),
|
||||||
BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(bootstrapper),
|
BootstrapperStyle.LegacyDialog2011 => new LegacyDialog2011(),
|
||||||
BootstrapperStyle.ProgressDialog => new ProgressDialog(bootstrapper),
|
BootstrapperStyle.ProgressDialog => new ProgressDialog(),
|
||||||
_ => new ProgressDialog(bootstrapper)
|
_ => new ProgressDialog()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bootstrapper is null)
|
|
||||||
{
|
|
||||||
dialog.ShowAsPreview();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (App.IsQuiet)
|
|
||||||
dialog.HideBootstrapper();
|
|
||||||
|
|
||||||
dialog.ShowAsBootstrapper();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Bloxstrap.Dialogs;
|
||||||
using Bloxstrap.Enums;
|
using Bloxstrap.Enums;
|
||||||
using Bloxstrap.Views;
|
using Bloxstrap.Views;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
@ -20,7 +21,14 @@ namespace Bloxstrap.ViewModels
|
|||||||
|
|
||||||
public ICommand PreviewBootstrapperCommand => new RelayCommand(PreviewBootstrapper);
|
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)
|
public BootstrapperViewModel(Page page)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user