diff --git a/CHANGELIST.md b/CHANGELIST.md index 960548b4..2c8c13b4 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -49,6 +49,7 @@ - Remove more Windows from MainViewModel - Fix null reference exception in disc type - Detected type and selected type are different +- Remove message boxes from MainViewModel ### 2.6.6 (2023-10-04) diff --git a/MPF.UI.Core/ViewModels/MainViewModel.cs b/MPF.UI.Core/ViewModels/MainViewModel.cs index cd85bde4..bb408a0d 100644 --- a/MPF.UI.Core/ViewModels/MainViewModel.cs +++ b/MPF.UI.Core/ViewModels/MainViewModel.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Threading.Tasks; -using System.Windows; using BurnOutSharp; using MPF.Core; using MPF.Core.Converters; @@ -12,7 +11,6 @@ using MPF.Core.Data; using MPF.Core.Utilities; using MPF.Core.UI.ComboBoxItems; using SabreTools.RedumpLib.Data; -using WPFCustomMessageBox; namespace MPF.UI.Core.ViewModels { @@ -48,6 +46,18 @@ namespace MPF.UI.Core.ViewModels /// private Action _logger; + /// + /// Display a message to a user + /// + /// + /// T1 - Title to display to the user + /// T1 - Message to display to the user + /// T3 - Number of default options to display + /// T4 - true for inquiry, false otherwise + /// TResult - true for positive, false for negative, null for neutral + /// + private Func _displayUserMessage; + /// /// Detected media type, distinct from the selected one /// @@ -505,10 +515,14 @@ namespace MPF.UI.Core.ViewModels /// /// Initialize the main window after loading /// - public void Init(Action loggerAction, Func processUserInfo) + public void Init( + Action loggerAction, + Func displayUserMessage, + Func processUserInfo) { // Set the callbacks _logger = loggerAction; + _displayUserMessage = displayUserMessage; _processUserInfo = processUserInfo; // Finish initializing the rest of the values @@ -1530,17 +1544,17 @@ namespace MPF.UI.Core.ViewModels // If still in custom parameter mode, check that users meant to continue or not if (this.ParametersCheckBoxEnabled == true) { - MessageBoxResult result = CustomMessageBox.Show("It looks like you have custom parameters that have not been saved. Would you like to apply those changes before starting to dump?", "Custom Changes", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); - if (result == MessageBoxResult.Yes) + bool? result = _displayUserMessage("Custom Changes", "It looks like you have custom parameters that have not been saved. Would you like to apply those changes before starting to dump?", 3, true); + if (result == true) { this.ParametersCheckBoxEnabled = false; ProcessCustomParameters(); } - else if (result == MessageBoxResult.Cancel) + else if (result == null) { return; } - // If "No", then we continue with the current known environment + // If false, then we continue with the current known environment } // Run path adjustments for DiscImageCreator -- Disabled until further notice @@ -1652,7 +1666,7 @@ namespace MPF.UI.Core.ViewModels // Validate that we have an output path of any sort if (string.IsNullOrWhiteSpace(_environment.OutputPath)) { - _ = CustomMessageBox.Show("No output path was provided so dumping cannot continue.", "Missing Path", MessageBoxButton.OK, MessageBoxImage.Exclamation); + _ = _displayUserMessage("Missing Path", "No output path was provided so dumping cannot continue.", 1, false); LogLn("Dumping aborted!"); return false; } @@ -1664,8 +1678,8 @@ namespace MPF.UI.Core.ViewModels + (!_environment.System.DetectedByWindows() ? $"This is normal for {_environment.System.LongName()} as the discs may not be readable on Windows. " : string.Empty) + "Do you want to continue?"; - MessageBoxResult mbresult = CustomMessageBox.Show(message, "No Disc Detected", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); - if (mbresult == MessageBoxResult.No || mbresult == MessageBoxResult.Cancel || mbresult == MessageBoxResult.None) + bool? mbresult = _displayUserMessage("No Disc Detected", message, 2, false); + if (mbresult != true) { LogLn("Dumping aborted!"); return false; @@ -1680,8 +1694,8 @@ namespace MPF.UI.Core.ViewModels (bool foundFiles, List _) = InfoTool.FoundAllFiles(outputDirectory, outputFilename, _environment.Parameters, true); if (foundFiles) { - MessageBoxResult mbresult = CustomMessageBox.Show("A complete dump already exists! Are you sure you want to overwrite?", "Overwrite?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); - if (mbresult == MessageBoxResult.No || mbresult == MessageBoxResult.Cancel || mbresult == MessageBoxResult.None) + bool? mbresult = _displayUserMessage("Overwrite?", "A complete dump already exists! Are you sure you want to overwrite?", 2, true); + if (mbresult != true) { LogLn("Dumping aborted!"); return false; @@ -1694,8 +1708,8 @@ namespace MPF.UI.Core.ViewModels var driveInfo = new DriveInfo(Path.GetPathRoot(fullPath)); if (driveInfo.AvailableFreeSpace < Math.Pow(2, 30)) { - MessageBoxResult mbresult = CustomMessageBox.Show("There is less than 1gb of space left on the target drive. Are you sure you want to continue?", "Low Space", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); - if (mbresult == MessageBoxResult.No || mbresult == MessageBoxResult.Cancel || mbresult == MessageBoxResult.None) + bool? mbresult = _displayUserMessage("Low Space", "There is less than 1gb of space left on the target drive. Are you sure you want to continue?", 2, true); + if (mbresult != true) { LogLn("Dumping aborted!"); return false; diff --git a/MPF.UI.Core/Windows/MainWindow.xaml.cs b/MPF.UI.Core/Windows/MainWindow.xaml.cs index 19773513..e8026178 100644 --- a/MPF.UI.Core/Windows/MainWindow.xaml.cs +++ b/MPF.UI.Core/Windows/MainWindow.xaml.cs @@ -42,7 +42,7 @@ namespace MPF.UI.Core.Windows if (MainViewModel.Options.ShowDebugViewMenuItem) DebugViewMenuItem.Visibility = Visibility.Visible; - MainViewModel.Init(LogOutput.EnqueueLog, ShowDiscInformationWindow); + MainViewModel.Init(LogOutput.EnqueueLog, DisplayUserMessage, ShowDiscInformationWindow); // Check for updates, if necessary if (MainViewModel.Options.CheckForUpdatesOnStartup) @@ -132,6 +132,57 @@ namespace MPF.UI.Core.Windows CustomMessageBox.Show(message, "Version Update Check", MessageBoxButton.OK, different ? MessageBoxImage.Exclamation : MessageBoxImage.Information); } + /// + /// Display a user message using a CustomMessageBox + /// + /// Title to display to the user + /// Message to display to the user + /// Number of options to display + /// true for inquiry, false otherwise + /// true for positive, false for negative, null for neutral + public bool? DisplayUserMessage(string title, string message, int optionCount, bool flag) + { + // Set the correct button style + MessageBoxButton button; + switch (optionCount) + { + case 1: + button = MessageBoxButton.OK; + break; + case 2: + button = MessageBoxButton.YesNo; + break; + case 3: + button = MessageBoxButton.YesNoCancel; + break; + + // This should not happen, but default to "OK" + default: + button = MessageBoxButton.OK; + break; + } + + // Set the correct icon + MessageBoxImage image = flag ? MessageBoxImage.Question : MessageBoxImage.Exclamation; + + // Display and get the result + MessageBoxResult result = CustomMessageBox.Show(this, message, title, button, image); + switch (result) + { + case MessageBoxResult.OK: + case MessageBoxResult.Yes: + return true; + + case MessageBoxResult.No: + return false; + + case MessageBoxResult.Cancel: + case MessageBoxResult.None: + default: + return null; + } + } + /// /// Build a dummy SubmissionInfo and display it for testing ///