mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Migrate to GetMissingRequiredFields
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
@@ -507,15 +508,13 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determine if an item has all required fields to write out
|
/// Return list of required fields missing from a DatItem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datItem">DatItem to check</param>
|
/// <returns>List of missing required fields, null or empty if none were found</returns>
|
||||||
/// <returns>True if the item has all required fields, false otherwise</returns>
|
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// TODO: Implement this in all relevant DatFile types
|
/// TODO: Implement this in all relevant DatFile types
|
||||||
/// TODO: Return list of missing fields?
|
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected virtual bool HasRequiredFields(DatItem datItem) => true;
|
protected virtual List<DatItemField> GetMissingRequiredFields(DatItem datItem) => null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get if a machine contains any writable items
|
/// Get if a machine contains any writable items
|
||||||
@@ -592,10 +591,11 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have an item with missing required fields
|
// If we have an item with missing required fields
|
||||||
if (!HasRequiredFields(datItem))
|
List<DatItemField> missingFields = GetMissingRequiredFields(datItem);
|
||||||
|
if (missingFields == null || missingFields.Count == 0)
|
||||||
{
|
{
|
||||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||||
logger?.Verbose($"Item '{itemString}' was skipped because it was missing required fields for {Header?.DatFormat}");
|
logger?.Verbose($"Item '{itemString}' was skipped because it was missing required fields for {Header?.DatFormat}: {string.Join(", ", missingFields)}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
@@ -107,27 +108,128 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override bool HasRequiredFields(DatItem datItem)
|
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
|
||||||
{
|
{
|
||||||
// TODO: Add code to ensure name as well
|
List<DatItemField> missingFields = new List<DatItemField>();
|
||||||
|
|
||||||
return (_hash, datItem.ItemType) switch
|
// Check item name
|
||||||
|
if (string.IsNullOrWhiteSpace(datItem.GetName()))
|
||||||
|
missingFields.Add(DatItemField.Name);
|
||||||
|
|
||||||
|
// Check hash linked to specific Hashfile type
|
||||||
|
switch (_hash)
|
||||||
{
|
{
|
||||||
(Hash.CRC, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.CRC),
|
case Hash.CRC:
|
||||||
(Hash.MD5, ItemType.Disk) => !string.IsNullOrEmpty((datItem as Disk)?.MD5),
|
switch (datItem.ItemType)
|
||||||
(Hash.MD5, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.MD5),
|
{
|
||||||
(Hash.MD5, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.MD5),
|
case ItemType.Rom:
|
||||||
(Hash.SHA1, ItemType.Disk) => !string.IsNullOrEmpty((datItem as Disk)?.SHA1),
|
if (!string.IsNullOrEmpty((datItem as Rom)?.CRC))
|
||||||
(Hash.SHA1, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SHA1),
|
missingFields.Add(DatItemField.CRC);
|
||||||
(Hash.SHA1, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA1),
|
break;
|
||||||
(Hash.SHA256, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SHA256),
|
default:
|
||||||
(Hash.SHA256, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA256),
|
missingFields.Add(DatItemField.CRC);
|
||||||
(Hash.SHA384, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA384),
|
break;
|
||||||
(Hash.SHA512, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA512),
|
}
|
||||||
(Hash.SpamSum, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SpamSum),
|
break;
|
||||||
(Hash.SpamSum, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SpamSum),
|
case Hash.MD5:
|
||||||
_ => false,
|
switch (datItem.ItemType)
|
||||||
};
|
{
|
||||||
|
case ItemType.Disk:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Disk)?.MD5))
|
||||||
|
missingFields.Add(DatItemField.MD5);
|
||||||
|
break;
|
||||||
|
case ItemType.Media:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Media)?.MD5))
|
||||||
|
missingFields.Add(DatItemField.MD5);
|
||||||
|
break;
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.MD5))
|
||||||
|
missingFields.Add(DatItemField.MD5);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.MD5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Hash.SHA1:
|
||||||
|
switch (datItem.ItemType)
|
||||||
|
{
|
||||||
|
case ItemType.Disk:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Disk)?.SHA1))
|
||||||
|
missingFields.Add(DatItemField.SHA1);
|
||||||
|
break;
|
||||||
|
case ItemType.Media:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Media)?.SHA1))
|
||||||
|
missingFields.Add(DatItemField.SHA1);
|
||||||
|
break;
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.SHA1))
|
||||||
|
missingFields.Add(DatItemField.SHA1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.SHA1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Hash.SHA256:
|
||||||
|
switch (datItem.ItemType)
|
||||||
|
{
|
||||||
|
case ItemType.Media:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Media)?.SHA256))
|
||||||
|
missingFields.Add(DatItemField.SHA256);
|
||||||
|
break;
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.SHA256))
|
||||||
|
missingFields.Add(DatItemField.SHA256);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.SHA256);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Hash.SHA384:
|
||||||
|
switch (datItem.ItemType)
|
||||||
|
{
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.SHA384))
|
||||||
|
missingFields.Add(DatItemField.SHA384);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.SHA384);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Hash.SHA512:
|
||||||
|
switch (datItem.ItemType)
|
||||||
|
{
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.SHA512))
|
||||||
|
missingFields.Add(DatItemField.SHA512);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.SHA512);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Hash.SpamSum:
|
||||||
|
switch (datItem.ItemType)
|
||||||
|
{
|
||||||
|
case ItemType.Media:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Media)?.SpamSum))
|
||||||
|
missingFields.Add(DatItemField.SpamSum);
|
||||||
|
break;
|
||||||
|
case ItemType.Rom:
|
||||||
|
if (!string.IsNullOrEmpty((datItem as Rom)?.SpamSum))
|
||||||
|
missingFields.Add(DatItemField.SpamSum);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
missingFields.Add(DatItemField.SpamSum);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return missingFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|||||||
Reference in New Issue
Block a user