Beispiel #1
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
        }
Beispiel #2
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
        }
        private static string GetFileName(NativeMethods.FDI.NOTIFICATION notification)
        {
            Encoding encoding = ((((uint)notification.attribs & 0x80u) != 0) ? Encoding.UTF8 : Encoding.Default);
            int      i;

            for (i = 0; Marshal.ReadByte(notification.psz1, i) != 0; i = checked (i + 1))
            {
            }
            byte[] array = new byte[i];
            Marshal.Copy(notification.psz1, array, 0, i);
            string text = encoding.GetString(array);

            if (Path.IsPathRooted(text))
            {
                string text2 = text;
                char   volumeSeparatorChar = Path.VolumeSeparatorChar;
                text = text2.Replace(volumeSeparatorChar.ToString() ?? "", "");
            }
            return(text);
        }
Beispiel #4
0
        private int CabExtractNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
            case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
            {
                if (this.NextCabinetName != null && this.NextCabinetName.StartsWith("?", StringComparison.Ordinal))
                {
                    // We are just continuing the copy of a file that spanned cabinets.
                    // The next cabinet name needs to be preserved.
                    this.NextCabinetName = this.NextCabinetName.Substring(1);
                }
                else
                {
                    string nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                    this.NextCabinetName = (nextCab.Length != 0 ? nextCab : null);
                }
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.NEXT_CABINET:
            {
                string nextCab = Marshal.PtrToStringAnsi(notification.psz1);
                this.CabNumbers[nextCab] = (short)notification.iCabinet;
                this.NextCabinetName     = "?" + this.NextCabinetName;
                return(0);         // Continue
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
            {
                return(this.CabExtractCopyFile(notification));
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.CLOSE_FILE_INFO:
            {
                return(this.CabExtractCloseFile(notification));
            }
            }
            return(0);
        }
Beispiel #5
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);
        }
        private int CabExtractNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            switch (notificationType)
            {
            case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
                if (base.NextCabinetName != null && base.NextCabinetName.StartsWith("?", StringComparison.Ordinal))
                {
                    base.NextCabinetName = base.NextCabinetName.Substring(1);
                }
                else
                {
                    string text = Marshal.PtrToStringAnsi(notification.psz1);
                    base.NextCabinetName = ((text.Length != 0) ? text : null);
                }
                return(0);

            case NativeMethods.FDI.NOTIFICATIONTYPE.NEXT_CABINET:
            {
                string key = Marshal.PtrToStringAnsi(notification.psz1);
                base.CabNumbers[key] = notification.iCabinet;
                base.NextCabinetName = "?" + base.NextCabinetName;
                return(0);
            }

            case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
                return(CabExtractCopyFile(notification));

            case NativeMethods.FDI.NOTIFICATIONTYPE.CLOSE_FILE_INFO:
                return(CabExtractCloseFile(notification));

            default:
                return(0);
            }
        }
        private int CabListNotify(NativeMethods.FDI.NOTIFICATIONTYPE notificationType, NativeMethods.FDI.NOTIFICATION notification)
        {
            checked
            {
                switch (notificationType)
                {
                case NativeMethods.FDI.NOTIFICATIONTYPE.CABINET_INFO:
                {
                    string text = Marshal.PtrToStringAnsi(notification.psz1);
                    base.NextCabinetName = ((text.Length != 0) ? text : null);
                    return(0);
                }

                case NativeMethods.FDI.NOTIFICATIONTYPE.PARTIAL_FILE:
                    return(0);

                case NativeMethods.FDI.NOTIFICATIONTYPE.COPY_FILE:
                {
                    string fileName = GetFileName(notification);
                    if ((filter == null || filter(fileName)) && fileList != null)
                    {
                        FileAttributes fileAttributes = unchecked ((FileAttributes)(notification.attribs & 0x27));
                        if (fileAttributes == (FileAttributes)0)
                        {
                            fileAttributes = FileAttributes.Normal;
                        }
                        CompressionEngine.DosDateAndTimeToDateTime(notification.date, notification.time, out var dateTime);
                        long        length = notification.cb;
                        CabFileInfo item   = new CabFileInfo(fileName, notification.iFolder, notification.iCabinet, fileAttributes, dateTime, length);
                        fileList.Add(item);
                        currentFileNumber   = fileList.Count - 1;
                        fileBytesProcessed += notification.cb;
                    }
                    totalFiles++;
                    totalFileBytes += notification.cb;
                    return(0);
                }

                default:
                    return(0);
                }
            }
        }