public IEnumerable <CompoundFileDirEntry> GetFolder(CompoundFileDirEntry storageEntry)
        {
            var result = new List <CompoundFileDirEntry>();

            if (storageEntry.ObjectType == DirEntryObjectType.StorageObject ||
                storageEntry.ObjectType == DirEntryObjectType.RootStorageObject)
            {
                var treeRootEntry = entries[storageEntry.ChildId];
                TraverseTree(treeRootEntry, result);
            }
            return(result);
        }
        private void TraverseTree(CompoundFileDirEntry entry, List <CompoundFileDirEntry> result)
        {
            var leftSiblingId  = entry.LeftSiblingId;
            var rightSiblingId = entry.RightSiblingId;

            // In case of incomplete directory (partially loaded directory)
            // some referenced entries can be unavailable, so the range check here is important
            if (leftSiblingId >= 0 && leftSiblingId < entries.Count)
            {
                var leftSiblilng = entries[leftSiblingId];
                TraverseTree(leftSiblilng, result);
            }
            result.Add(entry);
            if (rightSiblingId >= 0 && rightSiblingId < entries.Count)
            {
                var rightSiblilng = entries[rightSiblingId];
                TraverseTree(rightSiblilng, result);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves the content of specific entry of compound file
        /// </summary>
        /// <param name="entry">The entry whose content to retrieve</param>
        /// <param name="bytesLimit">Number of bytes to read. If set to null the whole content will be retrieved.</param>
        /// <param name="exceptionOnError">Whether an exception should be thrown in case of broken compound file</param>
        /// <returns></returns>
        public byte[] ReadEntryContent(CompoundFileDirEntry entry, int?bytesLimit = null, bool exceptionOnError = true)
        {
            long size = entry.StreamSize;

            if (bytesLimit.HasValue && bytesLimit < size)
            {
                size = bytesLimit.Value;
            }
            var result        = new byte[size];
            var offset        = 0;
            var remaining     = result.Length;
            var currentSector = entry.StartSector;

            if (entry.StreamSize < miniStreamCutoffSize)
            {
                while (remaining > 0 && currentSector != endOfSectorChain)
                {
                    var content = exceptionOnError ? ReadMiniSector(currentSector) : TryReadMiniSector(currentSector);
                    content = content ?? new byte[sectorSize];
                    var dataLength = content.Length < remaining ? content.Length : remaining;
                    Array.Copy(content, 0, result, offset, dataLength);
                    offset       += dataLength;
                    remaining    -= dataLength;
                    currentSector = NextSectorInMiniFatChain(currentSector, exceptionOnError);
                }
            }
            else
            {
                while (remaining > 0 && currentSector != endOfSectorChain)
                {
                    var content = exceptionOnError ? ReadSector(currentSector) : TryReadSector(currentSector);
                    content = content ?? new byte[sectorSize];
                    var dataLength = content.Length < remaining ? content.Length : remaining;
                    Array.Copy(content, 0, result, offset, dataLength);
                    offset       += dataLength;
                    remaining    -= dataLength;
                    currentSector = NextSectorInFatChain(currentSector, exceptionOnError);
                }
            }
            return(result);
        }
 public void AddEntry(CompoundFileDirEntry entry)
 {
     entries.Add(entry);
 }