public bool ExtractFile(string fileName, out byte[] outputData, out int outputLength) { if (_disposed) { throw new ObjectDisposedException("CabExtract"); } CabDecompressFile fileToDecompress = new CabDecompressFile { Found = false, Name = fileName }; _decompressFiles.Add(fileToDecompress); FdiCopy(FdiContext, NotifyCallback); if (fileToDecompress.Found) { outputData = fileToDecompress.Data; outputLength = fileToDecompress.Length; _decompressFiles.Remove(fileToDecompress); return(true); } outputData = null; outputLength = 0; return(false); }
private IntPtr OutputFileOpen(FdiNotification fdin) { CabDecompressFile extractFile = _decompressFiles.SingleOrDefault(ef => ef.Name == fdin.psz1); if (extractFile != null) { MemoryStream stream = new MemoryStream(); GCHandle gch = GCHandle.Alloc(stream); extractFile.Handle = (IntPtr)gch; return(extractFile.Handle); } //Don't extract return(IntPtr.Zero); }
private IntPtr OutputFileClose(FdiNotification fdin) { CabDecompressFile extractFile = _decompressFiles.Single(ef => ef.Handle == fdin.hf); Stream stream = StreamFromHandle(fdin.hf); extractFile.Found = true; extractFile.Length = (int)stream.Length; if (stream.Length > 0) { extractFile.Data = new byte[stream.Length]; stream.Position = 0; stream.Read(extractFile.Data, 0, (int)stream.Length); } stream.Close(); return(IntPtr.Zero); }
public bool ExtractFile(string fileName, out byte[] outputData, out int outputLength) { for (int attempt = 0; attempt < ExtractFileAttemptLimit; attempt++) { try { if (_disposed) { throw new ObjectDisposedException("CabExtract"); } CabDecompressFile fileToDecompress = new CabDecompressFile { Found = false, Name = fileName }; _decompressFiles.Add(fileToDecompress); FdiCopy(FdiContext, NotifyCallback); if (fileToDecompress.Found) { outputData = fileToDecompress.Data; outputLength = fileToDecompress.Length; _decompressFiles.Remove(fileToDecompress); return(true); } } catch (Exception ex) { Thread.Sleep(1000); } } outputData = null; outputLength = 0; return(false); }