diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index 5655d364..cb75db2b 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -641,6 +641,12 @@ namespace SabreTools.Library.DatFiles cmpw.WriteEndElement(); break; + case ItemType.DeviceReference: + cmpw.WriteStartElement("device_ref"); + cmpw.WriteRequiredAttributeString("name", datItem.Name); + cmpw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; cmpw.WriteStartElement("disk"); diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index b433a9c3..b09ec9ad 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1389,8 +1389,7 @@ namespace SabreTools.Library.DatFiles // If the game has no devices, mark it bool devices = true; - if (Items[game][0].Machine.DeviceReferences == null - || Items[game][0].Machine.DeviceReferences.Count == 0) + if (Items[game].Count(i => i.ItemType == ItemType.DeviceReference) == 0) { devices = false; } @@ -1399,7 +1398,10 @@ namespace SabreTools.Library.DatFiles if (devices) { // Determine if the game has any devices or not - List deviceReferences = Items[game][0].Machine.DeviceReferences.Select(d => d.Name).ToList(); + List deviceReferences = Items[game] + .Where(i => i.ItemType == ItemType.DeviceReference) + .Select(i => i.Name) + .ToList(); List newdevs = new List(); foreach (string deviceReference in deviceReferences) { @@ -1410,10 +1412,13 @@ namespace SabreTools.Library.DatFiles // Otherwise, copy the items from the device to the current game DatItem copyFrom = Items[game][0]; List devItems = Items[deviceReference]; + newdevs.AddRange((Items[deviceReference] ?? new List()) + .Where(i => i.ItemType == ItemType.DeviceReference) + .Select(i => i.Name)); + foreach (DatItem item in devItems) { DatItem datItem = (DatItem)item.Clone(); - newdevs.AddRange((datItem.Machine.DeviceReferences ?? new List()).Select(d => d.Name).ToList()); datItem.CopyMachineInformation(copyFrom); if (Items[game].Where(i => i.ItemType == datItem.ItemType && i.Name == datItem.Name).Count() == 0) { @@ -1427,7 +1432,7 @@ namespace SabreTools.Library.DatFiles foreach (string device in newdevs) { if (!deviceReferences.Contains(device)) - Items[game][0].Machine.DeviceReferences.Add(new ListXmlDeviceReference() { Name = device }); + Items[game].Add(new DeviceReference() { Name = device }); } } diff --git a/SabreTools.Library/DatFiles/ItemDictionary.cs b/SabreTools.Library/DatFiles/ItemDictionary.cs index 58267acb..b24db227 100644 --- a/SabreTools.Library/DatFiles/ItemDictionary.cs +++ b/SabreTools.Library/DatFiles/ItemDictionary.cs @@ -95,6 +95,12 @@ namespace SabreTools.Library.DatFiles [JsonIgnore] public long ChipCount { get; private set; } = 0; + /// + /// Number of Device Reference items + /// + [JsonIgnore] + public long DeviceReferenceCount { get; private set; } = 0; + /// /// Number of Disk items /// @@ -461,6 +467,9 @@ namespace SabreTools.Library.DatFiles case ItemType.Chip: ChipCount++; break; + case ItemType.DeviceReference: + DeviceReferenceCount++; + break; case ItemType.Disk: DiskCount++; if ((item as Disk).ItemStatus != ItemStatus.Nodump) @@ -590,6 +599,9 @@ namespace SabreTools.Library.DatFiles case ItemType.Chip: ChipCount--; break; + case ItemType.DeviceReference: + DeviceReferenceCount--; + break; case ItemType.Disk: DiskCount--; if ((item as Disk).ItemStatus != ItemStatus.Nodump) diff --git a/SabreTools.Library/DatFiles/Json.cs b/SabreTools.Library/DatFiles/Json.cs index 6536563c..91fbc259 100644 --- a/SabreTools.Library/DatFiles/Json.cs +++ b/SabreTools.Library/DatFiles/Json.cs @@ -220,6 +220,9 @@ namespace SabreTools.Library.DatFiles case ItemType.Chip: datItem = datItemObj.ToObject(); break; + case ItemType.DeviceReference: + datItem = datItemObj.ToObject(); + break; case ItemType.Disk: datItem = datItemObj.ToObject(); break; diff --git a/SabreTools.Library/DatFiles/Listxml.cs b/SabreTools.Library/DatFiles/Listxml.cs index 5eb74cd0..f8995875 100644 --- a/SabreTools.Library/DatFiles/Listxml.cs +++ b/SabreTools.Library/DatFiles/Listxml.cs @@ -238,14 +238,10 @@ namespace SabreTools.Library.DatFiles break; case "device_ref": - var deviceReference = new ListXmlDeviceReference(); - deviceReference.Name = reader.GetAttribute("name"); - - // Ensure the list exists - if (machine.DeviceReferences == null) - machine.DeviceReferences = new List(); - - machine.DeviceReferences.Add(deviceReference); + datItems.Add(new DeviceReference + { + Name = reader.GetAttribute("name"), + }); reader.Read(); break; @@ -503,7 +499,7 @@ namespace SabreTools.Library.DatFiles case "softwarelist": var softwareList = new ListXmlSoftwareList(); softwareList.Name = reader.GetAttribute("name"); - softwareList.Status = reader.GetAttribute("status"); + softwareList.Status = reader.GetAttribute("status").AsSoftwareListStatus(); softwareList.Filter = reader.GetAttribute("filter"); // Ensure the list exists @@ -1080,18 +1076,6 @@ namespace SabreTools.Library.DatFiles xtw.WriteOptionalElementString("manufacturer", datItem.Machine.Manufacturer); // TODO: These should go *after* the datitems - if (datItem.Machine.DeviceReferences != null) - { - foreach (var deviceReference in datItem.Machine.DeviceReferences) - { - xtw.WriteStartElement("device_ref"); - - xtw.WriteOptionalAttributeString("name", deviceReference.Name); - - // End device_ref - xtw.WriteEndElement(); - } - } if (datItem.Machine.Displays != null) { foreach (var display in datItem.Machine.Displays) @@ -1428,7 +1412,7 @@ namespace SabreTools.Library.DatFiles xtw.WriteStartElement("softwarelist"); xtw.WriteOptionalAttributeString("name", softwarelist.Name); - xtw.WriteOptionalAttributeString("status", softwarelist.Status); + xtw.WriteOptionalAttributeString("status", softwarelist.Status.FromSoftwareListStatus()); xtw.WriteOptionalAttributeString("filter", softwarelist.Filter); // End softwarelist @@ -1518,6 +1502,12 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); break; + case ItemType.DeviceReference: + xtw.WriteStartElement("device_ref"); + xtw.WriteRequiredAttributeString("name", datItem.Name); + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; xtw.WriteStartElement("disk"); diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index 9d2b0483..ce42ec57 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -988,6 +988,12 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); break; + case ItemType.DeviceReference: + xtw.WriteStartElement("device_ref"); + xtw.WriteRequiredAttributeString("name", datItem.Name); + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; xtw.WriteStartElement("disk"); diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index 6fe80fdc..465e8137 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -867,6 +867,13 @@ namespace SabreTools.Library.DatFiles xtw.WriteEndElement(); break; + case ItemType.DeviceReference: + xtw.WriteStartElement("file"); + xtw.WriteAttributeString("type", "device_ref"); + xtw.WriteRequiredAttributeString("name", datItem.Name); + xtw.WriteEndElement(); + break; + case ItemType.Disk: var disk = datItem as Disk; xtw.WriteStartElement("file"); diff --git a/SabreTools.Library/DatItems/Auxiliary.cs b/SabreTools.Library/DatItems/Auxiliary.cs index fc327023..cf445b18 100644 --- a/SabreTools.Library/DatItems/Auxiliary.cs +++ b/SabreTools.Library/DatItems/Auxiliary.cs @@ -181,17 +181,6 @@ namespace SabreTools.Library.DatItems public List Extensions { get; set; } } - /// - /// Represents one ListXML deviceref - /// - /// TODO: Promote this to the same level as Sample - [JsonObject("deviceref")] - public class ListXmlDeviceReference - { - [JsonProperty("name")] - public string Name { get; set; } - } - /// /// Represents one ListXML display /// @@ -440,7 +429,7 @@ namespace SabreTools.Library.DatItems public string Name { get; set; } [JsonProperty("status")] - public string Status { get; set; } // TODO: (original|compatible) + public SoftwareListStatus Status { get; set; } [JsonProperty("filter")] public string Filter { get; set; } diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index 24abe0b4..afb1bcc9 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -234,45 +234,51 @@ namespace SabreTools.Library.DatItems #region Item-Specific + #region Actionable + + // Rom + Field.DatItem_Bios, + Field.DatItem_Size, + Field.DatItem_CRC, + Field.DatItem_MD5, +#if NET_FRAMEWORK + Field.DatItem_RIPEMD160, +#endif + Field.DatItem_SHA1, + Field.DatItem_SHA256, + Field.DatItem_SHA384, + Field.DatItem_SHA512, + Field.DatItem_Merge, + Field.DatItem_Region, + Field.DatItem_Offset, + Field.DatItem_Date, + Field.DatItem_Status, + Field.DatItem_Optional, + Field.DatItem_Inverted, + + // Disk + Field.DatItem_Index, + Field.DatItem_Writable, + + #endregion + + #region Auxiliary + // BiosSet - Field.DatItem_Default, Field.DatItem_Description, + Field.DatItem_Default, // Chip Field.DatItem_Tag, Field.DatItem_ChipType, Field.DatItem_Clock, - // Disk - Field.DatItem_MD5, - Field.DatItem_SHA1, - Field.DatItem_Merge, - Field.DatItem_Region, - Field.DatItem_Index, - Field.DatItem_Writable, - Field.DatItem_Status, - Field.DatItem_Optional, - - // Media - Field.DatItem_SHA256, - // Release Field.DatItem_Language, - Field.DatItem_Date, - - // Rom - Field.DatItem_Bios, - Field.DatItem_Size, - Field.DatItem_CRC, -#if NET_FRAMEWORK - Field.DatItem_RIPEMD160, -#endif - Field.DatItem_SHA384, - Field.DatItem_SHA512, - Field.DatItem_Offset, - Field.DatItem_Inverted, #endregion + + #endregion // Item-Specific }; /// @@ -305,7 +311,6 @@ namespace SabreTools.Library.DatItems // ListXML Field.Machine_SourceFile, Field.Machine_Runnable, - Field.Machine_DeviceReference_Name, Field.Machine_Slots, Field.Machine_Infos, @@ -447,6 +452,9 @@ namespace SabreTools.Library.DatItems case ItemType.Chip: return new Chip(); + case ItemType.DeviceReference: + return new DeviceReference(); + case ItemType.Disk: return new Disk(); diff --git a/SabreTools.Library/DatItems/DeviceReference.cs b/SabreTools.Library/DatItems/DeviceReference.cs new file mode 100644 index 00000000..a787d498 --- /dev/null +++ b/SabreTools.Library/DatItems/DeviceReference.cs @@ -0,0 +1,77 @@ +using Newtonsoft.Json; + +namespace SabreTools.Library.DatItems +{ + /// + /// Represents which Device Reference(s) is associated with a set + /// + [JsonObject("device_ref")] + public class DeviceReference : DatItem + { + #region Constructors + + /// + /// Create a default, empty DeviceReference object + /// + public DeviceReference() + { + Name = string.Empty; + ItemType = ItemType.DeviceReference; + } + + #endregion + + #region Cloning Methods + + public override object Clone() + { + return new DeviceReference() + { + Name = this.Name, + ItemType = this.ItemType, + DupeType = this.DupeType, + + AltName = this.AltName, + AltTitle = this.AltTitle, + + Original = this.Original, + OpenMSXSubType = this.OpenMSXSubType, + OpenMSXType = this.OpenMSXType, + Remark = this.Remark, + Boot = this.Boot, + + Part = this.Part, + Features = this.Features, + AreaName = this.AreaName, + AreaSize = this.AreaSize, + AreaWidth = this.AreaWidth, + AreaEndianness = this.AreaEndianness, + Value = this.Value, + LoadFlag = this.LoadFlag, + + Machine = this.Machine.Clone() as Machine, + Source = this.Source.Clone() as Source, + Remove = this.Remove, + }; + } + + #endregion + + #region Comparision Methods + + public override bool Equals(DatItem other) + { + // If we don't have a device reference, return false + if (ItemType != other.ItemType) + return false; + + // Otherwise, treat it as a device reference + DeviceReference newOther = other as DeviceReference; + + // If the device reference information matches + return (Name == newOther.Name); + } + + #endregion + } +} diff --git a/SabreTools.Library/DatItems/Enums.cs b/SabreTools.Library/DatItems/Enums.cs index 0a2b3592..cb09e724 100644 --- a/SabreTools.Library/DatItems/Enums.cs +++ b/SabreTools.Library/DatItems/Enums.cs @@ -129,12 +129,8 @@ namespace SabreTools.Library.DatItems Machine_SourceFile, Machine_Runnable, - // DeviceReferences - Machine_DeviceReferences, // TODO: Double-check DeviceReferences usage - Machine_DeviceReference_Name, - // Displays - Machine_Displays, // TODO: Implement Displays usage + Machine_Displays, Machine_Display_Tag, Machine_Display_Type, Machine_Display_Rotate, @@ -151,18 +147,18 @@ namespace SabreTools.Library.DatItems Machine_Display_VBStart, // Sounds - Machine_Sounds, // TODO: Implement Sounds usage + Machine_Sounds, Machine_Sound_Channels, // Conditions - Machine_Conditions, // TODO: Implement Conditions usage + Machine_Conditions, Machine_Condition_Tag, Machine_Condition_Mask, Machine_Condition_Relation, Machine_Condition_Value, // Inputs - Machine_Inputs, // TODO: Implement Inputs usage + Machine_Inputs, Machine_Input_Service, Machine_Input_Tilt, Machine_Input_Players, @@ -184,7 +180,7 @@ namespace SabreTools.Library.DatItems Machine_Input_Control_Ways3, // DipSwitches - Machine_DipSwitches, // TODO: Implement DipSwitches usage + Machine_DipSwitches, Machine_DipSwitch_Name, Machine_DipSwitch_Tag, Machine_DipSwitch_Mask, @@ -202,7 +198,7 @@ namespace SabreTools.Library.DatItems Machine_DipSwitch_Value_Default, // Configurations - Machine_Configurations, // TODO: Implement Configurations usage + Machine_Configurations, Machine_Configuration_Name, Machine_Configuration_Tag, Machine_Configuration_Mask, @@ -220,7 +216,7 @@ namespace SabreTools.Library.DatItems Machine_Configuration_Setting_Default, // Ports - Machine_Ports, // TODO: Implement Ports usage + Machine_Ports, Machine_Port_Tag, // Ports.Analogs @@ -228,7 +224,7 @@ namespace SabreTools.Library.DatItems Machine_Port_Analog_Mask, // Adjusters - Machine_Adjusters, // TODO: Implement Adjusters usage + Machine_Adjusters, Machine_Adjuster_Name, Machine_Adjuster_Default, @@ -240,20 +236,20 @@ namespace SabreTools.Library.DatItems Machine_Adjuster_Condition_Value, // Drivers - Machine_Drivers, // TODO: Implement Drivers usage + Machine_Drivers, Machine_Driver_Status, Machine_Driver_Emulation, Machine_Driver_Cocktail, Machine_Driver_SaveState, // Features - Machine_Features, // TODO: Implement Features usage + Machine_Features, Machine_Feature_Type, Machine_Feature_Status, Machine_Feature_Overall, // Devices - Machine_Devices, // TODO: Implement Devices usage + Machine_Devices, Machine_Device_Type, Machine_Device_Tag, Machine_Device_FixedImage, @@ -270,7 +266,7 @@ namespace SabreTools.Library.DatItems Machine_Device_Extension_Name, // Slots - Machine_Slots, // TODO: Fix Slots usage + Machine_Slots, Machine_Slot_Name, // Slots.SlotOptions @@ -280,13 +276,13 @@ namespace SabreTools.Library.DatItems Machine_Slot_SlotOption_Default, // SoftwareLists - Machine_SoftwareLists, // TODO: Implement SoftwareLists usage + Machine_SoftwareLists, Machine_SoftwareList_Name, Machine_SoftwareList_Status, Machine_SoftwareList_Filter, // RamOptions - Machine_RamOptions, // TODO: Implement RamOptions usage + Machine_RamOptions, Machine_RamOption_Default, #endregion @@ -367,12 +363,12 @@ namespace SabreTools.Library.DatItems #region SoftwareList // Part - DatItem_Part, // TODO: Fully implement Part + DatItem_Part, DatItem_Part_Name, DatItem_Part_Interface, // Feature - DatItem_Features, // TODO: Fully implement Feature + DatItem_Features, DatItem_Feature_Name, DatItem_Feature_Value, @@ -387,46 +383,52 @@ namespace SabreTools.Library.DatItems #region Item-Specific + #region Actionable + + // Rom + DatItem_Bios, + DatItem_Size, + DatItem_CRC, + DatItem_MD5, +#if NET_FRAMEWORK + DatItem_RIPEMD160, +#endif + DatItem_SHA1, + DatItem_SHA256, + DatItem_SHA384, + DatItem_SHA512, + DatItem_Merge, + DatItem_Region, + DatItem_Offset, + DatItem_Date, + DatItem_Status, + DatItem_Optional, + DatItem_Inverted, + + // Disk + DatItem_Index, + DatItem_Writable, + + #endregion + + #region Auxiliary + // BiosSet - DatItem_Default, DatItem_Description, + DatItem_Default, // Chip DatItem_Tag, DatItem_ChipType, DatItem_Clock, - // Disk - DatItem_MD5, - DatItem_SHA1, - DatItem_Merge, - DatItem_Region, - DatItem_Index, - DatItem_Writable, - DatItem_Status, - DatItem_Optional, - - // Media - DatItem_SHA256, - // Release DatItem_Language, - DatItem_Date, - - // Rom - DatItem_Bios, - DatItem_Size, - DatItem_CRC, -#if NET_FRAMEWORK - DatItem_RIPEMD160, -#endif - DatItem_SHA384, - DatItem_SHA512, - DatItem_Offset, - DatItem_Inverted, #endregion + #endregion // Item-Specific + #endregion // DatItem } @@ -454,16 +456,17 @@ namespace SabreTools.Library.DatItems public enum ItemType { // "Actionable" item types - Rom = 0, - Disk = 1, - Media = 2, + Rom, + Disk, + Media, // "Auxiliary" item types - Archive = 3, - BiosSet = 4, - Chip = 5, - Release = 6, - Sample = 7, + Archive, + BiosSet, + Chip, + DeviceReference, + Release, + Sample, Blank = 99, // This is not a real type, only used internally } @@ -516,6 +519,21 @@ namespace SabreTools.Library.DatItems Yes = 1 << 2, } + /// + /// Determine software list status + /// + [Flags] + public enum SoftwareListStatus + { + /// + /// This is a fake flag that is used for filter only + /// + NULL = 0, + + Original = 1 << 0, + Compatible = 1 << 1, + } + /// /// Determine machine support status /// diff --git a/SabreTools.Library/DatItems/Machine.cs b/SabreTools.Library/DatItems/Machine.cs index 9578e638..dc3dab9d 100644 --- a/SabreTools.Library/DatItems/Machine.cs +++ b/SabreTools.Library/DatItems/Machine.cs @@ -152,12 +152,6 @@ namespace SabreTools.Library.DatItems [JsonProperty("runnable", DefaultValueHandling = DefaultValueHandling.Ignore)] public Runnable Runnable { get; set; } = Runnable.NULL; - /// - /// List of associated device names - /// - [JsonProperty("devicereferences", DefaultValueHandling = DefaultValueHandling.Ignore)] - public List DeviceReferences { get; set; } = null; - /// /// List of associated displays /// @@ -596,7 +590,6 @@ namespace SabreTools.Library.DatItems SourceFile = this.SourceFile, Runnable = this.Runnable, - DeviceReferences = this.DeviceReferences, Displays = this.Displays, Sounds = this.Sounds, Conditions = this.Conditions, @@ -807,34 +800,6 @@ namespace SabreTools.Library.DatItems if (filter.Machine_Runnable.MatchesNegative(Runnable.NULL, Runnable) == true) return false; - #region DeviceReferences - - // Machine_DeviceReferences - if (filter.Machine_DeviceReferences.MatchesNeutral(null, DeviceReferences?.Any() ?? null) == false) - return false; - - // Machine_DeviceReference_Name - if (DeviceReferences?.Any() == true) - { - bool anyPositive = false; - bool anyNegative = false; - - foreach (var deviceReference in DeviceReferences) - { - if (filter.Machine_DeviceReference_Name.MatchesPositiveSet(deviceReference?.Name) != false) - anyPositive = true; - if (filter.Machine_DeviceReference_Name.MatchesNegativeSet(deviceReference?.Name) == true) - anyNegative = true; - } - - if (!anyPositive) - return false; - if (anyNegative) - return false; - } - - #endregion - #region Displays // Machine_Displays @@ -1132,9 +1097,9 @@ namespace SabreTools.Library.DatItems foreach (var sound in Sounds) { - if (filter.Machine_DeviceReference_Name.MatchesPositiveSet(sound?.Channels) != false) + if (filter.Machine_Sound_Channels.MatchesPositiveSet(sound?.Channels) != false) anyPositive = true; - if (filter.Machine_DeviceReference_Name.MatchesNegativeSet(sound?.Channels) == true) + if (filter.Machine_Sound_Channels.MatchesNegativeSet(sound?.Channels) == true) anyNegative = true; } @@ -1538,9 +1503,6 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.Machine_Runnable)) Runnable = Runnable.NULL; - if (fields.Contains(Field.Machine_DeviceReferences)) - DeviceReferences = null; - if (fields.Contains(Field.Machine_Slots)) Slots = null; @@ -1703,9 +1665,6 @@ namespace SabreTools.Library.DatItems if (fields.Contains(Field.Machine_Runnable)) Runnable = machine.Runnable; - if (fields.Contains(Field.Machine_DeviceReferences)) - DeviceReferences = machine.DeviceReferences; - if (fields.Contains(Field.Machine_Slots)) Slots = machine.Slots; diff --git a/SabreTools.Library/Data/Constants.cs b/SabreTools.Library/Data/Constants.cs index 6f9f548b..4201fe0e 100644 --- a/SabreTools.Library/Data/Constants.cs +++ b/SabreTools.Library/Data/Constants.cs @@ -12,8 +12,8 @@ namespace SabreTools.Library.Data /// /// The current toolset version to be used by all child applications /// - public readonly static string Version = $"v1.0.3"; - //public readonly static string Version = $"v1.0.3-{File.GetCreationTime(Assembly.GetExecutingAssembly().Location):yyyy-MM-dd HH:mm:ss}"; + //public readonly static string Version = $"v1.0.3"; + public readonly static string Version = $"v1.0.3-{File.GetCreationTime(Assembly.GetExecutingAssembly().Location):yyyy-MM-dd HH:mm:ss}"; public const int HeaderHeight = 3; #region 0-byte file constants diff --git a/SabreTools.Library/FileTypes/GZipArchive.cs b/SabreTools.Library/FileTypes/GZipArchive.cs index 63067ced..4516d63d 100644 --- a/SabreTools.Library/FileTypes/GZipArchive.cs +++ b/SabreTools.Library/FileTypes/GZipArchive.cs @@ -281,7 +281,7 @@ namespace SabreTools.Library.FileTypes } // Check if the name is the right length - if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length + if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) { Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'"); return false; @@ -342,7 +342,7 @@ namespace SabreTools.Library.FileTypes } // Check if the name is the right length - if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length + if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.gz")) { Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'"); return null; @@ -392,7 +392,7 @@ namespace SabreTools.Library.FileTypes Size = extractedsize, CRC = headercrc, MD5 = headermd5, - SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), // TODO: When updating to SHA-256, this needs to update to SHA256 + SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(), }; @@ -457,7 +457,7 @@ namespace SabreTools.Library.FileTypes rom = new Rom(inputStream.GetInfo(keepReadOpen: true)); // Get the output file name - string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth)); // TODO: When updating to SHA-256, this needs to update to SHA256 + string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth)); // Check to see if the folder needs to be created if (!Directory.Exists(Path.GetDirectoryName(outfile))) diff --git a/SabreTools.Library/FileTypes/XZArchive.cs b/SabreTools.Library/FileTypes/XZArchive.cs index 505347e6..4cc21ba2 100644 --- a/SabreTools.Library/FileTypes/XZArchive.cs +++ b/SabreTools.Library/FileTypes/XZArchive.cs @@ -262,7 +262,7 @@ namespace SabreTools.Library.FileTypes string datum = Path.GetFileName(this.Filename).ToLowerInvariant(); // Check if the name is the right length - if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length + if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz")) { Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'"); return false; @@ -284,7 +284,7 @@ namespace SabreTools.Library.FileTypes string datum = Path.GetFileName(this.Filename).ToLowerInvariant(); // Check if the name is the right length - if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz")) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length + if (!Regex.IsMatch(datum, @"^[0-9a-f]{" + Constants.SHA1Length + @"}\.xz")) { Globals.Logger.Warning($"Non SHA-1 filename found, skipping: '{Path.GetFullPath(this.Filename)}'"); return null; @@ -293,7 +293,7 @@ namespace SabreTools.Library.FileTypes BaseFile baseFile = new BaseFile { Filename = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(), - SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), // TODO: When updating to SHA-256, this needs to update to SHA256 + SHA1 = Utilities.StringToByteArray(Path.GetFileNameWithoutExtension(this.Filename)), Parent = Path.GetFileNameWithoutExtension(this.Filename).ToLowerInvariant(), }; @@ -357,7 +357,7 @@ namespace SabreTools.Library.FileTypes rom = new Rom(inputStream.GetInfo(keepReadOpen: true)); // Get the output file name - string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth)); // TODO: When updating to SHA-256, this needs to update to SHA256 + string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, depth)); outfile = outfile.Replace(".gz", ".xz"); // Check to see if the folder needs to be created diff --git a/SabreTools.Library/Filtering/Filter.cs b/SabreTools.Library/Filtering/Filter.cs index b04190fc..cf8d50f5 100644 --- a/SabreTools.Library/Filtering/Filter.cs +++ b/SabreTools.Library/Filtering/Filter.cs @@ -50,10 +50,6 @@ namespace SabreTools.Library.Filtering public FilterItem Machine_SourceFile { get; private set; } = new FilterItem(); public FilterItem Machine_Runnable { get; private set; } = new FilterItem() { Positive = Runnable.NULL, Negative = Runnable.NULL }; - - // DeviceReferences - public FilterItem Machine_DeviceReferences { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem Machine_DeviceReference_Name { get; private set; } = new FilterItem(); // Displays public FilterItem Machine_Displays { get; private set; } = new FilterItem() { Neutral = null }; @@ -309,46 +305,52 @@ namespace SabreTools.Library.Filtering #region Item-Specific + #region Actionable + + // Rom + public FilterItem DatItem_Bios { get; private set; } = new FilterItem(); + public FilterItem DatItem_Size { get; private set; } = new FilterItem() { Positive = -1, Negative = -1, Neutral = -1 }; + public FilterItem DatItem_CRC { get; private set; } = new FilterItem(); + public FilterItem DatItem_MD5 { get; private set; } = new FilterItem(); +#if NET_FRAMEWORK + public FilterItem DatItem_RIPEMD160 { get; private set; } = new FilterItem(); +#endif + public FilterItem DatItem_SHA1 { get; private set; } = new FilterItem(); + public FilterItem DatItem_SHA256 { get; private set; } = new FilterItem(); + public FilterItem DatItem_SHA384 { get; private set; } = new FilterItem(); + public FilterItem DatItem_SHA512 { get; private set; } = new FilterItem(); + public FilterItem DatItem_Merge { get; private set; } = new FilterItem(); + public FilterItem DatItem_Region { get; private set; } = new FilterItem(); + public FilterItem DatItem_Offset { get; private set; } = new FilterItem(); + public FilterItem DatItem_Date { get; private set; } = new FilterItem(); + public FilterItem DatItem_Status { get; private set; } = new FilterItem() { Positive = ItemStatus.NULL, Negative = ItemStatus.NULL }; + public FilterItem DatItem_Optional { get; private set; } = new FilterItem() { Neutral = null }; + public FilterItem DatItem_Inverted { get; private set; } = new FilterItem(); + + // Disk + public FilterItem DatItem_Index { get; private set; } = new FilterItem(); + public FilterItem DatItem_Writable { get; private set; } = new FilterItem() { Neutral = null }; + + #endregion + + #region Auxiliary + // BiosSet - public FilterItem DatItem_Default { get; private set; } = new FilterItem() { Neutral = null }; public FilterItem DatItem_Description { get; private set; } = new FilterItem(); + public FilterItem DatItem_Default { get; private set; } = new FilterItem() { Neutral = null }; // Chip public FilterItem DatItem_Tag { get; private set; } = new FilterItem(); public FilterItem DatItem_ChipType { get; private set; } = new FilterItem(); public FilterItem DatItem_Clock { get; private set; } = new FilterItem(); - // Disk - public FilterItem DatItem_MD5 { get; private set; } = new FilterItem(); - public FilterItem DatItem_SHA1 { get; private set; } = new FilterItem(); - public FilterItem DatItem_Merge { get; private set; } = new FilterItem(); - public FilterItem DatItem_Region { get; private set; } = new FilterItem(); - public FilterItem DatItem_Index { get; private set; } = new FilterItem(); - public FilterItem DatItem_Writable { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem DatItem_Optional { get; private set; } = new FilterItem() { Neutral = null }; - public FilterItem DatItem_Status { get; private set; } = new FilterItem() { Positive = ItemStatus.NULL, Negative = ItemStatus.NULL }; - - // Media - public FilterItem DatItem_SHA256 { get; private set; } = new FilterItem(); - // Release public FilterItem DatItem_Language { get; private set; } = new FilterItem(); - public FilterItem DatItem_Date { get; private set; } = new FilterItem(); - - // Rom - public FilterItem DatItem_Bios { get; private set; } = new FilterItem(); - public FilterItem DatItem_Size { get; private set; } = new FilterItem() { Positive = -1, Negative = -1, Neutral = -1 }; - public FilterItem DatItem_CRC { get; private set; } = new FilterItem(); -#if NET_FRAMEWORK - public FilterItem DatItem_RIPEMD160 { get; private set; } = new FilterItem(); -#endif - public FilterItem DatItem_SHA384 { get; private set; } = new FilterItem(); - public FilterItem DatItem_SHA512 { get; private set; } = new FilterItem(); - public FilterItem DatItem_Offset { get; private set; } = new FilterItem(); - public FilterItem DatItem_Inverted { get; private set; } = new FilterItem(); #endregion + #endregion // Item-Specific + #endregion // DatItem Filters #region Additional Flags @@ -572,21 +574,6 @@ namespace SabreTools.Library.Filtering Machine_Runnable.Positive |= value.AsRunnable(); break; - // DeviceReferences - case Field.Machine_DeviceReferences: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - Machine_DeviceReferences.Neutral = false; - else - Machine_DeviceReferences.Neutral = true; - break; - - case Field.Machine_DeviceReference_Name: - if (negate) - Machine_DeviceReference_Name.NegativeSet.Add(value); - else - Machine_DeviceReference_Name.PositiveSet.Add(value); - break; - // Displays case Field.Machine_Displays: if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) @@ -1753,122 +1740,7 @@ namespace SabreTools.Library.Filtering #region Item-Specific - // BiosSet - case Field.DatItem_Default: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - DatItem_Default.Neutral = false; - else - DatItem_Default.Neutral = true; - break; - - case Field.DatItem_Description: - if (negate) - DatItem_Description.NegativeSet.Add(value); - else - DatItem_Description.PositiveSet.Add(value); - break; - - // Chip - case Field.DatItem_Tag: - if (negate) - DatItem_Tag.NegativeSet.Add(value); - else - DatItem_Tag.PositiveSet.Add(value); - break; - - case Field.DatItem_ChipType: - if (negate) - DatItem_ChipType.NegativeSet.Add(value); - else - DatItem_ChipType.PositiveSet.Add(value); - break; - - case Field.DatItem_Clock: - if (negate) - DatItem_Clock.NegativeSet.Add(value); - else - DatItem_Clock.PositiveSet.Add(value); - break; - - // Disk - case Field.DatItem_MD5: - if (negate) - DatItem_MD5.NegativeSet.Add(value); - else - DatItem_MD5.PositiveSet.Add(value); - break; - - case Field.DatItem_SHA1: - if (negate) - DatItem_SHA1.NegativeSet.Add(value); - else - DatItem_SHA1.PositiveSet.Add(value); - break; - - case Field.DatItem_Merge: - if (negate) - DatItem_Merge.NegativeSet.Add(value); - else - DatItem_Merge.PositiveSet.Add(value); - break; - - case Field.DatItem_Region: - if (negate) - DatItem_Region.NegativeSet.Add(value); - else - DatItem_Region.PositiveSet.Add(value); - break; - - case Field.DatItem_Index: - if (negate) - DatItem_Index.NegativeSet.Add(value); - else - DatItem_Index.PositiveSet.Add(value); - break; - - case Field.DatItem_Writable: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - DatItem_Writable.Neutral = false; - else - DatItem_Writable.Neutral = true; - break; - - case Field.DatItem_Optional: - if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) - DatItem_Optional.Neutral = false; - else - DatItem_Optional.Neutral = true; - break; - - case Field.DatItem_Status: - if (negate) - DatItem_Status.Negative |= value.AsItemStatus(); - else - DatItem_Status.Positive |= value.AsItemStatus(); - break; - - // Media - case Field.DatItem_SHA256: - if (negate) - DatItem_SHA256.NegativeSet.Add(value); - else - DatItem_SHA256.PositiveSet.Add(value); - break; - - // Release - case Field.DatItem_Language: - if (negate) - DatItem_Language.NegativeSet.Add(value); - else - DatItem_Language.PositiveSet.Add(value); - break; - - case Field.DatItem_Date: - if (negate) - DatItem_Date.NegativeSet.Add(value); - else - DatItem_Date.PositiveSet.Add(value); - break; + #region Actionable // Rom case Field.DatItem_Bios: @@ -1937,6 +1809,13 @@ namespace SabreTools.Library.Filtering DatItem_CRC.PositiveSet.Add(value); break; + case Field.DatItem_MD5: + if (negate) + DatItem_MD5.NegativeSet.Add(value); + else + DatItem_MD5.PositiveSet.Add(value); + break; + #if NET_FRAMEWORK case Field.DatItem_RIPEMD160: if (negate) @@ -1946,6 +1825,20 @@ namespace SabreTools.Library.Filtering break; #endif + case Field.DatItem_SHA1: + if (negate) + DatItem_SHA1.NegativeSet.Add(value); + else + DatItem_SHA1.PositiveSet.Add(value); + break; + + case Field.DatItem_SHA256: + if (negate) + DatItem_SHA256.NegativeSet.Add(value); + else + DatItem_SHA256.PositiveSet.Add(value); + break; + case Field.DatItem_SHA384: if (negate) DatItem_SHA384.NegativeSet.Add(value); @@ -1960,6 +1853,20 @@ namespace SabreTools.Library.Filtering DatItem_SHA512.PositiveSet.Add(value); break; + case Field.DatItem_Merge: + if (negate) + DatItem_Merge.NegativeSet.Add(value); + else + DatItem_Merge.PositiveSet.Add(value); + break; + + case Field.DatItem_Region: + if (negate) + DatItem_Region.NegativeSet.Add(value); + else + DatItem_Region.PositiveSet.Add(value); + break; + case Field.DatItem_Offset: if (negate) DatItem_Offset.NegativeSet.Add(value); @@ -1967,6 +1874,27 @@ namespace SabreTools.Library.Filtering DatItem_Offset.PositiveSet.Add(value); break; + case Field.DatItem_Date: + if (negate) + DatItem_Date.NegativeSet.Add(value); + else + DatItem_Date.PositiveSet.Add(value); + break; + + case Field.DatItem_Status: + if (negate) + DatItem_Status.Negative |= value.AsItemStatus(); + else + DatItem_Status.Positive |= value.AsItemStatus(); + break; + + case Field.DatItem_Optional: + if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) + DatItem_Optional.Neutral = false; + else + DatItem_Optional.Neutral = true; + break; + case Field.DatItem_Inverted: if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) DatItem_Inverted.Neutral = false; @@ -1974,8 +1902,74 @@ namespace SabreTools.Library.Filtering DatItem_Inverted.Neutral = true; break; + // Disk + case Field.DatItem_Index: + if (negate) + DatItem_Index.NegativeSet.Add(value); + else + DatItem_Index.PositiveSet.Add(value); + break; + + case Field.DatItem_Writable: + if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) + DatItem_Writable.Neutral = false; + else + DatItem_Writable.Neutral = true; + break; + #endregion + #region Auxiliary + + // BiosSet + case Field.DatItem_Description: + if (negate) + DatItem_Description.NegativeSet.Add(value); + else + DatItem_Description.PositiveSet.Add(value); + break; + + case Field.DatItem_Default: + if (negate || value.Equals("false", StringComparison.OrdinalIgnoreCase)) + DatItem_Default.Neutral = false; + else + DatItem_Default.Neutral = true; + break; + + // Chip + case Field.DatItem_Tag: + if (negate) + DatItem_Tag.NegativeSet.Add(value); + else + DatItem_Tag.PositiveSet.Add(value); + break; + + case Field.DatItem_ChipType: + if (negate) + DatItem_ChipType.NegativeSet.Add(value); + else + DatItem_ChipType.PositiveSet.Add(value); + break; + + case Field.DatItem_Clock: + if (negate) + DatItem_Clock.NegativeSet.Add(value); + else + DatItem_Clock.PositiveSet.Add(value); + break; + + // Release + case Field.DatItem_Language: + if (negate) + DatItem_Language.NegativeSet.Add(value); + else + DatItem_Language.PositiveSet.Add(value); + break; + + #endregion + + #endregion // Item-Specific + #endregion // DatItem Filters } } diff --git a/SabreTools.Library/IO/PathExtensions.cs b/SabreTools.Library/IO/PathExtensions.cs index 45557bb8..446cd1b9 100644 --- a/SabreTools.Library/IO/PathExtensions.cs +++ b/SabreTools.Library/IO/PathExtensions.cs @@ -42,7 +42,7 @@ namespace SabreTools.Library.IO public static string GetDepotPath(string hash, int depth) { // If the hash isn't the right size, then we return null - if (hash.Length != Constants.SHA1Length) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length + if (hash.Length != Constants.SHA1Length) return null; // Cap the depth between 0 and 20, for now diff --git a/SabreTools.Library/Tools/Converters.cs b/SabreTools.Library/Tools/Converters.cs index 5c4622a2..dd1487b4 100644 --- a/SabreTools.Library/Tools/Converters.cs +++ b/SabreTools.Library/Tools/Converters.cs @@ -151,7 +151,6 @@ namespace SabreTools.Library.Tools /// /// String to get value from /// Field value corresponding to the string - /// TODO: Needs to be SEVERELY overhauled. Start using dot notation for fields... (where possible) public static Field AsField(this string input) { // If the input is null, we return null @@ -457,14 +456,6 @@ namespace SabreTools.Library.Tools case "runnable": return Field.Machine_Runnable; - case "devreferences": - case "devicereferences": - return Field.Machine_DeviceReferences; - - case "devreference_name": - case "devicereference_name": - return Field.Machine_DeviceReference_Name; - case "displays": return Field.Machine_Displays; @@ -996,27 +987,19 @@ namespace SabreTools.Library.Tools #region Item-Specific - // BiosSet - case "default": - return Field.DatItem_Default; + #region Actionable - case "description": - case "biosdescription": - case "bios_description": - return Field.DatItem_Description; + // Rom + case "bios": + return Field.DatItem_Bios; - // Chip - case "tag": - return Field.DatItem_Tag; + case "size": + return Field.DatItem_Size; - case "chiptype": - case "chip_type": - return Field.DatItem_ChipType; + case "crc": + case "crc32": + return Field.DatItem_CRC; - case "clock": - return Field.DatItem_Clock; - - // Disk case "md5": case "md5_hash": return Field.DatItem_MD5; @@ -1067,11 +1050,11 @@ namespace SabreTools.Library.Tools case "region": return Field.DatItem_Region; - case "index": - return Field.DatItem_Index; + case "offset": + return Field.DatItem_Offset; - case "writable": - return Field.DatItem_Writable; + case "date": + return Field.DatItem_Date; case "status": return Field.DatItem_Status; @@ -1079,36 +1062,53 @@ namespace SabreTools.Library.Tools case "optional": return Field.DatItem_Optional; + case "inverted": + return Field.DatItem_Inverted; + + // Disk + case "index": + return Field.DatItem_Index; + + case "writable": + return Field.DatItem_Writable; + + #endregion + + #region Auxiliary + + // BiosSet + case "description": + case "biosdescription": + case "bios_description": + return Field.DatItem_Description; + + case "default": + return Field.DatItem_Default; + + // Chip + case "tag": + return Field.DatItem_Tag; + + case "chiptype": + case "chip_type": + return Field.DatItem_ChipType; + + case "clock": + return Field.DatItem_Clock; + // Release case "language": return Field.DatItem_Language; - case "date": - return Field.DatItem_Date; - - // Rom - case "bios": - return Field.DatItem_Bios; - - case "size": - return Field.DatItem_Size; - - case "crc": - return Field.DatItem_CRC; - - case "offset": - return Field.DatItem_Offset; - - case "inverted": - return Field.DatItem_Inverted; - #endregion + + #endregion // Item-Specific } } // Else, we fall back on the old matching // TODO: Remove this entirely - switch (input) + switch (input.Replace(' ', '_').Replace('-', '_').Replace('.', '_')) { #region Machine @@ -1218,9 +1218,6 @@ namespace SabreTools.Library.Tools case "runnable": return Field.Machine_Runnable; - case "devices": - return Field.Machine_DeviceReference_Name; - case "slotoptions": case "slot options": case "slot-options": @@ -1415,8 +1412,103 @@ namespace SabreTools.Library.Tools #endregion + #region Item-Specific + + #region Actionable + + // Rom case "bios": return Field.DatItem_Bios; + + case "equal": + case "greater": + case "less": + case "size": + return Field.DatItem_Size; + + case "crc": + case "crc32": + return Field.DatItem_CRC; + + case "md5": + case "md5_hash": + return Field.DatItem_MD5; + +#if NET_FRAMEWORK + case "ripemd160": + case "ripemd160_hash": + return Field.DatItem_RIPEMD160; +#endif + + case "sha1": + case "sha_1": + case "sha1hash": + case "sha1_hash": + case "sha_1hash": + case "sha_1_hash": + return Field.DatItem_SHA1; + + case "sha256": + case "sha_256": + case "sha256hash": + case "sha256_hash": + case "sha_256hash": + case "sha_256_hash": + return Field.DatItem_SHA256; + + case "sha384": + case "sha_384": + case "sha384hash": + case "sha384_hash": + case "sha_384hash": + case "sha_384_hash": + return Field.DatItem_SHA384; + + case "sha512": + case "sha_512": + case "sha512hash": + case "sha512_hash": + case "sha_512hash": + case "sha_512_hash": + return Field.DatItem_SHA512; + + case "merge": + case "mergetag": + case "merge_tag": + return Field.DatItem_Merge; + + case "region": + return Field.DatItem_Region; + + case "offset": + return Field.DatItem_Offset; + + case "date": + return Field.DatItem_Date; + + case "itemtatus": + case "item-status": + case "status": + return Field.DatItem_Status; + + case "optional": + return Field.DatItem_Optional; + + case "inverted": + return Field.DatItem_Inverted; + + // Disk + case "index": + return Field.DatItem_Index; + + case "writable": + return Field.DatItem_Writable; + + #endregion + + #region Auxiliary + + // BiosSet case "biosdescription": case "bios-description": case "biossetdescription": @@ -1424,6 +1516,10 @@ namespace SabreTools.Library.Tools case "bios-set-description": return Field.DatItem_Description; + case "default": + return Field.DatItem_Default; + + // Chip case "tag": return Field.DatItem_Tag; @@ -1433,59 +1529,14 @@ namespace SabreTools.Library.Tools case "clock": return Field.DatItem_Clock; - - case "crc": - case "crc32": - return Field.DatItem_CRC; - case "default": - return Field.DatItem_Default; - case "date": - return Field.DatItem_Date; - case "equal": - case "greater": - case "less": - case "size": - return Field.DatItem_Size; - case "index": - return Field.DatItem_Index; - case "inverted": - return Field.DatItem_Inverted; - case "itemtatus": - case "item-status": - case "status": - return Field.DatItem_Status; + + // Release case "language": return Field.DatItem_Language; - case "md5": - return Field.DatItem_MD5; - case "merge": - case "mergetag": - case "merge-tag": - return Field.DatItem_Merge; - case "offset": - return Field.DatItem_Offset; - case "optional": - return Field.DatItem_Optional; - case "region": - return Field.DatItem_Region; -#if NET_FRAMEWORK - case "ripemd160": - return Field.DatItem_RIPEMD160; -#endif - case "sha1": - case "sha-1": - return Field.DatItem_SHA1; - case "sha256": - case "sha-256": - return Field.DatItem_SHA256; - case "sha384": - case "sha-384": - return Field.DatItem_SHA384; - case "sha512": - case "sha-512": - return Field.DatItem_SHA512; - case "writable": - return Field.DatItem_Writable; + + #endregion + + #endregion // Item-Specific #endregion @@ -1551,6 +1602,8 @@ namespace SabreTools.Library.Tools return ItemType.Blank; case "chip": return ItemType.Chip; + case "device_ref": + return ItemType.DeviceReference; case "disk": return ItemType.Disk; case "media": @@ -1571,6 +1624,7 @@ namespace SabreTools.Library.Tools "biosset" => ItemType.BiosSet, "blank" => ItemType.Blank, "chip" => ItemType.Chip, + "device_ref" => ItemType.DeviceReference, "disk" => ItemType.Disk, "media" => ItemType.Media, "release" => ItemType.Release, @@ -1787,6 +1841,35 @@ namespace SabreTools.Library.Tools #endif } + /// + /// Get SoftwareListStatus value from input string + /// + /// String to get value from + /// SoftwareListStatus value corresponding to the string + public static SoftwareListStatus AsSoftwareListStatus(this string status) + { +#if NET_FRAMEWORK + switch (status?.ToLowerInvariant()) + { + case "original": + return SoftwareListStatus.Original; + case "compatible": + return SoftwareListStatus.Compatible; + case "none": + default: + return SoftwareListStatus.NULL; + } +#else + return status?.ToLowerInvariant() switch + { + "original" => SoftwareListStatus.Original, + "compatible" => SoftwareListStatus.Compatible, + "none" => SoftwareListStatus.NULL, + _ => SoftwareListStatus.NULL, + }; +#endif + } + /// /// Get StatReportFormat value from input string /// @@ -1946,6 +2029,8 @@ namespace SabreTools.Library.Tools return "blank"; case ItemType.Chip: return "chip"; + case ItemType.DeviceReference: + return "device_ref"; case ItemType.Disk: return "disk"; case ItemType.Media: @@ -1966,6 +2051,7 @@ namespace SabreTools.Library.Tools ItemType.BiosSet => "biosset", ItemType.Blank => "blank", ItemType.Chip => "chip", + ItemType.DeviceReference => "device_ref", ItemType.Disk => "disk", ItemType.Media => "media", ItemType.Release => "release", @@ -2219,6 +2305,33 @@ namespace SabreTools.Library.Tools #endif } + /// + /// Get string value from input SoftwareListStatus + /// + /// SoftwareListStatus to get value from + /// String value corresponding to the SoftwareListStatus + public static string FromSoftwareListStatus(this SoftwareListStatus status) + { +#if NET_FRAMEWORK + switch (status) + { + case SoftwareListStatus.Original: + return "original"; + case SoftwareListStatus.Compatible: + return "compatible"; + default: + return null; + } +#else + return status switch + { + SoftwareListStatus.Original => "original", + SoftwareListStatus.Compatible => "compatible", + _ => null, + }; +#endif + } + /// /// Get string value from input StatReportFormat ///