public static Object OpenNcaStorageByTID(string dirPath, ulong titleId, bool shouldReturnPath = false) { string outPath = null; foreach (string ncaPath in GetAllNcas(dirPath)) { NcaInfo nca; using (IStorage inFile = new LocalStorage(ncaPath, FileAccess.Read)) { nca = new NcaInfo(inFile); if (nca.Nca.Header.TitleId == titleId) { outPath = ncaPath; break; } } } if (outPath != null && shouldReturnPath == false) { return(new LocalStorage(outPath, FileAccess.Read)); } return(outPath); }
public static List <string> GetAllNcaPaths(string dirPath) { List <string> ncaPathList = new List <string>(); if (!Directory.Exists(dirPath)) { return(ncaPathList); } foreach (string dir in Directory.EnumerateDirectories(dirPath, "*.nca")) { string fullPath = Path.GetFullPath(dir + Path.DirectorySeparatorChar + "00.nca"); if (File.Exists(fullPath)) { NcaInfo ncaInfo = new NcaInfo(new LocalStorage(fullPath, FileAccess.Read)); if (ncaInfo.Nca.Header.ContentType != NcaContentType.Meta) { ncaPathList.Add(fullPath); } } } foreach (string ncaPath in Directory.EnumerateFiles(dirPath, "*.nca")) { NcaInfo ncaInfo = new NcaInfo(new LocalStorage(ncaPath, FileAccess.Read)); if (ncaInfo.Nca.Header.ContentType != NcaContentType.Meta) { ncaPathList.Add(ncaPath); } } return(ncaPathList); }
public static Dictionary <string, string> GetAllNcasAndName(string dirPath) { Dictionary <string, string> ncaPathList = new Dictionary <string, string>(); foreach (string dir in Directory.EnumerateDirectories(dirPath, "*.nca")) { if (File.Exists(dir + "/00.nca")) { NcaInfo nca; using (IStorage inFile = new LocalStorage(dir + "/00.nca", FileAccess.Read)) { nca = new NcaInfo(inFile); ncaPathList.Add(dir + "/00.nca", nca.TitleName); } } } foreach (string ncaPath in Directory.EnumerateFiles(dirPath, "*.nca")) { NcaInfo nca; using (IStorage inFile = new LocalStorage(ncaPath, FileAccess.Read)) { nca = new NcaInfo(inFile); ncaPathList.Add(ncaPath, nca.TitleName); } } return(ncaPathList); }
public static string GetNcaPathFromTID(string dirPath, ulong tid) { foreach (string path in GetAllNcaPaths(dirPath)) { NcaInfo ncaInfo = new NcaInfo(new LocalStorage(path, FileAccess.Read)); if (ncaInfo.Nca.Header.TitleId == tid) { return(path); } } return(""); }
public static void ExtractAll(string inFirmwareDirectoryPath, string outputDirectoryPath) { foreach (string ncaPath in GetAllNcas(inFirmwareDirectoryPath)) { NcaInfo nca; using (IStorage inFile = new LocalStorage(ncaPath, FileAccess.Read)) { nca = new NcaInfo(inFile); nca.Extract(outputDirectoryPath); } } }
public static string GetNcaPathFromName(string dirPath, string name) { Dictionary <string, string> PathNameMap = GetAllNcaPathsAndNames(dirPath); foreach (string path in PathNameMap.Keys) { if (!System.IO.File.Exists(path)) { continue; } IStorage ncaStorage = new LocalStorage(path, FileAccess.Read); NcaInfo ncaInfo = new NcaInfo(ncaStorage); if (ncaInfo.TitleName == name) { return(path); } } return(""); }
public static Dictionary <string, string> GetAllNcaPathsAndNames(string dirPath) { Dictionary <string, string> ncaPathList = new Dictionary <string, string>(); if (!Directory.Exists(dirPath)) { return(ncaPathList); } foreach (string ncaPath in GetAllNcaPaths(dirPath)) { NcaInfo nca; using (IStorage inFile = new LocalStorage(ncaPath, FileAccess.Read)) { if (inFile != null) { nca = new NcaInfo(inFile); ncaPathList.Add(ncaPath, nca.TitleName); } } } return(ncaPathList); }
public void ShowNcaInfo() { Window.RemoveAll(); string NcaPath = (string)Utils.FirmwareUtils.OpenNcaStorageByTitleName(Path, FwTui.NcaNames[FwTui.FirmwareListView.SelectedItem], true); NcaInfo ncaInfo = new NcaInfo(new LocalStorage(NcaPath, FileAccess.Read)); List <string> NcaInfoLines = new List <string>(); string FormattedTid = $"{ncaInfo.Nca.Header.TitleId:X16}"; string FormattedName = $"{ncaInfo.TitleName}"; NcaInfoLines.Add($"Title ID: {FormattedTid}"); if (FormattedName != FormattedTid) { NcaInfoLines.Add($"Title Name: {FormattedName}"); } NcaInfoLines.Add($"Content Type: {ncaInfo.Nca.Header.ContentType}"); string ncaID = NcaPath.Split("/").Last(); if (ncaID == "00.nca") { ncaID = NcaPath.Split("/")[NcaPath.Split("/").Length - 2]; } else { ncaID = ncaID.Replace(".nca", ""); } NcaInfoLines.Add($"Nca ID: {ncaID}"); for (NcaSectionType section = NcaSectionType.Code; section <= NcaSectionType.Logo; section++) { if (ncaInfo.Nca.SectionExists(section)) { NcaInfoLines.Add($"\n{section}"); try { using (PartitionFileSystem pfs = new PartitionFileSystem(ncaInfo.TryOpenStorageSection(section))) { foreach (DirectoryEntryEx dirEnt in pfs.EnumerateEntries()) { NcaInfoLines.Add($"{dirEnt.Name} - {dirEnt.Size} bytes"); } } } catch (LibHac.HorizonResultException) { } } } //Actually draw them int Y = 1; foreach (string content in NcaInfoLines) { int lines = System.Text.RegularExpressions.Regex.Matches(content, "\n").Count + 1; Window.Add(new Label(1, Y, content)); Y += lines; } }