示例#1
0
        private int CabExtractCloseFile(NativeMethods.FDI.NOTIFICATION notification)
        {
            Stream stream = this.StreamHandles[notification.hf];

            this.StreamHandles.FreeHandle(notification.hf);

            //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0;  // _A_EXEC

            string name = CabUnpacker.GetFileName(notification);

            FileAttributes attributes = (FileAttributes)notification.attribs &
                                        (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);

            if (attributes == (FileAttributes)0)
            {
                attributes = FileAttributes.Normal;
            }
            DateTime lastWriteTime;

            CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime);

            stream.Flush();
            this.context.CloseFileWriteStream(name, stream, attributes, lastWriteTime);
            this.FileStream = null;

            long remainder = this.currentFileTotalBytes - this.currentFileBytesProcessed;

            this.currentFileBytesProcessed += remainder;
            this.fileBytesProcessed        += remainder;
            this.OnProgress(ArchiveProgressType.FinishFile);
            this.currentFileName = null;

            return(1);  // Continue
        }
示例#2
0
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
            case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
            {
                string nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                this.NextCabinetName = (nextCab.Length != 0 ? nextCab : null);
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.PARTIAL_FILE:
            {
                // This notification can occur when examining the contents of a non-first cab file.
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
            {
                //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0;  // _A_EXEC

                string name = CabUnpacker.GetFileName(notification);

                if (this.filter == null || this.filter(name))
                {
                    if (this.fileList != null)
                    {
                        FileAttributes attributes = (FileAttributes)notification.attribs &
                                                    (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);
                        if (attributes == (FileAttributes)0)
                        {
                            attributes = FileAttributes.Normal;
                        }
                        DateTime lastWriteTime;
                        CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime);
                        long length = notification.cb;

                        CabFileInfo fileInfo = new CabFileInfo(
                            name,
                            notification.iFolder,
                            notification.iCabinet,
                            attributes,
                            lastWriteTime,
                            length);
                        this.fileList.Add(fileInfo);
                        this.currentFileNumber   = this.fileList.Count - 1;
                        this.fileBytesProcessed += notification.cb;
                    }
                }

                this.totalFiles++;
                this.totalFileBytes += notification.cb;
                return(0);         // Continue
            }
            }
            return(0);
        }
示例#3
0
        private int CabExtractCopyFile(NativeMethods.FDI.NOTIFICATION notification)
        {
            if (notification.iFolder != this.folderId)
            {
                if (notification.iFolder != -3) // -3 is a special folderId used when continuing a folder from a previous cab
                {
                    if (this.folderId != -1)    // -1 means we just started the extraction sequence
                    {
                        this.currentFolderNumber++;
                    }
                }
                this.folderId = notification.iFolder;
            }

            //bool execute = (notification.attribs & (ushort) FileAttributes.Device) != 0;  // _A_EXEC

            string name = CabUnpacker.GetFileName(notification);

            if (this.filter == null || this.filter(name))
            {
                this.currentFileNumber++;
                this.currentFileName = name;

                this.currentFileBytesProcessed = 0;
                this.currentFileTotalBytes     = notification.cb;
                this.OnProgress(ArchiveProgressType.StartFile);

                DateTime lastWriteTime;
                CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out lastWriteTime);

                Stream stream = this.context.OpenFileWriteStream(name, notification.cb, lastWriteTime);
                if (stream != null)
                {
                    this.FileStream = stream;
                    int streamHandle = this.StreamHandles.AllocHandle(stream);
                    return(streamHandle);
                }
                else
                {
                    this.fileBytesProcessed += notification.cb;
                    this.OnProgress(ArchiveProgressType.FinishFile);
                    this.currentFileName = null;
                }
            }
            return(0);  // Continue
        }
示例#4
0
        /// <summary>
        /// Disposes of resources allocated by the cabinet engine.
        /// </summary>
        /// <param name="disposing">If true, the method has been called directly
        /// or indirectly by a user's code, so managed and unmanaged resources
        /// will be disposed. If false, the method has been called by the runtime
        /// from inside the finalizer, and only unmanaged resources will be
        /// disposed.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (packer != null)
                {
                    packer.Dispose();
                    packer = null;
                }
                if (unpacker != null)
                {
                    unpacker.Dispose();
                    unpacker = null;
                }
            }

            base.Dispose(disposing);
        }