SevenZip/SevenZipExtractor.cs
/// <summary>
///   Retrieves all information about the archive.
/// </summary>
/// <exception cref = "SevenZip.SevenZipArchiveException" />
Retrieves all information about the archive.
Retrieves all information about the archive .
private void GetArchiveInfo(bool disposeStream)
        {
            if (_archive == null)
            {
                if (!ThrowException(null, new SevenZipArchiveException()))
                {
                    return;
                }
            }
            else
            {
                IInStream archiveStream;
                using ((archiveStream = GetArchiveStream(disposeStream)) as IDisposable)
                {
                    ArchiveOpenCallback openCallback = GetArchiveOpenCallback();
                    if (!_opened)
                    {
                        if (!OpenArchive(archiveStream, openCallback))
                        {
                            return;
                        }
                        _opened = !disposeStream;
                    }
                    _filesCount = _archive.GetNumberOfItems();
                    _archiveFileData = new List<ArchiveFileInfo>((int) _filesCount);
                    if (_filesCount != 0)
                    {
                        var data = new PropVariant();
                        try
                        {
                            #region Getting archive items data
                            for (uint i = 0; i < _filesCount; i++)
                            {
                                try
                                {
                                    var fileInfo = new ArchiveFileInfo {Index = (int) i};
                                    _archive.GetProperty(i, ItemPropId.Path, ref data);
                                    fileInfo.FileName = NativeMethods.SafeCast(data, "[no name]");
                                    _archive.GetProperty(i, ItemPropId.LastWriteTime, ref data);
                                    fileInfo.LastWriteTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.CreationTime, ref data);
                                    fileInfo.CreationTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.LastAccessTime, ref data);
                                    fileInfo.LastAccessTime = NativeMethods.SafeCast(data, DateTime.Now);
                                    _archive.GetProperty(i, ItemPropId.Size, ref data);
                                    fileInfo.Size = NativeMethods.SafeCast<ulong>(data, 0);
                                    if (fileInfo.Size == 0)
                                    {
                                        fileInfo.Size = NativeMethods.SafeCast<uint>(data, 0);
                                    }
                                    _archive.GetProperty(i, ItemPropId.Attributes, ref data);
                                    fileInfo.Attributes = NativeMethods.SafeCast<uint>(data, 0);
                                    _archive.GetProperty(i, ItemPropId.IsDirectory, ref data);
                                    fileInfo.IsDirectory = NativeMethods.SafeCast(data, false);
                                    _archive.GetProperty(i, ItemPropId.Encrypted, ref data);
                                    fileInfo.Encrypted = NativeMethods.SafeCast(data, false);
                                    _archive.GetProperty(i, ItemPropId.Crc, ref data);
                                    fileInfo.Crc = NativeMethods.SafeCast<uint>(data, 0);
                                    _archive.GetProperty(i, ItemPropId.Comment, ref data);
                                    fileInfo.Comment = NativeMethods.SafeCast(data, "");
                                    _archiveFileData.Add(fileInfo);
                                }
                                catch (InvalidCastException)
                                {
                                    ThrowException(null, new SevenZipArchiveException("probably archive is corrupted."));
                                }
                            }
                            #endregion
                            #region Getting archive properties
                            uint numProps = _archive.GetNumberOfArchiveProperties();
                            var archProps = new List<ArchiveProperty>((int) numProps);
                            for (uint i = 0; i < numProps; i++)
                            {
                                string propName;
                                ItemPropId propId;
                                ushort varType;
                                _archive.GetArchivePropertyInfo(i, out propName, out propId, out varType);
                                _archive.GetArchiveProperty(propId, ref data);
                                if (propId == ItemPropId.Solid)
                                {
                                    _isSolid = NativeMethods.SafeCast(data, true);
                                }
                                if (PropIdToName.PropIdNames.ContainsKey(propId))
                                {
                                    archProps.Add(new ArchiveProperty
                                                      {
                                                          Name = PropIdToName.PropIdNames[propId],
                                                          Value = data.Object
                                                      });
                                }
                                else
                                {
                                    Debug.WriteLine(
                                        "An unknown archive property encountered (code " +
                                        ((int) propId).ToString(CultureInfo.InvariantCulture) + ')');
                                }
                            }
                            _archiveProperties = new ReadOnlyCollection<ArchiveProperty>(archProps);
                            if (!_isSolid.HasValue && _format == InArchiveFormat.Zip)
                            {
                                _isSolid = false;
                            }
                            if (!_isSolid.HasValue)
                            {
                                _isSolid = true;
                            }
                            #endregion
                        }
                        catch (Exception)
                        {
                            if (openCallback.ThrowException())
                            {
                                throw;
                            }
                        }
                    }
                }
                if (disposeStream)
                {
                    _archive.Close();
                    _archiveStream = null;
                }
                _archiveFileInfoCollection = new ReadOnlyCollection<ArchiveFileInfo>(_archiveFileData);
            }
        }
