public void ReadFileNodeListHeader(ref FileNodeListHeader fileNodeListHeader)
        {
            if (!Unsafe.ReadStruct(binaryReader, ref fileNodeListHeader))
            {
                throw new FileFormatException("Cannot read header of FileNodeListFragment");
            }

            if (fileNodeListHeader.uintMagic != FileNodeListFragmentHeaderMagic)
            {
                throw new FileFormatException("Header of FileNodeListFragment is corrupted");
            }
        }
Esempio n. 2
0
        public void ReadFileNodeListFragment(IFileChunkReference fileChunkReference, ICollection <FNDBase> result, ref FileChunkReference64x32 nextFragment, Dictionary <uint, uint> transactionsData, params uint[] fileNodeIds)
        {
            oneNoteFileReader.Move(fileChunkReference.Offset, "FileNodeListFragment");

            var jumpSizeToNextFragmentReference = GetJumpSizeToNextFragmentReference(fileChunkReference.DataSize);

            var fileNodeListHeader = new FileNodeListHeader();

            oneNoteFileReader.ReadFileNodeListHeader(ref fileNodeListHeader);
            jumpSizeToNextFragmentReference -= FileNodeListHeader.SizeInBytes;

            var fileNodeListId = fileNodeListHeader.FileNodeListID;
            var nodesCount     = transactionsData[fileNodeListId];
            var fileNodeHeader = new FileNodeHeader();

            while (true)
            {
                if (nodesCount == 0)
                {
                    break;
                }

                oneNoteFileReader.ReadFileNodeHeader(ref fileNodeHeader);
                jumpSizeToNextFragmentReference -= FileNodeHeader.SizeInBytes;

                var fileNodeId = fileNodeHeader.FileNodeID;
                if (fileNodeId == FileNodeIDs.ChunkTerminatorFND)
                {
                    break;
                }

                var sizeOfData = fileNodeHeader.Size - FileNodeHeader.SizeInBytes;
                var skip       = true;

                if (fileNodeIds.Length == 0 || Array.IndexOf(fileNodeIds, fileNodeId) >= 0)
                {
                    var readFileNodeData = ReadFileNodeData(fileNodeHeader);
                    if (readFileNodeData == null)
                    {
                        readFileNodeData = new NotImplementedFND(fileNodeHeader);
                    }
                    else
                    {
                        skip = false;
                    }

                    result.Add(readFileNodeData);
                    jumpSizeToNextFragmentReference -= sizeOfData;
                }

                if (skip && sizeOfData != 0)
                {
                    oneNoteFileReader.Skip(sizeOfData);
                    jumpSizeToNextFragmentReference -= sizeOfData;
                }

                nodesCount--;

                const uint minJumpSize = 4;
                if (jumpSizeToNextFragmentReference < minJumpSize)
                {
                    break;
                }
            }

            if (jumpSizeToNextFragmentReference != 0)
            {
                oneNoteFileReader.Skip(jumpSizeToNextFragmentReference);
            }

            oneNoteFileReader.ReadFileChunkReference64x32(ref nextFragment, "FileNodeListFragment.nextFragment");
            oneNoteFileReader.ExpectFileNodeListFooter();

            transactionsData[fileNodeListId] = nodesCount;
        }