[FORMATTING] TABs -> 4 spaces

svn path=/trunk/; revision=32086
This commit is contained in:
Colin Finck 2008-02-02 11:57:16 +00:00
parent d91afce7df
commit 8dc242259f
10 changed files with 3790 additions and 3800 deletions

File diff suppressed because it is too large Load diff

View file

@ -65,18 +65,18 @@
extern ULONG DebugTraceLevel;
#define DPRINT(_t_, _x_) \
if (((DebugTraceLevel & NORMAL_MASK) >= _t_) || \
((DebugTraceLevel & _t_) > NORMAL_MASK)) { \
printf("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \
printf _x_ ; \
}
if (((DebugTraceLevel & NORMAL_MASK) >= _t_) || \
((DebugTraceLevel & _t_) > NORMAL_MASK)) { \
printf("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \
printf _x_ ; \
}
#define ASSERT(_b_) { \
if (!(_b_)) { \
printf("(%s:%d)(%s) ASSERTION: ", __FILE__, __LINE__, __FUNCTION__); \
printf(#_b_); \
exit(0); \
} \
if (!(_b_)) { \
printf("(%s:%d)(%s) ASSERTION: ", __FILE__, __LINE__, __FUNCTION__); \
printf(#_b_); \
exit(0); \
} \
}
#else /* DBG */
@ -123,108 +123,108 @@ extern ULONG DebugTraceLevel;
typedef struct _CFHEADER
{
ULONG Signature; // File signature 'MSCF' (CAB_SIGNATURE)
ULONG Reserved1; // Reserved field
ULONG CabinetSize; // Cabinet file size
ULONG Reserved2; // Reserved field
ULONG FileTableOffset; // Offset of first CFFILE
ULONG Reserved3; // Reserved field
USHORT Version; // Cabinet version (CAB_VERSION)
USHORT FolderCount; // Number of folders
USHORT FileCount; // Number of files
USHORT Flags; // Cabinet flags (CAB_FLAG_*)
USHORT SetID; // Cabinet set id
USHORT CabinetNumber; // Zero-based cabinet number
ULONG Signature; // File signature 'MSCF' (CAB_SIGNATURE)
ULONG Reserved1; // Reserved field
ULONG CabinetSize; // Cabinet file size
ULONG Reserved2; // Reserved field
ULONG FileTableOffset; // Offset of first CFFILE
ULONG Reserved3; // Reserved field
USHORT Version; // Cabinet version (CAB_VERSION)
USHORT FolderCount; // Number of folders
USHORT FileCount; // Number of files
USHORT Flags; // Cabinet flags (CAB_FLAG_*)
USHORT SetID; // Cabinet set id
USHORT CabinetNumber; // Zero-based cabinet number
/* Optional fields (depends on Flags)
USHORT CabinetResSize // Per-cabinet reserved area size
char FolderResSize // Per-folder reserved area size
char FileResSize // Per-file reserved area size
char CabinetReserved[] // Per-cabinet reserved area
char CabinetPrev[] // Name of previous cabinet file
char DiskPrev[] // Name of previous disk
char CabinetNext[] // Name of next cabinet file
char DiskNext[] // Name of next disk
USHORT CabinetResSize // Per-cabinet reserved area size
char FolderResSize // Per-folder reserved area size
char FileResSize // Per-file reserved area size
char CabinetReserved[] // Per-cabinet reserved area
char CabinetPrev[] // Name of previous cabinet file
char DiskPrev[] // Name of previous disk
char CabinetNext[] // Name of next cabinet file
char DiskNext[] // Name of next disk
*/
} CFHEADER, *PCFHEADER;
typedef struct _CFFOLDER
{
ULONG DataOffset; // Absolute offset of first CFDATA block in this folder
USHORT DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet
USHORT CompressionType; // Type of compression used for all CFDATA blocks in this folder
ULONG DataOffset; // Absolute offset of first CFDATA block in this folder
USHORT DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet
USHORT CompressionType; // Type of compression used for all CFDATA blocks in this folder
/* Optional fields (depends on Flags)
char FolderReserved[] // Per-folder reserved area
char FolderReserved[] // Per-folder reserved area
*/
} CFFOLDER, *PCFFOLDER;
typedef struct _CFFILE
{
ULONG FileSize; // Uncompressed file size in bytes
ULONG FileOffset; // Uncompressed offset of file in the folder
USHORT FileControlID; // File control ID (CAB_FILE_*)
USHORT FileDate; // File date stamp, as used by DOS
USHORT FileTime; // File time stamp, as used by DOS
USHORT Attributes; // File attributes (CAB_ATTRIB_*)
ULONG FileSize; // Uncompressed file size in bytes
ULONG FileOffset; // Uncompressed offset of file in the folder
USHORT FileControlID; // File control ID (CAB_FILE_*)
USHORT FileDate; // File date stamp, as used by DOS
USHORT FileTime; // File time stamp, as used by DOS
USHORT Attributes; // File attributes (CAB_ATTRIB_*)
/* After this is the NULL terminated filename */
} CFFILE, *PCFFILE;
typedef struct _CFDATA
{
ULONG Checksum; // Checksum of CFDATA entry
USHORT CompSize; // Number of compressed bytes in this block
USHORT UncompSize; // Number of uncompressed bytes in this block
ULONG Checksum; // Checksum of CFDATA entry
USHORT CompSize; // Number of compressed bytes in this block
USHORT UncompSize; // Number of uncompressed bytes in this block
/* Optional fields (depends on Flags)
char DataReserved[] // Per-datablock reserved area
char DataReserved[] // Per-datablock reserved area
*/
} CFDATA, *PCFDATA;
typedef struct _CFDATA_NODE
{
struct _CFDATA_NODE *Next;
struct _CFDATA_NODE *Prev;
ULONG ScratchFilePosition; // Absolute offset in scratch file
ULONG AbsoluteOffset; // Absolute offset in cabinet
ULONG UncompOffset; // Uncompressed offset in folder
CFDATA Data;
struct _CFDATA_NODE *Next;
struct _CFDATA_NODE *Prev;
ULONG ScratchFilePosition; // Absolute offset in scratch file
ULONG AbsoluteOffset; // Absolute offset in cabinet
ULONG UncompOffset; // Uncompressed offset in folder
CFDATA Data;
} CFDATA_NODE, *PCFDATA_NODE;
typedef struct _CFFOLDER_NODE
{
struct _CFFOLDER_NODE *Next;
struct _CFFOLDER_NODE *Prev;
ULONG UncompOffset; // File size accumulator
ULONG AbsoluteOffset;
ULONG TotalFolderSize; // Total size of folder in current disk
PCFDATA_NODE DataListHead;
PCFDATA_NODE DataListTail;
ULONG Index;
bool Commit; // true if the folder should be committed
bool Delete; // true if marked for deletion
CFFOLDER Folder;
struct _CFFOLDER_NODE *Next;
struct _CFFOLDER_NODE *Prev;
ULONG UncompOffset; // File size accumulator
ULONG AbsoluteOffset;
ULONG TotalFolderSize; // Total size of folder in current disk
PCFDATA_NODE DataListHead;
PCFDATA_NODE DataListTail;
ULONG Index;
bool Commit; // true if the folder should be committed
bool Delete; // true if marked for deletion
CFFOLDER Folder;
} CFFOLDER_NODE, *PCFFOLDER_NODE;
typedef struct _CFFILE_NODE
{
struct _CFFILE_NODE *Next;
struct _CFFILE_NODE *Prev;
CFFILE File;
char* FileName;
PCFDATA_NODE DataBlock; // First data block of file. NULL if not known
bool Commit; // true if the file data should be committed
bool Delete; // true if marked for deletion
PCFFOLDER_NODE FolderNode; // Folder this file belong to
struct _CFFILE_NODE *Next;
struct _CFFILE_NODE *Prev;
CFFILE File;
char* FileName;
PCFDATA_NODE DataBlock; // First data block of file. NULL if not known
bool Commit; // true if the file data should be committed
bool Delete; // true if marked for deletion
PCFFOLDER_NODE FolderNode; // Folder this file belong to
} CFFILE_NODE, *PCFFILE_NODE;
typedef struct _CAB_SEARCH
{
char Search[MAX_PATH]; // Search criteria
PCFFILE_NODE Next; // Pointer to next node
PCFFILE File; // Pointer to current CFFILE
char* FileName; // Current filename
char Search[MAX_PATH]; // Search criteria
PCFFILE_NODE Next; // Pointer to next node
PCFFILE File; // Pointer to current CFFILE
char* FileName; // Current filename
} CAB_SEARCH, *PCAB_SEARCH;
@ -249,20 +249,20 @@ typedef struct _CAB_SEARCH
class CCABCodec {
public:
/* Default constructor */
CCABCodec() {};
/* Default destructor */
virtual ~CCABCodec() {};
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength) = 0;
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength) = 0;
/* Default constructor */
CCABCodec() {};
/* Default destructor */
virtual ~CCABCodec() {};
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength) = 0;
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength) = 0;
};
@ -285,193 +285,193 @@ public:
class CCFDATAStorage {
public:
/* Default constructor */
CCFDATAStorage();
/* Default destructor */
virtual ~CCFDATAStorage();
ULONG Create(char* FileName);
ULONG Destroy();
ULONG Truncate();
ULONG Position();
ULONG Seek(LONG Position);
ULONG ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead);
ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten);
/* Default constructor */
CCFDATAStorage();
/* Default destructor */
virtual ~CCFDATAStorage();
ULONG Create(char* FileName);
ULONG Destroy();
ULONG Truncate();
ULONG Position();
ULONG Seek(LONG Position);
ULONG ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead);
ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten);
private:
char FullName[MAX_PATH];
bool FileCreated;
FILEHANDLE FileHandle;
char FullName[MAX_PATH];
bool FileCreated;
FILEHANDLE FileHandle;
};
#endif /* CAB_READ_ONLY */
class CCabinet {
public:
/* Default constructor */
CCabinet();
/* Default destructor */
virtual ~CCabinet();
/* Determines if a character is a separator */
bool IsSeparator(char Char);
/* Replaces \ or / with the one used be the host environment */
char* ConvertPath(char* Path, bool Allocate);
/* Returns a pointer to the filename part of a fully qualified filename */
char* GetFileName(char* Path);
/* Removes a filename from a fully qualified filename */
void RemoveFileName(char* Path);
/* Normalizes a path */
bool NormalizePath(char* Path, ULONG Length);
/* Returns name of cabinet file */
char* GetCabinetName();
/* Sets the name of the cabinet file */
void SetCabinetName(char* FileName);
/* Sets destination path for extracted files */
void SetDestinationPath(char* DestinationPath);
/* Sets cabinet reserved file */
bool SetCabinetReservedFile(char* FileName);
/* Returns cabinet reserved file */
char* GetCabinetReservedFile();
/* Returns destination path */
char* GetDestinationPath();
/* Returns zero-based current disk number */
ULONG GetCurrentDiskNumber();
/* Opens the current cabinet file */
ULONG Open();
/* Closes the current open cabinet file */
void Close();
/* Locates the first file in the current cabinet file that matches a search criteria */
ULONG FindFirst(char* FileName, PCAB_SEARCH Search);
/* Locates the next file in the current cabinet file */
ULONG FindNext(PCAB_SEARCH Search);
/* Extracts a file from the current cabinet file */
ULONG ExtractFile(char* FileName);
/* Select codec engine to use */
void SelectCodec(ULONG Id);
/* Default constructor */
CCabinet();
/* Default destructor */
virtual ~CCabinet();
/* Determines if a character is a separator */
bool IsSeparator(char Char);
/* Replaces \ or / with the one used be the host environment */
char* ConvertPath(char* Path, bool Allocate);
/* Returns a pointer to the filename part of a fully qualified filename */
char* GetFileName(char* Path);
/* Removes a filename from a fully qualified filename */
void RemoveFileName(char* Path);
/* Normalizes a path */
bool NormalizePath(char* Path, ULONG Length);
/* Returns name of cabinet file */
char* GetCabinetName();
/* Sets the name of the cabinet file */
void SetCabinetName(char* FileName);
/* Sets destination path for extracted files */
void SetDestinationPath(char* DestinationPath);
/* Sets cabinet reserved file */
bool SetCabinetReservedFile(char* FileName);
/* Returns cabinet reserved file */
char* GetCabinetReservedFile();
/* Returns destination path */
char* GetDestinationPath();
/* Returns zero-based current disk number */
ULONG GetCurrentDiskNumber();
/* Opens the current cabinet file */
ULONG Open();
/* Closes the current open cabinet file */
void Close();
/* Locates the first file in the current cabinet file that matches a search criteria */
ULONG FindFirst(char* FileName, PCAB_SEARCH Search);
/* Locates the next file in the current cabinet file */
ULONG FindNext(PCAB_SEARCH Search);
/* Extracts a file from the current cabinet file */
ULONG ExtractFile(char* FileName);
/* Select codec engine to use */
void SelectCodec(ULONG Id);
#ifndef CAB_READ_ONLY
/* Creates a new cabinet file */
ULONG NewCabinet();
/* Forces a new disk to be created */
ULONG NewDisk();
/* Forces a new folder to be created */
ULONG NewFolder();
/* Writes a file to scratch storage */
ULONG WriteFileToScratchStorage(PCFFILE_NODE FileNode);
/* Forces the current disk to be written */
ULONG WriteDisk(ULONG MoreDisks);
/* Commits the current disk */
ULONG CommitDisk(ULONG MoreDisks);
/* Closes the current disk */
ULONG CloseDisk();
/* Closes the current cabinet */
ULONG CloseCabinet();
/* Adds a file to the current disk */
ULONG AddFile(char* FileName);
/* Sets the maximum size of the current disk */
void SetMaxDiskSize(ULONG Size);
/* Creates a new cabinet file */
ULONG NewCabinet();
/* Forces a new disk to be created */
ULONG NewDisk();
/* Forces a new folder to be created */
ULONG NewFolder();
/* Writes a file to scratch storage */
ULONG WriteFileToScratchStorage(PCFFILE_NODE FileNode);
/* Forces the current disk to be written */
ULONG WriteDisk(ULONG MoreDisks);
/* Commits the current disk */
ULONG CommitDisk(ULONG MoreDisks);
/* Closes the current disk */
ULONG CloseDisk();
/* Closes the current cabinet */
ULONG CloseCabinet();
/* Adds a file to the current disk */
ULONG AddFile(char* FileName);
/* Sets the maximum size of the current disk */
void SetMaxDiskSize(ULONG Size);
#endif /* CAB_READ_ONLY */
/* Default event handlers */
/* Default event handlers */
/* Handler called when a file is about to be overridden */
virtual bool OnOverwrite(PCFFILE Entry, char* FileName);
/* Handler called when a file is about to be extracted */
virtual void OnExtract(PCFFILE Entry, char* FileName);
/* Handler called when a new disk is to be processed */
virtual void OnDiskChange(char* CabinetName, char* DiskLabel);
/* Handler called when a file is about to be overridden */
virtual bool OnOverwrite(PCFFILE Entry, char* FileName);
/* Handler called when a file is about to be extracted */
virtual void OnExtract(PCFFILE Entry, char* FileName);
/* Handler called when a new disk is to be processed */
virtual void OnDiskChange(char* CabinetName, char* DiskLabel);
#ifndef CAB_READ_ONLY
/* Handler called when a file is about to be added */
virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Handler called when a cabinet need a name */
virtual bool OnCabinetName(ULONG Number, char* Name);
/* Handler called when a disk needs a label */
virtual bool OnDiskLabel(ULONG Number, char* Label);
/* Handler called when a file is about to be added */
virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Handler called when a cabinet need a name */
virtual bool OnCabinetName(ULONG Number, char* Name);
/* Handler called when a disk needs a label */
virtual bool OnDiskLabel(ULONG Number, char* Label);
#endif /* CAB_READ_ONLY */
private:
PCFFOLDER_NODE LocateFolderNode(ULONG Index);
ULONG GetAbsoluteOffset(PCFFILE_NODE File);
ULONG LocateFile(char* FileName, PCFFILE_NODE *File);
ULONG ReadString(char* String, ULONG MaxLength);
ULONG ReadFileTable();
ULONG ReadDataBlocks(PCFFOLDER_NODE FolderNode);
PCFFOLDER_NODE NewFolderNode();
PCFFILE_NODE NewFileNode();
PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode);
void DestroyDataNodes(PCFFOLDER_NODE FolderNode);
void DestroyFileNodes();
void DestroyDeletedFileNodes();
void DestroyFolderNodes();
void DestroyDeletedFolderNodes();
ULONG ComputeChecksum(void* Buffer, ULONG Size, ULONG Seed);
ULONG ReadBlock(void* Buffer, ULONG Size, PULONG BytesRead);
PCFFOLDER_NODE LocateFolderNode(ULONG Index);
ULONG GetAbsoluteOffset(PCFFILE_NODE File);
ULONG LocateFile(char* FileName, PCFFILE_NODE *File);
ULONG ReadString(char* String, ULONG MaxLength);
ULONG ReadFileTable();
ULONG ReadDataBlocks(PCFFOLDER_NODE FolderNode);
PCFFOLDER_NODE NewFolderNode();
PCFFILE_NODE NewFileNode();
PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode);
void DestroyDataNodes(PCFFOLDER_NODE FolderNode);
void DestroyFileNodes();
void DestroyDeletedFileNodes();
void DestroyFolderNodes();
void DestroyDeletedFolderNodes();
ULONG ComputeChecksum(void* Buffer, ULONG Size, ULONG Seed);
ULONG ReadBlock(void* Buffer, ULONG Size, PULONG BytesRead);
#ifndef CAB_READ_ONLY
ULONG InitCabinetHeader();
ULONG WriteCabinetHeader(bool MoreDisks);
ULONG WriteFolderEntries();
ULONG WriteFileEntries();
ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode);
ULONG WriteDataBlock();
ULONG GetAttributesOnFile(PCFFILE_NODE File);
ULONG SetAttributesOnFile(PCFFILE_NODE File);
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
ULONG InitCabinetHeader();
ULONG WriteCabinetHeader(bool MoreDisks);
ULONG WriteFolderEntries();
ULONG WriteFileEntries();
ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode);
ULONG WriteDataBlock();
ULONG GetAttributesOnFile(PCFFILE_NODE File);
ULONG SetAttributesOnFile(PCFFILE_NODE File);
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
#if !defined(WIN32)
void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);
void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);
#endif
#endif /* CAB_READ_ONLY */
ULONG CurrentDiskNumber; // Zero based disk number
char CabinetName[256]; // Filename of current cabinet
char CabinetPrev[256]; // Filename of previous cabinet
char DiskPrev[256]; // Label of cabinet in file CabinetPrev
char CabinetNext[256]; // Filename of next cabinet
char DiskNext[256]; // Label of cabinet in file CabinetNext
ULONG TotalHeaderSize; // Size of header and optional fields
ULONG NextFieldsSize; // Size of next cabinet name and next disk label
ULONG TotalFolderSize; // Size of all folder entries
ULONG TotalFileSize; // Size of all file entries
ULONG FolderUncompSize; // Uncompressed size of folder
ULONG BytesLeftInBlock; // Number of bytes left in current block
bool ReuseBlock;
char DestPath[MAX_PATH];
char CabinetReservedFile[MAX_PATH];
void* CabinetReservedFileBuffer;
ULONG CabinetReservedFileSize;
FILEHANDLE FileHandle;
bool FileOpen;
CFHEADER CABHeader;
ULONG CabinetReserved;
ULONG FolderReserved;
ULONG DataReserved;
PCFFOLDER_NODE FolderListHead;
PCFFOLDER_NODE FolderListTail;
PCFFOLDER_NODE CurrentFolderNode;
PCFDATA_NODE CurrentDataNode;
PCFFILE_NODE FileListHead;
PCFFILE_NODE FileListTail;
CCABCodec *Codec;
ULONG CodecId;
bool CodecSelected;
void* InputBuffer;
void* CurrentIBuffer; // Current offset in input buffer
ULONG CurrentIBufferSize; // Bytes left in input buffer
void* OutputBuffer;
ULONG TotalCompSize; // Total size of current CFDATA block
void* CurrentOBuffer; // Current offset in output buffer
ULONG CurrentOBufferSize; // Bytes left in output buffer
ULONG BytesLeftInCabinet;
bool RestartSearch;
ULONG LastFileOffset; // Uncompressed offset of last extracted file
ULONG CurrentDiskNumber; // Zero based disk number
char CabinetName[256]; // Filename of current cabinet
char CabinetPrev[256]; // Filename of previous cabinet
char DiskPrev[256]; // Label of cabinet in file CabinetPrev
char CabinetNext[256]; // Filename of next cabinet
char DiskNext[256]; // Label of cabinet in file CabinetNext
ULONG TotalHeaderSize; // Size of header and optional fields
ULONG NextFieldsSize; // Size of next cabinet name and next disk label
ULONG TotalFolderSize; // Size of all folder entries
ULONG TotalFileSize; // Size of all file entries
ULONG FolderUncompSize; // Uncompressed size of folder
ULONG BytesLeftInBlock; // Number of bytes left in current block
bool ReuseBlock;
char DestPath[MAX_PATH];
char CabinetReservedFile[MAX_PATH];
void* CabinetReservedFileBuffer;
ULONG CabinetReservedFileSize;
FILEHANDLE FileHandle;
bool FileOpen;
CFHEADER CABHeader;
ULONG CabinetReserved;
ULONG FolderReserved;
ULONG DataReserved;
PCFFOLDER_NODE FolderListHead;
PCFFOLDER_NODE FolderListTail;
PCFFOLDER_NODE CurrentFolderNode;
PCFDATA_NODE CurrentDataNode;
PCFFILE_NODE FileListHead;
PCFFILE_NODE FileListTail;
CCABCodec *Codec;
ULONG CodecId;
bool CodecSelected;
void* InputBuffer;
void* CurrentIBuffer; // Current offset in input buffer
ULONG CurrentIBufferSize; // Bytes left in input buffer
void* OutputBuffer;
ULONG TotalCompSize; // Total size of current CFDATA block
void* CurrentOBuffer; // Current offset in output buffer
ULONG CurrentOBufferSize; // Bytes left in output buffer
ULONG BytesLeftInCabinet;
bool RestartSearch;
ULONG LastFileOffset; // Uncompressed offset of last extracted file
#ifndef CAB_READ_ONLY
ULONG LastBlockStart; // Uncompressed offset of last block in folder
ULONG MaxDiskSize;
ULONG DiskSize;
ULONG PrevCabinetNumber; // Previous cabinet number (where split file starts)
bool CreateNewDisk;
bool CreateNewFolder;
ULONG LastBlockStart; // Uncompressed offset of last block in folder
ULONG MaxDiskSize;
ULONG DiskSize;
ULONG PrevCabinetNumber; // Previous cabinet number (where split file starts)
bool CreateNewDisk;
bool CreateNewFolder;
CCFDATAStorage *ScratchFile;
FILEHANDLE SourceFile;
bool ContinueFile;
ULONG TotalBytesLeft;
bool BlockIsSplit; // true if current data block is split
ULONG NextFolderNumber; // Zero based folder number
CCFDATAStorage *ScratchFile;
FILEHANDLE SourceFile;
bool ContinueFile;
ULONG TotalBytesLeft;
bool BlockIsSplit; // true if current data block is split
ULONG NextFolderNumber; // Zero based folder number
#endif /* CAB_READ_ONLY */
};