private void GetArchiveInfo ( bool disposeStream ) { if ( _archive == null ) { if ( ! ThrowException ( null , new SevenZipArchiveException ( ) ) ) { return ; } } else { IInStream archiveStream ; using ( ( archiveStream = GetArchiveStream ( disposeStream ) ) as IDisposable ) { ArchiveOpenCallback openCallback = GetArchiveOpenCallback ( ) ; if ( ! _opened ) { if ( ! OpenArchive ( archiveStream , openCallback ) ) { return ; } _opened = ! disposeStream ; } _filesCount = _archive . GetNumberOfItems ( ) ; _archiveFileData = new List < ArchiveFileInfo > ( ( int ) _filesCount ) ; if ( _filesCount != 0 ) { var data = new PropVariant ( ) ; try { region  Getting archive items data for ( uint i = 0 ; i < _filesCount ; i ++ ) { try { var fileInfo = new ArchiveFileInfo { Index = ( int ) i } ; _archive . GetProperty ( i , ItemPropId . Path , ref data ) ; fileInfo . FileName = NativeMethods . SafeCast ( data , " " ) ; _archive . GetProperty ( i , ItemPropId . LastWriteTime , ref data ) ; fileInfo . LastWriteTime = NativeMethods . SafeCast ( data , DateTime . Now ) ; _archive . GetProperty ( i , ItemPropId . CreationTime , ref data ) ; fileInfo . CreationTime = NativeMethods . SafeCast ( data , DateTime . Now ) ; _archive . GetProperty ( i , ItemPropId . LastAccessTime , ref data ) ; fileInfo . LastAccessTime = NativeMethods . SafeCast ( data , DateTime . Now ) ; _archive . GetProperty ( i , ItemPropId . Size , ref data ) ; fileInfo . Size = NativeMethods . SafeCast < ulong > ( data , 0 ) ; if ( fileInfo . Size == 0 ) { fileInfo . Size = NativeMethods . SafeCast < uint > ( data , 0 ) ; } _archive . GetProperty ( i , ItemPropId . Attributes , ref data ) ; fileInfo . Attributes = NativeMethods . SafeCast < uint > ( data , 0 ) ; _archive . GetProperty ( i , ItemPropId . IsDirectory , ref data ) ; fileInfo . IsDirectory = NativeMethods . SafeCast ( data , false ) ; _archive . GetProperty ( i , ItemPropId . Encrypted , ref data ) ; fileInfo . Encrypted = NativeMethods . SafeCast ( data , false ) ; _archive . GetProperty ( i , ItemPropId . Crc , ref data ) ; fileInfo . Crc = NativeMethods . SafeCast < uint > ( data , 0 ) ; _archive . GetProperty ( i , ItemPropId . Comment , ref data ) ; fileInfo . Comment = NativeMethods . SafeCast ( data , " " ) ; _archiveFileData . Add ( fileInfo ) ; } catch ( InvalidCastException ) { ThrowException ( null , new SevenZipArchiveException ( " " ) ) ; } } endregion region  Getting archive properties uint numProps = _archive . GetNumberOfArchiveProperties ( ) ; var archProps = new List < ArchiveProperty > ( ( int ) numProps ) ; for ( uint i = 0 ; i < numProps ; i ++ ) { string propName ; ItemPropId propId ; ushort varType ; _archive . GetArchivePropertyInfo ( i , out propName , out propId , out varType ) ; _archive . GetArchiveProperty ( propId , ref data ) ; if ( propId == ItemPropId . Solid ) { _isSolid = NativeMethods . SafeCast ( data , true ) ; } if ( PropIdToName . PropIdNames . ContainsKey ( propId ) ) { archProps . Add ( new ArchiveProperty { Name = PropIdToName . PropIdNames [ propId ] , Value = data . Object } ) ; } else { Debug . WriteLine ( " " + ( ( int ) propId ) . ToString ( CultureInfo . InvariantCulture ) + ' ' ) ; } } _archiveProperties = new ReadOnlyCollection < ArchiveProperty > ( archProps ) ; if ( ! _isSolid . HasValue && _format == InArchiveFormat . Zip ) { _isSolid = false ; } if ( ! _isSolid . HasValue ) { _isSolid = true ; } endregion } catch ( Exception ) { if ( openCallback . ThrowException ( ) ) { throw ; } } } } if ( disposeStream ) { _archive . Close ( ) ; _archiveStream = null ; } _archiveFileInfoCollection = new ReadOnlyCollection < ArchiveFileInfo > ( _archiveFileData ) ; } }
Retrieves all information about the archive.
Retrieves all information about the archive .
// TODO Add more archive properties
None
disposeStream
bool