From 287bb2b3f70f1505cefd19c28d0fb135437aeee2 Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 18:06:11 +0000
Subject: [PATCH 1/6] Make bootstrapper independent of dialog
---
Bloxstrap/App.xaml.cs | 14 +++++++++-
Bloxstrap/Bootstrapper.cs | 56 ++++++++++++++++++++++++---------------
2 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index 6f57fce..b473996 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -5,6 +5,7 @@ using System.IO;
using System.Net.Http;
using System.Net;
using System.Reflection;
+using System.Threading.Tasks;
using System.Windows;
using Microsoft.Win32;
@@ -167,7 +168,18 @@ namespace Bloxstrap
ShouldSaveConfigs = true;
DeployManager.Channel = Settings.Prop.Channel;
- Settings.Prop.BootstrapperStyle.Show(new Bootstrapper(commandLine));
+
+ Bootstrapper bootstrapper = new Bootstrapper(commandLine);
+
+ if (IsQuiet)
+ {
+ //Task bootstrappertask = new Task(() => bootstrapper.Run());
+ Task.Run(() => bootstrapper.Run()).Wait();
+ }
+ else
+ {
+ Settings.Prop.BootstrapperStyle.Show(bootstrapper);
+ }
}
Terminate();
diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs
index 31fc182..bebdea5 100644
--- a/Bloxstrap/Bootstrapper.cs
+++ b/Bloxstrap/Bootstrapper.cs
@@ -79,7 +79,7 @@ namespace Bloxstrap
private int PackagesExtracted = 0;
private bool CancelFired = false;
- public IBootstrapperDialog Dialog = null!;
+ public IBootstrapperDialog? Dialog = null;
#endregion
#region Core
@@ -89,6 +89,14 @@ namespace Bloxstrap
FreshInstall = String.IsNullOrEmpty(App.State.Prop.VersionGuid);
}
+ public void SetStatus(string message)
+ {
+ Debug.WriteLine($"[Bootstrapper] {message}");
+
+ if (Dialog is not null)
+ Dialog.Message = message;
+ }
+
// this is called from BootstrapperStyleForm.SetupDialog()
public async Task Run()
{
@@ -129,7 +137,7 @@ namespace Bloxstrap
App.State.Save();
if (App.IsFirstRun && App.IsNoLaunch)
- Dialog.ShowSuccess($"{App.ProjectName} has successfully installed");
+ Dialog?.ShowSuccess($"{App.ProjectName} has successfully installed");
else if (!App.IsNoLaunch)
await StartRoblox();
}
@@ -143,7 +151,7 @@ namespace Bloxstrap
if (releaseInfo is null || releaseInfo.Name is null || releaseInfo.Assets is null || currentVersion == releaseInfo.Name)
return;
- Dialog.Message = $"Getting the latest {App.ProjectName}...";
+ SetStatus($"Getting the latest {App.ProjectName}...");
// 64-bit is always the first option
GithubReleaseAsset asset = releaseInfo.Assets[Environment.Is64BitOperatingSystem ? 0 : 1];
@@ -180,7 +188,7 @@ namespace Bloxstrap
private async Task CheckLatestVersion()
{
- Dialog.Message = "Connecting to Roblox...";
+ SetStatus("Connecting to Roblox...");
ClientVersion clientVersion = await DeployManager.GetLastDeploy(App.Settings.Prop.Channel);
VersionGuid = clientVersion.VersionGuid;
@@ -197,7 +205,7 @@ namespace Bloxstrap
if (shutdown)
{
- Dialog.PromptShutdown();
+ Dialog?.PromptShutdown();
try
{
@@ -219,7 +227,7 @@ namespace Bloxstrap
{
string startEventName = App.ProjectName.Replace(" ", "") + "StartEvent";
- Dialog.Message = "Starting Roblox...";
+ SetStatus("Starting Roblox...");
if (LaunchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
{
@@ -286,7 +294,7 @@ namespace Bloxstrap
return;
// keep bloxstrap open in the background
- Dialog.HideBootstrapper();
+ Dialog?.HideBootstrapper();
await gameClient.WaitForExitAsync();
richPresence?.Dispose();
@@ -297,7 +305,7 @@ namespace Bloxstrap
public void CancelButtonClicked()
{
- if (!Dialog.CancelEnabled)
+ if (Dialog is null || !Dialog.CancelEnabled)
{
App.Terminate(ERROR_INSTALL_USEREXIT);
return;
@@ -415,7 +423,7 @@ namespace Bloxstrap
{
CheckIfRunning(true);
- Dialog.Message = $"Uninstalling {App.ProjectName}...";
+ SetStatus($"Uninstalling {App.ProjectName}...");
//App.Settings.ShouldSave = false;
App.ShouldSaveConfigs = false;
@@ -460,7 +468,7 @@ namespace Bloxstrap
Debug.WriteLine($"Could not fully uninstall! ({e})");
}
- Dialog.ShowSuccess($"{App.ProjectName} has succesfully uninstalled");
+ Dialog?.ShowSuccess($"{App.ProjectName} has succesfully uninstalled");
App.Terminate();
}
@@ -476,15 +484,13 @@ namespace Bloxstrap
if (newProgress > 100)
return;
- Dialog.ProgressValue = newProgress;
+ if (Dialog is not null)
+ Dialog.ProgressValue = newProgress;
}
private async Task InstallLatestVersion()
{
- if (FreshInstall)
- Dialog.Message = "Installing Roblox...";
- else
- Dialog.Message = "Upgrading Roblox...";
+ SetStatus(FreshInstall ? "Installing Roblox..." : "Upgrading Roblox...");
// check if we have at least 300 megabytes of free disk space
if (Utilities.GetFreeDiskSpace(Directories.Base) < 1024*1024*300)
@@ -496,8 +502,11 @@ namespace Bloxstrap
Directory.CreateDirectory(Directories.Base);
- Dialog.CancelEnabled = true;
- Dialog.ProgressStyle = ProgressBarStyle.Continuous;
+ if (Dialog is not null)
+ {
+ Dialog.CancelEnabled = true;
+ Dialog.ProgressStyle = ProgressBarStyle.Continuous;
+ }
// compute total bytes to download
@@ -521,9 +530,11 @@ namespace Bloxstrap
// allow progress bar to 100% before continuing (purely ux reasons lol)
await Task.Delay(1000);
- Dialog.ProgressStyle = ProgressBarStyle.Marquee;
-
- Dialog.Message = "Configuring Roblox...";
+ if (Dialog is not null)
+ {
+ Dialog.ProgressStyle = ProgressBarStyle.Marquee;
+ SetStatus("Configuring Roblox...");
+ }
// wait for all packages to finish extracting
while (PackagesExtracted < VersionPackageManifest.Count)
@@ -554,14 +565,15 @@ namespace Bloxstrap
}
}
- Dialog.CancelEnabled = false;
+ if (Dialog is not null)
+ Dialog.CancelEnabled = false;
App.State.Prop.VersionGuid = VersionGuid;
}
private async Task ApplyModifications()
{
- Dialog.Message = "Applying Roblox modifications...";
+ SetStatus("Applying Roblox modifications...");
string modFolder = Path.Combine(Directories.Modifications);
From ff8e68abb29d585513f15d88c5ef701c5c12fc39 Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 18:57:58 +0000
Subject: [PATCH 2/6] 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.
---
Bloxstrap/App.xaml.cs | 20 +++---
Bloxstrap/Bootstrapper.cs | 2 +-
Bloxstrap/Dialogs/BootstrapperDialogForm.cs | 66 ++-----------------
Bloxstrap/Dialogs/IBootstrapperDialog.cs | 8 +--
Bloxstrap/Dialogs/LegacyDialog2009.cs | 2 +-
Bloxstrap/Dialogs/LegacyDialog2011.cs | 2 +-
Bloxstrap/Dialogs/ProgressDialog.cs | 2 +-
Bloxstrap/Dialogs/VistaDialog.cs | 22 +++----
Bloxstrap/Enums/BootstrapperStyle.cs | 26 ++------
Bloxstrap/ViewModels/BootstrapperViewModel.cs | 10 ++-
10 files changed, 47 insertions(+), 113 deletions(-)
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)
{
From d2557b4be509cf4452dfa379dbb17d4ca1b6242d Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 19:21:20 +0000
Subject: [PATCH 3/6] Add error handling for new bootstrapper handler
---
Bloxstrap/App.xaml.cs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index 569cd76..472ccef 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -181,7 +181,18 @@ namespace Bloxstrap
bootstrapper.Dialog = dialog;
}
- Task bootstrapperTask = Task.Run(() => bootstrapper.Run());
+ Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t =>
+ {
+ if (t.Exception is null)
+ return;
+
+#if DEBUG
+ throw t.Exception;
+#else
+ dialog?.ShowError(t.Exception.ToString());
+#endif
+ });
+
dialog?.ShowBootstrapper();
bootstrapperTask.Wait();
}
From 1805e31f86b54445fd71d6b3583c6181375f463d Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 19:56:07 +0000
Subject: [PATCH 4/6] Minor refactoring of VistaDialog
---
Bloxstrap/Bootstrapper.cs | 2 -
Bloxstrap/Dialogs/BootstrapperDialogForm.cs | 4 --
Bloxstrap/Dialogs/VistaDialog.cs | 64 +++++++++------------
3 files changed, 28 insertions(+), 42 deletions(-)
diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs
index 4e14ac5..0cfc76e 100644
--- a/Bloxstrap/Bootstrapper.cs
+++ b/Bloxstrap/Bootstrapper.cs
@@ -469,8 +469,6 @@ namespace Bloxstrap
}
Dialog?.ShowSuccess($"{App.ProjectName} has succesfully uninstalled");
-
- App.Terminate();
}
#endregion
diff --git a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
index e1e6f70..06b144c 100644
--- a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
+++ b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
@@ -86,13 +86,9 @@ namespace Bloxstrap.Dialogs
public virtual void CloseBootstrapper()
{
if (this.InvokeRequired)
- {
this.Invoke(CloseBootstrapper);
- }
else
- {
this.Close();
- }
}
public virtual void ShowSuccess(string message)
diff --git a/Bloxstrap/Dialogs/VistaDialog.cs b/Bloxstrap/Dialogs/VistaDialog.cs
index bbc9f97..589ad79 100644
--- a/Bloxstrap/Dialogs/VistaDialog.cs
+++ b/Bloxstrap/Dialogs/VistaDialog.cs
@@ -13,58 +13,54 @@ namespace Bloxstrap.Dialogs
public partial class VistaDialog : BootstrapperDialogForm
{
- private TaskDialogPage Dialog;
+ private TaskDialogPage _dialogPage;
- protected override string _message
+ protected sealed override string _message
{
- get => Dialog.Heading ?? "";
- set => Dialog.Heading = value;
+ get => _dialogPage.Heading ?? "";
+ set => _dialogPage.Heading = value;
}
- protected override ProgressBarStyle _progressStyle
+ protected sealed override ProgressBarStyle _progressStyle
{
set
{
- if (Dialog.ProgressBar is null)
+ if (_dialogPage.ProgressBar is null)
return;
- switch (value)
+ _dialogPage.ProgressBar.State = value switch
{
- case ProgressBarStyle.Continuous:
- case ProgressBarStyle.Blocks:
- Dialog.ProgressBar.State = TaskDialogProgressBarState.Normal;
- break;
-
- case ProgressBarStyle.Marquee:
- Dialog.ProgressBar.State = TaskDialogProgressBarState.Marquee;
- break;
- }
+ ProgressBarStyle.Continuous => TaskDialogProgressBarState.Normal,
+ ProgressBarStyle.Blocks => TaskDialogProgressBarState.Normal,
+ ProgressBarStyle.Marquee => TaskDialogProgressBarState.Marquee,
+ _ => _dialogPage.ProgressBar.State
+ };
}
}
- protected override int _progressValue
+ protected sealed override int _progressValue
{
- get => Dialog.ProgressBar is null ? 0 : Dialog.ProgressBar.Value;
+ get => _dialogPage.ProgressBar?.Value ?? 0;
set
{
- if (Dialog.ProgressBar is null)
+ if (_dialogPage.ProgressBar is null)
return;
- Dialog.ProgressBar.Value = value;
+ _dialogPage.ProgressBar.Value = value;
}
}
- protected override bool _cancelEnabled
+ protected sealed override bool _cancelEnabled
{
- get => Dialog.Buttons[0].Enabled;
- set => Dialog.Buttons[0].Enabled = value;
+ get => _dialogPage.Buttons[0].Enabled;
+ set => _dialogPage.Buttons[0].Enabled = value;
}
public VistaDialog()
{
InitializeComponent();
- Dialog = new TaskDialogPage()
+ _dialogPage = new TaskDialogPage()
{
Icon = new TaskDialogIcon(App.Settings.Prop.BootstrapperIcon.GetIcon()),
Caption = App.ProjectName,
@@ -79,7 +75,7 @@ namespace Bloxstrap.Dialogs
_message = "Please wait...";
_cancelEnabled = false;
- Dialog.Buttons[0].Click += (sender, e) => ButtonCancel_Click(sender, e);
+ _dialogPage.Buttons[0].Click += ButtonCancel_Click;
SetupDialog();
}
@@ -100,10 +96,10 @@ namespace Bloxstrap.Dialogs
Buttons = { TaskDialogButton.OK }
};
- successDialog.Buttons[0].Click += (sender, e) => App.Terminate();
+ successDialog.Buttons[0].Click += (_, _) => App.Terminate();
- Dialog.Navigate(successDialog);
- Dialog = successDialog;
+ _dialogPage.Navigate(successDialog);
+ _dialogPage = successDialog;
}
}
@@ -132,9 +128,8 @@ namespace Bloxstrap.Dialogs
errorDialog.Buttons[0].Click += (sender, e) => App.Terminate(Bootstrapper.ERROR_INSTALL_FAILURE);
- Dialog.Navigate(errorDialog);
-
- Dialog = errorDialog;
+ _dialogPage.Navigate(errorDialog);
+ _dialogPage = errorDialog;
}
}
@@ -146,15 +141,12 @@ namespace Bloxstrap.Dialogs
}
else
{
- Dialog.BoundDialog?.Close();
+ _dialogPage.BoundDialog?.Close();
base.CloseBootstrapper();
}
}
- private void VistaDialog_Load(object sender, EventArgs e)
- {
- TaskDialog.ShowDialog(Dialog);
- }
+ private void VistaDialog_Load(object sender, EventArgs e) => TaskDialog.ShowDialog(_dialogPage);
}
}
From a0be3fa9709101de5540a17c1d823a2eb7ff79b6 Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 20:19:59 +0000
Subject: [PATCH 5/6] Minor bootstrapper code refactor
---
Bloxstrap/App.xaml.cs | 2 +
Bloxstrap/Bootstrapper.cs | 111 ++++++++++++++++++--------------------
2 files changed, 53 insertions(+), 60 deletions(-)
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index 472ccef..9473eea 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -183,6 +183,8 @@ namespace Bloxstrap
Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t =>
{
+ // TODO: add error logging
+
if (t.Exception is null)
return;
diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs
index 0cfc76e..c5591c5 100644
--- a/Bloxstrap/Bootstrapper.cs
+++ b/Bloxstrap/Bootstrapper.cs
@@ -28,7 +28,6 @@ namespace Bloxstrap
public const int ERROR_SUCCESS = 0;
public const int ERROR_INSTALL_USEREXIT = 1602;
public const int ERROR_INSTALL_FAILURE = 1603;
- public const int ERROR_PRODUCT_UNINSTALLED = 1614;
// in case a new package is added, you can find the corresponding directory
// by opening the stock bootstrapper in a hex editor
@@ -58,26 +57,25 @@ namespace Bloxstrap
{ "extracontent-places.zip", @"ExtraContent\places\" },
};
- private static readonly string AppSettings =
+ private const string AppSettings =
"\n" +
"\n" +
" content\n" +
" http://www.roblox.com\n" +
"\n";
- private string? LaunchCommandLine;
+ private static bool FreshInstall => String.IsNullOrEmpty(App.State.Prop.VersionGuid);
- private string VersionGuid = null!;
- private PackageManifest VersionPackageManifest = null!;
- private string VersionFolder = null!;
+ private string? _launchCommandLine;
- private readonly bool FreshInstall;
+ private string _versionGuid = null!;
+ private PackageManifest _versionPackageManifest = null!;
+ private string _versionFolder = null!;
- private double ProgressIncrement;
- private long TotalBytes = 0;
- private long TotalDownloadedBytes = 0;
- private int PackagesExtracted = 0;
- private bool CancelFired = false;
+ private double _progressIncrement;
+ private long _totalDownloadedBytes = 0;
+ private int _packagesExtracted = 0;
+ private bool _cancelFired = false;
public IBootstrapperDialog? Dialog = null;
#endregion
@@ -85,8 +83,7 @@ namespace Bloxstrap
#region Core
public Bootstrapper(string? launchCommandLine = null)
{
- LaunchCommandLine = launchCommandLine;
- FreshInstall = String.IsNullOrEmpty(App.State.Prop.VersionGuid);
+ _launchCommandLine = launchCommandLine;
}
public void SetStatus(string message)
@@ -97,7 +94,6 @@ namespace Bloxstrap
Dialog.Message = message;
}
- // this is called from BootstrapperStyleForm.SetupDialog()
public async Task Run()
{
if (App.IsUninstall)
@@ -115,14 +111,11 @@ namespace Bloxstrap
// if bloxstrap is installing for the first time but is running, prompt to close roblox
// if roblox needs updating but is running, ignore update for now
- if (!Directory.Exists(VersionFolder) && CheckIfRunning(true) || App.State.Prop.VersionGuid != VersionGuid && !CheckIfRunning(false))
+ if (!Directory.Exists(_versionFolder) && CheckIfRunning(true) || App.State.Prop.VersionGuid != _versionGuid && !CheckIfRunning(false))
await InstallLatestVersion();
if (App.IsFirstRun)
- {
- //App.Settings.ShouldSave = App.State.ShouldSave = true;
App.ShouldSaveConfigs = true;
- }
await ApplyModifications();
@@ -148,7 +141,7 @@ namespace Bloxstrap
var releaseInfo = await Utilities.GetJson($"https://api.github.com/repos/{App.ProjectRepository}/releases/latest");
- if (releaseInfo is null || releaseInfo.Name is null || releaseInfo.Assets is null || currentVersion == releaseInfo.Name)
+ if (releaseInfo?.Assets is null || currentVersion == releaseInfo.Name)
return;
SetStatus($"Getting the latest {App.ProjectName}...");
@@ -191,9 +184,9 @@ namespace Bloxstrap
SetStatus("Connecting to Roblox...");
ClientVersion clientVersion = await DeployManager.GetLastDeploy(App.Settings.Prop.Channel);
- VersionGuid = clientVersion.VersionGuid;
- VersionFolder = Path.Combine(Directories.Versions, VersionGuid);
- VersionPackageManifest = await PackageManifest.Get(VersionGuid);
+ _versionGuid = clientVersion.VersionGuid;
+ _versionFolder = Path.Combine(Directories.Versions, _versionGuid);
+ _versionPackageManifest = await PackageManifest.Get(_versionGuid);
}
private bool CheckIfRunning(bool shutdown)
@@ -229,22 +222,22 @@ namespace Bloxstrap
SetStatus("Starting Roblox...");
- if (LaunchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
+ if (_launchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
{
Utilities.OpenWebsite("https://www.roblox.com/games");
return;
}
// launch time isn't really required for all launches, but it's usually just safest to do this
- LaunchCommandLine += " --launchtime=" + DateTimeOffset.Now.ToUnixTimeMilliseconds();
+ _launchCommandLine += " --launchtime=" + DateTimeOffset.Now.ToUnixTimeMilliseconds();
if (App.Settings.Prop.Channel.ToLower() != DeployManager.DefaultChannel.ToLower())
- LaunchCommandLine += " -channel " + App.Settings.Prop.Channel.ToLower();
+ _launchCommandLine += " -channel " + App.Settings.Prop.Channel.ToLower();
- LaunchCommandLine += " -startEvent " + startEventName;
+ _launchCommandLine += " -startEvent " + startEventName;
bool shouldWait = false;
- Process gameClient = Process.Start(Path.Combine(VersionFolder, "RobloxPlayerBeta.exe"), LaunchCommandLine);
+ Process gameClient = Process.Start(Path.Combine(_versionFolder, "RobloxPlayerBeta.exe"), _launchCommandLine);
Process? rbxFpsUnlocker = null;
DiscordRichPresence? richPresence = null;
Mutex? singletonMutex = null;
@@ -311,14 +304,14 @@ namespace Bloxstrap
return;
}
- CancelFired = true;
+ _cancelFired = true;
try
{
if (App.IsFirstRun)
Directory.Delete(Directories.Base, true);
- else if (Directory.Exists(VersionFolder))
- Directory.Delete(VersionFolder, true);
+ else if (Directory.Exists(_versionFolder))
+ Directory.Delete(_versionFolder, true);
}
catch (Exception) { }
@@ -340,7 +333,10 @@ namespace Bloxstrap
if (Directory.Exists(oldInstallLocation))
Directory.Delete(oldInstallLocation, true);
}
- catch (Exception) { }
+ catch (Exception)
+ {
+ // ignored
+ }
applicationKey.DeleteValue("OldInstallLocation");
}
@@ -475,7 +471,7 @@ namespace Bloxstrap
#region Roblox Install
private void UpdateProgressbar()
{
- int newProgress = (int)Math.Floor(ProgressIncrement * TotalDownloadedBytes);
+ int newProgress = (int)Math.Floor(_progressIncrement * _totalDownloadedBytes);
// bugcheck: if we're restoring a file from a package, it'll incorrectly increment the progress beyond 100
// too lazy to fix properly so lol
@@ -507,21 +503,17 @@ namespace Bloxstrap
}
// compute total bytes to download
-
- foreach (Package package in VersionPackageManifest)
- TotalBytes += package.PackedSize;
-
- ProgressIncrement = (double)1 / TotalBytes * 100;
+ _progressIncrement = (double)100 / _versionPackageManifest.Sum(package => package.PackedSize);
Directory.CreateDirectory(Directories.Downloads);
Directory.CreateDirectory(Directories.Versions);
- foreach (Package package in VersionPackageManifest)
+ foreach (Package package in _versionPackageManifest)
{
// download all the packages synchronously
await DownloadPackage(package);
- // extract the package immediately after download
+ // extract the package immediately after download asynchronously
ExtractPackage(package);
}
@@ -535,12 +527,12 @@ namespace Bloxstrap
}
// wait for all packages to finish extracting
- while (PackagesExtracted < VersionPackageManifest.Count)
+ while (_packagesExtracted < _versionPackageManifest.Count)
{
await Task.Delay(100);
}
- string appSettingsLocation = Path.Combine(VersionFolder, "AppSettings.xml");
+ string appSettingsLocation = Path.Combine(_versionFolder, "AppSettings.xml");
await File.WriteAllTextAsync(appSettingsLocation, AppSettings);
if (!FreshInstall)
@@ -550,13 +542,13 @@ namespace Bloxstrap
// let's take this opportunity to delete any packages we don't need anymore
foreach (string filename in Directory.GetFiles(Directories.Downloads))
{
- if (!VersionPackageManifest.Exists(package => filename.Contains(package.Signature)))
+ if (!_versionPackageManifest.Exists(package => filename.Contains(package.Signature)))
File.Delete(filename);
}
string oldVersionFolder = Path.Combine(Directories.Versions, App.State.Prop.VersionGuid);
- if (VersionGuid != App.State.Prop.VersionGuid && Directory.Exists(oldVersionFolder))
+ if (_versionGuid != App.State.Prop.VersionGuid && Directory.Exists(oldVersionFolder))
{
// and also to delete our old version folder
Directory.Delete(oldVersionFolder, true);
@@ -566,7 +558,7 @@ namespace Bloxstrap
if (Dialog is not null)
Dialog.CancelEnabled = false;
- App.State.Prop.VersionGuid = VersionGuid;
+ App.State.Prop.VersionGuid = _versionGuid;
}
private async Task ApplyModifications()
@@ -609,7 +601,7 @@ namespace Bloxstrap
foreach (string file in modFolderFiles)
{
string fileModFolder = Path.Combine(modFolder, file);
- string fileVersionFolder = Path.Combine(VersionFolder, file);
+ string fileVersionFolder = Path.Combine(_versionFolder, file);
if (File.Exists(fileVersionFolder))
{
@@ -645,7 +637,7 @@ namespace Bloxstrap
catch (InvalidOperationException)
{
// package doesn't exist, likely mistakenly placed file
- string versionFileLocation = Path.Combine(VersionFolder, fileLocation);
+ string versionFileLocation = Path.Combine(_versionFolder, fileLocation);
File.Delete(versionFileLocation);
@@ -688,7 +680,7 @@ namespace Bloxstrap
private async Task DownloadPackage(Package package)
{
- string packageUrl = $"{DeployManager.BaseUrl}/{VersionGuid}-{package.Name}";
+ string packageUrl = $"{DeployManager.BaseUrl}/{_versionGuid}-{package.Name}";
string packageLocation = Path.Combine(Directories.Downloads, package.Signature);
string robloxPackageLocation = Path.Combine(Directories.LocalAppData, "Roblox", "Downloads", package.Signature);
@@ -705,7 +697,7 @@ namespace Bloxstrap
else
{
Debug.WriteLine($"{package.Name} is already downloaded, skipping...");
- TotalDownloadedBytes += package.PackedSize;
+ _totalDownloadedBytes += package.PackedSize;
UpdateProgressbar();
return;
}
@@ -717,7 +709,7 @@ namespace Bloxstrap
Debug.WriteLine($"Found existing version of {package.Name} ({robloxPackageLocation})! Copying to Downloads folder...");
File.Copy(robloxPackageLocation, packageLocation);
- TotalDownloadedBytes += package.PackedSize;
+ _totalDownloadedBytes += package.PackedSize;
UpdateProgressbar();
return;
}
@@ -726,7 +718,7 @@ namespace Bloxstrap
{
Debug.WriteLine($"Downloading {package.Name}...");
- if (CancelFired)
+ if (_cancelFired)
return;
{
@@ -745,7 +737,7 @@ namespace Bloxstrap
await fileStream.WriteAsync(buffer, 0, bytesRead);
- TotalDownloadedBytes += bytesRead;
+ _totalDownloadedBytes += bytesRead;
UpdateProgressbar();
}
}
@@ -756,13 +748,12 @@ namespace Bloxstrap
private async void ExtractPackage(Package package)
{
- if (CancelFired)
+ if (_cancelFired)
return;
string packageLocation = Path.Combine(Directories.Downloads, package.Signature);
- string packageFolder = Path.Combine(VersionFolder, PackageDirectories[package.Name]);
+ string packageFolder = Path.Combine(_versionFolder, PackageDirectories[package.Name]);
string extractPath;
- string? directory;
Debug.WriteLine($"Extracting {package.Name} to {packageFolder}...");
@@ -770,7 +761,7 @@ namespace Bloxstrap
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
- if (CancelFired)
+ if (_cancelFired)
return;
if (entry.FullName.EndsWith('\\'))
@@ -780,7 +771,7 @@ namespace Bloxstrap
//Debug.WriteLine($"[{package.Name}] Writing {extractPath}...");
- directory = Path.GetDirectoryName(extractPath);
+ string? directory = Path.GetDirectoryName(extractPath);
if (directory is null)
continue;
@@ -793,12 +784,12 @@ namespace Bloxstrap
Debug.WriteLine($"Finished extracting {package.Name}");
- PackagesExtracted += 1;
+ _packagesExtracted += 1;
}
private void ExtractFileFromPackage(string packageName, string fileName)
{
- Package? package = VersionPackageManifest.Find(x => x.Name == packageName);
+ Package? package = _versionPackageManifest.Find(x => x.Name == packageName);
if (package is null)
return;
@@ -806,7 +797,7 @@ namespace Bloxstrap
DownloadPackage(package).GetAwaiter().GetResult();
string packageLocation = Path.Combine(Directories.Downloads, package.Signature);
- string packageFolder = Path.Combine(VersionFolder, PackageDirectories[package.Name]);
+ string packageFolder = Path.Combine(_versionFolder, PackageDirectories[package.Name]);
using ZipArchive archive = ZipFile.OpenRead(packageLocation);
From 0c4f7b4a27565d80ed6078bb439c8d7f71f2d856 Mon Sep 17 00:00:00 2001
From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com>
Date: Sat, 11 Feb 2023 21:31:19 +0000
Subject: [PATCH 6/6] Make install cancelling more reliable
---
Bloxstrap/App.xaml.cs | 1 +
Bloxstrap/Bootstrapper.cs | 59 +++++++++++++++------
Bloxstrap/Dialogs/BootstrapperDialogForm.cs | 3 ++
Bloxstrap/Dialogs/IBootstrapperDialog.cs | 2 +
4 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs
index 9473eea..d938d46 100644
--- a/Bloxstrap/App.xaml.cs
+++ b/Bloxstrap/App.xaml.cs
@@ -179,6 +179,7 @@ namespace Bloxstrap
{
dialog = Settings.Prop.BootstrapperStyle.GetNew();
bootstrapper.Dialog = dialog;
+ dialog.Bootstrapper = bootstrapper;
}
Task bootstrapperTask = Task.Run(() => bootstrapper.Run()).ContinueWith(t =>
diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs
index c5591c5..93aecc9 100644
--- a/Bloxstrap/Bootstrapper.cs
+++ b/Bloxstrap/Bootstrapper.cs
@@ -64,6 +64,8 @@ namespace Bloxstrap
" http://www.roblox.com\n" +
"\n";
+ private readonly CancellationTokenSource _cancelTokenSource = new();
+
private static bool FreshInstall => String.IsNullOrEmpty(App.State.Prop.VersionGuid);
private string? _launchCommandLine;
@@ -72,6 +74,7 @@ namespace Bloxstrap
private PackageManifest _versionPackageManifest = null!;
private string _versionFolder = null!;
+ private bool _isInstalling = false;
private double _progressIncrement;
private long _totalDownloadedBytes = 0;
private int _packagesExtracted = 0;
@@ -86,7 +89,7 @@ namespace Bloxstrap
_launchCommandLine = launchCommandLine;
}
- public void SetStatus(string message)
+ private void SetStatus(string message)
{
Debug.WriteLine($"[Bootstrapper] {message}");
@@ -296,25 +299,31 @@ namespace Bloxstrap
rbxFpsUnlocker.Kill();
}
- public void CancelButtonClicked()
+ public void CancelInstall()
{
- if (Dialog is null || !Dialog.CancelEnabled)
+ if (!_isInstalling)
{
App.Terminate(ERROR_INSTALL_USEREXIT);
return;
}
+ _cancelTokenSource.Cancel();
_cancelFired = true;
try
{
+ // clean up install
if (App.IsFirstRun)
Directory.Delete(Directories.Base, true);
else if (Directory.Exists(_versionFolder))
Directory.Delete(_versionFolder, true);
}
- catch (Exception) { }
-
+ catch (Exception e)
+ {
+ Debug.WriteLine("[Bootstrapper} Could not fully clean up installation!");
+ Debug.WriteLine(e);
+ }
+
App.Terminate(ERROR_INSTALL_USEREXIT);
}
#endregion
@@ -484,6 +493,8 @@ namespace Bloxstrap
private async Task InstallLatestVersion()
{
+ _isInstalling = true;
+
SetStatus(FreshInstall ? "Installing Roblox..." : "Upgrading Roblox...");
// check if we have at least 300 megabytes of free disk space
@@ -510,6 +521,9 @@ namespace Bloxstrap
foreach (Package package in _versionPackageManifest)
{
+ if (_cancelFired)
+ return;
+
// download all the packages synchronously
await DownloadPackage(package);
@@ -517,6 +531,9 @@ namespace Bloxstrap
ExtractPackage(package);
}
+ if (_cancelFired)
+ return;
+
// allow progress bar to 100% before continuing (purely ux reasons lol)
await Task.Delay(1000);
@@ -535,6 +552,9 @@ namespace Bloxstrap
string appSettingsLocation = Path.Combine(_versionFolder, "AppSettings.xml");
await File.WriteAllTextAsync(appSettingsLocation, AppSettings);
+ if (_cancelFired)
+ return;
+
if (!FreshInstall)
{
ReShade.SynchronizeConfigFile();
@@ -559,6 +579,8 @@ namespace Bloxstrap
Dialog.CancelEnabled = false;
App.State.Prop.VersionGuid = _versionGuid;
+
+ _isInstalling = false;
}
private async Task ApplyModifications()
@@ -680,6 +702,9 @@ namespace Bloxstrap
private async Task DownloadPackage(Package package)
{
+ if (_cancelFired)
+ return;
+
string packageUrl = $"{DeployManager.BaseUrl}/{_versionGuid}-{package.Name}";
string packageLocation = Path.Combine(Directories.Downloads, package.Signature);
string robloxPackageLocation = Path.Combine(Directories.LocalAppData, "Roblox", "Downloads", package.Signature);
@@ -716,26 +741,30 @@ namespace Bloxstrap
if (!File.Exists(packageLocation))
{
- Debug.WriteLine($"Downloading {package.Name}...");
-
- if (_cancelFired)
- return;
+ Debug.WriteLine($"Downloading {package.Name} ({package.Signature})...");
{
- var response = await App.HttpClient.GetAsync(packageUrl, HttpCompletionOption.ResponseHeadersRead);
- var buffer = new byte[8192];
+ var response = await App.HttpClient.GetAsync(packageUrl, HttpCompletionOption.ResponseHeadersRead, _cancelTokenSource.Token);
+ var buffer = new byte[4096];
- await using var stream = await response.Content.ReadAsStreamAsync();
- await using var fileStream = new FileStream(packageLocation, FileMode.CreateNew);
+ await using var stream = await response.Content.ReadAsStreamAsync(_cancelTokenSource.Token);
+ await using var fileStream = new FileStream(packageLocation, FileMode.CreateNew, FileAccess.Write, FileShare.Delete);
while (true)
{
- var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
+ if (_cancelFired)
+ {
+ stream.Close();
+ fileStream.Close();
+ return;
+ }
+
+ var bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, _cancelTokenSource.Token);
if (bytesRead == 0)
break; // we're done
- await fileStream.WriteAsync(buffer, 0, bytesRead);
+ await fileStream.WriteAsync(buffer, 0, bytesRead, _cancelTokenSource.Token);
_totalDownloadedBytes += bytesRead;
UpdateProgressbar();
diff --git a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
index 06b144c..62e2a50 100644
--- a/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
+++ b/Bloxstrap/Dialogs/BootstrapperDialogForm.cs
@@ -10,6 +10,8 @@ namespace Bloxstrap.Dialogs
{
public class BootstrapperDialogForm : Form, IBootstrapperDialog
{
+ public Bootstrapper Bootstrapper { get; set; } = null!;
+
protected virtual string _message { get; set; } = "Please wait...";
protected virtual ProgressBarStyle _progressStyle { get; set; }
protected virtual int _progressValue { get; set; }
@@ -117,6 +119,7 @@ namespace Bloxstrap.Dialogs
public void ButtonCancel_Click(object? sender, EventArgs e)
{
+ Bootstrapper.CancelInstall();
this.Close();
}
}
diff --git a/Bloxstrap/Dialogs/IBootstrapperDialog.cs b/Bloxstrap/Dialogs/IBootstrapperDialog.cs
index eff0e7b..3cbe197 100644
--- a/Bloxstrap/Dialogs/IBootstrapperDialog.cs
+++ b/Bloxstrap/Dialogs/IBootstrapperDialog.cs
@@ -4,6 +4,8 @@ namespace Bloxstrap.Dialogs
{
public interface IBootstrapperDialog
{
+ public Bootstrapper Bootstrapper { get; set; }
+
string Message { get; set; }
ProgressBarStyle ProgressStyle { get; set; }
int ProgressValue { get; set; }