示例#1
0
        /// <inheritdoc/>
        protected override void ExtractArchive()
        {
            try
            {
                // Read ZIP file sequentially and reference central directory in parallel
                foreach (var centralEntry in _centralDirectory)
                {
                    var localEntry = _zipStream.GetNextEntry();
                    if (localEntry == null)
                    {
                        break;
                    }

                    string?relativePath = GetRelativePath(centralEntry.Name);
                    if (string.IsNullOrEmpty(relativePath))
                    {
                        continue;
                    }

                    if (centralEntry.IsDirectory)
                    {
                        DirectoryBuilder.CreateDirectory(relativePath, localEntry.DateTime);
                    }
                    else if (centralEntry.IsFile)
                    {
                        if (IsSymlink(centralEntry))
                        {
                            DirectoryBuilder.CreateSymlink(relativePath, _zipStream.ReadToString());
                        }
                        else
                        {
                            WriteFile(relativePath, centralEntry.Size, localEntry.DateTime, _zipStream, IsExecutable(centralEntry));
                        }
                    }

                    UnitsProcessed += centralEntry.CompressedSize;
                }
            }
            #region Error handling
            catch (SharpZipBaseException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            catch (InvalidDataException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            #endregion
        }
示例#2
0
        /// <inheritdoc/>
        protected override void ExtractArchive()
        {
            try
            {
                TarEntry entry;
                while ((entry = _tarStream.GetNextEntry()) != null)
                {
                    string?relativePath = GetRelativePath(entry.Name);
                    if (string.IsNullOrEmpty(relativePath))
                    {
                        continue;
                    }

                    switch (entry.TarHeader.TypeFlag)
                    {
                    case TarHeader.LF_DIR:
                        DirectoryBuilder.CreateDirectory(relativePath, entry.TarHeader.ModTime);
                        break;

                    case TarHeader.LF_LINK:
                    {
                        string?targetPath = GetRelativePath(entry.TarHeader.LinkName);
                        if (string.IsNullOrEmpty(targetPath))
                        {
                            throw new IOException(string.Format(Resources.HardlinkTargetMissing, relativePath, entry.TarHeader.LinkName));
                        }
                        DirectoryBuilder.QueueHardlink(relativePath, targetPath, IsExecutable(entry));
                        break;
                    }

                    case TarHeader.LF_SYMLINK:
                        DirectoryBuilder.CreateSymlink(relativePath, entry.TarHeader.LinkName);
                        break;

                    default:
                        WriteFile(relativePath, entry.Size, entry.TarHeader.ModTime, _tarStream, IsExecutable(entry));
                        break;
                    }

                    UpdateProgress();
                }
            }
            #region Error handling
            catch (SharpZipBaseException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            catch (Exception ex) when(ex.Message == "Data Error")  // SharpCompress DataError
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid);
            }
            catch (InvalidDataException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Wrap exception since only certain exception types are allowed
                throw new IOException(Resources.ArchiveInvalid, ex);
            }
            #endregion
        }