Move field replacement

This commit is contained in:
Matt Nadareski
2020-08-17 22:35:17 -07:00
parent 5660da7b0e
commit 42b3bd906a
6 changed files with 327 additions and 348 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Security.Permissions;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -135,5 +134,34 @@ namespace SabreTools.Library.DatItems
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> updateFields)
{
// Replace common fields first
base.ReplaceFields(item, updateFields);
// If we don't have a BiosSet to replace from, ignore specific fields
if (item.ItemType != ItemType.BiosSet)
return;
// Cast for easier access
BiosSet newItem = item as BiosSet;
// Replace the fields
if (updateFields.Contains(Field.BiosDescription))
Description = newItem.Description;
if (updateFields.Contains(Field.Default))
Default = newItem.Default;
}
#endregion
}
}

View File

@@ -958,6 +958,101 @@ namespace SabreTools.Library.DatItems
return key;
}
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
public virtual void ReplaceFields(DatItem item, List<Field> updateFields)
{
if (updateFields.Contains(Field.Name))
Name = item.Name;
if (updateFields.Contains(Field.PartName))
PartName = item.PartName;
if (updateFields.Contains(Field.PartInterface))
PartInterface = item.PartInterface;
if (updateFields.Contains(Field.Features))
Features = item.Features;
if (updateFields.Contains(Field.AreaName))
AreaName = item.AreaName;
if (updateFields.Contains(Field.AreaSize))
AreaSize = item.AreaSize;
}
/// <summary>
/// Replace machine fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
/// <param name="onlySame">True if descriptions should only be replaced if the game name is the same, false otherwise</param>
public void ReplaceMachineFields(DatItem item, List<Field> updateFields, bool onlySame)
{
if (updateFields.Contains(Field.MachineName))
MachineName = item.MachineName;
if (updateFields.Contains(Field.Comment))
Comment = item.Comment;
if (updateFields.Contains(Field.Description))
{
if (!onlySame || (onlySame && MachineName == MachineDescription))
MachineDescription = item.MachineDescription;
}
if (updateFields.Contains(Field.Year))
Year = item.Year;
if (updateFields.Contains(Field.Manufacturer))
Manufacturer = item.Manufacturer;
if (updateFields.Contains(Field.Publisher))
Publisher = item.Publisher;
if (updateFields.Contains(Field.Category))
Category = item.Category;
if (updateFields.Contains(Field.RomOf))
RomOf = item.RomOf;
if (updateFields.Contains(Field.CloneOf))
CloneOf = item.CloneOf;
if (updateFields.Contains(Field.SampleOf))
SampleOf = item.SampleOf;
if (updateFields.Contains(Field.Supported))
Supported = item.Supported;
if (updateFields.Contains(Field.SourceFile))
SourceFile = item.SourceFile;
if (updateFields.Contains(Field.Runnable))
Runnable = item.Runnable;
if (updateFields.Contains(Field.Board))
Board = item.Board;
if (updateFields.Contains(Field.RebuildTo))
RebuildTo = item.RebuildTo;
if (updateFields.Contains(Field.Devices))
Devices = item.Devices;
if (updateFields.Contains(Field.SlotOptions))
SlotOptions = item.SlotOptions;
if (updateFields.Contains(Field.Infos))
Infos = item.Infos;
if (updateFields.Contains(Field.MachineType))
MachineType = item.MachineType;
}
#endregion
#endregion // Instance Methods

View File

