コード例 #1
0
        /// <summary>
        /// Populates directory object with data from given sector of directory
        /// </summary>
        /// <param name="sectorData">The server to process</param>
        /// <param name="directory">The directory object to populate</param>
        /// <returns></returns>
        private void ReadEntries(byte[] sectorData, CompoundFileDirectory directory)
        {
            // each directory entry has size of 128 byte
            var entriesPerSector = sectorSize / 128;

            for (var entryIdx = 0; entryIdx < entriesPerSector; entryIdx++)
            {
                var entryOffset = entryIdx * 128;
                directory.AddEntry(ReadDirEntry(sectorData, entryOffset, directory.EntriesCount));
            }
        }
コード例 #2
0
        private CompoundFileDirectory ReadDirectoryImpl(bool exceptionOnError = true)
        {
            var result = new CompoundFileDirectory();

            result.IsComplete = true;
            var currentSector = firstDirectorySector;

            while (currentSector != endOfSectorChain)
            {
                var sectorData = TryReadSector(currentSector);
                if (sectorData != null)
                {
                    ReadEntries(sectorData, result);
                }
                else
                {
                    isBroken          = true;
                    result.IsComplete = false;
                    if (exceptionOnError)
                    {
                        throw new InvalidOperationException(string.Format("Directory sector {0} can not be read.", currentSector));
                    }
                }
                try
                {
                    currentSector = NextSectorInFatChain(currentSector);
                }
                catch (Exception)
                {
                    isBroken          = true;
                    result.IsComplete = false;
                    if (exceptionOnError)
                    {
                        throw;
                    }
                    currentSector = endOfSectorChain;
                }
            }
            return(result);
        }