View file

@ -20,27 +20,27 @@
class CCABManager : public CDFParser {
public:
CCABManager();
virtual ~CCABManager();
bool ParseCmdline(int argc, char* argv[]);
bool Run();
CCABManager();
virtual ~CCABManager();
bool ParseCmdline(int argc, char* argv[]);
bool Run();
private:
void Usage();
bool CreateCabinet();
bool CreateSimpleCabinet();
bool DisplayCabinet();
bool ExtractFromCabinet();
/* Event handlers */
virtual bool OnOverwrite(PCFFILE File, char* FileName);
virtual void OnExtract(PCFFILE File, char* FileName);
virtual void OnDiskChange(char* CabinetName, char* DiskLabel);
virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Configuration */
bool ProcessAll;
ULONG Mode;
bool PromptOnOverwrite;
char Location[MAX_PATH];
char FileName[MAX_PATH];
void Usage();
bool CreateCabinet();
bool CreateSimpleCabinet();
bool DisplayCabinet();
bool ExtractFromCabinet();
/* Event handlers */
virtual bool OnOverwrite(PCFFILE File, char* FileName);
virtual void OnExtract(PCFFILE File, char* FileName);
virtual void OnDiskChange(char* CabinetName, char* DiskLabel);
virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Configuration */
bool ProcessAll;
ULONG Mode;
bool PromptOnOverwrite;
char Location[MAX_PATH];
char FileName[MAX_PATH];
};
#endif /* __CABMAN_H */

