📄 cabinet.hpp
字号:
// FCIERR_NONE No error
// FCIERR_OPEN_SRC Failure opening file to be stored in cabinet
// Use GetErrorCodeEx 2 get C run-time *errno* value
// FCIERR_READ_SRC Failure reading file to be stored in cabinet
// Use GetErrorCodeEx 2 get C run-time *errno* value
// FCIERR_ALLOC_FAIL Out of memory
// FCIERR_TEMP_FILE Could not create a temporary file
// Use GetErrorCodeEx 2 get C run-time *errno* value
// FCIERR_BAD_COMPR_TYPE Unknown compression type
// FCIERR_CAB_FILE Could not create cabinet file
// Use GetErrorCodeEx 2 get C run-time *errno* value
// FCIERR_USER_ABORT Client requested abort
// FCIERR_MCI_FAIL Failure compressing data
//--- Structure 2 hold information about a cabinet file --------------------
#ifdef __CAB_EXTRACT__
struct CABINETINFO
{
long m_cbSize; // Total length of cabinet file
USHORT m_nFolders; // Count of folders in cabinet
USHORT m_nFiles; // Count of files in cabinet
USHORT m_nID; // Cabinet set ID
USHORT m_nIndex; // Cabinet number in set (0 based)
BOOL m_bHasReservedSpace; // TRUE if there are reserved areas present in cabinet
BOOL m_bChainedPrev; // TRUE if cabinet is chained prev
BOOL m_bChainedNext; // TRUE if cabinet is chained next
};
#endif
#define MAX_CABINETS_IN_SET 50
//--- Class 4 cabinet extraction ------------------------------------------
#ifdef __CAB_EXTRACT__
class CCabinetExtractor: public CCabinetBase
{
// Data members
private:
CPath m_NextCabinet;
string m_strNextDisk;
int m_nNextIndex;
CPath m_ContinueCabinet;
string m_strContinueDisk;
int m_nContinueIndex;
BOOL m_bLastFileSkipped;
BOOL m_bNextCabinetReady;
protected:
HFDI m_hContext;
int m_nLastFileStartCabinetIndex;
int m_nLastFileEndCabinetIndex;
BOOL m_bCabinetSetFinished;
public:
CPath m_DefaultExtractPath;
CPath m_LastExtracted; // Last extracted file (real path, where file was extracted)
// Construction and destruction
public:
CCabinetExtractor();
BOOL GetCabinetInfo(LPCTSTR lpcszCabFile, CABINETINFO *lpInfo =NULL);
void SetDefaultExtractPath(LPCTSTR lpcszDefExtractPath);
BOOL ExtractFiles(LPCTSTR lpcszCabFile, BOOL bContinuous =TRUE);
virtual ~CCabinetExtractor();
// Callbacks
protected:
static int FAR DIAMONDAPI FileOpen(char FAR *pszFile, int oFlag, int pMode);
static UINT FAR DIAMONDAPI FileRead(int hFile, void FAR *ptrBuffer, UINT cbRead);
static UINT FAR DIAMONDAPI FileWrite(int hFile, void FAR *ptrBuffer, UINT cbWrite);
static int FAR DIAMONDAPI FileClose(int hFile);
static long FAR DIAMONDAPI FileSeek(int hFile, long offset, int seekType);
static int FAR DIAMONDAPI NotifyProgress(FDINOTIFICATIONTYPE notifyType, PFDINOTIFICATION notifyInfo);
// Callback helpers
protected:
virtual PFNALLOC MemAllocProc() const { return CCabinetBase::MemAlloc; }
virtual PFNFREE MemFreeProc() const { return CCabinetBase::MemFree; }
virtual PFNOPEN FileOpenProc() const { return CCabinetExtractor::FileOpen; }
virtual PFNREAD FileReadProc() const { return CCabinetExtractor::FileRead; }
virtual PFNWRITE FileWriteProc() const { return CCabinetExtractor::FileWrite; }
virtual PFNSEEK FileSeekProc() const { return CCabinetExtractor::FileSeek; }
virtual PFNCLOSE FileCloseProc() const { return CCabinetExtractor::FileClose; }
virtual PFNFDINOTIFY NotifyProgressProc() const { return CCabinetExtractor::NotifyProgress; }
// Miscellaneous helpers
protected:
virtual BOOL NotifyCabinetInfo(USHORT nID, LPCTSTR lpcszCabPath, LPCTSTR lpcszCabName, LPCTSTR lpcszDiskName, USHORT nCabIndex);
virtual BOOL NotifyPartialFile(LPCTSTR lpcszFileName, LPCTSTR lpcszFirstCab, LPCTSTR lpcszFirstDisk);
virtual BOOL NotifyFileCopy(LPCTSTR lpcszFileName, ULONG cbSize, string &strExtractTo, BOOL &bSkipFile);
virtual BOOL NotifyFileCopied(LPCTSTR lpcszFileName, USHORT &nDate, USHORT &nTime, USHORT &nAttribs);
virtual BOOL NotifyFileCopiedAndClosed(LPCTSTR lpcszFileName);
virtual BOOL NotifyEnumerate(USHORT nID, long &nCurrentPosition, USHORT &nFilesRemaining);
virtual BOOL NotifyNextCabinet(LPCTSTR lpcszNextCab, LPCTSTR lpcszNextDisk, string &strNextCabPath, int nErrorCode);
};
#endif
//--- Decompression errors -------------------------------------------------------
// Clients can retrieve the error code of the last cabinet operation using the
// GetErrorCode and GetErrorCodeEx (additional error info) members
// Possible values returned by GetErrorCode are:
// FDIERROR_NONE No error
// FDIERROR_CABINET_NOT_FOUND Cabinet not found
// Bad file name or path passed to FDICopy(), or returned
// to fdintNEXT_CABINET
// FDIERROR_NOT_A_CABINET Cabinet file does not have the correct format
// File passed to to FDICopy(), or returned to
// fdintNEXT_CABINET, is too small to be a cabinet file,
// or does not have the cabinet signature in its first 4 bytes
// FDIERROR_UNKNOWN_CABINET_VERSION Cabinet file has an unknown version number
// File passed to to FDICopy(), or returned to
// fdintNEXT_CABINET, has what looks like a cabinet file
// header, but the version of the cabinet file format
// is not one understood by this version of FDI. The
// erf.erfType field is filled in with the version number
// found in the cabinet file
// FDIERROR_CORRUPT_CABINET Cabinet file is corrupt
// FDI returns this error any time it finds a problem
// with the logical format of a cabinet file, and any
// time one of the passed-in file I/O calls fails when
// operating on a cabinet (PFNOPEN, PFNSEEK, PFNREAD,
// or PFNCLOSE). The client can distinguish these two
// cases based upon whether the last file I/O call
// failed or not
// Assuming this is not a real corruption problem in
// a cabinet file, the file I/O functions could attempt
// to do retries on failure (for example, if there is a
// temporary network connection problem). If this does
// not work, and the file I/O call has to fail, then the
// FDI client will have to clean up and call the
// FDICopy() function again.
// FDIERROR_ALLOC_FAIL Could not allocate enough memory
// FDI tried to allocate memory with the PFNALLOC
// function, but it failed
// If possible, PFNALLOC should take whatever steps
// are possible to allocate the memory requested. If
// memory is not immediately available, it might post a
// dialog asking the user to free memory, for example.
// Note that the bulk of FDI's memory allocations are
// made at FDICreate() time and when the first cabinet
// file is opened during FDICopy()
// FDIERROR_BAD_COMPR_TYPE Unknown compression type in a cabinet folder [Should never happen]
// A folder in a cabinet has an unknown compression type.
// This is probably caused by a mismatch between the version of FCI.LIB
// used to create the cabinet and the FDI.LIB used to read the cabinet
// FDIERROR_MDI_FAIL Failure decompressing data from a cabinet file
// The decompressor found an error in the data coming
// from the file cabinet. The cabinet file was corrupted.
// [When checksuming is turned on, this error should never occur]
// FDIERROR_TARGET_FILE Failure writing to target file
// FDI returns this error any time it gets an error back
// from one of the passed-in file I/O calls fails when
// writing to a file being extracted from a cabinet
// To avoid or minimize this error, the file I/O functions
// could attempt to avoid failing. A common cause might
// be disk full. In this case, the PFNWRITE function
// could have a check for free space, and put up a dialog
// asking the user to free some disk space.
// FDIERROR_RESERVE_MISMATCH Cabinets in a set do not have the same RESERVE sizes [Should never happen]
// FDI requires that the sizes of the per-cabinet, per-folder,
// and per-data block RESERVE sections be consistent across all the
// cabinets in a set
// FDIERROR_WRONG_CABINET Cabinet returned on fdintNEXT_CABINET is incorrect
// Note: This error is NEVER returned by FDICopy()
// Rather, FDICopy() keeps calling the fdintNEXT_CABINET
// callback until either the correct cabinet is specified,
// or you return ABORT.
// When FDICopy() is extracting a file that crosses a
// cabinet boundary, it calls fdintNEXT_CABINET to ask
// for the path to the next cabinet. Not being very
// trusting, FDI then checks to make sure that the
// correct continuation cabinet was supplied. It does
// this by checking the "setID" and "iCabinet" fields
// in the cabinet. FDI makes sure that the 16-bit
// setID of the continuation cabinet matches the
// cabinet file just processed, then checks that
// the cabinet number (iCabinet) is one more than the
// cabinet number for the cabinet just processed
// FDIERROR_USER_ABORT Client requested abort
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -