Make bootstrapper independent of dialog

This commit is contained in:
pizzaboxer 2023-02-11 18:06:11 +00:00
parent 93ad0fb609
commit 287bb2b3f7
2 changed files with 47 additions and 23 deletions

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Microsoft.Win32; using Microsoft.Win32;
@ -167,7 +168,18 @@ namespace Bloxstrap
ShouldSaveConfigs = true; ShouldSaveConfigs = true;
DeployManager.Channel = Settings.Prop.Channel; 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(); Terminate();

View File

@ -79,7 +79,7 @@ namespace Bloxstrap
private int PackagesExtracted = 0; private int PackagesExtracted = 0;
private bool CancelFired = false; private bool CancelFired = false;
public IBootstrapperDialog Dialog = null!; public IBootstrapperDialog? Dialog = null;
#endregion #endregion
#region Core #region Core
@ -89,6 +89,14 @@ namespace Bloxstrap
FreshInstall = String.IsNullOrEmpty(App.State.Prop.VersionGuid); 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() // this is called from BootstrapperStyleForm.SetupDialog()
public async Task Run() public async Task Run()
{ {
@ -129,7 +137,7 @@ namespace Bloxstrap
App.State.Save(); App.State.Save();
if (App.IsFirstRun && App.IsNoLaunch) if (App.IsFirstRun && App.IsNoLaunch)
Dialog.ShowSuccess($"{App.ProjectName} has successfully installed"); Dialog?.ShowSuccess($"{App.ProjectName} has successfully installed");
else if (!App.IsNoLaunch) else if (!App.IsNoLaunch)
await StartRoblox(); await StartRoblox();
} }
@ -143,7 +151,7 @@ namespace Bloxstrap
if (releaseInfo is null || releaseInfo.Name is null || releaseInfo.Assets is null || currentVersion == releaseInfo.Name) if (releaseInfo is null || releaseInfo.Name is null || releaseInfo.Assets is null || currentVersion == releaseInfo.Name)
return; return;
Dialog.Message = $"Getting the latest {App.ProjectName}..."; SetStatus($"Getting the latest {App.ProjectName}...");
// 64-bit is always the first option // 64-bit is always the first option
GithubReleaseAsset asset = releaseInfo.Assets[Environment.Is64BitOperatingSystem ? 0 : 1]; GithubReleaseAsset asset = releaseInfo.Assets[Environment.Is64BitOperatingSystem ? 0 : 1];
@ -180,7 +188,7 @@ namespace Bloxstrap
private async Task CheckLatestVersion() private async Task CheckLatestVersion()
{ {
Dialog.Message = "Connecting to Roblox..."; SetStatus("Connecting to Roblox...");
ClientVersion clientVersion = await DeployManager.GetLastDeploy(App.Settings.Prop.Channel); ClientVersion clientVersion = await DeployManager.GetLastDeploy(App.Settings.Prop.Channel);
VersionGuid = clientVersion.VersionGuid; VersionGuid = clientVersion.VersionGuid;
@ -197,7 +205,7 @@ namespace Bloxstrap
if (shutdown) if (shutdown)
{ {
Dialog.PromptShutdown(); Dialog?.PromptShutdown();
try try
{ {
@ -219,7 +227,7 @@ namespace Bloxstrap
{ {
string startEventName = App.ProjectName.Replace(" ", "") + "StartEvent"; string startEventName = App.ProjectName.Replace(" ", "") + "StartEvent";
Dialog.Message = "Starting Roblox..."; SetStatus("Starting Roblox...");
if (LaunchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch) if (LaunchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
{ {
@ -286,7 +294,7 @@ namespace Bloxstrap
return; return;
// keep bloxstrap open in the background // keep bloxstrap open in the background
Dialog.HideBootstrapper(); Dialog?.HideBootstrapper();
await gameClient.WaitForExitAsync(); await gameClient.WaitForExitAsync();
richPresence?.Dispose(); richPresence?.Dispose();
@ -297,7 +305,7 @@ namespace Bloxstrap
public void CancelButtonClicked() public void CancelButtonClicked()
{ {
if (!Dialog.CancelEnabled) if (Dialog is null || !Dialog.CancelEnabled)
{ {
App.Terminate(ERROR_INSTALL_USEREXIT); App.Terminate(ERROR_INSTALL_USEREXIT);
return; return;
@ -415,7 +423,7 @@ namespace Bloxstrap
{ {
CheckIfRunning(true); CheckIfRunning(true);
Dialog.Message = $"Uninstalling {App.ProjectName}..."; SetStatus($"Uninstalling {App.ProjectName}...");
//App.Settings.ShouldSave = false; //App.Settings.ShouldSave = false;
App.ShouldSaveConfigs = false; App.ShouldSaveConfigs = false;
@ -460,7 +468,7 @@ namespace Bloxstrap
Debug.WriteLine($"Could not fully uninstall! ({e})"); Debug.WriteLine($"Could not fully uninstall! ({e})");
} }
Dialog.ShowSuccess($"{App.ProjectName} has succesfully uninstalled"); Dialog?.ShowSuccess($"{App.ProjectName} has succesfully uninstalled");
App.Terminate(); App.Terminate();
} }
@ -476,15 +484,13 @@ namespace Bloxstrap
if (newProgress > 100) if (newProgress > 100)
return; return;
Dialog.ProgressValue = newProgress; if (Dialog is not null)
Dialog.ProgressValue = newProgress;
} }
private async Task InstallLatestVersion() private async Task InstallLatestVersion()
{ {
if (FreshInstall) SetStatus(FreshInstall ? "Installing Roblox..." : "Upgrading Roblox...");
Dialog.Message = "Installing Roblox...";
else
Dialog.Message = "Upgrading Roblox...";
// check if we have at least 300 megabytes of free disk space // check if we have at least 300 megabytes of free disk space
if (Utilities.GetFreeDiskSpace(Directories.Base) < 1024*1024*300) if (Utilities.GetFreeDiskSpace(Directories.Base) < 1024*1024*300)
@ -496,8 +502,11 @@ namespace Bloxstrap
Directory.CreateDirectory(Directories.Base); Directory.CreateDirectory(Directories.Base);
Dialog.CancelEnabled = true; if (Dialog is not null)
Dialog.ProgressStyle = ProgressBarStyle.Continuous; {
Dialog.CancelEnabled = true;
Dialog.ProgressStyle = ProgressBarStyle.Continuous;
}
// compute total bytes to download // compute total bytes to download
@ -521,9 +530,11 @@ namespace Bloxstrap
// allow progress bar to 100% before continuing (purely ux reasons lol) // allow progress bar to 100% before continuing (purely ux reasons lol)
await Task.Delay(1000); await Task.Delay(1000);
Dialog.ProgressStyle = ProgressBarStyle.Marquee; if (Dialog is not null)
{
Dialog.Message = "Configuring Roblox..."; Dialog.ProgressStyle = ProgressBarStyle.Marquee;
SetStatus("Configuring Roblox...");
}
// wait for all packages to finish extracting // wait for all packages to finish extracting
while (PackagesExtracted < VersionPackageManifest.Count) 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; App.State.Prop.VersionGuid = VersionGuid;
} }
private async Task ApplyModifications() private async Task ApplyModifications()
{ {
Dialog.Message = "Applying Roblox modifications..."; SetStatus("Applying Roblox modifications...");
string modFolder = Path.Combine(Directories.Modifications); string modFolder = Path.Combine(Directories.Modifications);