コード例 #1
0
 public NewFileEventArgs(RARFileInfo fileInfo)
 {
     FileInfo = fileInfo;
 }
コード例 #2
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 (_archiveHandle == IntPtr.Zero)
            {
                throw new IOException("Archive is not open.");
            }

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

            // Read next entry
            _currentFile = null;
            int result = RARReadHeaderEx(_archiveHandle, ref _header);

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

            // Determine if new file
            if (((_header.Flags & 0x01) != 0) && _currentFile != null)
            {
                _currentFile.ContinuedFromPrevious = true;
            }
            else
            {
                // New file, prepare header
                _currentFile          = new RARFileInfo();
                _currentFile.FileName = _header.FileNameW;
                if ((_header.Flags & 0x02) != 0)
                {
                    _currentFile.ContinuedOnNext = true;
                }
                if (_header.PackSizeHigh != 0)
                {
                    _currentFile.PackedSize = (_header.PackSizeHigh * 0x100000000) + _header.PackSize;
                }
                else
                {
                    _currentFile.PackedSize = _header.PackSize;
                }
                if (_header.UnpSizeHigh != 0)
                {
                    _currentFile.UnpackedSize = (_header.UnpSizeHigh * 0x100000000) + _header.UnpSize;
                }
                else
                {
                    _currentFile.UnpackedSize = _header.UnpSize;
                }
                _currentFile.HostOS          = (int)_header.HostOS;
                _currentFile.FileCRC         = _header.FileCRC;
                _currentFile.FileTime        = FromMSDOSTime(_header.FileTime);
                _currentFile.VersionToUnpack = (int)_header.UnpVer;
                _currentFile.Method          = (int)_header.Method;
                _currentFile.FileAttributes  = (int)_header.FileAttr;
                _currentFile.BytesExtracted  = 0;
                if ((_header.Flags & 0xE0) == 0xE0)
                {
                    _currentFile.IsDirectory = true;
                }
                OnNewFile();
            }

            // Return success
            return(true);
        }