Example #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
        }
Example #2
0
        /// <inheritdoc/>
        protected override void Execute()
        {
            State = TaskState.Data;

            try
            {
                if (!Directory.Exists(EffectiveTargetDir))
                {
                    Directory.CreateDirectory(EffectiveTargetDir);
                }

                // Read ZIP file sequentially and reference central directory in parallel
                int      i = 0;
                ZipEntry localEntry;
                while ((localEntry = _zipStream.GetNextEntry()) != null)
                {
                    ZipEntry centralEntry = _centralDirectory[i++];

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

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

                    UnitsProcessed += centralEntry.CompressedSize;
                }

                SetDirectoryWriteTimes();
            }
            #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

            State = TaskState.Complete;
        }