/// <summary> /// Flush the current cabinet file. /// </summary> public void FlushCabinet() { Trace.WriteLine("FlushCabinet"); if (disposed) { throw new ObjectDisposedException("CabCompressor"); } if (!CabSdk.FciFlushCabinet(FciContext, false, new FciGetNextCabinetDelegate(GetNextCabinet), new FciStatusDelegate(ProgressFunc))) { Trace.WriteLine("FciFlushCabinet failed."); throw new ApplicationException(string.Format("FlushCabinet failed with code {0}", erf.FciErrorCode)); } }
/// <summary> /// Adds a file to the current cabinet. /// </summary> /// <param name="filename">The full path name of the file to be added.</param> /// <param name="nameInCab">The name that the file will have in the cabinet.</param> /// <param name="execOnDecompress">A flag that indicates whether the file should be executed when it is decompressed. /// This is just a notification flag. Decompression programs must query the flag and execute the file if desired.</param> /// <param name="compressType">Type of compression to use for this file.</param> public void AddFile(string filename, string nameInCab, bool execOnDecompress, FciCompression compressType) { Trace.WriteLine("AddFile"); if (disposed) { throw new ObjectDisposedException("CabCompressor"); } if (!CabSdk.FciAddFile(FciContext, filename, nameInCab, execOnDecompress, new FciGetNextCabinetDelegate(GetNextCabinet), new FciStatusDelegate(ProgressFunc), new FciGetOpenInfoDelegate(GetOpenInfo), compressType)) { throw new ApplicationException(string.Format("AddFile failed with code {0}", erf.FciErrorCode)); } }
/// <summary> /// Determines whether a file, identified by a stream, is a cabinet file. /// </summary> /// <param name="fstream">The open file stream to be tested.</param> /// <param name="cabinfo">A <see cref="FdiCabinetInfo"/> object that will receive information about the cabinet file.</param> /// <returns>Returns True if the file is a cabinet. If so, the cabinfo object is filled with information about the cabinet file. /// Returns False if the file is not a cabinet.</returns> public bool IsCabinetFile(Stream fstream, FdiCabinetInfo cabinfo) { if (disposed) { throw new ObjectDisposedException("CabDecompressor"); } GCHandle gch = GCHandle.Alloc(fstream); try { return(CabSdk.FdiIsCabinet(FdiContext, (IntPtr)gch, cabinfo)); } finally { gch.Free(); } }
/// <summary> /// Extract files from a cabinet. /// </summary> /// <param name="cabinetFullPath">Full path name of the cabinet from which files are to be extracted.</param> /// <returns>Returns True if extraction was successful. Returns False on error.</returns> /// <remarks>On error, the <see cref="ErrorInfo"/> structure will contain error information.</remarks> public bool ExtractFiles(string cabinetFullPath) { Trace.WriteLine("ExtractFiles: {0}", cabinetFullPath); if (disposed) { throw new ObjectDisposedException("CabDecompressor"); } string path = Path.GetDirectoryName(cabinetFullPath); string filename = Path.GetFileName(cabinetFullPath); Trace.WriteLine("path = {0}", path); Trace.WriteLine("filename = {0}", filename); return(CabSdk.FdiCopy(FdiContext, filename, path, new FdiNotifyDelegate(NotifyCallback), null, //new FdiDecryptDelegate(DecryptCallback), userData)); }
/// <summary> /// Releases the unmanaged resources used by the CabCompressor and optionally releases the managed resources. /// </summary> /// <param name="disposing"></param> /// <remarks></remarks> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { // if disposing is true, dispose all managed and unmanaged resources } if (hfci != IntPtr.Zero) { CabSdk.FciDestroy(hfci); hfci = IntPtr.Zero; } if (!nullUserData) { gchUserData.Free(); nullUserData = true; } disposed = true; } }
/// <summary> /// Releases the unmanaged resources used by the CabDecompressor and optionally releases the managed resources. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { // if disposing is true, dispose all managed and unmanaged resources } if (hfdi != IntPtr.Zero) { Trace.WriteLine("Destroying..."); CabSdk.FdiDestroy(hfdi); hfdi = IntPtr.Zero; } if (!nullUserData) { gchUserData.Free(); nullUserData = true; } disposed = true; } }