File diff suppressed because it is too large Load diff

View file

@ -10,45 +10,45 @@
#include "cabinet.h"
typedef struct _CABINET_NAME {
struct _CABINET_NAME *Next;
ULONG DiskNumber;
char Name[128];
struct _CABINET_NAME *Next;
ULONG DiskNumber;
char Name[128];
} CABINET_NAME, *PCABINET_NAME;
typedef struct _DISK_NUMBER {
struct _DISK_NUMBER *Next;
ULONG DiskNumber;
ULONG Number;
struct _DISK_NUMBER *Next;
ULONG DiskNumber;
ULONG Number;
} DISK_NUMBER, *PDISK_NUMBER;
typedef enum {
TokenUnknown,
TokenInteger,
TokenIdentifier,
TokenString,
TokenSpace,
TokenSemi,
TokenEqual,
TokenPeriod,
TokenBackslash,
TokenEnd,
TokenUnknown,
TokenInteger,
TokenIdentifier,
TokenString,
TokenSpace,
TokenSemi,
TokenEqual,
TokenPeriod,
TokenBackslash,
TokenEnd,
} DFP_TOKEN;
typedef enum {
stCabinetName,
stCabinetNameTemplate,
stDiskLabel,
stDiskLabelTemplate,
stMaxDiskSize,
stInfFileName
stCabinetName,
stCabinetNameTemplate,
stDiskLabel,
stDiskLabelTemplate,
stMaxDiskSize,
stInfFileName
} SETTYPE;
typedef enum {
ntDisk,
ntCabinet,
ntFolder,
ntDisk,
ntCabinet,
ntFolder,
} NEWTYPE;
@ -56,86 +56,86 @@ typedef enum {
class CDFParser : public CCabinet {
public:
CDFParser();
virtual ~CDFParser();
ULONG Load(char* FileName);
ULONG Parse();
void SetFileRelativePath(char* Path);
bool InfFileOnly;
bool DontGenerateInf;
char FileRelativePath[300];
CDFParser();
virtual ~CDFParser();
ULONG Load(char* FileName);
ULONG Parse();
void SetFileRelativePath(char* Path);
bool InfFileOnly;
bool DontGenerateInf;
char FileRelativePath[300];
private:
/* Event handlers */
virtual bool OnDiskLabel(ULONG Number, char* Label);
virtual bool OnCabinetName(ULONG Number, char* Name);
/* Event handlers */
virtual bool OnDiskLabel(ULONG Number, char* Label);
virtual bool OnCabinetName(ULONG Number, char* Name);
void WriteInfLine(char* InfLine);
bool SetDiskName(PCABINET_NAME *List, ULONG Number, char* String);
bool GetDiskName(PCABINET_NAME *List, ULONG Number, char* String);
bool SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value);
bool GetDiskNumber(PDISK_NUMBER *List, ULONG Number, PULONG Value);
bool DoDiskLabel(ULONG Number, char* Label);
void DoDiskLabelTemplate(char* Template);
bool DoCabinetName(ULONG Number, char* Name);
void DoCabinetNameTemplate(char* Template);
void DoInfFileName(char* InfFileName);
ULONG DoMaxDiskSize(bool NumberValid, ULONG Number);
ULONG SetupNewDisk();
ULONG PerformSetCommand();
ULONG PerformNewCommand();
ULONG PerformInfBeginCommand();
ULONG PerformInfEndCommand();
ULONG PerformCommand();
ULONG PerformFileCopy();
void SkipSpaces();
bool IsNextToken(DFP_TOKEN Token, bool NoSpaces);
bool ReadLine();
void NextToken();
/* Parsing */
bool FileLoaded;
FILEHANDLE FileHandle;
char* FileBuffer;
ULONG FileBufferSize;
ULONG CurrentOffset;
char Line[128];
ULONG LineLength;
ULONG CurrentLine;
ULONG CurrentChar;
/* Token */
DFP_TOKEN CurrentToken;
ULONG CurrentInteger;
char CurrentString[256];
void WriteInfLine(char* InfLine);
bool SetDiskName(PCABINET_NAME *List, ULONG Number, char* String);
bool GetDiskName(PCABINET_NAME *List, ULONG Number, char* String);
bool SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value);
bool GetDiskNumber(PDISK_NUMBER *List, ULONG Number, PULONG Value);
bool DoDiskLabel(ULONG Number, char* Label);
void DoDiskLabelTemplate(char* Template);
bool DoCabinetName(ULONG Number, char* Name);
void DoCabinetNameTemplate(char* Template);
void DoInfFileName(char* InfFileName);
ULONG DoMaxDiskSize(bool NumberValid, ULONG Number);
ULONG SetupNewDisk();
ULONG PerformSetCommand();
ULONG PerformNewCommand();
ULONG PerformInfBeginCommand();
ULONG PerformInfEndCommand();
ULONG PerformCommand();
ULONG PerformFileCopy();
void SkipSpaces();
bool IsNextToken(DFP_TOKEN Token, bool NoSpaces);
bool ReadLine();
void NextToken();
/* Parsing */
bool FileLoaded;
FILEHANDLE FileHandle;
char* FileBuffer;
ULONG FileBufferSize;
ULONG CurrentOffset;
char Line[128];
ULONG LineLength;
ULONG CurrentLine;
ULONG CurrentChar;
/* Token */
DFP_TOKEN CurrentToken;
ULONG CurrentInteger;
char CurrentString[256];
/* State */
bool CabinetCreated;
bool DiskCreated;
bool FolderCreated;
/* Standard directive variable */
bool Cabinet;
ULONG CabinetFileCountThreshold;
PCABINET_NAME CabinetName;
bool CabinetNameTemplateSet;
char CabinetNameTemplate[128];
bool InfFileNameSet;
char InfFileName[256];
bool Compress;
ULONG CompressionType;
PCABINET_NAME DiskLabel;
bool DiskLabelTemplateSet;
char DiskLabelTemplate[128];
ULONG FolderFileCountThreshold;
ULONG FolderSizeThreshold;
ULONG MaxCabinetSize;
ULONG MaxDiskFileCount;
PDISK_NUMBER MaxDiskSize;
bool MaxDiskSizeAllSet;
ULONG MaxDiskSizeAll;
ULONG ReservePerCabinetSize;
ULONG ReservePerDataBlockSize;
ULONG ReservePerFolderSize;
char SourceDir[256];
FILEHANDLE InfFileHandle;
bool InfModeEnabled;
/* State */
bool CabinetCreated;
bool DiskCreated;
bool FolderCreated;
/* Standard directive variable */
bool Cabinet;
ULONG CabinetFileCountThreshold;
PCABINET_NAME CabinetName;
bool CabinetNameTemplateSet;
char CabinetNameTemplate[128];
bool InfFileNameSet;
char InfFileName[256];
bool Compress;
ULONG CompressionType;
PCABINET_NAME DiskLabel;
bool DiskLabelTemplateSet;
char DiskLabelTemplate[128];
ULONG FolderFileCountThreshold;
ULONG FolderSizeThreshold;
ULONG MaxCabinetSize;
ULONG MaxDiskFileCount;
PDISK_NUMBER MaxDiskSize;
bool MaxDiskSizeAllSet;
ULONG MaxDiskSizeAll;
ULONG ReservePerCabinetSize;
ULONG ReservePerDataBlockSize;
ULONG ReservePerFolderSize;
char SourceDir[256];
FILEHANDLE InfFileHandle;
bool InfModeEnabled;
};
#endif /* __DFP_H */

