Read nacp display name and version

This commit is contained in:
Alex Barney 2018-06-30 14:15:55 -05:00
parent 1df1ce7bcc
commit d5ddde4909
3 changed files with 55 additions and 2 deletions

View file

@ -129,7 +129,7 @@ namespace hactoolnet
{ {
foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id)) foreach (var title in sdfs.Titles.Values.OrderBy(x => x.Id))
{ {
Console.WriteLine(title.Name); Console.WriteLine($"{title.Name} {title.Control?.Version}");
Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}"); Console.WriteLine($"{title.Id:X16} v{title.Version.Version} ({title.Version}) {title.Metadata.Type}");
foreach (var content in title.Metadata.ContentEntries) foreach (var content in title.Metadata.ContentEntries)

41
libhac/Nacp.cs Normal file
View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace libhac
{
public class Nacp
{
public NacpLang[] Languages { get; } = new NacpLang[0x10];
public string Version { get; }
public Nacp(BinaryReader reader)
{
var start = reader.BaseStream.Position;
for (int i = 0; i < 16; i++)
{
Languages[i] = new NacpLang(reader);
}
reader.BaseStream.Position = start + 0x3060;
Version = reader.ReadUtf8Z();
}
}
public class NacpLang
{
public string Title { get; }
public string Developer { get; }
public NacpLang(BinaryReader reader)
{
var start = reader.BaseStream.Position;
Title = reader.ReadUtf8Z();
reader.BaseStream.Position = start + 0x200;
Developer = reader.ReadUtf8Z();
reader.BaseStream.Position = start + 0x300;
}
}
}

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -108,7 +109,16 @@ namespace libhac
File.WriteAllBytes($"control/{title.Id:X16}.nacp", control); File.WriteAllBytes($"control/{title.Id:X16}.nacp", control);
var reader = new BinaryReader(new MemoryStream(control)); var reader = new BinaryReader(new MemoryStream(control));
title.Name = reader.ReadUtf8Z(); title.Control = new Nacp(reader);
foreach (var lang in title.Control.Languages)
{
if (!string.IsNullOrWhiteSpace(lang.Title))
{
title.Name = lang.Title;
break;
}
}
} }
} }
@ -131,6 +141,7 @@ namespace libhac
} }
} }
[DebuggerDisplay("{" + nameof(Name) + "}")]
public class Title public class Title
{ {
public ulong Id { get; internal set; } public ulong Id { get; internal set; }
@ -139,6 +150,7 @@ namespace libhac
public Cnmt Metadata { get; internal set; } public Cnmt Metadata { get; internal set; }
public string Name { get; internal set; } public string Name { get; internal set; }
public Nacp Control { get; internal set; }
public Nca MetaNca { get; internal set; } public Nca MetaNca { get; internal set; }
public Nca ProgramNca { get; internal set; } public Nca ProgramNca { get; internal set; }
public Nca ControlNca { get; internal set; } public Nca ControlNca { get; internal set; }