bloxstrap/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
pizzaboxer ff8e68abb2 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.
2023-02-11 18:57:58 +00:00

128 lines
3.6 KiB
C#

using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using Bloxstrap.Enums;
using Bloxstrap.Helpers;
namespace Bloxstrap.Dialogs
{
public class BootstrapperDialogForm : Form, IBootstrapperDialog
{
protected virtual string _message { get; set; } = "Please wait...";
protected virtual ProgressBarStyle _progressStyle { get; set; }
protected virtual int _progressValue { get; set; }
protected virtual bool _cancelEnabled { get; set; }
public string Message
{
get => _message;
set
{
if (this.InvokeRequired)
this.Invoke(() => _message = value);
else
_message = value;
}
}
public ProgressBarStyle ProgressStyle
{
get => _progressStyle;
set
{
if (this.InvokeRequired)
this.Invoke(() => _progressStyle = value);
else
_progressStyle = value;
}
}
public int ProgressValue
{
get => _progressValue;
set
{
if (this.InvokeRequired)
this.Invoke(() => _progressValue = value);
else
_progressValue = value;
}
}
public bool CancelEnabled
{
get => _cancelEnabled;
set
{
if (this.InvokeRequired)
this.Invoke(() => _cancelEnabled = value);
else
_cancelEnabled = value;
}
}
public void ScaleWindow()
{
this.Size = this.MinimumSize = this.MaximumSize = WindowScaling.GetScaledSize(this.Size);
foreach (Control control in this.Controls)
{
control.Size = WindowScaling.GetScaledSize(control.Size);
control.Location = WindowScaling.GetScaledPoint(control.Location);
control.Padding = WindowScaling.GetScaledPadding(control.Padding);
}
}
public void SetupDialog()
{
this.Text = App.ProjectName;
this.Icon = App.Settings.Prop.BootstrapperIcon.GetIcon();
}
public void ShowBootstrapper() => this.ShowDialog();
public virtual void CloseBootstrapper()
{
if (this.InvokeRequired)
{
this.Invoke(CloseBootstrapper);
}
else
{
this.Close();
}
}
public virtual void ShowSuccess(string message)
{
App.ShowMessageBox(message, MessageBoxImage.Information);
App.Terminate();
}
public virtual void ShowError(string message)
{
App.ShowMessageBox($"An error occurred while starting Roblox\n\nDetails: {message}", MessageBoxImage.Error);
App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
}
public void PromptShutdown()
{
MessageBoxResult result = App.ShowMessageBox(
"Roblox is currently running, but needs to close. Would you like close Roblox now?",
MessageBoxImage.Information,
MessageBoxButton.OKCancel
);
if (result != MessageBoxResult.OK)
Environment.Exit(Bootstrapper.ERROR_INSTALL_USEREXIT);
}
public void ButtonCancel_Click(object? sender, EventArgs e)
{
this.Close();
}
}
}