private void ReadTitles() { foreach (Nca nca in Ncas.Values.Where(x => x.Header.ContentType == ContentType.Meta)) { var title = new Title(); // Meta contents always have 1 Partition FS section with 1 file in it IStorage sect = nca.OpenSection(0, false, IntegrityCheckLevel.ErrorOnInvalid, true); var pfs0 = new Pfs(sect); IStorage file = pfs0.OpenFile(pfs0.Files[0]); var metadata = new Cnmt(file.AsStream()); title.Id = metadata.TitleId; title.Version = metadata.TitleVersion; title.Metadata = metadata; title.MetaNca = nca; title.Ncas.Add(nca); foreach (CnmtContentEntry content in metadata.ContentEntries) { string ncaId = content.NcaId.ToHexString(); if (Ncas.TryGetValue(ncaId, out Nca contentNca)) { title.Ncas.Add(contentNca); } switch (content.Type) { case CnmtContentType.Program: case CnmtContentType.Data: title.MainNca = contentNca; break; case CnmtContentType.Control: title.ControlNca = contentNca; break; } } Titles[title.Id] = title; } }
public static void Extract(this Pfs pfs, string outDir, IProgressReport logger = null) { foreach (PfsFileEntry file in pfs.Header.Files) { IStorage storage = pfs.OpenFile(file); string outName = Path.Combine(outDir, file.Name); string dir = Path.GetDirectoryName(outName); if (!string.IsNullOrWhiteSpace(dir)) { Directory.CreateDirectory(dir); } using (var outFile = new FileStream(outName, FileMode.Create, FileAccess.ReadWrite)) { logger?.LogMessage(file.Name); storage.CopyToStream(outFile, storage.Length, logger); } } }