Example #1
0
        internal Handle CabGetOpenInfo(string file, out ushort date, out ushort time, out ushort attribs, out int err, Pointer pv)
        {
            try
            {
                if (file == CabBase.STREAM_FILE)
                {
                    FCI.DateTimeToCabDateAndTime(this.fileLastWriteTime, out date, out time);
                    attribs = (ushort)this.fileAttributes;

                    Stream stream = this.fileStream;
                    this.fileStream = new DuplicateStream(stream);
                    Handle hStream = streamHandles.AllocHandle(stream);
                    err = 0;
                    return(hStream);
                }
                else
                {
                    throw new NotSupportedException("Cab engine is trying to open a file other than the primary cab or target files.");
                }
            }
            catch (Exception ex)
            {
                if (this.abortException == null)
                {
                    this.abortException = ex;
                }
                err     = Marshal.GetHRForException(ex);
                date    = 0;
                time    = 0;
                attribs = 0;
                return((Handle)(-1));
            }
        }
Example #2
0
        internal void AddFile(string name, Stream stream, FileAttributes attributes, DateTime lastWriteTime,
                              bool execute, CabinetCompressionLevel compLevel)
        {
            this.fileStream     = stream;
            this.fileAttributes = attributes &
                                  (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);
            this.fileLastWriteTime      = lastWriteTime;
            this.status.currentFileName = name;
            try
            {
                this.erf.Clear();
                FCI.TCOMP tcomp = GetCompressionType(compLevel);

                if (Encoding.UTF8.GetByteCount(name) > name.Length)
                {
                    byte[] nameBytes = Encoding.UTF8.GetBytes(name);
                    name = Encoding.Default.GetString(nameBytes);
                    this.fileAttributes |= FileAttributes.Normal; // _A_NAME_IS_UTF
                }

                FCI.AddFile(this.fciHandle, CabBase.STREAM_FILE, name, execute, this.fciGetNextCabinetHandler,
                            this.fciStatusHandler, this.fciGetOpenInfoHandler, tcomp);
                if (this.erf.fError)
                {
                    throw new CabinetCreateException(this.erf.erfOper, this.erf.erfType, this.abortException);
                }
            }
            finally
            {
                this.fileStream             = null;
                this.status.currentFileName = null;
            }
        }
Example #3
0
 internal void FlushCabinet()
 {
     this.erf.Clear();
     FCI.FlushCabinet(this.fciHandle, false, this.fciGetNextCabinetHandler, this.fciStatusHandler);
     if (this.erf.fError)
     {
         throw new CabinetCreateException(this.erf.erfOper, this.erf.erfType, this.abortException);
     }
 }
Example #4
0
        internal CabCreator(long maxCabSize, long maxFolderSize) : base()
        {
            this.fciAllocMemHandler       = new FCI.PFNALLOC(this.CabAllocMem);
            this.fciFreeMemHandler        = new FCI.PFNFREE(this.CabFreeMem);
            this.fciOpenStreamHandler     = new FCI.PFNOPEN(this.CabOpenStreamEx);
            this.fciReadStreamHandler     = new FCI.PFNREAD(this.CabReadStreamEx);
            this.fciWriteStreamHandler    = new FCI.PFNWRITE(this.CabWriteStreamEx);
            this.fciCloseStreamHandler    = new FCI.PFNCLOSE(this.CabCloseStreamEx);
            this.fciSeekStreamHandler     = new FCI.PFNSEEK(this.CabSeekStreamEx);
            this.fciFilePlacedHandler     = new FCI.PFNFILEPLACED(this.CabFilePlaced);
            this.fciGetOpenInfoHandler    = new FCI.PFNGETOPENINFO(this.CabGetOpenInfo);
            this.fciGetNextCabinetHandler = new FCI.PFNGETNEXTCABINET(this.CabGetNextCabinet);
            this.fciStatusHandler         = new FCI.PFNSTATUS(this.CabCreateStatus);
            this.fciDeleteFileHandler     = new FCI.PFNDELETE(this.CabDeleteFile);
            this.fciGetTempFileHandler    = new FCI.PFNGETTEMPFILE(this.CabGetTempFile);

            this.cabStream  = null;
            this.cabNumbers = new Hashtable(1);

            this.ccab = new FCI.CCAB();
            if (maxCabSize > 0 && maxCabSize < ccab.cb)
            {
                ccab.cb = (uint)maxCabSize;
            }
            if (maxFolderSize > 0 && maxFolderSize < ccab.cbFolderThresh)
            {
                ccab.cbFolderThresh = (uint)maxFolderSize;
            }
            this.maxCabSize    = ccab.cb;
            this.maxFolderSize = ccab.cbFolderThresh;

            this.fciHandle = FCI.Create(this.erf, this.fciFilePlacedHandler, this.fciAllocMemHandler,
                                        this.fciFreeMemHandler, this.fciOpenStreamHandler, this.fciReadStreamHandler,
                                        this.fciWriteStreamHandler, this.fciCloseStreamHandler, this.fciSeekStreamHandler,
                                        this.fciDeleteFileHandler, this.fciGetTempFileHandler, ccab, Pointer.Zero);
            if (this.erf.fError)
            {
                int error     = this.erf.erfOper;
                int errorCode = this.erf.erfType;
                this.erf.Dispose();
                this.erf       = null;
                this.fciHandle = Pointer.Zero;
                throw new CabinetCreateException(error, errorCode, this.abortException);
            }
        }
Example #5
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed objects.
            }

            // Dispose unmanaged objects.
            if (this.fciHandle != Pointer.Zero)
            {
                FCI.Destroy(this.fciHandle);
                this.erf.Dispose();
                this.erf        = null;
                this.cabStream  = null;
                this.fileStream = null;
                this.fciHandle  = Pointer.Zero;
            }
        }
Example #6
0
 /// <summary>
 /// Releases the handle by calling FDIDestroy().
 /// </summary>
 /// <returns>True if the release succeeded.</returns>
 protected override bool ReleaseHandle()
 {
     return(FCI.Destroy(this.handle));
 }