Ejemplo n.º 1
0
 private ArchiveFileInfo GetArchiveFileInfo(SevenZibSharp.ArchiveFileInfo entry, SevenZibSharp.SevenZipExtractor archiveFile)
 {
     using (var entryStream = new MemoryStream())
     {
         archiveFile.ExtractFile(entry.FileName, entryStream);
         var retVal = new ArchiveFileInfo
         {
             FileName = entry.FileName,
             Content  = entryStream.ToArray()
         };
         entryStream.Close();
         return(retVal);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines whether the specified ArchiveFileInfo is equal to the current ArchiveFileInfo.
 /// </summary>
 /// <param name="afi">The ArchiveFileInfo to compare with the current ArchiveFileInfo.</param>
 /// <returns>true if the specified ArchiveFileInfo is equal to the current ArchiveFileInfo; otherwise, false.</returns>
 public bool Equals(ArchiveFileInfo afi)
 {
     return(afi.Index == Index && afi.FileName == FileName);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtractFileCallbackArgs"/> class.
 /// </summary>
 /// <param name="archiveFileInfo">The information about file in the archive.</param>
 public ExtractFileCallbackArgs(ArchiveFileInfo archiveFileInfo)
 {
     Reason           = ExtractFileCallbackReason.Start;
     _archiveFileInfo = archiveFileInfo;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the FileInfoEventArgs class.
 /// </summary>
 /// <param name="fileInfo">The current ArchiveFileInfo.</param>
 /// <param name="percentDone">The percent of finished work.</param>
 public FileInfoEventArgs(ArchiveFileInfo fileInfo, byte percentDone)
     : base(percentDone)
 {
     _fileInfo = fileInfo;
 }
        /// <summary>
        /// Retrieves all information about the archive.
        /// </summary>
        /// <exception cref="SevenZip.SevenZipArchiveException"/>
        private void GetArchiveInfo(bool disposeStream)
        {
            if (_archive == null)
            {
                if (!ThrowException(null, new SevenZipArchiveException()))
                {
                    return;
                }
            }
            else
            {
                IInStream archiveStream;
                using ((archiveStream = GetArchiveStream(disposeStream)) as IDisposable)
                {
                    var 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, "");
                                    _archive.GetProperty(i, ItemPropId.Method, ref data);
                                    fileInfo.Method = 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++)
                            {
                                _archive.GetArchivePropertyInfo(i, out string propName, out var propId, out var varType);
                                _archive.GetArchiveProperty(propId, ref data);

                                if (propId == ItemPropId.Solid)
                                {
                                    _isSolid = NativeMethods.SafeCast(data, true);
                                }

                                // TODO Add more archive properties
                                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);
            }
        }