private static void GetFsInfo(IFileSystemArchiveReader fsReader, EntryReplaceRule replaceRule, ArchiveReconstructionUtils.AddEntryToFsInfo addEntryDelegate)
        {
            ArchiveReconstructionUtils.BasicFileInfo basicFileInfo1 = new ArchiveReconstructionUtils.BasicFileInfo(fsReader.ListFileInfo().Find((Predicate <Tuple <string, long> >)(x => x.Item1 == replaceRule.Path)), fsReader);
            long num = replaceRule.Source.Size - basicFileInfo1.Size;
            List <ArchiveReconstructionUtils.BasicFileInfo> basicFileInfoList = new List <ArchiveReconstructionUtils.BasicFileInfo>();

            foreach (Tuple <string, long> fileInfo in fsReader.ListFileInfo())
            {
                ArchiveReconstructionUtils.BasicFileInfo basicFileInfo2 = new ArchiveReconstructionUtils.BasicFileInfo(fileInfo, fsReader);
                if (basicFileInfo2.Offset > basicFileInfo1.Offset)
                {
                    basicFileInfo2.Offset += num;
                }
                if (basicFileInfo2.Name == replaceRule.Path)
                {
                    basicFileInfo2.Size   = replaceRule.Source.Size;
                    basicFileInfo2.Source = (SourceInterface) new CliCompatibleSource(replaceRule.Source);
                }
                else
                {
                    basicFileInfo2.Source = (SourceInterface) new CliCompatibleSource((ISource) new FileSystemArchvieFileSource(fsReader, basicFileInfo2.Name));
                }
                basicFileInfoList.Add(basicFileInfo2);
            }
            addEntryDelegate((IEnumerable <ArchiveReconstructionUtils.BasicFileInfo>)basicFileInfoList);
        }
        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);
        }
        private static RomFsFileSystemInfo GetRomFsInfo(IFileSystemArchiveReader fsReader, EntryReplaceRule replaceRule)
        {
            RomFsFileSystemInfo fsInfo      = new RomFsFileSystemInfo();
            DirectoryList       directories = new DirectoryList();

            ArchiveReconstructionUtils.AddEntryToFsInfo addEntryDelegate = (ArchiveReconstructionUtils.AddEntryToFsInfo)(fileInfoList =>
            {
                foreach (ArchiveReconstructionUtils.BasicFileInfo fileInfo in fileInfoList)
                {
                    RomFsFileSystemInfo.EntryInfo entryInfo = new RomFsFileSystemInfo.EntryInfo();
                    entryInfo.type            = "source";
                    entryInfo.name            = "/" + fileInfo.Name;
                    entryInfo.size            = (ulong)fileInfo.Size;
                    entryInfo.offset          = (ulong)fileInfo.Offset;
                    entryInfo.path            = (string)null;
                    entryInfo.sourceInterface = fileInfo.Source;
                    fsInfo.entries.Add(entryInfo);
                    ++fsInfo.fileEntryCount;
                    directories.AddAncestors(Path.GetDirectoryName(entryInfo.name));
                }
            });
            ArchiveReconstructionUtils.GetFsInfo(fsReader, replaceRule, addEntryDelegate);
            fsInfo.directoryEntryCount = directories.Count;
            return(fsInfo);
        }
        private static PartitionFileSystemInfo GetPartitionFsInfo(IFileSystemArchiveReader fsReader, EntryReplaceRule replaceRule)
        {
            PartitionFileSystemInfo fsInfo = new PartitionFileSystemInfo();

            ArchiveReconstructionUtils.AddEntryToFsInfo addEntryDelegate = (ArchiveReconstructionUtils.AddEntryToFsInfo)(fileInfoList =>
            {
                foreach (ArchiveReconstructionUtils.BasicFileInfo fileInfo in fileInfoList)
                {
                    fsInfo.entries.Add(new PartitionFileSystemInfo.EntryInfo()
                    {
                        type            = "source",
                        name            = fileInfo.Name,
                        size            = (ulong)fileInfo.Size,
                        offset          = (ulong)fileInfo.Offset,
                        path            = (string)null,
                        sourceInterface = fileInfo.Source
                    });
                }
            });
            ArchiveReconstructionUtils.GetFsInfo(fsReader, replaceRule, addEntryDelegate);
            return(fsInfo);
        }
        private static NintendoContentFileSystemInfo.EntryInfo GetFsEntry(NintendoContentArchiveReader ncaReader, int fsIndex, EntryReplaceRule replaceRule)
        {
            NintendoContentArchiveFsHeaderInfo fsInfo = (NintendoContentArchiveFsHeaderInfo)null;
            IFileSystemArchiveReader           systemArchiveReader = ncaReader.OpenFileSystemArchiveReader(fsIndex, ref fsInfo);

            NintendoContentFileSystemInfo.EntryInfo commonFsEntry = ArchiveReconstructionUtils.GetCommonFsEntry(fsInfo, fsIndex);
            Tuple <long, long> tuple = systemArchiveReader.GetFileFragmentList(replaceRule.Path).First <Tuple <long, long> >();
            long offset = tuple.Item1;

            if (tuple.Item2 == replaceRule.Source.Size)
            {
                AdaptedSource adaptedSource = new AdaptedSource((ISource) new FileSystemArchvieBaseSource(systemArchiveReader), replaceRule.Source, offset, replaceRule.Source.Size);
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)adaptedSource);
            }
            else if (commonFsEntry.formatType == "RomFs")
            {
                RomFsArchiveSource romFsArchiveSource = new RomFsArchiveSource(ArchiveReconstructionUtils.GetRomFsInfo(systemArchiveReader, replaceRule));
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)romFsArchiveSource);
            }
            else if (commonFsEntry.formatType == "PartitionFs")
            {
                PartitionFsArchiveSource partitionFsArchiveSource = new PartitionFsArchiveSource(ArchiveReconstructionUtils.GetPartitionFsInfo(systemArchiveReader, replaceRule));
                commonFsEntry.sourceInterface = (SourceInterface) new CliCompatibleSource((ISource)partitionFsArchiveSource);
            }
            return(commonFsEntry);
        }