Handle some suggested changes

This commit is contained in:
Matt Nadareski
2023-10-11 12:26:24 -04:00
parent c96ff23ad1
commit 76b2dd79ab
10 changed files with 69 additions and 68 deletions

View File

@@ -13,6 +13,7 @@
- Enable nullability in MPF
- Enable nullability in MPF.UI.Core
- Enable nullability in MPF.Test
- Handle some suggested changes
### 2.7.0 (2023-10-11)

View File

@@ -4,11 +4,7 @@ using SabreTools.RedumpLib.Data;
namespace MPF.Core.Data
{
#if NET48
public class Options
#else
public class Options
#endif
{
/// <summary>
/// All settings in the form of a dictionary
@@ -664,9 +660,9 @@ namespace MPF.Core.Data
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private bool GetBooleanSetting(Dictionary<string, string> settings, string key, bool defaultValue)
private static bool GetBooleanSetting(Dictionary<string, string> settings, string key, bool defaultValue)
#else
private bool GetBooleanSetting(Dictionary<string, string?> settings, string key, bool defaultValue)
private static bool GetBooleanSetting(Dictionary<string, string?> settings, string key, bool defaultValue)
#endif
{
if (settings.ContainsKey(key))
@@ -690,9 +686,9 @@ namespace MPF.Core.Data
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private int GetInt32Setting(Dictionary<string, string> settings, string key, int defaultValue)
private static int GetInt32Setting(Dictionary<string, string> settings, string key, int defaultValue)
#else
private int GetInt32Setting(Dictionary<string, string?> settings, string key, int defaultValue)
private static int GetInt32Setting(Dictionary<string, string?> settings, string key, int defaultValue)
#endif
{
if (settings.ContainsKey(key))
@@ -716,9 +712,9 @@ namespace MPF.Core.Data
/// <param name="defaultValue">Default value to return if no value is found</param>
/// <returns>Setting value if possible, default value otherwise</returns>
#if NET48
private string GetStringSetting(Dictionary<string, string> settings, string key, string defaultValue)
private static string GetStringSetting(Dictionary<string, string> settings, string key, string defaultValue)
#else
private string? GetStringSetting(Dictionary<string, string?> settings, string key, string? defaultValue)
private static string? GetStringSetting(Dictionary<string, string?> settings, string key, string? defaultValue)
#endif
{
if (settings.ContainsKey(key))

View File

@@ -104,7 +104,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_optionsMenuItemEnabled = value;
TriggerPropertyChanged("OptionsMenuItemEnabled");
TriggerPropertyChanged(nameof(OptionsMenuItemEnabled));
}
}
private bool _optionsMenuItemEnabled;
@@ -118,7 +118,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_currentSystem = value;
TriggerPropertyChanged("CurrentSystem");
TriggerPropertyChanged(nameof(CurrentSystem));
}
}
private RedumpSystem? _currentSystem;
@@ -132,7 +132,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_systemTypeComboBoxEnabled = value;
TriggerPropertyChanged("SystemTypeComboBoxEnabled");
TriggerPropertyChanged(nameof(SystemTypeComboBoxEnabled));
}
}
private bool _systemTypeComboBoxEnabled;
@@ -146,7 +146,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_currentMediaType = value;
TriggerPropertyChanged("CurrentMediaType");
TriggerPropertyChanged(nameof(CurrentMediaType));
}
}
private MediaType? _currentMediaType;
@@ -160,7 +160,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_mediaTypeComboBoxEnabled = value;
TriggerPropertyChanged("MediaTypeComboBoxEnabled");
TriggerPropertyChanged(nameof(MediaTypeComboBoxEnabled));
}
}
private bool _mediaTypeComboBoxEnabled;
@@ -174,7 +174,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_outputPath = value;
TriggerPropertyChanged("OutputPath");
TriggerPropertyChanged(nameof(OutputPath));
}
}
private string _outputPath;
@@ -188,7 +188,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_outputPathTextBoxEnabled = value;
TriggerPropertyChanged("OutputPathTextBoxEnabled");
TriggerPropertyChanged(nameof(OutputPathTextBoxEnabled));
}
}
private bool _outputPathTextBoxEnabled;
@@ -202,7 +202,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_outputPathBrowseButtonEnabled = value;
TriggerPropertyChanged("OutputPathBrowseButtonEnabled");
TriggerPropertyChanged(nameof(OutputPathBrowseButtonEnabled));
}
}
private bool _outputPathBrowseButtonEnabled;
@@ -220,7 +220,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_currentDrive = value;
TriggerPropertyChanged("CurrentDrive");
TriggerPropertyChanged(nameof(CurrentDrive));
}
}
#if NET48
@@ -238,7 +238,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_driveLetterComboBoxEnabled = value;
TriggerPropertyChanged("DriveLetterComboBoxEnabled");
TriggerPropertyChanged(nameof(DriveLetterComboBoxEnabled));
}
}
private bool _driveLetterComboBoxEnabled;
@@ -252,7 +252,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_driveSpeed = value;
TriggerPropertyChanged("DriveSpeed");
TriggerPropertyChanged(nameof(DriveSpeed));
}
}
private int _driveSpeed;
@@ -266,7 +266,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_driveSpeedComboBoxEnabled = value;
TriggerPropertyChanged("DriveSpeedComboBoxEnabled");
TriggerPropertyChanged(nameof(DriveSpeedComboBoxEnabled));
}
}
private bool _driveSpeedComboBoxEnabled;
@@ -280,7 +280,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_currentProgram = value;
TriggerPropertyChanged("CurrentProgram");
TriggerPropertyChanged(nameof(CurrentProgram));
}
}
private InternalProgram _currentProgram;
@@ -294,7 +294,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_dumpingProgramComboBoxEnabled = value;
TriggerPropertyChanged("DumpingProgramComboBoxEnabled");
TriggerPropertyChanged(nameof(DumpingProgramComboBoxEnabled));
}
}
private bool _dumpingProgramComboBoxEnabled;
@@ -308,7 +308,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_parameters = value;
TriggerPropertyChanged("Parameters");
TriggerPropertyChanged(nameof(Parameters));
}
}
private string _parameters;
@@ -322,7 +322,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_parametersCheckBoxEnabled = value;
TriggerPropertyChanged("ParametersCheckBoxEnabled");
TriggerPropertyChanged(nameof(ParametersCheckBoxEnabled));
}
}
private bool _parametersCheckBoxEnabled;
@@ -336,7 +336,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_enableParametersCheckBoxEnabled = value;
TriggerPropertyChanged("EnableParametersCheckBoxEnabled");
TriggerPropertyChanged(nameof(EnableParametersCheckBoxEnabled));
}
}
private bool _enableParametersCheckBoxEnabled;
@@ -350,7 +350,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_startStopButtonEnabled = value;
TriggerPropertyChanged("StartStopButtonEnabled");
TriggerPropertyChanged(nameof(StartStopButtonEnabled));
}
}
private bool _startStopButtonEnabled;
@@ -364,7 +364,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_startStopButtonText = (value as string) ?? string.Empty;
TriggerPropertyChanged("StartStopButtonText");
TriggerPropertyChanged(nameof(StartStopButtonText));
}
}
private string _startStopButtonText;
@@ -378,7 +378,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_mediaScanButtonEnabled = value;
TriggerPropertyChanged("MediaScanButtonEnabled");
TriggerPropertyChanged(nameof(MediaScanButtonEnabled));
}
}
private bool _mediaScanButtonEnabled;
@@ -392,7 +392,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_updateVolumeLabelEnabled = value;
TriggerPropertyChanged("UpdateVolumeLabelEnabled");
TriggerPropertyChanged(nameof(UpdateVolumeLabelEnabled));
}
}
private bool _updateVolumeLabelEnabled;
@@ -406,7 +406,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_copyProtectScanButtonEnabled = value;
TriggerPropertyChanged("CopyProtectScanButtonEnabled");
TriggerPropertyChanged(nameof(CopyProtectScanButtonEnabled));
}
}
private bool _copyProtectScanButtonEnabled;
@@ -420,7 +420,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_status = value;
TriggerPropertyChanged("Status");
TriggerPropertyChanged(nameof(Status));
}
}
private string _status;
@@ -434,7 +434,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_logPanelExpanded = value;
TriggerPropertyChanged("LogPanelExpanded");
TriggerPropertyChanged(nameof(LogPanelExpanded));
}
}
private bool _logPanelExpanded;
@@ -452,7 +452,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_drives = value;
TriggerPropertyChanged("Drives");
TriggerPropertyChanged(nameof(Drives));
}
}
private List<Drive> _drives;
@@ -466,7 +466,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_driveSpeeds = value;
TriggerPropertyChanged("DriveSpeeds");
TriggerPropertyChanged(nameof(DriveSpeeds));
}
}
private List<int> _driveSpeeds;
@@ -484,7 +484,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_mediaTypes = value;
TriggerPropertyChanged("MediaTypes");
TriggerPropertyChanged(nameof(MediaTypes));
}
}
#if NET48
@@ -502,7 +502,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_systems = value;
TriggerPropertyChanged("Systems");
TriggerPropertyChanged(nameof(Systems));
}
}
private List<RedumpSystemComboBoxItem> _systems;
@@ -516,7 +516,7 @@ namespace MPF.Core.UI.ViewModels
set
{
_internalPrograms = value;
TriggerPropertyChanged("InternalPrograms");
TriggerPropertyChanged(nameof(InternalPrograms));
}
}
private List<Element<InternalProgram>> _internalPrograms;
@@ -801,7 +801,7 @@ namespace MPF.Core.UI.ViewModels
/// <summary>
/// Build a dummy SubmissionInfo
/// </summary>
public SubmissionInfo CreateDebugSubmissionInfo()
public static SubmissionInfo CreateDebugSubmissionInfo()
{
return new SubmissionInfo()
{
@@ -994,7 +994,7 @@ namespace MPF.Core.UI.ViewModels
}
}
#endregion
#endregion
#region UI Functionality
@@ -1822,7 +1822,11 @@ namespace MPF.Core.UI.ViewModels
var message = value?.Message;
// Update the label with only the first line of output
#if NET48
if (message != null && message.Contains("\n"))
#else
if (message != null && message.Contains('\n'))
#endif
this.Status = value?.Message?.Split('\n')[0] + " (See log output)";
else
this.Status = value?.Message ?? string.Empty;
@@ -1848,6 +1852,6 @@ namespace MPF.Core.UI.ViewModels
VerboseLogLn(message);
}
#endregion
#endregion
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using MPF.Core.Data;
using MPF.Core.Modules.DiscImageCreator;
using SabreTools.RedumpLib.Data;
@@ -33,7 +34,7 @@ namespace MPF.Test.Modules
var options = new Options();
var actual = new Parameters(knownSystem, mediaType, 'D', "disc.bin", 16, options);
HashSet<string> expectedSet = new HashSet<string>(expected ?? new string[0]);
HashSet<string> expectedSet = new HashSet<string>(expected ?? Array.Empty<string>());
HashSet<string> actualSet = GenerateUsedKeys(actual);
Assert.Equal(expectedSet, actualSet);
}
@@ -46,7 +47,7 @@ namespace MPF.Test.Modules
var options = new Options { DICRereadCount = rereadC2 };
var actual = new Parameters(knownSystem, mediaType, 'D', "disc.bin", 16, options);
HashSet<string> expectedSet = new HashSet<string>(expected ?? new string[0]);
HashSet<string> expectedSet = new HashSet<string>(expected ?? Array.Empty<string>());
HashSet<string> actualSet = GenerateUsedKeys(actual);
Assert.Equal(expectedSet, actualSet);
@@ -66,7 +67,7 @@ namespace MPF.Test.Modules
var options = new Options { DICDVDRereadCount = rereadDVDBD };
var actual = new Parameters(knownSystem, mediaType, 'D', "disc.bin", 16, options);
HashSet<string> expectedSet = new HashSet<string>(expected ?? new string[0]);
HashSet<string> expectedSet = new HashSet<string>(expected ?? Array.Empty<string>());
HashSet<string> actualSet = GenerateUsedKeys(actual);
Assert.Equal(expectedSet, actualSet);
@@ -90,7 +91,7 @@ namespace MPF.Test.Modules
var options = new Options { DICMultiSectorRead = multiSectorRead };
var actual = new Parameters(knownSystem, mediaType, 'D', "disc.bin", 16, options);
HashSet<string> expectedSet = new HashSet<string>(expected ?? new string[0]);
HashSet<string> expectedSet = new HashSet<string>(expected ?? Array.Empty<string>());
HashSet<string> actualSet = GenerateUsedKeys(actual);
Assert.Equal(expectedSet, actualSet);
if (expectedSet.Count != 1 && multiSectorRead)
@@ -111,7 +112,7 @@ namespace MPF.Test.Modules
var options = new Options { DICParanoidMode = paranoidMode };
var actual = new Parameters(knownSystem, mediaType, 'D', "disc.bin", 16, options);
HashSet<string> expectedSet = new HashSet<string>(expected ?? new string[0]);
HashSet<string> expectedSet = new HashSet<string>(expected ?? Array.Empty<string>());
HashSet<string> actualSet = GenerateUsedKeys(actual);
Assert.Equal(expectedSet, actualSet);
if (paranoidMode)