View file

@ -8,9 +8,7 @@
* REVISIONS:
* CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable
* CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces
* CF 04/05-2007 Made it compatible with 64-bit operating systems
* CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems
*/
#include <stdlib.h>
#include <stdarg.h>
@ -44,16 +42,16 @@ char* Pad(char* Str, char PadChar, ULONG Length)
* Str must be at least Length + 1 bytes
*/
{
ULONG Len;
ULONG Len;
Len = (ULONG)strlen(Str);
Len = (ULONG)strlen(Str);
if (Len < Length)
{
memcpy(&Str[Length - Len], Str, Len + 1);
memset(Str, PadChar, Length - Len);
}
return Str;
if (Len < Length)
{
memcpy(&Str[Length - Len], Str, Len + 1);
memset(Str, PadChar, Length - Len);
}
return Str;
}
@ -67,24 +65,24 @@ char* Date2Str(char* Str, USHORT Date)
* Pointer to string
*/
{
ULONG dw;
ULONG dw;
/* Month */
Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10);
Str[1] = (char)('0' + ((Date & 0x01E0) >> 5) % 10);
Str[2] = '-';
/* Day */
Str[3] = (char)('0' + (Date & 0x001F) / 10);
Str[4] = (char)('0' + (Date & 0x001F) % 10);
Str[5] = '-';
/* Year */
dw = 1980 + ((Date & 0xFE00) >> 9);
Str[6] = (char)('0' + dw / 1000); dw %= 1000;
Str[7] = (char)('0' + dw / 100); dw %= 100;
Str[8] = (char)('0' + dw / 10); dw %= 10;
Str[9] = (char)('0' + dw % 10);
Str[10] = '\0';
return Str;
/* Month */
Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10);
Str[1] = (char)('0' + ((Date & 0x01E0) >> 5) % 10);
Str[2] = '-';
/* Day */
Str[3] = (char)('0' + (Date & 0x001F) / 10);
Str[4] = (char)('0' + (Date & 0x001F) % 10);
Str[5] = '-';
/* Year */
dw = 1980 + ((Date & 0xFE00) >> 9);
Str[6] = (char)('0' + dw / 1000); dw %= 1000;
Str[7] = (char)('0' + dw / 100); dw %= 100;
Str[8] = (char)('0' + dw / 10); dw %= 10;
Str[9] = (char)('0' + dw % 10);
Str[10] = '\0';
return Str;
}
@ -98,33 +96,33 @@ char* Time2Str(char* Str, USHORT Time)
* Pointer to string
*/
{
bool PM;
ULONG Hour;
ULONG dw;
bool PM;
ULONG Hour;
ULONG dw;
Hour = ((Time & 0xF800) >> 11);
PM = (Hour >= 12);
Hour %= 12;
if (Hour == 0)
Hour = 12;
Hour = ((Time & 0xF800) >> 11);
PM = (Hour >= 12);
Hour %= 12;
if (Hour == 0)
Hour = 12;
if (Hour >= 10)
Str[0] = (char)('0' + Hour / 10);
else Str[0] = ' ';
Str[1] = (char)('0' + Hour % 10);
Str[2] = ':';
/* Minute */
Str[3] = (char)('0' + ((Time & 0x07E0) >> 5) / 10);
Str[4] = (char)('0' + ((Time & 0x07E0) >> 5) % 10);
Str[5] = ':';
/* Second */
dw = 2 * (Time & 0x001F);
Str[6] = (char)('0' + dw / 10);
Str[7] = (char)('0' + dw % 10);
if (Hour >= 10)
Str[0] = (char)('0' + Hour / 10);
else Str[0] = ' ';
Str[1] = (char)('0' + Hour % 10);
Str[2] = ':';
/* Minute */
Str[3] = (char)('0' + ((Time & 0x07E0) >> 5) / 10);
Str[4] = (char)('0' + ((Time & 0x07E0) >> 5) % 10);
Str[5] = ':';
/* Second */
dw = 2 * (Time & 0x001F);
Str[6] = (char)('0' + dw / 10);
Str[7] = (char)('0' + dw % 10);
Str[8] = PM? 'p' : 'a';
Str[9] = '\0';
return Str;
Str[8] = PM? 'p' : 'a';
Str[9] = '\0';
return Str;
}
@ -138,32 +136,32 @@ char* Attr2Str(char* Str, USHORT Attr)
* Pointer to string
*/
{
/* Archive */
if (Attr & CAB_ATTRIB_ARCHIVE)
Str[0] = 'A';
else
Str[0] = '-';
/* Archive */
if (Attr & CAB_ATTRIB_ARCHIVE)
Str[0] = 'A';
else
Str[0] = '-';
/* Hidden */
if (Attr & CAB_ATTRIB_HIDDEN)
Str[1] = 'H';
else
Str[1] = '-';
/* Hidden */
if (Attr & CAB_ATTRIB_HIDDEN)
Str[1] = 'H';
else
Str[1] = '-';
/* Read only */
if (Attr & CAB_ATTRIB_READONLY)
Str[2] = 'R';
else
Str[2] = '-';
/* Read only */
if (Attr & CAB_ATTRIB_READONLY)
Str[2] = 'R';
else
Str[2] = '-';
/* System */
if (Attr & CAB_ATTRIB_SYSTEM)
Str[3] = 'S';
else
Str[3] = '-';
/* System */
if (Attr & CAB_ATTRIB_SYSTEM)
Str[3] = 'S';
else
Str[3] = '-';
Str[4] = '\0';
return Str;
Str[4] = '\0';
return Str;
}
@ -174,9 +172,9 @@ CCABManager::CCABManager()
* FUNCTION: Default constructor
*/
{
ProcessAll = false;
InfFileOnly = false;
Mode = CM_MODE_DISPLAY;
ProcessAll = false;
InfFileOnly = false;
Mode = CM_MODE_DISPLAY;
}
@ -193,30 +191,30 @@ void CCABManager::Usage()
* FUNCTION: Display usage information on screen
*/
{
printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION);
printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n");
printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n");
printf("CABMAN -S cabinet filename\n");
printf(" cabinet Cabinet file.\n");
printf(" filename Name of the file to extract from the cabinet.\n");
printf(" Wild cards and multiple filenames\n");
printf(" (separated by blanks) may be used.\n\n");
printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION);
printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n");
printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n");
printf("CABMAN -S cabinet filename\n");
printf(" cabinet Cabinet file.\n");
printf(" filename Name of the file to extract from the cabinet.\n");
printf(" Wild cards and multiple filenames\n");
printf(" (separated by blanks) may be used.\n\n");
printf(" dirfile Name of the directive file to use.\n");
printf(" dirfile Name of the directive file to use.\n");
printf(" -A Process ALL cabinets. Follows cabinet chain\n");
printf(" starting in first cabinet mentioned.\n");
printf(" -C Create cabinet.\n");
printf(" -D Display cabinet directory.\n");
printf(" -E Extract files from cabinet.\n");
printf(" -I Don't create the cabinet, only the .inf file.\n");
printf(" -L dir Location to place extracted or generated files\n");
printf(" (default is current directory).\n");
printf(" -N Don't create the .inf file, only the cabinet.\n");
printf(" -RC Specify file to put in cabinet reserved area\n");
printf(" (size must be less than 64KB).\n");
printf(" -S Create simple cabinet.\n");
printf(" -P dir Files in the .dff are relative to this directory\n");
printf(" -A Process ALL cabinets. Follows cabinet chain\n");
printf(" starting in first cabinet mentioned.\n");
printf(" -C Create cabinet.\n");
printf(" -D Display cabinet directory.\n");
printf(" -E Extract files from cabinet.\n");
printf(" -I Don't create the cabinet, only the .inf file.\n");
printf(" -L dir Location to place extracted or generated files\n");
printf(" (default is current directory).\n");
printf(" -N Don't create the .inf file, only the cabinet.\n");
printf(" -RC Specify file to put in cabinet reserved area\n");
printf(" (size must be less than 64KB).\n");
printf(" -S Create simple cabinet.\n");
printf(" -P dir Files in the .dff are relative to this directory\n");
}
bool CCABManager::ParseCmdline(int argc, char* argv[])
@ -229,135 +227,135 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
* true if command line arguments was successfully parsed, false if not
*/
{
int i;
bool ShowUsage;
bool FoundCabinet = false;
int i;
bool ShowUsage;
bool FoundCabinet = false;
ShowUsage = (argc < 2);
ShowUsage = (argc < 2);
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'a':
case 'A':
ProcessAll = true;
break;
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'a':
case 'A':
ProcessAll = true;
break;
case 'c':
case 'C':
Mode = CM_MODE_CREATE;
break;
case 'c':
case 'C':
Mode = CM_MODE_CREATE;
break;
case 'd':
case 'D':
Mode = CM_MODE_DISPLAY;
break;
case 'd':
case 'D':
Mode = CM_MODE_DISPLAY;
break;
case 'e':
case 'E':
Mode = CM_MODE_EXTRACT;
break;
case 'e':
case 'E':
Mode = CM_MODE_EXTRACT;
break;
case 'i':
case 'I':
InfFileOnly = true;
break;
case 'i':
case 'I':
InfFileOnly = true;
break;
case 'l':
case 'L':
if (argv[i][2] == 0)
{
i++;
SetDestinationPath((char*)&argv[i][0]);
}
else
SetDestinationPath((char*)&argv[i][1]);
case 'l':
case 'L':
if (argv[i][2] == 0)
{
i++;
SetDestinationPath((char*)&argv[i][0]);
}
else
SetDestinationPath((char*)&argv[i][1]);
break;
break;
case 'n':
case 'N':
DontGenerateInf = true;
break;
case 'n':
case 'N':
DontGenerateInf = true;
break;
case 'R':
switch (argv[i][2])
{
case 'C': /* File to put in cabinet reserved area */
if (argv[i][3] == 0)
{
i++;
if (!SetCabinetReservedFile((char*)&argv[i][0]))
{
printf("Cannot open cabinet reserved area file.\n");
return false;
}
}
else
{
if (!SetCabinetReservedFile((char*)&argv[i][3]))
{
printf("Cannot open cabinet reserved area file.\n");
return false;
}
}
break;
case 'R':
switch (argv[i][2])
{
case 'C': /* File to put in cabinet reserved area */
if (argv[i][3] == 0)
{
i++;
if (!SetCabinetReservedFile((char*)&argv[i][0]))
{
printf("Cannot open cabinet reserved area file.\n");
return false;
}
}
else
{
if (!SetCabinetReservedFile((char*)&argv[i][3]))
{
printf("Cannot open cabinet reserved area file.\n");
return false;
}
}
break;
default:
printf("Bad parameter %s.\n", argv[i]);
return false;
}
break;
default:
printf("Bad parameter %s.\n", argv[i]);
return false;
}
break;
case 's':
case 'S':
Mode = CM_MODE_CREATE_SIMPLE;
break;
case 's':
case 'S':
Mode = CM_MODE_CREATE_SIMPLE;
break;
case 'P':
if (argv[i][2] == 0)
{
i++;
SetFileRelativePath((char*)&argv[i][0]);
}
else
SetFileRelativePath((char*)&argv[i][1]);
case 'P':
if (argv[i][2] == 0)
{
i++;
SetFileRelativePath((char*)&argv[i][0]);
}
else
SetFileRelativePath((char*)&argv[i][1]);
break;
break;
default:
printf("Bad parameter %s.\n", argv[i]);
return false;
}
}
else
{
if ((FoundCabinet) || (Mode == CM_MODE_CREATE))
{
/* FIXME: There may be many of these if Mode != CM_MODE_CREATE */
strcpy((char*)FileName, argv[i]);
}
else
{
SetCabinetName(argv[i]);
FoundCabinet = true;
}
}
}
default:
printf("Bad parameter %s.\n", argv[i]);
return false;
}
}
else
{
if ((FoundCabinet) || (Mode == CM_MODE_CREATE))
{
/* FIXME: There may be many of these if Mode != CM_MODE_CREATE */
strcpy((char*)FileName, argv[i]);
}
else
{
SetCabinetName(argv[i]);
FoundCabinet = true;
}
}
}
if (ShowUsage)
{
Usage();
return false;
}
if (ShowUsage)
{
Usage();
return false;
}
/* FIXME */
SelectCodec(CAB_CODEC_MSZIP);
/* FIXME */
SelectCodec(CAB_CODEC_MSZIP);
return true;
return true;
}
@ -366,18 +364,18 @@ bool CCABManager::CreateCabinet()
* FUNCTION: Create cabinet
*/
{
ULONG Status;
ULONG Status;
Status = Load((char*)&FileName);
if (Status != CAB_STATUS_SUCCESS)
{
printf("Specified directive file could not be found: %s.\n", (char*)&FileName);
return false;
}
Status = Load((char*)&FileName);
if (Status != CAB_STATUS_SUCCESS)
{
printf("Specified directive file could not be found: %s.\n", (char*)&FileName);
return false;
}
Status = Parse();
Status = Parse();
return (Status == CAB_STATUS_SUCCESS ? true : false);
return (Status == CAB_STATUS_SUCCESS ? true : false);
}
@ -386,34 +384,34 @@ bool CCABManager::CreateSimpleCabinet()
* FUNCTION: Create cabinet
*/
{
ULONG Status;
ULONG Status;
Status = NewCabinet();
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status));
return false;
}
Status = NewCabinet();
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status));
return false;
}
Status = AddFile(FileName);
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%lu).\n", (ULONG)Status));
return false;
}
Status = AddFile(FileName);
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%lu).\n", (ULONG)Status));
return false;
}
Status = WriteDisk(false);
if (Status == CAB_STATUS_SUCCESS)
Status = CloseDisk();
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status));
return false;
}
Status = WriteDisk(false);
if (Status == CAB_STATUS_SUCCESS)
Status = CloseDisk();
if (Status != CAB_STATUS_SUCCESS)
{
DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status));
return false;
}
CloseCabinet();
CloseCabinet();
return true;
return true;
}
@ -422,62 +420,62 @@ bool CCABManager::DisplayCabinet()
* FUNCTION: Display cabinet contents
*/
{
CAB_SEARCH Search;
char Str[20];
ULONG FileCount = 0;
ULONG ByteCount = 0;
CAB_SEARCH Search;
char Str[20];
ULONG FileCount = 0;
ULONG ByteCount = 0;
if (Open() == CAB_STATUS_SUCCESS)
{
printf("Cabinet %s\n\n", GetCabinetName());
if (Open() == CAB_STATUS_SUCCESS)
{
printf("Cabinet %s\n\n", GetCabinetName());
if (FindFirst("", &Search) == CAB_STATUS_SUCCESS)
{
do
{
if (Search.File->FileControlID != CAB_FILE_CONTINUED)
{
printf("%s ", Date2Str((char*)&Str, Search.File->FileDate));
printf("%s ", Time2Str((char*)&Str, Search.File->FileTime));
printf("%s ", Attr2Str((char*)&Str, Search.File->Attributes));
sprintf(Str, "%lu", Search.File->FileSize);
printf("%s ", Pad(Str, ' ', 13));
printf("%s\n", Search.FileName);
if (FindFirst("", &Search) == CAB_STATUS_SUCCESS)
{
do
{
if (Search.File->FileControlID != CAB_FILE_CONTINUED)
{
printf("%s ", Date2Str((char*)&Str, Search.File->FileDate));
printf("%s ", Time2Str((char*)&Str, Search.File->FileTime));
printf("%s ", Attr2Str((char*)&Str, Search.File->Attributes));
sprintf(Str, "%lu", Search.File->FileSize);
printf("%s ", Pad(Str, ' ', 13));
printf("%s\n", Search.FileName);
FileCount++;
ByteCount += Search.File->FileSize;
}
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
}
FileCount++;
ByteCount += Search.File->FileSize;
}
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
}
if (FileCount > 0) {
if (FileCount == 1)
printf(" 1 file ");
else
{
sprintf(Str, "%lu", FileCount);
printf(" %s files ", Pad(Str, ' ', 12));
}
if (FileCount > 0) {
if (FileCount == 1)
printf(" 1 file ");
else
{
sprintf(Str, "%lu", FileCount);
printf(" %s files ", Pad(Str, ' ', 12));
}
if (ByteCount == 1)
printf(" 1 byte\n");
else
{
sprintf(Str, "%lu", ByteCount);
printf("%s bytes\n", Pad(Str, ' ', 12));
}
}
else
{
/* There should be at least one file in a cabinet */
printf("No files in cabinet.");
}
return true;
}
else
printf("Cannot open file: %s\n", GetCabinetName());
if (ByteCount == 1)
printf(" 1 byte\n");
else
{
sprintf(Str, "%lu", ByteCount);
printf("%s bytes\n", Pad(Str, ' ', 12));
}
}
else
{
/* There should be at least one file in a cabinet */
printf("No files in cabinet.");
}
return true;
}
else
printf("Cannot open file: %s\n", GetCabinetName());
return false;
return false;
}
@ -486,44 +484,44 @@ bool CCABManager::ExtractFromCabinet()
* FUNCTION: Extract file(s) from cabinet
*/
{
CAB_SEARCH Search;
ULONG Status;
CAB_SEARCH Search;
ULONG Status;
if (Open() == CAB_STATUS_SUCCESS)
{
printf("Cabinet %s\n\n", GetCabinetName());
if (Open() == CAB_STATUS_SUCCESS)
{
printf("Cabinet %s\n\n", GetCabinetName());
if (FindFirst("", &Search) == CAB_STATUS_SUCCESS)
{
do
{
switch (Status = ExtractFile(Search.FileName)) {
case CAB_STATUS_SUCCESS:
break;
if (FindFirst("", &Search) == CAB_STATUS_SUCCESS)
{
do
{
switch (Status = ExtractFile(Search.FileName)) {
case CAB_STATUS_SUCCESS:
break;
case CAB_STATUS_INVALID_CAB:
printf("Cabinet contains errors.\n");
return false;
case CAB_STATUS_INVALID_CAB:
printf("Cabinet contains errors.\n");
return false;
case CAB_STATUS_UNSUPPCOMP:
printf("Cabinet uses unsupported compression type.\n");
return false;
case CAB_STATUS_UNSUPPCOMP:
printf("Cabinet uses unsupported compression type.\n");
return false;
case CAB_STATUS_CANNOT_WRITE:
printf("You've run out of free space on the destination volume or the volume is damaged.\n");
return false;
case CAB_STATUS_CANNOT_WRITE:
printf("You've run out of free space on the destination volume or the volume is damaged.\n");
return false;
default:
printf("Unspecified error code (%lu).\n", (ULONG)Status);
return false;
}
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
}
return true;
} else
printf("Cannot open file: %s.\n", GetCabinetName());
default:
printf("Unspecified error code (%lu).\n", (ULONG)Status);
return false;
}
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
}
return true;
} else
printf("Cannot open file: %s.\n", GetCabinetName());
return false;
return false;
}
@ -532,30 +530,30 @@ bool CCABManager::Run()
* FUNCTION: Process cabinet
*/
{
printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION);
printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION);
switch (Mode)
{
case CM_MODE_CREATE:
return CreateCabinet();
break;
switch (Mode)
{
case CM_MODE_CREATE:
return CreateCabinet();
break;
case CM_MODE_DISPLAY:
return DisplayCabinet();
break;
case CM_MODE_DISPLAY:
return DisplayCabinet();
break;
case CM_MODE_EXTRACT:
return ExtractFromCabinet();
break;
case CM_MODE_EXTRACT:
return ExtractFromCabinet();
break;
case CM_MODE_CREATE_SIMPLE:
return CreateSimpleCabinet();
break;
case CM_MODE_CREATE_SIMPLE:
return CreateSimpleCabinet();
break;
default:
break;
}
return false;
default:
break;
}
return false;
}
@ -572,11 +570,11 @@ bool CCABManager::OnOverwrite(PCFFILE File,
* true if the file should be overwritten, false if not
*/
{
if (Mode == CM_MODE_CREATE)
return true;
if (Mode == CM_MODE_CREATE)
return true;
/* Always overwrite */
return true;
/* Always overwrite */
return true;
}
@ -589,7 +587,7 @@ void CCABManager::OnExtract(PCFFILE File,
* FileName = Pointer to buffer with name of file (full path)
*/
{
printf("Extracting %s\n", GetFileName(FileName));
printf("Extracting %s\n", GetFileName(FileName));
}
@ -603,7 +601,7 @@ void CCABManager::OnDiskChange(char* CabinetName,
* DiskLabel = Pointer to buffer with label of disk
*/
{
printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel);
printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel);
}
@ -616,7 +614,7 @@ void CCABManager::OnAdd(PCFFILE File,
* FileName = Pointer to buffer with name of file (full path)
*/
{
printf("Adding %s\n", GetFileName(FileName));
printf("Adding %s\n", GetFileName(FileName));
}
@ -628,13 +626,13 @@ int main(int argc, char * argv[])
* argv = Pointer to list of command line arguments
*/
{
CCABManager CABMgr;
bool status = false;
CCABManager CABMgr;
bool status = false;
if (CABMgr.ParseCmdline(argc, argv))
status = CABMgr.Run();
if (CABMgr.ParseCmdline(argc, argv))
status = CABMgr.Run();
return (status ? 0 : 1);
return (status ? 0 : 1);
}
/* EOF */

View file

@ -10,9 +10,7 @@
* REVISIONS:
* CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable
* CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces
* CF 04/05-2007 Made it compatible with 64-bit operating systems
* CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems
*/
#include <stdio.h>
#include "mszip.h"
@ -22,14 +20,14 @@
voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size)
{
DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size));
return AllocateMemory(items * size);
DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size));
return AllocateMemory(items * size);
}
void MSZipFree (voidpf opaque, voidpf address)
{
DPRINT(DEBUG_MEMORY, ("\n"));
FreeMemory(address);
DPRINT(DEBUG_MEMORY, ("\n"));
FreeMemory(address);
}
@ -40,9 +38,9 @@ CMSZipCodec::CMSZipCodec()
* FUNCTION: Default constructor
*/
{
ZStream.zalloc = MSZipAlloc;
ZStream.zfree = MSZipFree;
ZStream.opaque = (voidpf)0;
ZStream.zalloc = MSZipAlloc;
ZStream.zfree = MSZipFree;
ZStream.opaque = (voidpf)0;
}
@ -67,50 +65,50 @@ ULONG CMSZipCodec::Compress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of compressed data
*/
{
PUSHORT Magic;
PUSHORT Magic;
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
Magic = (PUSHORT)OutputBuffer;
*Magic = MSZIP_MAGIC;
Magic = (PUSHORT)OutputBuffer;
*Magic = MSZIP_MAGIC;
ZStream.next_in = (unsigned char*)InputBuffer;
ZStream.avail_in = InputLength;
ZStream.next_out = (unsigned char*)((_W64 unsigned long)OutputBuffer + 2);
ZStream.avail_out = CAB_BLOCKSIZE + 12;
ZStream.next_in = (unsigned char*)InputBuffer;
ZStream.avail_in = InputLength;
ZStream.next_out = (unsigned char*)((_W64 unsigned long)OutputBuffer + 2);
ZStream.avail_out = CAB_BLOCKSIZE + 12;
/* WindowBits is passed < 0 to tell that there is no zlib header */
Status = deflateInit2(&ZStream,
Z_BEST_COMPRESSION,
Z_DEFLATED,
-MAX_WBITS,
8, /* memLevel */
Z_DEFAULT_STRATEGY);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("deflateInit() returned (%d).\n", Status));
return CS_NOMEMORY;
}
/* WindowBits is passed < 0 to tell that there is no zlib header */
Status = deflateInit2(&ZStream,
Z_BEST_COMPRESSION,
Z_DEFLATED,
-MAX_WBITS,
8, /* memLevel */
Z_DEFAULT_STRATEGY);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("deflateInit() returned (%d).\n", Status));
return CS_NOMEMORY;
}
Status = deflate(&ZStream, Z_FINISH);
if ((Status != Z_OK) && (Status != Z_STREAM_END))
{
DPRINT(MIN_TRACE, ("deflate() returned (%d) (%s).\n", Status, ZStream.msg));
if (Status == Z_MEM_ERROR)
return CS_NOMEMORY;
return CS_BADSTREAM;
}
Status = deflate(&ZStream, Z_FINISH);
if ((Status != Z_OK) && (Status != Z_STREAM_END))
{
DPRINT(MIN_TRACE, ("deflate() returned (%d) (%s).\n", Status, ZStream.msg));
if (Status == Z_MEM_ERROR)
return CS_NOMEMORY;
return CS_BADSTREAM;
}
*OutputLength = ZStream.total_out + 2;
*OutputLength = ZStream.total_out + 2;
Status = deflateEnd(&ZStream);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("deflateEnd() returned (%d).\n", Status));
return CS_BADSTREAM;
}
Status = deflateEnd(&ZStream);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("deflateEnd() returned (%d).\n", Status));
return CS_BADSTREAM;
}
return CS_SUCCESS;
return CS_SUCCESS;
}
@ -127,58 +125,58 @@ ULONG CMSZipCodec::Uncompress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of uncompressed data
*/
{
USHORT Magic;
USHORT Magic;
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
Magic = *((PUSHORT)InputBuffer);
Magic = *((PUSHORT)InputBuffer);
if (Magic != MSZIP_MAGIC)
{
DPRINT(MID_TRACE, ("Bad MSZIP block header magic (0x%X)\n", Magic));
return CS_BADSTREAM;
}
if (Magic != MSZIP_MAGIC)
{
DPRINT(MID_TRACE, ("Bad MSZIP block header magic (0x%X)\n", Magic));
return CS_BADSTREAM;
}
ZStream.next_in = (unsigned char*)((_W64 unsigned long)InputBuffer + 2);
ZStream.avail_in = InputLength - 2;
ZStream.next_out = (unsigned char*)OutputBuffer;
ZStream.avail_out = CAB_BLOCKSIZE + 12;
ZStream.next_in = (unsigned char*)((_W64 unsigned long)InputBuffer + 2);
ZStream.avail_in = InputLength - 2;
ZStream.next_out = (unsigned char*)OutputBuffer;
ZStream.avail_out = CAB_BLOCKSIZE + 12;
/* WindowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
* after the compressed stream in order to complete decompression and
* return Z_STREAM_END.
*/
Status = inflateInit2(&ZStream, -MAX_WBITS);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflateInit2() returned (%d).\n", Status));
return CS_BADSTREAM;
}
/* WindowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
* after the compressed stream in order to complete decompression and
* return Z_STREAM_END.
*/
Status = inflateInit2(&ZStream, -MAX_WBITS);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflateInit2() returned (%d).\n", Status));
return CS_BADSTREAM;
}
while ((ZStream.total_out < CAB_BLOCKSIZE + 12) &&
(ZStream.total_in < InputLength - 2))
{
Status = inflate(&ZStream, Z_NO_FLUSH);
if (Status == Z_STREAM_END) break;
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflate() returned (%d) (%s).\n", Status, ZStream.msg));
if (Status == Z_MEM_ERROR)
return CS_NOMEMORY;
return CS_BADSTREAM;
}
}
while ((ZStream.total_out < CAB_BLOCKSIZE + 12) &&
(ZStream.total_in < InputLength - 2))
{
Status = inflate(&ZStream, Z_NO_FLUSH);
if (Status == Z_STREAM_END) break;
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflate() returned (%d) (%s).\n", Status, ZStream.msg));
if (Status == Z_MEM_ERROR)
return CS_NOMEMORY;
return CS_BADSTREAM;
}
}
*OutputLength = ZStream.total_out;
*OutputLength = ZStream.total_out;
Status = inflateEnd(&ZStream);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflateEnd() returned (%d).\n", Status));
return CS_BADSTREAM;
}
return CS_SUCCESS;
Status = inflateEnd(&ZStream);
if (Status != Z_OK)
{
DPRINT(MIN_TRACE, ("inflateEnd() returned (%d).\n", Status));
return CS_BADSTREAM;
}
return CS_SUCCESS;
}
/* EOF */

