示例#1
0
        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);
            }
        }
示例#2
0
        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
        }
示例#3
0
 internal virtual int CabCloseStreamEx(int streamHandle, out int err, IntPtr pv)
 {
     StreamHandles.FreeHandle(streamHandle);
     err = 0;
     return(0);
 }