View File

@@ -37,8 +37,7 @@ namespace MPF.UI.Core
#endif
{
// If it's an IElement but ends up null
var element = value as IElement;
if (element == null)
if (!(value is IElement element))
return null;
switch (element)

View File

@@ -18,7 +18,7 @@ namespace WPFCustomMessageBox
/// Global parameter to enable (true) or disable (false) the removal of the title bar icon.
/// If you are using a custom window style, the icon removal may cause issues like displaying two title bar (the default windows one and the custom one).
/// </summary>
public static bool RemoveTitleBarIcon = true;
private static readonly bool RemoveTitleBarIcon = true;
/// <summary>
/// Displays a message box that has a message and returns a result.
@@ -578,7 +578,7 @@ namespace WPFCustomMessageBox
{
if (timeout.HasValue && timeout.Value <= 0)
{
throw new ArgumentOutOfRangeException("timeout", string.Format("Timeout must be greater than 0."));
throw new ArgumentOutOfRangeException(nameof(timeout), string.Format("Timeout must be greater than 0."));
}
if (timeout.HasValue)

View File

@@ -10,7 +10,7 @@ namespace WPFCustomMessageBox
/// </summary>
internal partial class CustomMessageBoxWindow : Window
{
private bool _removeTitleBarIcon = true;
private readonly bool _removeTitleBarIcon = true;
#if NET48
public string Caption

View File

@@ -88,7 +88,7 @@ namespace WPFCustomMessageBox
IntPtr hwnd = new WindowInteropHelper(window).Handle;
// Change the extended window style to not show a window icon
int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
_ = SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_DLGMODALFRAME);
// Update the window's non-client area to reflect the changes
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}

View File

@@ -151,43 +151,43 @@ namespace MPF.UI.Core.Windows
ErrorsCount.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.CommonDiscInfo?.EXEDateBuildDate))
EXEDateBuildDate.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.Filename) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.Filename) != true)
Filename.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.Extras?.Header))
Header.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.InternalName) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.InternalName) != true)
InternalName.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.InternalSerialName) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.InternalSerialName) != true)
InternalSerialName.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.Multisession) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.Multisession) != true)
Multisession.Visibility = Visibility.Collapsed;
if (submissionInfo.CopyProtection?.LibCrypt == null)
LibCrypt.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.CopyProtection?.LibCryptData))
LibCryptData.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.PFIHash) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.PFIHash) != true)
PFIHash.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.Extras?.PIC))
PIC.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.Extras?.PVD))
PVD.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.RingNonZeroDataStart) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.RingNonZeroDataStart) != true)
RingNonZeroDataStart.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.CopyProtection?.SecuROMData))
SecuROMData.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.SSHash) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.SSHash) != true)
SSHash.Visibility = Visibility.Collapsed;
if (string.IsNullOrWhiteSpace(submissionInfo.Extras?.SecuritySectorRanges))
SecuritySectorRanges.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.SSVersion) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.SSVersion) != true)
SSVersion.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.UniversalHash) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.UniversalHash) != true)
UniversalHash.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.VolumeLabel) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.VolumeLabel) != true)
VolumeLabel.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.XeMID) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.XeMID) != true)
XeMID.Visibility = Visibility.Collapsed;
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.Keys.Contains(SiteCode.XMID) != true)
if (submissionInfo.CommonDiscInfo?.CommentsSpecialFields?.ContainsKey(SiteCode.XMID) != true)
XMID.Visibility = Visibility.Collapsed;
}

View File

@@ -115,9 +115,9 @@ namespace MPF.UI.Core.Windows
/// <param name="name">Setting name to find</param>
/// <returns>TextBox for that setting</returns>
#if NET48
private System.Windows.Controls.TextBox TextBoxForPathSetting(Window parent, string name) =>
private static System.Windows.Controls.TextBox TextBoxForPathSetting(Window parent, string name) =>
#else
private System.Windows.Controls.TextBox? TextBoxForPathSetting(Window parent, string name) =>
private static System.Windows.Controls.TextBox? TextBoxForPathSetting(Window parent, string name) =>
#endif
parent.FindName(name + "TextBox") as System.Windows.Controls.TextBox;