public static void MatchupBaseNca(this IEnumerable <SwitchFsNca> ncas) { PseudoFileSystem ps = ncas.MakeFs(); SwitchFs fs = SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, ps); foreach (KeyValuePair <ulong, LibHac.Application> kv in fs.Applications) { ulong tid = kv.Key; LibHac.Application app = kv.Value; if (app.Patch != null && app.Main != null) { foreach (SwitchFsNca nca in app.Patch.Ncas) { ContentType type = nca.Nca.Header.ContentType; SwitchFsNca baseNca = app.Main.Ncas.Where(n => n.Nca.Header.ContentType == type).FirstOrDefault(); if (baseNca != null) { bool hasPatch = false; for (int i = 0; i < 4; i++) { Nca n = nca.Nca; if (n.CanOpenSection(i)) { NcaFsHeader section = n.Header.GetFsHeader(i); if (section.IsPatchSection()) { hasPatch = true; break; } } } if (hasPatch) { ncas.Where(n => n.Filename == nca.Filename.Replace("/", "")).First().BaseNca = baseNca.Nca; // set original NCA, not new parsed one } } } } } }
private void ImportGameDataClicked(object sender, RoutedEventArgs e) { string filter = @" Any game data (*.xci,*.nca,*.nsp)|*.xci;*.nca;*.nsp| NX Card Image (*.xci)|*.xci| Nintendo Content Archive (*.nca)|*.nca| Nintendo Installable Package (*.nsp)|*.nsp ".FilterMultilineString(); FileInfo[] files = RequestOpenFilesFromUser(".*", filter, "Select game data..."); if (files == null) { return; } TaskManagerPage.Current.Queue.Submit(new RunTask("Processing imported game data...", new Task(() => { IEnumerable <FileInfo> ncas = files.Where((f) => { try { new Nca(HACGUIKeyset.Keyset, new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); IEnumerable <FileInfo> xcis = files.Except(ncas).Where((f) => { try { new Xci(HACGUIKeyset.Keyset, new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); IEnumerable <FileInfo> nsp = files.Except(ncas).Except(xcis).Where((f) => { try { new PartitionFileSystem(new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); List <SwitchFs> switchFilesystems = new List <SwitchFs>(); PseudoFileSystem ncaFs = new PseudoFileSystem(); foreach (FileInfo file in ncas) { LocalFileSystem fs = new LocalFileSystem(file.Directory.FullName); // clean up filename so it only ends with .nca, then map to actual name string s = file.Name; while (s.EndsWith(".nca")) { s = s.Substring(0, s.IndexOf(".nca")); } ncaFs.Add($"/{s}.nca", $"/{file.Name}", fs); } if (ncas.Any()) { switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, ncaFs)); } foreach (FileInfo file in xcis) { Xci xci = new Xci(HACGUIKeyset.Keyset, new LocalFile(file.FullName, OpenMode.Read).AsStorage()); switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, xci.OpenPartition(XciPartitionType.Secure))); } foreach (FileInfo file in nsp) { PartitionFileSystem fs = new PartitionFileSystem(new LocalFile(file.FullName, OpenMode.Read).AsStorage()); switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, fs)); } foreach (SwitchFs fs in switchFilesystems) { DeviceService.FsView.LoadFileSystemAsync("Opening imported data...", () => fs, FSView.TitleSource.Imported, false); } }))); }