Exemplo n.º 1
0
        private int CabExtractCloseFile(NativeMethods.FDI.NOTIFICATION notification)
        {
            var stream = StreamHandles[notification.hf];

            StreamHandles.FreeHandle(notification.hf);

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

            var name = GetFileName(notification);

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

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

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

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

            var remainder = CurrentFileTotalBytes - CurrentFileBytesProcessed;

            CurrentFileBytesProcessed += remainder;
            FileBytesProcessed        += remainder;
            OnProgress(ArchiveProgressType.FinishFile);
            CurrentFileName = null;

            return(1);             // Continue
        }
Exemplo n.º 2
0
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
            case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
            {
                var nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                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

                var name = GetFileName(notification);

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

                        var fileInfo = new CabFileInfo(
                            name,
                            notification.iFolder,
                            notification.iCabinet,
                            attributes,
                            lastWriteTime,
                            length);
                        _fileList.Add(fileInfo);
                        CurrentFileNumber   = _fileList.Count - 1;
                        FileBytesProcessed += notification.cb;
                    }
                }

                TotalFiles++;
                TotalFileBytes += notification.cb;
                return(0);                         // Continue
            }
            }
            return(0);
        }
Exemplo n.º 3
0
        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

            var 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);

                var stream = _context.OpenFileWriteStream(name, notification.cb, lastWriteTime);
                if (stream != null)
                {
                    FileStream = stream;
                    var streamHandle = StreamHandles.AllocHandle(stream);
                    return(streamHandle);
                }

                FileBytesProcessed += notification.cb;
                OnProgress(ArchiveProgressType.FinishFile);
                CurrentFileName = null;
            }
            return(0);             // Continue
        }