From b68ec781844fe6ce3cb3c1ec0dfd2fefaf330f18 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 11 Oct 2023 13:07:45 -0400 Subject: [PATCH] Version-gate some more newer syntax --- CHANGELIST.md | 1 + .../UI/ViewModels/DiscInformationViewModel.cs | 8 +++++++ MPF.Core/UI/ViewModels/MainViewModel.cs | 24 +++++++++++-------- MPF.Core/Utilities/OptionsLoader.cs | 23 +++++++++--------- .../External/WPFCustomMessageBox/Util.cs | 2 +- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 09f7e929..3f566225 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -17,6 +17,7 @@ - Var-ify many instances - Version-gate some newer syntax - Fix Check always showing Help text +- Version-gate some more newer syntax ### 2.7.0 (2023-10-11) diff --git a/MPF.Core/UI/ViewModels/DiscInformationViewModel.cs b/MPF.Core/UI/ViewModels/DiscInformationViewModel.cs index fe768be0..4371c18c 100644 --- a/MPF.Core/UI/ViewModels/DiscInformationViewModel.cs +++ b/MPF.Core/UI/ViewModels/DiscInformationViewModel.cs @@ -38,7 +38,11 @@ namespace MPF.Core.UI.ViewModels /// /// List of Redump-supported Regions /// +#if NET48 private static readonly List RedumpRegions = new List +#else + private static readonly List RedumpRegions = new() +#endif { Region.Argentina, Region.Asia, @@ -129,7 +133,11 @@ namespace MPF.Core.UI.ViewModels /// /// List of Redump-supported Languages /// +#if NET48 private static readonly List RedumpLanguages = new List +#else + private static readonly List RedumpLanguages = new() +#endif { Language.Afrikaans, Language.Albanian, diff --git a/MPF.Core/UI/ViewModels/MainViewModel.cs b/MPF.Core/UI/ViewModels/MainViewModel.cs index 0f12fffe..a0e7c95a 100644 --- a/MPF.Core/UI/ViewModels/MainViewModel.cs +++ b/MPF.Core/UI/ViewModels/MainViewModel.cs @@ -589,8 +589,7 @@ namespace MPF.Core.UI.ViewModels DisableEventHandlers(); // If the property change event is initialized - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); // Reenable event handlers, if necessary if (cachedCanExecuteSelectionChanged) EnableEventHandlers(); @@ -1116,8 +1115,7 @@ namespace MPF.Core.UI.ViewModels /// Text to write to the log private void Log(string text) { - if (_logger != null) - _logger(LogLevel.USER, text); + _logger?.Invoke(LogLevel.USER, text); } /// @@ -1132,8 +1130,7 @@ namespace MPF.Core.UI.ViewModels /// Text to write to the log private void ErrorLog(string text) { - if (_logger != null) - _logger(LogLevel.ERROR, text); + _logger?.Invoke(LogLevel.ERROR, text); } /// @@ -1148,8 +1145,7 @@ namespace MPF.Core.UI.ViewModels /// Text to write to the log private void SecretLog(string text) { - if (_logger != null) - _logger(LogLevel.SECRET, text); + _logger?.Invoke(LogLevel.SECRET, text); } /// @@ -1433,7 +1429,7 @@ namespace MPF.Core.UI.ViewModels // Catch this in case there's an input path issue try { - int driveIndex = Drives.Select(d => d.Letter).ToList().IndexOf(_environment.Parameters?.InputPath?[0] ?? default(char)); + int driveIndex = Drives.Select(d => d.Letter).ToList().IndexOf(_environment.Parameters?.InputPath?[0] ?? default); this.CurrentDrive = (driveIndex != -1 ? Drives[driveIndex] : Drives[0]); } catch { } @@ -1470,8 +1466,12 @@ namespace MPF.Core.UI.ViewModels #endif { // Determine current environment, just in case +#if NET48 if (_environment == null) _environment = DetermineEnvironment(); +#else + _environment ??= DetermineEnvironment(); +#endif // If we don't have a valid drive if (this.CurrentDrive == null || this.CurrentDrive.Letter == default(char)) @@ -1789,7 +1789,7 @@ namespace MPF.Core.UI.ViewModels return true; } - #endregion +#endregion #region Progress Reporting @@ -1804,7 +1804,11 @@ namespace MPF.Core.UI.ViewModels { try { +#if NET48 value = value ?? string.Empty; +#else + value ??= string.Empty; +#endif LogLn(value); } catch { } diff --git a/MPF.Core/Utilities/OptionsLoader.cs b/MPF.Core/Utilities/OptionsLoader.cs index cd4fe2db..bff0a0a7 100644 --- a/MPF.Core/Utilities/OptionsLoader.cs +++ b/MPF.Core/Utilities/OptionsLoader.cs @@ -228,17 +228,18 @@ namespace MPF.Core.Utilities /// public static List PrintSupportedArguments() { - var supportedArguments = new List(); - - supportedArguments.Add("-u, --use Dumping program output type [REQUIRED]"); - supportedArguments.Add("-c, --credentials Redump username and password"); - supportedArguments.Add("-a, --pull-all Pull all information from Redump (requires --credentials)"); - supportedArguments.Add("-p, --path Physical drive path for additional checks"); - supportedArguments.Add("-s, --scan Enable copy protection scan (requires --path)"); - supportedArguments.Add("-f, --protect-file Output protection to separate file (requires --scan)"); - supportedArguments.Add("-l, --load-seed Load a seed submission JSON for user information"); - supportedArguments.Add("-j, --json Enable submission JSON output"); - supportedArguments.Add("-z, --zip Enable log file compression"); + var supportedArguments = new List + { + "-u, --use Dumping program output type [REQUIRED]", + "-c, --credentials Redump username and password", + "-a, --pull-all Pull all information from Redump (requires --credentials)", + "-p, --path Physical drive path for additional checks", + "-s, --scan Enable copy protection scan (requires --path)", + "-f, --protect-file Output protection to separate file (requires --scan)", + "-l, --load-seed Load a seed submission JSON for user information", + "-j, --json Enable submission JSON output", + "-z, --zip Enable log file compression" + }; return supportedArguments; } diff --git a/MPF.UI.Core/External/WPFCustomMessageBox/Util.cs b/MPF.UI.Core/External/WPFCustomMessageBox/Util.cs index 7642f00f..5dd24c55 100644 --- a/MPF.UI.Core/External/WPFCustomMessageBox/Util.cs +++ b/MPF.UI.Core/External/WPFCustomMessageBox/Util.cs @@ -37,7 +37,7 @@ namespace WPFCustomMessageBox const int SWP_NOMOVE = 0x0002; const int SWP_NOZORDER = 0x0004; const int SWP_FRAMECHANGED = 0x0020; - const uint WM_SETICON = 0x0080; + //const uint WM_SETICON = 0x0080; internal static ImageSource ToImageSource(this Icon icon)