Files
MPF/MPF.UI/Windows/MainWindow.xaml.cs

660 lines
24 KiB
C#
Raw Permalink Normal View History

2018-06-14 20:40:41 -04:00
using System;
2023-10-08 23:46:24 -04:00
using System.IO;
2023-10-08 20:52:29 -04:00
using System.Windows;
using System.Windows.Controls;
2024-05-23 15:40:12 -04:00
using MPF.Frontend.ViewModels;
using MPF.UI.Themes;
2024-05-23 21:35:02 -04:00
using MPF.UI.UserControls;
2023-11-16 12:45:47 -05:00
using SabreTools.RedumpLib;
2023-10-08 23:15:24 -04:00
using SabreTools.RedumpLib.Data;
using WPFCustomMessageBox;
2023-10-08 23:46:24 -04:00
using WinForms = System.Windows.Forms;
2023-12-01 23:58:01 -05:00
#pragma warning disable IDE1006 // Naming Styles
2024-05-23 21:35:02 -04:00
namespace MPF.UI.Windows
2018-05-12 19:48:18 -04:00
{
public partial class MainWindow : WindowBase
2018-05-12 19:48:18 -04:00
{
/// <summary>
/// Read-only access to the current main view model
/// </summary>
2023-10-11 11:49:56 -04:00
public MainViewModel MainViewModel => DataContext as MainViewModel ?? new MainViewModel();
2023-11-30 23:34:44 -05:00
#if NET35
#region Top Menu Bar
private MenuItem? _AboutMenuItem => ItemHelper.FindChild<MenuItem>(this, "AboutMenuItem");
private MenuItem? _AppExitMenuItem => ItemHelper.FindChild<MenuItem>(this, "AppExitMenuItem");
private MenuItem? _CheckForUpdatesMenuItem => ItemHelper.FindChild<MenuItem>(this, "CheckForUpdatesMenuItem");
private MenuItem? _DebugViewMenuItem => ItemHelper.FindChild<MenuItem>(this, "DebugViewMenuItem");
private MenuItem? _CheckDumpMenuItem => ItemHelper.FindChild<MenuItem>(this, "CheckDumpMenuItem");
private MenuItem? _CreateIRDMenuItem => ItemHelper.FindChild<MenuItem>(this, "CreateIRDMenuItem");
2023-11-30 23:34:44 -05:00
private MenuItem? _OptionsMenuItem => ItemHelper.FindChild<MenuItem>(this, "OptionsMenuItem");
#endregion
#region Settings
private ComboBox? _DriveLetterComboBox => ItemHelper.FindChild<ComboBox>(this, "DriveLetterComboBox");
private ComboBox? _DriveSpeedComboBox => ItemHelper.FindChild<ComboBox>(this, "DriveSpeedComboBox");
private ComboBox? _DumpingProgramComboBox => ItemHelper.FindChild<ComboBox>(this, "DumpingProgramComboBox");
private CheckBox? _EnableParametersCheckBox => ItemHelper.FindChild<CheckBox>(this, "EnableParametersCheckBox");
private ComboBox? _MediaTypeComboBox => ItemHelper.FindChild<ComboBox>(this, "MediaTypeComboBox");
private Button? _OutputPathBrowseButton => ItemHelper.FindChild<Button>(this, "OutputPathBrowseButton");
private TextBox? _OutputPathTextBox => ItemHelper.FindChild<TextBox>(this, "OutputPathTextBox");
private ComboBox? _SystemTypeComboBox => ItemHelper.FindChild<ComboBox>(this, "SystemTypeComboBox");
#endregion
#region Controls
private Button? _CopyProtectScanButton => ItemHelper.FindChild<Button>(this, "CopyProtectScanButton");
private Button? _MediaScanButton => ItemHelper.FindChild<Button>(this, "MediaScanButton");
private Button? _StartStopButton => ItemHelper.FindChild<Button>(this, "StartStopButton");
private Button? _UpdateVolumeLabel => ItemHelper.FindChild<Button>(this, "UpdateVolumeLabel");
#endregion
#region Status
private LogOutput? _LogOutput => ItemHelper.FindChild<LogOutput>(this, "LogOutput");
#endregion
#endif
/// <summary>
/// Constructor
/// </summary>
2023-11-15 12:10:54 -05:00
public MainWindow()
{
2023-11-30 23:34:44 -05:00
#if NET40_OR_GREATER || NETCOREAPP
InitializeComponent();
2023-11-30 23:34:44 -05:00
#endif
#if NET452_OR_GREATER || NETCOREAPP
2023-11-15 12:10:54 -05:00
var chrome = new System.Windows.Shell.WindowChrome
{
CaptionHeight = 0,
ResizeBorderThickness = new Thickness(0),
};
System.Windows.Shell.WindowChrome.SetWindowChrome(this, chrome);
#endif
}
2020-09-10 23:21:18 -07:00
/// <summary>
/// Handler for MainWindow OnContentRendered event
/// </summary>
protected override void OnContentRendered(EventArgs e)
{
base.OnContentRendered(e);
2023-10-08 20:52:29 -04:00
// Disable buttons until we load fully
2023-10-08 22:49:46 -04:00
MainViewModel.StartStopButtonEnabled = false;
MainViewModel.MediaScanButtonEnabled = false;
MainViewModel.UpdateVolumeLabelEnabled = false;
MainViewModel.CopyProtectScanButtonEnabled = false;
2023-10-08 20:52:29 -04:00
// Add the click handlers to the UI
AddEventHandlers();
// Display the debug option in the menu, if necessary
if (MainViewModel.Options.ShowDebugViewMenuItem)
2023-11-30 23:34:44 -05:00
#if NET35
_DebugViewMenuItem!.Visibility = Visibility.Visible;
#else
2023-10-08 20:52:29 -04:00
DebugViewMenuItem.Visibility = Visibility.Visible;
2023-11-30 23:34:44 -05:00
#endif
2023-10-08 20:52:29 -04:00
2023-11-30 23:34:44 -05:00
#if NET35
MainViewModel.Init(_LogOutput!.EnqueueLog, DisplayUserMessage, ShowDiscInformationWindow);
#else
MainViewModel.Init(LogOutput.EnqueueLog, DisplayUserMessage, ShowDiscInformationWindow);
2023-11-30 23:34:44 -05:00
#endif
2023-10-09 11:35:49 -04:00
// Set the UI color scheme according to the options
2023-10-18 10:21:40 -04:00
ApplyTheme();
2023-10-09 11:35:49 -04:00
// Check for updates, if necessary
if (MainViewModel.Options.CheckForUpdatesOnStartup)
CheckForUpdates(showIfSame: false);
2023-10-18 01:59:55 -04:00
// Handle first-run, if necessary
if (MainViewModel.Options.FirstRun)
{
// Show the options window
ShowOptionsWindow("Welcome to MPF, Explore the Options");
2023-10-18 01:59:55 -04:00
}
More and more cleanup (#86) * Namespace cleanups * Make dump validation instanced * Add note to Tasks * Move stuff to DumpEnvironment Most of the stuff in Tasks.cs acted on a single input parameter, namely a DumpEnvironment. Since that's the case, it was more logical to wrap those into DumpEnvironment and make them instance methods rather than keep them static. Due to this change, quite a few methods changed access, and some had to be marked internal due to wanting them to be tested separately. * Gut Tasks * One less thing in MainWindow * Remove explicit cast * Wrong check * Create helper method * Disable scan button on dump * Remove unnecessary getters/setters * Method name/description cleanup * Address TODO * Namespace cleanups * Make dump validation instanced * Add note to Tasks * Move stuff to DumpEnvironment Most of the stuff in Tasks.cs acted on a single input parameter, namely a DumpEnvironment. Since that's the case, it was more logical to wrap those into DumpEnvironment and make them instance methods rather than keep them static. Due to this change, quite a few methods changed access, and some had to be marked internal due to wanting them to be tested separately. * Gut Tasks * One less thing in MainWindow * Remove explicit cast * Wrong check * Create helper method * Disable scan button on dump * Remove unnecessary getters/setters * Method name/description cleanup * Address TODO * Clean up OnContentRendered * Namespace cleanups * Make dump validation instanced * Add note to Tasks * Move stuff to DumpEnvironment Most of the stuff in Tasks.cs acted on a single input parameter, namely a DumpEnvironment. Since that's the case, it was more logical to wrap those into DumpEnvironment and make them instance methods rather than keep them static. Due to this change, quite a few methods changed access, and some had to be marked internal due to wanting them to be tested separately. * Gut Tasks * One less thing in MainWindow * Remove explicit cast * Wrong check * Create helper method * Disable scan button on dump * Remove unnecessary getters/setters * Method name/description cleanup * Address TODO * Clean up OnContentRendered * Update event handlers
2018-07-05 21:34:04 -07:00
}
2023-10-08 20:52:29 -04:00
#region UI Functionality
/// <summary>
/// Add all event handlers
/// </summary>
public void AddEventHandlers()
{
// Menu Bar Click
2023-11-30 23:34:44 -05:00
#if NET35
_AboutMenuItem!.Click += AboutClick;
_AppExitMenuItem!.Click += AppExitClick;
_CheckForUpdatesMenuItem!.Click += CheckForUpdatesClick;
_DebugViewMenuItem!.Click += DebugViewClick;
_CheckDumpMenuItem!.Click += CheckDumpMenuItemClick;
_CreateIRDMenuItem!.Click += CreateIRDMenuItemClick;
2023-11-30 23:34:44 -05:00
_OptionsMenuItem!.Click += OptionsMenuItemClick;
#else
2023-10-08 20:52:29 -04:00
AboutMenuItem.Click += AboutClick;
AppExitMenuItem.Click += AppExitClick;
CheckForUpdatesMenuItem.Click += CheckForUpdatesClick;
DebugViewMenuItem.Click += DebugViewClick;
CheckDumpMenuItem.Click += CheckDumpMenuItemClick;
CreateIRDMenuItem.Click += CreateIRDMenuItemClick;
2023-10-08 20:52:29 -04:00
OptionsMenuItem.Click += OptionsMenuItemClick;
2023-11-30 23:34:44 -05:00
#endif
2023-10-08 20:52:29 -04:00
// User Area Click
2023-11-30 23:34:44 -05:00
#if NET35
_CopyProtectScanButton!.Click += CopyProtectScanButtonClick;
_EnableParametersCheckBox!.Click += EnableParametersCheckBoxClick;
_MediaScanButton!.Click += MediaScanButtonClick;
_UpdateVolumeLabel!.Click += UpdateVolumeLabelClick;
_OutputPathBrowseButton!.Click += OutputPathBrowseButtonClick;
_StartStopButton!.Click += StartStopButtonClick;
#else
2023-10-08 20:52:29 -04:00
CopyProtectScanButton.Click += CopyProtectScanButtonClick;
EnableParametersCheckBox.Click += EnableParametersCheckBoxClick;
MediaScanButton.Click += MediaScanButtonClick;
UpdateVolumeLabel.Click += UpdateVolumeLabelClick;
OutputPathBrowseButton.Click += OutputPathBrowseButtonClick;
StartStopButton.Click += StartStopButtonClick;
2023-11-30 23:34:44 -05:00
#endif
2023-10-08 20:52:29 -04:00
// User Area SelectionChanged
2023-11-30 23:34:44 -05:00
#if NET35
_SystemTypeComboBox!.SelectionChanged += SystemTypeComboBoxSelectionChanged;
_MediaTypeComboBox!.SelectionChanged += MediaTypeComboBoxSelectionChanged;
_DriveLetterComboBox!.SelectionChanged += DriveLetterComboBoxSelectionChanged;
_DriveSpeedComboBox!.SelectionChanged += DriveSpeedComboBoxSelectionChanged;
_DumpingProgramComboBox!.SelectionChanged += DumpingProgramComboBoxSelectionChanged;
#else
2023-10-08 20:52:29 -04:00
SystemTypeComboBox.SelectionChanged += SystemTypeComboBoxSelectionChanged;
MediaTypeComboBox.SelectionChanged += MediaTypeComboBoxSelectionChanged;
DriveLetterComboBox.SelectionChanged += DriveLetterComboBoxSelectionChanged;
DriveSpeedComboBox.SelectionChanged += DriveSpeedComboBoxSelectionChanged;
DumpingProgramComboBox.SelectionChanged += DumpingProgramComboBoxSelectionChanged;
2023-11-30 23:34:44 -05:00
#endif
2023-10-08 20:52:29 -04:00
// User Area TextChanged
2023-11-30 23:34:44 -05:00
#if NET35
_OutputPathTextBox!.TextChanged += OutputPathTextBoxTextChanged;
#else
2023-10-08 20:52:29 -04:00
OutputPathTextBox.TextChanged += OutputPathTextBoxTextChanged;
2023-11-30 23:34:44 -05:00
#endif
2023-10-08 20:52:29 -04:00
}
2023-10-08 23:46:24 -04:00
/// <summary>
/// Browse for an output file path
/// </summary>
public void BrowseFile()
{
// Get the current path, if possible
string currentPath = MainViewModel.OutputPath;
if (string.IsNullOrEmpty(currentPath) && !string.IsNullOrEmpty(MainViewModel.Options.DefaultOutputPath))
2023-10-08 23:46:24 -04:00
currentPath = Path.Combine(MainViewModel.Options.DefaultOutputPath, "track.bin");
else if (string.IsNullOrEmpty(currentPath))
2023-10-11 11:49:56 -04:00
currentPath = "track.bin";
if (string.IsNullOrEmpty(currentPath))
2023-11-14 23:14:33 -05:00
currentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory!, "track.bin");
2023-10-08 23:46:24 -04:00
// Get the full path
currentPath = Path.GetFullPath(currentPath);
// Get the directory
2023-10-11 11:49:56 -04:00
var directory = Path.GetDirectoryName(currentPath);
2023-10-08 23:46:24 -04:00
// Get the filename
string filename = Path.GetFileName(currentPath);
WinForms.FileDialog fileDialog = new WinForms.SaveFileDialog
{
FileName = filename,
InitialDirectory = directory,
};
WinForms.DialogResult result = fileDialog.ShowDialog();
if (result == WinForms.DialogResult.OK)
{
MainViewModel.OutputPath = fileDialog.FileName;
}
}
/// <summary>
/// Check for available updates
/// </summary>
/// <param name="showIfSame">True to show the box even if it's the same, false to only show if it's different</param>
public void CheckForUpdates(bool showIfSame)
{
2023-10-11 11:49:56 -04:00
(bool different, string message, var url) = MainViewModel.CheckForUpdates();
// If we have a new version, put it in the clipboard
if (different && !string.IsNullOrEmpty(url))
Clipboard.SetText(url);
if (showIfSame || different)
CustomMessageBox.Show(this, message, "Version Update Check", MessageBoxButton.OK, different ? MessageBoxImage.Exclamation : MessageBoxImage.Information);
}
/// <summary>
/// Display a user message using a CustomMessageBox
/// </summary>
/// <param name="title">Title to display to the user</param>
/// <param name="message">Message to display to the user</param>
/// <param name="optionCount">Number of options to display</param>
/// <param name="flag">true for inquiry, false otherwise</param>
/// <returns>true for positive, false for negative, null for neutral</returns>
public bool? DisplayUserMessage(string title, string message, int optionCount, bool flag)
{
// Set the correct button style
2023-11-06 23:06:11 -05:00
var button = optionCount switch
{
2023-11-06 23:06:11 -05:00
1 => MessageBoxButton.OK,
2 => MessageBoxButton.YesNo,
3 => MessageBoxButton.YesNoCancel,
// This should not happen, but default to "OK"
2023-11-06 23:06:11 -05:00
_ => MessageBoxButton.OK,
};
// 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);
2023-11-06 23:06:11 -05:00
return result switch
{
2023-11-06 23:06:11 -05:00
MessageBoxResult.OK or MessageBoxResult.Yes => true,
MessageBoxResult.No => false,
_ => null,
};
}
2023-10-08 23:06:17 -04:00
/// <summary>
/// Build a dummy SubmissionInfo and display it for testing
/// </summary>
public void ShowDebugDiscInfoWindow()
{
var submissionInfo = MainViewModel.CreateDebugSubmissionInfo();
2023-10-08 23:15:24 -04:00
var result = ShowDiscInformationWindow(submissionInfo);
2023-11-16 12:45:47 -05:00
Formatter.ProcessSpecialFields(result.Item2);
2023-10-08 23:06:17 -04:00
}
2023-10-08 23:15:24 -04:00
/// <summary>
/// Show the disc information window
/// </summary>
/// <param name="submissionInfo">SubmissionInfo object to display and possibly change</param>
/// <returns>Dialog open result</returns>
2023-10-11 11:49:56 -04:00
public (bool?, SubmissionInfo?) ShowDiscInformationWindow(SubmissionInfo? submissionInfo)
2023-10-08 23:15:24 -04:00
{
if (MainViewModel.Options.ShowDiscEjectReminder)
CustomMessageBox.Show(this, "It is now safe to eject the disc", "Eject", MessageBoxButton.OK, MessageBoxImage.Information);
2023-10-08 23:15:24 -04:00
var discInformationWindow = new DiscInformationWindow(MainViewModel.Options, submissionInfo)
{
Focusable = true,
Owner = this,
ShowActivated = true,
ShowInTaskbar = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
discInformationWindow.Closed += delegate { this.Activate(); };
2023-10-08 23:15:24 -04:00
bool? result = discInformationWindow.ShowDialog();
// Copy back the submission info changes, if necessary
if (result == true)
2023-10-11 11:49:56 -04:00
submissionInfo = (discInformationWindow.DiscInformationViewModel.SubmissionInfo.Clone() as SubmissionInfo)!;
2023-10-08 23:15:24 -04:00
2023-10-11 11:49:56 -04:00
return (result, submissionInfo!);
2023-10-08 23:15:24 -04:00
}
/// <summary>
/// Show the Check Dump window
/// </summary>
public void ShowCheckDumpWindow()
{
// Hide MainWindow while Check GUI is open
this.Hide();
var checkDumpWindow = new CheckDumpWindow(this)
{
Focusable = true,
Owner = this,
ShowActivated = true,
ShowInTaskbar = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
checkDumpWindow.Closed += delegate {
// Unhide Main window after Check window has been closed
this.Show();
this.Activate();
};
checkDumpWindow.Show();
}
/// <summary>
/// Show the Create IRD window
/// </summary>
public void ShowCreateIRDWindow()
{
// Hide MainWindow while Create IRD UI is open
this.Hide();
var createIRDWindow = new CreateIRDWindow(this)
{
Focusable = true,
Owner = this,
ShowActivated = true,
ShowInTaskbar = true,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
createIRDWindow.Closed += delegate {
// Unhide Main window after Create IRD window has been closed
this.Show();
this.Activate();
};
createIRDWindow.Show();
}
2023-10-08 20:52:29 -04:00
/// <summary>
2023-10-08 22:49:46 -04:00
/// Show the Options window
2023-10-08 20:52:29 -04:00
/// </summary>
public void ShowOptionsWindow(string? title = null)
2023-10-08 20:52:29 -04:00
{
2023-10-08 22:49:46 -04:00
var optionsWindow = new OptionsWindow(MainViewModel.Options)
2023-10-08 20:52:29 -04:00
{
2023-10-08 22:49:46 -04:00
Focusable = true,
Owner = this,
ShowActivated = true,
ShowInTaskbar = true,
Title = title ?? "Options",
2023-10-08 22:49:46 -04:00
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
optionsWindow.Closed += delegate { this.Activate(); };
optionsWindow.Closed += OnOptionsUpdated;
2023-10-08 22:49:46 -04:00
optionsWindow.Show();
2023-10-08 20:52:29 -04:00
}
2023-10-18 10:21:40 -04:00
/// <summary>
/// Set the UI color scheme according to the options
/// </summary>
private void ApplyTheme()
{
2023-10-18 10:31:58 -04:00
Theme theme;
2023-10-18 10:21:40 -04:00
if (MainViewModel.Options.EnableDarkMode)
2023-10-18 10:31:58 -04:00
theme = new DarkModeTheme();
2024-06-24 10:46:15 +09:00
else if (MainViewModel.Options.EnablePurpMode)
theme = new CustomTheme("111111", "9A5EC0");
else if (IsHexColor(MainViewModel.Options.CustomBackgroundColor) && IsHexColor(MainViewModel.Options.CustomTextColor))
theme = new CustomTheme(MainViewModel.Options.CustomBackgroundColor, MainViewModel.Options.CustomTextColor);
2023-10-18 10:21:40 -04:00
else
2023-10-18 10:31:58 -04:00
theme = new LightModeTheme();
2023-10-09 11:35:49 -04:00
theme.Apply();
}
/// <summary>
/// Check whether a string represents a valid hex color
/// </summary>
public static bool IsHexColor(string? color)
{
if (string.IsNullOrWhiteSpace(color))
return false;
if (color!.Length == 7 && color[0] == '#')
color = color.Substring(1);
if (color.Length != 6)
return false;
for (int i = 0; i < color.Length; i++)
{
switch (color[i])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
continue;
default:
break;
}
}
return true;
}
#endregion
2023-10-08 20:52:29 -04:00
#region Event Handlers
/// <summary>
/// Handler for OptionsWindow OnUpdated event
/// </summary>
2023-10-11 11:49:56 -04:00
public void OnOptionsUpdated(object? sender, EventArgs e)
{
// Get the options window
var optionsWindow = (sender as OptionsWindow);
if (optionsWindow?.OptionsViewModel == null)
return;
bool savedSettings = optionsWindow.OptionsViewModel.SavedSettings;
var options = optionsWindow.OptionsViewModel.Options;
MainViewModel.UpdateOptions(savedSettings, options);
2023-10-18 03:28:41 -04:00
// Set the UI color scheme according to the options
2023-10-18 10:21:40 -04:00
ApplyTheme();
}
2023-10-08 20:52:29 -04:00
#region Menu Bar
/// <summary>
/// Handler for AboutMenuItem Click event
/// </summary>
public void AboutClick(object sender, RoutedEventArgs e)
{
string aboutText = MainViewModel.CreateAboutText();
CustomMessageBox.Show(this, aboutText, "About", MessageBoxButton.OK, MessageBoxImage.Information);
}
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for AppExitMenuItem Click event
/// </summary>
public void AppExitClick(object sender, RoutedEventArgs e) =>
2023-10-09 00:13:40 -04:00
Application.Current.Shutdown();
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for CheckDumpMenuItem Click event
/// </summary>
public void CheckDumpMenuItemClick(object sender, RoutedEventArgs e) =>
ShowCheckDumpWindow();
/// <summary>
/// Handler for CreateIRDMenuItem Click event
/// </summary>
public void CreateIRDMenuItemClick(object sender, RoutedEventArgs e) =>
ShowCreateIRDWindow();
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for CheckForUpdatesMenuItem Click event
/// </summary>
public void CheckForUpdatesClick(object sender, RoutedEventArgs e)
=> CheckForUpdates(showIfSame: true);
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for DebugViewMenuItem Click event
/// </summary>
public void DebugViewClick(object sender, RoutedEventArgs e) =>
2023-10-08 23:06:17 -04:00
ShowDebugDiscInfoWindow();
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for OptionsMenuItem Click event
/// </summary>
public void OptionsMenuItemClick(object sender, RoutedEventArgs e) =>
2023-10-08 22:49:46 -04:00
ShowOptionsWindow();
2023-10-08 20:52:29 -04:00
#endregion
#region User Area
/// <summary>
/// Handler for CopyProtectScanButton Click event
/// </summary>
#if NET40
public void CopyProtectScanButtonClick(object sender, RoutedEventArgs e)
#else
public async void CopyProtectScanButtonClick(object sender, RoutedEventArgs e)
#endif
{
#if NET40
var (output, error) = MainViewModel.ScanAndShowProtection();
#else
2023-10-11 11:49:56 -04:00
var (output, error) = await MainViewModel.ScanAndShowProtection();
#endif
if (!MainViewModel.LogPanelExpanded)
{
2023-10-11 11:49:56 -04:00
if (!string.IsNullOrEmpty(output) && string.IsNullOrEmpty(error))
CustomMessageBox.Show(this, output, "Detected Protection(s)", MessageBoxButton.OK, MessageBoxImage.Information);
else
CustomMessageBox.Show(this, "An exception occurred, see the log for details", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for DriveLetterComboBox SelectionChanged event
/// </summary>
public void DriveLetterComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.InitializeUIValues(removeEventHandlers: true, rescanDrives: false);
}
/// <summary>
/// Handler for DriveSpeedComboBox SelectionChanged event
/// </summary>
public void DriveSpeedComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.EnsureDiscInformation();
}
/// <summary>
/// Handler for DumpingProgramComboBox SelectionChanged event
/// </summary>
public void DumpingProgramComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.ChangeDumpingProgram();
}
/// <summary>
/// Handler for EnableParametersCheckBox Click event
/// </summary>
2023-10-08 22:49:46 -04:00
public void EnableParametersCheckBoxClick(object sender, RoutedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.ToggleParameters();
}
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for MediaScanButton Click event
/// </summary>
public void MediaScanButtonClick(object sender, RoutedEventArgs e) =>
MainViewModel.InitializeUIValues(removeEventHandlers: true, rescanDrives: true);
/// <summary>
/// Handler for MediaTypeComboBox SelectionChanged event
/// </summary>
public void MediaTypeComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
2023-10-09 00:13:40 -04:00
MainViewModel.ChangeMediaType(e.RemovedItems, e.AddedItems);
2023-10-08 20:52:29 -04:00
}
/// <summary>
/// Handler for OutputPathBrowseButton Click event
/// </summary>
2023-10-08 23:46:24 -04:00
public void OutputPathBrowseButtonClick(object sender, RoutedEventArgs e)
{
BrowseFile();
MainViewModel.EnsureDiscInformation();
}
2023-10-08 20:52:29 -04:00
/// <summary>
/// Handler for OutputPathTextBox TextChanged event
/// </summary>
public void OutputPathTextBoxTextChanged(object sender, TextChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.EnsureDiscInformation();
}
/// <summary>
/// Handler for StartStopButton Click event
/// </summary>
public void StartStopButtonClick(object sender, RoutedEventArgs e) =>
MainViewModel.ToggleStartStop();
/// <summary>
/// Handler for SystemTypeComboBox SelectionChanged event
/// </summary>
public void SystemTypeComboBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
MainViewModel.ChangeSystem();
}
/// <summary>
/// Handler for UpdateVolumeLabel Click event
/// </summary>
public void UpdateVolumeLabelClick(object sender, RoutedEventArgs e)
{
if (MainViewModel.CanExecuteSelectionChanged)
{
if (MainViewModel.Options.FastUpdateLabel)
MainViewModel.FastUpdateLabel(removeEventHandlers: true);
else
MainViewModel.InitializeUIValues(removeEventHandlers: true, rescanDrives: false);
}
}
#endregion
#endregion // Event Handlers
2018-05-12 19:48:18 -04:00
}
}