Recombine the pack type enums with comments

This commit is contained in:
Matt Nadareski
2026-06-14 16:31:05 -04:00
parent 5e5e15505e
commit cf77149d24
13 changed files with 207 additions and 389 deletions

View File

@@ -272,6 +272,113 @@ namespace SabreTools.RedumpLib.Test.Data
#endregion
#region Pack Type
/// <summary>
/// Check that every PackType has a long name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_LongName(PackType? packType, bool expectNull)
{
var actual = packType.LongName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Check that every PackType has a short name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ShortName(PackType? packType, bool expectNull)
{
var actual = packType.ShortName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Ensure that every PackType that has a short name that is unique
/// </summary>
[Fact]
public void PackType_ShortName_NoDuplicates()
{
var fullPackTypes = Enum.GetValues<PackType>().Cast<PackType>().ToList();
var filteredPackTypes = new Dictionary<string, PackType?>();
int totalCount = 0;
foreach (PackType? packType in fullPackTypes)
{
var code = packType.ShortName();
if (string.IsNullOrEmpty(code))
continue;
// Throw if the code already exists
if (filteredPackTypes.ContainsKey(code))
throw new DuplicateNameException($"Code {code} already in dictionary");
filteredPackTypes[code] = packType;
totalCount++;
}
Assert.Equal(totalCount, filteredPackTypes.Count);
}
/// <summary>
/// Check that every PackType can be mapped from a string
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ToPackType(PackType? packType, bool expectNull)
{
string? longName = packType.LongName();
string? longNameSpaceless = longName?.Replace(" ", string.Empty);
var actualNormal = longName.ToPackType();
var actualSpaceless = longNameSpaceless.ToPackType();
if (expectNull)
{
Assert.Null(actualNormal);
Assert.Null(actualSpaceless);
}
else
{
Assert.Equal(packType, actualNormal);
Assert.Equal(packType, actualSpaceless);
}
}
/// <summary>
/// Generate a test set of PackType values
/// </summary>
/// <returns>MemberData-compatible list of PackType values</returns>
public static TheoryData<PackType?, bool> GeneratePackTypeTestData()
{
var testData = new TheoryData<PackType?, bool>() { { null, true } };
foreach (PackType? packType in Enum.GetValues<PackType>().Cast<PackType?>())
{
testData.Add(packType, false);
}
return testData;
}
#endregion
#region Physical Media Type
[Fact]

View File

@@ -420,113 +420,6 @@ namespace SabreTools.RedumpLib.Test.RedumpInfo
#endregion
#region Pack Type
/// <summary>
/// Check that every PackType has a long name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_LongName(PackType? packType, bool expectNull)
{
var actual = packType.LongName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Check that every PackType has a short name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ShortName(PackType? packType, bool expectNull)
{
var actual = packType.ShortName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Ensure that every PackType that has a short name that is unique
/// </summary>
[Fact]
public void PackType_ShortName_NoDuplicates()
{
var fullPackTypes = Enum.GetValues<PackType>().Cast<PackType>().ToList();
var filteredPackTypes = new Dictionary<string, PackType?>();
int totalCount = 0;
foreach (PackType? packType in fullPackTypes)
{
var code = packType.ShortName();
if (string.IsNullOrEmpty(code))
continue;
// Throw if the code already exists
if (filteredPackTypes.ContainsKey(code))
throw new DuplicateNameException($"Code {code} already in dictionary");
filteredPackTypes[code] = packType;
totalCount++;
}
Assert.Equal(totalCount, filteredPackTypes.Count);
}
/// <summary>
/// Check that every PackType can be mapped from a string
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ToPackType(PackType? packType, bool expectNull)
{
string? longName = packType.LongName();
string? longNameSpaceless = longName?.Replace(" ", string.Empty);
var actualNormal = longName.ToPackType();
var actualSpaceless = longNameSpaceless.ToPackType();
if (expectNull)
{
Assert.Null(actualNormal);
Assert.Null(actualSpaceless);
}
else
{
Assert.Equal(packType, actualNormal);
Assert.Equal(packType, actualSpaceless);
}
}
/// <summary>
/// Generate a test set of PackType values
/// </summary>
/// <returns>MemberData-compatible list of PackType values</returns>
public static TheoryData<PackType?, bool> GeneratePackTypeTestData()
{
var testData = new TheoryData<PackType?, bool>() { { null, true } };
foreach (PackType? packType in Enum.GetValues<PackType>().Cast<PackType?>())
{
testData.Add(packType, false);
}
return testData;
}
#endregion
#region System Category
/// <summary>

View File

@@ -467,113 +467,6 @@ namespace SabreTools.RedumpLib.Test.RedumpOrg
#endregion
#region Pack Type
/// <summary>
/// Check that every PackType has a long name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_LongName(PackType? packType, bool expectNull)
{
var actual = packType.LongName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Check that every PackType has a short name provided
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ShortName(PackType? packType, bool expectNull)
{
var actual = packType.ShortName();
if (expectNull)
Assert.Null(actual);
else
Assert.NotNull(actual);
}
/// <summary>
/// Ensure that every PackType that has a short name that is unique
/// </summary>
[Fact]
public void PackType_ShortName_NoDuplicates()
{
var fullPackTypes = Enum.GetValues<PackType>().Cast<PackType>().ToList();
var filteredPackTypes = new Dictionary<string, PackType?>();
int totalCount = 0;
foreach (PackType? packType in fullPackTypes)
{
var code = packType.ShortName();
if (string.IsNullOrEmpty(code))
continue;
// Throw if the code already exists
if (filteredPackTypes.ContainsKey(code))
throw new DuplicateNameException($"Code {code} already in dictionary");
filteredPackTypes[code] = packType;
totalCount++;
}
Assert.Equal(totalCount, filteredPackTypes.Count);
}
/// <summary>
/// Check that every PackType can be mapped from a string
/// </summary>
/// <param name="packType">PackType value to check</param>
/// <param name="expectNull">True to expect a null value, false otherwise</param>
[Theory]
[MemberData(nameof(GeneratePackTypeTestData))]
public void PackType_ToPackType(PackType? packType, bool expectNull)
{
string? longName = packType.LongName();
string? longNameSpaceless = longName?.Replace(" ", string.Empty);
var actualNormal = longName.ToPackType();
var actualSpaceless = longNameSpaceless.ToPackType();
if (expectNull)
{
Assert.Null(actualNormal);
Assert.Null(actualSpaceless);
}
else
{
Assert.Equal(packType, actualNormal);
Assert.Equal(packType, actualSpaceless);
}
}
/// <summary>
/// Generate a test set of PackType values
/// </summary>
/// <returns>MemberData-compatible list of PackType values</returns>
public static TheoryData<PackType?, bool> GeneratePackTypeTestData()
{
var testData = new TheoryData<PackType?, bool>() { { null, true } };
foreach (PackType? packType in Enum.GetValues<PackType>().Cast<PackType?>())
{
testData.Add(packType, false);
}
return testData;
}
#endregion
#region Site Code
/// <summary>

View File

@@ -1670,6 +1670,36 @@ namespace SabreTools.RedumpLib.Data
#endregion
}
/// <summary>
/// All possible packs
/// </summary>
public enum PackType
{
[HumanReadable(LongName = "CUES", ShortName = "cues")]
Cuesheets,
[HumanReadable(LongName = "DAT", ShortName = "datfile")]
Datfile,
/// <remarks>Only in redump.org</remarks>
[HumanReadable(LongName = "Decrypted KEYS", ShortName = "dkeys")]
DecryptedKeys,
/// <remarks>Only in redump.org</remarks>
[HumanReadable(LongName = "GDIs", ShortName = "gdi")]
Gdis,
[HumanReadable(LongName = "KEYS", ShortName = "keys")]
Keys,
/// <remarks>Only in redump.org</remarks>
[HumanReadable(LongName = "LSD", ShortName = "lsd")]
Lsds,
[HumanReadable(LongName = "SBI", ShortName = "sbi")]
Sbis,
}
/// <summary>
/// All possible media types not bound to specific site limitations
/// </summary>

View File

@@ -967,6 +967,70 @@ namespace SabreTools.RedumpLib.Data
#endregion
#region Pack Type
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the Region enum value for a given string
/// </summary>
/// <param name="packType">String value to convert</param>
/// <returns>Region represented by the string, if possible</returns>
public static PackType? ToPackType(this string? packType)
{
// No value means no match
if (packType is null || packType.Length == 0)
return null;
packType = packType.ToLowerInvariant();
var packTypes = (PackType[])Enum.GetValues(typeof(PackType));
// Check short names
int index = Array.FindIndex(packTypes, s => packType == s.ShortName()?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
// Check long names
index = Array.FindIndex(packTypes, s => packType == s.LongName()?.ToLowerInvariant()
|| packType == s.LongName()?.Replace(" ", string.Empty)?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
return null;
}
#endregion
#region Physical Media Type
/// <summary>

View File

@@ -1422,7 +1422,10 @@ namespace SabreTools.RedumpLib.RedumpInfo
{
PackType.Cuesheets => system.HasCues(),
PackType.Datfile => system.HasDat(),
PackType.DecryptedKeys => false,
PackType.Gdis => false,
PackType.Keys => system.HasKeys(),
PackType.Lsds => false,
PackType.Sbis => system.HasSbi(),
_ => false,
};

View File

@@ -100,22 +100,4 @@ namespace SabreTools.RedumpLib.RedumpInfo.Data
[HumanReadable(LongName = "Wii U Optical Disc (SL)", ShortName = "bd25wiiu")]
WiiUOpticalDiscSL,
}
/// <summary>
/// All possible packs
/// </summary>
public enum PackType
{
[HumanReadable(LongName = "CUES", ShortName = "cues")]
Cuesheets,
[HumanReadable(LongName = "DAT", ShortName = "datfile")]
Datfile,
[HumanReadable(LongName = "KEYS", ShortName = "keys")]
Keys,
[HumanReadable(LongName = "SBI", ShortName = "sbi")]
Sbis,
}
}

View File

@@ -324,70 +324,6 @@ namespace SabreTools.RedumpLib.RedumpInfo.Data
#endregion
#region Pack Type
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the Region enum value for a given string
/// </summary>
/// <param name="packType">String value to convert</param>
/// <returns>Region represented by the string, if possible</returns>
public static PackType? ToPackType(this string? packType)
{
// No value means no match
if (packType is null || packType.Length == 0)
return null;
packType = packType.ToLowerInvariant();
var packTypes = (PackType[])Enum.GetValues(typeof(PackType));
// Check short names
int index = Array.FindIndex(packTypes, s => packType == s.ShortName()?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
// Check long names
index = Array.FindIndex(packTypes, s => packType == s.LongName()?.ToLowerInvariant()
|| packType == s.LongName()?.Replace(" ", string.Empty)?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
return null;
}
#endregion
#region System Category
/// <summary>

View File

@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpInfo.Data;
namespace SabreTools.RedumpLib.RedumpInfo
{

View File

@@ -260,7 +260,10 @@ namespace SabreTools.RedumpLib.RedumpInfo
{
case PackType.Cuesheets: sb.AppendFormat(CuesPath, systemName); break;
case PackType.Datfile: sb.AppendFormat(DatfilePath, systemName); break;
case PackType.DecryptedKeys: break; // Not supported
case PackType.Gdis: break; // Not supported
case PackType.Keys: sb.AppendFormat(KeysPath, systemName); break;
case PackType.Lsds: break; // Not supported
case PackType.Sbis: sb.AppendFormat(SbiPath, systemName); break;
default: throw new ArgumentOutOfRangeException(nameof(packType));

View File

@@ -148,33 +148,6 @@ namespace SabreTools.RedumpLib.RedumpOrg.Data
OptionsMenu,
}
/// <summary>
/// All possible packs
/// </summary>
public enum PackType
{
[HumanReadable(LongName = "CUES", ShortName = "cues")]
Cuesheets,
[HumanReadable(LongName = "DAT", ShortName = "datfile")]
Datfile,
[HumanReadable(LongName = "Decrypted KEYS", ShortName = "dkeys")]
DecryptedKeys,
[HumanReadable(LongName = "GDIs", ShortName = "gdi")]
Gdis,
[HumanReadable(LongName = "KEYS", ShortName = "keys")]
Keys,
[HumanReadable(LongName = "LSD", ShortName = "lsd")]
Lsds,
[HumanReadable(LongName = "SBI", ShortName = "sbi")]
Sbis,
}
/// <summary>
/// List of all Redump site codes
/// </summary>

View File

@@ -312,70 +312,6 @@ namespace SabreTools.RedumpLib.RedumpOrg.Data
#endregion
#region Pack Type
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the human readable name for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? LongName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.LongName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType packType)
=> AttributeHelper<PackType>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the URL path part for a PackType
/// </summary>
/// <param name="packType"></param>
/// <returns></returns>
public static string? ShortName(this PackType? packType)
=> AttributeHelper<PackType?>.GetHumanReadableAttribute(packType)?.ShortName;
/// <summary>
/// Get the Region enum value for a given string
/// </summary>
/// <param name="packType">String value to convert</param>
/// <returns>Region represented by the string, if possible</returns>
public static PackType? ToPackType(this string? packType)
{
// No value means no match
if (packType is null || packType.Length == 0)
return null;
packType = packType.ToLowerInvariant();
var packTypes = (PackType[])Enum.GetValues(typeof(PackType));
// Check short names
int index = Array.FindIndex(packTypes, s => packType == s.ShortName()?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
// Check long names
index = Array.FindIndex(packTypes, s => packType == s.LongName()?.ToLowerInvariant()
|| packType == s.LongName()?.Replace(" ", string.Empty)?.ToLowerInvariant());
if (index > -1)
return packTypes[index];
return null;
}
#endregion
#region Site Code
/// <summary>

View File

@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using SabreTools.RedumpLib.Data;
using SabreTools.RedumpLib.RedumpOrg.Data;
namespace SabreTools.RedumpLib.RedumpOrg
{