📄 fdi.h
字号:
/*
* FDI.H -- File Decompression Interface
*
* Copyright (C) Microsoft Corporation 1993-1997
* All Rights Reserved.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef INCLUDED_TYPES_FCI_FDI
#define INCLUDED_TYPES_FCI_FDI 1
#ifndef HUGE
#define HUGE
#endif
#ifndef FAR
#define FAR
#endif
#ifndef DIAMONDAPI
#define DIAMONDAPI __cdecl
#endif
//** Specify structure packing explicitly for clients of FDI
#pragma pack(4)
//** Don't redefine types defined in Win16 WINDOWS.H (_INC_WINDOWS)
// or Win32 WINDOWS.H (_WINDOWS_)
//
#if !defined(_INC_WINDOWS) && !defined(_WINDOWS_)
typedef int BOOL; /* f */
typedef unsigned char BYTE; /* b */
typedef unsigned int UINT; /* ui */
typedef unsigned short USHORT; /* us */
typedef unsigned long ULONG; /* ul */
#endif // _INC_WINDOWS
typedef unsigned long CHECKSUM; /* csum */
typedef unsigned long UOFF; /* uoff - uncompressed offset */
typedef unsigned long COFF; /* coff - cabinet file offset */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
/*** ERF - Error structure
*
* This structure returns error information from FCI/FDI. The caller should
* not modify this structure.
*/
typedef struct {
int erfOper; // FCI/FDI error code -- see FDIERROR_XXX
// and FCIERR_XXX equates for details.
int erfType; // Optional error value filled in by FCI/FDI.
// For FCI, this is usually the C run-time
// *errno* value.
BOOL fError; // TRUE => error present
} ERF; /* erf */
typedef ERF FAR *PERF; /* perf */
#ifdef _DEBUG
// don't hide statics from map during debugging
#define STATIC
#else // !DEBUG
#define STATIC static
#endif // !DEBUG
#define CB_MAX_CHUNK 32768U
#define CB_MAX_DISK 0x7ffffffL
#define CB_MAX_FILENAME 256
#define CB_MAX_CABINET_NAME 256
#define CB_MAX_CAB_PATH 256
#define CB_MAX_DISK_NAME 256
/*** tcompXXX - Compression types
*
* These are passed to FCIAddFile(), and are also stored in the CFFOLDER
* structures in cabinet files.
*
* NOTE: We reserve bits for the TYPE, QUANTUM_LEVEL, and QUANTUM_MEM
* to provide room for future expansion. Since this value is stored
* in the CFDATA records in the cabinet file, we don't want to
* have to change the format for existing compression configurations
* if we add new ones in the future. This will allows us to read
* old cabinet files in the future.
*/
typedef unsigned short TCOMP; /* tcomp */
#define tcompMASK_TYPE 0x000F // Mask for compression type
#define tcompTYPE_NONE 0x0000 // No compression
#define tcompTYPE_MSZIP 0x0001 // MSZIP
#define tcompTYPE_QUANTUM 0x0002 // Quantum
#define tcompTYPE_LZX 0x0003 // LZX
#define tcompBAD 0x000F // Unspecified compression type
#define tcompMASK_LZX_WINDOW 0x1F00 // Mask for LZX Compression Memory
#define tcompLZX_WINDOW_LO 0x0F00 // Lowest LZX Memory (15)
#define tcompLZX_WINDOW_HI 0x1500 // Highest LZX Memory (21)
#define tcompSHIFT_LZX_WINDOW 8 // Amount to shift over to get int
#define tcompMASK_QUANTUM_LEVEL 0x00F0 // Mask for Quantum Compression Level
#define tcompQUANTUM_LEVEL_LO 0x0010 // Lowest Quantum Level (1)
#define tcompQUANTUM_LEVEL_HI 0x0070 // Highest Quantum Level (7)
#define tcompSHIFT_QUANTUM_LEVEL 4 // Amount to shift over to get int
#define tcompMASK_QUANTUM_MEM 0x1F00 // Mask for Quantum Compression Memory
#define tcompQUANTUM_MEM_LO 0x0A00 // Lowest Quantum Memory (10)
#define tcompQUANTUM_MEM_HI 0x1500 // Highest Quantum Memory (21)
#define tcompSHIFT_QUANTUM_MEM 8 // Amount to shift over to get int
#define tcompMASK_RESERVED 0xE000 // Reserved bits (high 3 bits)
#define CompressionTypeFromTCOMP(tc) \
((tc) & tcompMASK_TYPE)
#define CompressionLevelFromTCOMP(tc) \
(((tc) & tcompMASK_QUANTUM_LEVEL) >> tcompSHIFT_QUANTUM_LEVEL)
#define CompressionMemoryFromTCOMP(tc) \
(((tc) & tcompMASK_QUANTUM_MEM) >> tcompSHIFT_QUANTUM_MEM)
#define TCOMPfromTypeLevelMemory(t,l,m) \
(((m) << tcompSHIFT_QUANTUM_MEM ) | \
((l) << tcompSHIFT_QUANTUM_LEVEL) | \
( t ))
#define LZXCompressionWindowFromTCOMP(tc) \
(((tc) & tcompMASK_LZX_WINDOW) >> tcompSHIFT_LZX_WINDOW)
#define TCOMPfromLZXWindow(w) \
(((w) << tcompSHIFT_LZX_WINDOW ) | \
( tcompTYPE_LZX ))
//** Revert to default structure packing
#pragma pack()
#endif // !INCLUDED_TYPES_FCI_FDI
/*
* Concepts:
* A *cabinet* file contains one or more *folders*. A folder contains
* one or more (pieces of) *files*. A folder is by definition a
* decompression unit, i.e., to extract a file from a folder, all of
* the data from the start of the folder up through and including the
* desired file must be read and decompressed.
*
* A folder can span one (or more) cabinet boundaries, and by implication
* a file can also span one (or more) cabinet boundaries. Indeed, more
* than one file can span a cabinet boundary, since FCI concatenates
* files together into a single data stream before compressing (actually,
* at most one file will span any one cabinet boundary, but FCI does
* not know which file this is, since the mapping from uncompressed bytes
* to compressed bytes is pretty obscure. Also, since FCI compresses
* in blocks of 32K (at present), any files with data in a 32K block that
* spans a cabinet boundary require FDI to read both cabinet files
* to get the two halves of the compressed block).
*
* Overview:
* The File Decompression Interface is used to simplify the reading of
* cabinet files. A setup program will proceed in a manner very
* similar to the pseudo code below. An FDI context is created, the
* setup program calls FDICopy() for each cabinet to be processed. For
* each file in the cabinet, FDICopy() calls a notification callback
* routine, asking the setup program if the file should be copied.
* This call-back approach is great because it allows the cabinet file
* to be read and decompressed in an optimal manner, and also makes FDI
* independent of the run-time environment -- FDI makes *no* C run-time
* calls whatsoever. All memory allocation and file I/O functions are
* passed into FDI by the client.
*
* main(...)
* {
* // Read INF file to construct list of desired files.
* // Ideally, these would be sorted in the same order as the
* // files appear in the cabinets, so that you can just walk
* // down the list in response to fdintCOPY_FILE notifications.
*
* // Construct list of required cabinets.
*
* hfdi = FDICreate(...); // Create FDI context
* For (cabinet in List of Cabinets) {
* FDICopy(hfdi,cabinet,fdiNotify,...); // Process each cabinet
* }
* FDIDestroy(hfdi);
* ...
* }
*
* // Notification callback function
* fdiNotify(fdint,...)
* {
* If (User Aborted) // Permit cancellation
* if (fdint == fdintCLOSE_FILE_INFO)
* close open file
* return -1;
* switch (fdint) {
* case fdintCOPY_FILE: // File to copy, maybe
* // Check file against list of desired files
* if want to copy file
* open destination file and return handle
* else
* return NULL; // Skip file
* case fdintCLOSE_FILE_INFO:
* close file
* set date, time, and attributes
*
* case fdintNEXT_CABINET:
* if not an error callback
* Tell FDI to use suggested directory name
* else
* Tell user what the problem was, and prompt
* for a new disk and/or path.
* if user aborts
* Tell FDI to abort
* else
* return to FDI to try another cabinet
*
* default:
* return 0; // more messages may be defined
* ...
* }
*
* Error Handling Suggestions:
* Since you the client have passed in *all* of the functions that
* FDI uses to interact with the "outside" world, you are in prime
* position to understand and deal with errors.
*
* The general philosophy of FDI is to pass all errors back up to
* the client. FDI returns fairly generic error codes in the case
* where one of the callback functions (PFNOPEN, PFNREAD, etc.) fail,
* since it assumes that the callback function will save enough
* information in a static/global so that when FDICopy() returns
* fail, the client can examine this information and report enough
* detail about the problem that the user can take corrective action.
*
* For very specific errors (CORRUPT_CABINET, for example), FDI returns
* very specific error codes.
*
* THE BEST POLICY IS FOR YOUR CALLBACK ROUTINES TO AVOID RETURNING
* ERRORS TO FDI!
*
* Examples:
* (1) If the disk is getting full, instead of returning an error
* from your PFNWRITE function, you should -- inside your
* PFNWRITE function -- put up a dialog telling the user to free
* some disk space.
* (2) When you get the fdintNEXT_CABINET notification, you should
* verify that the cabinet you return is the correct one (call
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -