BitMiracle.LibTiff.Classic.Tiff.RewriteDirectory C# (CSharp) Method

RewriteDirectory() public method

Rewrites the contents of the current directory to the file and setup to create a new subfile (page) in the same file.
The RewriteDirectory operates similarly to WriteDirectory, but can be called with directories previously read or written that already have an established location in the file. It will rewrite the directory, but instead of place it at it's old location (as WriteDirectory would) it will place them at the end of the file, correcting the pointer from the preceeding directory or file header to point to it's new location. This is particularly important in cases where the size of the directory and pointed to data has grown, so it won’t fit in the space available at the old location. Note that this will result in the loss of the previously used directory space.
public RewriteDirectory ( ) : bool
return bool
        public bool RewriteDirectory()
        {
            const string module = "RewriteDirectory";

            // We don't need to do anything special if it hasn't been written.
            if (m_diroff == 0)
                return WriteDirectory();

            // Find and zero the pointer to this directory, so that linkDirectory will cause it to
            // be added after this directories current pre-link.

            // Is it the first directory in the file?
            if (m_header.tiff_diroff == m_diroff)
            {
                m_header.tiff_diroff = 0;
                m_diroff = 0;

                seekFile(TiffHeader.TIFF_MAGIC_SIZE + TiffHeader.TIFF_VERSION_SIZE, SeekOrigin.Begin);
                if (!writeIntOK((int)m_header.tiff_diroff))
                {
                    ErrorExt(this, m_clientdata, m_name, "Error updating TIFF header");
                    return false;
                }
            }
            else
            {
                uint nextdir = m_header.tiff_diroff;
                do
                {
                    short dircount;
                    if (!seekOK(nextdir) || !readShortOK(out dircount))
                    {
                        ErrorExt(this, m_clientdata, module, "Error fetching directory count");
                        return false;
                    }

                    if ((m_flags & TiffFlags.SWAB) == TiffFlags.SWAB)
                        SwabShort(ref dircount);

                    seekFile(dircount * TiffDirEntry.SizeInBytes, SeekOrigin.Current);

                    if (!readUIntOK(out nextdir))
                    {
                        ErrorExt(this, m_clientdata, module, "Error fetching directory link");
                        return false;
                    }

                    if ((m_flags & TiffFlags.SWAB) == TiffFlags.SWAB)
                        SwabUInt(ref nextdir);
                }
                while (nextdir != m_diroff && nextdir != 0);

                // get current offset
                long off = seekFile(0, SeekOrigin.Current);
                seekFile(off - sizeof(int), SeekOrigin.Begin);
                m_diroff = 0;

                if (!writeIntOK((int)m_diroff))
                {
                    ErrorExt(this, m_clientdata, module, "Error writing directory link");
                    return false;
                }
            }

            // Now use WriteDirectory() normally.
            return WriteDirectory();
        }
Tiff