private bool IsCabinet(Stream cabStream, out short id, out int cabFolderCount, out int fileCount) { int streamHandle = StreamHandles.AllocHandle(cabStream); try { Erf.Clear(); NativeMethods.FDI.CABINFO fdici; bool isCabinet = 0 != NativeMethods.FDI.IsCabinet(fdiHandle, streamHandle, out fdici); if (Erf.Error) { if (((NativeMethods.FDI.ERROR)Erf.Oper) == NativeMethods.FDI.ERROR.UNKNOWN_CABINET_VERSION) { isCabinet = false; } else { throw new CabException( Erf.Oper, Erf.Type, CabException.GetErrorMessage(Erf.Oper, Erf.Type, true)); } } id = fdici.setID; cabFolderCount = fdici.cFolders; fileCount = fdici.cFiles; return(isCabinet); } finally { StreamHandles.FreeHandle(streamHandle); } }
internal virtual int CabOpenStreamEx(string path, int openFlags, int shareMode, out int err, IntPtr pv) { path = path.Trim(); var stream = CabStream; CabStream = new DuplicateStream(stream); var streamHandle = StreamHandles.AllocHandle(stream); err = 0; return(streamHandle); }
internal override int CabOpenStreamEx(string path, int openFlags, int shareMode, out int err, IntPtr pv) { if (CabNumbers.ContainsKey(path)) { Stream stream = CabStream; if (stream == null) { short cabNumber = CabNumbers[path]; currentFolderTotalBytes = 0; stream = context.OpenArchiveWriteStream(cabNumber, path, true, CabEngine); if (stream == null) { throw new FileNotFoundException( String.Format(CultureInfo.InvariantCulture, "Cabinet {0} not provided.", cabNumber)); } currentArchiveName = path; currentArchiveTotalBytes = Math.Min( totalFolderBytesProcessedInCurrentCab, maxCabBytes); currentArchiveBytesProcessed = 0; OnProgress(ArchiveProgressType.StartArchive); CabStream = stream; } path = CabStreamName; } else if (path == TempStreamName) { // Opening memory stream for a temp file. Stream stream = new MemoryStream(); tempStreams.Add(stream); int streamHandle = StreamHandles.AllocHandle(stream); err = 0; return(streamHandle); } else if (path != CabStreamName) { // Opening a file on disk for a temp file. path = Path.Combine(Path.GetTempPath(), path); Stream stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); tempStreams.Add(stream); stream = new DuplicateStream(stream); int streamHandle = StreamHandles.AllocHandle(stream); err = 0; return(streamHandle); } return(base.CabOpenStreamEx(path, openFlags, shareMode, out err, pv)); }
private int CabExtractCopyFile(NativeMethods.FDI.NOTIFICATION notification) { if (notification.iFolder != folderId) { if (notification.iFolder != -3) // -3 is a special folderId used when continuing a folder from a previous cab { if (folderId != -1) // -1 means we just started the extraction sequence { currentFolderNumber++; } } folderId = notification.iFolder; } //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0; // _A_EXEC string name = GetFileName(notification); if (filter == null || filter(name)) { currentFileNumber++; currentFileName = name; currentFileBytesProcessed = 0; currentFileTotalBytes = notification.cb; OnProgress(ArchiveProgressType.StartFile); DateTime lastWriteTime; CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime); Stream stream = context.OpenFileWriteStream(name, notification.cb, lastWriteTime); if (stream != null) { FileStream = stream; int streamHandle = StreamHandles.AllocHandle(stream); return(streamHandle); } fileBytesProcessed += notification.cb; OnProgress(ArchiveProgressType.FinishFile); currentFileName = null; } return(0); // Continue }
private int CabGetOpenInfo( string path, out short date, out short time, out short attribs, out int err, IntPtr pv) { CompressionEngine.DateTimeToDOSDateAndTime(_fileLastWriteTime, out date, out time); attribs = (short)_fileAttributes; var stream = FileStream; FileStream = new DuplicateStream(stream); var streamHandle = StreamHandles.AllocHandle(stream); err = 0; return(streamHandle); }