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)); } }
private void CreateFci(long maxArchiveSize) { var ccab = new NativeMethods.FCI.CCAB(); if (maxArchiveSize > 0 && maxArchiveSize < ccab.cb) { ccab.cb = Math.Max( NativeMethods.FCI.MIN_DISK, (int)maxArchiveSize); } var maxFolderSizeOption = _context.GetOption( "maxFolderSize", null); if (maxFolderSizeOption != null) { var maxFolderSize = Convert.ToInt64( maxFolderSizeOption, CultureInfo.InvariantCulture); if (maxFolderSize > 0 && maxFolderSize < ccab.cbFolderThresh) { ccab.cbFolderThresh = (int)maxFolderSize; } } _maxCabBytes = ccab.cb; ccab.szCab = _context.GetArchiveName(0); if (ccab.szCab == null) { throw new FileNotFoundException("Cabinet name not provided by stream context."); } ccab.setID = (short)new Random().Next( Int16.MinValue, Int16.MaxValue + 1); CabNumbers[ccab.szCab] = 0; CurrentArchiveName = ccab.szCab; TotalArchives = 1; CabStream = null; Erf.Clear(); _fciHandle = NativeMethods.FCI.Create( ErfHandle.AddrOfPinnedObject(), _fciFilePlacedHandler, _fciAllocMemHandler, _fciFreeMemHandler, _fciOpenStreamHandler, _fciReadStreamHandler, _fciWriteStreamHandler, _fciCloseStreamHandler, _fciSeekStreamHandler, _fciDeleteFileHandler, _fciGetTempFileHandler, ccab, IntPtr.Zero); CheckError(false); }