@@ -536,6 +536,81 @@ namespace SabreTools.Library.DatItems
return key;
}
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> updateFields)
{
// Replace common fields first
base.ReplaceFields(item, updateFields);
// If we don't have a Disk to replace from, ignore specific fields
if (item.ItemType != ItemType.Disk)
return;
// Cast for easier access
Disk newItem = item as Disk;
// Replace the fields
if (updateFields.Contains(Field.MD5))
{
if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5))
MD5 = newItem.MD5;
}
#if NET_FRAMEWORK
if (updateFields.Contains(Field.RIPEMD160))
{
if (string.IsNullOrEmpty(RIPEMD160) && !string.IsNullOrEmpty(newItem.RIPEMD160))
RIPEMD160 = newItem.RIPEMD160;
}
#endif
if (updateFields.Contains(Field.SHA1))
{
if (string.IsNullOrEmpty(SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
SHA1 = newItem.SHA1;
}
if (updateFields.Contains(Field.SHA256))
{
if (string.IsNullOrEmpty(SHA256) && !string.IsNullOrEmpty(newItem.SHA256))
SHA256 = newItem.SHA256;
}
if (updateFields.Contains(Field.SHA384))
{
if (string.IsNullOrEmpty(SHA384) && !string.IsNullOrEmpty(newItem.SHA384))
SHA384 = newItem.SHA384;
}
if (updateFields.Contains(Field.SHA512))
{
if (string.IsNullOrEmpty(SHA512) && !string.IsNullOrEmpty(newItem.SHA512))
SHA512 = newItem.SHA512;
}
if (updateFields.Contains(Field.Merge))
MergeTag = newItem.MergeTag;
if (updateFields.Contains(Field.Region))
Region = newItem.Region;
if (updateFields.Contains(Field.Index))
Index = newItem.Index;
if (updateFields.Contains(Field.Writable))
Writable = newItem.Writable;
if (updateFields.Contains(Field.Status))
ItemStatus = newItem.ItemStatus;
if (updateFields.Contains(Field.Optional))
Optional = newItem.Optional;
}
#endregion
}
}

View File

@@ -162,5 +162,40 @@ namespace SabreTools.Library.DatItems
}
#endregion
#region Sorting and Merging
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> updateFields)
{
// Replace common fields first
base.ReplaceFields(item, updateFields);
// If we don't have a Release to replace from, ignore specific fields
if (item.ItemType != ItemType.Release)
return;
// Cast for easier access
Release newItem = item as Release;
// Replace the fields
if (updateFields.Contains(Field.Region))
Region = newItem.Region;
if (updateFields.Contains(Field.Language))
Language = newItem.Language;
if (updateFields.Contains(Field.Date))
Date = newItem.Date;
if (updateFields.Contains(Field.Default))
Default = newItem.Default;
}
#endregion
}
}

View File

@@ -565,6 +565,96 @@ namespace SabreTools.Library.DatItems
return key;
}
/// <summary>
/// Replace fields from another item
/// </summary>
/// <param name="item">DatItem to pull new information from</param>
/// <param name="updateFields">List of Fields representing what should be updated</param>
public override void ReplaceFields(DatItem item, List<Field> updateFields)
{
// Replace common fields first
base.ReplaceFields(item, updateFields);
// 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
if (updateFields.Contains(Field.Bios))
Bios = newItem.Bios;
if (updateFields.Contains(Field.Size))
Size = newItem.Size;
if (updateFields.Contains(Field.CRC))
{
if (string.IsNullOrEmpty(CRC) && !string.IsNullOrEmpty(newItem.CRC))
CRC = newItem.CRC;
}
if (updateFields.Contains(Field.MD5))
{
if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5))
MD5 = newItem.MD5;
}
#if NET_FRAMEWORK
if (updateFields.Contains(Field.RIPEMD160))
{
if (string.IsNullOrEmpty(RIPEMD160) && !string.IsNullOrEmpty(newItem.RIPEMD160))
RIPEMD160 = newItem.RIPEMD160;
}
#endif
if (updateFields.Contains(Field.SHA1))
{
if (string.IsNullOrEmpty(SHA1) && !string.IsNullOrEmpty(newItem.SHA1))
SHA1 = newItem.SHA1;
}
if (updateFields.Contains(Field.SHA256))
{
if (string.IsNullOrEmpty(SHA256) && !string.IsNullOrEmpty(newItem.SHA256))
SHA256 = newItem.SHA256;
}
if (updateFields.Contains(Field.SHA384))
{
if (string.IsNullOrEmpty(SHA384) && !string.IsNullOrEmpty(newItem.SHA384))
SHA384 = newItem.SHA384;
}
if (updateFields.Contains(Field.SHA512))
{
if (string.IsNullOrEmpty(SHA512) && !string.IsNullOrEmpty(newItem.SHA512))
SHA512 = newItem.SHA512;
}
if (updateFields.Contains(Field.Merge))
MergeTag = newItem.MergeTag;
if (updateFields.Contains(Field.Region))
Region = newItem.Region;
if (updateFields.Contains(Field.Offset))
Offset = newItem.Offset;
if (updateFields.Contains(Field.Date))
Date = newItem.Date;
if (updateFields.Contains(Field.Status))
ItemStatus = newItem.ItemStatus;
if (updateFields.Contains(Field.Optional))
Optional = newItem.Optional;
if (updateFields.Contains(Field.Inverted))
Inverted = newItem.Inverted;
}
#endregion
}
}