internal static NintendoContentFileSystemInfo GetReplacedNcaInfo(NintendoContentArchiveReader ncaReader, string descFilePath, EntryReplaceRule replaceRule)
        {
            NintendoContentFileSystemInfo commonNcaInfo = ArchiveReconstructionUtils.GetCommonNcaInfo(ncaReader);

            commonNcaInfo.keyAreaEncryptionKeyIndex = ncaReader.GetKeyIndex();
            commonNcaInfo.isProdEncryption          = false;
            if (descFilePath != null)
            {
                NintendoContentAdfReader.RetrieveInfoFromDesc(ref commonNcaInfo, descFilePath);
            }
            else if (replaceRule != null && commonNcaInfo.contentType == (byte)0)
            {
                throw new Exception("Replacing 'Program' content needs desc file.");
            }
            for (int fsIndex = 0; fsIndex < commonNcaInfo.numFsEntries; ++fsIndex)
            {
                string str = string.Format("fs{0}", (object)fsIndex);
                if (replaceRule != null && replaceRule.Path.StartsWith(str))
                {
                    EntryReplaceRule replaceRule1 = replaceRule;
                    replaceRule1.Path = replaceRule1.Path.Substring(str.Length + 1);
                    commonNcaInfo.fsEntries.Add(ArchiveReconstructionUtils.GetFsEntry(ncaReader, fsIndex, replaceRule1));
                }
                else
                {
                    commonNcaInfo.fsEntries.Add(ArchiveReconstructionUtils.GetFsEntry(ncaReader, fsIndex));
                }
            }
            return(commonNcaInfo);
        }
        public NintendoContentFileSystemInfo GetFileSystemInfo()
        {
            NintendoContentFileSystemInfo fileSystemInfo1 = new NintendoContentFileSystemInfo();

            using (StreamReader streamReader = new StreamReader(this.m_adfPath, Encoding.UTF8))
            {
                YamlStream yamlStream = new YamlStream();
                yamlStream.Load((TextReader)streamReader);
                YamlMappingNode  rootNode;
                YamlSequenceNode child1;
                try
                {
                    rootNode = (YamlMappingNode)yamlStream.Documents[0].RootNode;
                    if (((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("formatType")]).Value != "NintendoContent")
                    {
                        throw new ArgumentException();
                    }
                    YamlScalarNode child2 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("contentType")];
                    YamlScalarNode child3 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("keyGeneration")];
                    YamlScalarNode child4 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("programId")];
                    YamlScalarNode child5 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("contentIndex")];
                    child1 = (YamlSequenceNode)rootNode.Children[(YamlNode) new YamlScalarNode("entries")];
                    fileSystemInfo1.contentType   = this.ConvertToContentTypeByte(child2.Value);
                    fileSystemInfo1.keyGeneration = Convert.ToByte(child3.Value);
                    fileSystemInfo1.programId     = Convert.ToUInt64(child4.Value, 16);
                    fileSystemInfo1.contentIndex  = Convert.ToUInt32(child5.Value);
                }
                catch
                {
                    throw new ArgumentException("invalid format .adf file.");
                }
                try
                {
                    YamlScalarNode child2 = (YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("keyAreaEncryptionKeyIndex")];
                    fileSystemInfo1.keyAreaEncryptionKeyIndex = Convert.ToByte(child2.Value);
                }
                catch
                {
                    fileSystemInfo1.keyAreaEncryptionKeyIndex = (byte)0;
                }
                string descFilePath;
                if (fileSystemInfo1.contentType == (byte)0)
                {
                    try
                    {
                        descFilePath = ((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("descFilePath")]).Value;
                    }
                    catch
                    {
                        throw new ArgumentException(".desc file is not specified for program content.");
                    }
                }
                else
                {
                    descFilePath = (string)null;
                }
                byte[] numArray = (byte[])null;
                if (descFilePath != null)
                {
                    numArray = NintendoContentAdfReader.RetrieveInfoFromDesc(ref fileSystemInfo1, descFilePath);
                }
                foreach (YamlMappingNode yamlMappingNode in child1)
                {
                    NintendoContentFileSystemInfo.EntryInfo entryInfo1 = new NintendoContentFileSystemInfo.EntryInfo();
                    string adfPath = (string)null;
                    foreach (KeyValuePair <YamlNode, YamlNode> keyValuePair in yamlMappingNode)
                    {
                        switch (((YamlScalarNode)keyValuePair.Key).Value)
                        {
                        case "encryptionType":
                            entryInfo1.encryptionType = Convert.ToByte(((YamlScalarNode)keyValuePair.Value).Value);
                            continue;

                        case "formatType":
                            entryInfo1.formatType = ((YamlScalarNode)keyValuePair.Value).Value;
                            continue;

                        case "hashType":
                            entryInfo1.hashType = Convert.ToByte(((YamlScalarNode)keyValuePair.Value).Value);
                            continue;

                        case "partitionType":
                            entryInfo1.partitionType  = ((YamlScalarNode)keyValuePair.Value).Value;
                            entryInfo1.partitionIndex = this.GetPartitionIndex(entryInfo1.partitionType);
                            continue;

                        case "path":
                            adfPath = ((YamlScalarNode)keyValuePair.Value).Value;
                            continue;

                        case "type":
                            entryInfo1.type = ((YamlScalarNode)keyValuePair.Value).Value;
                            continue;

                        case "version":
                            entryInfo1.version = Convert.ToUInt16(((YamlScalarNode)keyValuePair.Value).Value);
                            continue;

                        default:
                            throw new ArgumentException("invalid format .adf file. invalid key is specified\n" + yamlMappingNode.ToString());
                        }
                    }
                    if (entryInfo1.type == null || entryInfo1.formatType == null || adfPath == null)
                    {
                        throw new ArgumentException("invalid format .adf file. \"type\" or \"formatType\" is not specified\n" + yamlMappingNode.ToString());
                    }
                    entryInfo1.version        = (ushort)2;
                    entryInfo1.hashType       = NintendoContentArchiveSource.VerifyHashType(fileSystemInfo1, entryInfo1);
                    entryInfo1.encryptionType = NintendoContentArchiveSource.VerifyEncryptionType(fileSystemInfo1, entryInfo1);
                    string formatType = entryInfo1.formatType;
                    if (!(formatType == "PartitionFs"))
                    {
                        if (!(formatType == "RomFs"))
                        {
                            throw new NotImplementedException("invalid format .adf file. invalid formatType." + yamlMappingNode.ToString());
                        }
                        RomFsAdfReader romFsAdfReader = new RomFsAdfReader(adfPath);
                        entryInfo1.fileSystemInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)romFsAdfReader.GetFileSystemInfo();
                    }
                    else
                    {
                        PartitionFileSystemInfo fileSystemInfo2 = new PartitionFsAdfReader(adfPath).GetFileSystemInfo();
                        if (numArray != null && entryInfo1.partitionType == "code")
                        {
                            IEnumerable <PartitionFileSystemInfo.EntryInfo> source = fileSystemInfo2.entries.Where <PartitionFileSystemInfo.EntryInfo>((Func <PartitionFileSystemInfo.EntryInfo, bool>)(p => p.name == "main.npdm"));
                            if (fileSystemInfo1.contentType == (byte)0 && source.Count <PartitionFileSystemInfo.EntryInfo>() != 1)
                            {
                                throw new ArgumentException("\"main.npdm\" must be included in the code region.");
                            }
                            foreach (PartitionFileSystemInfo.EntryInfo entryInfo2 in source)
                            {
                                if (!((IEnumerable <byte>) this.ReadAcid(entryInfo2.path)).SequenceEqual <byte>((IEnumerable <byte>)numArray))
                                {
                                    throw new ArgumentException(".desc file specified differ from the one used to build code.");
                                }
                            }
                        }
                        entryInfo1.fileSystemInfo = (Nintendo.Authoring.FileSystemMetaLibrary.FileSystemInfo)fileSystemInfo2;
                    }
                    fileSystemInfo1.fsEntries.Add(entryInfo1);
                }
            }
            fileSystemInfo1.numFsEntries     = fileSystemInfo1.fsEntries.Count;
            fileSystemInfo1.isProdEncryption = false;
            return(fileSystemInfo1);
        }