From 90edc42fdf6acf34a4597c6506f1dce5b8b76b5b Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 14 Nov 2023 23:40:41 -0500 Subject: [PATCH] Support C# 12 syntax --- CHANGELIST.md | 1 + MPF.Core/Data/Drive.cs | 4 +- MPF.Core/Data/IniFile.cs | 6 +- MPF.Core/Hashing/Hasher.cs | 4 - MPF.Core/InfoTool.cs | 2 +- MPF.Core/MPF.Core.csproj | 5 + MPF.Core/Modules/Aaru/Parameters.cs | 166 +++++++-------- MPF.Core/Modules/BaseParameters.cs | 4 +- MPF.Core/Modules/CleanRIp/Parameters.cs | 34 ++-- .../Modules/DiscImageCreator/Parameters.cs | 190 ++++++++---------- MPF.Core/Modules/Redumper/Parameters.cs | 66 +++--- .../Modules/UmdImageCreator/Parameters.cs | 4 +- MPF.Core/SubmissionInfoTool.cs | 29 +-- MPF.Core/UI/ViewModels/MainViewModel.cs | 24 +-- MPF.Core/UI/ViewModels/OptionsViewModel.cs | 15 +- MPF.UI.Core/MPF.UI.Core.csproj | 1 + MPF.UI.Core/Windows/OptionsWindow.xaml.cs | 2 +- 17 files changed, 251 insertions(+), 306 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index f1cd1f2e..f4c18df5 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -5,6 +5,7 @@ - Fix BE flag logic bug in DIC - Support ancient .NET in Core - Support ancient .NET in UI Core +- Support C# 12 syntax ### 3.0.0 (2023-11-14) diff --git a/MPF.Core/Data/Drive.cs b/MPF.Core/Data/Drive.cs index 58f73671..e8f55034 100644 --- a/MPF.Core/Data/Drive.cs +++ b/MPF.Core/Data/Drive.cs @@ -111,7 +111,7 @@ namespace MPF.Core.Data // Sanitize a Windows-formatted long device path if (devicePath.StartsWith("\\\\.\\")) - devicePath = devicePath.Substring("\\\\.\\".Length); + devicePath = devicePath["\\\\.\\".Length..]; // Create and validate the drive info object var driveInfo = new DriveInfo(devicePath); @@ -161,7 +161,7 @@ namespace MPF.Core.Data public static List CreateListOfDrives(bool ignoreFixedDrives) { var drives = GetDriveList(ignoreFixedDrives); - drives = drives.OrderBy(i => i == null ? "\0" : i.Name).ToList(); + drives = [.. drives.OrderBy(i => i == null ? "\0" : i.Name)]; return drives; } diff --git a/MPF.Core/Data/IniFile.cs b/MPF.Core/Data/IniFile.cs index 94f72438..e22fbb1f 100644 --- a/MPF.Core/Data/IniFile.cs +++ b/MPF.Core/Data/IniFile.cs @@ -8,13 +8,13 @@ namespace MPF.Core.Data { public class IniFile : IDictionary { - private Dictionary _keyValuePairs = new(); + private Dictionary _keyValuePairs = []; public string this[string key] { get { - _keyValuePairs ??= new Dictionary(); + _keyValuePairs ??= []; key = key.ToLowerInvariant(); if (_keyValuePairs.ContainsKey(key)) @@ -24,7 +24,7 @@ namespace MPF.Core.Data } set { - _keyValuePairs ??= new Dictionary(); + _keyValuePairs ??= []; key = key.ToLowerInvariant(); _keyValuePairs[key] = value; diff --git a/MPF.Core/Hashing/Hasher.cs b/MPF.Core/Hashing/Hasher.cs index a4730f0d..31e600cf 100644 --- a/MPF.Core/Hashing/Hasher.cs +++ b/MPF.Core/Hashing/Hasher.cs @@ -289,11 +289,7 @@ namespace MPF.Core.Hashing /// NonCryptographicHashAlgorithm implementations do not need finalization public void Terminate() { -#if NET40 || NET452 byte[] emptyBuffer = []; -#else - byte[] emptyBuffer = Array.Empty(); -#endif switch (_hasher) { case HashAlgorithm ha: diff --git a/MPF.Core/InfoTool.cs b/MPF.Core/InfoTool.cs index 2e0a6e1e..21f9e1dd 100644 --- a/MPF.Core/InfoTool.cs +++ b/MPF.Core/InfoTool.cs @@ -1134,7 +1134,7 @@ namespace MPF.Core } else { - string entryName = file.Substring(outputDirectory!.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + string entryName = file[outputDirectory!.Length..].TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); #if NETFRAMEWORK || NETCOREAPP3_1 || NET5_0 zf.CreateEntryFromFile(file, entryName, CompressionLevel.Optimal); diff --git a/MPF.Core/MPF.Core.csproj b/MPF.Core/MPF.Core.csproj index 261e7e52..9dfd9fa8 100644 --- a/MPF.Core/MPF.Core.csproj +++ b/MPF.Core/MPF.Core.csproj @@ -6,6 +6,7 @@ win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 latest enable + true true 3.0.0 @@ -33,6 +34,10 @@ + + + + diff --git a/MPF.Core/Modules/Aaru/Parameters.cs b/MPF.Core/Modules/Aaru/Parameters.cs index 11793773..2a773138 100644 --- a/MPF.Core/Modules/Aaru/Parameters.cs +++ b/MPF.Core/Modules/Aaru/Parameters.cs @@ -409,7 +409,7 @@ namespace MPF.Core.Modules.Aaru // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { - info.Artifacts ??= new Dictionary(); + info.Artifacts ??= []; if (File.Exists(basePath + ".cicm.xml")) info.Artifacts["cicm"] = GetBase64(GetFullFile(basePath + ".cicm.xml")) ?? string.Empty; if (File.Exists(basePath + ".ibg")) @@ -1128,48 +1128,42 @@ namespace MPF.Core.Modules.Aaru { #region Archive Family - [CommandStrings.ArchivePrefixLong + " " + CommandStrings.ArchiveInfo] = new List() - { - }, + [CommandStrings.ArchivePrefixLong + " " + CommandStrings.ArchiveInfo] = [], #endregion #region Database Family - [CommandStrings.DatabasePrefixLong + " " + CommandStrings.DatabaseStats] = new List() - { - }, + [CommandStrings.DatabasePrefixLong + " " + CommandStrings.DatabaseStats] = [], - [CommandStrings.DatabasePrefixLong + " " + CommandStrings.DatabaseUpdate] = new List() - { + [CommandStrings.DatabasePrefixLong + " " + CommandStrings.DatabaseUpdate] = + [ FlagStrings.ClearLong, FlagStrings.ClearAllLong, - }, + ], #endregion #region Device Family - [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceInfo] = new List() - { + [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceInfo] = + [ FlagStrings.OutputPrefixLong, - }, + ], - [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceList] = new List() - { - }, + [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceList] = [], - [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceReport] = new List() - { + [CommandStrings.DevicePrefixLong + " " + CommandStrings.DeviceReport] = + [ FlagStrings.TrapDiscLong, - }, + ], #endregion #region Filesystem Family - [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemExtract] = new List() - { + [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemExtract] = + [ FlagStrings.EncodingLong, FlagStrings.EncodingShort, FlagStrings.ExtendedAttributesLong, @@ -1178,10 +1172,10 @@ namespace MPF.Core.Modules.Aaru FlagStrings.NamespaceShort, FlagStrings.OptionsLong, FlagStrings.OptionsShort, - }, + ], - [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemInfo] = new List() - { + [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemInfo] = + [ FlagStrings.EncodingLong, FlagStrings.EncodingShort, FlagStrings.ExtendedAttributesLong, @@ -1190,10 +1184,10 @@ namespace MPF.Core.Modules.Aaru FlagStrings.NamespaceShort, FlagStrings.OptionsLong, FlagStrings.OptionsShort, - }, + ], - [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemListLong] = new List() - { + [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemListLong] = + [ FlagStrings.EncodingLong, FlagStrings.EncodingShort, FlagStrings.FilesystemsLong, @@ -1202,18 +1196,16 @@ namespace MPF.Core.Modules.Aaru FlagStrings.LongFormatShort, FlagStrings.PartitionsLong, FlagStrings.PartitionsShort, - }, + ], - [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemOptions] = new List() - { - }, + [CommandStrings.FilesystemPrefixLong + " " + CommandStrings.FilesystemOptions] = [], #endregion #region Image Family - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageChecksumLong] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageChecksumLong] = + [ FlagStrings.Adler32Long, FlagStrings.Adler32Short, FlagStrings.CRC16Long, @@ -1235,14 +1227,12 @@ namespace MPF.Core.Modules.Aaru FlagStrings.SpamSumShort, FlagStrings.WholeDiscLong, FlagStrings.WholeDiscShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageCompareLong] = new List() - { - }, + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageCompareLong] = [], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageConvert] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageConvert] = + [ FlagStrings.CommentsLong, FlagStrings.CountLong, FlagStrings.CountShort, @@ -1275,20 +1265,20 @@ namespace MPF.Core.Modules.Aaru FlagStrings.ResumeFileShort, FlagStrings.XMLSidecarLong, FlagStrings.XMLSidecarShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageCreateSidecar] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageCreateSidecar] = + [ FlagStrings.BlockSizeLong, FlagStrings.BlockSizeShort, FlagStrings.EncodingLong, FlagStrings.EncodingShort, FlagStrings.TapeLong, FlagStrings.TapeShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageDecode] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageDecode] = + [ FlagStrings.DiskTagsLong, FlagStrings.DiskTagsShort, FlagStrings.LengthLong, @@ -1297,28 +1287,24 @@ namespace MPF.Core.Modules.Aaru FlagStrings.SectorTagsShort, FlagStrings.StartLong, FlagStrings.StartShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageEntropy] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageEntropy] = + [ FlagStrings.DuplicatedSectorsLong, FlagStrings.DuplicatedSectorsShort, FlagStrings.SeparatedTracksLong, FlagStrings.SeparatedTracksShort, FlagStrings.WholeDiscLong, FlagStrings.WholeDiscShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageInfo] = new List() - { - }, + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageInfo] = [], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageOptions] = new List() - { - }, + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageOptions] = [], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImagePrint] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImagePrint] = + [ FlagStrings.LengthLong, FlagStrings.LengthShort, FlagStrings.LongSectorsLong, @@ -1327,22 +1313,22 @@ namespace MPF.Core.Modules.Aaru FlagStrings.StartShort, FlagStrings.WidthLong, FlagStrings.WidthShort, - }, + ], - [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageVerify] = new List() - { + [CommandStrings.ImagePrefixLong + " " + CommandStrings.ImageVerify] = + [ FlagStrings.VerifyDiscLong, FlagStrings.VerifyDiscShort, FlagStrings.VerifySectorsLong, FlagStrings.VerifySectorsShort, - }, + ], #endregion #region Media Family - [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaDump] = new List() - { + [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaDump] = + [ FlagStrings.EjectLong, FlagStrings.EncodingLong, FlagStrings.EncodingShort, @@ -1380,29 +1366,29 @@ namespace MPF.Core.Modules.Aaru FlagStrings.UseBufferedReadsLong, FlagStrings.XMLSidecarLong, FlagStrings.XMLSidecarShort, - }, + ], - [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaInfo] = new List() - { + [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaInfo] = + [ FlagStrings.OutputPrefixLong, FlagStrings.OutputPrefixShort, - }, + ], - [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaScan] = new List() - { + [CommandStrings.MediaPrefixLong + " " + CommandStrings.MediaScan] = + [ FlagStrings.ImgBurnLogLong, FlagStrings.ImgBurnLogShort, FlagStrings.MHDDLogLong, FlagStrings.MHDDLogShort, FlagStrings.UseBufferedReadsLong, - }, + ], #endregion #region Standalone Commands - [CommandStrings.NONE] = new List() - { + [CommandStrings.NONE] = + [ FlagStrings.DebugLong, FlagStrings.DebugShort, FlagStrings.HelpLong, @@ -1411,27 +1397,17 @@ namespace MPF.Core.Modules.Aaru FlagStrings.VerboseLong, FlagStrings.VerboseShort, FlagStrings.VersionLong, - }, + ], - [CommandStrings.Configure] = new List() - { - }, + [CommandStrings.Configure] = [], - [CommandStrings.Formats] = new List() - { - }, + [CommandStrings.Formats] = [], - [CommandStrings.ListEncodings] = new List() - { - }, + [CommandStrings.ListEncodings] = [], - [CommandStrings.ListNamespaces] = new List() - { - }, + [CommandStrings.ListNamespaces] = [], - [CommandStrings.Remote] = new List() - { - }, + [CommandStrings.Remote] = [], #endregion }; @@ -1500,7 +1476,7 @@ namespace MPF.Core.Modules.Aaru { BaseCommand = CommandStrings.NONE; - flags = new Dictionary(); + flags = []; BlockSizeValue = null; CommentsValue = null; @@ -2470,14 +2446,14 @@ namespace MPF.Core.Modules.Aaru } } - cueTrack.Indices = cueIndicies.ToArray(); + cueTrack.Indices = [.. cueIndicies]; } else { // Default if index data missing from sidecar cueTrack.Indices = new CueIndex[] { - new CueIndex + new() { Index = 1, Minutes = 0, @@ -2496,7 +2472,7 @@ namespace MPF.Core.Modules.Aaru } // If we have a cuesheet to write out, do so - cueSheet.Files = cueFiles.ToArray(); + cueSheet.Files = [.. cueFiles]; if (cueSheet != null && cueSheet != default) { var ms = new SabreTools.Serialization.Streams.CueSheet().Serialize(cueSheet); @@ -2726,7 +2702,7 @@ namespace MPF.Core.Modules.Aaru // Assign the roms to a new game datafile.Games = new Game[1]; - datafile.Games[0] = new Game { Roms = roms.ToArray() }; + datafile.Games[0] = new Game { Roms = [.. roms] }; return datafile; } @@ -2887,7 +2863,7 @@ namespace MPF.Core.Modules.Aaru pvdData.AddRange(new string((char)0, 14).ToCharArray().Select(c => (byte)c)); // Return the filled array - return pvdData.ToArray(); + return [.. pvdData]; } /// @@ -2928,7 +2904,7 @@ namespace MPF.Core.Modules.Aaru // Get and return the byte array List dateTimeList = dateTimeString.ToCharArray().Select(c => (byte)c).ToList(); dateTimeList.Add(timeZoneNumber); - return dateTimeList.ToArray(); + return [.. dateTimeList]; } /// diff --git a/MPF.Core/Modules/BaseParameters.cs b/MPF.Core/Modules/BaseParameters.cs index 1c946a46..c482be70 100644 --- a/MPF.Core/Modules/BaseParameters.cs +++ b/MPF.Core/Modules/BaseParameters.cs @@ -48,7 +48,7 @@ namespace MPF.Core.Modules /// /// Set of flags to pass to the executable /// - protected Dictionary flags = new(); + protected Dictionary flags = []; protected internal IEnumerable Keys => flags.Keys; /// @@ -1120,7 +1120,7 @@ namespace MPF.Core.Modules return null; if (trimLength > -1) - hex = hex.Substring(0, trimLength); + hex = hex[..trimLength]; return Regex.Replace(hex, ".{32}", "$0\n", RegexOptions.Compiled); } diff --git a/MPF.Core/Modules/CleanRIp/Parameters.cs b/MPF.Core/Modules/CleanRIp/Parameters.cs index d3e730b2..8735d458 100644 --- a/MPF.Core/Modules/CleanRIp/Parameters.cs +++ b/MPF.Core/Modules/CleanRIp/Parameters.cs @@ -107,7 +107,7 @@ namespace MPF.Core.Modules.CleanRip // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { - info.Artifacts ??= new Dictionary(); + info.Artifacts ??= []; if (File.Exists(basePath + ".bca")) info.Artifacts["bca"] = GetBase64(GetFullFile(basePath + ".bca", binary: true)) ?? string.Empty; @@ -171,25 +171,25 @@ namespace MPF.Core.Modules.CleanRip if (string.IsNullOrWhiteSpace(line)) continue; else if (line!.StartsWith("CRC32")) - crc = line.Substring(7).ToLowerInvariant(); + crc = line[7..].ToLowerInvariant(); else if (line.StartsWith("MD5")) - md5 = line.Substring(5); + md5 = line[5..]; else if (line.StartsWith("SHA-1")) - sha1 = line.Substring(7); + sha1 = line[7..]; } return new Datafile { - Games = new Game[] - { - new Game + Games = + [ + new() { - Roms = new Rom[] - { + Roms = + [ new Rom { Name = Path.GetFileName(iso), Size = size.ToString(), Crc = crc, Md5 = md5, Sha1 = sha1 }, - } + ] } - } + ] }; } catch @@ -257,11 +257,11 @@ namespace MPF.Core.Modules.CleanRip if (string.IsNullOrWhiteSpace(line)) continue; else if (line!.StartsWith("CRC32")) - crc = line.Substring(7).ToLowerInvariant(); + crc = line[7..].ToLowerInvariant(); else if (line.StartsWith("MD5")) - md5 = line.Substring(5); + md5 = line[5..]; else if (line.StartsWith("SHA-1")) - sha1 = line.Substring(7); + sha1 = line[7..]; } return $""; @@ -306,15 +306,15 @@ namespace MPF.Core.Modules.CleanRip } else if (line!.StartsWith("Version")) { - version = line.Substring("Version: ".Length); + version = line["Version: ".Length..]; } else if (line.StartsWith("Internal Name")) { - name = line.Substring("Internal Name: ".Length); + name = line["Internal Name: ".Length..]; } else if (line.StartsWith("Filename")) { - string serial = line.Substring("Filename: ".Length); + string serial = line["Filename: ".Length..]; // char gameType = serial[0]; // string gameid = serial[1] + serial[2]; diff --git a/MPF.Core/Modules/DiscImageCreator/Parameters.cs b/MPF.Core/Modules/DiscImageCreator/Parameters.cs index 69619d7d..f27d22d9 100644 --- a/MPF.Core/Modules/DiscImageCreator/Parameters.cs +++ b/MPF.Core/Modules/DiscImageCreator/Parameters.cs @@ -825,7 +825,7 @@ namespace MPF.Core.Modules.DiscImageCreator // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { - info.Artifacts ??= new Dictionary(); + info.Artifacts ??= []; //if (File.Exists($"{basePath}.c2")) // info.Artifacts["c2"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}.c2")) ?? string.Empty; @@ -1368,8 +1368,8 @@ namespace MPF.Core.Modules.DiscImageCreator { return new Dictionary>() { - [CommandStrings.Audio] = new List() - { + [CommandStrings.Audio] = + [ FlagStrings.BEOpcode, FlagStrings.C2Opcode, FlagStrings.D8Opcode, @@ -1385,23 +1385,21 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.ScanSectorProtect, FlagStrings.SkipSector, FlagStrings.SubchannelReadLevel, - }, + ], - [CommandStrings.BluRay] = new List() - { + [CommandStrings.BluRay] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, FlagStrings.DVDReread, FlagStrings.ForceUnitAccess, FlagStrings.UseAnchorVolumeDescriptorPointer, - }, + ], - [CommandStrings.Close] = new List() - { - }, + [CommandStrings.Close] = [], - [CommandStrings.CompactDisc] = new List() - { + [CommandStrings.CompactDisc] = + [ FlagStrings.AddOffset, FlagStrings.AMSF, FlagStrings.AtariJaguar, @@ -1426,10 +1424,10 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.VideoNow, FlagStrings.VideoNowColor, FlagStrings.VideoNowXP, - }, + ], - [CommandStrings.Data] = new List() - { + [CommandStrings.Data] = + [ FlagStrings.BEOpcode, FlagStrings.C2Opcode, FlagStrings.D8Opcode, @@ -1445,10 +1443,10 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.ScanSectorProtect, FlagStrings.SkipSector, FlagStrings.SubchannelReadLevel, - }, + ], - [CommandStrings.DigitalVideoDisc] = new List() - { + [CommandStrings.DigitalVideoDisc] = + [ FlagStrings.CopyrightManagementInformation, FlagStrings.DatExpand, FlagStrings.DisableBeep, @@ -1463,28 +1461,24 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.ScanFileProtect, FlagStrings.SkipSector, FlagStrings.UseAnchorVolumeDescriptorPointer, - }, + ], - [CommandStrings.Disk] = new List() - { + [CommandStrings.Disk] = + [ FlagStrings.DatExpand, - }, + ], - [CommandStrings.DriveSpeed] = new List() - { - }, + [CommandStrings.DriveSpeed] = [], - [CommandStrings.Eject] = new List() - { - }, + [CommandStrings.Eject] = [], - [CommandStrings.Floppy] = new List() - { + [CommandStrings.Floppy] = + [ FlagStrings.DatExpand, - }, + ], - [CommandStrings.GDROM] = new List() - { + [CommandStrings.GDROM] = + [ FlagStrings.BEOpcode, FlagStrings.C2Opcode, FlagStrings.D8Opcode, @@ -1495,40 +1489,28 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.NoFixSubQ, FlagStrings.NoFixSubRtoW, FlagStrings.SubchannelReadLevel, - }, + ], - [CommandStrings.MDS] = new List() - { - }, + [CommandStrings.MDS] = [], - [CommandStrings.Merge] = new List() - { - }, + [CommandStrings.Merge] = [], - [CommandStrings.Reset] = new List() - { - }, + [CommandStrings.Reset] = [], - [CommandStrings.SACD] = new List() - { + [CommandStrings.SACD] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, - }, + ], - [CommandStrings.Start] = new List() - { - }, + [CommandStrings.Start] = [], - [CommandStrings.Stop] = new List() - { - }, + [CommandStrings.Stop] = [], - [CommandStrings.Sub] = new List() - { - }, + [CommandStrings.Sub] = [], - [CommandStrings.Swap] = new List() - { + [CommandStrings.Swap] = + [ FlagStrings.AddOffset, FlagStrings.BEOpcode, FlagStrings.C2Opcode, @@ -1549,48 +1531,44 @@ namespace MPF.Core.Modules.DiscImageCreator FlagStrings.VideoNow, FlagStrings.VideoNowColor, FlagStrings.VideoNowXP, - }, + ], - [CommandStrings.Tape] = new List() - { - }, + [CommandStrings.Tape] = [], - [CommandStrings.Version] = new List() - { - }, + [CommandStrings.Version] = [], - [CommandStrings.XBOX] = new List() - { + [CommandStrings.XBOX] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, FlagStrings.DVDReread, FlagStrings.ForceUnitAccess, FlagStrings.NoSkipSS, - }, + ], - [CommandStrings.XBOXSwap] = new List() - { + [CommandStrings.XBOXSwap] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, FlagStrings.ForceUnitAccess, FlagStrings.NoSkipSS, - }, + ], - [CommandStrings.XGD2Swap] = new List() - { + [CommandStrings.XGD2Swap] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, FlagStrings.ForceUnitAccess, FlagStrings.NoSkipSS, - }, + ], - [CommandStrings.XGD3Swap] = new List() - { + [CommandStrings.XGD3Swap] = + [ FlagStrings.DatExpand, FlagStrings.DisableBeep, FlagStrings.ForceUnitAccess, FlagStrings.NoSkipSS, - }, + ], }; } @@ -1813,7 +1791,7 @@ namespace MPF.Core.Modules.DiscImageCreator StartLBAValue = null; EndLBAValue = null; - flags = new Dictionary(); + flags = []; AddOffsetValue = null; BEOpcodeValue = null; @@ -2697,25 +2675,25 @@ namespace MPF.Core.Modules.DiscImageCreator if (line.StartsWith("DiscType:")) { // DiscType: - string identifier = line.Substring("DiscType: ".Length); + string identifier = line["DiscType: ".Length..]; discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("DiscTypeIdentifier:")) { // DiscTypeIdentifier: - string identifier = line.Substring("DiscTypeIdentifier: ".Length); + string identifier = line["DiscTypeIdentifier: ".Length..]; discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("DiscTypeSpecific:")) { // DiscTypeSpecific: - string identifier = line.Substring("DiscTypeSpecific: ".Length); + string identifier = line["DiscTypeSpecific: ".Length..]; discTypeOrBookTypeSet.Add(identifier); } else if (line.StartsWith("BookType:")) { // BookType: - string identifier = line.Substring("BookType: ".Length); + string identifier = line["BookType: ".Length..]; discTypeOrBookTypeSet.Add(identifier); } @@ -2767,9 +2745,9 @@ namespace MPF.Core.Modules.DiscImageCreator break; if (line.StartsWith("CopyrightProtectionType")) - copyrightProtectionSystemType = line.Substring("CopyrightProtectionType: ".Length); + copyrightProtectionSystemType = line["CopyrightProtectionType: ".Length..]; else if (line.StartsWith("RegionManagementInformation")) - region = line.Substring("RegionManagementInformation: ".Length); + region = line["RegionManagementInformation: ".Length..]; line = sr.ReadLine()?.Trim(); } @@ -2792,7 +2770,7 @@ namespace MPF.Core.Modules.DiscImageCreator if (line.StartsWith("DecryptedDiscKey")) { - decryptedDiscKey = line.Substring("DecryptedDiscKey[020]: ".Length); + decryptedDiscKey = line["DecryptedDiscKey[020]: ".Length..]; } else if (line.StartsWith("LBA:")) { @@ -2805,7 +2783,7 @@ namespace MPF.Core.Modules.DiscImageCreator var match = Regex.Match(line, @"^LBA:\s*[0-9]+, Filename: (.*?), No TitleKey$", RegexOptions.Compiled); string matchedFilename = match.Groups[1].Value; if (matchedFilename.EndsWith(";1")) - matchedFilename = matchedFilename.Substring(0, matchedFilename.Length - 2); + matchedFilename = matchedFilename[..^2]; vobKeys += $"{matchedFilename} Title Key: No Title Key\n"; } @@ -2814,7 +2792,7 @@ namespace MPF.Core.Modules.DiscImageCreator var match = Regex.Match(line, @"^LBA:\s*[0-9]+, Filename: (.*?), EncryptedTitleKey: .*?, DecryptedTitleKey: (.*?)$", RegexOptions.Compiled); string matchedFilename = match.Groups[1].Value; if (matchedFilename.EndsWith(";1")) - matchedFilename = matchedFilename.Substring(0, matchedFilename.Length - 2); + matchedFilename = matchedFilename[..^2]; vobKeys += $"{matchedFilename} Title Key: {match.Groups[2].Value}\n"; } @@ -2876,14 +2854,14 @@ namespace MPF.Core.Modules.DiscImageCreator { totalErrors ??= 0; - if (Int64.TryParse(line.Substring("Total errors: ".Length).Trim(), out long te)) + if (Int64.TryParse(line["Total errors: ".Length..].Trim(), out long te)) totalErrors += te; } else if (line.StartsWith("Total warnings")) { totalErrors ??= 0; - if (Int64.TryParse(line.Substring("Total warnings: ".Length).Trim(), out long tw)) + if (Int64.TryParse(line["Total warnings: ".Length..].Trim(), out long tw)) totalErrors += tw; } } @@ -2915,11 +2893,11 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader!.Split('\n'); - string versionLine = header[4].Substring(58); - string dateLine = header[5].Substring(58); - serial = versionLine.Substring(0, 10).TrimEnd(); + string versionLine = header[4][58..]; + string dateLine = header[5][58..]; + serial = versionLine[..10].TrimEnd(); version = versionLine.Substring(10, 6).TrimStart('V', 'v'); - date = dateLine.Substring(0, 8); + date = dateLine[..8]; return true; } catch @@ -2956,17 +2934,17 @@ namespace MPF.Core.Modules.DiscImageCreator if (string.IsNullOrEmpty(manufacturer) && line.StartsWith("VendorId")) { // VendorId: - manufacturer = line.Substring("VendorId: ".Length); + manufacturer = line["VendorId: ".Length..]; } else if (string.IsNullOrEmpty(model) && line.StartsWith("ProductId")) { // ProductId: - model = line.Substring("ProductId: ".Length); + model = line["ProductId: ".Length..]; } else if (string.IsNullOrEmpty(firmware) && line.StartsWith("ProductRevisionLevel")) { // ProductRevisionLevel: - firmware = line.Substring("ProductRevisionLevel: ".Length); + firmware = line["ProductRevisionLevel: ".Length..]; } line = sr.ReadLine(); @@ -3117,7 +3095,7 @@ namespace MPF.Core.Modules.DiscImageCreator // TODO: Are there any examples of 3+ session discs? // Read the first session lead-out - var firstSessionLeadOutLengthString = line?.Substring("Lead-out length of 1st session: ".Length); + var firstSessionLeadOutLengthString = line?["Lead-out length of 1st session: ".Length..]; line = sr.ReadLine()?.Trim(); if (line == null) return null; @@ -3126,12 +3104,12 @@ namespace MPF.Core.Modules.DiscImageCreator string? secondSessionLeadInLengthString = null; while (line?.StartsWith("Lead-in length") == false) { - secondSessionLeadInLengthString = line?.Substring("Lead-in length of 2nd session: ".Length); + secondSessionLeadInLengthString = line?["Lead-in length of 2nd session: ".Length..]; line = sr.ReadLine()?.Trim(); } // Read the second session pregap - var secondSessionPregapLengthString = line?.Substring("Pregap length of 1st track of 2nd session: ".Length); + var secondSessionPregapLengthString = line?["Pregap length of 1st track of 2nd session: ".Length..]; // Calculate the session gap total if (!int.TryParse(firstSessionLeadOutLengthString, out int firstSessionLeadOutLength)) @@ -3355,11 +3333,11 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader!.Split('\n'); - string serialVersionLine = header[2].Substring(58); - string dateLine = header[3].Substring(58); - serial = serialVersionLine.Substring(0, 10).Trim(); + string serialVersionLine = header[2][58..]; + string dateLine = header[3][58..]; + serial = serialVersionLine[..10].Trim(); version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v'); - date = dateLine.Substring(0, 8); + date = dateLine[..8]; date = $"{date[0]}{date[1]}{date[2]}{date[3]}-{date[4]}{date[5]}-{date[6]}{date[7]}"; return true; } @@ -3388,16 +3366,16 @@ namespace MPF.Core.Modules.DiscImageCreator try { string[] header = segaHeader!.Split('\n'); - string serialVersionLine = header[8].Substring(58); - string dateLine = header[1].Substring(58); + string serialVersionLine = header[8][58..]; + string dateLine = header[1][58..]; serial = serialVersionLine.Substring(3, 8).TrimEnd('-', ' '); - date = dateLine.Substring(8).Trim(); + date = dateLine[8..].Trim(); // Properly format the date string, if possible string[] dateSplit = date.Split('.'); if (dateSplit.Length == 1) - dateSplit = [date.Substring(0, 4), date.Substring(4)]; + dateSplit = [date[..4], date[4..]]; string month = dateSplit[1]; dateSplit[1] = month switch diff --git a/MPF.Core/Modules/Redumper/Parameters.cs b/MPF.Core/Modules/Redumper/Parameters.cs index 7de1f2f1..3497750b 100644 --- a/MPF.Core/Modules/Redumper/Parameters.cs +++ b/MPF.Core/Modules/Redumper/Parameters.cs @@ -480,7 +480,7 @@ namespace MPF.Core.Modules.Redumper // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { - info.Artifacts ??= new Dictionary(); + info.Artifacts ??= []; if (File.Exists($"{basePath}.cdtext")) info.Artifacts["cdtext"] = GetBase64(GetFullFile($"{basePath}.cdtext")) ?? string.Empty; @@ -525,7 +525,7 @@ namespace MPF.Core.Modules.Redumper { var parameters = new List(); - ModeValues ??= new List { CommandStrings.NONE }; + ModeValues ??= [CommandStrings.NONE]; // Modes parameters.AddRange(ModeValues); @@ -752,8 +752,8 @@ namespace MPF.Core.Modules.Redumper { return new Dictionary>() { - [CommandStrings.NONE] = new List - { + [CommandStrings.NONE] = + [ // General FlagStrings.HelpLong, FlagStrings.HelpShort, @@ -799,7 +799,7 @@ namespace MPF.Core.Modules.Redumper FlagStrings.Skip, FlagStrings.DumpReadSize, FlagStrings.OverreadLeadout, - }, + ], }; } @@ -894,7 +894,7 @@ namespace MPF.Core.Modules.Redumper { BaseCommand = CommandStrings.NONE; - flags = new Dictionary(); + flags = []; // General DriveValue = null; @@ -943,18 +943,18 @@ namespace MPF.Core.Modules.Redumper case MediaType.CDROM: ModeValues = this.System switch { - RedumpSystem.SuperAudioCD => new List { CommandStrings.SACD }, - _ => new List { CommandStrings.CD }, + RedumpSystem.SuperAudioCD => [CommandStrings.SACD], + _ => [CommandStrings.CD], }; break; case MediaType.DVD: - ModeValues = new List { CommandStrings.DVD }; + ModeValues = [CommandStrings.DVD]; break; case MediaType.HDDVD: // TODO: Keep in sync if another command string shows up - ModeValues = new List { CommandStrings.DVD }; + ModeValues = [CommandStrings.DVD]; break; case MediaType.BluRay: - ModeValues = new List { CommandStrings.BluRay }; + ModeValues = [CommandStrings.BluRay]; break; default: BaseCommand = null; @@ -1023,7 +1023,7 @@ namespace MPF.Core.Modules.Redumper .ToList(); // Setup the modes - ModeValues = new List(); + ModeValues = []; // All modes should be cached separately int index = 0; @@ -1352,7 +1352,7 @@ namespace MPF.Core.Modules.Redumper if (line.StartsWith("current profile:")) { // current profile: - discTypeOrBookType = line.Substring("current profile: ".Length); + discTypeOrBookType = line["current profile: ".Length..]; } line = sr.ReadLine(); @@ -1394,17 +1394,17 @@ namespace MPF.Core.Modules.Redumper { if (line.StartsWith("protection system type")) { - copyrightProtectionSystemType = line.Substring("protection system type: ".Length); + copyrightProtectionSystemType = line["protection system type: ".Length..]; if (copyrightProtectionSystemType == "none" || copyrightProtectionSystemType == "") copyrightProtectionSystemType = "No"; } else if (line.StartsWith("region management information:")) { - region = line.Substring("region management information: ".Length); + region = line["region management information: ".Length..]; } else if (line.StartsWith("disc key")) { - decryptedDiscKey = line.Substring("disc key: ".Length).Replace(':', ' '); + decryptedDiscKey = line["disc key: ".Length..].Replace(':', ' '); } else if (line.StartsWith("title keys")) { @@ -1596,24 +1596,24 @@ namespace MPF.Core.Modules.Redumper else if (line.StartsWith("layer break:")) { // layer break: - layerbreak1 = line.Substring("layer break: ".Length).Trim(); + layerbreak1 = line["layer break: ".Length..].Trim(); } // Multi-layer discs have the layer in the name else if (line.StartsWith("layer break (layer: 0):")) { // layer break (layer: 0): - layerbreak1 = line.Substring("layer break (layer: 0): ".Length).Trim(); + layerbreak1 = line["layer break (layer: 0): ".Length..].Trim(); } else if (line.StartsWith("layer break (layer: 1):")) { // layer break (layer: 1): - layerbreak2 = line.Substring("layer break (layer: 1): ".Length).Trim(); + layerbreak2 = line["layer break (layer: 1): ".Length..].Trim(); } else if (line.StartsWith("layer break (layer: 2):")) { // layer break (layer: 2): - layerbreak3 = line.Substring("layer break (layer: 2): ".Length).Trim(); + layerbreak3 = line["layer break (layer: 2): ".Length..].Trim(); } } @@ -1658,11 +1658,11 @@ namespace MPF.Core.Modules.Redumper // Store the first session range if (line.Contains("session 1:")) - firstSession = line.Substring("session 1: ".Length).Trim(); + firstSession = line["session 1: ".Length..].Trim(); // Store the secomd session range else if (line.Contains("session 2:")) - secondSession = line.Substring("session 2: ".Length).Trim(); + secondSession = line["session 2: ".Length..].Trim(); } // If either is blank, we don't have multisession @@ -1884,7 +1884,7 @@ namespace MPF.Core.Modules.Redumper { string? line = sr.ReadLine()?.TrimStart(); if (line?.StartsWith("non-zero data sample range") == true) - return line.Substring("non-zero data sample range: [".Length).Trim().Split(' ')[0]; + return line["non-zero data sample range: [".Length..].Trim().Split(' ')[0]; } // We couldn't detect it then @@ -1915,11 +1915,11 @@ namespace MPF.Core.Modules.Redumper try { string[] header = segaHeader!.Split('\n'); - string serialVersionLine = header[2].Substring(58); - string dateLine = header[3].Substring(58); - serial = serialVersionLine.Substring(0, 10).Trim(); + string serialVersionLine = header[2][58..]; + string dateLine = header[3][58..]; + serial = serialVersionLine[..10].Trim(); version = serialVersionLine.Substring(10, 6).TrimStart('V', 'v'); - date = dateLine.Substring(0, 8); + date = dateLine[..8]; date = $"{date[0]}{date[1]}{date[2]}{date[3]}-{date[4]}{date[5]}-{date[6]}{date[7]}"; return true; } @@ -2052,19 +2052,19 @@ namespace MPF.Core.Modules.Redumper if (line.StartsWith("build date:")) { - buildDate = line.Substring("build date: ".Length).Trim(); + buildDate = line["build date: ".Length..].Trim(); } else if (line.StartsWith("serial:")) { - serial = line.Substring("serial: ".Length).Trim(); + serial = line["serial: ".Length..].Trim(); } else if (line.StartsWith("region:")) { - region = line.Substring("region: ".Length).Trim(); + region = line["region: ".Length..].Trim(); } else if (line.StartsWith("regions:")) { - region = line.Substring("regions: ".Length).Trim(); + region = line["regions: ".Length..].Trim(); } else if (line.StartsWith("header:")) { @@ -2109,7 +2109,7 @@ namespace MPF.Core.Modules.Redumper { string? line = sr.ReadLine()?.TrimStart(); if (line?.StartsWith("Universal Hash") == true) - return line.Substring("Universal Hash (SHA-1): ".Length).Trim(); + return line["Universal Hash (SHA-1): ".Length..].Trim(); } // We couldn't detect it then @@ -2141,7 +2141,7 @@ namespace MPF.Core.Modules.Redumper { string? line = sr.ReadLine()?.TrimStart(); if (line?.StartsWith("disc write offset") == true) - return line.Substring("disc write offset: ".Length).Trim(); + return line["disc write offset: ".Length..].Trim(); } // We couldn't detect it then diff --git a/MPF.Core/Modules/UmdImageCreator/Parameters.cs b/MPF.Core/Modules/UmdImageCreator/Parameters.cs index a578c40b..1b5686ec 100644 --- a/MPF.Core/Modules/UmdImageCreator/Parameters.cs +++ b/MPF.Core/Modules/UmdImageCreator/Parameters.cs @@ -102,7 +102,7 @@ namespace MPF.Core.Modules.UmdImageCreator // Fill in any artifacts that exist, Base64-encoded, if we need to if (includeArtifacts) { - info.Artifacts ??= new Dictionary(); + info.Artifacts ??= []; if (File.Exists(basePath + "_disc.txt")) info.Artifacts["disc"] = GetBase64(GetFullFile(basePath + "_disc.txt")) ?? string.Empty; @@ -203,7 +203,7 @@ namespace MPF.Core.Modules.UmdImageCreator break; if (line.StartsWith("TITLE") && title == null) - title = line.Substring("TITLE: ".Length); + title = line["TITLE: ".Length..]; else if (line.StartsWith("DISC_VERSION") && umdversion == null) umdversion = line.Split(' ')[1]; else if (line.StartsWith("pspUmdTypes")) diff --git a/MPF.Core/SubmissionInfoTool.cs b/MPF.Core/SubmissionInfoTool.cs index 8cfdc97a..6eeeb204 100644 --- a/MPF.Core/SubmissionInfoTool.cs +++ b/MPF.Core/SubmissionInfoTool.cs @@ -273,8 +273,8 @@ namespace MPF.Core info.DumpingInfo ??= new DumpingInfoSection(); // Ensure special dictionaries - info.CommonDiscInfo.CommentsSpecialFields ??= new Dictionary(); - info.CommonDiscInfo.ContentsSpecialFields ??= new Dictionary(); + info.CommonDiscInfo.CommentsSpecialFields ??= []; + info.CommonDiscInfo.ContentsSpecialFields ??= []; return info; } @@ -496,7 +496,7 @@ namespace MPF.Core var (protectionString, fullProtections) = await InfoTool.GetCopyProtection(drive, options, protectionProgress); info.CopyProtection!.Protection = protectionString; - info.CopyProtection.FullProtections = fullProtections as Dictionary?> ?? new Dictionary?>(); + info.CopyProtection.FullProtections = fullProtections as Dictionary?> ?? []; resultProgress?.Report(Result.Success("Copy protection scan complete!")); break; @@ -668,7 +668,7 @@ namespace MPF.Core break; case RedumpSystem.SonyPlayStation2: - info.CommonDiscInfo!.LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu }; + info.CommonDiscInfo!.LanguageSelection = [LanguageSelection.BiosSettings, LanguageSelection.LanguageSelector, LanguageSelection.OptionsMenu]; break; case RedumpSystem.SonyPlayStation3: @@ -734,7 +734,7 @@ namespace MPF.Core int firstParenLocation = title.IndexOf(" ("); if (firstParenLocation >= 0) { - info.CommonDiscInfo!.Title = title.Substring(0, firstParenLocation); + info.CommonDiscInfo!.Title = title[..firstParenLocation]; var subMatches = Constants.DiscNumberLetterRegex.Matches(title); foreach (Match subMatch in subMatches.Cast()) { @@ -837,7 +837,7 @@ namespace MPF.Core tempDumpers.Add(WebUtility.HtmlDecode(submatch.Groups[1].Value)); } - info.DumpersAndStatus.Dumpers = tempDumpers.ToArray(); + info.DumpersAndStatus.Dumpers = [.. tempDumpers]; } // TODO: Unify handling of fields that can include site codes (Comments/Contents) @@ -1093,7 +1093,7 @@ namespace MPF.Core // Set the current dumper based on username info.DumpersAndStatus ??= new DumpersAndStatusSection(); info.DumpersAndStatus.Dumpers = [options.RedumpUsername!]; - info.PartiallyMatchedIDs = new List(); + info.PartiallyMatchedIDs = []; // Login to Redump #if NETFRAMEWORK @@ -1122,11 +1122,7 @@ namespace MPF.Core resultProgress?.Report(Result.Success("Finding disc matches on Redump...")); var splitData = info.TracksAndWriteOffsets?.ClrMameProData?.TrimEnd('\n')?.Split('\n'); int trackCount = splitData?.Length ?? 0; -#if NET40 || NET452 foreach (string hashData in splitData ?? []) -#else - foreach (string hashData in splitData ?? Array.Empty()) -#endif { // Catch any errant blank lines if (string.IsNullOrWhiteSpace(hashData)) @@ -1165,7 +1161,7 @@ namespace MPF.Core // If no tracks were found, remove all fully matched IDs found so far else { - fullyMatchedIDs = new List(); + fullyMatchedIDs = []; } } @@ -1185,15 +1181,12 @@ namespace MPF.Core // If no tracks were found, remove all fully matched IDs found so far else { - fullyMatchedIDs = new List(); + fullyMatchedIDs = []; } } // Make sure we only have unique IDs - info.PartiallyMatchedIDs = info.PartiallyMatchedIDs - .Distinct() - .OrderBy(id => id) - .ToList(); + info.PartiallyMatchedIDs = [.. info.PartiallyMatchedIDs.Distinct().OrderBy(id => id)]; resultProgress?.Report(Result.Success("Match finding complete! " + (fullyMatchedIDs != null && fullyMatchedIDs.Count > 0 ? "Fully Matched IDs: " + string.Join(",", fullyMatchedIDs) @@ -1496,7 +1489,7 @@ namespace MPF.Core } // Format the universal hash for finding within the comments - universalHash = $"{universalHash.Substring(0, universalHash.Length - 1)}/comments/only"; + universalHash = $"{universalHash[..^1]}/comments/only"; // Get all matching IDs for the hash var newIds = await ListSearchResults(wc, universalHash, filterForwardSlashes: false); diff --git a/MPF.Core/UI/ViewModels/MainViewModel.cs b/MPF.Core/UI/ViewModels/MainViewModel.cs index 4425434f..dee004b1 100644 --- a/MPF.Core/UI/ViewModels/MainViewModel.cs +++ b/MPF.Core/UI/ViewModels/MainViewModel.cs @@ -495,14 +495,14 @@ namespace MPF.Core.UI.ViewModels _options = OptionsLoader.LoadFromConfig(); // Added to clear warnings, all are set externally - _drives = new List(); - _driveSpeeds = new List(); - _internalPrograms = new List>(); + _drives = []; + _driveSpeeds = []; + _internalPrograms = []; _outputPath = string.Empty; _parameters = string.Empty; _startStopButtonText = string.Empty; _status = string.Empty; - _systems = new List(); + _systems = []; OptionsMenuItemEnabled = true; SystemTypeComboBoxEnabled = true; @@ -517,9 +517,9 @@ namespace MPF.Core.UI.ViewModels EnableParametersCheckBoxEnabled = true; LogPanelExpanded = _options.OpenLogWindowAtStartup; - MediaTypes = new List>(); + MediaTypes = []; Systems = RedumpSystemComboBoxItem.GenerateElements().ToList(); - InternalPrograms = new List>(); + InternalPrograms = []; } /// @@ -764,7 +764,7 @@ namespace MPF.Core.UI.ViewModels { SchemaVersion = 1, FullyMatchedID = 3, - PartiallyMatchedIDs = new List { 0, 1, 2, 3 }, + PartiallyMatchedIDs = [0, 1, 2, 3], Added = DateTime.UtcNow, LastModified = DateTime.UtcNow, @@ -778,8 +778,8 @@ namespace MPF.Core.UI.ViewModels DiscTitle = "Install Disc", Category = DiscCategory.Games, Region = Region.World, - Languages = new Language?[] { Language.English, Language.Spanish, Language.French }, - LanguageSelection = new LanguageSelection?[] { LanguageSelection.BiosSettings }, + Languages = [Language.English, Language.Spanish, Language.French], + LanguageSelection = [LanguageSelection.BiosSettings], Serial = "Disc Serial", Layer0MasteringRing = "L0 Mastering Ring", Layer0MasteringSID = "L0 Mastering SID", @@ -817,7 +817,7 @@ namespace MPF.Core.UI.ViewModels { Version = "Original", VersionDatfile = "Alt", - CommonEditions = new string[] { "Taikenban" }, + CommonEditions = ["Taikenban"], OtherEditions = "Rerelease", }, @@ -855,7 +855,7 @@ namespace MPF.Core.UI.ViewModels DumpersAndStatus = new DumpersAndStatusSection() { Status = DumpStatus.TwoOrMoreGreen, - Dumpers = new string[] { "Dumper1", "Dumper2" }, + Dumpers = ["Dumper1", "Dumper2"], OtherDumpers = "Dumper3", }, @@ -863,7 +863,7 @@ namespace MPF.Core.UI.ViewModels { ClrMameProData = "Datfile", Cuesheet = "Cuesheet", - CommonWriteOffsets = new int[] { 0, 12, -12 }, + CommonWriteOffsets = [0, 12, -12], OtherWriteOffsets = "-2", }, diff --git a/MPF.Core/UI/ViewModels/OptionsViewModel.cs b/MPF.Core/UI/ViewModels/OptionsViewModel.cs index 3b192037..2436f504 100644 --- a/MPF.Core/UI/ViewModels/OptionsViewModel.cs +++ b/MPF.Core/UI/ViewModels/OptionsViewModel.cs @@ -8,7 +8,10 @@ using SabreTools.RedumpLib.Web; namespace MPF.Core.UI.ViewModels { - public class OptionsViewModel : INotifyPropertyChanged + /// + /// Constructor + /// + public class OptionsViewModel(Options baseOptions) : INotifyPropertyChanged { #region Fields @@ -29,7 +32,7 @@ namespace MPF.Core.UI.ViewModels /// /// Current set of options /// - public Options Options { get; } + public Options Options { get; } = new Options(baseOptions); /// /// Flag for if settings were saved or not @@ -55,14 +58,6 @@ namespace MPF.Core.UI.ViewModels #endregion - /// - /// Constructor - /// - public OptionsViewModel(Options baseOptions) - { - Options = new Options(baseOptions); - } - #region Population /// diff --git a/MPF.UI.Core/MPF.UI.Core.csproj b/MPF.UI.Core/MPF.UI.Core.csproj index 01bfc51e..11d1b9d2 100644 --- a/MPF.UI.Core/MPF.UI.Core.csproj +++ b/MPF.UI.Core/MPF.UI.Core.csproj @@ -6,6 +6,7 @@ win-x86;win-x64 latest enable + true true 3.0.0 true diff --git a/MPF.UI.Core/Windows/OptionsWindow.xaml.cs b/MPF.UI.Core/Windows/OptionsWindow.xaml.cs index 9267c3c0..6602990f 100644 --- a/MPF.UI.Core/Windows/OptionsWindow.xaml.cs +++ b/MPF.UI.Core/Windows/OptionsWindow.xaml.cs @@ -65,7 +65,7 @@ namespace MPF.UI.Core.Windows return; // Strips button prefix to obtain the setting name - string pathSettingName = button.Name.Substring(0, button.Name.IndexOf("Button")); + string pathSettingName = button.Name[..button.Name.IndexOf("Button")]; // TODO: hack for now, then we'll see bool shouldBrowseForPath = pathSettingName == "DefaultOutputPath";