diff --git a/NX_Game_Info/Common.cs b/NX_Game_Info/Common.cs index 478d183..6c91103 100644 --- a/NX_Game_Info/Common.cs +++ b/NX_Game_Info/Common.cs @@ -92,6 +92,14 @@ public char CsvSeparator set { this["CsvSeparator"] = value; } } + [UserScopedSetting()] + [DefaultSettingValue("False")] + public bool NszExtension + { + get { return (bool)this["NszExtension"]; } + set { this["NszExtension"] = value; } + } + #if WINDOWS [UserScopedSetting()] [DefaultSettingValue("0, 0")] diff --git a/NX_Game_Info/Process.cs b/NX_Game_Info/Process.cs index b774ef1..eb988d4 100644 --- a/NX_Game_Info/Process.cs +++ b/NX_Game_Info/Process.cs @@ -372,12 +372,22 @@ public static Title processXci(string filename) { if (entry.Name.EndsWith(".cnmt.nca")) { - using (var cnmtNca = xci.SecurePartition.OpenFile(entry)) + try { - var nca = processCnmtNca(cnmtNca, ref title); - if (nca.Item1 != null && (nca.Item2 != null || title.type == TitleType.AddOnContent)) + using (var cnmtNca = xci.SecurePartition.OpenFile(entry)) { - (biggestNca, controlNca) = nca; + var nca = processCnmtNca(cnmtNca, ref title); + if (nca.Item1 != null && (nca.Item2 != null || title.type == TitleType.AddOnContent)) + { + (biggestNca, controlNca) = nca; + } + } + } + catch (FileNotFoundException) + { + if (xci.SecurePartition.FileExists(entry.Name.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; } } @@ -389,13 +399,23 @@ public static Title processXci(string filename) } else if (entry.Name.EndsWith(".tik")) { - using (var tik = xci.SecurePartition.OpenFile(entry)) + try { - if (entry.Name.Split('.')[0].TryToBytes(out byte[] rightsId)) + using (var tik = xci.SecurePartition.OpenFile(entry)) { - processTik(tik, rightsId, ref keyset, out byte[] titleKey); + if (entry.Name.Split('.')[0].TryToBytes(out byte[] rightsId)) + { + processTik(tik, rightsId, ref keyset, out byte[] titleKey); - title.titleKey = BitConverter.ToString(titleKey).Replace("-", "").ToUpper(); + title.titleKey = BitConverter.ToString(titleKey).Replace("-", "").ToUpper(); + } + } + } + catch (FileNotFoundException) + { + if (xci.SecurePartition.FileExists(entry.Name.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; } } @@ -405,17 +425,37 @@ public static Title processXci(string filename) if (!String.IsNullOrEmpty(biggestNca)) { - using (var biggest = xci.SecurePartition.OpenFile(biggestNca)) + try { - processBiggestNca(biggest, ref title); + using (var biggest = xci.SecurePartition.OpenFile(biggestNca)) + { + processBiggestNca(biggest, ref title); + } + } + catch (FileNotFoundException) + { + if (xci.SecurePartition.FileExists(biggestNca.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; + } } } if (!String.IsNullOrEmpty(controlNca)) { - using (var control = xci.SecurePartition.OpenFile(controlNca)) + try { - processControlNca(control, ref title); + using (var control = xci.SecurePartition.OpenFile(controlNca)) + { + processControlNca(control, ref title); + } + } + catch (FileNotFoundException) + { + if (xci.SecurePartition.FileExists(controlNca.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; + } } } @@ -468,21 +508,35 @@ public static Title processNsp(string filename) { if (entry.Name.EndsWith(".cnmt.xml")) { - using (var cnmtXml = pfs.OpenFile(entry)) + try { - (biggestNca, controlNca) = processCnmtXml(cnmtXml, ref title); + using (var cnmtXml = pfs.OpenFile(entry)) + { + (biggestNca, controlNca) = processCnmtXml(cnmtXml, ref title); + } } + catch (FileNotFoundException) { } title.structure.Add(Title.Structure.CnmtXml); } else if (entry.Name.EndsWith(".cnmt.nca")) { - using (var cnmtNca = pfs.OpenFile(entry)) + try + { + using (var cnmtNca = pfs.OpenFile(entry)) + { + var nca = processCnmtNca(cnmtNca, ref title); + if (nca.Item1 != null && (nca.Item2 != null || title.type == TitleType.AddOnContent)) + { + (biggestNca, controlNca) = nca; + } + } + } + catch (FileNotFoundException) { - var nca = processCnmtNca(cnmtNca, ref title); - if (nca.Item1 != null && (nca.Item2 != null || title.type == TitleType.AddOnContent)) + if (pfs.FileExists(entry.Name.Replace(".nca", ".ncz"))) { - (biggestNca, controlNca) = nca; + title.error = "Unsupported Format: Compressed NCA"; } } @@ -494,13 +548,23 @@ public static Title processNsp(string filename) } else if (entry.Name.EndsWith(".tik")) { - using (var tik = pfs.OpenFile(entry)) + try { - if (entry.Name.Split('.')[0].TryToBytes(out byte[] rightsId)) + using (var tik = pfs.OpenFile(entry)) { - processTik(tik, rightsId, ref keyset, out byte[] titleKey); + if (entry.Name.Split('.')[0].TryToBytes(out byte[] rightsId)) + { + processTik(tik, rightsId, ref keyset, out byte[] titleKey); - title.titleKey = BitConverter.ToString(titleKey).Replace("-", "").ToUpper(); + title.titleKey = BitConverter.ToString(titleKey).Replace("-", "").ToUpper(); + } + } + } + catch (FileNotFoundException) + { + if (pfs.FileExists(entry.Name.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; } } @@ -512,10 +576,14 @@ public static Title processNsp(string filename) } else if (entry.Name.EndsWith(".nacp.xml")) { - using (var nacpXml = pfs.OpenFile(entry)) + try { - processNacpXml(nacpXml, ref title); + using (var nacpXml = pfs.OpenFile(entry)) + { + processNacpXml(nacpXml, ref title); + } } + catch (FileNotFoundException) { } title.structure.Add(Title.Structure.NacpXml); } @@ -535,17 +603,37 @@ public static Title processNsp(string filename) if (!String.IsNullOrEmpty(biggestNca)) { - using (var biggest = pfs.OpenFile(biggestNca)) + try + { + using (var biggest = pfs.OpenFile(biggestNca)) + { + processBiggestNca(biggest, ref title); + } + } + catch (FileNotFoundException) { - processBiggestNca(biggest, ref title); + if (pfs.FileExists(biggestNca.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; + } } } if (!String.IsNullOrEmpty(controlNca)) { - using (var control = pfs.OpenFile(controlNca)) + try + { + using (var control = pfs.OpenFile(controlNca)) + { + processControlNca(control, ref title); + } + } + catch (FileNotFoundException) { - processControlNca(control, ref title); + if (pfs.FileExists(controlNca.Replace(".nca", ".ncz"))) + { + title.error = "Unsupported Format: Compressed NCA"; + } } } } @@ -853,6 +941,7 @@ private static (string, string) processCnmtNca(Nca nca, ref Title title, bool cn log?.WriteLine(title.error); } + catch (FileNotFoundException) { } return (biggestNca, controlNca); } @@ -993,6 +1082,7 @@ private static void processControlNca(Nca nca, ref Title title) log?.WriteLine(title.error); } + catch (FileNotFoundException) { } } } diff --git a/Windows/Main.cs b/Windows/Main.cs index 12426c8..0b1720e 100644 --- a/Windows/Main.cs +++ b/Windows/Main.cs @@ -284,7 +284,8 @@ private void openFileToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Open NX Game Files"; - openFileDialog.Filter = "NX Game Files (*.xci;*.nsp;*.nro)|*.xci;*.nsp;*.nro|Gamecard Files (*.xci)|*.xci|Package Files (*.nsp)|*.nsp|Homebrew Files (*.nro)|*.nro|All Files (*.*)|*.*"; + openFileDialog.Filter = String.Format("NX Game Files (*.xci;*.nsp;{0}*.nro)|*.xci;*.nsp;{0}*.nro|Gamecard Files (*.xci{1})|*.xci{1}|Package Files (*.nsp{2})|*.nsp{2}|Homebrew Files (*.nro)|*.nro|All Files (*.*)|*.*", + Common.Settings.Default.NszExtension ? "*.xcz;*.nsz;" : "", Common.Settings.Default.NszExtension ? ";*.xcz" : "", Common.Settings.Default.NszExtension ? ";*.nsz" : ""); openFileDialog.Multiselect = true; openFileDialog.InitialDirectory = !String.IsNullOrEmpty(Common.Settings.Default.InitialDirectory) && Directory.Exists(Common.Settings.Default.InitialDirectory) ? Common.Settings.Default.InitialDirectory : Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()); @@ -783,7 +784,8 @@ private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel if (argumentPath.Item1 == Worker.Directory && argumentPath.Item2 is string path) { List filenames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) - .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro")).ToList(); + .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro") || + (Common.Settings.Default.NszExtension && (filename.ToLower().EndsWith(".xcz") || filename.ToLower().EndsWith(".nsz")))).ToList(); filenames.Sort(); Process.log?.WriteLine("{0} files selected", filenames.Count); diff --git a/cli/Program.cs b/cli/Program.cs index a08fe4f..4c78bff 100644 --- a/cli/Program.cs +++ b/cli/Program.cs @@ -39,6 +39,7 @@ static void Main(string[] args) { "c|sdcard", "open path as sdcard", v => sdcard = v != null }, { "s|sort=", "sort by titleid, titlename or filename [default: filename]", (string s) => sort = s }, { "h|help", "show this help message and exit", v => printHelp(options) }, + { "z|nsz", "enable nsz extension", v => Common.Settings.Default.NszExtension = v != null, true }, { "d|debug", "enable debug log", v => Common.Settings.Default.DebugLog = v != null }, }; @@ -101,7 +102,7 @@ static void processPaths(List paths, string sort, bool sdcard) titles.AddRange(openDirectory(path)); } } - else if (File.Exists(path) && new string[] { ".xci", ".nsp", ".nro" }.Any(ext => ext.Equals(Path.GetExtension(path).ToLower())) && !sdcard) + else if (File.Exists(path) && (Common.Settings.Default.NszExtension ? new string[] { ".xci", ".nsp", ".xcz", ".nsz", ".nro" } : new string[] { ".xci", ".nsp", ".nro" }).Any(ext => ext.Equals(Path.GetExtension(path).ToLower())) && !sdcard) { Title title = openFile(path); if (title != null) @@ -205,7 +206,8 @@ static List openDirectory(string path) Process.log?.WriteLine("\nOpen Directory"); List<string> filenames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) - .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro")).ToList(); + .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro") || + (Common.Settings.Default.NszExtension && (filename.ToLower().EndsWith(".xcz") || filename.ToLower().EndsWith(".nsz")))).ToList(); filenames.Sort(); Process.log?.WriteLine("{0} files selected", filenames.Count); diff --git a/macOS/MainWindowController.cs b/macOS/MainWindowController.cs index 8fae58c..539d63e 100644 --- a/macOS/MainWindowController.cs +++ b/macOS/MainWindowController.cs @@ -154,7 +154,7 @@ public void OpenFile(NSMenuItem menuItem) openPanel.CanChooseFiles = true; openPanel.CanChooseDirectories = false; openPanel.AllowsMultipleSelection = true; - openPanel.AllowedFileTypes = new string[] { "xci", "nsp", "nro" }; + openPanel.AllowedFileTypes = Common.Settings.Default.NszExtension ? new string[] { "xci", "nsp", "xcz", "nsz", "nro" } : new string[] { "xci", "nsp", "nro" }; openPanel.DirectoryUrl = NSUrl.FromFilename(!String.IsNullOrEmpty(Common.Settings.Default.InitialDirectory) && Directory.Exists(Common.Settings.Default.InitialDirectory) ? Common.Settings.Default.InitialDirectory : Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); openPanel.Title = "Open NX Game Files"; @@ -688,7 +688,8 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) if (argumentPath.Item1 == Worker.Directory && argumentPath.Item2 is string path) { List<string> filenames = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories) - .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro")).ToList(); + .Where(filename => filename.ToLower().EndsWith(".xci") || filename.ToLower().EndsWith(".nsp") || filename.ToLower().EndsWith(".nro") || + (Common.Settings.Default.NszExtension && (filename.ToLower().EndsWith(".xcz") || filename.ToLower().EndsWith(".nsz")))).ToList(); filenames.Sort(); Process.log?.WriteLine("{0} files selected", filenames.Count);