From f2f21117298b9862674c3a78ebd51ad278fd64c1 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 17 Aug 2020 18:41:39 -0700 Subject: [PATCH] hactoolnet: Add functions to convert some enums to strings --- src/hactoolnet/EnumStrings.cs | 87 +++++++++++++++++++++++++++++++ src/hactoolnet/ProcessNca.cs | 8 +-- src/hactoolnet/ProcessSwitchFs.cs | 2 +- 3 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/hactoolnet/EnumStrings.cs diff --git a/src/hactoolnet/EnumStrings.cs b/src/hactoolnet/EnumStrings.cs new file mode 100644 index 00000000..a154ff17 --- /dev/null +++ b/src/hactoolnet/EnumStrings.cs @@ -0,0 +1,87 @@ +using LibHac; +using LibHac.FsSystem.NcaUtils; +using LibHac.Ncm; + +namespace hactoolnet +{ + internal static class EnumStrings + { + public static string Print(this ContentType value) + { + return value switch + { + ContentType.Meta => nameof(ContentType.Meta), + ContentType.Program => nameof(ContentType.Program), + ContentType.Data => nameof(ContentType.Data), + ContentType.Control => nameof(ContentType.Control), + ContentType.HtmlDocument => nameof(ContentType.HtmlDocument), + ContentType.LegalInformation => nameof(ContentType.LegalInformation), + ContentType.DeltaFragment => nameof(ContentType.DeltaFragment), + _ => value.ToString() + }; + } + + public static string Print(this ContentMetaType value) + { + return value switch + { + ContentMetaType.SystemProgram => nameof(ContentMetaType.SystemProgram), + ContentMetaType.SystemData => nameof(ContentMetaType.SystemData), + ContentMetaType.SystemUpdate => nameof(ContentMetaType.SystemUpdate), + ContentMetaType.BootImagePackage => nameof(ContentMetaType.BootImagePackage), + ContentMetaType.BootImagePackageSafe => nameof(ContentMetaType.BootImagePackageSafe), + ContentMetaType.Application => nameof(ContentMetaType.Application), + ContentMetaType.Patch => nameof(ContentMetaType.Patch), + ContentMetaType.AddOnContent => nameof(ContentMetaType.AddOnContent), + ContentMetaType.Delta => nameof(ContentMetaType.Delta), + _ => value.ToString() + }; + } + + public static string Print(this DistributionType value) + { + return value switch + { + DistributionType.Download => nameof(DistributionType.Download), + DistributionType.GameCard => nameof(DistributionType.GameCard), + _ => value.ToString() + }; + } + + public static string Print(this NcaContentType value) + { + return value switch + { + NcaContentType.Program => nameof(NcaContentType.Program), + NcaContentType.Meta => nameof(NcaContentType.Meta), + NcaContentType.Control => nameof(NcaContentType.Control), + NcaContentType.Manual => nameof(NcaContentType.Manual), + NcaContentType.Data => nameof(NcaContentType.Data), + NcaContentType.PublicData => nameof(NcaContentType.PublicData), + _ => value.ToString() + }; + } + + public static string Print(this NcaFormatType value) + { + return value switch + { + NcaFormatType.Romfs => nameof(NcaFormatType.Romfs), + NcaFormatType.Pfs0 => nameof(NcaFormatType.Pfs0), + _ => value.ToString() + }; + } + + public static string Print(this Validity value) + { + return value switch + { + Validity.Unchecked => nameof(Validity.Unchecked), + Validity.Invalid => nameof(Validity.Invalid), + Validity.Valid => nameof(Validity.Valid), + Validity.MissingKey => nameof(Validity.MissingKey), + _ => value.ToString() + }; + } + } +} diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs index 5e9b051d..cb3287ff 100644 --- a/src/hactoolnet/ProcessNca.cs +++ b/src/hactoolnet/ProcessNca.cs @@ -250,8 +250,8 @@ namespace hactoolnet } PrintItem(sb, colLen, "SDK Version:", nca.Header.SdkVersion); - PrintItem(sb, colLen, "Distribution type:", nca.Header.DistributionType); - PrintItem(sb, colLen, "Content Type:", nca.Header.ContentType); + PrintItem(sb, colLen, "Distribution type:", nca.Header.DistributionType.Print()); + PrintItem(sb, colLen, "Content Type:", nca.Header.ContentType.Print()); PrintItem(sb, colLen, "Master Key Revision:", $"{masterKey} ({Utilities.GetKeyRevisionSummary(masterKey)})"); PrintItem(sb, colLen, "Encryption Type:", $"{(nca.Header.HasRightsId ? "Titlekey crypto" : "Standard crypto")}"); @@ -326,7 +326,7 @@ namespace hactoolnet PrintItem(sb, colLen, " Size:", $"0x{nca.Header.GetSectionSize(i):x12}"); PrintItem(sb, colLen, " Partition Type:", GetPartitionType(sectHeader, isExefs, nca.Header.IsNca0())); PrintItem(sb, colLen, " Section CTR:", $"{sectHeader.Counter:x16}"); - PrintItem(sb, colLen, " Section Validity:", $"{ncaHolder.Validities[i]}"); + PrintItem(sb, colLen, " Section Validity:", $"{ncaHolder.Validities[i].Print()}"); switch (sectHeader.HashType) { @@ -350,7 +350,7 @@ namespace hactoolnet if (isExefs) return "ExeFS"; if (isNca0 && fsHeader.FormatType == NcaFormatType.Romfs) return "NCA0 RomFS"; - return fsHeader.FormatType + (fsHeader.IsPatchSection() ? " patch" : ""); + return fsHeader.FormatType.Print() + (fsHeader.IsPatchSection() ? " patch" : ""); } void PrintSha256Hash(NcaFsHeader sect, int index) diff --git a/src/hactoolnet/ProcessSwitchFs.cs b/src/hactoolnet/ProcessSwitchFs.cs index 488083be..21586cb5 100644 --- a/src/hactoolnet/ProcessSwitchFs.cs +++ b/src/hactoolnet/ProcessSwitchFs.cs @@ -241,7 +241,7 @@ namespace hactoolnet table.AddRow($"{title.Id:X16}", $"v{title.Version?.Version}", title.Version?.ToString(), - title.Metadata?.Type.ToString(), + title.Metadata?.Type.Print(), Utilities.GetBytesReadable(title.GetSize()), title.Control.Value.DisplayVersion.ToString(), title.Name);