From 38b1c584d29e38236eb0883507e05e0239c25501 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 16:14:48 +0100 Subject: [PATCH 01/50] Don't hardcode mfplat.dll check (#439) --- Bloxstrap/Bootstrapper.cs | 4 ++-- Bloxstrap/Directories.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 6824e312..6d4dbd64 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -205,7 +205,7 @@ private async Task StartRoblox() return; } - if (!File.Exists("C:\\Windows\\System32\\mfplat.dll")) + if (!File.Exists(Path.Combine(Directories.System, "mfplat.dll"))) { Controls.ShowMessageBox( "Roblox requires the use of Windows Media Foundation components. You appear to be missing them, likely because you are using an N edition of Windows. Please install them first, and then launch Roblox.", @@ -1093,7 +1093,7 @@ private async Task ApplyModifications() if (File.Exists(fileVersionFolder)) { - if (Utility.MD5Hash.FromFile(fileModFolder) == Utility.MD5Hash.FromFile(fileVersionFolder)) + if (MD5Hash.FromFile(fileModFolder) == MD5Hash.FromFile(fileVersionFolder)) continue; } diff --git a/Bloxstrap/Directories.cs b/Bloxstrap/Directories.cs index 21f9d13c..7f0141e9 100644 --- a/Bloxstrap/Directories.cs +++ b/Bloxstrap/Directories.cs @@ -8,7 +8,7 @@ static class Directories public static string LocalAppData => Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); public static string Desktop => Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); public static string StartMenu => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", App.ProjectName); - public static string MyPictures => Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); + public static string System => Environment.GetFolderPath(Environment.SpecialFolder.System); public static string Base { get; private set; } = ""; public static string Downloads { get; private set; } = ""; From 5cf51b33116889caf177c26f04d2f5ff0416d8b7 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 16:19:03 +0100 Subject: [PATCH 02/50] Fix install location warning showing twice (#438) --- Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs index 613240b8..5464a153 100644 --- a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs @@ -42,7 +42,7 @@ private void ConfirmSettings() bool shouldCheckInstallLocation = App.IsFirstRun || App.BaseDirectory != _originalBaseDirectory; - if (shouldCheckInstallLocation) + if (shouldCheckInstallLocation && NavigationVisibility == Visibility.Visible) { try { @@ -96,14 +96,15 @@ private void ConfirmSettings() ((INavigationWindow)_window).Navigate(typeof(PreInstallPage)); NavigationVisibility = Visibility.Collapsed; - ConfirmButtonEnabled = false; - OnPropertyChanged(nameof(NavigationVisibility)); + + ConfirmButtonEnabled = false; OnPropertyChanged(nameof(ConfirmButtonEnabled)); Task.Run(async delegate { await Task.Delay(3000); + ConfirmButtonEnabled = true; OnPropertyChanged(nameof(ConfirmButtonEnabled)); }); From dc3500e11056a2de7ef7b8942bb893e0b4cdada7 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 17:28:33 +0100 Subject: [PATCH 03/50] Don't force DPI scaling fixes --- Bloxstrap/FastFlagManager.cs | 7 +------ .../UI/Elements/Menu/Pages/FastFlagsPage.xaml | 20 +++++++++++++++++++ .../UI/ViewModels/Menu/FastFlagsViewModel.cs | 6 ++++++ Bloxstrap/Updater.cs | 9 +++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Bloxstrap/FastFlagManager.cs b/Bloxstrap/FastFlagManager.cs index 404528d4..618ba323 100644 --- a/Bloxstrap/FastFlagManager.cs +++ b/Bloxstrap/FastFlagManager.cs @@ -22,9 +22,7 @@ public class FastFlagManager : JsonManager> { "Rendering.Framerate", "DFIntTaskSchedulerTargetFps" }, { "Rendering.Fullscreen", "FFlagHandleAltEnterFullscreenManually" }, { "Rendering.TexturePack", "FStringPartTexturePackTable2022" }, - - { "Rendering.DPI.Disable", "DFFlagDisableDPIScale" }, - { "Rendering.DPI.Variable", "DFFlagVariableDPIScale2" }, + { "Rendering.DisableScaling", "DFFlagDisableDPIScale" }, { "Rendering.Mode.D3D11", "FFlagDebugGraphicsPreferD3D11" }, { "Rendering.Mode.D3D10", "FFlagDebugGraphicsPreferD3D11FL10" }, @@ -191,9 +189,6 @@ public override void Load() SetPresetOnce("Rendering.Framerate", 9999); SetPresetOnce("Rendering.Fullscreen", "False"); - - SetPresetOnce("Rendering.DPI.Disable", "True"); - SetPresetOnce("Rendering.DPI.Variable", "False"); } } } diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml index 31eae9dd..111c0710 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagsPage.xaml @@ -173,6 +173,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs index 3412a308..38592601 100644 --- a/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/FastFlagsViewModel.cs @@ -66,6 +66,12 @@ public string SelectedRenderingMode set => App.FastFlags.SetPresetEnum("Rendering.Mode", RenderingModes[value], "True"); } + public bool FixDisplayScaling + { + get => App.FastFlags.GetPreset("Rendering.DisableScaling") == "True"; + set => App.FastFlags.SetPreset("Rendering.DisableScaling", value ? "True" : null); + } + public bool AlternateGraphicsSelectorEnabled { get => App.FastFlags.GetPreset("UI.Menu.GraphicsSlider") == "True"; diff --git a/Bloxstrap/Updater.cs b/Bloxstrap/Updater.cs index 4e091e96..e1fb8e7b 100644 --- a/Bloxstrap/Updater.cs +++ b/Bloxstrap/Updater.cs @@ -67,6 +67,15 @@ public static void CheckInstalledVersion() Bootstrapper.Register(); + // update migrations + + if (App.BuildMetadata.CommitRef.StartsWith("tag") && App.Version == "2.4.1") + { + App.FastFlags.SetValue("DFFlagDisableDPIScale", null); + App.FastFlags.SetValue("DFFlagVariableDPIScale2", null); + App.FastFlags.Save(); + } + if (isAutoUpgrade) { App.NotifyIcon?.ShowAlert( From f02fba2ce14409e54e8e4c5aefab0cdab43d85a0 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 17:52:23 +0100 Subject: [PATCH 04/50] Fix font application mod on first install --- Bloxstrap/App.xaml.cs | 2 ++ Bloxstrap/Bootstrapper.cs | 10 +++++++--- Bloxstrap/Directories.cs | 2 ++ .../UI/ViewModels/Menu/MainWindowViewModel.cs | 2 +- Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs | 19 ++++++++++++++----- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 13ed82b1..7b867354 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -17,8 +17,10 @@ public partial class App : Application // used only for communicating between app and menu - use Directories.Base for anything else public static string BaseDirectory = null!; + public static string? CustomFontLocation; public static bool ShouldSaveConfigs { get; set; } = false; + public static bool IsSetupComplete { get; set; } = true; public static bool IsFirstRun { get; private set; } = true; public static bool IsQuiet { get; private set; } = false; diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 6d4dbd64..acf18610 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -980,7 +980,6 @@ private async Task ApplyModifications() bool appDisabled = App.Settings.Prop.UseDisableAppPatch && !_launchCommandLine.Contains("--deeplink"); // cursors - await CheckModPreset(App.Settings.Prop.CursorType == CursorType.From2006, new Dictionary { { @"content\textures\Cursors\KeyboardMouse\ArrowCursor.png", "Cursor.From2006.ArrowCursor.png" }, @@ -1036,9 +1035,14 @@ private async Task ApplyModifications() // instead of replacing the fonts themselves, we'll just alter the font family manifests string modFontFamiliesFolder = Path.Combine(Directories.Modifications, "content\\fonts\\families"); - string customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf"); - if (File.Exists(customFontLocation)) + if (App.IsFirstRun && App.CustomFontLocation is not null) + { + Directory.CreateDirectory(Path.GetDirectoryName(Directories.CustomFont)!); + File.Copy(App.CustomFontLocation, Directories.CustomFont); + } + + if (File.Exists(Directories.CustomFont)) { App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Begin font check"); diff --git a/Bloxstrap/Directories.cs b/Bloxstrap/Directories.cs index 7f0141e9..c98a6137 100644 --- a/Bloxstrap/Directories.cs +++ b/Bloxstrap/Directories.cs @@ -19,6 +19,8 @@ static class Directories public static string Application { get; private set; } = ""; + public static string CustomFont => Path.Combine(Modifications, "content\\fonts\\CustomFont.ttf"); + public static bool Initialized => !String.IsNullOrEmpty(Base); public static void Initialize(string baseDirectory) diff --git a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs index 5464a153..2049a44a 100644 --- a/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/MainWindowViewModel.cs @@ -75,7 +75,7 @@ private void ConfirmSettings() $"The folder you've chosen to install {App.ProjectName} to already exists and is NOT empty. It is strongly recommended for {App.ProjectName} to be installed to its own independent folder.\n\n" + "Changing to the following location is suggested:\n" + $"{suggestedChange}\n\n" + - "Would you like to change your install location to this?\n" + + "Would you like to change to the suggested location?\n" + "Selecting 'No' will ignore this warning and continue installation.", MessageBoxImage.Warning, MessageBoxButton.YesNoCancel, diff --git a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs index 3502350d..a5fde9c4 100644 --- a/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/ModsViewModel.cs @@ -11,14 +11,16 @@ public class ModsViewModel : NotifyPropertyChangedViewModel { private void OpenModsFolder() => Process.Start("explorer.exe", Directories.Modifications); - private string _customFontLocation = Path.Combine(Directories.Modifications, "content\\fonts\\CustomFont.ttf"); - private bool _usingCustomFont => File.Exists(_customFontLocation); + private bool _usingCustomFont => App.IsFirstRun && App.CustomFontLocation is not null || !App.IsFirstRun && File.Exists(Directories.CustomFont); private void ManageCustomFont() { if (_usingCustomFont) { - File.Delete(_customFontLocation); + if (App.IsFirstRun) + App.CustomFontLocation = null; + else + File.Delete(Directories.CustomFont); } else { @@ -30,8 +32,15 @@ private void ManageCustomFont() if (dialog.ShowDialog() != true) return; - Directory.CreateDirectory(Path.GetDirectoryName(_customFontLocation)!); - File.Copy(dialog.FileName, _customFontLocation); + if (App.IsFirstRun) + { + App.CustomFontLocation = dialog.FileName; + } + else + { + Directory.CreateDirectory(Path.GetDirectoryName(Directories.CustomFont)!); + File.Copy(dialog.FileName, Directories.CustomFont); + } } OnPropertyChanged(nameof(ChooseCustomFontVisibility)); From 6652d4330835824ce3b7d921b681e94c1248d010 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 18:08:37 +0100 Subject: [PATCH 05/50] Improve server location fetch handling (#445) --- Bloxstrap/RobloxActivity.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Bloxstrap/RobloxActivity.cs b/Bloxstrap/RobloxActivity.cs index 0c5ab82a..26d75cf0 100644 --- a/Bloxstrap/RobloxActivity.cs +++ b/Bloxstrap/RobloxActivity.cs @@ -265,11 +265,21 @@ public async Task GetServerLocation() if (GeolcationCache.ContainsKey(ActivityMachineAddress)) return GeolcationCache[ActivityMachineAddress]; - string location = ""; + string location, locationCity, locationRegion, locationCountry = ""; - string locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/city"); - string locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/region"); - string locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/country"); + try + { + locationCity = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/city"); + locationRegion = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/region"); + locationCountry = await App.HttpClient.GetStringAsync($"https://ipinfo.io/{ActivityMachineAddress}/country"); + } + catch (Exception ex) + { + App.Logger.WriteLine($"[RobloxActivity::GetServerLocation] Failed to get server location for {ActivityMachineAddress}"); + App.Logger.WriteLine($"[RobloxActivity::GetServerLocation] {ex}"); + + return "N/A (lookup failed)"; + } locationCity = locationCity.ReplaceLineEndings(""); locationRegion = locationRegion.ReplaceLineEndings(""); From b5f4017326807ad69b5de67b53b714286e468b34 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 18:20:33 +0100 Subject: [PATCH 06/50] Sort names alphabetically in the FFlag editor --- Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs index 112c49ca..dd9fc9d0 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs +++ b/Bloxstrap/UI/Elements/Menu/Pages/FastFlagEditorPage.xaml.cs @@ -33,7 +33,7 @@ private void ReloadList() var presetFlags = FastFlagManager.PresetFlags.Values; - foreach (var pair in App.FastFlags.Prop) + foreach (var pair in App.FastFlags.Prop.OrderBy(x => x.Key)) { if (!_showPresets && presetFlags.Contains(pair.Key)) continue; From 1df1a8495c86b48e937edb2229f22f0ade232f24 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 25 Jul 2023 19:08:43 +0100 Subject: [PATCH 07/50] Make logging more consistent consistent prefix names, and logging exceptions in english --- Bloxstrap/App.xaml.cs | 52 +++---- Bloxstrap/Bootstrapper.cs | 141 +++++++++++------- Bloxstrap/Extensions/BootstrapperIconEx.cs | 5 +- Bloxstrap/FastFlagManager.cs | 8 +- Bloxstrap/HttpClientLoggingHandler.cs | 4 +- Bloxstrap/Integrations/DiscordRichPresence.cs | 56 ++++--- Bloxstrap/JsonManager.cs | 23 ++- Bloxstrap/Logger.cs | 24 ++- Bloxstrap/ProtocolHandler.cs | 4 +- Bloxstrap/RobloxActivity.cs | 50 ++++--- Bloxstrap/RobloxDeployment.cs | 24 +-- .../ContextMenu/MenuContainer.xaml.cs | 2 +- Bloxstrap/UI/Elements/Menu/MainWindow.xaml.cs | 2 +- Bloxstrap/UI/NotifyIconWrapper.cs | 18 ++- .../UI/ViewModels/Menu/BehaviourViewModel.cs | 6 +- .../UI/ViewModels/Menu/MainWindowViewModel.cs | 2 +- Bloxstrap/Updater.cs | 6 +- Bloxstrap/Utility/Http.cs | 6 +- 18 files changed, 258 insertions(+), 175 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 7b867354..a9c4efc1 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -53,7 +53,7 @@ public static void Terminate(ErrorCode exitCode = ErrorCode.ERROR_SUCCESS) int exitCodeNum = (int)exitCode; - Logger.WriteLine($"[App::Terminate] Terminating with exit code {exitCodeNum} ({exitCode})"); + Logger.WriteLine("App::Terminate", $"Terminating with exit code {exitCodeNum} ({exitCode})"); Settings.Save(); State.Save(); @@ -66,8 +66,8 @@ void GlobalExceptionHandler(object sender, DispatcherUnhandledExceptionEventArgs { e.Handled = true; - Logger.WriteLine("[App::OnStartup] An exception occurred when running the main thread"); - Logger.WriteLine($"[App::OnStartup] {e.Exception}"); + Logger.WriteLine("App::GlobalExceptionHandler", "An exception occurred"); + Logger.WriteLine("App::GlobalExceptionHandler", $"{e.Exception}"); FinalizeExceptionHandling(e.Exception); } @@ -86,14 +86,16 @@ void FinalizeExceptionHandling(Exception exception) protected override void OnStartup(StartupEventArgs e) { + const string LOG_IDENT = "App::OnStartup"; + base.OnStartup(e); - Logger.WriteLine($"[App::OnStartup] Starting {ProjectName} v{Version}"); + Logger.WriteLine(LOG_IDENT, $"Starting {ProjectName} v{Version}"); if (String.IsNullOrEmpty(BuildMetadata.CommitHash)) - Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from {BuildMetadata.Machine}"); + Logger.WriteLine(LOG_IDENT, $"Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from {BuildMetadata.Machine}"); else - Logger.WriteLine($"[App::OnStartup] Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from commit {BuildMetadata.CommitHash} ({BuildMetadata.CommitRef})"); + Logger.WriteLine(LOG_IDENT, $"Compiled {BuildMetadata.Timestamp.ToFriendlyString()} from commit {BuildMetadata.CommitHash} ({BuildMetadata.CommitRef})"); // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. @@ -108,31 +110,31 @@ protected override void OnStartup(StartupEventArgs e) { if (Array.IndexOf(LaunchArgs, "-preferences") != -1 || Array.IndexOf(LaunchArgs, "-menu") != -1) { - Logger.WriteLine("[App::OnStartup] Started with IsMenuLaunch flag"); + Logger.WriteLine(LOG_IDENT, "Started with IsMenuLaunch flag"); IsMenuLaunch = true; } if (Array.IndexOf(LaunchArgs, "-quiet") != -1) { - Logger.WriteLine("[App::OnStartup] Started with IsQuiet flag"); + Logger.WriteLine(LOG_IDENT, "Started with IsQuiet flag"); IsQuiet = true; } if (Array.IndexOf(LaunchArgs, "-uninstall") != -1) { - Logger.WriteLine("[App::OnStartup] Started with IsUninstall flag"); + Logger.WriteLine(LOG_IDENT, "Started with IsUninstall flag"); IsUninstall = true; } if (Array.IndexOf(LaunchArgs, "-nolaunch") != -1) { - Logger.WriteLine("[App::OnStartup] Started with IsNoLaunch flag"); + Logger.WriteLine(LOG_IDENT, "Started with IsNoLaunch flag"); IsNoLaunch = true; } if (Array.IndexOf(LaunchArgs, "-upgrade") != -1) { - Logger.WriteLine("[App::OnStartup] Bloxstrap started with IsUpgrade flag"); + Logger.WriteLine(LOG_IDENT, "Bloxstrap started with IsUpgrade flag"); IsUpgrade = true; } } @@ -147,7 +149,7 @@ protected override void OnStartup(StartupEventArgs e) if (registryKey is null || installLocation is null) { - Logger.WriteLine("[App::OnStartup] Running first-time install"); + Logger.WriteLine(LOG_IDENT, "Running first-time install"); BaseDirectory = Path.Combine(Directories.LocalAppData, ProjectName); Logger.Initialize(true); @@ -169,7 +171,7 @@ protected override void OnStartup(StartupEventArgs e) // exit if we don't click the install button on installation if (!IsSetupComplete) { - Logger.WriteLine("[App::OnStartup] Installation cancelled!"); + Logger.WriteLine(LOG_IDENT, "Installation cancelled!"); Terminate(ErrorCode.ERROR_CANCELLED); } @@ -183,7 +185,7 @@ protected override void OnStartup(StartupEventArgs e) if (!Logger.Initialized) { - Logger.WriteLine("[App::OnStartup] Possible duplicate launch detected, terminating."); + Logger.WriteLine(LOG_IDENT, "Possible duplicate launch detected, terminating."); Terminate(); } @@ -209,7 +211,7 @@ protected override void OnStartup(StartupEventArgs e) if (menuProcess is not null) { IntPtr handle = menuProcess.MainWindowHandle; - Logger.WriteLine($"[App::OnStartup] Found an already existing menu window with handle {handle}"); + Logger.WriteLine(LOG_IDENT, $"Found an already existing menu window with handle {handle}"); NativeMethods.SetForegroundWindow(handle); } else @@ -255,13 +257,13 @@ protected override void OnStartup(StartupEventArgs e) ShouldSaveConfigs = true; // start bootstrapper and show the bootstrapper modal if we're not running silently - Logger.WriteLine($"[App::OnStartup] Initializing bootstrapper"); + Logger.WriteLine(LOG_IDENT, "Initializing bootstrapper"); Bootstrapper bootstrapper = new(commandLine); IBootstrapperDialog? dialog = null; if (!IsQuiet) { - Logger.WriteLine($"[App::OnStartup] Initializing bootstrapper dialog"); + Logger.WriteLine(LOG_IDENT, "Initializing bootstrapper dialog"); dialog = Settings.Prop.BootstrapperStyle.GetNew(); bootstrapper.Dialog = dialog; dialog.Bootstrapper = bootstrapper; @@ -275,12 +277,12 @@ protected override void OnStartup(StartupEventArgs e) if (Settings.Prop.MultiInstanceLaunching) { - Logger.WriteLine("[App::OnStartup] Creating singleton mutex"); + Logger.WriteLine(LOG_IDENT, "Creating singleton mutex"); try { Mutex.OpenExisting("ROBLOX_singletonMutex"); - Logger.WriteLine("[App::OnStartup] Warning - singleton mutex already exists!"); + Logger.WriteLine(LOG_IDENT, "Warning - singleton mutex already exists!"); } catch { @@ -293,18 +295,18 @@ protected override void OnStartup(StartupEventArgs e) bootstrapperTask.ContinueWith(t => { - Logger.WriteLine("[App::OnStartup] Bootstrapper task has finished"); + Logger.WriteLine(LOG_IDENT, "Bootstrapper task has finished"); // notifyicon is blocking main thread, must be disposed here NotifyIcon?.Dispose(); if (t.IsFaulted) - Logger.WriteLine("[App::OnStartup] An exception occurred when running the bootstrapper"); + Logger.WriteLine(LOG_IDENT, "An exception occurred when running the bootstrapper"); if (t.Exception is null) return; - Logger.WriteLine($"[App::OnStartup] {t.Exception}"); + Logger.WriteLine(LOG_IDENT, $"{t.Exception}"); Exception exception = t.Exception; @@ -322,13 +324,13 @@ protected override void OnStartup(StartupEventArgs e) if (!IsNoLaunch && Settings.Prop.EnableActivityTracking) NotifyIcon?.InitializeContextMenu(); - Logger.WriteLine($"[App::OnStartup] Waiting for bootstrapper task to finish"); + Logger.WriteLine(LOG_IDENT, "Waiting for bootstrapper task to finish"); bootstrapperTask.Wait(); if (singletonMutex is not null) { - Logger.WriteLine($"[App::OnStartup] We have singleton mutex ownership! Running in background until all Roblox processes are closed"); + Logger.WriteLine(LOG_IDENT, "We have singleton mutex ownership! Running in background until all Roblox processes are closed"); // we've got ownership of the roblox singleton mutex! // if we stop running, everything will screw up once any more roblox instances launched @@ -337,7 +339,7 @@ protected override void OnStartup(StartupEventArgs e) } } - Logger.WriteLine($"[App::OnStartup] Successfully reached end of main thread. Terminating..."); + Logger.WriteLine(LOG_IDENT, "Successfully reached end of main thread. Terminating..."); Terminate(); } diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index acf18610..398f6e51 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -79,7 +79,7 @@ public Bootstrapper(string launchCommandLine) private void SetStatus(string message) { - App.Logger.WriteLine($"[Bootstrapper::SetStatus] {message}"); + App.Logger.WriteLine("Bootstrapper::SetStatus", message); // yea idk if (App.Settings.Prop.BootstrapperStyle == BootstrapperStyle.ByfronDialog) @@ -104,7 +104,9 @@ private void UpdateProgressBar() public async Task Run() { - App.Logger.WriteLine("[Bootstrapper::Run] Running bootstrapper"); + const string LOG_IDENT = "Bootstrapper::Run"; + + App.Logger.WriteLine(LOG_IDENT, "Running bootstrapper"); if (App.IsUninstall) { @@ -125,7 +127,7 @@ public async Task Run() try { Mutex.OpenExisting("Bloxstrap_BootstrapperMutex").Close(); - App.Logger.WriteLine("[Bootstrapper::Run] Bloxstrap_BootstrapperMutex mutex exists, waiting..."); + App.Logger.WriteLine(LOG_IDENT, "Bloxstrap_BootstrapperMutex mutex exists, waiting..."); mutexExists = true; } catch (Exception) @@ -196,6 +198,8 @@ private async Task CheckLatestVersion() private async Task StartRoblox() { + const string LOG_IDENT = "Bootstrapper::StartRoblox"; + SetStatus("Starting Roblox..."); if (_launchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch) @@ -235,7 +239,7 @@ private async Task StartRoblox() RobloxActivity? activityWatcher = null; DiscordRichPresence? richPresence = null; - App.Logger.WriteLine($"[Bootstrapper::StartRoblox] Started Roblox (PID {gameClientPid})"); + App.Logger.WriteLine(LOG_IDENT, $"Started Roblox (PID {gameClientPid})"); using (SystemEvent startEvent = new("www.roblox.com/robloxStartedEvent")) { @@ -256,7 +260,7 @@ private async Task StartRoblox() if (App.Settings.Prop.UseDiscordRichPresence) { - App.Logger.WriteLine("[Bootstrapper::StartRoblox] Using Discord Rich Presence"); + App.Logger.WriteLine(LOG_IDENT, "Using Discord Rich Presence"); richPresence = new(activityWatcher); App.NotifyIcon?.SetRichPresenceHandler(richPresence); @@ -266,7 +270,7 @@ private async Task StartRoblox() // launch custom integrations now foreach (CustomIntegration integration in App.Settings.Prop.CustomIntegrations) { - App.Logger.WriteLine($"[Bootstrapper::StartRoblox] Launching custom integration '{integration.Name}' ({integration.Location} {integration.LaunchArgs} - autoclose is {integration.AutoClose})"); + App.Logger.WriteLine(LOG_IDENT, $"Launching custom integration '{integration.Name}' ({integration.Location} {integration.LaunchArgs} - autoclose is {integration.AutoClose})"); try { @@ -280,7 +284,8 @@ private async Task StartRoblox() } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::StartRoblox] Failed to launch integration '{integration.Name}'! ({ex.Message})"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to launch integration '{integration.Name}'!"); + App.Logger.WriteLine(LOG_IDENT, $"{ex.Message}"); } } @@ -294,12 +299,12 @@ private async Task StartRoblox() activityWatcher?.StartWatcher(); - App.Logger.WriteLine("[Bootstrapper::StartRoblox] Waiting for Roblox to close"); + App.Logger.WriteLine(LOG_IDENT, "Waiting for Roblox to close"); while (Process.GetProcesses().Any(x => x.Id == gameClientPid)) await Task.Delay(1000); - App.Logger.WriteLine($"[Bootstrapper::StartRoblox] Roblox has exited"); + App.Logger.WriteLine(LOG_IDENT, $"Roblox has exited"); richPresence?.Dispose(); @@ -308,20 +313,22 @@ private async Task StartRoblox() if (process.HasExited) continue; - App.Logger.WriteLine($"[Bootstrapper::StartRoblox] Autoclosing process '{process.ProcessName}' (PID {process.Id})"); + App.Logger.WriteLine(LOG_IDENT, $"Autoclosing process '{process.ProcessName}' (PID {process.Id})"); process.Kill(); } } public void CancelInstall() { + const string LOG_IDENT = "Bootstrapper::CancelInstall"; + if (!_isInstalling) { App.Terminate(ErrorCode.ERROR_CANCELLED); return; } - App.Logger.WriteLine("[Bootstrapper::CancelInstall] Cancelling install..."); + App.Logger.WriteLine(LOG_IDENT, "Cancelling install..."); _cancelTokenSource.Cancel(); _cancelFired = true; @@ -336,8 +343,8 @@ public void CancelInstall() } catch (Exception ex) { - App.Logger.WriteLine("[Bootstrapper::CancelInstall] Could not fully clean up installation!"); - App.Logger.WriteLine($"[Bootstrapper::CancelInstall] {ex}"); + App.Logger.WriteLine(LOG_IDENT, "Could not fully clean up installation!"); + App.Logger.WriteException(LOG_IDENT, ex); } App.Terminate(ErrorCode.ERROR_CANCELLED); @@ -347,6 +354,8 @@ public void CancelInstall() #region App Install public static void Register() { + const string LOG_IDENT = "Bootstrapper::Register"; + using (RegistryKey applicationKey = Registry.CurrentUser.CreateSubKey($@"Software\{App.ProjectName}")) { applicationKey.SetValue("InstallLocation", Directories.Base); @@ -372,12 +381,14 @@ public static void Register() uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{App.ProjectRepository}/releases/latest"); } - App.Logger.WriteLine("[Bootstrapper::StartRoblox] Registered application"); + App.Logger.WriteLine(LOG_IDENT, "Registered application"); } public void RegisterProgramSize() { - App.Logger.WriteLine("[Bootstrapper::RegisterProgramSize] Registering approximate program size..."); + const string LOG_IDENT = "Bootstrapper::RegisterProgramSize"; + + App.Logger.WriteLine(LOG_IDENT, "Registering approximate program size..."); using RegistryKey uninstallKey = Registry.CurrentUser.CreateSubKey($"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{App.ProjectName}"); @@ -386,11 +397,13 @@ public void RegisterProgramSize() uninstallKey.SetValue("EstimatedSize", totalSize); - App.Logger.WriteLine($"[Bootstrapper::RegisterProgramSize] Registered as {totalSize} KB"); + App.Logger.WriteLine(LOG_IDENT, $"Registered as {totalSize} KB"); } private void CheckInstallMigration() { + const string LOG_IDENT = "Bootstrapper::CheckInstallMigration"; + // check if we've changed our install location since the last time we started // in which case, we'll have to copy over all our folders so we don't lose any mods and stuff @@ -405,7 +418,7 @@ private void CheckInstallMigration() if (Directory.Exists(oldInstallLocation)) { - App.Logger.WriteLine($"[Bootstrapper::CheckInstallMigration] Moving all files in {oldInstallLocation} to {Directories.Base}..."); + App.Logger.WriteLine(LOG_IDENT, $"Moving all files in {oldInstallLocation} to {Directories.Base}..."); foreach (string oldFileLocation in Directory.GetFiles(oldInstallLocation, "*.*", SearchOption.AllDirectories)) { @@ -422,18 +435,18 @@ private void CheckInstallMigration() } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::CheckInstallMigration] Failed to move {oldFileLocation} to {newFileLocation}! {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to move {oldFileLocation} to {newFileLocation}! {ex}"); } } try { Directory.Delete(oldInstallLocation, true); - App.Logger.WriteLine("[Bootstrapper::CheckInstallMigration] Deleted old install location"); + App.Logger.WriteLine(LOG_IDENT, "Deleted old install location"); } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::CheckInstallMigration] Failed to delete old install location! {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to delete old install location! {ex}"); } } @@ -449,12 +462,14 @@ private void CheckInstallMigration() App.Settings.Prop.CreateDesktopIcon = true; } - App.Logger.WriteLine("[Bootstrapper::CheckInstallMigration] Finished migrating install location!"); + App.Logger.WriteLine(LOG_IDENT, "Finished migrating install location!"); } public static void CheckInstall() { - App.Logger.WriteLine("[Bootstrapper::CheckInstall] Checking install"); + const string LOG_IDENT = "Bootstrapper::CheckInstall"; + + App.Logger.WriteLine(LOG_IDENT, "Checking install"); // check if launch uri is set to our bootstrapper // this doesn't go under register, so we check every launch @@ -509,8 +524,8 @@ public static void CheckInstall() } catch (Exception ex) { - App.Logger.WriteLine("[Bootstrapper::CheckInstall] Could not create desktop shortcut, aborting"); - App.Logger.WriteLine($"[Bootstrapper::CheckInstall] {ex}"); + App.Logger.WriteLine(LOG_IDENT, "Could not create desktop shortcut, aborting"); + App.Logger.WriteException(LOG_IDENT, ex); } } @@ -521,14 +536,16 @@ public static void CheckInstall() private async Task CheckForUpdates() { + const string LOG_IDENT = "Bootstrapper::CheckForUpdates"; + // don't update if there's another instance running (likely running in the background) if (Process.GetProcessesByName(App.ProjectName).Count() > 1) { - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] More than one Bloxstrap instance running, aborting update check"); + App.Logger.WriteLine(LOG_IDENT, $"More than one Bloxstrap instance running, aborting update check"); return; } - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Checking for updates..."); + App.Logger.WriteLine(LOG_IDENT, $"Checking for updates..."); GithubRelease? releaseInfo; try @@ -537,13 +554,13 @@ private async Task CheckForUpdates() } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Failed to fetch releases: {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to fetch releases: {ex}"); return; } if (releaseInfo is null || releaseInfo.Assets is null) { - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found"); + App.Logger.WriteLine(LOG_IDENT, $"No updates found"); return; } @@ -552,7 +569,7 @@ private async Task CheckForUpdates() // check if we aren't using a deployed build, so we can update to one if a new version comes out if (versionComparison == 0 && App.BuildMetadata.CommitRef.StartsWith("tag") || versionComparison == 1) { - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] No updates found"); + App.Logger.WriteLine(LOG_IDENT, $"No updates found"); return; } @@ -563,7 +580,7 @@ private async Task CheckForUpdates() GithubReleaseAsset asset = releaseInfo.Assets[0]; string downloadLocation = Path.Combine(Directories.LocalAppData, "Temp", asset.Name); - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Downloading {releaseInfo.TagName}..."); + App.Logger.WriteLine(LOG_IDENT, $"Downloading {releaseInfo.TagName}..."); if (!File.Exists(downloadLocation)) { @@ -573,7 +590,7 @@ private async Task CheckForUpdates() await response.Content.CopyToAsync(fileStream); } - App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] Starting {releaseInfo.TagName}..."); + App.Logger.WriteLine(LOG_IDENT, $"Starting {releaseInfo.TagName}..."); ProcessStartInfo startInfo = new() { @@ -593,10 +610,12 @@ private async Task CheckForUpdates() private void Uninstall() { + const string LOG_IDENT = "Bootstrapper::Uninstall"; + // prompt to shutdown roblox if its currently running if (Process.GetProcessesByName(App.RobloxAppName).Any()) { - App.Logger.WriteLine($"[Bootstrapper::Uninstall] Prompting to shut down all open Roblox instances"); + App.Logger.WriteLine(LOG_IDENT, $"Prompting to shut down all open Roblox instances"); MessageBoxResult result = Controls.ShowMessageBox( "Roblox is currently running, but must be closed before uninstalling Bloxstrap. Would you like close Roblox now?", @@ -617,10 +636,10 @@ private void Uninstall() } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] Failed to close process! {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to close process! {ex}"); } - App.Logger.WriteLine($"[Bootstrapper::Uninstall] All Roblox processes closed"); + App.Logger.WriteLine(LOG_IDENT, $"All Roblox processes closed"); } SetStatus($"Uninstalling {App.ProjectName}..."); @@ -680,8 +699,8 @@ private void Uninstall() } catch (Exception ex) { - App.Logger.WriteLine($"[Bootstrapper::Uninstall] Encountered exception when running cleanup sequence (#{cleanupSequence.IndexOf(process)})"); - App.Logger.WriteLine($"[Bootstrapper::Uninstall] {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Encountered exception when running cleanup sequence (#{cleanupSequence.IndexOf(process)})"); + App.Logger.WriteException(LOG_IDENT, ex); } } @@ -719,6 +738,8 @@ private void Uninstall() #region Roblox Install private async Task InstallLatestVersion() { + const string LOG_IDENT = "Bootstrapper::InstallLatestVersion"; + _isInstalling = true; SetStatus(FreshInstall ? "Installing Roblox..." : "Upgrading Roblox..."); @@ -800,7 +821,7 @@ private async Task InstallLatestVersion() { if (!_versionPackageManifest.Exists(package => filename.Contains(package.Signature))) { - App.Logger.WriteLine($"[Bootstrapper::InstallLatestVersion] Deleting unused package {filename}"); + App.Logger.WriteLine(LOG_IDENT, $"Deleting unused package {filename}"); File.Delete(filename); } } @@ -815,7 +836,7 @@ private async Task InstallLatestVersion() if (appFlags is not null) { - App.Logger.WriteLine($"[Bootstrapper::InstallLatestVersion] Migrating app compatibility flags from {oldGameClientLocation} to {_playerLocation}..."); + App.Logger.WriteLine(LOG_IDENT, $"Migrating app compatibility flags from {oldGameClientLocation} to {_playerLocation}..."); appFlagsKey.SetValue(_playerLocation, appFlags); appFlagsKey.DeleteValue(oldGameClientLocation); } @@ -831,7 +852,7 @@ private async Task InstallLatestVersion() if (dir.Name == _latestVersionGuid || !dir.Name.StartsWith("version-")) continue; - App.Logger.WriteLine($"[Bootstrapper::InstallLatestVersion] Removing old version folder for {dir.Name}"); + App.Logger.WriteLine(LOG_IDENT, $"Removing old version folder for {dir.Name}"); dir.Delete(true); } } @@ -851,6 +872,8 @@ private async Task InstallLatestVersion() private async Task InstallWebView2() { + const string LOG_IDENT = "Bootstrapper::InstallWebView2"; + // check if the webview2 runtime needs to be installed // webview2 can either be installed be per-user or globally, so we need to check in both hklm and hkcu // https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#detect-if-a-suitable-webview2-runtime-is-already-installed @@ -861,7 +884,7 @@ private async Task InstallWebView2() if (hklmKey is not null || hkcuKey is not null) return; - App.Logger.WriteLine($"[Bootstrapper::InstallWebView2] Installing runtime..."); + App.Logger.WriteLine(LOG_IDENT, "Installing runtime..."); string baseDirectory = Path.Combine(_versionFolder, "WebView2RuntimeInstaller"); @@ -871,7 +894,7 @@ private async Task InstallWebView2() if (package is null) { - App.Logger.WriteLine($"[Bootstrapper::InstallWebView2] Aborted runtime install because package does not exist, has WebView2 been added in this Roblox version yet?"); + App.Logger.WriteLine(LOG_IDENT, "Aborted runtime install because package does not exist, has WebView2 been added in this Roblox version yet?"); return; } @@ -889,7 +912,7 @@ private async Task InstallWebView2() await Process.Start(startInfo)!.WaitForExitAsync(); - App.Logger.WriteLine($"[Bootstrapper::InstallWebView2] Finished installing runtime"); + App.Logger.WriteLine(LOG_IDENT, "Finished installing runtime"); } public static void MigrateIntegrations() @@ -921,10 +944,12 @@ public static void MigrateIntegrations() private async Task ApplyModifications() { + const string LOG_IDENT = "Bootstrapper::ApplyModifications"; + SetStatus("Applying Roblox modifications..."); // set executable flags for fullscreen optimizations - App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Checking executable flags..."); + App.Logger.WriteLine(LOG_IDENT, "Checking executable flags..."); using (RegistryKey appFlagsKey = Registry.CurrentUser.CreateSubKey($"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers")) { string flag = " DISABLEDXMAXIMIZEDWINDOWEDMODE"; @@ -939,7 +964,7 @@ private async Task ApplyModifications() } else if (appFlags is not null && appFlags.Contains(flag)) { - App.Logger.WriteLine($"[Bootstrapper::ApplyModifications] Deleting flag '{flag.Trim()}'"); + App.Logger.WriteLine(LOG_IDENT, $"Deleting flag '{flag.Trim()}'"); // if there's more than one space, there's more flags set we need to preserve if (appFlags.Split(' ').Length > 2) @@ -955,7 +980,7 @@ private async Task ApplyModifications() if (appFlags is not null && appFlags.Contains(flag)) { - App.Logger.WriteLine($"[Bootstrapper::ApplyModifications] Deleting flag '{flag.Trim()}'"); + App.Logger.WriteLine(LOG_IDENT, $"Deleting flag '{flag.Trim()}'"); // if there's more than one space, there's more flags set we need to preserve if (appFlags.Split(' ').Length > 2) @@ -966,7 +991,7 @@ private async Task ApplyModifications() } // handle file mods - App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Checking file mods..."); + App.Logger.WriteLine(LOG_IDENT, "Checking file mods..."); string modFolder = Path.Combine(Directories.Modifications); // manifest has been moved to State.json @@ -1044,7 +1069,7 @@ private async Task ApplyModifications() if (File.Exists(Directories.CustomFont)) { - App.Logger.WriteLine("[Bootstrapper::ApplyModifications] Begin font check"); + App.Logger.WriteLine(LOG_IDENT, "Begin font check"); Directory.CreateDirectory(modFontFamiliesFolder); @@ -1067,7 +1092,7 @@ private async Task ApplyModifications() File.WriteAllText(modFilepath, JsonSerializer.Serialize(fontFamilyData, new JsonSerializerOptions { WriteIndented = true })); } - App.Logger.WriteLine("[Bootstrapper::ApplyModifications] End font check"); + App.Logger.WriteLine(LOG_IDENT, "End font check"); } else if (Directory.Exists(modFontFamiliesFolder)) { @@ -1182,6 +1207,8 @@ private static async Task CheckModPreset(bool condition, Dictionary ZipFile.OpenRead(packageLocation)); @@ -1279,7 +1308,7 @@ private async Task ExtractPackage(Package package) extractPath = Path.Combine(packageFolder, entry.FullName); - //App.Logger.WriteLine($"[{package.Name}] Writing {extractPath}..."); + //App.Logger.WriteLine("{package.Name}", $"Writing {extractPath}..."); string? directory = Path.GetDirectoryName(extractPath); @@ -1296,7 +1325,7 @@ private async Task ExtractPackage(Package package) File.SetLastWriteTime(extractPath, entry.LastWriteTime.DateTime); } - App.Logger.WriteLine($"[Bootstrapper::ExtractPackage] Finished extracting {package.Name}"); + App.Logger.WriteLine(LOG_IDENT, $"Finished extracting {package.Name}"); _packagesExtracted += 1; } diff --git a/Bloxstrap/Extensions/BootstrapperIconEx.cs b/Bloxstrap/Extensions/BootstrapperIconEx.cs index 90656a76..49df9698 100644 --- a/Bloxstrap/Extensions/BootstrapperIconEx.cs +++ b/Bloxstrap/Extensions/BootstrapperIconEx.cs @@ -10,6 +10,8 @@ static class BootstrapperIconEx public static Icon GetIcon(this BootstrapperIcon icon) { + const string LOG_IDENT = "BootstrapperIconEx::GetIcon"; + // load the custom icon file if (icon == BootstrapperIcon.IconCustom) { @@ -21,7 +23,8 @@ public static Icon GetIcon(this BootstrapperIcon icon) } catch (Exception ex) { - App.Logger.WriteLine($"[BootstrapperIconEx::GetIcon] Failed to load custom icon! {ex}"); + App.Logger.WriteLine(LOG_IDENT, $"Failed to load custom icon!"); + App.Logger.WriteException(LOG_IDENT, ex); } return customIcon ?? Properties.Resources.IconBloxstrap; diff --git a/Bloxstrap/FastFlagManager.cs b/Bloxstrap/FastFlagManager.cs index 618ba323..271b4c6d 100644 --- a/Bloxstrap/FastFlagManager.cs +++ b/Bloxstrap/FastFlagManager.cs @@ -106,19 +106,21 @@ public class FastFlagManager : JsonManager> // to delete a flag, set the value as null public void SetValue(string key, object? value) { + const string LOG_IDENT = "FastFlagManager::SetValue"; + if (value is null) { if (Prop.ContainsKey(key)) - App.Logger.WriteLine($"[FastFlagManager::SetValue] Deletion of '{key}' is pending"); + App.Logger.WriteLine(LOG_IDENT, $"Deletion of '{key}' is pending"); Prop.Remove(key); } else { if (Prop.ContainsKey(key)) - App.Logger.WriteLine($"[FastFlagManager::SetValue] Setting of '{key}' from '{Prop[key]}' to '{value}' is pending"); + App.Logger.WriteLine(LOG_IDENT, $"Setting of '{key}' from '{Prop[key]}' to '{value}' is pending"); else - App.Logger.WriteLine($"[FastFlagManager::SetValue] Setting of '{key}' to '{value}' is pending"); + App.Logger.WriteLine(LOG_IDENT, $"Setting of '{key}' to '{value}' is pending"); Prop[key] = value.ToString()!; } diff --git a/Bloxstrap/HttpClientLoggingHandler.cs b/Bloxstrap/HttpClientLoggingHandler.cs index a39b94ad..07cdacdf 100644 --- a/Bloxstrap/HttpClientLoggingHandler.cs +++ b/Bloxstrap/HttpClientLoggingHandler.cs @@ -9,13 +9,13 @@ public HttpClientLoggingHandler(HttpMessageHandler innerHandler) protected override HttpRequestMessage ProcessRequest(HttpRequestMessage request, CancellationToken cancellationToken) { - App.Logger.WriteLine($"[HttpClientLoggingHandler::HttpRequestMessage] {request.Method} {request.RequestUri}"); + App.Logger.WriteLine("HttpClientLoggingHandler::HttpRequestMessage", $"{request.Method} {request.RequestUri}"); return request; } protected override HttpResponseMessage ProcessResponse(HttpResponseMessage response, CancellationToken cancellationToken) { - App.Logger.WriteLine($"[HttpClientLoggingHandler::HttpResponseMessage] {(int)response.StatusCode} {response.ReasonPhrase} {response.RequestMessage!.RequestUri}"); + App.Logger.WriteLine("HttpClientLoggingHandler::HttpResponseMessage", $"{(int)response.StatusCode} {response.ReasonPhrase} {response.RequestMessage!.RequestUri}"); return response; } } diff --git a/Bloxstrap/Integrations/DiscordRichPresence.cs b/Bloxstrap/Integrations/DiscordRichPresence.cs index 5e2a18ca..4c0bcb62 100644 --- a/Bloxstrap/Integrations/DiscordRichPresence.cs +++ b/Bloxstrap/Integrations/DiscordRichPresence.cs @@ -15,6 +15,8 @@ public class DiscordRichPresence : IDisposable public DiscordRichPresence(RobloxActivity activityWatcher) { + const string LOG_IDENT = "DiscordRichPresence::"; + _activityWatcher = activityWatcher; _activityWatcher.OnGameJoin += (_, _) => Task.Run(() => SetCurrentGame()); @@ -22,23 +24,23 @@ public DiscordRichPresence(RobloxActivity activityWatcher) _activityWatcher.OnGameMessage += (_, message) => OnGameMessage(message); _rpcClient.OnReady += (_, e) => - App.Logger.WriteLine($"[DiscordRichPresence::DiscordRichPresence] Received ready from user {e.User.Username} ({e.User.ID})"); + App.Logger.WriteLine(LOG_IDENT, $"Received ready from user {e.User.Username} ({e.User.ID})"); _rpcClient.OnPresenceUpdate += (_, e) => - App.Logger.WriteLine("[DiscordRichPresence::DiscordRichPresence] Presence updated"); + App.Logger.WriteLine(LOG_IDENT, "Presence updated"); _rpcClient.OnError += (_, e) => - App.Logger.WriteLine($"[DiscordRichPresence::DiscordRichPresence] An RPC error occurred - {e.Message}"); + App.Logger.WriteLine(LOG_IDENT, $"An RPC error occurred - {e.Message}"); _rpcClient.OnConnectionEstablished += (_, e) => - App.Logger.WriteLine("[DiscordRichPresence::DiscordRichPresence] Established connection with Discord RPC"); + App.Logger.WriteLine(LOG_IDENT, "Established connection with Discord RPC"); //spams log as it tries to connect every ~15 sec when discord is closed so not now //_rpcClient.OnConnectionFailed += (_, e) => - // App.Logger.WriteLine("[DiscordRichPresence::DiscordRichPresence] Failed to establish connection with Discord RPC"); + // App.Logger.WriteLine(LOG_IDENT, "Failed to establish connection with Discord RPC"); _rpcClient.OnClose += (_, e) => - App.Logger.WriteLine($"[DiscordRichPresence::DiscordRichPresence] Lost connection to Discord RPC - {e.Reason} ({e.Code})"); + App.Logger.WriteLine(LOG_IDENT, $"Lost connection to Discord RPC - {e.Reason} ({e.Code})"); _rpcClient.Initialize(); } @@ -51,17 +53,19 @@ public void OnGameMessage(GameMessage message) public void SetStatus(string status) { - App.Logger.WriteLine($"[DiscordRichPresence::SetStatus] Setting status to '{status}'"); + const string LOG_IDENT = "DiscordRichPresence::SetStatus"; + + App.Logger.WriteLine(LOG_IDENT, $"Setting status to '{status}'"); if (_currentPresence is null) { - App.Logger.WriteLine($"[DiscordRichPresence::SetStatus] Presence is not set, aborting"); + App.Logger.WriteLine(LOG_IDENT, $"Presence is not set, aborting"); return; } if (status.Length > 128) { - App.Logger.WriteLine($"[DiscordRichPresence::SetStatus] Status cannot be longer than 128 characters, aborting"); + App.Logger.WriteLine(LOG_IDENT, $"Status cannot be longer than 128 characters, aborting"); return; } @@ -72,7 +76,7 @@ public void SetStatus(string status) if (string.IsNullOrEmpty(status)) { - App.Logger.WriteLine($"[DiscordRichPresence::SetStatus] Status is empty, reverting to initial status"); + App.Logger.WriteLine(LOG_IDENT, $"Status is empty, reverting to initial status"); finalStatus = _initialStatus; } else @@ -82,7 +86,7 @@ public void SetStatus(string status) if (_currentPresence.State == finalStatus) { - App.Logger.WriteLine($"[DiscordRichPresence::SetStatus] Status is unchanged, aborting"); + App.Logger.WriteLine(LOG_IDENT, $"Status is unchanged, aborting"); return; } @@ -92,7 +96,7 @@ public void SetStatus(string status) public void SetVisibility(bool visible) { - App.Logger.WriteLine($"[DiscordRichPresence::SetVisibility] Setting presence visibility ({visible})"); + App.Logger.WriteLine("DiscordRichPresence::SetVisibility", $"Setting presence visibility ({visible})"); _visible = visible; @@ -104,9 +108,11 @@ public void SetVisibility(bool visible) public async Task SetCurrentGame() { + const string LOG_IDENT = "DiscordRichPresence::SetCurrentGame"; + if (!_activityWatcher.ActivityInGame) { - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Not in game, clearing presence"); + App.Logger.WriteLine(LOG_IDENT, "Not in game, clearing presence"); _currentPresence = null; _initialStatus = null; UpdatePresence(); @@ -116,17 +122,17 @@ public async Task SetCurrentGame() string icon = "roblox"; long placeId = _activityWatcher.ActivityPlaceId; - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Setting presence for Place ID {placeId}"); + App.Logger.WriteLine(LOG_IDENT, $"Setting presence for Place ID {placeId}"); var universeIdResponse = await Http.GetJson($"https://apis.roblox.com/universes/v1/places/{placeId}/universe"); if (universeIdResponse is null) { - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe ID!"); + App.Logger.WriteLine(LOG_IDENT, "Could not get Universe ID!"); return false; } long universeId = universeIdResponse.UniverseId; - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Got Universe ID as {universeId}"); + App.Logger.WriteLine(LOG_IDENT, $"Got Universe ID as {universeId}"); // preserve time spent playing if we're teleporting between places in the same universe if (_timeStartedUniverse is null || !_activityWatcher.ActivityIsTeleport || universeId != _currentUniverseId) @@ -137,22 +143,22 @@ public async Task SetCurrentGame() var gameDetailResponse = await Http.GetJson>($"https://games.roblox.com/v1/games?universeIds={universeId}"); if (gameDetailResponse is null || !gameDetailResponse.Data.Any()) { - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe info!"); + App.Logger.WriteLine(LOG_IDENT, "Could not get Universe info!"); return false; } GameDetailResponse universeDetails = gameDetailResponse.Data.ToArray()[0]; - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Got Universe details"); + App.Logger.WriteLine(LOG_IDENT, "Got Universe details"); var universeThumbnailResponse = await Http.GetJson>($"https://thumbnails.roblox.com/v1/games/icons?universeIds={universeId}&returnPolicy=PlaceHolder&size=512x512&format=Png&isCircular=false"); if (universeThumbnailResponse is null || !universeThumbnailResponse.Data.Any()) { - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Could not get Universe thumbnail info!"); + App.Logger.WriteLine(LOG_IDENT, "Could not get Universe thumbnail info!"); } else { icon = universeThumbnailResponse.Data.ToArray()[0].ImageUrl; - App.Logger.WriteLine($"[DiscordRichPresence::SetCurrentGame] Got Universe thumbnail as {icon}"); + App.Logger.WriteLine(LOG_IDENT, $"Got Universe thumbnail as {icon}"); } List