private int CabExtractCloseFile(NativeMethods.FDI.NOTIFICATION notification) { Stream stream = StreamHandles[notification.hf]; StreamHandles.FreeHandle(notification.hf); //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0; // _A_EXEC string name = GetFileName(notification); FileAttributes attributes = (FileAttributes)notification.attribs & (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); if (attributes == 0) { attributes = FileAttributes.Normal; } DateTime lastWriteTime; CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime); stream.Flush(); context.CloseFileWriteStream(name, stream, attributes, lastWriteTime); FileStream = null; long remainder = currentFileTotalBytes - currentFileBytesProcessed; currentFileBytesProcessed += remainder; fileBytesProcessed += remainder; OnProgress(ArchiveProgressType.FinishFile); currentFileName = null; return(1); // Continue }
private int CabExtractCloseFile(NativeMethods.FDI.NOTIFICATION notification) { Stream stream = base.StreamHandles[notification.hf]; base.StreamHandles.FreeHandle(notification.hf); string fileName = GetFileName(notification); FileAttributes fileAttributes = (FileAttributes)(notification.attribs & 0x27); if (fileAttributes == (FileAttributes)0) { fileAttributes = FileAttributes.Normal; } CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out var dateTime); stream.Flush(); context.CloseFileWriteStream(fileName, stream, fileAttributes, dateTime); base.FileStream = null; checked { long num = currentFileTotalBytes - currentFileBytesProcessed; currentFileBytesProcessed += num; fileBytesProcessed += num; OnProgress(ArchiveProgressType.FinishFile); currentFileName = null; return(1); } }
public void Unpack(IUnpackStreamContext streamContext, Predicate <string> fileFilter) { checked { lock (this) { IList <ArchiveFileInfo> fileInfo = GetFileInfo(streamContext, fileFilter); ResetProgressData(); if (fileInfo != null) { totalFiles = fileInfo.Count; for (int i = 0; i < fileInfo.Count; i++) { totalFileBytes += fileInfo[i].Length; if (fileInfo[i].ArchiveNumber >= totalArchives) { int num = fileInfo[i].ArchiveNumber + 1; totalArchives = (short)num; } } } context = streamContext; fileList = null; base.NextCabinetName = string.Empty; folderId = -1; currentFileNumber = -1; try { short num2 = 0; while (base.NextCabinetName != null) { base.Erf.Clear(); base.CabNumbers[base.NextCabinetName] = num2; NativeMethods.FDI.Copy(fdiHandle, base.NextCabinetName, string.Empty, 0, CabExtractNotify, IntPtr.Zero, IntPtr.Zero); CheckError(extracting: true); num2 = (short)(num2 + 1); } } finally { if (base.CabStream != null) { context.CloseArchiveReadStream(currentArchiveNumber, currentArchiveName, base.CabStream); base.CabStream = null; } if (base.FileStream != null) { context.CloseFileWriteStream(currentFileName, base.FileStream, FileAttributes.Normal, DateTime.Now); base.FileStream = null; } context = null; } } } }
/// <summary> /// Unpacks a single file from an archive or archive chain. /// </summary> private void UnpackOneFile( IUnpackStreamContext streamContext, ZipFileHeader header, ref Stream archiveStream) { ZipFileInfo fileInfo = null; Stream fileStream = null; try { Func <Stream, Stream> compressionStreamCreator; if (!ZipEngine.decompressionStreamCreators.TryGetValue( header.compressionMethod, out compressionStreamCreator)) { // Silently skip files of an unsupported compression method. return; } long compressedSize; long uncompressedSize; long localHeaderOffset; int archiveNumber; uint crc; header.GetZip64Fields( out compressedSize, out uncompressedSize, out localHeaderOffset, out archiveNumber, out crc); if (this.currentArchiveNumber != archiveNumber + 1) { if (archiveStream != null) { streamContext.CloseArchiveReadStream( this.currentArchiveNumber, String.Empty, archiveStream); archiveStream = null; this.OnProgress(ArchiveProgressType.FinishArchive); this.currentArchiveName = null; } this.currentArchiveNumber = (short)(archiveNumber + 1); this.currentArchiveBytesProcessed = 0; this.currentArchiveTotalBytes = 0; archiveStream = this.OpenArchive( streamContext, this.currentArchiveNumber); FileStream archiveFileStream = archiveStream as FileStream; this.currentArchiveName = (archiveFileStream != null ? Path.GetFileName(archiveFileStream.Name) : null); this.currentArchiveTotalBytes = archiveStream.Length; this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.StartArchive); this.currentArchiveNumber++; } archiveStream.Seek(localHeaderOffset, SeekOrigin.Begin); ZipFileHeader localHeader = new ZipFileHeader(); if (!localHeader.Read(archiveStream, false) || !ZipEngine.AreFilePathsEqual(localHeader.fileName, header.fileName)) { string msg = "Could not read file: " + header.fileName; throw new ZipException(msg); } fileInfo = header.ToZipFileInfo(); fileStream = streamContext.OpenFileWriteStream( fileInfo.FullName, fileInfo.Length, fileInfo.LastWriteTime); if (fileStream != null) { this.currentFileName = header.fileName; this.currentFileBytesProcessed = 0; this.currentFileTotalBytes = fileInfo.Length; this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.StartFile); this.currentArchiveNumber++; this.UnpackFileBytes( streamContext, fileInfo.FullName, fileInfo.CompressedLength, fileInfo.Length, header.crc32, fileStream, compressionStreamCreator, ref archiveStream); } } finally { if (fileStream != null) { streamContext.CloseFileWriteStream( fileInfo.FullName, fileStream, fileInfo.Attributes, fileInfo.LastWriteTime); this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.FinishFile); this.currentArchiveNumber++; } } }
/// <summary> /// Unpacks a single file from an archive or archive chain. /// </summary> private void UnpackOneFile( IUnpackStreamContext streamContext, ZipFileHeader header, ref Stream archiveStream) { ZipFileInfo fileInfo = null; Stream fileStream = null; try { Converter<Stream, Stream> compressionStreamCreator; if (!ZipEngine.decompressionStreamCreators.TryGetValue( header.compressionMethod, out compressionStreamCreator)) { // Silently skip files of an unsupported compression method. return; } long compressedSize; long uncompressedSize; long localHeaderOffset; int archiveNumber; uint crc; header.GetZip64Fields( out compressedSize, out uncompressedSize, out localHeaderOffset, out archiveNumber, out crc); if (this.currentArchiveNumber != archiveNumber + 1) { if (archiveStream != null) { streamContext.CloseArchiveReadStream( this.currentArchiveNumber, String.Empty, archiveStream); archiveStream = null; this.OnProgress(ArchiveProgressType.FinishArchive); this.currentArchiveName = null; } this.currentArchiveNumber = (short) (archiveNumber + 1); this.currentArchiveBytesProcessed = 0; this.currentArchiveTotalBytes = 0; archiveStream = this.OpenArchive( streamContext, this.currentArchiveNumber); FileStream archiveFileStream = archiveStream as FileStream; this.currentArchiveName = (archiveFileStream != null ? Path.GetFileName(archiveFileStream.Name) : null); this.currentArchiveTotalBytes = archiveStream.Length; this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.StartArchive); this.currentArchiveNumber++; } archiveStream.Seek(localHeaderOffset, SeekOrigin.Begin); ZipFileHeader localHeader = new ZipFileHeader(); if (!localHeader.Read(archiveStream, false) || !ZipEngine.AreFilePathsEqual(localHeader.fileName, header.fileName)) { string msg = "Could not read file: " + header.fileName; throw new ZipException(msg); } fileInfo = header.ToZipFileInfo(); fileStream = streamContext.OpenFileWriteStream( fileInfo.FullName, fileInfo.Length, fileInfo.LastWriteTime); if (fileStream != null) { this.currentFileName = header.fileName; this.currentFileBytesProcessed = 0; this.currentFileTotalBytes = fileInfo.Length; this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.StartFile); this.currentArchiveNumber++; this.UnpackFileBytes( streamContext, fileInfo.FullName, fileInfo.CompressedLength, fileInfo.Length, header.crc32, fileStream, compressionStreamCreator, ref archiveStream); } } finally { if (fileStream != null) { streamContext.CloseFileWriteStream( fileInfo.FullName, fileStream, fileInfo.Attributes, fileInfo.LastWriteTime); this.currentArchiveNumber--; this.OnProgress(ArchiveProgressType.FinishFile); this.currentArchiveNumber++; } } }
public void Unpack( IUnpackStreamContext streamContext, Predicate <string> fileFilter) { lock (this) { IList <ArchiveFileInfo> files = GetFileInfo(streamContext, fileFilter); ResetProgressData(); if (files != null) { totalFiles = files.Count; for (int i = 0; i < files.Count; i++) { totalFileBytes += files[i].Length; if (files[i].ArchiveNumber >= this.totalArchives) { int totalArchives = files[i].ArchiveNumber + 1; this.totalArchives = (short)totalArchives; } } } context = streamContext; fileList = null; NextCabinetName = String.Empty; folderId = -1; currentFileNumber = -1; try { for (short cabNumber = 0; NextCabinetName != null; cabNumber++) { Erf.Clear(); CabNumbers[NextCabinetName] = cabNumber; NativeMethods.FDI.Copy( fdiHandle, NextCabinetName, String.Empty, 0, CabExtractNotify, IntPtr.Zero, IntPtr.Zero); CheckError(true); } } finally { if (CabStream != null) { context.CloseArchiveReadStream( currentArchiveNumber, currentArchiveName, CabStream); CabStream = null; } if (FileStream != null) { context.CloseFileWriteStream(currentFileName, FileStream, FileAttributes.Normal, DateTime.Now); FileStream = null; } context = null; } } }