/// <summary> /// Replace fields from another item /// </summary> /// <param name="item">DatItem to pull new information from</param> /// <param name="fields">List of Fields representing what should be updated</param> public override void ReplaceFields(DatItem item, List <Field> fields) { // Replace common fields first base.ReplaceFields(item, fields); // If we don't have a DataArea to replace from, ignore specific fields if (item.ItemType != ItemType.DataArea) { return; } // Cast for easier access DataArea newItem = item as DataArea; // Replace the fields if (fields.Contains(Field.DatItem_AreaName)) { Name = newItem.Name; } if (fields.Contains(Field.DatItem_AreaSize)) { Size = newItem.Size; } if (fields.Contains(Field.DatItem_AreaWidth)) { Width = newItem.Width; } if (fields.Contains(Field.DatItem_AreaEndianness)) { Endianness = newItem.Endianness; } }
public override bool Equals(DatItem other) { // If we don't have a DataArea, return false if (ItemType != other.ItemType) { return(false); } // Otherwise, treat it as a DataArea DataArea newOther = other as DataArea; // If the DataArea information matches return(Name == newOther.Name && Size == newOther.Size && Width == newOther.Width && Endianness == newOther.Endianness); }
/// <summary> /// Check to see if a DatItem passes the filter /// </summary> /// <param name="filter">Filter to check against</param> /// <param name="sub">True if this is a subitem, false otherwise</param> /// <returns>True if the item passed the filter, false otherwise</returns> public override bool PassesFilter(Filter filter, bool sub = false) { // Check common fields first if (!base.PassesFilter(filter, sub)) { return(false); } #region Common // Filter on item name if (!filter.PassStringFilter(filter.DatItem_Name, Name)) { return(false); } // Filter on bios if (!filter.PassStringFilter(filter.DatItem_Bios, Bios)) { return(false); } // Filter on rom size if (!filter.PassLongFilter(filter.DatItem_Size, Size)) { return(false); } // Filter on CRC if (!filter.PassStringFilter(filter.DatItem_CRC, CRC)) { return(false); } // Filter on MD5 if (!filter.PassStringFilter(filter.DatItem_MD5, MD5)) { return(false); } #if NET_FRAMEWORK // Filter on RIPEMD160 if (!filter.PassStringFilter(filter.DatItem_RIPEMD160, RIPEMD160)) { return(false); } #endif // Filter on SHA-1 if (!filter.PassStringFilter(filter.DatItem_SHA1, SHA1)) { return(false); } // Filter on SHA-256 if (!filter.PassStringFilter(filter.DatItem_SHA256, SHA256)) { return(false); } // Filter on SHA-384 if (!filter.PassStringFilter(filter.DatItem_SHA384, SHA384)) { return(false); } // Filter on SHA-512 if (!filter.PassStringFilter(filter.DatItem_SHA512, SHA512)) { return(false); } // Filter on SpamSum if (!filter.PassStringFilter(filter.DatItem_SpamSum, SpamSum)) { return(false); } // Filter on merge tag if (!filter.PassStringFilter(filter.DatItem_Merge, MergeTag)) { return(false); } // Filter on region if (!filter.PassStringFilter(filter.DatItem_Region, Region)) { return(false); } // Filter on offset if (!filter.PassStringFilter(filter.DatItem_Offset, Offset)) { return(false); } // Filter on date if (!filter.PassStringFilter(filter.DatItem_Date, Date)) { return(false); } // Filter on status if (filter.DatItem_Status.MatchesPositive(ItemStatus.NULL, ItemStatus) == false) { return(false); } if (filter.DatItem_Status.MatchesNegative(ItemStatus.NULL, ItemStatus) == true) { return(false); } // Filter on optional if (!filter.PassBoolFilter(filter.DatItem_Optional, Optional)) { return(false); } // Filter on inverted if (!filter.PassBoolFilter(filter.DatItem_Inverted, Inverted)) { return(false); } #endregion #region AttractMode // Filter on alt name if (!filter.PassStringFilter(filter.DatItem_AltName, AltName)) { return(false); } // Filter on alt title if (!filter.PassStringFilter(filter.DatItem_AltTitle, AltTitle)) { return(false); } #endregion #region OpenMSX // Filter on original if (!filter.PassStringFilter(filter.DatItem_Original, Original?.Content)) { return(false); } // Filter on OpenMSX subtype if (filter.DatItem_OpenMSXSubType.MatchesPositive(OpenMSXSubType.NULL, OpenMSXSubType) == false) { return(false); } if (filter.DatItem_OpenMSXSubType.MatchesNegative(OpenMSXSubType.NULL, OpenMSXSubType) == true) { return(false); } // Filter on OpenMSX type if (!filter.PassStringFilter(filter.DatItem_OpenMSXType, OpenMSXType)) { return(false); } // Filter on remark if (!filter.PassStringFilter(filter.DatItem_Remark, Remark)) { return(false); } // Filter on boot if (!filter.PassStringFilter(filter.DatItem_Boot, Boot)) { return(false); } #endregion #region SoftwareList // Filter on load flag if (filter.DatItem_LoadFlag.MatchesPositive(LoadFlag.NULL, LoadFlag) == false) { return(false); } if (filter.DatItem_LoadFlag.MatchesNegative(LoadFlag.NULL, LoadFlag) == true) { return(false); } // Filter on value if (!filter.PassStringFilter(filter.DatItem_Value, Value)) { return(false); } // Filter on DataArea if (DataAreaSpecified) { if (!DataArea.PassesFilter(filter, true)) { return(false); } } // Filter on Part if (PartSpecified) { if (!Part.PassesFilter(filter, true)) { return(false); } } #endregion return(true); }
/// <summary> /// Set fields with given values /// </summary> /// <param name="mappings">Mappings dictionary</param> public override void SetFields(Dictionary <Field, string> mappings) { // Set base fields base.SetFields(mappings); // Handle Rom-specific fields #region Common if (mappings.Keys.Contains(Field.DatItem_Name)) { Name = mappings[Field.DatItem_Name]; } if (mappings.Keys.Contains(Field.DatItem_Bios)) { Bios = mappings[Field.DatItem_Bios]; } if (mappings.Keys.Contains(Field.DatItem_Size)) { Size = Sanitizer.CleanLong(mappings[Field.DatItem_Size]); } if (mappings.Keys.Contains(Field.DatItem_CRC)) { CRC = mappings[Field.DatItem_CRC]; } if (mappings.Keys.Contains(Field.DatItem_MD5)) { MD5 = mappings[Field.DatItem_MD5]; } #if NET_FRAMEWORK if (mappings.Keys.Contains(Field.DatItem_RIPEMD160)) { RIPEMD160 = mappings[Field.DatItem_RIPEMD160]; } #endif if (mappings.Keys.Contains(Field.DatItem_SHA1)) { SHA1 = mappings[Field.DatItem_SHA1]; } if (mappings.Keys.Contains(Field.DatItem_SHA256)) { SHA256 = mappings[Field.DatItem_SHA256]; } if (mappings.Keys.Contains(Field.DatItem_SHA384)) { SHA384 = mappings[Field.DatItem_SHA384]; } if (mappings.Keys.Contains(Field.DatItem_SHA512)) { SHA512 = mappings[Field.DatItem_SHA512]; } if (mappings.Keys.Contains(Field.DatItem_SpamSum)) { SpamSum = mappings[Field.DatItem_SpamSum]; } if (mappings.Keys.Contains(Field.DatItem_Merge)) { MergeTag = mappings[Field.DatItem_Merge]; } if (mappings.Keys.Contains(Field.DatItem_Region)) { Region = mappings[Field.DatItem_Region]; } if (mappings.Keys.Contains(Field.DatItem_Offset)) { Offset = mappings[Field.DatItem_Offset]; } if (mappings.Keys.Contains(Field.DatItem_Date)) { Date = mappings[Field.DatItem_Date]; } if (mappings.Keys.Contains(Field.DatItem_Status)) { ItemStatus = mappings[Field.DatItem_Status].AsItemStatus(); } if (mappings.Keys.Contains(Field.DatItem_Optional)) { Optional = mappings[Field.DatItem_Optional].AsYesNo(); } if (mappings.Keys.Contains(Field.DatItem_Inverted)) { Inverted = mappings[Field.DatItem_Optional].AsYesNo(); } #endregion #region AttractMode if (mappings.Keys.Contains(Field.DatItem_AltName)) { AltName = mappings[Field.DatItem_AltName]; } if (mappings.Keys.Contains(Field.DatItem_AltTitle)) { AltTitle = mappings[Field.DatItem_AltTitle]; } #endregion #region OpenMSX if (mappings.Keys.Contains(Field.DatItem_Original)) { Original = new Original() { Content = mappings[Field.DatItem_Original] } } ; if (mappings.Keys.Contains(Field.DatItem_OpenMSXSubType)) { OpenMSXSubType = mappings[Field.DatItem_OpenMSXSubType].AsOpenMSXSubType(); } if (mappings.Keys.Contains(Field.DatItem_OpenMSXType)) { OpenMSXType = mappings[Field.DatItem_OpenMSXType]; } if (mappings.Keys.Contains(Field.DatItem_Remark)) { Remark = mappings[Field.DatItem_Remark]; } if (mappings.Keys.Contains(Field.DatItem_Boot)) { Boot = mappings[Field.DatItem_Boot]; } #endregion #region SoftwareList if (mappings.Keys.Contains(Field.DatItem_LoadFlag)) { LoadFlag = mappings[Field.DatItem_LoadFlag].AsLoadFlag(); } if (mappings.Keys.Contains(Field.DatItem_Value)) { Value = mappings[Field.DatItem_Value]; } // Handle DataArea-specific fields if (DataArea == null) { DataArea = new DataArea(); } DataArea.SetFields(mappings); // Handle Part-specific fields if (Part == null) { Part = new Part(); } Part.SetFields(mappings); #endregion }
/// <summary> /// Replace fields from another item /// </summary> /// <param name="item">DatItem to pull new information from</param> /// <param name="fields">List of Fields representing what should be updated</param> public override void ReplaceFields(DatItem item, List <Field> fields) { // Replace common fields first base.ReplaceFields(item, fields); // If we don't have a Rom to replace from, ignore specific fields if (item.ItemType != ItemType.Rom) { return; } // Cast for easier access Rom newItem = item as Rom; // Replace the fields #region Common if (fields.Contains(Field.DatItem_Name)) { Name = newItem.Name; } if (fields.Contains(Field.DatItem_Bios)) { Bios = newItem.Bios; } if (fields.Contains(Field.DatItem_Size)) { Size = newItem.Size; } if (fields.Contains(Field.DatItem_CRC)) { if (string.IsNullOrEmpty(CRC) && !string.IsNullOrEmpty(newItem.CRC)) { CRC = newItem.CRC; } } if (fields.Contains(Field.DatItem_MD5)) { if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5)) { MD5 = newItem.MD5; } } #if NET_FRAMEWORK if (fields.Contains(Field.DatItem_RIPEMD160)) { if (string.IsNullOrEmpty(RIPEMD160) && !string.IsNullOrEmpty(newItem.RIPEMD160)) { RIPEMD160 = newItem.RIPEMD160; } } #endif if (fields.Contains(Field.DatItem_SHA1)) { if (string.IsNullOrEmpty(SHA1) && !string.IsNullOrEmpty(newItem.SHA1)) { SHA1 = newItem.SHA1; } } if (fields.Contains(Field.DatItem_SHA256)) { if (string.IsNullOrEmpty(SHA256) && !string.IsNullOrEmpty(newItem.SHA256)) { SHA256 = newItem.SHA256; } } if (fields.Contains(Field.DatItem_SHA384)) { if (string.IsNullOrEmpty(SHA384) && !string.IsNullOrEmpty(newItem.SHA384)) { SHA384 = newItem.SHA384; } } if (fields.Contains(Field.DatItem_SHA512)) { if (string.IsNullOrEmpty(SHA512) && !string.IsNullOrEmpty(newItem.SHA512)) { SHA512 = newItem.SHA512; } } if (fields.Contains(Field.DatItem_SpamSum)) { if (string.IsNullOrEmpty(SpamSum) && !string.IsNullOrEmpty(newItem.SpamSum)) { SpamSum = newItem.SpamSum; } } if (fields.Contains(Field.DatItem_Merge)) { MergeTag = newItem.MergeTag; } if (fields.Contains(Field.DatItem_Region)) { Region = newItem.Region; } if (fields.Contains(Field.DatItem_Offset)) { Offset = newItem.Offset; } if (fields.Contains(Field.DatItem_Date)) { Date = newItem.Date; } if (fields.Contains(Field.DatItem_Status)) { ItemStatus = newItem.ItemStatus; } if (fields.Contains(Field.DatItem_Optional)) { Optional = newItem.Optional; } if (fields.Contains(Field.DatItem_Inverted)) { Inverted = newItem.Inverted; } #endregion #region AttractMode if (fields.Contains(Field.DatItem_AltName)) { AltName = newItem.AltName; } if (fields.Contains(Field.DatItem_AltTitle)) { AltTitle = newItem.AltTitle; } #endregion #region OpenMSX if (fields.Contains(Field.DatItem_Original)) { Original = newItem.Original; } if (fields.Contains(Field.DatItem_OpenMSXSubType)) { OpenMSXSubType = newItem.OpenMSXSubType; } if (fields.Contains(Field.DatItem_OpenMSXType)) { OpenMSXType = newItem.OpenMSXType; } if (fields.Contains(Field.DatItem_Remark)) { Remark = newItem.Remark; } if (fields.Contains(Field.DatItem_Boot)) { Boot = newItem.Boot; } #endregion #region SoftwareList if (fields.Contains(Field.DatItem_LoadFlag)) { LoadFlag = newItem.LoadFlag; } if (fields.Contains(Field.DatItem_Value)) { Value = newItem.Value; } if (DataAreaSpecified && newItem.DataAreaSpecified) { DataArea.ReplaceFields(newItem.DataArea, fields); } if (PartSpecified && newItem.PartSpecified) { Part.ReplaceFields(newItem.Part, fields); } #endregion }
/// <summary> /// Remove fields from the DatItem /// </summary> /// <param name="fields">List of Fields to remove</param> public override void RemoveFields(List <Field> fields) { // Remove common fields first base.RemoveFields(fields); // Remove the fields #region Common if (fields.Contains(Field.DatItem_Name)) { Name = null; } if (fields.Contains(Field.DatItem_Bios)) { Bios = null; } if (fields.Contains(Field.DatItem_Size)) { Size = 0; } if (fields.Contains(Field.DatItem_CRC)) { CRC = null; } if (fields.Contains(Field.DatItem_MD5)) { MD5 = null; } #if NET_FRAMEWORK if (fields.Contains(Field.DatItem_RIPEMD160)) { RIPEMD160 = null; } #endif if (fields.Contains(Field.DatItem_SHA1)) { SHA1 = null; } if (fields.Contains(Field.DatItem_SHA256)) { SHA256 = null; } if (fields.Contains(Field.DatItem_SHA384)) { SHA384 = null; } if (fields.Contains(Field.DatItem_SHA512)) { SHA512 = null; } if (fields.Contains(Field.DatItem_SpamSum)) { SpamSum = null; } if (fields.Contains(Field.DatItem_Merge)) { MergeTag = null; } if (fields.Contains(Field.DatItem_Region)) { Region = null; } if (fields.Contains(Field.DatItem_Offset)) { Offset = null; } if (fields.Contains(Field.DatItem_Date)) { Date = null; } if (fields.Contains(Field.DatItem_Status)) { ItemStatus = ItemStatus.NULL; } if (fields.Contains(Field.DatItem_Optional)) { Optional = null; } if (fields.Contains(Field.DatItem_Inverted)) { Inverted = null; } #endregion #region AttractMode if (fields.Contains(Field.DatItem_AltName)) { AltName = null; } if (fields.Contains(Field.DatItem_AltTitle)) { AltTitle = null; } #endregion #region OpenMSX if (fields.Contains(Field.DatItem_Original)) { Original = null; } if (fields.Contains(Field.DatItem_OpenMSXSubType)) { OpenMSXSubType = OpenMSXSubType.NULL; } if (fields.Contains(Field.DatItem_OpenMSXType)) { OpenMSXType = null; } if (fields.Contains(Field.DatItem_Remark)) { Remark = null; } if (fields.Contains(Field.DatItem_Boot)) { Boot = null; } #endregion #region SoftwareList if (fields.Contains(Field.DatItem_LoadFlag)) { LoadFlag = LoadFlag.NULL; } if (fields.Contains(Field.DatItem_Value)) { Value = null; } if (DataAreaSpecified) { DataArea.RemoveFields(fields); } if (PartSpecified) { Part.RemoveFields(fields); } #endregion }