Example #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);
            }
        }
Example #2
0
        public CabUnpacker(CabEngine cabEngine)
            : base(cabEngine)
        {
            fdiAllocMemHandler    = CabAllocMem;
            fdiFreeMemHandler     = CabFreeMem;
            fdiOpenStreamHandler  = CabOpenStream;
            fdiReadStreamHandler  = CabReadStream;
            fdiWriteStreamHandler = CabWriteStream;
            fdiCloseStreamHandler = CabCloseStream;
            fdiSeekStreamHandler  = CabSeekStream;

            fdiHandle = NativeMethods.FDI.Create(
                fdiAllocMemHandler,
                fdiFreeMemHandler,
                fdiOpenStreamHandler,
                fdiReadStreamHandler,
                fdiWriteStreamHandler,
                fdiCloseStreamHandler,
                fdiSeekStreamHandler,
                NativeMethods.FDI.CPU_80386,
                ErfHandle.AddrOfPinnedObject());
            if (Erf.Error)
            {
                int error     = Erf.Oper;
                int errorCode = Erf.Type;
                ErfHandle.Free();
                throw new CabException(
                          error,
                          errorCode,
                          CabException.GetErrorMessage(error, errorCode, true));
            }
        }
Example #3
0
 protected void CheckError(bool extracting)
 {
     if (Erf.Error)
     {
         throw new CabException(
                   Erf.Oper,
                   Erf.Type,
                   CabException.GetErrorMessage(Erf.Oper, Erf.Type, extracting));
     }
 }