Beispiel #1
0
        private void OpenAllNcas()
        {
            // Todo: give warning if directories named "*.nca" are found or manually fix the archive bit
            IEnumerable <DirectoryEntry> files = ContentFs.OpenDirectory("/", OpenDirectoryMode.All)
                                                 .EnumerateEntries("*.nca", SearchOptions.RecurseSubdirectories)
                                                 .Where(x => x.Type == DirectoryEntryType.File);

            foreach (DirectoryEntry fileEntry in files)
            {
                SwitchFsNca nca = null;
                try
                {
                    IStorage storage = ContentFs.OpenFile(fileEntry.FullPath, OpenMode.Read).AsStorage();

                    nca = new SwitchFsNca(new Nca(Keyset, storage));

                    nca.NcaId = Path.GetFileNameWithoutExtension(fileEntry.Name);
                    string extension = nca.Nca.Header.ContentType == ContentType.Meta ? ".cnmt.nca" : ".nca";
                    nca.Filename = nca.NcaId + extension;
                }
                catch (MissingKeyException ex)
                {
                    if (ex.Name == null)
                    {
                        Console.WriteLine($"{ex.Message} File:\n{fileEntry}");
                    }
                    else
                    {
                        string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
                        Console.WriteLine($"{ex.Message}\nKey: {name}\nFile: {fileEntry}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message} File: {fileEntry.FullPath}");
                }

                if (nca?.NcaId != null)
                {
                    Ncas.Add(nca.NcaId, nca);
                }
            }
        }
Beispiel #2
0
        private void OpenAllNcas()
        {
            string[] files = Fs.GetFileSystemEntries(ContentsDir, "*.nca", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                Nca nca = null;
                try
                {
                    bool     isNax0;
                    IStorage storage = OpenSplitNcaStream(Fs, file);
                    if (storage == null)
                    {
                        continue;
                    }

                    using (var reader = new BinaryReader(storage.AsStream(), Encoding.Default, true))
                    {
                        reader.BaseStream.Position = 0x20;
                        isNax0 = reader.ReadUInt32() == 0x3058414E; // NAX0
                        reader.BaseStream.Position = 0;
                    }

                    if (isNax0)
                    {
                        string sdPath = "/" + Util.GetRelativePath(file, ContentsDir).Replace('\\', '/');
                        var    nax0   = new Nax0(Keyset, storage, sdPath, false);
                        nca = new Nca(Keyset, nax0.BaseStorage, false);
                    }
                    else
                    {
                        nca = new Nca(Keyset, storage, false);
                    }

                    nca.NcaId = Path.GetFileNameWithoutExtension(file);
                    string extension = nca.Header.ContentType == ContentType.Meta ? ".cnmt.nca" : ".nca";
                    nca.Filename = nca.NcaId + extension;
                }
                catch (MissingKeyException ex)
                {
                    if (ex.Name == null)
                    {
                        Console.WriteLine($"{ex.Message} File:\n{file}");
                    }
                    else
                    {
                        string name = ex.Type == KeyType.Title ? $"Title key for rights ID {ex.Name}" : ex.Name;
                        Console.WriteLine($"{ex.Message}\nKey: {name}\nFile: {file}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message} File: {file}");
                }

                if (nca?.NcaId != null)
                {
                    Ncas.Add(nca.NcaId, nca);
                }
            }
        }