📄 cabinet.hpp
字号:
//---------------------------------------------------------------------------
// Copyright (C) 1998, Interscope Ltd. All rights reserved.
// Reproduction or distribution of this program, or any portion of it,
// is permitted only if this header is kept as it is.
// For more information, contact:
//
// Interscope Ltd., 5 Culturii St., 5th floor, 4800 Baia Mare, Romania
// Phone/Fax: +40-62-215023
// E-mail: office@interscope.ro
//
// $Author: Levente Farkas $
// $Date: 5/13/98 12:02a $
// $Modtime: 4/27/98 6:50a $
// $Revision: 51 $
// $Archive: /Interscope/Thebe/InstallMaster/Cabinet.hpp $
// $Workfile: Cabinet.hpp $
//-----------------------------------------------------------------------
#ifndef __Cabinet_Hpp__
#define __Cabinet_Hpp__
// Define the following symbol if compiling using precompiled headers through
// header file StdAfx.H
// #define __STDAFX__
//
// Define the following symbol if used in a MFC project
// #define __MFC__
#ifdef __MFC__
#undef __STDAFX__
#define __STDAFX__
#endif
// If you want 2 trace the progress of compression/decompression, define the
// symbols below
// #define __TRACE_CAB_MEMORY__
// #define __TRACE_CAB_COMPRESSION__
// #define __TRACE_CAB_EXTRACTION__
// Define one of the following symbols 2 include only the code you need
// in your project
// #define __CAB_BUILD__
// #define __CAB_EXTRACT__
#if !defined(__CAB_BUILD__) && !defined(__CAB_EXTRACT__)
#error You did not specified what cabinet functionality to include
#endif
#include <String>
#include "Portable.H"
#include "StringHelper.Hpp"
#include "Path.Hpp"
#ifdef __CAB_BUILD__
#include "FCI.H" // File Compression Interface
#endif
#ifdef __CAB_EXTRACT__
#include "FDI.H" // File Decompression Interface
#endif
using namespace std;
//--- Cabinet handler base -----------------------------------------------
// These classes implement cabinet file (.CAB) file handlig. They require the
// code of the Microsoft Cabinet API and the headers and sources that implement
// C wrappers for the API. These reside in the files CABINET.DLL (the API code) and
// in the files FCI.H, FDI.H, FCIDLL.C and FDIDLL.C. These files are part of the
// Microsoft Cabinet SDK which can be obtained from Microsft SiteBuilder website
// at http://www.microsoft.com/sbnmember/download/download.asp
//
// Warning: These classes are not thread safe. So, do not mess with the same instance
// of either CCabinetBuilder or CCabinetExtractor from withing different threads
// However, since each instance of these classes keeps its own compression/decompression
// context, you can use multiple instances and you even can instantiate separate instances
// in separate threads
class CCabinetBase
{
// Data members
protected:
ERF m_CabinetError;
BOOL m_bStatus; // TRUE when everything is OK
public:
CPath m_CabinetPath;
string m_strCabinetName;
// Implementation
public:
CCabinetBase(): m_bStatus(FALSE) { ZeroMemory(&m_CabinetError,sizeof(m_CabinetError)); }
BOOL GetStatus() const { return m_bStatus && !m_CabinetError.fError; }
int GetErrorCode() const { return m_CabinetError.erfOper; }
int GetErrorCodeEx() const { return m_CabinetError.erfType; }
// Callbacks
protected:
static void HUGE * FAR DIAMONDAPI MemAlloc(ULONG cbSize);
static void FAR DIAMONDAPI MemFree(void HUGE *ptrMemory);
static int FAR DIAMONDAPI FileOpen(char FAR *pszFile, int oFlag, int pMode, int FAR *ptrErr, void FAR *pv);
static UINT FAR DIAMONDAPI FileRead (int hFile, void FAR *ptrBuffer, UINT cbRead, int FAR *ptrErr, void FAR *pv);
static UINT FAR DIAMONDAPI FileWrite(int hFile, void FAR *ptrBuffer, UINT cbWrite, int FAR *ptrErr, void FAR *pv);
static long FAR DIAMONDAPI FileSeek (int hFile, long offset, int seekType, int FAR *ptrErr, void FAR *pv);
static int FAR DIAMONDAPI FileClose(int hFile, int FAR *ptrErr, void FAR *pv);
};
//--- Class 4 cabinet creation -------------------------------------------
#ifdef __CAB_BUILD__
// Warning: File paths are not stored in the .CAB file(s), so that you will
// have 2 remember or know where 2 extract them later
class CCabinetBuilder: public CCabinetBase
{
// Data members
protected:
HFCI m_hContext;
CCAB m_CabinetInfo;
int m_nLastStartDisk;
string m_strLastCabinet;
public:
string m_strDiskName;
ULONG m_cbFirstCabSize; // Size 4 the first .CAB file
ULONG m_cbCabSize; // Size 4 the rest of the .CAB files
ULONG m_cbTreshold; // Flush 2 cabinet after each block of this size
USHORT m_nID; // Unique ID
UINT m_cbReserveCFHeader; // Space to reserve in CFHEADER
UINT m_cbReserveCFFolder; // Space to reserve in CFFOLDER
UINT m_cbReserveCFData; // Space to reserve in CFDATA
// Construction and destruction
public:
CCabinetBuilder(USHORT nID, ULONG cbFirstCabSize, ULONG cbCabSize, ULONG cbTreshold);
BOOL InitCabinet(LPCTSTR lpcszCabPath, LPCTSTR lpcszCabName, LPCTSTR lpcszDiskName, BOOL bCreatePath =TRUE);
void ReserveHeader(UINT reserve) { m_cbReserveCFHeader =reserve; }
void ReserveFolder(UINT reserve) { m_cbReserveCFFolder =reserve; }
void ReserveData(UINT reserve) { m_cbReserveCFData =reserve; }
BOOL AddFile(LPTSTR lpszFileName, LPTSTR lpszStoreAs =NULL, BOOL bCompress =TRUE, BOOL bExecuteOnExtract =FALSE);
BOOL FlushFolder();
BOOL FlushCabinet();
void WaitUntilDone() { FlushCabinet(); }
virtual ~CCabinetBuilder();
// Callbacks
protected:
static int FAR DIAMONDAPI FileDelete(char FAR *pszFile, int FAR *ptrErr, void FAR *pv);
static BOOL FAR DIAMONDAPI GetTempFile(char *pszTempName, int cbTempName, void FAR *pv);
static int FAR DIAMONDAPI GetFileInfo(char *pszName, USHORT *pdate, USHORT *ptime, USHORT *pattribs, int FAR *ptrErr, void FAR *pv);
static BOOL FAR DIAMONDAPI GetNextCabinet(PCCAB pccab, ULONG cbPrevCab, void FAR *pv);
static int FAR DIAMONDAPI NotifyFilePlaced(PCCAB pccab, char *pszFile, long cbFile, BOOL bContinuation, void FAR *pv);
static long FAR DIAMONDAPI NotifyProgress(UINT typeStatus, ULONG cb1, ULONG cb2, void FAR *pv);
// Callback helpers
protected:
virtual PFNFCIALLOC MemAllocProc() const { return CCabinetBase::MemAlloc; }
virtual PFNFCIFREE MemFreeProc() const { return CCabinetBase::MemFree; }
virtual PFNFCIOPEN FileOpenProc() const { return CCabinetBase::FileOpen; }
virtual PFNFCIREAD FileReadProc() const { return CCabinetBase::FileRead; }
virtual PFNFCIWRITE FileWriteProc() const { return CCabinetBase::FileWrite; }
virtual PFNFCISEEK FileSeekProc() const { return CCabinetBase::FileSeek; }
virtual PFNFCICLOSE FileCloseProc() const { return CCabinetBase::FileClose; }
virtual PFNFCIDELETE FileDeleteProc() const { return CCabinetBuilder::FileDelete; }
virtual PFNFCIGETTEMPFILE GetTempFileProc() const { return CCabinetBuilder::GetTempFile; }
virtual PFNFCIGETOPENINFO GetFileInfoProc() const { return CCabinetBuilder::GetFileInfo; }
virtual PFNFCIGETNEXTCABINET GetNextCabinetProc() const { return CCabinetBuilder::GetNextCabinet; }
virtual PFNFCISTATUS NotifyProgressProc() const { return CCabinetBuilder::NotifyProgress; }
virtual PFNFCIFILEPLACED NotifyFilePlacedProc() const { return CCabinetBuilder::NotifyFilePlaced; }
// Miscellaneous helpers
public:
virtual void ManufactureDiskName(PCCAB cabinfo);
virtual void ManufactureCabinetName(PCCAB cabinfo);
protected:
virtual BOOL NotifyPlaced(char *pszFile, long cbFile, BOOL bContinuation, int nDisk, char *pszCabinet);
virtual BOOL NotifyCompress(ULONG cbOriginal, ULONG cbCompressed);
virtual BOOL NotifyFolderFlush(ULONG cbSize, ULONG cbWritten);
virtual ULONG NotifyCabinetFlush(ULONG cbEstimatedSize, ULONG cbActualSize);
};
#endif
//--- Compression 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:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -