예제 #1
0
        public CabUnpacker(CabEngine cabEngine)
            : base(cabEngine)
        {
            this.fdiAllocMemHandler    = this.CabAllocMem;
            this.fdiFreeMemHandler     = this.CabFreeMem;
            this.fdiOpenStreamHandler  = this.CabOpenStream;
            this.fdiReadStreamHandler  = this.CabReadStream;
            this.fdiWriteStreamHandler = this.CabWriteStream;
            this.fdiCloseStreamHandler = this.CabCloseStream;
            this.fdiSeekStreamHandler  = this.CabSeekStream;

            this.fdiHandle = NativeMethods.FDI.Create(
                this.fdiAllocMemHandler,
                this.fdiFreeMemHandler,
                this.fdiOpenStreamHandler,
                this.fdiReadStreamHandler,
                this.fdiWriteStreamHandler,
                this.fdiCloseStreamHandler,
                this.fdiSeekStreamHandler,
                NativeMethods.FDI.CPU_80386,
                this.ErfHandle.AddrOfPinnedObject());
            if (this.Erf.Error)
            {
                int error     = this.Erf.Oper;
                int errorCode = this.Erf.Type;
                this.ErfHandle.Free();
                throw new CabException(
                          error,
                          errorCode,
                          CabException.GetErrorMessage(error, errorCode, true));
            }
        }
예제 #2
0
        private bool IsCabinet(Stream cabStream, out short id, out int cabFolderCount, out int fileCount)
        {
            int streamHandle = this.StreamHandles.AllocHandle(cabStream);

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

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

                id             = fdici.setID;
                cabFolderCount = (int)fdici.cFolders;
                fileCount      = (int)fdici.cFiles;
                return(isCabinet);
            }
            finally
            {
                this.StreamHandles.FreeHandle(streamHandle);
            }
        }
예제 #3
0
파일: CabWorker.cs 프로젝트: zhitian/3P
 protected void CheckError(bool extracting)
 {
     if (Erf.Error)
     {
         throw new CabException(
                   Erf.Oper,
                   Erf.Type,
                   CabException.GetErrorMessage(Erf.Oper, Erf.Type, extracting));
     }
 }