mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 18:11: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 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();
|
||||
|
@ -294,7 +294,7 @@ namespace Bloxstrap
|
||||
return;
|
||||
|
||||
// keep bloxstrap open in the background
|
||||
Dialog?.HideBootstrapper();
|
||||
Dialog?.CloseBootstrapper();
|
||||
await gameClient.WaitForExitAsync();
|
||||
|
||||
richPresence?.Dispose();
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -32,7 +32,7 @@ namespace Bloxstrap.Dialogs
|
||||
set => this.buttonCancel.Enabled = value;
|
||||
}
|
||||
|
||||
public LegacyDialog2009(Bootstrapper? bootstrapper = null) : base(bootstrapper)
|
||||
public LegacyDialog2009()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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 = successDialog;
|
||||
}
|
||||
}
|
||||
@ -134,32 +132,28 @@ namespace Bloxstrap.Dialogs
|
||||
|
||||
errorDialog.Buttons[0].Click += (sender, e) => App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
|
||||
|
||||
if (!App.IsQuiet)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user