hactoolnet: Remove use of enum reflection

This commit is contained in:
Alex Barney 2020-08-19 11:00:32 -07:00
parent 2242fc6371
commit 3a3c4822be
3 changed files with 20 additions and 7 deletions

View file

@ -72,6 +72,19 @@ namespace hactoolnet
};
}
public static string Print(this XciPartitionType value)
{
return value switch
{
XciPartitionType.Update => nameof(XciPartitionType.Update),
XciPartitionType.Normal => nameof(XciPartitionType.Normal),
XciPartitionType.Secure => nameof(XciPartitionType.Secure),
XciPartitionType.Logo => nameof(XciPartitionType.Logo),
XciPartitionType.Root => nameof(XciPartitionType.Root),
_ => value.ToString()
};
}
public static string Print(this Validity value)
{
return value switch

View file

@ -189,11 +189,11 @@ namespace hactoolnet
foreach (SwitchFsNca nca in title.Ncas)
{
ctx.Logger.LogMessage($" {nca.Nca.Header.ContentType.ToString()}");
ctx.Logger.LogMessage($" {nca.Nca.Header.ContentType.Print()}");
Validity validity = nca.VerifyNca(ctx.Logger, true);
ctx.Logger.LogMessage($" {validity.ToString()}");
ctx.Logger.LogMessage($" {validity.Print()}");
}
}
catch (Exception ex)
@ -256,7 +256,7 @@ namespace hactoolnet
foreach (SwitchFsNca nca in sdfs.Ncas.Values.OrderBy(x => x.NcaId))
{
table.AddRow(nca.NcaId, nca.Nca.Header.ContentType.ToString(), nca.Nca.Header.TitleId.ToString("X16"));
table.AddRow(nca.NcaId, nca.Nca.Header.ContentType.Print(), nca.Nca.Header.TitleId.ToString("X16"));
}
return table.Print();

View file

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Linq;
using System.Text;
using LibHac;
@ -155,8 +154,9 @@ namespace hactoolnet
PrintPartition(sb, colLen, xci.OpenPartition(XciPartitionType.Root), XciPartitionType.Root);
foreach (XciPartitionType type in Enum.GetValues(typeof(XciPartitionType)))
for (int i = 0; i <= (int)XciPartitionType.Root; i++)
{
var type = (XciPartitionType)i;
if (type == XciPartitionType.Root || !xci.HasPartition(type)) continue;
XciPartition partition = xci.OpenPartition(type);
@ -170,7 +170,7 @@ namespace hactoolnet
{
const int fileNameLen = 57;
sb.AppendLine($"{type.ToString()} Partition:{partition.HashValidity.GetValidityString()}");
sb.AppendLine($"{type.Print()} Partition:{partition.HashValidity.GetValidityString()}");
PrintItem(sb, colLen, " Magic:", partition.Header.Magic);
PrintItem(sb, colLen, " Offset:", $"{partition.Offset:x12}");
PrintItem(sb, colLen, " Number of files:", partition.Files.Length);