From cd411e33ff97ecec72624ce79d303a8cb66a9ab7 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sun, 8 Sep 2024 01:42:21 +0100 Subject: [PATCH] Use state entry for WebView2 runtime prompt --- Bloxstrap/Bootstrapper.cs | 40 +++++++++++++++++++++++++-------------- Bloxstrap/Models/State.cs | 2 ++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 4ad89c3b..8beaea43 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -36,8 +36,6 @@ public class Bootstrapper private readonly IAppData AppData; - private bool FreshInstall => !File.Exists(AppData.ExecutablePath) || String.IsNullOrEmpty(AppData.State.VersionGuid); - private string _launchCommandLine = App.LaunchSettings.RobloxLaunchArgs; private LaunchMode _launchMode = App.LaunchSettings.RobloxLaunchMode; private string _latestVersionGuid = null!; @@ -47,7 +45,7 @@ public class Bootstrapper private double _progressIncrement; private long _totalDownloadedBytes = 0; - private bool _mustUpgrade => File.Exists(AppData.LockFilePath) || !File.Exists(AppData.ExecutablePath); + private bool _mustUpgrade => String.IsNullOrEmpty(AppData.State.VersionGuid) || File.Exists(AppData.LockFilePath) || !File.Exists(AppData.ExecutablePath); private bool _noConnection = false; public IBootstrapperDialog? Dialog = null; @@ -164,12 +162,16 @@ public async Task Run() // TODO: handle exception and update skip await GetLatestVersionInfo(); - // install/update roblox if we're running for the first time, needs updating, or the player location doesn't exist - if (!_noConnection && (AppData.State.VersionGuid != _latestVersionGuid || _mustUpgrade)) - await UpgradeRoblox(); - if (!_noConnection) + { + if (AppData.State.VersionGuid != _latestVersionGuid || _mustUpgrade) + await UpgradeRoblox(); + + // we require deployment details for applying modifications for a worst case scenario, + // where we'd need to restore files from a package that isn't present on disk and needs to be redownloaded await ApplyModifications(); + } + // check if launch uri is set to our bootstrapper // this doesn't go under register, so we check every launch @@ -522,8 +524,11 @@ private async Task CheckForUpdates() private async Task UpgradeRoblox() { const string LOG_IDENT = "Bootstrapper::UpgradeRoblox"; - - SetStatus(FreshInstall ? Strings.Bootstrapper_Status_Installing : Strings.Bootstrapper_Status_Upgrading); + + if (String.IsNullOrEmpty(AppData.State.VersionGuid)) + SetStatus(Strings.Bootstrapper_Status_Installing); + else + SetStatus(Strings.Bootstrapper_Status_Upgrading); Directory.CreateDirectory(Paths.Base); Directory.CreateDirectory(Paths.Downloads); @@ -628,18 +633,25 @@ private async Task UpgradeRoblox() if (_cancelTokenSource.IsCancellationRequested) return; - // only prompt on fresh install, since we don't want to be prompting them for every single launch - // TODO: state entry? - if (FreshInstall) + if (App.State.Prop.PromptWebView2Install) { using var hklmKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"); using var hkcuKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"); - if (hklmKey is null && hkcuKey is null) + if (hklmKey is not null || hkcuKey is not null) + { + // reset prompt state if the user has it installed + App.State.Prop.PromptWebView2Install = true; + } + else { var result = Frontend.ShowMessageBox(Strings.Bootstrapper_WebView2NotFound, MessageBoxImage.Warning, MessageBoxButton.YesNo, MessageBoxResult.Yes); - if (result == MessageBoxResult.Yes) + if (result != MessageBoxResult.Yes) + { + App.State.Prop.PromptWebView2Install = false; + } + else { App.Logger.WriteLine(LOG_IDENT, "Installing WebView2 runtime..."); diff --git a/Bloxstrap/Models/State.cs b/Bloxstrap/Models/State.cs index 9aeea4aa..45e2ef44 100644 --- a/Bloxstrap/Models/State.cs +++ b/Bloxstrap/Models/State.cs @@ -3,6 +3,8 @@ public class State { public bool ShowFFlagEditorWarning { get; set; } = true; + + public bool PromptWebView2Install { get; set; } = true; public AppState Player { get; set; } = new();