diff --git a/RombaSharp/Program.cs b/RombaSharp/Program.cs index 5e228339..e8bda3d7 100644 --- a/RombaSharp/Program.cs +++ b/RombaSharp/Program.cs @@ -30,7 +30,7 @@ namespace RombaSharp /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -52,7 +52,7 @@ namespace RombaSharp // Credits take precidence over all if ((new List(args)).Contains("--credits")) { - _help.OutputCredits(); + FeatureSet.OutputCredits(); LoggerImpl.Close(); return; } @@ -174,7 +174,7 @@ namespace RombaSharp { // Create and add the header to the Help object string barrier = "-----------------------------------------"; - List helpHeader = new List() + List helpHeader = new() { "RombaSharp - C# port of the Romba rom management tool", barrier, @@ -183,7 +183,7 @@ namespace RombaSharp }; // Create the base help object with header - FeatureSet help = new FeatureSet(helpHeader); + FeatureSet help = new(helpHeader); // Add all of the features help.Add(new DisplayHelp()); diff --git a/SabreTools.Core/ConcurrentList.cs b/SabreTools.Core/ConcurrentList.cs index e3dd1da3..b1c2b484 100644 --- a/SabreTools.Core/ConcurrentList.cs +++ b/SabreTools.Core/ConcurrentList.cs @@ -9,8 +9,8 @@ namespace SabreTools.Core /// public class ConcurrentList : ICollection, IEnumerable, IEnumerable, IList, IReadOnlyCollection, IReadOnlyList, ICollection, IList { - private List _list = new List(); - private object _lock = new object(); + private List _list = new(); + private readonly object _lock = new(); public T this[int index] { diff --git a/SabreTools.Core/Globals.cs b/SabreTools.Core/Globals.cs index d99bcbcf..0566baba 100644 --- a/SabreTools.Core/Globals.cs +++ b/SabreTools.Core/Globals.cs @@ -18,7 +18,7 @@ namespace SabreTools.Core /// /// ParallelOptions object for use in parallel operations /// - public static ParallelOptions ParallelOptions => new ParallelOptions() + public static ParallelOptions ParallelOptions => new() { MaxDegreeOfParallelism = MaxThreads }; diff --git a/SabreTools.Core/NaturalSort/NaturalComparer.cs b/SabreTools.Core/NaturalSort/NaturalComparer.cs index 43bfaa60..c08cbd93 100644 --- a/SabreTools.Core/NaturalSort/NaturalComparer.cs +++ b/SabreTools.Core/NaturalSort/NaturalComparer.cs @@ -25,7 +25,7 @@ namespace NaturalSort table = new Dictionary(); } - public void Dispose() + public void Dispose() { table.Clear(); table = null; diff --git a/SabreTools.Core/Tools/Converters.cs b/SabreTools.Core/Tools/Converters.cs index bd945117..a37e3f3c 100644 --- a/SabreTools.Core/Tools/Converters.cs +++ b/SabreTools.Core/Tools/Converters.cs @@ -12,7 +12,7 @@ namespace SabreTools.Core.Tools /// public static List AsDatItemFields(this Hash hash) { - List fields = new List(); + List fields = new(); if (hash.HasFlag(Hash.CRC)) fields.Add(DatItemField.CRC); @@ -106,199 +106,161 @@ namespace SabreTools.Core.Tools .Replace('-', '_') .Replace('.', '_'); - switch (headerInput) + return headerInput switch { #region Common - case "file": - case "filename": - case "file_name": - return DatHeaderField.FileName; + "file" => DatHeaderField.FileName, + "filename" => DatHeaderField.FileName, + "file_name" => DatHeaderField.FileName, - case "dat": - case "datname": - case "dat_name": - case "internalname": - case "internal_name": - return DatHeaderField.Name; + "dat" => DatHeaderField.Name, + "datname" => DatHeaderField.Name, + "dat_name" => DatHeaderField.Name, + "internalname" => DatHeaderField.Name, + "internal_name" => DatHeaderField.Name, - case "desc": - case "description": - return DatHeaderField.Description; + "desc" => DatHeaderField.Description, + "description" => DatHeaderField.Description, - case "root": - case "rootdir": - case "root_dir": - case "rootdirectory": - case "root_directory": - return DatHeaderField.RootDir; + "root" => DatHeaderField.RootDir, + "rootdir" => DatHeaderField.RootDir, + "root_dir" => DatHeaderField.RootDir, + "rootdirectory" => DatHeaderField.RootDir, + "root_directory" => DatHeaderField.RootDir, - case "category": - return DatHeaderField.Category; + "category" => DatHeaderField.Category, - case "version": - return DatHeaderField.Version; + "version" => DatHeaderField.Version, - case "date": - case "timestamp": - case "time_stamp": - return DatHeaderField.Date; + "date" => DatHeaderField.Date, + "timestamp" => DatHeaderField.Date, + "time_stamp" => DatHeaderField.Date, - case "author": - return DatHeaderField.Author; + "author" => DatHeaderField.Author, - case "email": - case "e_mail": - return DatHeaderField.Email; + "email" => DatHeaderField.Email, + "e_mail" => DatHeaderField.Email, - case "homepage": - case "home_page": - return DatHeaderField.Homepage; + "homepage" => DatHeaderField.Homepage, + "home_page" => DatHeaderField.Homepage, - case "url": - return DatHeaderField.Url; + "url" => DatHeaderField.Url, - case "comment": - return DatHeaderField.Comment; + "comment" => DatHeaderField.Comment, - case "header": - case "headerskipper": - case "header_skipper": - case "skipper": - return DatHeaderField.HeaderSkipper; + "header" => DatHeaderField.HeaderSkipper, + "headerskipper" => DatHeaderField.HeaderSkipper, + "header_skipper" => DatHeaderField.HeaderSkipper, + "skipper" => DatHeaderField.HeaderSkipper, - case "dattype": - case "type": - case "superdat": - return DatHeaderField.Type; + "dattype" => DatHeaderField.Type, + "type" => DatHeaderField.Type, + "superdat" => DatHeaderField.Type, - case "forcemerging": - case "force_merging": - return DatHeaderField.ForceMerging; + "forcemerging" => DatHeaderField.ForceMerging, + "force_merging" => DatHeaderField.ForceMerging, - case "forcenodump": - case "force_nodump": - return DatHeaderField.ForceNodump; + "forcenodump" => DatHeaderField.ForceNodump, + "force_nodump" => DatHeaderField.ForceNodump, - case "forcepacking": - case "force_packing": - return DatHeaderField.ForcePacking; + "forcepacking" => DatHeaderField.ForcePacking, + "force_packing" => DatHeaderField.ForcePacking, #endregion #region ListXML - case "debug": - return DatHeaderField.Debug; + "debug" => DatHeaderField.Debug, - case "mameconfig": - case "mame_config": - return DatHeaderField.MameConfig; + "mameconfig" => DatHeaderField.MameConfig, + "mame_config" => DatHeaderField.MameConfig, #endregion #region Logiqx - case "id": - case "nointroid": - case "no_intro_id": - return DatHeaderField.NoIntroID; + "id" => DatHeaderField.NoIntroID, + "nointroid" => DatHeaderField.NoIntroID, + "no_intro_id" => DatHeaderField.NoIntroID, - case "build": - return DatHeaderField.Build; + "build" => DatHeaderField.Build, - case "rommode": - case "rom_mode": - return DatHeaderField.RomMode; + "rommode" => DatHeaderField.RomMode, + "rom_mode" => DatHeaderField.RomMode, - case "biosmode": - case "bios_mode": - return DatHeaderField.BiosMode; + "biosmode" => DatHeaderField.BiosMode, + "bios_mode" => DatHeaderField.BiosMode, - case "samplemode": - case "sample_mode": - return DatHeaderField.SampleMode; + "samplemode" => DatHeaderField.SampleMode, + "sample_mode" => DatHeaderField.SampleMode, - case "lockrommode": - case "lockrom_mode": - case "lock_rommode": - case "lock_rom_mode": - return DatHeaderField.LockRomMode; + "lockrommode" => DatHeaderField.LockRomMode, + "lockrom_mode" => DatHeaderField.LockRomMode, + "lock_rommode" => DatHeaderField.LockRomMode, + "lock_rom_mode" => DatHeaderField.LockRomMode, - case "lockbiosmode": - case "lockbios_mode": - case "lock_biosmode": - case "lock_bios_mode": - return DatHeaderField.LockBiosMode; + "lockbiosmode" => DatHeaderField.LockBiosMode, + "lockbios_mode" => DatHeaderField.LockBiosMode, + "lock_biosmode" => DatHeaderField.LockBiosMode, + "lock_bios_mode" => DatHeaderField.LockBiosMode, - case "locksamplemode": - case "locksample_mode": - case "lock_samplemode": - case "lock_sample_mode": - return DatHeaderField.LockSampleMode; + "locksamplemode" => DatHeaderField.LockSampleMode, + "locksample_mode" => DatHeaderField.LockSampleMode, + "lock_samplemode" => DatHeaderField.LockSampleMode, + "lock_sample_mode" => DatHeaderField.LockSampleMode, #endregion #region OfflineList - case "system": - case "plugin": // Used with RomCenter - return DatHeaderField.System; + "system" => DatHeaderField.System, + "plugin" => DatHeaderField.System, // Used with RomCenter - case "screenshotwidth": - case "screenshotswidth": - case "screenshot_width": - case "screenshots_width": - return DatHeaderField.ScreenshotsWidth; + "screenshotwidth" => DatHeaderField.ScreenshotsWidth, + "screenshotswidth" => DatHeaderField.ScreenshotsWidth, + "screenshot_width" => DatHeaderField.ScreenshotsWidth, + "screenshots_width" => DatHeaderField.ScreenshotsWidth, - case "screenshotheight": - case "screenshotsheight": - case "screenshot_height": - case "screenshots_height": - return DatHeaderField.ScreenshotsHeight; + "screenshotheight" => DatHeaderField.ScreenshotsHeight, + "screenshotsheight" => DatHeaderField.ScreenshotsHeight, + "screenshot_height" => DatHeaderField.ScreenshotsHeight, + "screenshots_height" => DatHeaderField.ScreenshotsHeight, - case "info_name": - case "infos_name": - return DatHeaderField.Info_Name; + "info_name" => DatHeaderField.Info_Name, + "infos_name" => DatHeaderField.Info_Name, - case "info_visible": - case "infos_visible": - return DatHeaderField.Info_Visible; + "info_visible" => DatHeaderField.Info_Visible, + "infos_visible" => DatHeaderField.Info_Visible, - case "info_isnamingoption": - case "info_is_naming_option": - case "infos_isnamingoption": - case "infos_is_naming_option": - return DatHeaderField.Info_IsNamingOption; + "info_isnamingoption" => DatHeaderField.Info_IsNamingOption, + "info_is_naming_option" => DatHeaderField.Info_IsNamingOption, + "infos_isnamingoption" => DatHeaderField.Info_IsNamingOption, + "infos_is_naming_option" => DatHeaderField.Info_IsNamingOption, - case "info_default": - case "infos_default": - return DatHeaderField.Info_Default; + "info_default" => DatHeaderField.Info_Default, + "infos_default" => DatHeaderField.Info_Default, - case "canopen": - case "can_open": - return DatHeaderField.CanOpen; + "canopen" => DatHeaderField.CanOpen, + "can_open" => DatHeaderField.CanOpen, - case "romtitle": - case "rom_title": - return DatHeaderField.RomTitle; + "romtitle" => DatHeaderField.RomTitle, + "rom_title" => DatHeaderField.RomTitle, #endregion #region RomCenter - case "rcversion": - case "rc_version": - case "romcenterversion": - case "romcenter_version": - case "rom_center_version": - return DatHeaderField.RomCenterVersion; + "rcversion" => DatHeaderField.RomCenterVersion, + "rc_version" => DatHeaderField.RomCenterVersion, + "romcenterversion" => DatHeaderField.RomCenterVersion, + "romcenter_version" => DatHeaderField.RomCenterVersion, + "rom_center_version" => DatHeaderField.RomCenterVersion, #endregion - default: - return DatHeaderField.NULL; - } + _ => DatHeaderField.NULL, + }; } /// @@ -328,12 +290,11 @@ namespace SabreTools.Core.Tools .Replace('-', '_') .Replace('.', '_'); - switch (itemInput) + return itemInput switch { #region Common - case "type": - return DatItemField.Type; + "type" => DatItemField.Type, #endregion @@ -341,472 +302,447 @@ namespace SabreTools.Core.Tools #region Actionable - // Rom - case "name": - return DatItemField.Name; + #region Rom - case "bios": - return DatItemField.Bios; + "name" => DatItemField.Name, - case "size": - return DatItemField.Size; + "bios" => DatItemField.Bios, - case "crc": - case "crc32": - return DatItemField.CRC; + "size" => DatItemField.Size, - case "md5": - case "md5_hash": - return DatItemField.MD5; + "crc" => DatItemField.CRC, + "crc32" => DatItemField.CRC, - case "sha1": - case "sha_1": - case "sha1hash": - case "sha1_hash": - case "sha_1hash": - case "sha_1_hash": - return DatItemField.SHA1; + "md5" => DatItemField.MD5, + "md5hash" => DatItemField.MD5, + "md5_hash" => DatItemField.MD5, - case "sha256": - case "sha_256": - case "sha256hash": - case "sha256_hash": - case "sha_256hash": - case "sha_256_hash": - return DatItemField.SHA256; + "sha1" => DatItemField.SHA1, + "sha_1" => DatItemField.SHA1, + "sha1hash" => DatItemField.SHA1, + "sha1_hash" => DatItemField.SHA1, + "sha_1hash" => DatItemField.SHA1, + "sha_1_hash" => DatItemField.SHA1, - case "sha384": - case "sha_384": - case "sha384hash": - case "sha384_hash": - case "sha_384hash": - case "sha_384_hash": - return DatItemField.SHA384; + "sha256" => DatItemField.SHA256, + "sha_256" => DatItemField.SHA256, + "sha256hash" => DatItemField.SHA256, + "sha256_hash" => DatItemField.SHA256, + "sha_256hash" => DatItemField.SHA256, + "sha_256_hash" => DatItemField.SHA256, - case "sha512": - case "sha_512": - case "sha512hash": - case "sha512_hash": - case "sha_512hash": - case "sha_512_hash": - return DatItemField.SHA512; - - case "spamsum": - case "spam_sum": - return DatItemField.SpamSum; + "sha384" => DatItemField.SHA384, + "sha_384" => DatItemField.SHA384, + "sha384hash" => DatItemField.SHA384, + "sha384_hash" => DatItemField.SHA384, + "sha_384hash" => DatItemField.SHA384, + "sha_384_hash" => DatItemField.SHA384, - case "merge": - case "mergetag": - case "merge_tag": - return DatItemField.Merge; + "sha512" => DatItemField.SHA512, + "sha_512" => DatItemField.SHA512, + "sha512hash" => DatItemField.SHA512, + "sha512_hash" => DatItemField.SHA512, + "sha_512hash" => DatItemField.SHA512, + "sha_512_hash" => DatItemField.SHA512, - case "region": - return DatItemField.Region; + "spamsum" => DatItemField.SpamSum, + "spam_sum" => DatItemField.SpamSum, - case "offset": - return DatItemField.Offset; + "merge" => DatItemField.Merge, + "mergetag" => DatItemField.Merge, + "merge_tag" => DatItemField.Merge, - case "date": - return DatItemField.Date; + "region" => DatItemField.Region, - case "status": - return DatItemField.Status; + "offset" => DatItemField.Offset, - case "optional": - return DatItemField.Optional; + "date" => DatItemField.Date, - case "inverted": - return DatItemField.Inverted; + "status" => DatItemField.Status, - // Rom (Archive.org) - case "ado-source": - case "ado source": - return DatItemField.ArchiveDotOrgSource; + "optional" => DatItemField.Optional, - case "ado-format": - case "ado format": - return DatItemField.ArchiveDotOrgFormat; + "inverted" => DatItemField.Inverted, - case "original-filename": - case "original filename": - return DatItemField.OriginalFilename; + #endregion - case "rotation": - return DatItemField.Rotation; + #region Rom (Archive.org) - case "summation": - return DatItemField.Summation; + "ado_source" => DatItemField.ArchiveDotOrgSource, - // Rom (AttractMode) - case "altname": - case "alt name": - case "alt-name": - case "altromname": - case "alt romname": - case "alt-romname": - return DatItemField.AltName; + "ado_format" => DatItemField.ArchiveDotOrgFormat, - case "alttitle": - case "alt title": - case "alt-title": - case "altromtitle": - case "alt romtitle": - case "alt-romtitle": - return DatItemField.AltTitle; + "original_filename" => DatItemField.OriginalFilename, - // Rom (Logiqx) - case "mia": - return DatItemField.MIA; + "rotation" => DatItemField.Rotation, - // Rom (OpenMSX) - case "original": - return DatItemField.Original; + "summation" => DatItemField.Summation, - case "subtype": - case "sub_type": - case "openmsxsubtype": - case "openmsx_subtype": - return DatItemField.OpenMSXSubType; + #endregion - case "openmsxtype": - case "openmsx_type": - return DatItemField.OpenMSXType; + #region Rom (AttractMode) - case "remark": - return DatItemField.Remark; + "altname" => DatItemField.AltName, + "alt_name" => DatItemField.AltName, + "altromname" => DatItemField.AltName, + "alt_romname" => DatItemField.AltName, + "alt_rom_name" => DatItemField.AltName, - case "boot": - return DatItemField.Boot; + "alttitle" => DatItemField.AltTitle, + "alt_title" => DatItemField.AltTitle, + "altromtitle" => DatItemField.AltTitle, + "alt_romtitle" => DatItemField.AltTitle, + "alt_rom_title" => DatItemField.AltTitle, - // Rom (SoftwareList) - case "areaname": - case "area_name": - return DatItemField.AreaName; + #endregion - case "areasize": - case "area_size": - return DatItemField.AreaSize; + #region Rom (Logiqx) - case "areawidth": - case "area_width": - return DatItemField.AreaWidth; + "mia" => DatItemField.MIA, - case "areaendinanness": - case "area_endianness": - return DatItemField.AreaEndianness; + #endregion - case "loadflag": - case "load_flag": - return DatItemField.LoadFlag; + #region Rom (OpenMSX) - case "partname": - case "part_name": - return DatItemField.Part_Name; + "original" => DatItemField.Original, - case "partinterface": - case "part_interface": - return DatItemField.Part_Interface; + "subtype" => DatItemField.OpenMSXSubType, + "sub_type" => DatItemField.OpenMSXSubType, + "openmsxsubtype" => DatItemField.OpenMSXSubType, + "openmsx_subtype" => DatItemField.OpenMSXSubType, + "openmsx_sub_type" => DatItemField.OpenMSXSubType, - case "part_feature_name": - return DatItemField.Part_Feature_Name; + "openmsxtype" => DatItemField.OpenMSXType, + "openmsx_type" => DatItemField.OpenMSXType, - case "part_feature_value": - return DatItemField.Part_Feature_Value; + "remark" => DatItemField.Remark, - case "value": - return DatItemField.Value; + "boot" => DatItemField.Boot, - // Disk - case "index": - return DatItemField.Index; + #endregion - case "writable": - return DatItemField.Writable; + #region Rom (SoftwareList) + + "areaname" => DatItemField.AreaName, + "area_name" => DatItemField.AreaName, + + "areasize" => DatItemField.AreaSize, + "area_size" => DatItemField.AreaSize, + + "areawidth" => DatItemField.AreaWidth, + "area_width" => DatItemField.AreaWidth, + + "areaendinanness" => DatItemField.AreaEndianness, + "area_endianness" => DatItemField.AreaEndianness, + + "loadflag" => DatItemField.LoadFlag, + "load_flag" => DatItemField.LoadFlag, + + "partname" => DatItemField.Part_Name, + "part_name" => DatItemField.Part_Name, + + "partinterface" => DatItemField.Part_Interface, + "part_interface" => DatItemField.Part_Interface, + + "part_feature_name" => DatItemField.Part_Feature_Name, + + "part_feature_value" => DatItemField.Part_Feature_Value, + + "value" => DatItemField.Value, + + #endregion + + #region Disk + + "index" => DatItemField.Index, + + "writable" => DatItemField.Writable, + + #endregion #endregion #region Auxiliary - // Adjuster - case "default": - return DatItemField.Default; + #region Adjuster - // Analog - case "analog_mask": - return DatItemField.Analog_Mask; + "default" => DatItemField.Default, - // Archive - case "number": - return DatItemField.Number; + #endregion - case "clone": - return DatItemField.Clone; + #region Analog - case "regparent": - case "reg_parent": - return DatItemField.RegParent; + "analog_mask" => DatItemField.Analog_Mask, - case "languages": - return DatItemField.Languages; + #endregion - case "devstatus": - case "dev_status": - return DatItemField.DevStatus; + #region Archive - case "physical": - return DatItemField.Physical; + "number" => DatItemField.Number, - case "complete": - return DatItemField.Complete; + "clone" => DatItemField.Clone, - case "categories": - return DatItemField.Categories; + "regparent" => DatItemField.RegParent, + "reg_parent" => DatItemField.RegParent, - // BiosSet - case "description": - case "biosdescription": - case "bios_description": - return DatItemField.Description; + "languages" => DatItemField.Languages, - // Chip - case "tag": - return DatItemField.Tag; + "devstatus" => DatItemField.DevStatus, + "dev_status" => DatItemField.DevStatus, - case "chiptype": - case "chip_type": - return DatItemField.ChipType; + "physical" => DatItemField.Physical, - case "clock": - return DatItemField.Clock; + "complete" => DatItemField.Complete, - // Condition - case "mask": - return DatItemField.Mask; + "categories" => DatItemField.Categories, - case "relation": - return DatItemField.Relation; + #endregion - case "condition_tag": - return DatItemField.Condition_Tag; + #region BiosSet - case "condition_mask": - return DatItemField.Condition_Mask; + "description" => DatItemField.Description, + "biosdescription" => DatItemField.Description, + "bios_description" => DatItemField.Description, - case "condition_relation": - return DatItemField.Condition_Relation; + #endregion - case "condition_value": - return DatItemField.Condition_Value; + #region Chip - // Control - case "control_type": - return DatItemField.Control_Type; + "tag" => DatItemField.Tag, - case "control_player": - return DatItemField.Control_Player; + "chiptype" => DatItemField.ChipType, + "chip_type" => DatItemField.ChipType, - case "control_buttons": - return DatItemField.Control_Buttons; + "clock" => DatItemField.Clock, - case "control_reqbuttons": - return DatItemField.Control_RequiredButtons; + #endregion - case "control_minimum": - return DatItemField.Control_Minimum; + #region Condition - case "control_maximum": - return DatItemField.Control_Maximum; + "mask" => DatItemField.Mask, - case "control_sensitivity": - return DatItemField.Control_Sensitivity; + "relation" => DatItemField.Relation, - case "control_keydelta": - return DatItemField.Control_KeyDelta; + "condition_tag" => DatItemField.Condition_Tag, - case "control_reverse": - return DatItemField.Control_Reverse; + "condition_mask" => DatItemField.Condition_Mask, - case "control_ways": - return DatItemField.Control_Ways; + "condition_relation" => DatItemField.Condition_Relation, - case "control_ways2": - return DatItemField.Control_Ways2; + "condition_value" => DatItemField.Condition_Value, - case "control_ways3": - return DatItemField.Control_Ways3; + #endregion - // Device - case "devicetype": - return DatItemField.DeviceType; + #region Control - case "fixedimage": - return DatItemField.FixedImage; + "control_type" => DatItemField.Control_Type, - case "mandatory": - return DatItemField.Mandatory; + "control_player" => DatItemField.Control_Player, - case "interface": - return DatItemField.Interface; + "control_buttons" => DatItemField.Control_Buttons, - // Display - case "displaytype": - return DatItemField.DisplayType; + "control_reqbuttons" => DatItemField.Control_RequiredButtons, + "control_req_buttons" => DatItemField.Control_RequiredButtons, - case "rotate": - return DatItemField.Rotate; + "control_minimum" => DatItemField.Control_Minimum, - case "flipx": - return DatItemField.FlipX; + "control_maximum" => DatItemField.Control_Maximum, - case "width": - return DatItemField.Width; + "control_sensitivity" => DatItemField.Control_Sensitivity, - case "height": - return DatItemField.Height; + "control_keydelta" => DatItemField.Control_KeyDelta, + "control_key_delta" => DatItemField.Control_KeyDelta, - case "refresh": - return DatItemField.Refresh; + "control_reverse" => DatItemField.Control_Reverse, - case "pixclock": - return DatItemField.PixClock; + "control_ways" => DatItemField.Control_Ways, - case "htotal": - return DatItemField.HTotal; + "control_ways2" => DatItemField.Control_Ways2, - case "hbend": - return DatItemField.HBEnd; + "control_ways3" => DatItemField.Control_Ways3, - case "hbstart": - return DatItemField.HBStart; + #endregion - case "vtotal": - return DatItemField.VTotal; + #region Device - case "vbend": - return DatItemField.VBEnd; + "devicetype" => DatItemField.DeviceType, + "device_type" => DatItemField.DeviceType, - case "vbstart": - return DatItemField.VBStart; + "fixedimage" => DatItemField.FixedImage, + "fixed_image" => DatItemField.FixedImage, - // Driver - case "supportstatus": - return DatItemField.SupportStatus; + "mandatory" => DatItemField.Mandatory, - case "emulationstatus": - return DatItemField.EmulationStatus; + "interface" => DatItemField.Interface, - case "cocktailstatus": - return DatItemField.CocktailStatus; + #endregion - case "savestatestatus": - return DatItemField.SaveStateStatus; + #region Display - case "requiresartwork": - return DatItemField.RequiresArtwork; + "displaytype" => DatItemField.DisplayType, + "display_type" => DatItemField.DisplayType, - case "unofficial": - return DatItemField.Unofficial; + "rotate" => DatItemField.Rotate, - case "nosoundhardware": - return DatItemField.NoSoundHardware; + "flipx" => DatItemField.FlipX, - case "incomplete": - return DatItemField.Incomplete; + "width" => DatItemField.Width, - // Extension - case "extension_name": - return DatItemField.Extension_Name; + "height" => DatItemField.Height, - // Feature - case "featuretype": - return DatItemField.FeatureType; + "refresh" => DatItemField.Refresh, - case "featurestatus": - return DatItemField.FeatureStatus; + "pixclock" => DatItemField.PixClock, + "pix_clock" => DatItemField.PixClock, - case "featureoverall": - return DatItemField.FeatureOverall; + "htotal" => DatItemField.HTotal, - // Input - case "service": - return DatItemField.Service; + "hbend" => DatItemField.HBEnd, - case "tilt": - return DatItemField.Tilt; + "hbstart" => DatItemField.HBStart, - case "players": - return DatItemField.Players; + "vtotal" => DatItemField.VTotal, - case "coins": - return DatItemField.Coins; + "vbend" => DatItemField.VBEnd, - // Instance - case "instance_name": - return DatItemField.Instance_Name; + "vbstart" => DatItemField.VBStart, - case "instance_briefname": - return DatItemField.Instance_BriefName; + #endregion - // Location - case "location_name": - return DatItemField.Location_Name; + #region Driver - case "location_number": - return DatItemField.Location_Number; + "supportstatus" => DatItemField.SupportStatus, + "support_status" => DatItemField.SupportStatus, - case "location_inverted": - return DatItemField.Location_Inverted; + "emulationstatus" => DatItemField.EmulationStatus, + "emulation_status" => DatItemField.EmulationStatus, - // RamOption - case "content": - return DatItemField.Content; + "cocktailstatus" => DatItemField.CocktailStatus, + "cocktail_status" => DatItemField.CocktailStatus, - // Release - case "language": - return DatItemField.Language; + "savestatestatus" => DatItemField.SaveStateStatus, + "savestate_status" => DatItemField.SaveStateStatus, + "save_state_status" => DatItemField.SaveStateStatus, - // Setting - case "setting_name": - case "value_name": - return DatItemField.Setting_Name; + "requiresartwork" => DatItemField.RequiresArtwork, + "requires_artwork" => DatItemField.RequiresArtwork, - case "setting_value": - case "value_value": - return DatItemField.Setting_Value; + "unofficial" => DatItemField.Unofficial, - case "setting_default": - case "value_default": - return DatItemField.Setting_Default; + "nosoundhardware" => DatItemField.NoSoundHardware, + "no_sound_hardware" => DatItemField.NoSoundHardware, - // SlotOption - case "slotoption_name": - return DatItemField.SlotOption_Name; + "incomplete" => DatItemField.Incomplete, - case "slotoption_devicename": - return DatItemField.SlotOption_DeviceName; + #endregion - case "slotoption_default": - return DatItemField.SlotOption_Default; + #region Extension - // SoftwareList - case "softwareliststatus": - case "softwarelist_status": - return DatItemField.SoftwareListStatus; + "extension_name" => DatItemField.Extension_Name, - case "filter": - return DatItemField.Filter; + #endregion - // Sound - case "channels": - return DatItemField.Channels; + #region Feature + + "featuretype" => DatItemField.FeatureType, + "feature_type" => DatItemField.FeatureType, + + "featurestatus" => DatItemField.FeatureStatus, + "feature_status" => DatItemField.FeatureStatus, + + "featureoverall" => DatItemField.FeatureOverall, + "feature_overall" => DatItemField.FeatureOverall, + + #endregion + + #region Input + + "service" => DatItemField.Service, + + "tilt" => DatItemField.Tilt, + + "players" => DatItemField.Players, + + "coins" => DatItemField.Coins, + + #endregion + + #region Instance + + "instance_name" => DatItemField.Instance_Name, + + "instance_briefname" => DatItemField.Instance_BriefName, + "instance_brief_name" => DatItemField.Instance_BriefName, + + #endregion + + #region Location + + "location_name" => DatItemField.Location_Name, + + "location_number" => DatItemField.Location_Number, + + "location_inverted" => DatItemField.Location_Inverted, + + #endregion + + #region RamOption + + "content" => DatItemField.Content, + + #endregion + + #region Release + + "language" => DatItemField.Language, + + #endregion + + #region Setting + + "setting_name" => DatItemField.Setting_Name, + "value_name" => DatItemField.Setting_Name, + + "setting_value" => DatItemField.Setting_Value, + "value_value" => DatItemField.Setting_Value, + + "setting_default" => DatItemField.Setting_Default, + "value_default" => DatItemField.Setting_Default, + + #endregion + + #region SlotOption + + "slotoption_name" => DatItemField.SlotOption_Name, + + "slotoption_devicename" => DatItemField.SlotOption_DeviceName, + "slotoption_device_name" => DatItemField.SlotOption_DeviceName, + + "slotoption_default" => DatItemField.SlotOption_Default, + + #endregion + + #region SoftwareList + + "softwareliststatus" => DatItemField.SoftwareListStatus, + "softwarelist_status" => DatItemField.SoftwareListStatus, + + "filter" => DatItemField.Filter, + + #endregion + + #region Sound + + "channels" => DatItemField.Channels, + + #endregion #endregion #endregion // Item-Specific - default: - return DatItemField.NULL; - } + _ => DatItemField.NULL, + }; } /// @@ -958,6 +894,7 @@ namespace SabreTools.Core.Tools "control" => ItemType.Control, "dataarea" => ItemType.DataArea, "device" => ItemType.Device, + "deviceref" => ItemType.DeviceReference, "device_ref" => ItemType.DeviceReference, "dipswitch" => ItemType.DipSwitch, "disk" => ItemType.Disk, @@ -1065,181 +1002,144 @@ namespace SabreTools.Core.Tools .Replace('-', '_') .Replace('.', '_'); - switch (machineInput) + return machineInput switch { #region Common - case "name": - return MachineField.Name; + "name" => MachineField.Name, - case "comment": - case "extra": // Used with AttractMode - return MachineField.Comment; + "comment" => MachineField.Comment, + "extra" => MachineField.Comment, // Used with AttractMode - case "desc": - case "description": - return MachineField.Description; + "desc" => MachineField.Description, + "description" => MachineField.Description, - case "year": - return MachineField.Year; + "year" => MachineField.Year, - case "manufacturer": - return MachineField.Manufacturer; + "manufacturer" => MachineField.Manufacturer, - case "publisher": - return MachineField.Publisher; + "publisher" => MachineField.Publisher, - case "category": - return MachineField.Category; + "category" => MachineField.Category, - case "romof": - case "rom_of": - return MachineField.RomOf; + "romof" => MachineField.RomOf, + "rom_of" => MachineField.RomOf, - case "cloneof": - case "clone_of": - return MachineField.CloneOf; + "cloneof" => MachineField.CloneOf, + "clone_of" => MachineField.CloneOf, - case "sampleof": - case "sample_of": - return MachineField.SampleOf; - - case "type": - return MachineField.Type; + "sampleof" => MachineField.SampleOf, + "sample_of" => MachineField.SampleOf, + + "type" => MachineField.Type, #endregion #region AttractMode + + "players" => MachineField.Players, - case "players": - return MachineField.Players; + "rotation" => MachineField.Rotation, - case "rotation": - return MachineField.Rotation; + "control" => MachineField.Control, - case "control": - return MachineField.Control; + "amstatus" => MachineField.Status, + "am_status" => MachineField.Status, + "gamestatus" => MachineField.Status, + "supportstatus" => MachineField.Status, + "support_status" => MachineField.Status, - case "amstatus": - case "am_status": - case "gamestatus": - case "supportstatus": - case "support_status": - return MachineField.Status; + "displaycount" => MachineField.DisplayCount, + "display_count" => MachineField.DisplayCount, - case "displaycount": - return MachineField.DisplayCount; + "displaytype" => MachineField.DisplayType, + "display_type" => MachineField.DisplayType, - case "displaytype": - return MachineField.DisplayType; - - case "buttons": - return MachineField.Buttons; + "buttons" => MachineField.Buttons, #endregion #region ListXML - case "history": - return MachineField.History; + "history" => MachineField.History, - case "sourcefile": - case "source_file": - return MachineField.SourceFile; + "sourcefile" => MachineField.SourceFile, + "source_file" => MachineField.SourceFile, - case "runnable": - return MachineField.Runnable; + "runnable" => MachineField.Runnable, #endregion #region Logiqx - case "board": - return MachineField.Board; + "board" => MachineField.Board, - case "rebuildto": - case "rebuild_to": - return MachineField.RebuildTo; + "rebuildto" => MachineField.RebuildTo, + "rebuild_to" => MachineField.RebuildTo, - case "id": - case "nointroid": - case "nointro_id": - case "no_intro_id": - return MachineField.NoIntroId; + "id" => MachineField.NoIntroId, + "nointroid" => MachineField.NoIntroId, + "nointro_id" => MachineField.NoIntroId, + "no_intro_id" => MachineField.NoIntroId, - case "cloneofid": - case "nointrocloneofid": - case "nointro_cloneofid": - case "no_intro_cloneofid": - case "no_intro_clone_of_id": - return MachineField.NoIntroCloneOfId; + "cloneofid" => MachineField.NoIntroCloneOfId, + "nointrocloneofid" => MachineField.NoIntroCloneOfId, + "nointro_cloneofid" => MachineField.NoIntroCloneOfId, + "no_intro_cloneofid" => MachineField.NoIntroCloneOfId, + "no_intro_clone_of_id" => MachineField.NoIntroCloneOfId, #endregion #region Logiqx EmuArc - case "titleid": - case "title_id": - return MachineField.TitleID; + "titleid" => MachineField.TitleID, + "title_id" => MachineField.TitleID, - case "developer": - return MachineField.Developer; + "developer" => MachineField.Developer, - case "genre": - return MachineField.Genre; + "genre" => MachineField.Genre, - case "subgenre": - case "sub_genre": - return MachineField.Subgenre; + "subgenre" => MachineField.Subgenre, + "sub_genre" => MachineField.Subgenre, - case "ratings": - return MachineField.Ratings; + "ratings" => MachineField.Ratings, - case "score": - return MachineField.Score; + "score" => MachineField.Score, - case "enabled": - return MachineField.Enabled; + "enabled" => MachineField.Enabled, - case "crc": - case "hascrc": - case "has_crc": - return MachineField.CRC; + "crc" => MachineField.CRC, + "hascrc" => MachineField.CRC, + "has_crc" => MachineField.CRC, - case "relatedto": - case "related_to": - return MachineField.RelatedTo; + "relatedto" => MachineField.RelatedTo, + "related_to" => MachineField.RelatedTo, #endregion #region OpenMSX - case "genmsxid": - case "genmsx_id": - case "gen_msxid": - case "gen_msx_id": - return MachineField.GenMSXID; + "genmsxid" => MachineField.GenMSXID, + "genmsx_id" => MachineField.GenMSXID, + "gen_msxid" => MachineField.GenMSXID, + "gen_msx_id" => MachineField.GenMSXID, - case "system": - case "msxsystem": - case "msx_system": - return MachineField.System; - - case "country": - return MachineField.Country; + "system" => MachineField.System, + "msxsystem" => MachineField.System, + "msx_system" => MachineField.System, + + "country" => MachineField.Country, #endregion #region SoftwareList - - case "supported": - return MachineField.Supported; + + "supported" => MachineField.Supported, #endregion - default: - return MachineField.NULL; - } + _ => MachineField.NULL, + }; } /// @@ -1683,8 +1583,8 @@ namespace SabreTools.Core.Tools ItemType.ReleaseDetails => "release_details", ItemType.Rom => "rom", ItemType.Sample => "sample", - ItemType.Serials => "sample", - ItemType.Setting => "serials", + ItemType.Serials => "serials", + ItemType.Setting => "setting", ItemType.SharedFeature => "sharedfeat", ItemType.Slot => "slot", ItemType.SlotOption => "slotoption", diff --git a/SabreTools.Core/Tools/Hasher.cs b/SabreTools.Core/Tools/Hasher.cs index ee68455f..871efcd7 100644 --- a/SabreTools.Core/Tools/Hasher.cs +++ b/SabreTools.Core/Tools/Hasher.cs @@ -92,7 +92,7 @@ namespace SabreTools.Core.Tools /// public void Terminate() { - byte[] emptyBuffer = new byte[0]; + byte[] emptyBuffer = Array.Empty(); switch (HashType) { case Hash.CRC: @@ -118,23 +118,17 @@ namespace SabreTools.Core.Tools /// public byte[] GetHash() { - switch (HashType) + return HashType switch { - case Hash.CRC: - return BitConverter.GetBytes((_hasher as OptimizedCRC.OptimizedCRC).Value).Reverse().ToArray(); - - case Hash.MD5: - case Hash.SHA1: - case Hash.SHA256: - case Hash.SHA384: - case Hash.SHA512: - return (_hasher as HashAlgorithm).Hash; - - case Hash.SpamSum: - return (_hasher as SpamSumContext).Final(); - } - - return null; + Hash.CRC => BitConverter.GetBytes((_hasher as OptimizedCRC.OptimizedCRC).Value).Reverse().ToArray(), + Hash.MD5 => (_hasher as HashAlgorithm).Hash, + Hash.SHA1 => (_hasher as HashAlgorithm).Hash, + Hash.SHA256 => (_hasher as HashAlgorithm).Hash, + Hash.SHA384 => (_hasher as HashAlgorithm).Hash, + Hash.SHA512 => (_hasher as HashAlgorithm).Hash, + Hash.SpamSum => (_hasher as SpamSumContext).Final(), + _ => null, + }; } } } diff --git a/SabreTools.Core/Tools/Utilities.cs b/SabreTools.Core/Tools/Utilities.cs index a6b4b3b9..25fc192e 100644 --- a/SabreTools.Core/Tools/Utilities.cs +++ b/SabreTools.Core/Tools/Utilities.cs @@ -182,26 +182,24 @@ namespace SabreTools.Core.Tools string ext = Path.GetExtension(path).TrimStart('.').ToLowerInvariant(); // Check against the list of known DAT extensions - switch (ext) + return ext switch { - case "csv": - case "dat": - case "json": - case "md5": - case "sfv": - case "sha1": - case "sha256": - case "sha384": - case "sha512": - case "spamsum": - case "ssv": - case "tsv": - case "txt": - case "xml": - return true; - default: - return false; - } + "csv" => true, + "dat" => true, + "json" => true, + "md5" => true, + "sfv" => true, + "sha1" => true, + "sha256" => true, + "sha384" => true, + "sha512" => true, + "spamsum" => true, + "ssv" => true, + "tsv" => true, + "txt" => true, + "xml" => true, + _ => false, + }; } /// Indicates whether the specified array is null or has a length of zero @@ -213,7 +211,7 @@ namespace SabreTools.Core.Tools { return array == null || array.Length == 0; } - + /// /// Remove all chars that are considered path unsafe /// @@ -224,7 +222,7 @@ namespace SabreTools.Core.Tools List invalidPath = Path.GetInvalidPathChars().ToList(); return new string(s.Where(c => !invalidPath.Contains(c)).ToArray()); } - + /// /// Returns if the first byte array starts with the second array /// diff --git a/SabreTools.DatFiles/DatHeader.cs b/SabreTools.DatFiles/DatHeader.cs index e5246e02..9f680709 100644 --- a/SabreTools.DatFiles/DatHeader.cs +++ b/SabreTools.DatFiles/DatHeader.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Xml.Serialization; using SabreTools.Core; @@ -417,119 +416,119 @@ namespace SabreTools.DatFiles { #region Common - if (mappings.Keys.Contains(DatHeaderField.FileName)) + if (mappings.ContainsKey(DatHeaderField.FileName)) FileName = mappings[DatHeaderField.FileName]; - if (mappings.Keys.Contains(DatHeaderField.Name)) + if (mappings.ContainsKey(DatHeaderField.Name)) Name = mappings[DatHeaderField.Name]; - if (mappings.Keys.Contains(DatHeaderField.Description)) + if (mappings.ContainsKey(DatHeaderField.Description)) Description = mappings[DatHeaderField.Description]; - if (mappings.Keys.Contains(DatHeaderField.RootDir)) + if (mappings.ContainsKey(DatHeaderField.RootDir)) RootDir = mappings[DatHeaderField.RootDir]; - if (mappings.Keys.Contains(DatHeaderField.Category)) + if (mappings.ContainsKey(DatHeaderField.Category)) Category = mappings[DatHeaderField.Category]; - if (mappings.Keys.Contains(DatHeaderField.Version)) + if (mappings.ContainsKey(DatHeaderField.Version)) Version = mappings[DatHeaderField.Version]; - if (mappings.Keys.Contains(DatHeaderField.Date)) + if (mappings.ContainsKey(DatHeaderField.Date)) Date = mappings[DatHeaderField.Date]; - if (mappings.Keys.Contains(DatHeaderField.Author)) + if (mappings.ContainsKey(DatHeaderField.Author)) Author = mappings[DatHeaderField.Author]; - if (mappings.Keys.Contains(DatHeaderField.Email)) + if (mappings.ContainsKey(DatHeaderField.Email)) Email = mappings[DatHeaderField.Email]; - if (mappings.Keys.Contains(DatHeaderField.Homepage)) + if (mappings.ContainsKey(DatHeaderField.Homepage)) Homepage = mappings[DatHeaderField.Homepage]; - if (mappings.Keys.Contains(DatHeaderField.Url)) + if (mappings.ContainsKey(DatHeaderField.Url)) Url = mappings[DatHeaderField.Url]; - if (mappings.Keys.Contains(DatHeaderField.Comment)) + if (mappings.ContainsKey(DatHeaderField.Comment)) Comment = mappings[DatHeaderField.Comment]; - if (mappings.Keys.Contains(DatHeaderField.HeaderSkipper)) + if (mappings.ContainsKey(DatHeaderField.HeaderSkipper)) HeaderSkipper = mappings[DatHeaderField.HeaderSkipper]; - if (mappings.Keys.Contains(DatHeaderField.Type)) + if (mappings.ContainsKey(DatHeaderField.Type)) Type = mappings[DatHeaderField.Type]; - if (mappings.Keys.Contains(DatHeaderField.ForceMerging)) + if (mappings.ContainsKey(DatHeaderField.ForceMerging)) ForceMerging = mappings[DatHeaderField.ForceMerging].AsMergingFlag(); - if (mappings.Keys.Contains(DatHeaderField.ForceNodump)) + if (mappings.ContainsKey(DatHeaderField.ForceNodump)) ForceNodump = mappings[DatHeaderField.ForceNodump].AsNodumpFlag(); - if (mappings.Keys.Contains(DatHeaderField.ForcePacking)) + if (mappings.ContainsKey(DatHeaderField.ForcePacking)) ForcePacking = mappings[DatHeaderField.ForcePacking].AsPackingFlag(); #endregion #region ListXML - if (mappings.Keys.Contains(DatHeaderField.Debug)) + if (mappings.ContainsKey(DatHeaderField.Debug)) Debug = mappings[DatHeaderField.Debug].AsYesNo(); - if (mappings.Keys.Contains(DatHeaderField.MameConfig)) + if (mappings.ContainsKey(DatHeaderField.MameConfig)) MameConfig = mappings[DatHeaderField.MameConfig]; #endregion #region Logiqx - if (mappings.Keys.Contains(DatHeaderField.NoIntroID)) + if (mappings.ContainsKey(DatHeaderField.NoIntroID)) NoIntroID = mappings[DatHeaderField.NoIntroID]; - if (mappings.Keys.Contains(DatHeaderField.Build)) + if (mappings.ContainsKey(DatHeaderField.Build)) Build = mappings[DatHeaderField.Build]; - if (mappings.Keys.Contains(DatHeaderField.RomMode)) + if (mappings.ContainsKey(DatHeaderField.RomMode)) RomMode = mappings[DatHeaderField.RomMode].AsMergingFlag(); - if (mappings.Keys.Contains(DatHeaderField.BiosMode)) + if (mappings.ContainsKey(DatHeaderField.BiosMode)) BiosMode = mappings[DatHeaderField.BiosMode].AsMergingFlag(); - if (mappings.Keys.Contains(DatHeaderField.SampleMode)) + if (mappings.ContainsKey(DatHeaderField.SampleMode)) SampleMode = mappings[DatHeaderField.SampleMode].AsMergingFlag(); - if (mappings.Keys.Contains(DatHeaderField.LockRomMode)) + if (mappings.ContainsKey(DatHeaderField.LockRomMode)) LockRomMode = mappings[DatHeaderField.LockRomMode].AsYesNo(); - if (mappings.Keys.Contains(DatHeaderField.LockBiosMode)) + if (mappings.ContainsKey(DatHeaderField.LockBiosMode)) LockBiosMode = mappings[DatHeaderField.LockBiosMode].AsYesNo(); - if (mappings.Keys.Contains(DatHeaderField.LockSampleMode)) + if (mappings.ContainsKey(DatHeaderField.LockSampleMode)) LockSampleMode = mappings[DatHeaderField.LockSampleMode].AsYesNo(); #endregion #region OfflineList - if (mappings.Keys.Contains(DatHeaderField.System)) + if (mappings.ContainsKey(DatHeaderField.System)) System = mappings[DatHeaderField.System]; - if (mappings.Keys.Contains(DatHeaderField.ScreenshotsWidth)) + if (mappings.ContainsKey(DatHeaderField.ScreenshotsWidth)) ScreenshotsWidth = mappings[DatHeaderField.ScreenshotsWidth]; - if (mappings.Keys.Contains(DatHeaderField.ScreenshotsHeight)) + if (mappings.ContainsKey(DatHeaderField.ScreenshotsHeight)) ScreenshotsHeight = mappings[DatHeaderField.ScreenshotsHeight]; // TODO: Add DatHeader_Info* // TDOO: Add DatHeader_CanOpen* - if (mappings.Keys.Contains(DatHeaderField.RomTitle)) + if (mappings.ContainsKey(DatHeaderField.RomTitle)) RomTitle = mappings[DatHeaderField.RomTitle]; #endregion #region RomCenter - if (mappings.Keys.Contains(DatHeaderField.RomCenterVersion)) + if (mappings.ContainsKey(DatHeaderField.RomCenterVersion)) RomCenterVersion = mappings[DatHeaderField.RomCenterVersion]; #endregion @@ -742,14 +741,14 @@ namespace SabreTools.DatFiles public Dictionary CreateOutFileNames(string outDir, bool overwrite = true) { // Create the output dictionary - Dictionary outfileNames = new Dictionary(); + Dictionary outfileNames = new(); // Double check the outDir for the end delim if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString())) outDir += Path.DirectorySeparatorChar; // Get all used extensions - List usedExtensions = new List(); + List usedExtensions = new(); // Get the extensions from the output type diff --git a/SabreTools.DatFiles/Formats/ArchiveDotOrg.cs b/SabreTools.DatFiles/Formats/ArchiveDotOrg.cs index 7b6dc978..90ae704d 100644 --- a/SabreTools.DatFiles/Formats/ArchiveDotOrg.cs +++ b/SabreTools.DatFiles/Formats/ArchiveDotOrg.cs @@ -162,7 +162,7 @@ namespace SabreTools.DatFiles.Formats reader.MoveToContent(); // Create the Rom to store the info - Rom rom = new Rom + Rom rom = new() { Name = reader.GetAttribute("name"), ArchiveDotOrgSource = reader.GetAttribute("source"), @@ -187,7 +187,7 @@ namespace SabreTools.DatFiles.Formats rom.Machine.Name = splitpath[0]; rom.Machine.Description = splitpath[0]; - rom.Name = rom.Name.Substring(splitpath[0].Length + 1); + rom.Name = rom.Name[(splitpath[0].Length + 1)..]; } // TODO: Handle SuperDAT @@ -287,7 +287,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = ' ', diff --git a/SabreTools.DatFiles/Formats/AttractMode.cs b/SabreTools.DatFiles/Formats/AttractMode.cs index 0abc8369..09e93f0c 100644 --- a/SabreTools.DatFiles/Formats/AttractMode.cs +++ b/SabreTools.DatFiles/Formats/AttractMode.cs @@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc) + SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc) { Header = true, Quotes = false, @@ -56,7 +56,7 @@ namespace SabreTools.DatFiles.Formats // Get the current line, split and parse svr.ReadNextLine(); - Rom rom = new Rom + Rom rom = new() { Name = "-", Size = Constants.SizeZero, @@ -134,7 +134,7 @@ namespace SabreTools.DatFiles.Formats return false; } - SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false)) + SeparatedValueWriter svw = new(fs, new UTF8Encoding(false)) { Quotes = false, Separator = ';', diff --git a/SabreTools.DatFiles/Formats/ClrMamePro.cs b/SabreTools.DatFiles/Formats/ClrMamePro.cs index 2325ce81..05947887 100644 --- a/SabreTools.DatFiles/Formats/ClrMamePro.cs +++ b/SabreTools.DatFiles/Formats/ClrMamePro.cs @@ -42,7 +42,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - ClrMameProReader cmpr = new ClrMameProReader(System.IO.File.OpenRead(filename), enc) + ClrMameProReader cmpr = new(System.IO.File.OpenRead(filename), enc) { DosCenter = false, Quotes = Quotes, @@ -210,7 +210,7 @@ namespace SabreTools.DatFiles.Formats { // Prepare all internal variables bool containsItems = false; - Machine machine = new Machine() + Machine machine = new() { MachineType = (resource ? MachineType.Bios : MachineType.NULL), }; @@ -402,7 +402,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder if (!containsItems) { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -455,7 +455,7 @@ namespace SabreTools.DatFiles.Formats return false; } - ClrMameProWriter cmpw = new ClrMameProWriter(fs, new UTF8Encoding(false)) + ClrMameProWriter cmpw = new(fs, new UTF8Encoding(false)) { Quotes = Quotes }; diff --git a/SabreTools.DatFiles/Formats/DosCenter.cs b/SabreTools.DatFiles/Formats/DosCenter.cs index fe2acef3..030a94ac 100644 --- a/SabreTools.DatFiles/Formats/DosCenter.cs +++ b/SabreTools.DatFiles/Formats/DosCenter.cs @@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - ClrMameProReader cmpr = new ClrMameProReader(System.IO.File.OpenRead(filename), enc) + ClrMameProReader cmpr = new(System.IO.File.OpenRead(filename), enc) { DosCenter = true }; @@ -143,7 +143,7 @@ namespace SabreTools.DatFiles.Formats { // Prepare all internal variables bool containsItems = false; - Machine machine = new Machine() + Machine machine = new() { MachineType = MachineType.NULL, }; @@ -236,7 +236,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder if (!containsItems) { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -280,7 +280,7 @@ namespace SabreTools.DatFiles.Formats return false; } - ClrMameProWriter cmpw = new ClrMameProWriter(fs, new UTF8Encoding(false)) + ClrMameProWriter cmpw = new(fs, new UTF8Encoding(false)) { Quotes = false }; diff --git a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs index e39ea63b..f20ec5bf 100644 --- a/SabreTools.DatFiles/Formats/EverdriveSmdb.cs +++ b/SabreTools.DatFiles/Formats/EverdriveSmdb.cs @@ -31,7 +31,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc) + SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc) { Header = false, Quotes = false, @@ -63,7 +63,7 @@ namespace SabreTools.DatFiles.Formats string[] fullname = svr.Line[1].Split('/'); - Rom rom = new Rom + Rom rom = new() { Name = svr.Line[1][(fullname[0].Length + 1)..], Size = null, // No size provided, but we don't want the size being 0 @@ -131,7 +131,7 @@ namespace SabreTools.DatFiles.Formats return false; } - SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false)) + SeparatedValueWriter svw = new(fs, new UTF8Encoding(false)) { Quotes = false, Separator = '\t', diff --git a/SabreTools.DatFiles/Formats/Hashfile.cs b/SabreTools.DatFiles/Formats/Hashfile.cs index b4d86408..863bab5a 100644 --- a/SabreTools.DatFiles/Formats/Hashfile.cs +++ b/SabreTools.DatFiles/Formats/Hashfile.cs @@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), enc); + StreamReader sr = new(System.IO.File.OpenRead(filename), enc); while (!sr.EndOfStream) { @@ -66,16 +66,16 @@ namespace SabreTools.DatFiles.Formats { split = name.Split('/'); machine = split[0]; - name = name.Substring(machine.Length + 1); + name = name[(machine.Length + 1)..]; } else if (name.Contains('\\')) { split = name.Split('\\'); machine = split[0]; - name = name.Substring(machine.Length + 1); + name = name[(machine.Length + 1)..]; } - Rom rom = new Rom + Rom rom = new() { Name = name, Size = null, @@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats /// protected override List GetMissingRequiredFields(DatItem datItem) { - List missingFields = new List(); + List missingFields = new(); // Check item name if (string.IsNullOrWhiteSpace(datItem.GetName())) @@ -259,7 +259,7 @@ namespace SabreTools.DatFiles.Formats return false; } - SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false)) + SeparatedValueWriter svw = new(fs, new UTF8Encoding(false)) { Quotes = false, Separator = ' ', diff --git a/SabreTools.DatFiles/Formats/Listrom.cs b/SabreTools.DatFiles/Formats/Listrom.cs index 28c7e1f4..5abd1a98 100644 --- a/SabreTools.DatFiles/Formats/Listrom.cs +++ b/SabreTools.DatFiles/Formats/Listrom.cs @@ -39,7 +39,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), enc); + StreamReader sr = new(System.IO.File.OpenRead(filename), enc); string gamename = string.Empty; while (!sr.EndOfStream) @@ -90,12 +90,12 @@ namespace SabreTools.DatFiles.Formats line = line[romname.Length..]; // Next we separate the ROM into pieces - split = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); + split = line.Split(Array.Empty(), StringSplitOptions.RemoveEmptyEntries); // Standard Disks have 2 pieces (name, sha1) if (split.Length == 1) { - Disk disk = new Disk() + Disk disk = new() { Name = romname, SHA1 = CleanListromHashData(split[0]), @@ -118,7 +118,7 @@ namespace SabreTools.DatFiles.Formats // Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP) else if (split.Length == 3 && line.EndsWith("BAD_DUMP")) { - Disk disk = new Disk() + Disk disk = new() { Name = romname, SHA1 = CleanListromHashData(split[1]), @@ -142,7 +142,7 @@ namespace SabreTools.DatFiles.Formats // Standard ROMs have 4 pieces (name, size, crc, sha1) else if (split.Length == 3) { - Rom rom = new Rom() + Rom rom = new() { Name = romname, Size = Utilities.CleanLong(split[0]), @@ -167,7 +167,7 @@ namespace SabreTools.DatFiles.Formats // Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN) else if (split.Length == 4 && line.EndsWith("NO GOOD DUMP KNOWN")) { - Disk disk = new Disk() + Disk disk = new() { Name = romname, ItemStatus = ItemStatus.Nodump, @@ -190,7 +190,7 @@ namespace SabreTools.DatFiles.Formats // Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP) else if (split.Length == 5 && line.EndsWith("BAD_DUMP")) { - Rom rom = new Rom() + Rom rom = new() { Name = romname, Size = Utilities.CleanLong(split[0]), @@ -216,7 +216,7 @@ namespace SabreTools.DatFiles.Formats // Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN) else if (split.Length == 5 && line.EndsWith("NO GOOD DUMP KNOWN")) { - Rom rom = new Rom() + Rom rom = new() { Name = romname, Size = Utilities.CleanLong(split[0]), @@ -261,7 +261,7 @@ namespace SabreTools.DatFiles.Formats /// protected override List GetMissingRequiredFields(DatItem datItem) { - List missingFields = new List(); + List missingFields = new(); // Check item name if (string.IsNullOrWhiteSpace(datItem.GetName())) @@ -287,7 +287,7 @@ namespace SabreTools.DatFiles.Formats return false; } - StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); + StreamWriter sw = new(fs, new UTF8Encoding(false)); // Write out each of the machines and roms string lastgame = null; diff --git a/SabreTools.DatFiles/Formats/Listxml.cs b/SabreTools.DatFiles/Formats/Listxml.cs index c795d6bb..91ee37ba 100644 --- a/SabreTools.DatFiles/Formats/Listxml.cs +++ b/SabreTools.DatFiles/Formats/Listxml.cs @@ -295,7 +295,7 @@ namespace SabreTools.DatFiles.Formats if (reader.GetAttribute("ismechanical").AsYesNo() == true) machineType |= MachineType.Mechanical; - Machine machine = new Machine + Machine machine = new() { Name = reader.GetAttribute("name"), Description = reader.GetAttribute("name"), @@ -309,7 +309,7 @@ namespace SabreTools.DatFiles.Formats }; // Get list for new DatItems - List datItems = new List(); + List datItems = new(); while (!reader.EOF) { @@ -776,7 +776,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder else { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -1370,7 +1370,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.DatFiles/Formats/Logiqx.cs b/SabreTools.DatFiles/Formats/Logiqx.cs index 5ee3c1a4..d911626e 100644 --- a/SabreTools.DatFiles/Formats/Logiqx.cs +++ b/SabreTools.DatFiles/Formats/Logiqx.cs @@ -213,7 +213,7 @@ namespace SabreTools.DatFiles.Formats ValidationType = ValidationType.None, }); - List dirs = new List(); + List dirs = new(); // If we got a null reader, just return if (xtr == null) @@ -474,8 +474,8 @@ namespace SabreTools.DatFiles.Formats if (reader.GetAttribute("ismechanical").AsYesNo() == true) // Listxml-specific, used by older DATs machineType |= MachineType.Mechanical; - string dirsString = (dirs != null && dirs.Count() > 0 ? string.Join("/", dirs) + "/" : string.Empty); - Machine machine = new Machine + string dirsString = (dirs != null && dirs.Count > 0 ? string.Join("/", dirs) + "/" : string.Empty); + Machine machine = new() { Name = dirsString + reader.GetAttribute("name"), Description = dirsString + reader.GetAttribute("name"), @@ -727,7 +727,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder if (!containsItems) { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -869,7 +869,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.DatFiles/Formats/Missfile.cs b/SabreTools.DatFiles/Formats/Missfile.cs index 56029481..c33a4acb 100644 --- a/SabreTools.DatFiles/Formats/Missfile.cs +++ b/SabreTools.DatFiles/Formats/Missfile.cs @@ -50,7 +50,7 @@ namespace SabreTools.DatFiles.Formats return false; } - StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); + StreamWriter sw = new(fs, new UTF8Encoding(false)); // Write out each of the machines and roms string lastgame = null; diff --git a/SabreTools.DatFiles/Formats/OfflineList.cs b/SabreTools.DatFiles/Formats/OfflineList.cs index d991fad2..13bc4751 100644 --- a/SabreTools.DatFiles/Formats/OfflineList.cs +++ b/SabreTools.DatFiles/Formats/OfflineList.cs @@ -470,8 +470,8 @@ namespace SabreTools.DatFiles.Formats // Prepare all internal variables string releaseNumber = string.Empty, duplicateid; long? size = null; - List datItems = new List(); - Machine machine = new Machine(); + List datItems = new(); + Machine machine = new(); // If there's no subtree to the configuration, skip it if (reader == null) @@ -683,7 +683,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.DatFiles/Formats/OpenMSX.cs b/SabreTools.DatFiles/Formats/OpenMSX.cs index e614bc4c..f0027e93 100644 --- a/SabreTools.DatFiles/Formats/OpenMSX.cs +++ b/SabreTools.DatFiles/Formats/OpenMSX.cs @@ -125,7 +125,7 @@ namespace SabreTools.DatFiles.Formats bool containsItems = false; // Create a new machine - Machine machine = new Machine(); + Machine machine = new(); while (!reader.EOF) { @@ -180,7 +180,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder if (!containsItems) { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -215,7 +215,7 @@ namespace SabreTools.DatFiles.Formats string filename, int indexId) { - List items = new List(); + List items = new(); Original original = null; while (!reader.EOF) @@ -556,7 +556,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.DatFiles/Formats/RomCenter.cs b/SabreTools.DatFiles/Formats/RomCenter.cs index fc2d055d..d9056303 100644 --- a/SabreTools.DatFiles/Formats/RomCenter.cs +++ b/SabreTools.DatFiles/Formats/RomCenter.cs @@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false) { // Prepare all intenral variables - IniReader ir = new IniReader(filename) { ValidateRows = false }; + IniReader ir = new(filename) { ValidateRows = false }; // If we got a null reader, just return if (ir == null) @@ -326,7 +326,7 @@ namespace SabreTools.DatFiles.Formats 9 - merge name */ string[] rominfo = line.Split('¬'); - Rom rom = new Rom + Rom rom = new() { Name = rominfo[5], Size = Utilities.CleanLong(rominfo[7]), @@ -385,14 +385,14 @@ namespace SabreTools.DatFiles.Formats return false; } - IniWriter iw = new IniWriter(fs, new UTF8Encoding(false)); + IniWriter iw = new(fs, new UTF8Encoding(false)); // Write out the header WriteHeader(iw); // Write out each of the machines and roms string lastgame = null; - List splitpath = new List(); + List splitpath = new(); // Use a sorted list of games to output foreach (string key in Items.SortedKeys) diff --git a/SabreTools.DatFiles/Formats/SabreJSON.cs b/SabreTools.DatFiles/Formats/SabreJSON.cs index f6399dca..d9254c71 100644 --- a/SabreTools.DatFiles/Formats/SabreJSON.cs +++ b/SabreTools.DatFiles/Formats/SabreJSON.cs @@ -31,8 +31,8 @@ namespace SabreTools.DatFiles.Formats public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false) { // Prepare all internal variables - StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), new UTF8Encoding(false)); - JsonTextReader jtr = new JsonTextReader(sr); + StreamReader sr = new(System.IO.File.OpenRead(filename), new UTF8Encoding(false)); + JsonTextReader jtr = new(sr); // If we got a null reader, just return if (jtr == null) @@ -91,7 +91,7 @@ namespace SabreTools.DatFiles.Formats // Read in the header and apply any new fields jtr.Read(); - JsonSerializer js = new JsonSerializer(); + JsonSerializer js = new(); DatHeader header = js.Deserialize(jtr); Header.ConditionalCopy(header); } @@ -111,7 +111,7 @@ namespace SabreTools.DatFiles.Formats // Read in the machine array jtr.Read(); - JsonSerializer js = new JsonSerializer(); + JsonSerializer js = new(); JArray machineArray = js.Deserialize(jtr); // Loop through each machine object and process @@ -355,8 +355,8 @@ namespace SabreTools.DatFiles.Formats return false; } - StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false)); - JsonTextWriter jtw = new JsonTextWriter(sw) + StreamWriter sw = new(fs, new UTF8Encoding(false)); + JsonTextWriter jtw = new(sw) { Formatting = Formatting.Indented, IndentChar = '\t', @@ -431,7 +431,7 @@ namespace SabreTools.DatFiles.Formats // Write the DatHeader jtw.WritePropertyName("header"); - JsonSerializer js = new JsonSerializer() { Formatting = Formatting.Indented }; + JsonSerializer js = new() { Formatting = Formatting.Indented }; js.Serialize(jtw, Header); jtw.WritePropertyName("machines"); @@ -455,7 +455,7 @@ namespace SabreTools.DatFiles.Formats // Write the Machine jtw.WritePropertyName("machine"); - JsonSerializer js = new JsonSerializer() { Formatting = Formatting.Indented }; + JsonSerializer js = new() { Formatting = Formatting.Indented }; js.Serialize(jtw, datItem.Machine); jtw.WritePropertyName("items"); @@ -494,7 +494,7 @@ namespace SabreTools.DatFiles.Formats // Write the DatItem jtw.WritePropertyName("datitem"); - JsonSerializer js = new JsonSerializer() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented }; + JsonSerializer js = new() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented }; js.Serialize(jtw, datItem); // End item diff --git a/SabreTools.DatFiles/Formats/SabreXML.cs b/SabreTools.DatFiles/Formats/SabreXML.cs index 625aecf0..0add4955 100644 --- a/SabreTools.DatFiles/Formats/SabreXML.cs +++ b/SabreTools.DatFiles/Formats/SabreXML.cs @@ -57,7 +57,7 @@ namespace SabreTools.DatFiles.Formats switch (xtr.Name) { case "header": - XmlSerializer xs = new XmlSerializer(typeof(DatHeader)); + XmlSerializer xs = new(typeof(DatHeader)); DatHeader header = xs.Deserialize(xtr.ReadSubtree()) as DatHeader; Header.ConditionalCopy(header); xtr.Skip(); @@ -116,7 +116,7 @@ namespace SabreTools.DatFiles.Formats switch (xtr.Name) { case "machine": - XmlSerializer xs = new XmlSerializer(typeof(Machine)); + XmlSerializer xs = new(typeof(Machine)); machine = xs.Deserialize(xtr.ReadSubtree()) as Machine; xtr.Skip(); break; @@ -162,7 +162,7 @@ namespace SabreTools.DatFiles.Formats switch (xtr.Name) { case "datitem": - XmlSerializer xs = new XmlSerializer(typeof(DatItem)); + XmlSerializer xs = new(typeof(DatItem)); DatItem item = xs.Deserialize(xtr.ReadSubtree()) as DatItem; item.CopyMachineInformation(machine); item.Source = new Source { Name = filename, Index = indexId }; @@ -191,7 +191,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', @@ -266,8 +266,8 @@ namespace SabreTools.DatFiles.Formats xtw.WriteStartElement("datafile"); - XmlSerializer xs = new XmlSerializer(typeof(DatHeader)); - XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); + XmlSerializer xs = new(typeof(DatHeader)); + XmlSerializerNamespaces ns = new(); ns.Add("", ""); xs.Serialize(xtw, Header, ns); @@ -288,8 +288,8 @@ namespace SabreTools.DatFiles.Formats // Write the machine xtw.WriteStartElement("directory"); - XmlSerializer xs = new XmlSerializer(typeof(Machine)); - XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); + XmlSerializer xs = new(typeof(Machine)); + XmlSerializerNamespaces ns = new(); ns.Add("", ""); xs.Serialize(xtw, datItem.Machine, ns); @@ -324,8 +324,8 @@ namespace SabreTools.DatFiles.Formats ProcessItemName(datItem, true); // Write the DatItem - XmlSerializer xs = new XmlSerializer(typeof(DatItem)); - XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); + XmlSerializer xs = new(typeof(DatItem)); + XmlSerializerNamespaces ns = new(); ns.Add("", ""); xs.Serialize(xtw, datItem, ns); diff --git a/SabreTools.DatFiles/Formats/SeparatedValue.cs b/SabreTools.DatFiles/Formats/SeparatedValue.cs index 510d0e9e..625cf6ca 100644 --- a/SabreTools.DatFiles/Formats/SeparatedValue.cs +++ b/SabreTools.DatFiles/Formats/SeparatedValue.cs @@ -36,7 +36,7 @@ namespace SabreTools.DatFiles.Formats { // Open a file reader Encoding enc = filename.GetEncoding(); - SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc) + SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc) { Header = true, Quotes = true, @@ -60,11 +60,11 @@ namespace SabreTools.DatFiles.Formats svr.ReadNextLine(); // Create mapping dictionaries - Setter setter = new Setter(); + Setter setter = new(); setter.PopulateSettersFromList(svr.HeaderValues, svr.Line); // Set DatHeader fields - DatHeader datHeader = new DatHeader(); + DatHeader datHeader = new(); setter.SetFields(datHeader); Header.ConditionalCopy(datHeader); @@ -117,7 +117,7 @@ namespace SabreTools.DatFiles.Formats return false; } - SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false)) + SeparatedValueWriter svw = new(fs, new UTF8Encoding(false)) { Quotes = true, Separator = this._delim, diff --git a/SabreTools.DatFiles/Formats/SoftwareList.cs b/SabreTools.DatFiles/Formats/SoftwareList.cs index ca799803..cf3b4844 100644 --- a/SabreTools.DatFiles/Formats/SoftwareList.cs +++ b/SabreTools.DatFiles/Formats/SoftwareList.cs @@ -176,7 +176,7 @@ namespace SabreTools.DatFiles.Formats bool containsItems = false; // Create a new machine - Machine machine = new Machine + Machine machine = new() { Name = reader.GetAttribute("name"), CloneOf = reader.GetAttribute("cloneof"), @@ -262,7 +262,7 @@ namespace SabreTools.DatFiles.Formats // If no items were found for this machine, add a Blank placeholder if (!containsItems) { - Blank blank = new Blank() + Blank blank = new() { Source = new Source { @@ -295,7 +295,7 @@ namespace SabreTools.DatFiles.Formats // Get lists ready part.Features = new List(); - List items = new List(); + List items = new(); while (!reader.EOF) { @@ -434,7 +434,7 @@ namespace SabreTools.DatFiles.Formats /// DataArea representing the enclosing area private List ReadDataArea(XmlReader reader, DataArea dataArea) { - List items = new List(); + List items = new(); while (!reader.EOF) { @@ -483,7 +483,7 @@ namespace SabreTools.DatFiles.Formats /// DiskArea representing the enclosing area private List ReadDiskArea(XmlReader reader, DiskArea diskArea) { - List items = new List(); + List items = new(); while (!reader.EOF) { @@ -586,7 +586,7 @@ namespace SabreTools.DatFiles.Formats /// protected override List GetMissingRequiredFields(DatItem datItem) { - List missingFields = new List(); + List missingFields = new(); switch (datItem.ItemType) { @@ -705,7 +705,7 @@ namespace SabreTools.DatFiles.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false)) + XmlTextWriter xtw = new(fs, new UTF8Encoding(false)) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index e72a9ebd..efac9177 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -44,7 +44,7 @@ namespace SabreTools.DatFiles /// /// Lock for statistics calculation /// - private readonly object statsLock = new object(); + private readonly object statsLock = new(); /// /// Logging object @@ -981,7 +981,7 @@ namespace SabreTools.DatFiles public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true) { // If we have a situation where there's no dictionary or no keys at all, we skip - if (items == null || items.Count == 0) + if (items == null || items.IsEmpty) return; // If the sorted type isn't the same, we want to sort the dictionary accordingly @@ -1084,7 +1084,7 @@ namespace SabreTools.DatFiles items.TryRemove(key, out _); // If there are no non-blank items, remove - else if (items[key].Count(i => i != null && i.ItemType != ItemType.Blank) == 0) + else if (!items[key].Any(i => i != null && i.ItemType != ItemType.Blank)) items.TryRemove(key, out _); } } @@ -1113,7 +1113,7 @@ namespace SabreTools.DatFiles /// List of matched DatItem objects public ConcurrentList GetDuplicates(DatItem datItem, bool sorted = false) { - ConcurrentList output = new ConcurrentList(); + ConcurrentList output = new(); // Check for an empty rom list first if (TotalCount == 0) @@ -1128,7 +1128,7 @@ namespace SabreTools.DatFiles // Try to find duplicates ConcurrentList roms = this[key]; - ConcurrentList left = new ConcurrentList(); + ConcurrentList left = new(); for (int i = 0; i < roms.Count; i++) { DatItem other = roms[i]; diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index 9ae43fa5..9de7aea9 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -47,7 +47,7 @@ namespace SabreTools.DatFiles /// /// Lock for statistics calculation /// - private readonly object statsLock = new object(); + private readonly object statsLock = new(); /// /// Logging object @@ -100,10 +100,10 @@ namespace SabreTools.DatFiles dbc.Open(); string query = $"SELECT key FROM keys"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); - List keys = new List(); + List keys = GetKeys(); if (sldr.HasRows) { while (sldr.Read()) @@ -121,6 +121,11 @@ namespace SabreTools.DatFiles } } + private static List GetKeys() + { + return new List(); + } + /// /// Get the keys in sorted order from the file dictionary /// @@ -457,10 +462,10 @@ namespace SabreTools.DatFiles dbc.Open(); string query = $"SELECT item FROM groups WHERE key='{key}'"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); - ConcurrentList items = new ConcurrentList(); + ConcurrentList items = new(); if (sldr.HasRows) { while (sldr.Read()) @@ -495,7 +500,7 @@ namespace SabreTools.DatFiles // Now remove the value string itemString = JsonConvert.SerializeObject(value); string query = $"DELETE FROM groups WHERE key='{key}'"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); // Dispose of database objects @@ -536,7 +541,7 @@ namespace SabreTools.DatFiles // Now add the value string itemString = JsonConvert.SerializeObject(value); string query = $"INSERT INTO groups (key, item) VALUES ('{key}', '{itemString}')"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); // Dispose of database objects @@ -836,7 +841,7 @@ namespace SabreTools.DatFiles dbc.Open(); string query = $"INSERT INTO keys (key) VALUES ('{key}')"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); // Dispose of database objects @@ -917,7 +922,7 @@ namespace SabreTools.DatFiles // Now remove the value string itemString = JsonConvert.SerializeObject(value); string query = $"DELETE FROM groups WHERE key='{key}' AND item='{itemString}'"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); // Dispose of database objects @@ -1142,7 +1147,7 @@ CREATE TABLE IF NOT EXISTS keys ( 'key' TEXT NOT NULL PRIMARY KEY (key) )"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); query = @" @@ -1275,7 +1280,7 @@ CREATE TABLE IF NOT EXISTS groups ( this[key] = null; // If there are no non-blank items, remove - else if (this[key].Count(i => i != null && i.ItemType != ItemType.Blank) == 0) + else if (!this[key].Any(i => i != null && i.ItemType != ItemType.Blank)) this[key] = null; } } @@ -1304,7 +1309,7 @@ CREATE TABLE IF NOT EXISTS groups ( /// List of matched DatItem objects public ConcurrentList GetDuplicates(DatItem datItem, bool sorted = false) { - ConcurrentList output = new ConcurrentList(); + ConcurrentList output = new(); // Check for an empty rom list first if (TotalCount == 0) @@ -1319,7 +1324,7 @@ CREATE TABLE IF NOT EXISTS groups ( // Try to find duplicates ConcurrentList roms = this[key]; - ConcurrentList left = new ConcurrentList(); + ConcurrentList left = new(); for (int i = 0; i < roms.Count; i++) { DatItem other = roms[i]; diff --git a/SabreTools.DatFiles/List.cs b/SabreTools.DatFiles/List.cs new file mode 100644 index 00000000..e69de29b diff --git a/SabreTools.DatFiles/Setter.cs b/SabreTools.DatFiles/Setter.cs index eb3c20e8..225f9167 100644 --- a/SabreTools.DatFiles/Setter.cs +++ b/SabreTools.DatFiles/Setter.cs @@ -40,7 +40,7 @@ namespace SabreTools.DatFiles /// /// Logging object /// - private readonly Logger logger = new Logger(); + private readonly Logger logger = new(); #endregion @@ -105,119 +105,119 @@ namespace SabreTools.DatFiles #region Common - if (DatHeaderMappings.Keys.Contains(DatHeaderField.FileName)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.FileName)) datHeader.FileName = DatHeaderMappings[DatHeaderField.FileName]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Name)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Name)) datHeader.Name = DatHeaderMappings[DatHeaderField.Name]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Description)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Description)) datHeader.Description = DatHeaderMappings[DatHeaderField.Description]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.RootDir)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.RootDir)) datHeader.RootDir = DatHeaderMappings[DatHeaderField.RootDir]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Category)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Category)) datHeader.Category = DatHeaderMappings[DatHeaderField.Category]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Version)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Version)) datHeader.Version = DatHeaderMappings[DatHeaderField.Version]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Date)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Date)) datHeader.Date = DatHeaderMappings[DatHeaderField.Date]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Author)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Author)) datHeader.Author = DatHeaderMappings[DatHeaderField.Author]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Email)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Email)) datHeader.Email = DatHeaderMappings[DatHeaderField.Email]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Homepage)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Homepage)) datHeader.Homepage = DatHeaderMappings[DatHeaderField.Homepage]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Url)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Url)) datHeader.Url = DatHeaderMappings[DatHeaderField.Url]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Comment)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Comment)) datHeader.Comment = DatHeaderMappings[DatHeaderField.Comment]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.HeaderSkipper)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.HeaderSkipper)) datHeader.HeaderSkipper = DatHeaderMappings[DatHeaderField.HeaderSkipper]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Type)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Type)) datHeader.Type = DatHeaderMappings[DatHeaderField.Type]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.ForceMerging)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.ForceMerging)) datHeader.ForceMerging = DatHeaderMappings[DatHeaderField.ForceMerging].AsMergingFlag(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.ForceNodump)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.ForceNodump)) datHeader.ForceNodump = DatHeaderMappings[DatHeaderField.ForceNodump].AsNodumpFlag(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.ForcePacking)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.ForcePacking)) datHeader.ForcePacking = DatHeaderMappings[DatHeaderField.ForcePacking].AsPackingFlag(); #endregion #region ListXML - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Debug)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Debug)) datHeader.Debug = DatHeaderMappings[DatHeaderField.Debug].AsYesNo(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.MameConfig)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.MameConfig)) datHeader.MameConfig = DatHeaderMappings[DatHeaderField.MameConfig]; #endregion #region Logiqx - if (DatHeaderMappings.Keys.Contains(DatHeaderField.NoIntroID)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.NoIntroID)) datHeader.NoIntroID = DatHeaderMappings[DatHeaderField.NoIntroID]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.Build)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.Build)) datHeader.Build = DatHeaderMappings[DatHeaderField.Build]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.RomMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.RomMode)) datHeader.RomMode = DatHeaderMappings[DatHeaderField.RomMode].AsMergingFlag(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.BiosMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.BiosMode)) datHeader.BiosMode = DatHeaderMappings[DatHeaderField.BiosMode].AsMergingFlag(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.SampleMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.SampleMode)) datHeader.SampleMode = DatHeaderMappings[DatHeaderField.SampleMode].AsMergingFlag(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.LockRomMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.LockRomMode)) datHeader.LockRomMode = DatHeaderMappings[DatHeaderField.LockRomMode].AsYesNo(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.LockBiosMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.LockBiosMode)) datHeader.LockBiosMode = DatHeaderMappings[DatHeaderField.LockBiosMode].AsYesNo(); - if (DatHeaderMappings.Keys.Contains(DatHeaderField.LockSampleMode)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.LockSampleMode)) datHeader.LockSampleMode = DatHeaderMappings[DatHeaderField.LockSampleMode].AsYesNo(); #endregion #region OfflineList - if (DatHeaderMappings.Keys.Contains(DatHeaderField.System)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.System)) datHeader.System = DatHeaderMappings[DatHeaderField.System]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.ScreenshotsWidth)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.ScreenshotsWidth)) datHeader.ScreenshotsWidth = DatHeaderMappings[DatHeaderField.ScreenshotsWidth]; - if (DatHeaderMappings.Keys.Contains(DatHeaderField.ScreenshotsHeight)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.ScreenshotsHeight)) datHeader.ScreenshotsHeight = DatHeaderMappings[DatHeaderField.ScreenshotsHeight]; // TODO: Add DatHeader_Info* // TDOO: Add DatHeader_CanOpen* - if (DatHeaderMappings.Keys.Contains(DatHeaderField.RomTitle)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.RomTitle)) datHeader.RomTitle = DatHeaderMappings[DatHeaderField.RomTitle]; #endregion #region RomCenter - if (DatHeaderMappings.Keys.Contains(DatHeaderField.RomCenterVersion)) + if (DatHeaderMappings.ContainsKey(DatHeaderField.RomCenterVersion)) datHeader.RomCenterVersion = DatHeaderMappings[DatHeaderField.RomCenterVersion]; #endregion @@ -234,7 +234,7 @@ namespace SabreTools.DatFiles #region Common - if (DatItemMappings.Keys.Contains(DatItemField.Name)) + if (DatItemMappings.ContainsKey(DatItemField.Name)) datItem.SetName(DatItemMappings[DatItemField.Name]); #endregion @@ -290,142 +290,142 @@ namespace SabreTools.DatFiles #region Common - if (MachineMappings.Keys.Contains(MachineField.Name)) + if (MachineMappings.ContainsKey(MachineField.Name)) machine.Name = MachineMappings[MachineField.Name]; - if (MachineMappings.Keys.Contains(MachineField.Comment)) + if (MachineMappings.ContainsKey(MachineField.Comment)) machine.Comment = MachineMappings[MachineField.Comment]; - if (MachineMappings.Keys.Contains(MachineField.Description)) + if (MachineMappings.ContainsKey(MachineField.Description)) machine.Description = MachineMappings[MachineField.Description]; - if (MachineMappings.Keys.Contains(MachineField.Year)) + if (MachineMappings.ContainsKey(MachineField.Year)) machine.Year = MachineMappings[MachineField.Year]; - if (MachineMappings.Keys.Contains(MachineField.Manufacturer)) + if (MachineMappings.ContainsKey(MachineField.Manufacturer)) machine.Manufacturer = MachineMappings[MachineField.Manufacturer]; - if (MachineMappings.Keys.Contains(MachineField.Publisher)) + if (MachineMappings.ContainsKey(MachineField.Publisher)) machine.Publisher = MachineMappings[MachineField.Publisher]; - if (MachineMappings.Keys.Contains(MachineField.Category)) + if (MachineMappings.ContainsKey(MachineField.Category)) machine.Category = MachineMappings[MachineField.Category]; - if (MachineMappings.Keys.Contains(MachineField.RomOf)) + if (MachineMappings.ContainsKey(MachineField.RomOf)) machine.RomOf = MachineMappings[MachineField.RomOf]; - if (MachineMappings.Keys.Contains(MachineField.CloneOf)) + if (MachineMappings.ContainsKey(MachineField.CloneOf)) machine.CloneOf = MachineMappings[MachineField.CloneOf]; - if (MachineMappings.Keys.Contains(MachineField.SampleOf)) + if (MachineMappings.ContainsKey(MachineField.SampleOf)) machine.SampleOf = MachineMappings[MachineField.SampleOf]; - if (MachineMappings.Keys.Contains(MachineField.Type)) + if (MachineMappings.ContainsKey(MachineField.Type)) machine.MachineType = MachineMappings[MachineField.Type].AsMachineType(); #endregion #region AttractMode - if (MachineMappings.Keys.Contains(MachineField.Players)) + if (MachineMappings.ContainsKey(MachineField.Players)) machine.Players = MachineMappings[MachineField.Players]; - if (MachineMappings.Keys.Contains(MachineField.Rotation)) + if (MachineMappings.ContainsKey(MachineField.Rotation)) machine.Rotation = MachineMappings[MachineField.Rotation]; - if (MachineMappings.Keys.Contains(MachineField.Control)) + if (MachineMappings.ContainsKey(MachineField.Control)) machine.Control = MachineMappings[MachineField.Control]; - if (MachineMappings.Keys.Contains(MachineField.Status)) + if (MachineMappings.ContainsKey(MachineField.Status)) machine.Status = MachineMappings[MachineField.Status]; - if (MachineMappings.Keys.Contains(MachineField.DisplayCount)) + if (MachineMappings.ContainsKey(MachineField.DisplayCount)) machine.DisplayCount = MachineMappings[MachineField.DisplayCount]; - if (MachineMappings.Keys.Contains(MachineField.DisplayType)) + if (MachineMappings.ContainsKey(MachineField.DisplayType)) machine.DisplayType = MachineMappings[MachineField.DisplayType]; - if (MachineMappings.Keys.Contains(MachineField.Buttons)) + if (MachineMappings.ContainsKey(MachineField.Buttons)) machine.Buttons = MachineMappings[MachineField.Buttons]; #endregion #region ListXML - if (MachineMappings.Keys.Contains(MachineField.History)) + if (MachineMappings.ContainsKey(MachineField.History)) machine.History = MachineMappings[MachineField.History]; - if (MachineMappings.Keys.Contains(MachineField.SourceFile)) + if (MachineMappings.ContainsKey(MachineField.SourceFile)) machine.SourceFile = MachineMappings[MachineField.SourceFile]; - if (MachineMappings.Keys.Contains(MachineField.Runnable)) + if (MachineMappings.ContainsKey(MachineField.Runnable)) machine.Runnable = MachineMappings[MachineField.Runnable].AsRunnable(); #endregion #region Logiqx - if (MachineMappings.Keys.Contains(MachineField.Board)) + if (MachineMappings.ContainsKey(MachineField.Board)) machine.Board = MachineMappings[MachineField.Board]; - if (MachineMappings.Keys.Contains(MachineField.RebuildTo)) + if (MachineMappings.ContainsKey(MachineField.RebuildTo)) machine.RebuildTo = MachineMappings[MachineField.RebuildTo]; - if (MachineMappings.Keys.Contains(MachineField.NoIntroId)) + if (MachineMappings.ContainsKey(MachineField.NoIntroId)) machine.NoIntroId = MachineMappings[MachineField.NoIntroId]; - if (MachineMappings.Keys.Contains(MachineField.NoIntroCloneOfId)) + if (MachineMappings.ContainsKey(MachineField.NoIntroCloneOfId)) machine.NoIntroCloneOfId = MachineMappings[MachineField.NoIntroCloneOfId]; #endregion #region Logiqx EmuArc - if (MachineMappings.Keys.Contains(MachineField.TitleID)) + if (MachineMappings.ContainsKey(MachineField.TitleID)) machine.TitleID = MachineMappings[MachineField.TitleID]; - if (MachineMappings.Keys.Contains(MachineField.Developer)) + if (MachineMappings.ContainsKey(MachineField.Developer)) machine.Developer = MachineMappings[MachineField.Developer]; - if (MachineMappings.Keys.Contains(MachineField.Genre)) + if (MachineMappings.ContainsKey(MachineField.Genre)) machine.Genre = MachineMappings[MachineField.Genre]; - if (MachineMappings.Keys.Contains(MachineField.Subgenre)) + if (MachineMappings.ContainsKey(MachineField.Subgenre)) machine.Subgenre = MachineMappings[MachineField.Subgenre]; - if (MachineMappings.Keys.Contains(MachineField.Ratings)) + if (MachineMappings.ContainsKey(MachineField.Ratings)) machine.Ratings = MachineMappings[MachineField.Ratings]; - if (MachineMappings.Keys.Contains(MachineField.Score)) + if (MachineMappings.ContainsKey(MachineField.Score)) machine.Score = MachineMappings[MachineField.Score]; - if (MachineMappings.Keys.Contains(MachineField.Enabled)) + if (MachineMappings.ContainsKey(MachineField.Enabled)) machine.Enabled = MachineMappings[MachineField.Enabled]; - if (MachineMappings.Keys.Contains(MachineField.CRC)) + if (MachineMappings.ContainsKey(MachineField.CRC)) machine.Crc = MachineMappings[MachineField.CRC].AsYesNo(); - if (MachineMappings.Keys.Contains(MachineField.RelatedTo)) + if (MachineMappings.ContainsKey(MachineField.RelatedTo)) machine.RelatedTo = MachineMappings[MachineField.RelatedTo]; #endregion #region OpenMSX - if (MachineMappings.Keys.Contains(MachineField.GenMSXID)) + if (MachineMappings.ContainsKey(MachineField.GenMSXID)) machine.GenMSXID = MachineMappings[MachineField.GenMSXID]; - if (MachineMappings.Keys.Contains(MachineField.System)) + if (MachineMappings.ContainsKey(MachineField.System)) machine.System = MachineMappings[MachineField.System]; - if (MachineMappings.Keys.Contains(MachineField.Country)) + if (MachineMappings.ContainsKey(MachineField.Country)) machine.Country = MachineMappings[MachineField.Country]; #endregion #region SoftwareList - if (MachineMappings.Keys.Contains(MachineField.Supported)) + if (MachineMappings.ContainsKey(MachineField.Supported)) machine.Supported = MachineMappings[MachineField.Supported].AsSupported(); #endregion @@ -437,7 +437,7 @@ namespace SabreTools.DatFiles /// Adjuster to remove replace fields in private void SetFields(Adjuster adjuster) { - if (DatItemMappings.Keys.Contains(DatItemField.Default)) + if (DatItemMappings.ContainsKey(DatItemField.Default)) adjuster.Default = DatItemMappings[DatItemField.Default].AsYesNo(); // Field.DatItem_Conditions does not apply here @@ -456,7 +456,7 @@ namespace SabreTools.DatFiles /// Analog to remove replace fields in private void SetFields(Analog analog) { - if (DatItemMappings.Keys.Contains(DatItemField.Analog_Mask)) + if (DatItemMappings.ContainsKey(DatItemField.Analog_Mask)) analog.Mask = DatItemMappings[DatItemField.Analog_Mask]; } @@ -466,31 +466,31 @@ namespace SabreTools.DatFiles /// Archive to remove replace fields in private void SetFields(Archive archive) { - if (DatItemMappings.Keys.Contains(DatItemField.Number)) + if (DatItemMappings.ContainsKey(DatItemField.Number)) archive.Number = DatItemMappings[DatItemField.Number]; - if (DatItemMappings.Keys.Contains(DatItemField.Clone)) + if (DatItemMappings.ContainsKey(DatItemField.Clone)) archive.CloneValue = DatItemMappings[DatItemField.Clone]; - if (DatItemMappings.Keys.Contains(DatItemField.RegParent)) + if (DatItemMappings.ContainsKey(DatItemField.RegParent)) archive.RegParent = DatItemMappings[DatItemField.RegParent]; - if (DatItemMappings.Keys.Contains(DatItemField.Region)) + if (DatItemMappings.ContainsKey(DatItemField.Region)) archive.Region = DatItemMappings[DatItemField.Region]; - if (DatItemMappings.Keys.Contains(DatItemField.Languages)) + if (DatItemMappings.ContainsKey(DatItemField.Languages)) archive.Languages = DatItemMappings[DatItemField.Languages]; - if (DatItemMappings.Keys.Contains(DatItemField.DevStatus)) + if (DatItemMappings.ContainsKey(DatItemField.DevStatus)) archive.DevStatus = DatItemMappings[DatItemField.DevStatus]; - if (DatItemMappings.Keys.Contains(DatItemField.Physical)) + if (DatItemMappings.ContainsKey(DatItemField.Physical)) archive.Physical = DatItemMappings[DatItemField.Physical]; - if (DatItemMappings.Keys.Contains(DatItemField.Complete)) + if (DatItemMappings.ContainsKey(DatItemField.Complete)) archive.Complete = DatItemMappings[DatItemField.Complete]; - if (DatItemMappings.Keys.Contains(DatItemField.Categories)) + if (DatItemMappings.ContainsKey(DatItemField.Categories)) archive.Categories = DatItemMappings[DatItemField.Categories]; } @@ -500,10 +500,10 @@ namespace SabreTools.DatFiles /// BiosSet to remove replace fields in private void SetFields(BiosSet biosSet) { - if (DatItemMappings.Keys.Contains(DatItemField.Description)) + if (DatItemMappings.ContainsKey(DatItemField.Description)) biosSet.Description = DatItemMappings[DatItemField.Description]; - if (DatItemMappings.Keys.Contains(DatItemField.Default)) + if (DatItemMappings.ContainsKey(DatItemField.Default)) biosSet.Default = DatItemMappings[DatItemField.Default].AsYesNo(); } @@ -513,13 +513,13 @@ namespace SabreTools.DatFiles /// Chip to remove replace fields in private void SetFields(Chip chip) { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) chip.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.ChipType)) + if (DatItemMappings.ContainsKey(DatItemField.ChipType)) chip.ChipType = DatItemMappings[DatItemField.ChipType].AsChipType(); - if (DatItemMappings.Keys.Contains(DatItemField.Clock)) + if (DatItemMappings.ContainsKey(DatItemField.Clock)) chip.Clock = Utilities.CleanLong(DatItemMappings[DatItemField.Clock]); } @@ -532,30 +532,30 @@ namespace SabreTools.DatFiles { if (sub) { - if (DatItemMappings.Keys.Contains(DatItemField.Condition_Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Condition_Tag)) condition.Tag = DatItemMappings[DatItemField.Condition_Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.Condition_Mask)) + if (DatItemMappings.ContainsKey(DatItemField.Condition_Mask)) condition.Mask = DatItemMappings[DatItemField.Condition_Mask]; - if (DatItemMappings.Keys.Contains(DatItemField.Condition_Relation)) + if (DatItemMappings.ContainsKey(DatItemField.Condition_Relation)) condition.Relation = DatItemMappings[DatItemField.Condition_Relation].AsRelation(); - if (DatItemMappings.Keys.Contains(DatItemField.Condition_Value)) + if (DatItemMappings.ContainsKey(DatItemField.Condition_Value)) condition.Value = DatItemMappings[DatItemField.Condition_Value]; } else { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) condition.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.Mask)) + if (DatItemMappings.ContainsKey(DatItemField.Mask)) condition.Mask = DatItemMappings[DatItemField.Mask]; - if (DatItemMappings.Keys.Contains(DatItemField.Relation)) + if (DatItemMappings.ContainsKey(DatItemField.Relation)) condition.Relation = DatItemMappings[DatItemField.Relation].AsRelation(); - if (DatItemMappings.Keys.Contains(DatItemField.Value)) + if (DatItemMappings.ContainsKey(DatItemField.Value)) condition.Value = DatItemMappings[DatItemField.Value]; } } @@ -566,10 +566,10 @@ namespace SabreTools.DatFiles /// Configuration to remove replace fields in private void SetFields(Configuration configuration) { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) configuration.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.Mask)) + if (DatItemMappings.ContainsKey(DatItemField.Mask)) configuration.Mask = DatItemMappings[DatItemField.Mask]; if (configuration.ConditionsSpecified) @@ -603,40 +603,40 @@ namespace SabreTools.DatFiles /// Control to remove replace fields in private void SetFields(Control control) { - if (DatItemMappings.Keys.Contains(DatItemField.Control_Type)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Type)) control.ControlType = DatItemMappings[DatItemField.Control_Type].AsControlType(); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Player)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Player)) control.Player = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Player]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Buttons)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Buttons)) control.Buttons = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Buttons]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_RequiredButtons)) + if (DatItemMappings.ContainsKey(DatItemField.Control_RequiredButtons)) control.RequiredButtons = Utilities.CleanLong(DatItemMappings[DatItemField.Control_RequiredButtons]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Minimum)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Minimum)) control.Minimum = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Minimum]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Maximum)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Maximum)) control.Maximum = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Maximum]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Sensitivity)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Sensitivity)) control.Sensitivity = Utilities.CleanLong(DatItemMappings[DatItemField.Control_Sensitivity]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_KeyDelta)) + if (DatItemMappings.ContainsKey(DatItemField.Control_KeyDelta)) control.KeyDelta = Utilities.CleanLong(DatItemMappings[DatItemField.Control_KeyDelta]); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Reverse)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Reverse)) control.Reverse = DatItemMappings[DatItemField.Control_Reverse].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Control_Ways)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Ways)) control.Ways = DatItemMappings[DatItemField.Control_Ways]; - if (DatItemMappings.Keys.Contains(DatItemField.Control_Ways2)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Ways2)) control.Ways2 = DatItemMappings[DatItemField.Control_Ways2]; - if (DatItemMappings.Keys.Contains(DatItemField.Control_Ways3)) + if (DatItemMappings.ContainsKey(DatItemField.Control_Ways3)) control.Ways3 = DatItemMappings[DatItemField.Control_Ways3]; } @@ -646,13 +646,13 @@ namespace SabreTools.DatFiles /// DataArea to remove replace fields in private void SetFields(DataArea dataArea) { - if (DatItemMappings.Keys.Contains(DatItemField.AreaSize)) + if (DatItemMappings.ContainsKey(DatItemField.AreaSize)) dataArea.Size = Utilities.CleanLong(DatItemMappings[DatItemField.AreaSize]); - if (DatItemMappings.Keys.Contains(DatItemField.AreaWidth)) + if (DatItemMappings.ContainsKey(DatItemField.AreaWidth)) dataArea.Width = Utilities.CleanLong(DatItemMappings[DatItemField.AreaWidth]); - if (DatItemMappings.Keys.Contains(DatItemField.AreaEndianness)) + if (DatItemMappings.ContainsKey(DatItemField.AreaEndianness)) dataArea.Endianness = DatItemMappings[DatItemField.AreaEndianness].AsEndianness(); } @@ -662,19 +662,19 @@ namespace SabreTools.DatFiles /// Device to remove replace fields in private void SetFields(Device device) { - if (DatItemMappings.Keys.Contains(DatItemField.DeviceType)) + if (DatItemMappings.ContainsKey(DatItemField.DeviceType)) device.DeviceType = DatItemMappings[DatItemField.DeviceType].AsDeviceType(); - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) device.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.FixedImage)) + if (DatItemMappings.ContainsKey(DatItemField.FixedImage)) device.FixedImage = DatItemMappings[DatItemField.FixedImage]; - if (DatItemMappings.Keys.Contains(DatItemField.Mandatory)) + if (DatItemMappings.ContainsKey(DatItemField.Mandatory)) device.Mandatory = Utilities.CleanLong(DatItemMappings[DatItemField.Mandatory]); - if (DatItemMappings.Keys.Contains(DatItemField.Interface)) + if (DatItemMappings.ContainsKey(DatItemField.Interface)) device.Interface = DatItemMappings[DatItemField.Interface]; if (device.InstancesSpecified) @@ -702,10 +702,10 @@ namespace SabreTools.DatFiles { #region Common - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) dipSwitch.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.Mask)) + if (DatItemMappings.ContainsKey(DatItemField.Mask)) dipSwitch.Mask = DatItemMappings[DatItemField.Mask]; if (dipSwitch.ConditionsSpecified) @@ -737,8 +737,7 @@ namespace SabreTools.DatFiles #region SoftwareList // Handle Part-specific fields - if (dipSwitch.Part == null) - dipSwitch.Part = new Part(); + dipSwitch.Part ??= new Part(); SetFields(dipSwitch.Part); @@ -753,41 +752,39 @@ namespace SabreTools.DatFiles { #region Common - if (DatItemMappings.Keys.Contains(DatItemField.MD5)) + if (DatItemMappings.ContainsKey(DatItemField.MD5)) disk.MD5 = DatItemMappings[DatItemField.MD5]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA1)) + if (DatItemMappings.ContainsKey(DatItemField.SHA1)) disk.SHA1 = DatItemMappings[DatItemField.SHA1]; - if (DatItemMappings.Keys.Contains(DatItemField.Merge)) + if (DatItemMappings.ContainsKey(DatItemField.Merge)) disk.MergeTag = DatItemMappings[DatItemField.Merge]; - if (DatItemMappings.Keys.Contains(DatItemField.Region)) + if (DatItemMappings.ContainsKey(DatItemField.Region)) disk.Region = DatItemMappings[DatItemField.Region]; - if (DatItemMappings.Keys.Contains(DatItemField.Index)) + if (DatItemMappings.ContainsKey(DatItemField.Index)) disk.Index = DatItemMappings[DatItemField.Index]; - if (DatItemMappings.Keys.Contains(DatItemField.Writable)) + if (DatItemMappings.ContainsKey(DatItemField.Writable)) disk.Writable = DatItemMappings[DatItemField.Writable].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Status)) + if (DatItemMappings.ContainsKey(DatItemField.Status)) disk.ItemStatus = DatItemMappings[DatItemField.Status].AsItemStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.Optional)) + if (DatItemMappings.ContainsKey(DatItemField.Optional)) disk.Optional = DatItemMappings[DatItemField.Optional].AsYesNo(); #endregion #region SoftwareList - if (disk.DiskArea == null) - disk.DiskArea = new DiskArea(); + disk.DiskArea ??= new DiskArea(); SetFields(disk.DiskArea); - if (disk.Part == null) - disk.Part = new Part(); + disk.Part ??= new Part(); SetFields(disk.Part); @@ -800,7 +797,7 @@ namespace SabreTools.DatFiles /// DiskArea to remove replace fields in private void SetFields(DiskArea diskArea) { - if (DatItemMappings.Keys.Contains(DatItemField.AreaName)) + if (DatItemMappings.ContainsKey(DatItemField.AreaName)) diskArea.Name = DatItemMappings[DatItemField.AreaName]; } @@ -810,46 +807,46 @@ namespace SabreTools.DatFiles /// Display to remove replace fields in private void SetFields(Display display) { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) display.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.DisplayType)) + if (DatItemMappings.ContainsKey(DatItemField.DisplayType)) display.DisplayType = DatItemMappings[DatItemField.DisplayType].AsDisplayType(); - if (DatItemMappings.Keys.Contains(DatItemField.Rotate)) + if (DatItemMappings.ContainsKey(DatItemField.Rotate)) display.Rotate = Utilities.CleanLong(DatItemMappings[DatItemField.Rotate]); - if (DatItemMappings.Keys.Contains(DatItemField.FlipX)) + if (DatItemMappings.ContainsKey(DatItemField.FlipX)) display.FlipX = DatItemMappings[DatItemField.FlipX].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Width)) + if (DatItemMappings.ContainsKey(DatItemField.Width)) display.Width = Utilities.CleanLong(DatItemMappings[DatItemField.Width]); - if (DatItemMappings.Keys.Contains(DatItemField.Height)) + if (DatItemMappings.ContainsKey(DatItemField.Height)) display.Height = Utilities.CleanLong(DatItemMappings[DatItemField.Height]); - if (DatItemMappings.Keys.Contains(DatItemField.Refresh)) + if (DatItemMappings.ContainsKey(DatItemField.Refresh)) display.Refresh = Utilities.CleanDouble(DatItemMappings[DatItemField.Refresh]); - if (DatItemMappings.Keys.Contains(DatItemField.PixClock)) + if (DatItemMappings.ContainsKey(DatItemField.PixClock)) display.PixClock = Utilities.CleanLong(DatItemMappings[DatItemField.PixClock]); - if (DatItemMappings.Keys.Contains(DatItemField.HTotal)) + if (DatItemMappings.ContainsKey(DatItemField.HTotal)) display.HTotal = Utilities.CleanLong(DatItemMappings[DatItemField.HTotal]); - if (DatItemMappings.Keys.Contains(DatItemField.HBEnd)) + if (DatItemMappings.ContainsKey(DatItemField.HBEnd)) display.HBEnd = Utilities.CleanLong(DatItemMappings[DatItemField.HBEnd]); - if (DatItemMappings.Keys.Contains(DatItemField.HBStart)) + if (DatItemMappings.ContainsKey(DatItemField.HBStart)) display.HBStart = Utilities.CleanLong(DatItemMappings[DatItemField.HBStart]); - if (DatItemMappings.Keys.Contains(DatItemField.VTotal)) + if (DatItemMappings.ContainsKey(DatItemField.VTotal)) display.VTotal = Utilities.CleanLong(DatItemMappings[DatItemField.VTotal]); - if (DatItemMappings.Keys.Contains(DatItemField.VBEnd)) + if (DatItemMappings.ContainsKey(DatItemField.VBEnd)) display.VBEnd = Utilities.CleanLong(DatItemMappings[DatItemField.VBEnd]); - if (DatItemMappings.Keys.Contains(DatItemField.VBStart)) + if (DatItemMappings.ContainsKey(DatItemField.VBStart)) display.VBStart = Utilities.CleanLong(DatItemMappings[DatItemField.VBStart]); } @@ -859,28 +856,28 @@ namespace SabreTools.DatFiles /// Driver to remove replace fields in private void SetFields(Driver driver) { - if (DatItemMappings.Keys.Contains(DatItemField.SupportStatus)) + if (DatItemMappings.ContainsKey(DatItemField.SupportStatus)) driver.Status = DatItemMappings[DatItemField.SupportStatus].AsSupportStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.EmulationStatus)) + if (DatItemMappings.ContainsKey(DatItemField.EmulationStatus)) driver.Emulation = DatItemMappings[DatItemField.EmulationStatus].AsSupportStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.CocktailStatus)) + if (DatItemMappings.ContainsKey(DatItemField.CocktailStatus)) driver.Cocktail = DatItemMappings[DatItemField.CocktailStatus].AsSupportStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.SaveStateStatus)) + if (DatItemMappings.ContainsKey(DatItemField.SaveStateStatus)) driver.SaveState = DatItemMappings[DatItemField.SaveStateStatus].AsSupported(); - if (DatItemMappings.Keys.Contains(DatItemField.RequiresArtwork)) + if (DatItemMappings.ContainsKey(DatItemField.RequiresArtwork)) driver.RequiresArtwork = DatItemMappings[DatItemField.RequiresArtwork].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Unofficial)) + if (DatItemMappings.ContainsKey(DatItemField.Unofficial)) driver.Unofficial = DatItemMappings[DatItemField.Unofficial].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.NoSoundHardware)) + if (DatItemMappings.ContainsKey(DatItemField.NoSoundHardware)) driver.NoSoundHardware = DatItemMappings[DatItemField.NoSoundHardware].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Incomplete)) + if (DatItemMappings.ContainsKey(DatItemField.Incomplete)) driver.Incomplete = DatItemMappings[DatItemField.Incomplete].AsYesNo(); } @@ -890,7 +887,7 @@ namespace SabreTools.DatFiles /// Extension to remove replace fields in private void SetFields(Extension extension) { - if (DatItemMappings.Keys.Contains(DatItemField.Extension_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Extension_Name)) extension.Name = DatItemMappings[DatItemField.Extension_Name]; } @@ -900,13 +897,13 @@ namespace SabreTools.DatFiles /// Feature to remove replace fields in private void SetFields(Feature feature) { - if (DatItemMappings.Keys.Contains(DatItemField.FeatureType)) + if (DatItemMappings.ContainsKey(DatItemField.FeatureType)) feature.Type = DatItemMappings[DatItemField.FeatureType].AsFeatureType(); - if (DatItemMappings.Keys.Contains(DatItemField.FeatureStatus)) + if (DatItemMappings.ContainsKey(DatItemField.FeatureStatus)) feature.Status = DatItemMappings[DatItemField.FeatureStatus].AsFeatureStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.FeatureOverall)) + if (DatItemMappings.ContainsKey(DatItemField.FeatureOverall)) feature.Overall = DatItemMappings[DatItemField.FeatureOverall].AsFeatureStatus(); } @@ -916,7 +913,7 @@ namespace SabreTools.DatFiles /// Info to remove replace fields in private void SetFields(Info info) { - if (DatItemMappings.Keys.Contains(DatItemField.Value)) + if (DatItemMappings.ContainsKey(DatItemField.Value)) info.Value = DatItemMappings[DatItemField.Value]; } @@ -926,16 +923,16 @@ namespace SabreTools.DatFiles /// Input to remove replace fields in private void SetFields(Input input) { - if (DatItemMappings.Keys.Contains(DatItemField.Service)) + if (DatItemMappings.ContainsKey(DatItemField.Service)) input.Service = DatItemMappings[DatItemField.Service].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Tilt)) + if (DatItemMappings.ContainsKey(DatItemField.Tilt)) input.Tilt = DatItemMappings[DatItemField.Tilt].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Players)) + if (DatItemMappings.ContainsKey(DatItemField.Players)) input.Players = Utilities.CleanLong(DatItemMappings[DatItemField.Players]); - if (DatItemMappings.Keys.Contains(DatItemField.Coins)) + if (DatItemMappings.ContainsKey(DatItemField.Coins)) input.Coins = Utilities.CleanLong(DatItemMappings[DatItemField.Coins]); if (input.ControlsSpecified) @@ -953,10 +950,10 @@ namespace SabreTools.DatFiles /// Instance to remove replace fields in private void SetFields(Instance instance) { - if (DatItemMappings.Keys.Contains(DatItemField.Instance_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Instance_Name)) instance.BriefName = DatItemMappings[DatItemField.Instance_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.Instance_BriefName)) + if (DatItemMappings.ContainsKey(DatItemField.Instance_BriefName)) instance.BriefName = DatItemMappings[DatItemField.Instance_BriefName]; } @@ -966,13 +963,13 @@ namespace SabreTools.DatFiles /// Location to remove replace fields in private void SetFields(Location location) { - if (DatItemMappings.Keys.Contains(DatItemField.Location_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Location_Name)) location.Name = DatItemMappings[DatItemField.Location_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.Location_Number)) + if (DatItemMappings.ContainsKey(DatItemField.Location_Number)) location.Number = Utilities.CleanLong(DatItemMappings[DatItemField.Location_Number]); - if (DatItemMappings.Keys.Contains(DatItemField.Location_Inverted)) + if (DatItemMappings.ContainsKey(DatItemField.Location_Inverted)) location.Inverted = DatItemMappings[DatItemField.Location_Inverted].AsYesNo(); } @@ -982,16 +979,16 @@ namespace SabreTools.DatFiles /// Media to remove replace fields in private void SetFields(Media media) { - if (DatItemMappings.Keys.Contains(DatItemField.MD5)) + if (DatItemMappings.ContainsKey(DatItemField.MD5)) media.MD5 = DatItemMappings[DatItemField.MD5]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA1)) + if (DatItemMappings.ContainsKey(DatItemField.SHA1)) media.SHA1 = DatItemMappings[DatItemField.SHA1]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA256)) + if (DatItemMappings.ContainsKey(DatItemField.SHA256)) media.SHA256 = DatItemMappings[DatItemField.SHA256]; - if (DatItemMappings.Keys.Contains(DatItemField.SpamSum)) + if (DatItemMappings.ContainsKey(DatItemField.SpamSum)) media.SpamSum = DatItemMappings[DatItemField.SpamSum]; } @@ -1001,10 +998,10 @@ namespace SabreTools.DatFiles /// Part to remove replace fields in private void SetFields(Part part) { - if (DatItemMappings.Keys.Contains(DatItemField.Part_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Part_Name)) part.Name = DatItemMappings[DatItemField.Part_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.Part_Interface)) + if (DatItemMappings.ContainsKey(DatItemField.Part_Interface)) part.Interface = DatItemMappings[DatItemField.Part_Interface]; if (part.FeaturesSpecified) @@ -1022,10 +1019,10 @@ namespace SabreTools.DatFiles /// PartFeature to remove replace fields in private void SetFields(PartFeature partFeature) { - if (DatItemMappings.Keys.Contains(DatItemField.Part_Feature_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Part_Feature_Name)) partFeature.Name = DatItemMappings[DatItemField.Part_Feature_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.Part_Feature_Value)) + if (DatItemMappings.ContainsKey(DatItemField.Part_Feature_Value)) partFeature.Value = DatItemMappings[DatItemField.Part_Feature_Value]; } @@ -1035,7 +1032,7 @@ namespace SabreTools.DatFiles /// Port to remove replace fields in private void SetFields(Port port) { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) port.Tag = DatItemMappings[DatItemField.Tag]; if (port.AnalogsSpecified) @@ -1053,10 +1050,10 @@ namespace SabreTools.DatFiles /// RamOption to remove replace fields in private void SetFields(RamOption ramOption) { - if (DatItemMappings.Keys.Contains(DatItemField.Default)) + if (DatItemMappings.ContainsKey(DatItemField.Default)) ramOption.Default = DatItemMappings[DatItemField.Default].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Content)) + if (DatItemMappings.ContainsKey(DatItemField.Content)) ramOption.Content = DatItemMappings[DatItemField.Content]; } @@ -1066,16 +1063,16 @@ namespace SabreTools.DatFiles /// Release to remove replace fields in private void SetFields(Release release) { - if (DatItemMappings.Keys.Contains(DatItemField.Region)) + if (DatItemMappings.ContainsKey(DatItemField.Region)) release.Region = DatItemMappings[DatItemField.Region]; - if (DatItemMappings.Keys.Contains(DatItemField.Language)) + if (DatItemMappings.ContainsKey(DatItemField.Language)) release.Language = DatItemMappings[DatItemField.Language]; - if (DatItemMappings.Keys.Contains(DatItemField.Date)) + if (DatItemMappings.ContainsKey(DatItemField.Date)) release.Date = DatItemMappings[DatItemField.Date]; - if (DatItemMappings.Keys.Contains(DatItemField.Default)) + if (DatItemMappings.ContainsKey(DatItemField.Default)) release.Default = DatItemMappings[DatItemField.Default].AsYesNo(); } @@ -1087,122 +1084,120 @@ namespace SabreTools.DatFiles { #region Common - if (DatItemMappings.Keys.Contains(DatItemField.Bios)) + if (DatItemMappings.ContainsKey(DatItemField.Bios)) rom.Bios = DatItemMappings[DatItemField.Bios]; - if (DatItemMappings.Keys.Contains(DatItemField.Size)) + if (DatItemMappings.ContainsKey(DatItemField.Size)) rom.Size = Utilities.CleanLong(DatItemMappings[DatItemField.Size]); - if (DatItemMappings.Keys.Contains(DatItemField.CRC)) + if (DatItemMappings.ContainsKey(DatItemField.CRC)) rom.CRC = DatItemMappings[DatItemField.CRC]; - if (DatItemMappings.Keys.Contains(DatItemField.MD5)) + if (DatItemMappings.ContainsKey(DatItemField.MD5)) rom.MD5 = DatItemMappings[DatItemField.MD5]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA1)) + if (DatItemMappings.ContainsKey(DatItemField.SHA1)) rom.SHA1 = DatItemMappings[DatItemField.SHA1]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA256)) + if (DatItemMappings.ContainsKey(DatItemField.SHA256)) rom.SHA256 = DatItemMappings[DatItemField.SHA256]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA384)) + if (DatItemMappings.ContainsKey(DatItemField.SHA384)) rom.SHA384 = DatItemMappings[DatItemField.SHA384]; - if (DatItemMappings.Keys.Contains(DatItemField.SHA512)) + if (DatItemMappings.ContainsKey(DatItemField.SHA512)) rom.SHA512 = DatItemMappings[DatItemField.SHA512]; - if (DatItemMappings.Keys.Contains(DatItemField.SpamSum)) + if (DatItemMappings.ContainsKey(DatItemField.SpamSum)) rom.SpamSum = DatItemMappings[DatItemField.SpamSum]; - if (DatItemMappings.Keys.Contains(DatItemField.Merge)) + if (DatItemMappings.ContainsKey(DatItemField.Merge)) rom.MergeTag = DatItemMappings[DatItemField.Merge]; - if (DatItemMappings.Keys.Contains(DatItemField.Region)) + if (DatItemMappings.ContainsKey(DatItemField.Region)) rom.Region = DatItemMappings[DatItemField.Region]; - if (DatItemMappings.Keys.Contains(DatItemField.Offset)) + if (DatItemMappings.ContainsKey(DatItemField.Offset)) rom.Offset = DatItemMappings[DatItemField.Offset]; - if (DatItemMappings.Keys.Contains(DatItemField.Date)) + if (DatItemMappings.ContainsKey(DatItemField.Date)) rom.Date = DatItemMappings[DatItemField.Date]; - if (DatItemMappings.Keys.Contains(DatItemField.Status)) + if (DatItemMappings.ContainsKey(DatItemField.Status)) rom.ItemStatus = DatItemMappings[DatItemField.Status].AsItemStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.Optional)) + if (DatItemMappings.ContainsKey(DatItemField.Optional)) rom.Optional = DatItemMappings[DatItemField.Optional].AsYesNo(); - if (DatItemMappings.Keys.Contains(DatItemField.Inverted)) + if (DatItemMappings.ContainsKey(DatItemField.Inverted)) rom.Inverted = DatItemMappings[DatItemField.Optional].AsYesNo(); #endregion #region Archive.org - if (DatItemMappings.Keys.Contains(DatItemField.ArchiveDotOrgSource)) + if (DatItemMappings.ContainsKey(DatItemField.ArchiveDotOrgSource)) rom.ArchiveDotOrgSource = DatItemMappings[DatItemField.ArchiveDotOrgSource]; - if (DatItemMappings.Keys.Contains(DatItemField.ArchiveDotOrgFormat)) + if (DatItemMappings.ContainsKey(DatItemField.ArchiveDotOrgFormat)) rom.ArchiveDotOrgFormat = DatItemMappings[DatItemField.ArchiveDotOrgFormat]; - if (DatItemMappings.Keys.Contains(DatItemField.OriginalFilename)) + if (DatItemMappings.ContainsKey(DatItemField.OriginalFilename)) rom.OriginalFilename = DatItemMappings[DatItemField.OriginalFilename]; - if (DatItemMappings.Keys.Contains(DatItemField.Rotation)) + if (DatItemMappings.ContainsKey(DatItemField.Rotation)) rom.Rotation = DatItemMappings[DatItemField.Rotation]; - if (DatItemMappings.Keys.Contains(DatItemField.Summation)) + if (DatItemMappings.ContainsKey(DatItemField.Summation)) rom.Summation = DatItemMappings[DatItemField.Summation]; #endregion #region AttractMode - if (DatItemMappings.Keys.Contains(DatItemField.AltName)) + if (DatItemMappings.ContainsKey(DatItemField.AltName)) rom.AltName = DatItemMappings[DatItemField.AltName]; - if (DatItemMappings.Keys.Contains(DatItemField.AltTitle)) + if (DatItemMappings.ContainsKey(DatItemField.AltTitle)) rom.AltTitle = DatItemMappings[DatItemField.AltTitle]; - if (DatItemMappings.Keys.Contains(DatItemField.MIA)) + if (DatItemMappings.ContainsKey(DatItemField.MIA)) rom.MIA = DatItemMappings[DatItemField.MIA].AsYesNo(); #endregion #region OpenMSX - if (DatItemMappings.Keys.Contains(DatItemField.Original)) + if (DatItemMappings.ContainsKey(DatItemField.Original)) rom.Original = new Original() { Content = DatItemMappings[DatItemField.Original] }; - if (DatItemMappings.Keys.Contains(DatItemField.OpenMSXSubType)) + if (DatItemMappings.ContainsKey(DatItemField.OpenMSXSubType)) rom.OpenMSXSubType = DatItemMappings[DatItemField.OpenMSXSubType].AsOpenMSXSubType(); - if (DatItemMappings.Keys.Contains(DatItemField.OpenMSXType)) + if (DatItemMappings.ContainsKey(DatItemField.OpenMSXType)) rom.OpenMSXType = DatItemMappings[DatItemField.OpenMSXType]; - if (DatItemMappings.Keys.Contains(DatItemField.Remark)) + if (DatItemMappings.ContainsKey(DatItemField.Remark)) rom.Remark = DatItemMappings[DatItemField.Remark]; - if (DatItemMappings.Keys.Contains(DatItemField.Boot)) + if (DatItemMappings.ContainsKey(DatItemField.Boot)) rom.Boot = DatItemMappings[DatItemField.Boot]; #endregion #region SoftwareList - if (DatItemMappings.Keys.Contains(DatItemField.LoadFlag)) + if (DatItemMappings.ContainsKey(DatItemField.LoadFlag)) rom.LoadFlag = DatItemMappings[DatItemField.LoadFlag].AsLoadFlag(); - if (DatItemMappings.Keys.Contains(DatItemField.Value)) + if (DatItemMappings.ContainsKey(DatItemField.Value)) rom.Value = DatItemMappings[DatItemField.Value]; - if (rom.DataArea == null) - rom.DataArea = new DataArea(); + rom.DataArea ??= new DataArea(); SetFields(rom.DataArea); - if (rom.Part == null) - rom.Part = new Part(); + rom.Part ??= new Part(); SetFields(rom.Part); @@ -1215,13 +1210,13 @@ namespace SabreTools.DatFiles /// Setting to remove replace fields in private void SetFields(Setting setting) { - if (DatItemMappings.Keys.Contains(DatItemField.Setting_Name)) + if (DatItemMappings.ContainsKey(DatItemField.Setting_Name)) setting.Name = DatItemMappings[DatItemField.Setting_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.Setting_Value)) + if (DatItemMappings.ContainsKey(DatItemField.Setting_Value)) setting.Value = DatItemMappings[DatItemField.Setting_Value]; - if (DatItemMappings.Keys.Contains(DatItemField.Setting_Default)) + if (DatItemMappings.ContainsKey(DatItemField.Setting_Default)) setting.Default = DatItemMappings[DatItemField.Setting_Default].AsYesNo(); if (setting.ConditionsSpecified) @@ -1239,7 +1234,7 @@ namespace SabreTools.DatFiles /// SharedFeature to remove replace fields in private void SetFields(SharedFeature sharedFeature) { - if (DatItemMappings.Keys.Contains(DatItemField.Value)) + if (DatItemMappings.ContainsKey(DatItemField.Value)) sharedFeature.Value = DatItemMappings[DatItemField.Value]; } @@ -1264,13 +1259,13 @@ namespace SabreTools.DatFiles /// SlotOption to remove replace fields in private void SetFields(SlotOption slotOption) { - if (DatItemMappings.Keys.Contains(DatItemField.SlotOption_Name)) + if (DatItemMappings.ContainsKey(DatItemField.SlotOption_Name)) slotOption.Name = DatItemMappings[DatItemField.SlotOption_Name]; - if (DatItemMappings.Keys.Contains(DatItemField.SlotOption_DeviceName)) + if (DatItemMappings.ContainsKey(DatItemField.SlotOption_DeviceName)) slotOption.DeviceName = DatItemMappings[DatItemField.SlotOption_DeviceName]; - if (DatItemMappings.Keys.Contains(DatItemField.SlotOption_Default)) + if (DatItemMappings.ContainsKey(DatItemField.SlotOption_Default)) slotOption.Default = DatItemMappings[DatItemField.SlotOption_Default].AsYesNo(); } @@ -1280,13 +1275,13 @@ namespace SabreTools.DatFiles /// SoftwareList to remove replace fields in private void SetFields(SoftwareList softwareList) { - if (DatItemMappings.Keys.Contains(DatItemField.Tag)) + if (DatItemMappings.ContainsKey(DatItemField.Tag)) softwareList.Tag = DatItemMappings[DatItemField.Tag]; - if (DatItemMappings.Keys.Contains(DatItemField.SoftwareListStatus)) + if (DatItemMappings.ContainsKey(DatItemField.SoftwareListStatus)) softwareList.Status = DatItemMappings[DatItemField.SoftwareListStatus].AsSoftwareListStatus(); - if (DatItemMappings.Keys.Contains(DatItemField.Filter)) + if (DatItemMappings.ContainsKey(DatItemField.Filter)) softwareList.Filter = DatItemMappings[DatItemField.Filter]; } @@ -1296,7 +1291,7 @@ namespace SabreTools.DatFiles /// Sound to remove replace fields in private void SetFields(Sound sound) { - if (DatItemMappings.Keys.Contains(DatItemField.Channels)) + if (DatItemMappings.ContainsKey(DatItemField.Channels)) sound.Channels = Utilities.CleanLong(DatItemMappings[DatItemField.Channels]); } } diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index 6d4995d5..730fbd22 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -120,7 +120,7 @@ namespace SabreTools.DatItems /// Static logger for static methods /// [JsonIgnore, XmlIgnore] - protected static Logger staticLogger = new Logger(); + protected static Logger staticLogger = new(); #endregion @@ -207,31 +207,23 @@ namespace SabreTools.DatItems /// DatItem of the specific internal type that corresponds to the inputs public static DatItem Create(BaseFile baseFile) { - switch (baseFile.Type) + return baseFile.Type switch { - case FileType.AaruFormat: - return new Media(baseFile); - - case FileType.CHD: - return new Disk(baseFile); - - case FileType.GZipArchive: - case FileType.LRZipArchive: - case FileType.LZ4Archive: - case FileType.None: - case FileType.RarArchive: - case FileType.SevenZipArchive: - case FileType.TapeArchive: - case FileType.XZArchive: - case FileType.ZipArchive: - case FileType.ZPAQArchive: - case FileType.ZstdArchive: - return new Rom(baseFile); - - case FileType.Folder: - default: - return null; - } + FileType.AaruFormat => new Media(baseFile), + FileType.CHD => new Disk(baseFile), + FileType.GZipArchive => new Rom(baseFile), + FileType.LRZipArchive => new Rom(baseFile), + FileType.LZ4Archive => new Rom(baseFile), + FileType.None => new Rom(baseFile), + FileType.RarArchive => new Rom(baseFile), + FileType.SevenZipArchive => new Rom(baseFile), + FileType.TapeArchive => new Rom(baseFile), + FileType.XZArchive => new Rom(baseFile), + FileType.ZipArchive => new Rom(baseFile), + FileType.ZPAQArchive => new Rom(baseFile), + FileType.ZstdArchive => new Rom(baseFile), + _ => null, + }; } #endregion @@ -332,7 +324,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanCRC32(string hash) + protected static string CleanCRC32(string hash) { return CleanHashData(hash, Constants.CRCLength); } @@ -342,7 +334,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanMD5(string hash) + protected static string CleanMD5(string hash) { return CleanHashData(hash, Constants.MD5Length); } @@ -352,7 +344,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanSHA1(string hash) + protected static string CleanSHA1(string hash) { return CleanHashData(hash, Constants.SHA1Length); } @@ -362,7 +354,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanSHA256(string hash) + protected static string CleanSHA256(string hash) { return CleanHashData(hash, Constants.SHA256Length); } @@ -372,7 +364,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanSHA384(string hash) + protected static string CleanSHA384(string hash) { return CleanHashData(hash, Constants.SHA384Length); } @@ -382,7 +374,7 @@ namespace SabreTools.DatItems /// /// Hash string to sanitize /// Cleaned string - protected string CleanSHA512(string hash) + protected static string CleanSHA512(string hash) { return CleanHashData(hash, Constants.SHA512Length); } @@ -393,7 +385,7 @@ namespace SabreTools.DatItems /// Hash string to sanitize /// Amount of characters to pad to /// Cleaned string - private string CleanHashData(string hash, int padding) + private static string CleanHashData(string hash, int padding) { // If we have a known blank hash, return blank if (string.IsNullOrWhiteSpace(hash) || hash == "-" || hash == "_") @@ -463,8 +455,7 @@ namespace SabreTools.DatItems if (lower) key = key.ToLowerInvariant(); - if (key == null) - key = "null"; + key ??= "null"; break; @@ -494,8 +485,7 @@ namespace SabreTools.DatItems } // Double and triple check the key for corner cases - if (key == null) - key = string.Empty; + key ??= string.Empty; return key; } @@ -540,7 +530,7 @@ namespace SabreTools.DatItems return new ConcurrentList(); // Create output list - ConcurrentList outfiles = new ConcurrentList(); + ConcurrentList outfiles = new(); // Then deduplicate them by checking to see if data matches previous saved roms int nodumpCount = 0; @@ -652,7 +642,7 @@ namespace SabreTools.DatItems public static ConcurrentList ResolveNames(ConcurrentList infiles) { // Create the output list - ConcurrentList output = new ConcurrentList(); + ConcurrentList output = new(); // First we want to make sure the list is in alphabetical order Sort(ref infiles, true); @@ -763,7 +753,7 @@ namespace SabreTools.DatItems { try { - NaturalComparer nc = new NaturalComparer(); + NaturalComparer nc = new(); // If machine names match, more refinement is needed if (x.Machine.Name == y.Machine.Name) diff --git a/SabreTools.DatItems/Formats/Disk.cs b/SabreTools.DatItems/Formats/Disk.cs index 9752f864..a1be653e 100644 --- a/SabreTools.DatItems/Formats/Disk.cs +++ b/SabreTools.DatItems/Formats/Disk.cs @@ -379,8 +379,7 @@ namespace SabreTools.DatItems.Formats } // Double and triple check the key for corner cases - if (key == null) - key = string.Empty; + key ??= string.Empty; return key; } diff --git a/SabreTools.DatItems/Formats/File.cs b/SabreTools.DatItems/Formats/File.cs index 58d87825..41ff085b 100644 --- a/SabreTools.DatItems/Formats/File.cs +++ b/SabreTools.DatItems/Formats/File.cs @@ -358,8 +358,7 @@ namespace SabreTools.DatItems.Formats } // Double and triple check the key for corner cases - if (key == null) - key = string.Empty; + key ??= string.Empty; return key; } diff --git a/SabreTools.DatItems/Formats/Media.cs b/SabreTools.DatItems/Formats/Media.cs index f4a08216..8bd56da3 100644 --- a/SabreTools.DatItems/Formats/Media.cs +++ b/SabreTools.DatItems/Formats/Media.cs @@ -316,8 +316,7 @@ namespace SabreTools.DatItems.Formats } // Double and triple check the key for corner cases - if (key == null) - key = string.Empty; + key ??= string.Empty; return key; } diff --git a/SabreTools.DatItems/Formats/Rom.cs b/SabreTools.DatItems/Formats/Rom.cs index b3e6d7f9..6c83ccd6 100644 --- a/SabreTools.DatItems/Formats/Rom.cs +++ b/SabreTools.DatItems/Formats/Rom.cs @@ -693,8 +693,7 @@ namespace SabreTools.DatItems.Formats } // Double and triple check the key for corner cases - if (key == null) - key = string.Empty; + key ??= string.Empty; return key; } diff --git a/SabreTools.DatTools/DatFileTool.cs b/SabreTools.DatTools/DatFileTool.cs index 39dcb080..9b9615ab 100644 --- a/SabreTools.DatTools/DatFileTool.cs +++ b/SabreTools.DatTools/DatFileTool.cs @@ -22,7 +22,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -37,7 +37,7 @@ namespace SabreTools.DatTools Parallel.ForEach(keys, Globals.ParallelOptions, key => { ConcurrentList items = datFile.Items[key]; - ConcurrentList newItems = new ConcurrentList(); + ConcurrentList newItems = new(); foreach (DatItem item in items) { DatItem newItem = item; @@ -75,7 +75,7 @@ namespace SabreTools.DatTools List datItemFields, bool onlySame) { - InternalStopwatch watch = new InternalStopwatch($"Replacing items in '{intDat.Header.FileName}' from the base DAT"); + InternalStopwatch watch = new($"Replacing items in '{intDat.Header.FileName}' from the base DAT"); // If we are matching based on DatItem fields of any sort if (datItemFields.Any()) @@ -88,7 +88,7 @@ namespace SabreTools.DatTools Parallel.ForEach(intDat.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList datItems = intDat.Items[key]; - ConcurrentList newDatItems = new ConcurrentList(); + ConcurrentList newDatItems = new(); foreach (DatItem datItem in datItems) { ConcurrentList dupes = datFile.Items.GetDuplicates(datItem, sorted: true); @@ -118,11 +118,11 @@ namespace SabreTools.DatTools Parallel.ForEach(intDat.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList datItems = intDat.Items[key]; - ConcurrentList newDatItems = new ConcurrentList(); + ConcurrentList newDatItems = new(); foreach (DatItem datItem in datItems) { DatItem newDatItem = datItem.Clone() as DatItem; - if (datFile.Items.ContainsKey(key) && datFile.Items[key].Count() > 0) + if (datFile.Items.ContainsKey(key) && datFile.Items[key].Count > 0) Replacer.ReplaceFields(newDatItem.Machine, datFile.Items[key][0].Machine, machineFields, onlySame); newDatItems.Add(newDatItem); @@ -151,7 +151,7 @@ namespace SabreTools.DatTools else datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None); - InternalStopwatch watch = new InternalStopwatch($"Comparing '{intDat.Header.FileName}' to base DAT"); + InternalStopwatch watch = new($"Comparing '{intDat.Header.FileName}' to base DAT"); // For comparison's sake, we want to a the base bucketing if (useGames) @@ -195,7 +195,7 @@ namespace SabreTools.DatTools else { ConcurrentList datItems = intDat.Items[key]; - ConcurrentList keepDatItems = new ConcurrentList(); + ConcurrentList keepDatItems = new(); foreach (DatItem datItem in datItems) { if (!datFile.Items.HasDuplicates(datItem, true)) @@ -220,13 +220,13 @@ namespace SabreTools.DatTools public static List DiffCascade(DatFile datFile, List datHeaders) { // Create a list of DatData objects representing output files - List outDats = new List(); + List outDats = new(); // Ensure the current DatFile is sorted optimally datFile.Items.BucketBy(ItemKey.CRC, DedupeType.None); // Loop through each of the inputs and get or create a new DatData object - InternalStopwatch watch = new InternalStopwatch("Initializing and filling all output DATs"); + InternalStopwatch watch = new("Initializing and filling all output DATs"); // Create the DatFiles from the set of headers DatFile[] outDatsArray = new DatFile[datHeaders.Count]; @@ -262,7 +262,7 @@ namespace SabreTools.DatTools /// List of inputs to write out from public static DatFile DiffDuplicates(DatFile datFile, List inputs) { - InternalStopwatch watch = new InternalStopwatch("Initializing duplicate DAT"); + InternalStopwatch watch = new("Initializing duplicate DAT"); // Fill in any information not in the base DAT if (string.IsNullOrWhiteSpace(datFile.Header.FileName)) @@ -330,7 +330,7 @@ namespace SabreTools.DatTools /// List of inputs to write out from public static List DiffIndividuals(DatFile datFile, List inputs) { - InternalStopwatch watch = new InternalStopwatch("Initializing all individual DATs"); + InternalStopwatch watch = new("Initializing all individual DATs"); // Fill in any information not in the base DAT if (string.IsNullOrWhiteSpace(datFile.Header.FileName)) @@ -403,7 +403,7 @@ namespace SabreTools.DatTools /// List of inputs to write out from public static DatFile DiffNoDuplicates(DatFile datFile, List inputs) { - InternalStopwatch watch = new InternalStopwatch("Initializing no duplicate DAT"); + InternalStopwatch watch = new("Initializing no duplicate DAT"); // Fill in any information not in the base DAT if (string.IsNullOrWhiteSpace(datFile.Header.FileName)) @@ -473,7 +473,7 @@ namespace SabreTools.DatTools public static List PopulateUserData(DatFile datFile, List inputs) { DatFile[] datFiles = new DatFile[inputs.Count]; - InternalStopwatch watch = new InternalStopwatch("Processing individual DATs"); + InternalStopwatch watch = new("Processing individual DATs"); // Parse all of the DATs into their own DatFiles in the array Parallel.For(0, inputs.Count, Globals.ParallelOptions, i => diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index fe86916b..c8680395 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -26,7 +26,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -51,7 +51,7 @@ namespace SabreTools.DatTools long totalSize = 0; long currentSize = 0; - InternalStopwatch watch = new InternalStopwatch($"Populating DAT from {basePath}"); + InternalStopwatch watch = new($"Populating DAT from {basePath}"); // Process the input if (Directory.Exists(basePath)) @@ -187,14 +187,14 @@ namespace SabreTools.DatTools return false; // Check the file as if it were in a depot - GZipArchive gzarc = new GZipArchive(item); + GZipArchive gzarc = new(item); BaseFile baseFile = gzarc.GetTorrentGZFileInfo(); // If the rom is valid, add it if (baseFile != null && baseFile.Filename != null) { // Add the list if it doesn't exist already - Rom rom = new Rom(baseFile); + Rom rom = new(baseFile); datFile.Items.Add(rom.GetKey(ItemKey.CRC), rom); logger.Verbose($"File added: {Path.GetFileNameWithoutExtension(item)}"); } @@ -236,7 +236,7 @@ namespace SabreTools.DatTools /// BaseArchive to get blanks from private static void ProcessArchiveBlanks(DatFile datFile, string item, string basePath, BaseArchive archive) { - List empties = new List(); + List empties = new(); // Get the parent path for all items string parent = (Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, basePath.Length) + Path.GetFileNameWithoutExtension(item); @@ -248,7 +248,7 @@ namespace SabreTools.DatTools // Add add all of the found empties to the DAT Parallel.ForEach(empties, Globals.ParallelOptions, empty => { - Rom emptyRom = new Rom(Path.Combine(empty, "_"), item); + Rom emptyRom = new(Path.Combine(empty, "_"), item); ProcessFileHelper(datFile, item, emptyRom, basePath, parent); }); } @@ -324,7 +324,7 @@ namespace SabreTools.DatTools private static void ProcessFileHelper(DatFile datFile, string item, DatItem datItem, string basepath, string parent) { // If we didn't get an accepted parsed type somehow, cancel out - List parsed = new List { ItemType.Disk, ItemType.Media, ItemType.Rom }; + List parsed = new() { ItemType.Disk, ItemType.File, ItemType.Media, ItemType.Rom }; if (!parsed.Contains(datItem.ItemType)) return; diff --git a/SabreTools.DatTools/Parser.cs b/SabreTools.DatTools/Parser.cs index 53db5e33..b115bc45 100644 --- a/SabreTools.DatTools/Parser.cs +++ b/SabreTools.DatTools/Parser.cs @@ -20,7 +20,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -58,7 +58,7 @@ namespace SabreTools.DatTools bool statsOnly = false, bool throwOnError = false) { - ParentablePath path = new ParentablePath(filename.Trim('"')); + ParentablePath path = new(filename.Trim('"')); ParseInto(datFile, path, indexId, keep, keepext, quotes, statsOnly, throwOnError); } @@ -102,7 +102,7 @@ namespace SabreTools.DatTools datFile.Header.DatFormat = datFile.Header.DatFormat == 0 ? currentPathFormat : datFile.Header.DatFormat; datFile.Items.SetBucketedBy(ItemKey.CRC); // Setting this because it can reduce issues later - InternalStopwatch watch = new InternalStopwatch($"Parsing '{currentPath}' into internal DAT"); + InternalStopwatch watch = new($"Parsing '{currentPath}' into internal DAT"); // Now parse the correct type of DAT try @@ -215,7 +215,7 @@ namespace SabreTools.DatTools return DatFormat.EverdriveSMDB; // If we have an INI-based DAT - else if (first.Contains("[") && first.Contains("]")) + else if (first.Contains('[') && first.Contains(']')) return DatFormat.RomCenter; // If we have a listroms DAT diff --git a/SabreTools.DatTools/Rebuilder.cs b/SabreTools.DatTools/Rebuilder.cs index cbe1a9aa..ff6e7310 100644 --- a/SabreTools.DatTools/Rebuilder.cs +++ b/SabreTools.DatTools/Rebuilder.cs @@ -26,7 +26,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -73,10 +73,10 @@ namespace SabreTools.DatTools #region Rebuild from depots in order string format = FromOutputFormat(outputFormat) ?? string.Empty; - InternalStopwatch watch = new InternalStopwatch($"Rebuilding all files to {format}"); + InternalStopwatch watch = new($"Rebuilding all files to {format}"); // Now loop through and get only directories from the input paths - List directories = new List(); + List directories = new(); Parallel.ForEach(inputs, Globals.ParallelOptions, input => { // Add to the list if the input is a directory @@ -126,7 +126,7 @@ namespace SabreTools.DatTools continue; // If we have a path, we want to try to get the rom information - GZipArchive archive = new GZipArchive(foundpath); + GZipArchive archive = new(foundpath); BaseFile fileinfo = archive.GetTorrentGZFileInfo(); // If the file information is null, then we continue @@ -215,7 +215,7 @@ namespace SabreTools.DatTools #region Rebuild from sources in order string format = FromOutputFormat(outputFormat) ?? string.Empty; - InternalStopwatch watch = new InternalStopwatch($"Rebuilding all files to {format}"); + InternalStopwatch watch = new($"Rebuilding all files to {format}"); // Now loop through all of the files in all of the inputs foreach (string input in inputs) @@ -287,8 +287,8 @@ namespace SabreTools.DatTools List entries = null; // Get the TGZ and TXZ status for later - GZipArchive tgz = new GZipArchive(file); - XZArchive txz = new XZArchive(file); + GZipArchive tgz = new(file); + XZArchive txz = new(file); bool isSingleTorrent = tgz.IsTorrent() || txz.IsTorrent(); // Get the base archive first @@ -431,11 +431,11 @@ namespace SabreTools.DatTools if (rule.Tests != null && rule.Tests.Length != 0) { // If the file could be transformed correctly - MemoryStream transformStream = new MemoryStream(); + MemoryStream transformStream = new(); if (rule.TransformStream(fileStream, transformStream, keepReadOpen: true, keepWriteOpen: true)) { // Get the file informations that we will be using - Rom headerless = new Rom(BaseFile.GetInfo(transformStream, keepReadOpen: true)); + Rom headerless = new(BaseFile.GetInfo(transformStream, keepReadOpen: true)); // If we have duplicates and we're not filtering if (ShouldRebuild(datFile, headerless, transformStream, false, out dupes)) @@ -508,7 +508,7 @@ namespace SabreTools.DatTools string machinename = null; // Get the item from the current file - Rom item = new Rom(BaseFile.GetInfo(stream, keepReadOpen: true)); + Rom item = new(BaseFile.GetInfo(stream, keepReadOpen: true)); item.Machine.Name = Path.GetFileNameWithoutExtension(item.Name); item.Machine.Description = Path.GetFileNameWithoutExtension(item.Name); @@ -543,7 +543,7 @@ namespace SabreTools.DatTools private static bool RebuildTorrentGzip(DatFile datFile, DatItem datItem, string file, string outDir, OutputFormat outputFormat, bool? isZip) { // If we have a very specific TGZ->TGZ case, just copy it accordingly - GZipArchive tgz = new GZipArchive(file); + GZipArchive tgz = new(file); BaseFile tgzRom = tgz.GetTorrentGZFileInfo(); if (isZip == false && tgzRom != null && (outputFormat == OutputFormat.TorrentGzip || outputFormat == OutputFormat.TorrentGzipRomba)) { @@ -587,7 +587,7 @@ namespace SabreTools.DatTools private static bool RebuildTorrentXz(DatFile datFile, DatItem datItem, string file, string outDir, OutputFormat outputFormat, bool? isZip) { // If we have a very specific TGZ->TGZ case, just copy it accordingly - XZArchive txz = new XZArchive(file); + XZArchive txz = new(file); BaseFile txzRom = txz.GetTorrentXZFileInfo(); if (isZip == false && txzRom != null && (outputFormat == OutputFormat.TorrentXZ || outputFormat == OutputFormat.TorrentXZRomba)) { diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index eed31f41..09fc56c5 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -26,7 +26,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -43,7 +43,7 @@ namespace SabreTools.DatTools if (datFile.Items.TotalCount == 0) return (null, null); - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by extension"); + InternalStopwatch watch = new($"Splitting DAT by extension"); // Make sure all of the extensions don't have a dot at the beginning var newExtA = extA.Select(s => s.TrimStart('.').ToLowerInvariant()); @@ -98,10 +98,10 @@ namespace SabreTools.DatTools public static Dictionary SplitByHash(DatFile datFile) { // Create each of the respective output DATs - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by best available hashes"); + InternalStopwatch watch = new($"Splitting DAT by best available hashes"); // Create the set of field-to-dat mappings - Dictionary fieldDats = new Dictionary(); + Dictionary fieldDats = new(); // TODO: Can this be made into a loop? fieldDats[DatItemField.Status] = DatFile.Create(datFile.Header.CloneStandard()); @@ -223,7 +223,7 @@ namespace SabreTools.DatTools /// True if split succeeded, false otherwise public static bool SplitByLevel(DatFile datFile, string outDir, bool shortname, bool basedat) { - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by level"); + InternalStopwatch watch = new($"Splitting DAT by level"); // First, bucket by games so that we can do the right thing datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, lower: false, norename: true); @@ -271,7 +271,7 @@ namespace SabreTools.DatTools /// -1 for a coming before b, 0 for a == b, 1 for a coming after b private static int SplitByLevelSort(string a, string b) { - NaturalComparer nc = new NaturalComparer(); + NaturalComparer nc = new(); int adeep = a.Count(c => c == '/' || c == '\\'); int bdeep = b.Count(c => c == '/' || c == '\\'); @@ -321,7 +321,7 @@ namespace SabreTools.DatTools public static (DatFile lessThan, DatFile greaterThan) SplitBySize(DatFile datFile, long radix) { // Create each of the respective output DATs - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by size"); + InternalStopwatch watch = new($"Splitting DAT by size"); DatFile lessThan = DatFile.Create(datFile.Header.CloneStandard()); lessThan.Header.FileName += $" (less than {radix})"; @@ -375,7 +375,7 @@ namespace SabreTools.DatTools return new List(); // Create each of the respective output DATs - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by total size"); + InternalStopwatch watch = new($"Splitting DAT by total size"); // Sort the DatFile by machine name datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None); @@ -384,7 +384,7 @@ namespace SabreTools.DatTools var keys = datFile.Items.SortedKeys; // Get the output list - List datFiles = new List(); + List datFiles = new(); // Initialize everything long currentSize = 0; @@ -459,13 +459,13 @@ namespace SabreTools.DatTools public static Dictionary SplitByType(DatFile datFile) { // Create each of the respective output DATs - InternalStopwatch watch = new InternalStopwatch($"Splitting DAT by item type"); + InternalStopwatch watch = new($"Splitting DAT by item type"); // Create the set of type-to-dat mappings - Dictionary typeDats = new Dictionary(); + Dictionary typeDats = new(); // We only care about a subset of types - List outputTypes = new List + List outputTypes = new() { ItemType.Disk, ItemType.Media, diff --git a/SabreTools.DatTools/Statistics.cs b/SabreTools.DatTools/Statistics.cs index 6a12fe0b..c6e77c9a 100644 --- a/SabreTools.DatTools/Statistics.cs +++ b/SabreTools.DatTools/Statistics.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using SabreTools.Core; using SabreTools.DatFiles; -using SabreTools.DatItems; using SabreTools.IO; using SabreTools.Logging; using SabreTools.Reports; @@ -25,7 +24,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -38,7 +37,7 @@ namespace SabreTools.DatTools public static List CalculateStatistics(List inputs, bool single, bool throwOnError = false) { // Create the output list - List stats = new List(); + List stats = new(); // Make sure we have all files and then order them List files = PathTool.GetFilesOnly(inputs); @@ -48,7 +47,7 @@ namespace SabreTools.DatTools .ToList(); // Init total - DatStatistics totalStats = new DatStatistics + DatStatistics totalStats = new() { Statistics = new ItemDictionary(), DisplayName = "DIR: All DATs", @@ -58,7 +57,7 @@ namespace SabreTools.DatTools // Init directory-level variables string lastdir = null; - DatStatistics dirStats = new DatStatistics + DatStatistics dirStats = new() { Statistics = new ItemDictionary(), MachineCount = 0, @@ -85,15 +84,15 @@ namespace SabreTools.DatTools }; } - InternalStopwatch watch = new InternalStopwatch($"Collecting statistics for '{file.CurrentPath}'"); + InternalStopwatch watch = new($"Collecting statistics for '{file.CurrentPath}'"); - List machines = new List(); + List machines = new(); DatFile datdata = Parser.CreateAndParse(file.CurrentPath, statsOnly: true, throwOnError: throwOnError); // Add single DAT stats (if asked) if (single) { - DatStatistics individualStats = new DatStatistics + DatStatistics individualStats = new() { Statistics = datdata.Items, DisplayName = datdata.Header.FileName, @@ -105,11 +104,11 @@ namespace SabreTools.DatTools // Add single DAT stats to dir dirStats.Statistics.AddStatistics(datdata.Items); - dirStats.Statistics.GameCount += datdata.Items.Keys.Count(); + dirStats.Statistics.GameCount += datdata.Items.Keys.Count; // Add single DAT stats to totals totalStats.Statistics.AddStatistics(datdata.Items); - totalStats.Statistics.GameCount += datdata.Items.Keys.Count(); + totalStats.Statistics.GameCount += datdata.Items.Keys.Count; // Make sure to assign the new directory lastdir = thisdir; @@ -165,7 +164,7 @@ namespace SabreTools.DatTools // Get the proper output directory name outDir = outDir.Ensure(); - InternalStopwatch watch = new InternalStopwatch($"Writing out report data to '{outDir}'"); + InternalStopwatch watch = new($"Writing out report data to '{outDir}'"); // Get the dictionary of desired output report names Dictionary outfiles = CreateOutStatsNames(outDir, statDatFormat, reportName); @@ -209,7 +208,7 @@ namespace SabreTools.DatTools /// Dictionary of output formats mapped to file names private static Dictionary CreateOutStatsNames(string outDir, StatReportFormat statDatFormat, string reportName, bool overwrite = true) { - Dictionary output = new Dictionary(); + Dictionary output = new(); // First try to create the output directory if we need to if (!Directory.Exists(outDir)) diff --git a/SabreTools.DatTools/Verification.cs b/SabreTools.DatTools/Verification.cs index 8df91990..874ba64c 100644 --- a/SabreTools.DatTools/Verification.cs +++ b/SabreTools.DatTools/Verification.cs @@ -23,7 +23,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -37,10 +37,10 @@ namespace SabreTools.DatTools { bool success = true; - InternalStopwatch watch = new InternalStopwatch("Verifying all from supplied depots"); + InternalStopwatch watch = new("Verifying all from supplied depots"); // Now loop through and get only directories from the input paths - List directories = new List(); + List directories = new(); foreach (string input in inputs) { // Add to the list if the input is a directory @@ -87,7 +87,7 @@ namespace SabreTools.DatTools continue; // If we have a path, we want to try to get the rom information - GZipArchive tgz = new GZipArchive(foundpath); + GZipArchive tgz = new(foundpath); BaseFile fileinfo = tgz.GetTorrentGZFileInfo(); // If the file information is null, then we continue @@ -120,7 +120,7 @@ namespace SabreTools.DatTools { bool success = true; - InternalStopwatch watch = new InternalStopwatch("Verifying all from supplied paths"); + InternalStopwatch watch = new("Verifying all from supplied paths"); // Force bucketing according to the flags datFile.Items.SetBucketedBy(ItemKey.NULL); diff --git a/SabreTools.DatTools/Writer.cs b/SabreTools.DatTools/Writer.cs index 584a4698..acbbf3df 100644 --- a/SabreTools.DatTools/Writer.cs +++ b/SabreTools.DatTools/Writer.cs @@ -22,7 +22,7 @@ namespace SabreTools.DatTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -54,7 +54,7 @@ namespace SabreTools.DatTools // Ensure the output directory is set and created outDir = outDir.Ensure(create: true); - InternalStopwatch watch = new InternalStopwatch($"Writing out internal dat to '{outDir}'"); + InternalStopwatch watch = new($"Writing out internal dat to '{outDir}'"); // If the DAT has no output format, default to XML if (datFile.Header.DatFormat == 0) @@ -122,7 +122,7 @@ namespace SabreTools.DatTools { Statistics = datFile.Items, DisplayName = datFile.Header.FileName, - MachineCount = datFile.Items.Keys.Count(), + MachineCount = datFile.Items.Keys.Count, IsDirectory = false, }, }; diff --git a/SabreTools.FileTypes/Aaru/AaruFormat.cs b/SabreTools.FileTypes/Aaru/AaruFormat.cs index bd7ea957..8f33eb2d 100644 --- a/SabreTools.FileTypes/Aaru/AaruFormat.cs +++ b/SabreTools.FileTypes/Aaru/AaruFormat.cs @@ -118,9 +118,9 @@ namespace SabreTools.FileTypes.Aaru { try { - AaruFormat aif = new AaruFormat(); + AaruFormat aif = new(); - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { aif.Identifier = br.ReadUInt64(); aif.Application = Encoding.Unicode.GetString(br.ReadBytes(64), 0, 64); diff --git a/SabreTools.FileTypes/Archives/GZipArchive.cs b/SabreTools.FileTypes/Archives/GZipArchive.cs index 77e48eb6..7e2813dc 100644 --- a/SabreTools.FileTypes/Archives/GZipArchive.cs +++ b/SabreTools.FileTypes/Archives/GZipArchive.cs @@ -162,7 +162,7 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry; try @@ -221,14 +221,14 @@ namespace SabreTools.FileTypes.Archives try { // Create a blank item for the entry - BaseFile gzipEntryRom = new BaseFile(); + BaseFile gzipEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) { gzipEntryRom.Filename = gamename; - using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)); + using BinaryReader br = new(File.OpenRead(this.Filename)); br.BaseStream.Seek(-8, SeekOrigin.End); gzipEntryRom.CRC = br.ReadBytesBigEndian(4); gzipEntryRom.Size = br.ReadInt32BigEndian(); @@ -300,7 +300,7 @@ namespace SabreTools.FileTypes.Archives } // Get the Romba-specific header data - BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)); + BinaryReader br = new(File.OpenRead(this.Filename)); byte[] header = br.ReadBytes(12); // Get preamble header for checking br.ReadBytes(16); // headermd5 br.ReadBytes(4); // headercrc @@ -365,7 +365,7 @@ namespace SabreTools.FileTypes.Archives byte[] headermd5; // MD5 byte[] headercrc; // CRC ulong headersz; // Int64 size - BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)); + BinaryReader br = new(File.OpenRead(this.Filename)); header = br.ReadBytes(12); headermd5 = br.ReadBytes(16); headercrc = br.ReadBytes(4); @@ -391,7 +391,7 @@ namespace SabreTools.FileTypes.Archives // Now convert the data and get the right position long extractedsize = (long)headersz; - BaseFile baseFile = new BaseFile + BaseFile baseFile = new() { Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(), Size = extractedsize, @@ -457,7 +457,7 @@ namespace SabreTools.FileTypes.Archives FileStream outputStream = File.Create(outfile); // Open the output file for writing - BinaryWriter sw = new BinaryWriter(outputStream); + BinaryWriter sw = new(outputStream); // Write standard header and TGZ info byte[] data = TorrentGZHeader @@ -468,7 +468,7 @@ namespace SabreTools.FileTypes.Archives sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored) // Now create a deflatestream from the input file - ZlibBaseStream ds = new ZlibBaseStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true); + ZlibBaseStream ds = new(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true); // Copy the input stream to the output byte[] ibuffer = new byte[_bufferSize]; diff --git a/SabreTools.FileTypes/Archives/RarArchive.cs b/SabreTools.FileTypes/Archives/RarArchive.cs index d28e3632..f7833549 100644 --- a/SabreTools.FileTypes/Archives/RarArchive.cs +++ b/SabreTools.FileTypes/Archives/RarArchive.cs @@ -124,7 +124,7 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry = null; try @@ -158,7 +158,7 @@ namespace SabreTools.FileTypes.Archives /// public override List GetChildren() { - List found = new List(); + List found = new(); string gamename = Path.GetFileNameWithoutExtension(this.Filename); try @@ -167,7 +167,7 @@ namespace SabreTools.FileTypes.Archives foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory)) { // Create a blank item for the entry - BaseFile rarEntryRom = new BaseFile(); + BaseFile rarEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) @@ -204,7 +204,7 @@ namespace SabreTools.FileTypes.Archives /// public override List GetEmptyFolders() { - List empties = new List(); + List empties = new(); try { diff --git a/SabreTools.FileTypes/Archives/SevenZipArchive.cs b/SabreTools.FileTypes/Archives/SevenZipArchive.cs index 2a4cec50..f566c212 100644 --- a/SabreTools.FileTypes/Archives/SevenZipArchive.cs +++ b/SabreTools.FileTypes/Archives/SevenZipArchive.cs @@ -71,7 +71,7 @@ namespace SabreTools.FileTypes.Archives Directory.CreateDirectory(outDir); // Extract all files to the temp directory - SevenZ zf = new SevenZ(); + SevenZ zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -189,12 +189,12 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry = null; try { - SevenZ zf = new SevenZ(); + SevenZ zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -258,12 +258,12 @@ namespace SabreTools.FileTypes.Archives /// public override List GetChildren() { - List found = new List(); + List found = new(); string gamename = Path.GetFileNameWithoutExtension(this.Filename); try { - SevenZ zf = new SevenZ(); + SevenZ zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -293,7 +293,7 @@ namespace SabreTools.FileTypes.Archives } // Create a blank item for the entry - BaseFile zipEntryRom = new BaseFile(); + BaseFile zipEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) @@ -329,18 +329,18 @@ namespace SabreTools.FileTypes.Archives /// public override List GetEmptyFolders() { - List empties = new List(); + List empties = new(); try { - SevenZ zf = new SevenZ(); + SevenZ zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { throw new Exception(ZipUtils.ZipErrorMessageText(zr)); } - List<(string, bool)> zipEntries = new List<(string, bool)>(); + List<(string, bool)> zipEntries = new(); for (int i = 0; i < zf.LocalFilesCount(); i++) { zipEntries.Add((zf.Filename(i), zf.IsDirectory(i))); @@ -377,7 +377,7 @@ namespace SabreTools.FileTypes.Archives /// public override bool IsTorrent() { - SevenZ zf = new SevenZ(); + SevenZ zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -420,8 +420,8 @@ namespace SabreTools.FileTypes.Archives // Set internal variables Stream writeStream = null; - SevenZ oldZipFile = new SevenZ(); - SevenZ zipFile = new SevenZ(); + SevenZ oldZipFile = new(); + SevenZ zipFile = new(); ZipReturn zipReturn = ZipReturn.ZipGood; try @@ -443,7 +443,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts); } else @@ -470,7 +470,7 @@ namespace SabreTools.FileTypes.Archives oldZipFile.ZipFileOpen(archiveFileName, -1, true); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); var oldZipFileContents = new List(); for (int i = 0; i < oldZipFile.LocalFilesCount(); i++) { @@ -519,7 +519,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts); } else @@ -617,8 +617,8 @@ namespace SabreTools.FileTypes.Archives // Set internal variables Stream writeStream = null; - SevenZ oldZipFile = new SevenZ(); - SevenZ zipFile = new SevenZ(); + SevenZ oldZipFile = new(); + SevenZ zipFile = new(); ZipReturn zipReturn = ZipReturn.ZipGood; try @@ -635,7 +635,7 @@ namespace SabreTools.FileTypes.Archives zipReturn = zipFile.ZipFileCreate(tempFile); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i); @@ -659,7 +659,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts); } else @@ -688,7 +688,7 @@ namespace SabreTools.FileTypes.Archives oldZipFile.ZipFileOpen(archiveFileName, -1, true); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { var oldZipFileContents = new List(); @@ -743,7 +743,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, out writeStream, ts); } else diff --git a/SabreTools.FileTypes/Archives/TapeArchive.cs b/SabreTools.FileTypes/Archives/TapeArchive.cs index 41605973..160b6cf6 100644 --- a/SabreTools.FileTypes/Archives/TapeArchive.cs +++ b/SabreTools.FileTypes/Archives/TapeArchive.cs @@ -129,7 +129,7 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry = null; try @@ -163,7 +163,7 @@ namespace SabreTools.FileTypes.Archives /// public override List GetChildren() { - List found = new List(); + List found = new(); string gamename = Path.GetFileNameWithoutExtension(this.Filename); try @@ -172,7 +172,7 @@ namespace SabreTools.FileTypes.Archives foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory)) { // Create a blank item for the entry - BaseFile tarEntryRom = new BaseFile(); + BaseFile tarEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) @@ -209,7 +209,7 @@ namespace SabreTools.FileTypes.Archives /// public override List GetEmptyFolders() { - List empties = new List(); + List empties = new(); try { @@ -309,7 +309,7 @@ namespace SabreTools.FileTypes.Archives List entries = oldTarFile.Entries.Select(i => i.Key).ToList(); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); // If the old one doesn't contain the new file, then add it if (!entries.Contains(baseFile.Filename.Replace('\\', '/'))) @@ -356,7 +356,7 @@ namespace SabreTools.FileTypes.Archives { // Get the stream from the original archive TarArchiveEntry tae = oldTarFile.Entries.ElementAt(index); - MemoryStream entry = new MemoryStream(); + MemoryStream entry = new(); tae.OpenEntryStream().CopyTo(entry); // Copy the input stream to the output @@ -436,7 +436,7 @@ namespace SabreTools.FileTypes.Archives if (!File.Exists(archiveFileName)) { // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i); @@ -472,7 +472,7 @@ namespace SabreTools.FileTypes.Archives List entries = oldTarFile.Entries.Select(i => i.Key).ToList(); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { // If the old one contains the new file, then just skip out @@ -524,7 +524,7 @@ namespace SabreTools.FileTypes.Archives { // Get the stream from the original archive TarArchiveEntry tae = oldTarFile.Entries.ElementAt(index); - MemoryStream entry = new MemoryStream(); + MemoryStream entry = new(); tae.OpenEntryStream().CopyTo(entry); // Copy the input stream to the output diff --git a/SabreTools.FileTypes/Archives/XZArchive.cs b/SabreTools.FileTypes/Archives/XZArchive.cs index 748c0749..e58c6a2d 100644 --- a/SabreTools.FileTypes/Archives/XZArchive.cs +++ b/SabreTools.FileTypes/Archives/XZArchive.cs @@ -148,7 +148,7 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry; try @@ -205,14 +205,14 @@ namespace SabreTools.FileTypes.Archives try { // Create a blank item for the entry - BaseFile xzEntryRom = new BaseFile(); + BaseFile xzEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) { xzEntryRom.Filename = gamename; - using BinaryReader br = new BinaryReader(File.OpenRead(this.Filename)); + using BinaryReader br = new(File.OpenRead(this.Filename)); br.BaseStream.Seek(-8, SeekOrigin.End); xzEntryRom.CRC = br.ReadBytesBigEndian(4); xzEntryRom.Size = br.ReadInt32BigEndian(); @@ -286,7 +286,7 @@ namespace SabreTools.FileTypes.Archives return null; } - BaseFile baseFile = new BaseFile + BaseFile baseFile = new() { Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(), SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), @@ -347,7 +347,7 @@ namespace SabreTools.FileTypes.Archives if (!File.Exists(outfile)) { // Compress the input stream - XZStream outputStream = new XZStream(File.Create(outfile)); + XZStream outputStream = new(File.Create(outfile)); inputStream.CopyTo(outputStream); // Dispose of everything diff --git a/SabreTools.FileTypes/Archives/ZipArchive.cs b/SabreTools.FileTypes/Archives/ZipArchive.cs index 5ca0cd93..65878b44 100644 --- a/SabreTools.FileTypes/Archives/ZipArchive.cs +++ b/SabreTools.FileTypes/Archives/ZipArchive.cs @@ -80,7 +80,7 @@ namespace SabreTools.FileTypes.Archives Directory.CreateDirectory(outDir); // Extract all files to the temp directory - Zip zf = new Zip(); + Zip zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -200,12 +200,12 @@ namespace SabreTools.FileTypes.Archives /// public override (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realEntry = null; try { - Zip zf = new Zip(); + Zip zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -269,12 +269,12 @@ namespace SabreTools.FileTypes.Archives /// public override List GetChildren() { - List found = new List(); + List found = new(); string gamename = Path.GetFileNameWithoutExtension(this.Filename); try { - Zip zf = new Zip(); + Zip zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -304,7 +304,7 @@ namespace SabreTools.FileTypes.Archives } // Create a blank item for the entry - BaseFile zipEntryRom = new BaseFile(); + BaseFile zipEntryRom = new(); // Perform a quickscan, if flagged to if (this.AvailableHashes == Hash.CRC) @@ -341,18 +341,18 @@ namespace SabreTools.FileTypes.Archives /// public override List GetEmptyFolders() { - List empties = new List(); + List empties = new(); try { - Zip zf = new Zip(); + Zip zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { throw new Exception(ZipUtils.ZipErrorMessageText(zr)); } - List<(string, bool)> zipEntries = new List<(string, bool)>(); + List<(string, bool)> zipEntries = new(); for (int i = 0; i < zf.LocalFilesCount(); i++) { zipEntries.Add((zf.Filename(i), zf.IsDirectory(i))); @@ -389,7 +389,7 @@ namespace SabreTools.FileTypes.Archives /// public override bool IsTorrent() { - Zip zf = new Zip(); + Zip zf = new(); ZipReturn zr = zf.ZipFileOpen(this.Filename, -1, true); if (zr != ZipReturn.ZipGood) { @@ -432,8 +432,8 @@ namespace SabreTools.FileTypes.Archives // Set internal variables Stream writeStream = null; - Zip oldZipFile = new Zip(); - Zip zipFile = new Zip(); + Zip oldZipFile = new(); + Zip zipFile = new(); ZipReturn zipReturn = ZipReturn.ZipGood; try @@ -455,7 +455,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); } else @@ -482,7 +482,7 @@ namespace SabreTools.FileTypes.Archives oldZipFile.ZipFileOpen(archiveFileName, -1, true); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); var oldZipFileContents = new List(); for (int i = 0; i < oldZipFile.LocalFilesCount(); i++) { @@ -529,7 +529,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); } else @@ -555,7 +555,7 @@ namespace SabreTools.FileTypes.Archives // Instantiate the streams oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod); long msDosDateTime = oldZipFile.LastModified(index); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); // Copy the input stream to the output @@ -629,8 +629,8 @@ namespace SabreTools.FileTypes.Archives // Set internal variables Stream writeStream = null; - Zip oldZipFile = new Zip(); - Zip zipFile = new Zip(); + Zip oldZipFile = new(); + Zip zipFile = new(); ZipReturn zipReturn = ZipReturn.ZipGood; try @@ -647,7 +647,7 @@ namespace SabreTools.FileTypes.Archives zipReturn = zipFile.ZipFileCreate(tempFile); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i); @@ -671,7 +671,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); } else @@ -700,7 +700,7 @@ namespace SabreTools.FileTypes.Archives oldZipFile.ZipFileOpen(archiveFileName, -1, true); // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); + Dictionary inputIndexMap = new(); for (int i = 0; i < inputFiles.Count; i++) { var oldZipFileContents = new List(); @@ -755,7 +755,7 @@ namespace SabreTools.FileTypes.Archives if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt)) { long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); } else @@ -781,7 +781,7 @@ namespace SabreTools.FileTypes.Archives // Instantiate the streams oldZipFile.ZipFileOpenReadStream(index, false, out Stream zreadStream, out ulong istreamSize, out ushort icompressionMethod); long msDosDateTime = oldZipFile.LastModified(index); - TimeStamps ts = new TimeStamps { ModTime = msDosDateTime }; + TimeStamps ts = new() { ModTime = msDosDateTime }; zipFile.ZipFileOpenWriteStream(false, true, oldZipFile.Filename(index), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts); // Copy the input stream to the output diff --git a/SabreTools.FileTypes/BaseFile.cs b/SabreTools.FileTypes/BaseFile.cs index 025d8332..201e6ba5 100644 --- a/SabreTools.FileTypes/BaseFile.cs +++ b/SabreTools.FileTypes/BaseFile.cs @@ -200,7 +200,7 @@ namespace SabreTools.FileTypes return outFileType; // Read the first bytes of the file and get the magic number - BinaryReader br = new BinaryReader(File.OpenRead(input)); + BinaryReader br = new(File.OpenRead(input)); byte[] magic = br.ReadBytes(8); br.Dispose(); @@ -291,7 +291,7 @@ namespace SabreTools.FileTypes if (rule.Tests != null && rule.Tests.Length != 0) { // Create the output stream - MemoryStream outputStream = new MemoryStream(); + MemoryStream outputStream = new(); // Transform the stream and get the information from it rule.TransformStream(inputStream, outputStream, keepReadOpen: false, keepWriteOpen: true); @@ -335,7 +335,7 @@ namespace SabreTools.FileTypes try { // Get a list of hashers to run over the buffer - List hashers = new List(); + List hashers = new(); if (hashes.HasFlag(Hash.CRC)) hashers.Add(new Hasher(Hash.CRC)); @@ -391,7 +391,7 @@ namespace SabreTools.FileTypes Parallel.ForEach(hashers, Globals.ParallelOptions, h => h.Terminate()); // Get the results - BaseFile baseFile = new BaseFile() + BaseFile baseFile = new() { Size = size, CRC = hashes.HasFlag(Hash.CRC) ? hashers.First(h => h.HashType == Hash.CRC).GetHash() : null, @@ -433,35 +433,34 @@ namespace SabreTools.FileTypes string ext = path.GetNormalizedExtension(); // Check against the list of known archive extensions - switch (ext) + return ext switch { // Aaruformat - case "aaru": - case "aaruf": - case "aaruformat": - case "aif": - case "dicf": - - // Archives - case "7z": - case "gz": - case "lzma": - case "rar": - case "rev": - case "r00": - case "r01": - case "tar": - case "tgz": - case "tlz": - case "zip": - case "zipx": - + "aaru" => true, + "aaruf" => true, + "aaruformat" => true, + "aif" => true, + "dicf" => true, + + // Archive + "7z" => true, + "gz" => true, + "lzma" => true, + "rar" => true, + "rev" => true, + "r00" => true, + "r01" => true, + "tar" => true, + "tgz" => true, + "tlz" => true, + "zip" => true, + "zipx" => true, + // CHD - case "chd": - return true; - default: - return false; - } + "chd" => true, + + _ => false, + }; } #endregion diff --git a/SabreTools.FileTypes/CHD/CHDFile.cs b/SabreTools.FileTypes/CHD/CHDFile.cs index ab77b278..eaff0c93 100644 --- a/SabreTools.FileTypes/CHD/CHDFile.cs +++ b/SabreTools.FileTypes/CHD/CHDFile.cs @@ -95,7 +95,7 @@ namespace SabreTools.FileTypes.CHD uint parsedLength = 0; uint parsedVersion = 0; - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { parsedTag = br.ReadChars(8); parsedLength = br.ReadUInt32BigEndian(); diff --git a/SabreTools.FileTypes/CHD/CHDFileV1.cs b/SabreTools.FileTypes/CHD/CHDFileV1.cs index 6611f159..11e26618 100644 --- a/SabreTools.FileTypes/CHD/CHDFileV1.cs +++ b/SabreTools.FileTypes/CHD/CHDFileV1.cs @@ -58,9 +58,9 @@ namespace SabreTools.FileTypes.CHD /// public static CHDFileV1 Deserialize(Stream stream) { - CHDFileV1 chd = new CHDFileV1(); + CHDFileV1 chd = new(); - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); diff --git a/SabreTools.FileTypes/CHD/CHDFileV2.cs b/SabreTools.FileTypes/CHD/CHDFileV2.cs index dcf1dff4..8438e940 100644 --- a/SabreTools.FileTypes/CHD/CHDFileV2.cs +++ b/SabreTools.FileTypes/CHD/CHDFileV2.cs @@ -59,9 +59,9 @@ namespace SabreTools.FileTypes.CHD /// public static CHDFileV2 Deserialize(Stream stream) { - CHDFileV2 chd = new CHDFileV2(); + CHDFileV2 chd = new(); - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); diff --git a/SabreTools.FileTypes/CHD/CHDFileV3.cs b/SabreTools.FileTypes/CHD/CHDFileV3.cs index 0d2829fb..f3312587 100644 --- a/SabreTools.FileTypes/CHD/CHDFileV3.cs +++ b/SabreTools.FileTypes/CHD/CHDFileV3.cs @@ -63,9 +63,9 @@ namespace SabreTools.FileTypes.CHD /// public static CHDFileV3 Deserialize(Stream stream) { - CHDFileV3 chd = new CHDFileV3(); + CHDFileV3 chd = new(); - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); diff --git a/SabreTools.FileTypes/CHD/CHDFileV4.cs b/SabreTools.FileTypes/CHD/CHDFileV4.cs index 3ebb9cca..bc1fe9ff 100644 --- a/SabreTools.FileTypes/CHD/CHDFileV4.cs +++ b/SabreTools.FileTypes/CHD/CHDFileV4.cs @@ -63,9 +63,9 @@ namespace SabreTools.FileTypes.CHD /// public static CHDFileV4 Deserialize(Stream stream) { - CHDFileV4 chd = new CHDFileV4(); + CHDFileV4 chd = new(); - using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) + using (BinaryReader br = new(stream, Encoding.Default, true)) { chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); diff --git a/SabreTools.FileTypes/Folder.cs b/SabreTools.FileTypes/Folder.cs index 7460c031..ee661814 100644 --- a/SabreTools.FileTypes/Folder.cs +++ b/SabreTools.FileTypes/Folder.cs @@ -27,7 +27,7 @@ namespace SabreTools.FileTypes /// /// Static logger for static methods /// - protected static Logger staticLogger = new Logger(); + protected static Logger staticLogger = new(); /// /// Flag specific to Folder to omit Machine name from output path @@ -70,49 +70,24 @@ namespace SabreTools.FileTypes /// Archive object representing the inputs public static Folder Create(OutputFormat outputFormat) { - switch (outputFormat) + return outputFormat switch { - case OutputFormat.Folder: - return new Folder(false); - - case OutputFormat.ParentFolder: - return new Folder(true); - - case OutputFormat.TapeArchive: - return new TapeArchive(); - - case OutputFormat.Torrent7Zip: - return new SevenZipArchive(); - - case OutputFormat.TorrentGzip: - case OutputFormat.TorrentGzipRomba: - return new GZipArchive(); - - case OutputFormat.TorrentLRZip: - return new LRZipArchive(); - - case OutputFormat.TorrentLZ4: - return new LZ4Archive(); - - case OutputFormat.TorrentRar: - return new RarArchive(); - - case OutputFormat.TorrentXZ: - case OutputFormat.TorrentXZRomba: - return new XZArchive(); - - case OutputFormat.TorrentZip: - return new ZipArchive(); - - case OutputFormat.TorrentZPAQ: - return new ZPAQArchive(); - - case OutputFormat.TorrentZstd: - return new ZstdArchive(); - - default: - return null; - } + OutputFormat.Folder => new Folder(false), + OutputFormat.ParentFolder => new Folder(true), + OutputFormat.TapeArchive => new TapeArchive(), + OutputFormat.Torrent7Zip => new SevenZipArchive(), + OutputFormat.TorrentGzip => new GZipArchive(), + OutputFormat.TorrentGzipRomba => new GZipArchive(), + OutputFormat.TorrentLRZip => new LRZipArchive(), + OutputFormat.TorrentLZ4 => new LZ4Archive(), + OutputFormat.TorrentRar => new RarArchive(), + OutputFormat.TorrentXZ => new XZArchive(), + OutputFormat.TorrentXZRomba => new XZArchive(), + OutputFormat.TorrentZip => new ZipArchive(), + OutputFormat.TorrentZPAQ => new ZPAQArchive(), + OutputFormat.TorrentZstd => new ZstdArchive(), + _ => null, + }; } #endregion @@ -148,7 +123,7 @@ namespace SabreTools.FileTypes private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs) { // Get the subdirectories for the specified directory. - DirectoryInfo dir = new DirectoryInfo(sourceDirName); + DirectoryInfo dir = new(sourceDirName); if (!dir.Exists) { @@ -229,7 +204,7 @@ namespace SabreTools.FileTypes /// MemoryStream representing the entry, null on error public virtual (MemoryStream, string) CopyToStream(string entryName) { - MemoryStream ms = new MemoryStream(); + MemoryStream ms = new(); string realentry = null; // Copy single file from the current folder to the output directory, if exists @@ -281,7 +256,7 @@ namespace SabreTools.FileTypes foreach (string dir in Directory.EnumerateDirectories(this.Filename, "*", SearchOption.TopDirectoryOnly)) { - Folder fl = new Folder(dir); + Folder fl = new(dir); _children.Add(fl); } } diff --git a/SabreTools.Filtering/Cleaner.cs b/SabreTools.Filtering/Cleaner.cs index 3a4b7c8f..eb7139ca 100644 --- a/SabreTools.Filtering/Cleaner.cs +++ b/SabreTools.Filtering/Cleaner.cs @@ -90,7 +90,7 @@ namespace SabreTools.Filtering /// /// Logging object /// - private readonly Logger logger = new Logger(); + private readonly Logger logger = new(); #endregion @@ -104,7 +104,7 @@ namespace SabreTools.Filtering /// True if cleaning was successful, false on error public bool ApplyCleaning(DatFile datFile, bool throwOnError = false) { - InternalStopwatch watch = new InternalStopwatch("Applying cleaning steps to DAT"); + InternalStopwatch watch = new("Applying cleaning steps to DAT"); try { @@ -212,7 +212,7 @@ namespace SabreTools.Filtering if (datItem.GetName().Length > usableLength) { string ext = Path.GetExtension(datItem.GetName()); - datItem.SetName(datItem.GetName().Substring(0, usableLength - ext.Length) + ext); + datItem.SetName(datItem.GetName()[..(usableLength - ext.Length)] + ext); } } } @@ -222,7 +222,7 @@ namespace SabreTools.Filtering /// /// Name of the game to be cleaned /// The cleaned name - internal string CleanGameName(string game) + internal static string CleanGameName(string game) { if (game == null) return null; @@ -247,7 +247,7 @@ namespace SabreTools.Filtering try { // First we want to get a mapping for all games to description - ConcurrentDictionary mapping = new ConcurrentDictionary(); + ConcurrentDictionary mapping = new(); Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList items = datFile.Items[key]; @@ -262,7 +262,7 @@ namespace SabreTools.Filtering Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key => { ConcurrentList items = datFile.Items[key]; - ConcurrentList newItems = new ConcurrentList(); + ConcurrentList newItems = new(); foreach (DatItem item in items) { // Update machine name @@ -301,7 +301,7 @@ namespace SabreTools.Filtering /// /// String to be parsed /// String with characters replaced - internal string NormalizeChars(string input) + internal static string NormalizeChars(string input) { if (input == null) return null; @@ -357,7 +357,7 @@ namespace SabreTools.Filtering /// /// Input string to clean /// Cleaned string - internal string RemoveUnicodeCharacters(string s) + internal static string RemoveUnicodeCharacters(string s) { if (s == null) return null; @@ -370,7 +370,7 @@ namespace SabreTools.Filtering /// /// String to be parsed /// String with characters replaced - internal string RussianToLatin(string input) + internal static string RussianToLatin(string input) { if (input == null) return null; @@ -405,7 +405,7 @@ namespace SabreTools.Filtering /// /// String to be parsed /// String with characters replaced - internal string SearchPattern(string input) + internal static string SearchPattern(string input) { if (input == null) return null; @@ -464,14 +464,13 @@ namespace SabreTools.Filtering internal void SetOneGamePerRegion(DatFile datFile) { // If we have null region list, make it empty - if (RegionList == null) - RegionList = new List(); + RegionList ??= new List(); // For sake of ease, the first thing we want to do is bucket by game datFile.Items.BucketBy(ItemKey.Machine, DedupeType.None, norename: true); // Then we want to get a mapping of all machines to parents - Dictionary> parents = new Dictionary>(); + Dictionary> parents = new(); foreach (string key in datFile.Items.Keys) { DatItem item = datFile.Items[key][0]; @@ -535,7 +534,7 @@ namespace SabreTools.Filtering /// Ensure that all roms are in their own game (or at least try to ensure) /// /// Current DatFile object to run operations on - internal void SetOneRomPerGame(DatFile datFile) + internal static void SetOneRomPerGame(DatFile datFile) { // Because this introduces subfolders, we need to set the SuperDAT type datFile.Header.Type = "SuperDAT"; @@ -555,7 +554,7 @@ namespace SabreTools.Filtering /// Set internal names to match One Rom Per Game (ORPG) logic /// /// DatItem to run logic on - internal void SetOneRomPerGame(DatItem datItem) + internal static void SetOneRomPerGame(DatItem datItem) { if (datItem.GetName() == null) return; diff --git a/SabreTools.Filtering/ExtraIni.cs b/SabreTools.Filtering/ExtraIni.cs index 8b8c7f0b..e3a6bc42 100644 --- a/SabreTools.Filtering/ExtraIni.cs +++ b/SabreTools.Filtering/ExtraIni.cs @@ -54,14 +54,14 @@ namespace SabreTools.Filtering if (inputs == null || !inputs.Any()) return; - InternalStopwatch watch = new InternalStopwatch("Populating extras from list"); + InternalStopwatch watch = new("Populating extras from list"); foreach (string input in inputs) { - ExtraIniItem item = new ExtraIniItem(); + ExtraIniItem item = new(); // If we don't even have a possible field and file combination - if (!input.Contains(":")) + if (!input.Contains(':')) { logger.Warning($"'{input}` is not a valid INI extras string. Valid INI extras strings are of the form 'key:value'. Please refer to README.1ST or the help feature for more details."); return; @@ -96,7 +96,7 @@ namespace SabreTools.Filtering if (Items == null || !Items.Any()) return true; - InternalStopwatch watch = new InternalStopwatch("Applying extra mappings to DAT"); + InternalStopwatch watch = new("Applying extra mappings to DAT"); try { @@ -125,7 +125,7 @@ namespace SabreTools.Filtering combinedDatItemMaps.TryGetValue(machine, out Dictionary datItemMappings); // Create a setter with the new mappings - Setter setter = new Setter + Setter setter = new() { MachineMappings = machineMappings, DatItemMappings = datItemMappings, diff --git a/SabreTools.Filtering/ExtraIniItem.cs b/SabreTools.Filtering/ExtraIniItem.cs index 5d1fa692..e24ba3e5 100644 --- a/SabreTools.Filtering/ExtraIniItem.cs +++ b/SabreTools.Filtering/ExtraIniItem.cs @@ -45,7 +45,7 @@ namespace SabreTools.Filtering public bool PopulateFromFile(string ini) { // Prepare all intenral variables - IniReader ir = new IniReader(ini) { ValidateRows = false }; + IniReader ir = new(ini) { ValidateRows = false }; bool foundRootFolder = false; // If we got a null reader, just return diff --git a/SabreTools.Filtering/Filter.cs b/SabreTools.Filtering/Filter.cs index 2fef477c..29fdc16c 100644 --- a/SabreTools.Filtering/Filter.cs +++ b/SabreTools.Filtering/Filter.cs @@ -96,7 +96,7 @@ namespace SabreTools.Filtering if (filters == null || filters.Count == 0) return; - InternalStopwatch watch = new InternalStopwatch("Populating filters from list"); + InternalStopwatch watch = new("Populating filters from list"); foreach (string filterPair in filters) { @@ -138,7 +138,7 @@ namespace SabreTools.Filtering protected (string field, string value, bool negate) ProcessFilterPair(string filter) { // If we don't even have a possible filter pair - if (!filter.Contains(":")) + if (!filter.Contains(':')) { logger.Warning($"'{filter}` is not a valid filter string. Valid filter strings are of the form 'key:value'. Please refer to README.1ST or the help feature for more details."); return (null, null, false); @@ -163,7 +163,7 @@ namespace SabreTools.Filtering /// FilterItem to populate /// String value to add /// True to set negative filter, false otherwise - protected void SetBooleanFilter(FilterItem filterItem, string value, bool negate) + protected static void SetBooleanFilter(FilterItem filterItem, string value, bool negate) { if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) filterItem.Neutral = false; @@ -177,7 +177,7 @@ namespace SabreTools.Filtering /// FilterItem to populate /// String value to add /// True to set negative filter, false otherwise - protected void SetDoubleFilter(FilterItem filterItem, string value, bool negate) + protected static void SetDoubleFilter(FilterItem filterItem, string value, bool negate) { bool? operation = null; if (value.StartsWith(">")) @@ -235,7 +235,7 @@ namespace SabreTools.Filtering /// FilterItem to populate /// String value to add /// True to set negative filter, false otherwise - protected void SetLongFilter(FilterItem filterItem, string value, bool negate) + protected static void SetLongFilter(FilterItem filterItem, string value, bool negate) { bool? operation = null; if (value.StartsWith(">")) @@ -294,7 +294,7 @@ namespace SabreTools.Filtering /// FilterItem to populate /// String value to add /// True to set negative filter, false otherwise - protected void SetStringFilter(FilterItem filterItem, string value, bool negate) + protected static void SetStringFilter(FilterItem filterItem, string value, bool negate) { if (negate) filterItem.NegativeSet.Add(value); @@ -382,7 +382,7 @@ namespace SabreTools.Filtering if (!MachineFilter.HasFilters && !DatItemFilter.HasFilters) return true; - InternalStopwatch watch = new InternalStopwatch("Applying filters to DAT"); + InternalStopwatch watch = new("Applying filters to DAT"); // If we're filtering per machine, bucket by machine first if (perMachine) diff --git a/SabreTools.Filtering/FilterItem.cs b/SabreTools.Filtering/FilterItem.cs index b7a4a9e5..36732224 100644 --- a/SabreTools.Filtering/FilterItem.cs +++ b/SabreTools.Filtering/FilterItem.cs @@ -110,7 +110,7 @@ namespace SabreTools.Filtering /// Default value to check filter value /// Value to check /// True if the value was found in the supplied filter, null on default value, false otherwise - private bool? Matches(T single, T def, T value) + private static bool? Matches(T single, T def, T value) { // If the filter is default, we ignore if (single.Equals(def)) @@ -129,12 +129,12 @@ namespace SabreTools.Filtering /// Set to check against /// Value to check /// True if the value was found in the supplied filter, null on an empty set, false otherwise - private bool? MatchesSet(List set, T value) + private static bool? MatchesSet(List set, T value) { if (set.Count == 0) return null; - if (this.FindValueInList(set, value)) + if (FindValueInList(set, value)) return true; return false; @@ -146,7 +146,7 @@ namespace SabreTools.Filtering /// List to search for the value in /// Value to search the list for /// True if the value could be found, false otherwise - private bool FindValueInList(List haystack, T needle) + private static bool FindValueInList(List haystack, T needle) { bool found = false; foreach (T straw in haystack) diff --git a/SabreTools.Filtering/Remover.cs b/SabreTools.Filtering/Remover.cs index 8fc4e5c8..c60bbbe9 100644 --- a/SabreTools.Filtering/Remover.cs +++ b/SabreTools.Filtering/Remover.cs @@ -65,7 +65,7 @@ namespace SabreTools.Filtering if (fields == null || fields.Count == 0) return; - InternalStopwatch watch = new InternalStopwatch("Populating removals from list"); + InternalStopwatch watch = new("Populating removals from list"); foreach (string field in fields) { @@ -102,7 +102,7 @@ namespace SabreTools.Filtering if (DatHeaderRemover == null && DatItemRemover == null) return; - InternalStopwatch watch = new InternalStopwatch("Applying removals to DAT"); + InternalStopwatch watch = new("Applying removals to DAT"); // Remove DatHeader fields if (DatHeaderRemover != null && DatHeaderRemover.DatHeaderFields.Any()) diff --git a/SabreTools.Filtering/Splitter.cs b/SabreTools.Filtering/Splitter.cs index bbe0ec85..fe5075d5 100644 --- a/SabreTools.Filtering/Splitter.cs +++ b/SabreTools.Filtering/Splitter.cs @@ -26,7 +26,7 @@ namespace SabreTools.Filtering /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -47,7 +47,7 @@ namespace SabreTools.Filtering /// True if the DatFile was split, false on error public bool ApplySplitting(DatFile datFile, bool useTags, bool throwOnError = false) { - InternalStopwatch watch = new InternalStopwatch("Applying splitting to DAT"); + InternalStopwatch watch = new("Applying splitting to DAT"); try { @@ -260,7 +260,7 @@ namespace SabreTools.Filtering { DatItem datItem = (DatItem)item.Clone(); datItem.CopyMachineInformation(copyFrom); - if (datFile.Items[game].Where(i => i.GetName() == datItem.GetName()).Count() == 0 && !datFile.Items[game].Contains(datItem)) + if (!datFile.Items[game].Where(i => i.GetName() == datItem.GetName()).Any() && !datFile.Items[game].Contains(datItem)) datFile.Items.Add(game, datItem); } } @@ -308,7 +308,7 @@ namespace SabreTools.Filtering if (deviceReferences.Any()) { // Loop through all names and check the corresponding machines - List newDeviceReferences = new List(); + List newDeviceReferences = new(); foreach (string deviceReference in deviceReferences) { // If the machine doesn't exist then we continue @@ -351,7 +351,7 @@ namespace SabreTools.Filtering if (useSlotOptions && slotOptions.Any()) { // Loop through all names and check the corresponding machines - List newSlotOptions = new List(); + List newSlotOptions = new(); foreach (string slotOption in slotOptions) { // If the machine doesn't exist then we continue @@ -429,7 +429,7 @@ namespace SabreTools.Filtering { DatItem datItem = (DatItem)item.Clone(); datItem.CopyMachineInformation(copyFrom); - if (datFile.Items[game].Where(i => i.GetName()?.ToLowerInvariant() == datItem.GetName()?.ToLowerInvariant()).Count() == 0 + if (!datFile.Items[game].Where(i => i.GetName()?.ToLowerInvariant() == datItem.GetName()?.ToLowerInvariant()).Any() && !datFile.Items[game].Contains(datItem)) { datFile.Items.Add(game, datItem); diff --git a/SabreTools.Help/Feature.cs b/SabreTools.Help/Feature.cs index d8e51324..9a3b93fc 100644 --- a/SabreTools.Help/Feature.cs +++ b/SabreTools.Help/Feature.cs @@ -87,9 +87,7 @@ namespace SabreTools.Help /// public void AddFeature(Feature feature) { - if (this.Features == null) - this.Features = new Dictionary(); - + this.Features ??= new Dictionary(); lock (this.Features) { this.Features[feature.Name] = feature; @@ -102,9 +100,7 @@ namespace SabreTools.Help /// Flag to add for this feature public void AddFlag(string flag) { - if (this.Flags == null) - this.Flags = new List(); - + this.Flags ??= new List(); lock (this.Flags) { this.Flags.Add(flag); @@ -117,9 +113,7 @@ namespace SabreTools.Help /// List of flags to add to this feature public void AddFlags(List flags) { - if (this.Flags == null) - this.Flags = new List(); - + this.Flags ??= new List(); lock (this.Flags) { this.Flags.AddRange(flags); @@ -159,7 +153,7 @@ namespace SabreTools.Help public List Output(int pre = 0, int midpoint = 0, bool includeLongDescription = false) { // Create the output list - List outputList = new List(); + List outputList = new(); // Build the output string first string output = string.Empty; @@ -216,7 +210,7 @@ namespace SabreTools.Help for (int i = 0; i < split.Length; i++) { // If we have a newline character, reset the line and continue - if (split[i].Contains("\n")) + if (split[i].Contains('\n')) { string[] subsplit = split[i].Replace("\r", string.Empty).Split('\n'); for (int j = 0; j < subsplit.Length - 1; j++) @@ -269,7 +263,7 @@ namespace SabreTools.Help /// /// Number of padding spaces to add /// String with requested number of blank spaces - private string CreatePadding(int spaces) + private static string CreatePadding(int spaces) { return string.Empty.PadRight(spaces); } @@ -284,7 +278,7 @@ namespace SabreTools.Help public List OutputRecursive(int tabLevel, int pre = 0, int midpoint = 0, bool includeLongDescription = false) { // Create the output list - List outputList = new List(); + List outputList = new(); // Build the output string first string output = string.Empty; @@ -350,7 +344,7 @@ namespace SabreTools.Help for (int i = 0; i < split.Length; i++) { // If we have a newline character, reset the line and continue - if (split[i].Contains("\n")) + if (split[i].Contains('\n')) { string[] subsplit = split[i].Replace("\r", string.Empty).Split('\n'); for (int j = 0; j < subsplit.Length - 1; j++) @@ -420,7 +414,7 @@ namespace SabreTools.Help { // If we have a flag, make sure it doesn't have an equal sign in it case ParameterType.Flag: - valid = !input.Contains("=") && this.Flags.Contains(input); + valid = !input.Contains('=') && this.Flags.Contains(input); if (valid) { _value = true; @@ -436,7 +430,7 @@ namespace SabreTools.Help // If we have an Int32, try to parse it if at all possible case ParameterType.Int32: - valid = input.Contains("=") && this.Flags.Contains(input.Split('=')[0]); + valid = input.Contains('=') && this.Flags.Contains(input.Split('=')[0]); if (valid) { if (!Int32.TryParse(input.Split('=')[1], out int value)) @@ -455,7 +449,7 @@ namespace SabreTools.Help // If we have an Int32, try to parse it if at all possible case ParameterType.Int64: - valid = input.Contains("=") && this.Flags.Contains(input.Split('=')[0]); + valid = input.Contains('=') && this.Flags.Contains(input.Split('=')[0]); if (valid) { if (!Int64.TryParse(input.Split('=')[1], out long value)) @@ -474,19 +468,17 @@ namespace SabreTools.Help // If we have an input, make sure it has an equals sign in it case ParameterType.List: - valid = input.Contains("=") && this.Flags.Contains(input.Split('=')[0]); + valid = input.Contains('=') && this.Flags.Contains(input.Split('=')[0]); if (valid) { - if (_value == null) - _value = new List(); - + _value ??= new List(); (_value as List).Add(input.Split('=')[1]); } break; case ParameterType.String: - valid = input.Contains("=") && this.Flags.Contains(input.Split('=')[0]); + valid = input.Contains('=') && this.Flags.Contains(input.Split('=')[0]); if (valid) { _value = input.Split('=')[1]; diff --git a/SabreTools.Help/FeatureSet.cs b/SabreTools.Help/FeatureSet.cs index 5b9a2da7..a9c67c0b 100644 --- a/SabreTools.Help/FeatureSet.cs +++ b/SabreTools.Help/FeatureSet.cs @@ -36,9 +36,7 @@ namespace SabreTools.Help { get { - if (_features == null) - _features = new Dictionary(); - + _features ??= new Dictionary(); if (!_features.ContainsKey(name)) return null; @@ -46,9 +44,7 @@ namespace SabreTools.Help } set { - if (_features == null) - _features = new Dictionary(); - + _features ??= new Dictionary(); _features[name] = value; } } @@ -57,9 +53,7 @@ namespace SabreTools.Help { get { - if (_features == null) - _features = new Dictionary(); - + _features ??= new Dictionary(); if (!_features.ContainsKey(subfeature.Name)) return null; @@ -67,9 +61,7 @@ namespace SabreTools.Help } set { - if (_features == null) - _features = new Dictionary(); - + _features ??= new Dictionary(); _features[subfeature.Name] = value; } } @@ -80,9 +72,7 @@ namespace SabreTools.Help /// Feature object to map to public void Add(Feature feature) { - if (_features == null) - _features = new Dictionary(); - + _features ??= new Dictionary(); lock (_features) { _features.Add(feature.Name, feature); @@ -108,7 +98,7 @@ namespace SabreTools.Help public void OutputGenericHelp() { // Start building the output list - List output = new List(); + List output = new(); // Append the header first output.AddRange(_header); @@ -134,7 +124,7 @@ namespace SabreTools.Help public void OutputAllHelp() { // Start building the output list - List output = new List(); + List output = new(); // Append the header first output.AddRange(_header); @@ -153,9 +143,9 @@ namespace SabreTools.Help /// /// Output the SabreTools suite credits /// - public void OutputCredits() + public static void OutputCredits() { - List credits = new List + List credits = new() { _barrier, "Credits", @@ -178,7 +168,7 @@ namespace SabreTools.Help public void OutputIndividualFeature(string featurename, bool includeLongDescription = false) { // Start building the output list - List output = new List(); + List output = new(); // If the feature name is null, empty, or just consisting of `-` characters, just show everything if (string.IsNullOrEmpty(featurename?.TrimStart('-'))) @@ -189,7 +179,7 @@ namespace SabreTools.Help // Now try to find the feature that has the name included string realname = null; - List startsWith = new List(); + List startsWith = new(); foreach (string feature in _features.Keys) { // If we have a match to the feature name somehow @@ -250,7 +240,7 @@ namespace SabreTools.Help /// List of Features representing what is enabled public Dictionary GetEnabledFeatures() { - Dictionary enabled = new Dictionary(); + Dictionary enabled = new(); // Loop through the features foreach (KeyValuePair feature in _features) @@ -276,7 +266,7 @@ namespace SabreTools.Help /// List of Features representing what is enabled private Dictionary GetEnabledSubfeatures(string key, Feature feature) { - Dictionary enabled = new Dictionary(); + Dictionary enabled = new(); // First determine if the current feature is enabled if (feature.IsEnabled()) @@ -302,7 +292,7 @@ namespace SabreTools.Help /// Write out the help text with pauses, if needed /// /// - private void WriteOutWithPauses(List helptext) + private static void WriteOutWithPauses(List helptext) { // Now output based on the size of the screen int i = 0; diff --git a/SabreTools.Help/TopLevel.cs b/SabreTools.Help/TopLevel.cs index c0d88ab0..9eb1f39f 100644 --- a/SabreTools.Help/TopLevel.cs +++ b/SabreTools.Help/TopLevel.cs @@ -16,7 +16,7 @@ namespace SabreTools.Help /// /// List of files, directories, and potential wildcard paths /// - public List Inputs = new List(); + public List Inputs = new(); #endregion @@ -60,7 +60,7 @@ namespace SabreTools.Help } // Special precautions for wildcarded inputs (potential paths) - else if (args[i].Contains("*") || args[i].Contains("?")) + else if (args[i].Contains('*') || args[i].Contains('?')) { Inputs.Add(args[i]); } @@ -92,7 +92,7 @@ namespace SabreTools.Help /// /// Get boolean value from nullable feature /// - protected bool GetBoolean(Dictionary features, string key) + protected static bool GetBoolean(Dictionary features, string key) { if (!features.ContainsKey(key)) return false; @@ -103,7 +103,7 @@ namespace SabreTools.Help /// /// Get int value from nullable feature /// - protected int GetInt32(Dictionary features, string key) + protected static int GetInt32(Dictionary features, string key) { if (!features.ContainsKey(key)) return Int32.MinValue; @@ -114,7 +114,7 @@ namespace SabreTools.Help /// /// Get long value from nullable feature /// - protected long GetInt64(Dictionary features, string key) + protected static long GetInt64(Dictionary features, string key) { if (!features.ContainsKey(key)) return Int64.MinValue; @@ -125,7 +125,7 @@ namespace SabreTools.Help /// /// Get list value from nullable feature /// - protected List GetList(Dictionary features, string key) + protected static List GetList(Dictionary features, string key) { if (!features.ContainsKey(key)) return new List(); @@ -136,7 +136,7 @@ namespace SabreTools.Help /// /// Get string value from nullable feature /// - protected string GetString(Dictionary features, string key) + protected static string GetString(Dictionary features, string key) { if (!features.ContainsKey(key)) return null; diff --git a/SabreTools.IO/IOExtensions.cs b/SabreTools.IO/IOExtensions.cs index 683a7a61..4ebd837d 100644 --- a/SabreTools.IO/IOExtensions.cs +++ b/SabreTools.IO/IOExtensions.cs @@ -113,12 +113,12 @@ namespace SabreTools.IO return null; // If it does and it is empty, return a blank enumerable - if (Directory.EnumerateFileSystemEntries(root, "*", SearchOption.AllDirectories).Count() == 0) + if (!Directory.EnumerateFileSystemEntries(root, "*", SearchOption.AllDirectories).Any()) return new List(); // Otherwise, get the complete list return Directory.EnumerateDirectories(root, "*", SearchOption.AllDirectories) - .Where(dir => Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories).Count() == 0) + .Where(dir => !Directory.EnumerateFileSystemEntries(dir, "*", SearchOption.AllDirectories).Any()) .ToList(); } } diff --git a/SabreTools.IO/PathTool.cs b/SabreTools.IO/PathTool.cs index 6ea71816..8ded7c1a 100644 --- a/SabreTools.IO/PathTool.cs +++ b/SabreTools.IO/PathTool.cs @@ -21,7 +21,7 @@ namespace SabreTools.IO /// List of strings representing just directories from the inputs public static List GetDirectoriesOnly(List inputs, bool appendparent = false) { - List outputs = new List(); + List outputs = new(); for (int i = 0; i < inputs.Count; i++) { string input = inputs[i]; @@ -32,10 +32,10 @@ namespace SabreTools.IO // If we have a wildcard string pattern = "*"; - if (input.Contains("*") || input.Contains("?")) + if (input.Contains('*') || input.Contains('?')) { pattern = Path.GetFileName(input); - input = input.Substring(0, input.Length - pattern.Length); + input = input[..^pattern.Length]; } // Get the parent path in case of appending @@ -96,7 +96,7 @@ namespace SabreTools.IO /// List of strings representing just files from the inputs public static List GetFilesOnly(List inputs, bool appendparent = false) { - List outputs = new List(); + List outputs = new(); for (int i = 0; i < inputs.Count; i++) { string input = inputs[i].Trim('"'); @@ -107,10 +107,10 @@ namespace SabreTools.IO // If we have a wildcard string pattern = "*"; - if (input.Contains("*") || input.Contains("?")) + if (input.Contains('*') || input.Contains('?')) { pattern = Path.GetFileName(input); - input = input.Substring(0, input.Length - pattern.Length); + input = input[..^pattern.Length]; } // Get the parent path in case of appending diff --git a/SabreTools.IO/Readers/ClrMameProReader.cs b/SabreTools.IO/Readers/ClrMameProReader.cs index 05648e53..020ed3f0 100644 --- a/SabreTools.IO/Readers/ClrMameProReader.cs +++ b/SabreTools.IO/Readers/ClrMameProReader.cs @@ -278,7 +278,7 @@ namespace SabreTools.IO.Readers /// Line to split /// Line split /// Uses code from http://stackoverflow.com/questions/554013/regular-expression-to-split-on-spaces-unless-in-quotes - private string[] SplitLineAsCMP(string s) + private static string[] SplitLineAsCMP(string s) { // Get the opening and closing brace locations int openParenLoc = s.IndexOf('('); diff --git a/SabreTools.IO/Readers/IniReader.cs b/SabreTools.IO/Readers/IniReader.cs index b1d5632a..4296fb19 100644 --- a/SabreTools.IO/Readers/IniReader.cs +++ b/SabreTools.IO/Readers/IniReader.cs @@ -105,7 +105,7 @@ namespace SabreTools.IO.Readers } // KeyValuePair - else if (CurrentLine.Contains("=")) + else if (CurrentLine.Contains('=')) { // Split the line by '=' for key-value pairs string[] data = CurrentLine.Split('='); diff --git a/SabreTools.IO/Readers/SeparatedValueReader.cs b/SabreTools.IO/Readers/SeparatedValueReader.cs index 2f2938c3..6941b372 100644 --- a/SabreTools.IO/Readers/SeparatedValueReader.cs +++ b/SabreTools.IO/Readers/SeparatedValueReader.cs @@ -166,7 +166,7 @@ namespace SabreTools.IO.Readers return null; int index = HeaderValues.IndexOf(key); - if (Line.Count() < index) + if (Line.Count < index) throw new ArgumentException($"Current line doesn't have index {index}"); return Line[index]; @@ -177,7 +177,7 @@ namespace SabreTools.IO.Readers /// public string GetValue(int index) { - if (Line.Count() < index) + if (Line.Count < index) throw new ArgumentException($"Current line doesn't have index {index}"); return Line[index]; diff --git a/SabreTools.IO/Writers/ClrMameProWriter.cs b/SabreTools.IO/Writers/ClrMameProWriter.cs index 3138efa2..d9324f1a 100644 --- a/SabreTools.IO/Writers/ClrMameProWriter.cs +++ b/SabreTools.IO/Writers/ClrMameProWriter.cs @@ -299,7 +299,7 @@ namespace SabreTools.IO.Writers try { if (string.IsNullOrEmpty(name)) - throw new ArgumentException(); + throw new ArgumentException("Name cannot be null or empty", nameof(name)); // If we're writing quotes, don't write out quote characters internally if ((quoteOverride == null && Quotes) diff --git a/SabreTools.IO/Writers/IniWriter.cs b/SabreTools.IO/Writers/IniWriter.cs index 900870b1..26ad51e8 100644 --- a/SabreTools.IO/Writers/IniWriter.cs +++ b/SabreTools.IO/Writers/IniWriter.cs @@ -33,7 +33,7 @@ namespace SabreTools.IO.Writers public void WriteSection(string value) { if (string.IsNullOrWhiteSpace(value)) - throw new ArgumentException(nameof(value)); + throw new ArgumentException("Section tag cannot be null or empty", nameof(value)); sw.WriteLine($"[{value.TrimStart('[').TrimEnd(']')}]"); } @@ -44,11 +44,9 @@ namespace SabreTools.IO.Writers public void WriteKeyValuePair(string key, string value) { if (string.IsNullOrWhiteSpace(key)) - throw new ArgumentException(nameof(key)); - - if (value == null) - value = string.Empty; + throw new ArgumentException("Key cannot be null or empty", nameof(key)); + value ??= string.Empty; sw.WriteLine($"{key}={value}"); } @@ -57,9 +55,7 @@ namespace SabreTools.IO.Writers /// public void WriteComment(string value) { - if (value == null) - value = string.Empty; - + value ??= string.Empty; sw.WriteLine($";{value}"); } @@ -68,9 +64,7 @@ namespace SabreTools.IO.Writers /// public void WriteString(string value) { - if (value == null) - value = string.Empty; - + value ??= string.Empty; sw.Write(value); } diff --git a/SabreTools.Logging/LoggerImpl.cs b/SabreTools.Logging/LoggerImpl.cs index 26987abe..12bc27d3 100644 --- a/SabreTools.Logging/LoggerImpl.cs +++ b/SabreTools.Logging/LoggerImpl.cs @@ -71,7 +71,7 @@ namespace SabreTools.Logging /// /// Object lock for multithreaded logging /// - private static readonly object _lock = new object(); + private static readonly object _lock = new(); #endregion diff --git a/SabreTools.Reports/BaseReport.cs b/SabreTools.Reports/BaseReport.cs index 31472760..8dd9afeb 100644 --- a/SabreTools.Reports/BaseReport.cs +++ b/SabreTools.Reports/BaseReport.cs @@ -15,7 +15,7 @@ namespace SabreTools.Reports /// /// Logging object /// - protected readonly Logger logger = new Logger(); + protected readonly Logger logger = new(); #endregion diff --git a/SabreTools.Reports/Formats/Html.cs b/SabreTools.Reports/Formats/Html.cs index 7291385f..8518c9ee 100644 --- a/SabreTools.Reports/Formats/Html.cs +++ b/SabreTools.Reports/Formats/Html.cs @@ -27,7 +27,7 @@ namespace SabreTools.Reports.Formats /// public override bool WriteToFile(string outfile, bool baddumpCol, bool nodumpCol, bool throwOnError = false) { - InternalStopwatch watch = new InternalStopwatch($"Writing statistics to '{outfile}"); + InternalStopwatch watch = new($"Writing statistics to '{outfile}"); try { @@ -39,7 +39,7 @@ namespace SabreTools.Reports.Formats return false; } - XmlTextWriter xtw = new XmlTextWriter(fs, Encoding.UTF8) + XmlTextWriter xtw = new(fs, Encoding.UTF8) { Formatting = Formatting.Indented, IndentChar = '\t', diff --git a/SabreTools.Reports/Formats/SeparatedValue.cs b/SabreTools.Reports/Formats/SeparatedValue.cs index 285d9ff1..273aa074 100644 --- a/SabreTools.Reports/Formats/SeparatedValue.cs +++ b/SabreTools.Reports/Formats/SeparatedValue.cs @@ -29,7 +29,7 @@ namespace SabreTools.Reports.Formats /// public override bool WriteToFile(string outfile, bool baddumpCol, bool nodumpCol, bool throwOnError = false) { - InternalStopwatch watch = new InternalStopwatch($"Writing statistics to '{outfile}"); + InternalStopwatch watch = new($"Writing statistics to '{outfile}"); try { @@ -41,7 +41,7 @@ namespace SabreTools.Reports.Formats return false; } - SeparatedValueWriter svw = new SeparatedValueWriter(fs, Encoding.UTF8) + SeparatedValueWriter svw = new(fs, Encoding.UTF8) { Separator = _separator, Quotes = true, diff --git a/SabreTools.Reports/Formats/Textfile.cs b/SabreTools.Reports/Formats/Textfile.cs index f428d520..ed5601ef 100644 --- a/SabreTools.Reports/Formats/Textfile.cs +++ b/SabreTools.Reports/Formats/Textfile.cs @@ -27,7 +27,7 @@ namespace SabreTools.Reports.Formats /// public override bool WriteToFile(string outfile, bool baddumpCol, bool nodumpCol, bool throwOnError = false) { - InternalStopwatch watch = new InternalStopwatch($"Writing statistics to '{outfile}"); + InternalStopwatch watch = new($"Writing statistics to '{outfile}"); try { @@ -39,7 +39,7 @@ namespace SabreTools.Reports.Formats return false; } - StreamWriter sw = new StreamWriter(fs); + StreamWriter sw = new(fs); // Now process each of the statistics for (int i = 0; i < Statistics.Count; i++) diff --git a/SabreTools.Skippers/SkipperMatch.cs b/SabreTools.Skippers/SkipperMatch.cs index 7292f94f..a69799f1 100644 --- a/SabreTools.Skippers/SkipperMatch.cs +++ b/SabreTools.Skippers/SkipperMatch.cs @@ -95,15 +95,23 @@ namespace SabreTools.Skippers }); // Deserialize the detector, if possible - if (xts.Deserialize(xtr) is not Detector detector) + if (xts.Deserialize(xtr) is not Detector detector || detector == null) continue; - // Set the source file + // Set the source file on the detector string sourceFile = Path.GetFileNameWithoutExtension(skipperPath); detector.SourceFile = sourceFile; - for (int i = 0; i < (detector.Rules?.Length ?? 0); i++) + + // Set the source file on the rules + if (detector.Rules != null) { - detector.Rules[i].SourceFile = sourceFile; + for (int i = 0; i < detector.Rules.Length; i++) + { + if (detector.Rules[i] == null) + continue; + + detector.Rules[i].SourceFile = sourceFile; + } } // Add the skipper to the set diff --git a/SabreTools.Test/DatFiles/SetterTests.cs b/SabreTools.Test/DatFiles/SetterTests.cs index 62355376..3f6a8815 100644 --- a/SabreTools.Test/DatFiles/SetterTests.cs +++ b/SabreTools.Test/DatFiles/SetterTests.cs @@ -14,7 +14,7 @@ namespace SabreTools.Test.DatFiles public void SetFieldsDatItemTest() { var datItem = CreateDatItem(); - Setter setter = new Setter + Setter setter = new() { DatItemMappings = new Dictionary { [DatItemField.Name] = "bar" } }; @@ -26,7 +26,7 @@ namespace SabreTools.Test.DatFiles public void SetFieldsMachineTest() { var datItem = CreateDatItem(); - Setter setter = new Setter + Setter setter = new() { MachineMappings = new Dictionary { [MachineField.Name] = "foo" } }; @@ -37,7 +37,7 @@ namespace SabreTools.Test.DatFiles /// /// Generate a consistent DatItem for testing /// - private DatItem CreateDatItem() + private static DatItem CreateDatItem() { return new Rom { diff --git a/SabreTools.Test/DatItems/DatItemTests.cs b/SabreTools.Test/DatItems/DatItemTests.cs index 8903ca1c..ca0b71d9 100644 --- a/SabreTools.Test/DatItems/DatItemTests.cs +++ b/SabreTools.Test/DatItems/DatItemTests.cs @@ -200,7 +200,7 @@ namespace SabreTools.Test.DatItems /// /// Create a BaseFile for testing /// - private BaseFile CreateBaseFile(FileType fileType) + private static BaseFile CreateBaseFile(FileType fileType) { return fileType switch { diff --git a/SabreTools.Test/Filtering/CleaningTests.cs b/SabreTools.Test/Filtering/CleaningTests.cs index 02801c9a..f414cb23 100644 --- a/SabreTools.Test/Filtering/CleaningTests.cs +++ b/SabreTools.Test/Filtering/CleaningTests.cs @@ -99,17 +99,11 @@ namespace SabreTools.Test.Filtering [Fact] public void SetOneRomPerGameTest() { - // Setup cleaner - var cleaner = new Cleaner - { - OneRomPerGame = true, - }; - // Setup DatItem var datItem = CreateDatItem("name", "name-2", "name-3"); // Run cleaning - cleaner.SetOneRomPerGame(datItem); + Cleaner.SetOneRomPerGame(datItem); // Check the fields Assert.Equal("name", datItem.GetName()); @@ -119,7 +113,7 @@ namespace SabreTools.Test.Filtering /// /// Generate a consistent DatItem for testing /// - private DatItem CreateDatItem(string name, string machine, string desc) + private static DatItem CreateDatItem(string name, string machine, string desc) { return new Rom { diff --git a/SabreTools.Test/Filtering/FilteringTests.cs b/SabreTools.Test/Filtering/FilteringTests.cs index 357a3d73..a91bb89f 100644 --- a/SabreTools.Test/Filtering/FilteringTests.cs +++ b/SabreTools.Test/Filtering/FilteringTests.cs @@ -72,7 +72,7 @@ namespace SabreTools.Test.Filtering /// /// Generate a consistent DatItem for testing /// - private DatItem CreateDatItem() + private static DatItem CreateDatItem() { return new Rom { diff --git a/SabreTools.Test/Filtering/PopulationTests.cs b/SabreTools.Test/Filtering/PopulationTests.cs index 3802e5e1..b9ba9211 100644 --- a/SabreTools.Test/Filtering/PopulationTests.cs +++ b/SabreTools.Test/Filtering/PopulationTests.cs @@ -27,7 +27,7 @@ namespace SabreTools.Test.Filtering public void PopulateExclusionEmptyListTest() { // Setup the list - List exclusions = new List(); + List exclusions = new(); // Setup the remover var remover = new Remover(); @@ -43,7 +43,7 @@ namespace SabreTools.Test.Filtering public void PopulateExclusionHeaderFieldTest() { // Setup the list - List exclusions = new List + List exclusions = new() { "header.datname", }; @@ -62,7 +62,7 @@ namespace SabreTools.Test.Filtering public void PopulateExclusionMachineFieldTest() { // Setup the list - List exclusions = new List + List exclusions = new() { "machine.name", }; @@ -81,7 +81,7 @@ namespace SabreTools.Test.Filtering public void PopulateExclusionDatItemFieldTest() { // Setup the list - List exclusions = new List + List exclusions = new() { "item.name", }; @@ -115,7 +115,7 @@ namespace SabreTools.Test.Filtering public void PopulateFilterEmptyListTest() { // Setup the list - List filters = new List(); + List filters = new(); // Setup the filter var filter = new Filter(); @@ -130,7 +130,7 @@ namespace SabreTools.Test.Filtering public void PopulateFilterMachineFieldTest() { // Setup the list - List filters = new List + List filters = new() { "machine.name:foo", "!machine.name:bar", @@ -150,7 +150,7 @@ namespace SabreTools.Test.Filtering public void PopulateFilterDatItemFieldTest() { // Setup the list - List filters = new List + List filters = new() { "item.name:foo", "!item.name:bar" diff --git a/SabreTools.Test/Filtering/RemoverTests.cs b/SabreTools.Test/Filtering/RemoverTests.cs index dff5f423..d0c64c7c 100644 --- a/SabreTools.Test/Filtering/RemoverTests.cs +++ b/SabreTools.Test/Filtering/RemoverTests.cs @@ -30,7 +30,7 @@ namespace SabreTools.Test.Filtering /// /// Generate a consistent DatItem for testing /// - private DatItem CreateDatItem() + private static DatItem CreateDatItem() { return new Rom { diff --git a/SabreTools.Test/Filtering/ReplacerTests.cs b/SabreTools.Test/Filtering/ReplacerTests.cs index 33aec135..da4130f5 100644 --- a/SabreTools.Test/Filtering/ReplacerTests.cs +++ b/SabreTools.Test/Filtering/ReplacerTests.cs @@ -35,7 +35,7 @@ namespace SabreTools.Test.Filtering /// /// Generate a consistent DatItem for testing /// - private DatItem CreateDatItem() + private static DatItem CreateDatItem() { return new Rom { diff --git a/SabreTools/Features/BaseFeature.cs b/SabreTools/Features/BaseFeature.cs index 7a4177e0..6456f765 100644 --- a/SabreTools/Features/BaseFeature.cs +++ b/SabreTools/Features/BaseFeature.cs @@ -23,7 +23,7 @@ namespace SabreTools.Features /// /// Logging object /// - protected Logger logger = new Logger(); + protected Logger logger = new(); #endregion @@ -1916,7 +1916,7 @@ Some special strings that can be used: /// /// Get include from scan from feature list /// - protected Hash GetIncludeInScan(Dictionary features) + protected static Hash GetIncludeInScan(Dictionary features) { Hash includeInScan = 0x00; @@ -1945,7 +1945,7 @@ Some special strings that can be used: /// /// Get OutputFormat from feature list /// - protected OutputFormat GetOutputFormat(Dictionary features) + protected static OutputFormat GetOutputFormat(Dictionary features) { if (GetBoolean(features, TarValue)) return OutputFormat.TapeArchive; @@ -1974,7 +1974,7 @@ Some special strings that can be used: /// /// Get SkipFileType from feature list /// - protected SkipFileType GetSkipFileType(Dictionary features) + protected static SkipFileType GetSkipFileType(Dictionary features) { if (GetBoolean(features, SkipArchivesValue)) return SkipFileType.Archive; @@ -1987,7 +1987,7 @@ Some special strings that can be used: /// /// Get SplittingMode from feature list /// - protected SplittingMode GetSplittingMode(Dictionary features) + protected static SplittingMode GetSplittingMode(Dictionary features) { SplittingMode splittingMode = SplittingMode.None; @@ -2010,7 +2010,7 @@ Some special strings that can be used: /// /// Get StatReportFormat from feature list /// - protected StatReportFormat GetStatReportFormat(Dictionary features) + protected static StatReportFormat GetStatReportFormat(Dictionary features) { StatReportFormat statDatFormat = StatReportFormat.None; @@ -2025,7 +2025,7 @@ Some special strings that can be used: /// /// Get TreatAsFiles from feature list /// - protected TreatAsFile GetTreatAsFiles(Dictionary features) + protected static TreatAsFile GetTreatAsFiles(Dictionary features) { TreatAsFile asFiles = 0x00; if (GetBoolean(features, AaruFormatsAsFilesValue)) @@ -2041,9 +2041,9 @@ Some special strings that can be used: /// /// Get update DatItem fields from feature list /// - protected List GetUpdateDatItemFields(Dictionary features) + protected static List GetUpdateDatItemFields(Dictionary features) { - List updateFields = new List(); + List updateFields = new(); foreach (string fieldName in GetList(features, UpdateFieldListValue)) { updateFields.Add(fieldName.AsDatItemField()); @@ -2055,9 +2055,9 @@ Some special strings that can be used: /// /// Get update Machine fields from feature list /// - protected List GetUpdateMachineFields(Dictionary features) + protected static List GetUpdateMachineFields(Dictionary features) { - List updateFields = new List(); + List updateFields = new(); foreach (string fieldName in GetList(features, UpdateFieldListValue)) { updateFields.Add(fieldName.AsMachineField()); @@ -2069,7 +2069,7 @@ Some special strings that can be used: /// /// Get UpdateMode from feature list /// - protected UpdateMode GetUpdateMode(Dictionary features) + protected static UpdateMode GetUpdateMode(Dictionary features) { UpdateMode updateMode = UpdateMode.None; @@ -2113,9 +2113,9 @@ Some special strings that can be used: /// /// Get Cleaner from feature list /// - private Cleaner GetCleaner(Dictionary features) + private static Cleaner GetCleaner(Dictionary features) { - Cleaner cleaner = new Cleaner() + Cleaner cleaner = new() { Clean = GetBoolean(features, CleanValue), DedupeRoms = GetDedupeType(features), @@ -2140,7 +2140,7 @@ Some special strings that can be used: private DatHeader GetDatHeader(Dictionary features) { // TODO: Sort this by region, like the actual header - DatHeader datHeader = new DatHeader + DatHeader datHeader = new() { AddExtension = GetString(features, AddExtensionStringValue), Author = GetString(features, AuthorStringValue), @@ -2167,15 +2167,14 @@ Some special strings that can be used: Url = GetString(features, UrlStringValue), UseRomName = GetBoolean(features, RomsValue), Version = GetString(features, VersionStringValue), - }; - - // Get the depot information - datHeader.InputDepot = new DepotInformation( + // Get the depot information + InputDepot = new DepotInformation( GetBoolean(features, DepotValue), - GetInt32(features, DepotDepthInt32Value)); - datHeader.OutputDepot = new DepotInformation( + GetInt32(features, DepotDepthInt32Value)), + OutputDepot = new DepotInformation( GetBoolean(features, RombaValue), - GetInt32(features, RombaDepthInt32Value)); + GetInt32(features, RombaDepthInt32Value)) + }; bool deprecated = GetBoolean(features, DeprecatedValue); foreach (string ot in GetList(features, OutputTypeListValue)) @@ -2202,7 +2201,7 @@ Some special strings that can be used: /// /// Get DedupeType from feature list /// - private DedupeType GetDedupeType(Dictionary features) + private static DedupeType GetDedupeType(Dictionary features) { if (GetBoolean(features, DedupValue)) return DedupeType.Full; @@ -2215,9 +2214,9 @@ Some special strings that can be used: /// /// Get ExtraIni from feature list /// - private ExtraIni GetExtras(Dictionary features) + private static ExtraIni GetExtras(Dictionary features) { - ExtraIni extraIni = new ExtraIni(); + ExtraIni extraIni = new(); extraIni.PopulateFromList(GetList(features, ExtraIniListValue)); return extraIni; } @@ -2225,9 +2224,9 @@ Some special strings that can be used: /// /// Get Filter from feature list /// - private Filter GetFilter(Dictionary features) + private static Filter GetFilter(Dictionary features) { - Filter filter = new Filter() + Filter filter = new() { DatItemFilter = new DatItemFilter(), MachineFilter = new MachineFilter(), @@ -2246,9 +2245,9 @@ Some special strings that can be used: /// /// Get Remover from feature list /// - private Remover GetRemover(Dictionary features) + private static Remover GetRemover(Dictionary features) { - Remover remover = new Remover(); + Remover remover = new(); // Populate field exclusions List exclusionFields = GetList(features, ExcludeFieldListValue); @@ -2260,9 +2259,9 @@ Some special strings that can be used: /// /// Get Splitter from feature list /// - private Filtering.Splitter GetSplitter(Dictionary features) + private static Filtering.Splitter GetSplitter(Dictionary features) { - Filtering.Splitter splitter = new Filtering.Splitter + Filtering.Splitter splitter = new() { SplitType = GetSplitType(features), }; @@ -2272,7 +2271,7 @@ Some special strings that can be used: /// /// Get SplitType from feature list /// - private MergingFlag GetSplitType(Dictionary features) + private static MergingFlag GetSplitType(Dictionary features) { MergingFlag splitType = MergingFlag.None; if (GetBoolean(features, DatDeviceNonMergedValue)) @@ -2305,7 +2304,7 @@ Some special strings that can be used: File.Create(HeadererFileName); // Open the database connection - SqliteConnection dbc = new SqliteConnection(HeadererConnectionString); + SqliteConnection dbc = new(HeadererConnectionString); dbc.Open(); // Make sure the database has the correct schema @@ -2316,7 +2315,7 @@ CREATE TABLE IF NOT EXISTS data ( 'type' TEXT NOT NULL, PRIMARY KEY (sha1, header, type) )"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); slc.ExecuteNonQuery(); slc.Dispose(); dbc.Dispose(); @@ -2329,81 +2328,36 @@ CREATE TABLE IF NOT EXISTS data ( /// DatFormat value corresponding to the string protected static DatFormat GetDatFormat(string input) { - switch (input?.Trim().ToLowerInvariant()) + return (input?.Trim().ToLowerInvariant()) switch { - case "all": - return DatFormat.ALL; - case "ado": - case "archive": - return DatFormat.ArchiveDotOrg; - case "am": - case "attractmode": - return DatFormat.AttractMode; - case "cmp": - case "clrmamepro": - return DatFormat.ClrMamePro; - case "csv": - return DatFormat.CSV; - case "dc": - case "doscenter": - return DatFormat.DOSCenter; - case "everdrive": - case "smdb": - return DatFormat.EverdriveSMDB; - case "json": - case "sj": - case "sabrejson": - return DatFormat.SabreJSON; - case "lr": - case "listrom": - return DatFormat.Listrom; - case "lx": - case "listxml": - return DatFormat.Listxml; - case "md5": - return DatFormat.RedumpMD5; - case "miss": - case "missfile": - return DatFormat.MissFile; - case "msx": - case "openmsx": - return DatFormat.OpenMSX; - case "ol": - case "offlinelist": - return DatFormat.OfflineList; - case "rc": - case "romcenter": - return DatFormat.RomCenter; - case "sd": - case "sabredat": - case "sx": - case "sabrexml": - return DatFormat.SabreXML; - case "sfv": - return DatFormat.RedumpSFV; - case "sha1": - return DatFormat.RedumpSHA1; - case "sha256": - return DatFormat.RedumpSHA256; - case "sha384": - return DatFormat.RedumpSHA384; - case "sha512": - return DatFormat.RedumpSHA512; - case "sl": - case "softwarelist": - return DatFormat.SoftwareList; - case "spamsum": - return DatFormat.RedumpSpamSum; - case "ssv": - return DatFormat.SSV; - case "tsv": - return DatFormat.TSV; - case "xml": - case "logiqx": - return DatFormat.Logiqx; - default: - return 0x0; - } + "all" => DatFormat.ALL, + "ado" or "archive" => DatFormat.ArchiveDotOrg, + "am" or "attractmode" => DatFormat.AttractMode, + "cmp" or "clrmamepro" => DatFormat.ClrMamePro, + "csv" => DatFormat.CSV, + "dc" or "doscenter" => DatFormat.DOSCenter, + "everdrive" or "smdb" => DatFormat.EverdriveSMDB, + "json" or "sj" or "sabrejson" => DatFormat.SabreJSON, + "lr" or "listrom" => DatFormat.Listrom, + "lx" or "listxml" => DatFormat.Listxml, + "md5" => DatFormat.RedumpMD5, + "miss" or "missfile" => DatFormat.MissFile, + "msx" or "openmsx" => DatFormat.OpenMSX, + "ol" or "offlinelist" => DatFormat.OfflineList, + "rc" or "romcenter" => DatFormat.RomCenter, + "sd" or "sabredat" or "sx" or "sabrexml" => DatFormat.SabreXML, + "sfv" => DatFormat.RedumpSFV, + "sha1" => DatFormat.RedumpSHA1, + "sha256" => DatFormat.RedumpSHA256, + "sha384" => DatFormat.RedumpSHA384, + "sha512" => DatFormat.RedumpSHA512, + "sl" or "softwarelist" => DatFormat.SoftwareList, + "spamsum" => DatFormat.RedumpSpamSum, + "ssv" => DatFormat.SSV, + "tsv" => DatFormat.TSV, + "xml" or "logiqx" => DatFormat.Logiqx, + _ => 0x0, + }; } #endregion diff --git a/SabreTools/Features/Batch.cs b/SabreTools/Features/Batch.cs index ea829043..3308a3da 100644 --- a/SabreTools/Features/Batch.cs +++ b/SabreTools/Features/Batch.cs @@ -60,7 +60,7 @@ Reset the internal state: reset();"; // Try to read each input as a batch run file foreach (string path in Inputs) { - InternalStopwatch watch = new InternalStopwatch($"Processing '{path}'..."); + InternalStopwatch watch = new($"Processing '{path}'..."); ProcessScript(path); watch.Stop(); } @@ -88,7 +88,7 @@ Reset the internal state: reset();"; string[] lines = File.ReadAllLines(path); // Each batch file has its own state - BatchState batchState = new BatchState(); + BatchState batchState = new(); // Process each command line foreach (string line in lines) @@ -244,7 +244,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - Cleaner descNameCleaner = new Cleaner { DescriptionAsName = true }; + Cleaner descNameCleaner = new() { DescriptionAsName = true }; descNameCleaner.ApplyCleaning(batchState.DatFile); } } @@ -286,7 +286,7 @@ Reset the internal state: reset();"; } // TODO: We might not want to remove dates in the future - Remover dfdRemover = new Remover(); + Remover dfdRemover = new(); dfdRemover.PopulateExclusionsFromList(new List { "DatItem.Date" }); dfdRemover.ApplyRemovals(batchState.DatFile); } @@ -345,8 +345,8 @@ Reset the internal state: reset();"; string extraFile = Arguments[1]; // Create the extra INI - ExtraIni extraIni = new ExtraIni(); - ExtraIniItem extraIniItem = new ExtraIniItem + ExtraIni extraIni = new(); + ExtraIniItem extraIniItem = new() { MachineField = extraMachineField, DatItemField = extraDatItemField, @@ -430,7 +430,7 @@ Reset the internal state: reset();"; filterPerMachine = Arguments[3].AsYesNo(); // Create filter to run filters from - Filter filter = new Filter + Filter filter = new() { MachineFilter = new MachineFilter { HasFilters = true }, DatItemFilter = new DatItemFilter { HasFilters = true }, @@ -474,7 +474,7 @@ Reset the internal state: reset();"; } // Check all inputs to be valid formats - List unmappedFormats = new List(); + List unmappedFormats = new(); foreach (string format in Arguments) { if (GetDatFormat(format) == 0x0) @@ -586,7 +586,7 @@ Reset the internal state: reset();"; MergingFlag mergingFlag = Arguments[0].AsMergingFlag(); // Apply the merging flag - Filtering.Splitter splitter = new Filtering.Splitter { SplitType = mergingFlag }; + Filtering.Splitter splitter = new() { SplitType = mergingFlag }; splitter.ApplySplitting(batchState.DatFile, false, false); } } @@ -620,7 +620,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - Cleaner ogorCleaner = new Cleaner { OneGamePerRegion = true, RegionList = Arguments }; + Cleaner ogorCleaner = new() { OneGamePerRegion = true, RegionList = Arguments }; ogorCleaner.ApplyCleaning(batchState.DatFile); } } @@ -654,7 +654,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - Cleaner orpgCleaner = new Cleaner { OneRomPerGame = true }; + Cleaner orpgCleaner = new() { OneRomPerGame = true }; orpgCleaner.ApplyCleaning(batchState.DatFile); } } @@ -721,7 +721,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - Remover remover = new Remover(); + Remover remover = new(); remover.PopulateExclusionsFromList(Arguments); remover.ApplyRemovals(batchState.DatFile); } @@ -789,7 +789,7 @@ Reset the internal state: reset();"; /// public override void Process(BatchState batchState) { - Cleaner stripCleaner = new Cleaner { SceneDateStrip = true }; + Cleaner stripCleaner = new() { SceneDateStrip = true }; stripCleaner.ApplyCleaning(batchState.DatFile); } } diff --git a/SabreTools/Features/Extract.cs b/SabreTools/Features/Extract.cs index 4e6bf9a3..9ce437fc 100644 --- a/SabreTools/Features/Extract.cs +++ b/SabreTools/Features/Extract.cs @@ -130,11 +130,11 @@ The following systems have headers that this program can work with: EnsureDatabase(); // Open the database connection - SqliteConnection dbc = new SqliteConnection(HeadererConnectionString); + SqliteConnection dbc = new(HeadererConnectionString); dbc.Open(); string query = $"SELECT * FROM data WHERE sha1='{SHA1}' AND header='{header}'"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); bool exists = sldr.HasRows; diff --git a/SabreTools/Features/Restore.cs b/SabreTools/Features/Restore.cs index 951d7190..8aef3c0e 100644 --- a/SabreTools/Features/Restore.cs +++ b/SabreTools/Features/Restore.cs @@ -100,14 +100,14 @@ The following systems have headers that this program can work with: EnsureDatabase(); // Open the database connection - SqliteConnection dbc = new SqliteConnection(HeadererConnectionString); + SqliteConnection dbc = new(HeadererConnectionString); dbc.Open(); // Create the output list of headers - List headers = new List(); + List headers = new(); string query = $"SELECT header, type FROM data WHERE sha1='{SHA1}'"; - SqliteCommand slc = new SqliteCommand(query, dbc); + SqliteCommand slc = new(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); if (sldr.HasRows) @@ -138,7 +138,7 @@ The following systems have headers that this program can work with: /// Outputted file /// Bytes to be added to head of file /// Bytes to be added to tail of file - private void AppendBytes(string input, string output, byte[] bytesToAddToHead, byte[] bytesToAddToTail) + private static void AppendBytes(string input, string output, byte[] bytesToAddToHead, byte[] bytesToAddToTail) { // If any of the inputs are invalid, skip if (!File.Exists(input)) @@ -146,7 +146,7 @@ The following systems have headers that this program can work with: using FileStream fsr = File.OpenRead(input); using FileStream fsw = File.OpenWrite(output); - + AppendBytes(fsr, fsw, bytesToAddToHead, bytesToAddToTail); } @@ -157,7 +157,7 @@ The following systems have headers that this program can work with: /// Outputted stream /// Bytes to be added to head of stream /// Bytes to be added to tail of stream - private void AppendBytes(Stream input, Stream output, byte[] bytesToAddToHead, byte[] bytesToAddToTail) + private static void AppendBytes(Stream input, Stream output, byte[] bytesToAddToHead, byte[] bytesToAddToTail) { // Write out prepended bytes if (bytesToAddToHead != null && bytesToAddToHead.Length > 0) diff --git a/SabreTools/Features/Sort.cs b/SabreTools/Features/Sort.cs index f1357027..88346095 100644 --- a/SabreTools/Features/Sort.cs +++ b/SabreTools/Features/Sort.cs @@ -127,7 +127,7 @@ namespace SabreTools.Features // Otherwise, process all DATs into the same output else { - InternalStopwatch watch = new InternalStopwatch("Populating internal DAT"); + InternalStopwatch watch = new("Populating internal DAT"); // Add all of the input DATs into one huge internal DAT DatFile datdata = DatFile.Create(); diff --git a/SabreTools/Features/Split.cs b/SabreTools/Features/Split.cs index 5020a893..fba832b9 100644 --- a/SabreTools/Features/Split.cs +++ b/SabreTools/Features/Split.cs @@ -77,7 +77,7 @@ namespace SabreTools.Features { (DatFile extADat, DatFile extBDat) = DatTools.Splitter.SplitByExtension(internalDat, GetList(features, ExtAListValue), GetList(features, ExtBListValue)); - InternalStopwatch watch = new InternalStopwatch("Outputting extension-split DATs"); + InternalStopwatch watch = new("Outputting extension-split DATs"); // Output both possible DatFiles Writer.Write(extADat, OutputDir); @@ -91,7 +91,7 @@ namespace SabreTools.Features { Dictionary typeDats = DatTools.Splitter.SplitByHash(internalDat); - InternalStopwatch watch = new InternalStopwatch("Outputting hash-split DATs"); + InternalStopwatch watch = new("Outputting hash-split DATs"); // Loop through each type DatFile Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType => @@ -118,7 +118,7 @@ namespace SabreTools.Features { (DatFile lessThan, DatFile greaterThan) = DatTools.Splitter.SplitBySize(internalDat, GetInt64(features, RadixInt64Value)); - InternalStopwatch watch = new InternalStopwatch("Outputting size-split DATs"); + InternalStopwatch watch = new("Outputting size-split DATs"); // Output both possible DatFiles Writer.Write(lessThan, OutputDir); @@ -133,7 +133,7 @@ namespace SabreTools.Features logger.Warning("This feature is not implemented: level-split"); List sizedDats = DatTools.Splitter.SplitByTotalSize(internalDat, GetInt64(features, ChunkSizeInt64Value)); - InternalStopwatch watch = new InternalStopwatch("Outputting total-size-split DATs"); + InternalStopwatch watch = new("Outputting total-size-split DATs"); // Loop through each type DatFile Parallel.ForEach(sizedDats, Globals.ParallelOptions, sizedDat => @@ -149,7 +149,7 @@ namespace SabreTools.Features { Dictionary typeDats = DatTools.Splitter.SplitByType(internalDat); - InternalStopwatch watch = new InternalStopwatch("Outputting ItemType DATs"); + InternalStopwatch watch = new("Outputting ItemType DATs"); // Loop through each type DatFile Parallel.ForEach(typeDats.Keys, Globals.ParallelOptions, itemType => diff --git a/SabreTools/Features/Update.cs b/SabreTools/Features/Update.cs index bd36c839..1edd9625 100644 --- a/SabreTools/Features/Update.cs +++ b/SabreTools/Features/Update.cs @@ -214,7 +214,7 @@ namespace SabreTools.Features { DatFile dupeData = DatFileTool.DiffDuplicates(userInputDat, inputPaths); - InternalStopwatch watch = new InternalStopwatch("Outputting duplicate DAT"); + InternalStopwatch watch = new("Outputting duplicate DAT"); Writer.Write(dupeData, OutputDir, overwrite: false); watch.Stop(); } @@ -224,7 +224,7 @@ namespace SabreTools.Features { DatFile outerDiffData = DatFileTool.DiffNoDuplicates(userInputDat, inputPaths); - InternalStopwatch watch = new InternalStopwatch("Outputting no duplicate DAT"); + InternalStopwatch watch = new("Outputting no duplicate DAT"); Writer.Write(outerDiffData, OutputDir, overwrite: false); watch.Stop(); } @@ -236,7 +236,7 @@ namespace SabreTools.Features List datFiles = DatFileTool.DiffIndividuals(userInputDat, inputPaths); // Loop through and output the new DatFiles - InternalStopwatch watch = new InternalStopwatch("Outputting all individual DATs"); + InternalStopwatch watch = new("Outputting all individual DATs"); Parallel.For(0, inputPaths.Count, Globals.ParallelOptions, j => { @@ -271,7 +271,7 @@ namespace SabreTools.Features List datFiles = DatFileTool.DiffCascade(userInputDat, datHeaders); // Loop through and output the new DatFiles - InternalStopwatch watch = new InternalStopwatch("Outputting all created DATs"); + InternalStopwatch watch = new("Outputting all created DATs"); int startIndex = GetBoolean(features, SkipFirstOutputValue) ? 1 : 0; Parallel.For(startIndex, inputPaths.Count, Globals.ParallelOptions, j => diff --git a/SabreTools/Features/Verify.cs b/SabreTools/Features/Verify.cs index 9634fdf6..480589c8 100644 --- a/SabreTools/Features/Verify.cs +++ b/SabreTools/Features/Verify.cs @@ -104,7 +104,7 @@ namespace SabreTools.Features // Otherwise, process all DATs into the same output else { - InternalStopwatch watch = new InternalStopwatch("Populating internal DAT"); + InternalStopwatch watch = new("Populating internal DAT"); // Add all of the input DATs into one huge internal DAT DatFile datdata = DatFile.Create(); diff --git a/SabreTools/Program.cs b/SabreTools/Program.cs index 5db8aa1b..505715e1 100644 --- a/SabreTools/Program.cs +++ b/SabreTools/Program.cs @@ -22,7 +22,7 @@ namespace SabreTools /// /// Logging object /// - private static readonly Logger logger = new Logger(); + private static readonly Logger logger = new(); #endregion @@ -45,7 +45,7 @@ namespace SabreTools // Credits take precidence over all if ((new List(args)).Contains("--credits")) { - _help.OutputCredits(); + FeatureSet.OutputCredits(); LoggerImpl.Close(); return; } @@ -161,7 +161,7 @@ namespace SabreTools { // Create and add the header to the Help object string barrier = "-----------------------------------------"; - List helpHeader = new List() + List helpHeader = new() { "SabreTools - Manipulate, convert, and use DAT files", barrier, @@ -170,7 +170,7 @@ namespace SabreTools }; // Create the base help object with header - FeatureSet help = new FeatureSet(helpHeader); + FeatureSet help = new(helpHeader); // Add all of the features help.Add(new DisplayHelp());