コード例 #1
0
ファイル: CabUnpacker.cs プロジェクト: massreuy/3P
        private int CabExtractCloseFile(NativeMethods.FDI.NOTIFICATION notification)
        {
            Stream stream = StreamHandles[notification.hf];

            StreamHandles.FreeHandle(notification.hf);

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

            string name = GetFileName(notification);

            FileAttributes 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;

            long remainder = currentFileTotalBytes - currentFileBytesProcessed;

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

            return(1); // Continue
        }
コード例 #2
0
ファイル: CabUnpacker.cs プロジェクト: massreuy/3P
        private bool IsCabinet(Stream cabStream, out short id, out int cabFolderCount, out int fileCount)
        {
            int streamHandle = StreamHandles.AllocHandle(cabStream);

            try {
                Erf.Clear();
                NativeMethods.FDI.CABINFO fdici;
                bool isCabinet = 0 != NativeMethods.FDI.IsCabinet(fdiHandle, streamHandle, out fdici);

                if (Erf.Error)
                {
                    if (((NativeMethods.FDI.ERROR)Erf.Oper) == NativeMethods.FDI.ERROR.UNKNOWN_CABINET_VERSION)
                    {
                        isCabinet = false;
                    }
                    else
                    {
                        throw new CabException(
                                  Erf.Oper,
                                  Erf.Type,
                                  CabException.GetErrorMessage(Erf.Oper, Erf.Type, true));
                    }
                }

                id             = fdici.setID;
                cabFolderCount = fdici.cFolders;
                fileCount      = fdici.cFiles;
                return(isCabinet);
            } finally {
                StreamHandles.FreeHandle(streamHandle);
            }
        }
コード例 #3
0
        internal virtual int CabOpenStreamEx(string path, int openFlags, int shareMode, out int err, IntPtr pv)
        {
            path = path.Trim();
            var stream = CabStream;

            CabStream = new DuplicateStream(stream);
            var streamHandle = StreamHandles.AllocHandle(stream);

            err = 0;
            return(streamHandle);
        }
コード例 #4
0
ファイル: CabPacker.cs プロジェクト: jcaillon/CabinetManager
        internal override int CabOpenStreamEx(string path, int openFlags, int shareMode, out int err, IntPtr pv)
        {
            if (CabNumbers.ContainsKey(path))
            {
                Stream stream = CabStream;
                if (stream == null)
                {
                    short cabNumber = CabNumbers[path];

                    currentFolderTotalBytes = 0;

                    stream = context.OpenArchiveWriteStream(cabNumber, path, true, CabEngine);
                    if (stream == null)
                    {
                        throw new FileNotFoundException(
                                  String.Format(CultureInfo.InvariantCulture, "Cabinet {0} not provided.", cabNumber));
                    }

                    currentArchiveName = path;

                    currentArchiveTotalBytes = Math.Min(
                        totalFolderBytesProcessedInCurrentCab, maxCabBytes);
                    currentArchiveBytesProcessed = 0;

                    OnProgress(ArchiveProgressType.StartArchive);
                    CabStream = stream;
                }

                path = CabStreamName;
            }
            else if (path == TempStreamName)
            {
                // Opening memory stream for a temp file.
                Stream stream = new MemoryStream();
                tempStreams.Add(stream);
                int streamHandle = StreamHandles.AllocHandle(stream);
                err = 0;
                return(streamHandle);
            }
            else if (path != CabStreamName)
            {
                // Opening a file on disk for a temp file.
                path = Path.Combine(Path.GetTempPath(), path);
                Stream stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
                tempStreams.Add(stream);
                stream = new DuplicateStream(stream);
                int streamHandle = StreamHandles.AllocHandle(stream);
                err = 0;
                return(streamHandle);
            }

            return(base.CabOpenStreamEx(path, openFlags, shareMode, out err, pv));
        }
コード例 #5
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

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

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

                fileBytesProcessed += notification.cb;
                OnProgress(ArchiveProgressType.FinishFile);
                currentFileName = null;
            }

            return(0); // Continue
        }
コード例 #6
0
ファイル: CabPacker.cs プロジェクト: mrjrt/IntegrateDrv
        private int CabGetOpenInfo(
            string path,
            out short date,
            out short time,
            out short attribs,
            out int err,
            IntPtr pv)
        {
            CompressionEngine.DateTimeToDOSDateAndTime(_fileLastWriteTime, out date, out time);
            attribs = (short)_fileAttributes;

            var stream = FileStream;

            FileStream = new DuplicateStream(stream);
            var streamHandle = StreamHandles.AllocHandle(stream);

            err = 0;
            return(streamHandle);
        }
コード例 #7
0
 internal virtual int CabCloseStreamEx(int streamHandle, out int err, IntPtr pv)
 {
     StreamHandles.FreeHandle(streamHandle);
     err = 0;
     return(0);
 }