View file

@ -17,23 +17,23 @@
class CMSZipCodec : public CCABCodec {
public:
/* Default constructor */
CMSZipCodec();
/* Default destructor */
virtual ~CMSZipCodec();
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Default constructor */
CMSZipCodec();
/* Default destructor */
virtual ~CMSZipCodec();
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
private:
int Status;
z_stream ZStream; /* Zlib stream */
int Status;
z_stream ZStream; /* Zlib stream */
};
#endif /* __MSZIP_H */

View file

@ -8,9 +8,7 @@
* REVISIONS:
* CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable
* CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces
* CF 04/05-2007 Made it compatible with 64-bit operating systems
* CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems
*/
#include "raw.h"
@ -46,9 +44,9 @@ ULONG CRawCodec::Compress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of compressed data
*/
{
memcpy(OutputBuffer, InputBuffer, InputLength);
*OutputLength = InputLength;
return CS_SUCCESS;
memcpy(OutputBuffer, InputBuffer, InputLength);
*OutputLength = InputLength;
return CS_SUCCESS;
}
ULONG CRawCodec::Uncompress(void* OutputBuffer,
@ -64,9 +62,9 @@ ULONG CRawCodec::Uncompress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of uncompressed data
*/
{
memcpy(OutputBuffer, InputBuffer, InputLength);
*OutputLength = InputLength;
return CS_SUCCESS;
memcpy(OutputBuffer, InputBuffer, InputLength);
*OutputLength = InputLength;
return CS_SUCCESS;
}
/* EOF */

View file

@ -14,20 +14,20 @@
class CRawCodec : public CCABCodec {
public:
/* Default constructor */
CRawCodec();
/* Default destructor */
virtual ~CRawCodec();
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Default constructor */
CRawCodec();
/* Default destructor */
virtual ~CRawCodec();
/* Compresses a data block */
virtual ULONG Compress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
/* Uncompresses a data block */
virtual ULONG Uncompress(void* OutputBuffer,
void* InputBuffer,
ULONG InputLength,
PULONG OutputLength);
};
#endif /* __RAW_H */