From 703d51f10b8e6e5544e27b16b579534f9e0e337d Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 20 Apr 2020 14:20:28 +0100 Subject: [PATCH] Checking for errors when doing the UAC check and when opening the config folder. Some small color changes. --- BannerLord.Common/IModManager.cs | 1 + BannerLord.Common/ModManager.cs | 34 ++++++++++---- BannerLordLauncher/BannerLordLauncher.csproj | 3 -- BannerLordLauncher/Dictionary.xaml | 35 ++++++++------- .../ViewModels/MainWindowViewModel.cs | 45 ++++++++++++------- BannerLordLauncher/Views/MainWindow.xaml | 7 ++- BannerLordLauncher/package.bat | 7 +++ 7 files changed, 85 insertions(+), 47 deletions(-) create mode 100644 BannerLordLauncher/package.bat diff --git a/BannerLord.Common/IModManager.cs b/BannerLord.Common/IModManager.cs index 2eb39e1..78c5b7d 100644 --- a/BannerLord.Common/IModManager.cs +++ b/BannerLord.Common/IModManager.cs @@ -6,6 +6,7 @@ public interface IModManager : IEnableLogger { bool Initialize(string configPath, string gamePath, out string errorMessage); + bool OpenConfig(out string errorMessage); bool Save(out string errorMessage); bool Run(out string errorMessage); diff --git a/BannerLord.Common/ModManager.cs b/BannerLord.Common/ModManager.cs index 3e7ad9a..93eba4b 100644 --- a/BannerLord.Common/ModManager.cs +++ b/BannerLord.Common/ModManager.cs @@ -220,17 +220,33 @@ public bool Run(out string errorMessage) return true; } - public void OpenConfig() + public bool OpenConfig(out string errorMessage) { - if (string.IsNullOrEmpty(this._basePath) || !Directory.Exists(this._basePath)) return; - var info = new ProcessStartInfo + errorMessage = default; + try { - Arguments = this._basePath, - FileName = "explorer.exe", - WorkingDirectory = this._basePath, - UseShellExecute = false - }; - Process.Start(info); + if (string.IsNullOrEmpty(this._basePath) || !Directory.Exists(this._basePath)) + { + errorMessage = $"{this._basePath} is invalid"; + return false; + } + var info = new ProcessStartInfo + { + Arguments = this._basePath, + FileName = "explorer.exe", + WorkingDirectory = this._basePath, + UseShellExecute = false + }; + Process.Start(info); + } + catch (Exception e) + { + this.Log().Error(e); + errorMessage = e.Message; + return false; + } + + return true; } public bool Save(out string errorMessage) diff --git a/BannerLordLauncher/BannerLordLauncher.csproj b/BannerLordLauncher/BannerLordLauncher.csproj index be8e5b4..feacde0 100644 --- a/BannerLordLauncher/BannerLordLauncher.csproj +++ b/BannerLordLauncher/BannerLordLauncher.csproj @@ -7,11 +7,8 @@ BLLicon.ico win-x64 BannerLordLauncher - 0.1.14.0 - 0.1.14.0 https://www.nexusmods.com/mountandblade2bannerlord/mods/265 https://github.com/tstavrianos/BannerLordLauncher - 0.1.14 BannerLordLauncher.Program diff --git a/BannerLordLauncher/Dictionary.xaml b/BannerLordLauncher/Dictionary.xaml index 69caeee..e6e481d 100644 --- a/BannerLordLauncher/Dictionary.xaml +++ b/BannerLordLauncher/Dictionary.xaml @@ -16,11 +16,16 @@ - - - + + + + + + + + @@ -82,10 +87,10 @@ - + - + @@ -103,7 +108,7 @@ - + - + @@ -137,7 +142,7 @@ - + - + diff --git a/BannerLordLauncher/ViewModels/MainWindowViewModel.cs b/BannerLordLauncher/ViewModels/MainWindowViewModel.cs index f96cdbf..2c1c238 100644 --- a/BannerLordLauncher/ViewModels/MainWindowViewModel.cs +++ b/BannerLordLauncher/ViewModels/MainWindowViewModel.cs @@ -72,7 +72,7 @@ public MainWindowViewModel(MainWindow window) this.UncheckAll = ReactiveCommand.Create(this.UncheckAllCmd); this.InvertCheck = ReactiveCommand.Create(this.InvertCheckCmd); this.Run = ReactiveCommand.Create(this.RunCmd); - this.Config = ReactiveCommand.Create(() => this.Manager.OpenConfig()); + this.Config = ReactiveCommand.Create(this.OpenConfigCmd); } private void SafeMessage(string message) @@ -321,6 +321,13 @@ private void SaveCmd() if (this.Manager.Save(out var error)) return; if (!string.IsNullOrEmpty(error)) this.SafeMessage(error); } + + private void OpenConfigCmd() + { + + if (this.Manager.OpenConfig(out var error)) return; + if (!string.IsNullOrEmpty(error)) this.SafeMessage(error); + } public void DragOver(IDropInfo dropInfo) { @@ -390,14 +397,22 @@ public bool CanRun() return false; } - if (UACChecker.RequiresElevation(this.Manager.GameExe)) + try { - if (!UacUtil.IsElevated) + if (UACChecker.RequiresElevation(this.Manager.GameExe)) { - this.SafeMessage("The application must be run as admin, to allow launching the game"); - return false; + if (!UacUtil.IsElevated) + { + this.SafeMessage("The application must be run as admin, to allow launching the game"); + return false; + } } } + catch (Exception e) + { + this.Log().Error(e); + SafeMessage(e.Message); + } return true; } @@ -405,20 +420,18 @@ public bool CanRun() public bool CanSave() { this._ignoredWarning = false; - if (this.Manager.Mods.Any(x => x.HasConflicts)) + if (!this.Manager.Mods.Any(x => x.HasConflicts)) return true; + if (MessageBox.Show( + this._window, + "Your mod list has existing conflicts, are you sure that you want to save it?", + "Warning", + MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { - if (MessageBox.Show( - this._window, - "Your mod list has existing conflicts, are you sure that you want to save it?", - "Warning", - MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) - { - return false; - } - - this._ignoredWarning = true; + return false; } + this._ignoredWarning = true; + return true; } diff --git a/BannerLordLauncher/Views/MainWindow.xaml b/BannerLordLauncher/Views/MainWindow.xaml index e696538..7269e53 100644 --- a/BannerLordLauncher/Views/MainWindow.xaml +++ b/BannerLordLauncher/Views/MainWindow.xaml @@ -14,7 +14,7 @@ - + @@ -106,7 +106,7 @@ RelativeSource={RelativeSource AncestorType={x:Type Button}}}" StrokeThickness="1" /> - +