diff --git a/SabreTools.DatFiles/DatFile.cs b/SabreTools.DatFiles/DatFile.cs
index ea312d02..52ff123d 100644
--- a/SabreTools.DatFiles/DatFile.cs
+++ b/SabreTools.DatFiles/DatFile.cs
@@ -506,6 +506,16 @@ namespace SabreTools.DatFiles
return Enum.GetValues(typeof(ItemType)) as ItemType[];
}
+ ///
+ /// Determine if an item has all required fields to write out
+ ///
+ /// DatItem to check
+ /// True if the item has all required fields, false otherwise
+ ///
+ /// TODO: Implement this in all relevant DatFile types
+ ///
+ protected virtual bool HasRequiredFields(DatItem datItem) => true;
+
///
/// Get if a machine contains any writable items
///
@@ -564,16 +574,6 @@ namespace SabreTools.DatFiles
return false;
}
- ///
- /// Determine if an item has all required fields to write out
- ///
- /// DatItem to check
- /// True if the item has all required fields, false otherwise
- ///
- /// TODO: Implement this in all relevant DatFile types
- ///
- protected virtual bool HasRequiredFields(DatItem datItem) => true;
-
#endregion
}
}
diff --git a/SabreTools.DatFiles/Formats/Hashfile.cs b/SabreTools.DatFiles/Formats/Hashfile.cs
index 23e97075..2fbb9202 100644
--- a/SabreTools.DatFiles/Formats/Hashfile.cs
+++ b/SabreTools.DatFiles/Formats/Hashfile.cs
@@ -1,5 +1,7 @@
using System;
+using System.ComponentModel;
using System.IO;
+using System.Security.Cryptography;
using System.Text;
using SabreTools.Core;
@@ -107,6 +109,31 @@ namespace SabreTools.DatFiles.Formats
return new ItemType[] { ItemType.Disk, ItemType.Media, ItemType.Rom };
}
+ ///
+ protected override bool HasRequiredFields(DatItem datItem)
+ {
+ return true;
+
+ // TODO: Use this code once `strict` rules determined
+ return (_hash, datItem.ItemType) switch
+ {
+ (Hash.CRC, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.CRC),
+ (Hash.MD5, ItemType.Disk) => !string.IsNullOrEmpty((datItem as Disk)?.MD5),
+ (Hash.MD5, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.MD5),
+ (Hash.MD5, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.MD5),
+ (Hash.SHA1, ItemType.Disk) => !string.IsNullOrEmpty((datItem as Disk)?.SHA1),
+ (Hash.SHA1, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SHA1),
+ (Hash.SHA1, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA1),
+ (Hash.SHA256, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SHA256),
+ (Hash.SHA256, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA256),
+ (Hash.SHA384, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA384),
+ (Hash.SHA512, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SHA512),
+ (Hash.SpamSum, ItemType.Media) => !string.IsNullOrEmpty((datItem as Media)?.SpamSum),
+ (Hash.SpamSum, ItemType.Rom) => !string.IsNullOrEmpty((datItem as Rom)?.SpamSum),
+ _ => false,
+ };
+ }
+
///
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{