From 2a7d894319ea640dabac07ef88238b0adf9be084 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Tue, 2 Jul 2024 23:27:40 +0400 Subject: [PATCH] Custom integration improvements ShellExecute, working directory setting, file picker, easier command line flag input --- Bloxstrap/Bootstrapper.cs | 14 ++++++++---- .../Elements/Menu/Pages/IntegrationsPage.xaml | 11 ++++++++-- .../ViewModels/Menu/IntegrationsViewModel.cs | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index e4bcc01..078a545 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -336,7 +336,7 @@ namespace Bloxstrap gameClientPid = gameClient.Id; } - List autocloseProcesses = new(); + List autocloseProcesses = new(); ActivityWatcher? activityWatcher = null; DiscordRichPresence? richPresence = null; @@ -379,7 +379,13 @@ namespace Bloxstrap try { - Process process = Process.Start(integration.Location, integration.LaunchArgs); + var process = Process.Start(new ProcessStartInfo + { + FileName = integration.Location, + Arguments = integration.LaunchArgs.Replace("\r\n", " "), + WorkingDirectory = Path.GetDirectoryName(integration.Location), + UseShellExecute = true + }); if (integration.AutoClose) { @@ -413,9 +419,9 @@ namespace Bloxstrap richPresence?.Dispose(); - foreach (Process process in autocloseProcesses) + foreach (var process in autocloseProcesses) { - if (process.HasExited) + if (process is null || process.HasExited) continue; App.Logger.WriteLine(LOG_IDENT, $"Autoclosing process '{process.ProcessName}' (PID {process.Id})"); diff --git a/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml b/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml index 51c9cb5..4b255dc 100644 --- a/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml +++ b/Bloxstrap/UI/Elements/Menu/Pages/IntegrationsPage.xaml @@ -90,9 +90,16 @@ - + + + + + + + + - + diff --git a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs index 73cbdd1..f08306b 100644 --- a/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs +++ b/Bloxstrap/UI/ViewModels/Menu/IntegrationsViewModel.cs @@ -1,6 +1,10 @@ using System.Collections.ObjectModel; using System.Windows.Input; +using Bloxstrap.Resources; + +using Microsoft.Win32; + using CommunityToolkit.Mvvm.Input; namespace Bloxstrap.UI.ViewModels.Menu @@ -9,6 +13,7 @@ namespace Bloxstrap.UI.ViewModels.Menu { public ICommand AddIntegrationCommand => new RelayCommand(AddIntegration); public ICommand DeleteIntegrationCommand => new RelayCommand(DeleteIntegration); + public ICommand BrowseIntegrationLocationCommand => new RelayCommand(BrowseIntegrationLocation); private void AddIntegration() { @@ -39,6 +44,23 @@ namespace Bloxstrap.UI.ViewModels.Menu OnPropertyChanged(nameof(IsCustomIntegrationSelected)); } + private void BrowseIntegrationLocation() + { + if (SelectedCustomIntegration is null) + return; + + var dialog = new OpenFileDialog + { + Filter = $"{Strings.Menu_AllFiles}|*.*" + }; + + if (dialog.ShowDialog() != true) + return; + + SelectedCustomIntegration.Location = dialog.FileName; + OnPropertyChanged(nameof(SelectedCustomIntegration)); + } + public bool ActivityTrackingEnabled { get => App.Settings.Prop.EnableActivityTracking;