Exemplo n.º 1
0
        /// <summary>
        /// Reads the next archive header and populates CurrentFile property data
        /// </summary>
        /// <returns></returns>
        public bool ReadHeader()
        {
            // Throw exception if archive not open
            if (this.archiveHandle == IntPtr.Zero)
            {
                throw new IOException("Archive is not open.");
            }

            // Initialize header struct
            this.header = new RARHeaderDataEx();
            header.Initialize();

            // Read next entry
            int result = Unrar.RARReadHeaderEx(this.archiveHandle, ref this.header);

            // Check for error or end of archive
            if ((RarError)result == RarError.EndOfArchive)
            {
                return(false);
            }
            else if ((RarError)result == RarError.BadData)
            {
                throw new IOException("Archive data is corrupt.");
            }

            // New file, prepare header
            currentFile          = new RARFileInfo();
            currentFile.FileName = header.FileNameW.ToString();

            if ((header.Flags & 0xE0) == 0xE0)
            {
                currentFile.IsDirectory = true;
            }

            // Return success
            return(true);
        }
        /// <summary>
        /// Reads the next archive header and populates CurrentFile property data
        /// </summary>
        /// <returns></returns>
        public bool ReadHeader()
        {
            // Throw exception if archive not open
            if (this.archiveHandle == IntPtr.Zero)
                throw new IOException("Archive is not open.");

            // Initialize header struct
            this.header = new RARHeaderDataEx();
            header.Initialize();

            // Read next entry
            int result = Unrar.RARReadHeaderEx(this.archiveHandle, ref this.header);

            // Check for error or end of archive
            if ((RarError)result == RarError.EndOfArchive)
                return false;
            else if ((RarError)result == RarError.BadData)
                throw new IOException("Archive data is corrupt.");

            // New file, prepare header
            currentFile = new RARFileInfo();
            currentFile.FileName = header.FileNameW.ToString();

            if ((header.Flags & 0xE0) == 0xE0)
                currentFile.IsDirectory = true;

            // Return success
            return true;
        }