/// <inheritdoc/> protected override void ExtractArchive() { State = TaskState.Data; try { UnitsTotal = _archive.TotalUncompressSize; foreach (var entry in _archive.Entries) { string?relativePath = GetRelativePath(entry.Key.Replace('\\', '/')); if (relativePath == null) { continue; } if (entry.IsDirectory) { DirectoryBuilder.CreateDirectory(relativePath, entry.LastModifiedTime?.ToUniversalTime()); } else { CancellationToken.ThrowIfCancellationRequested(); string absolutePath = DirectoryBuilder.NewFilePath(relativePath, entry.LastModifiedTime?.ToUniversalTime()); using (var fileStream = File.Create(absolutePath)) entry.WriteTo(fileStream); UnitsProcessed += entry.Size; } } } #region Error handling catch (ExtractionException ex) { // Wrap exception since only certain exception types are allowed throw new IOException(Resources.ArchiveInvalid, ex); } #endregion }
Stream IUnpackStreamContext.OpenFileWriteStream(string path, long fileSize, DateTime lastWriteTime) { #region Sanity checks if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } #endregion CancellationToken.ThrowIfCancellationRequested(); string relativePath = GetRelativePath(path); if (relativePath == null) { return(null); } _bytesStaged = fileSize; string absolutePath = DirectoryBuilder.NewFilePath(relativePath, lastWriteTime); return(File.Create(absolutePath)); }