mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
Patch for reformatting the cabman code, Colin Finck, see bug report #2234.
svn path=/trunk/; revision=26640
This commit is contained in:
parent
0a981d42cf
commit
2408771fff
10 changed files with 3833 additions and 3426 deletions
File diff suppressed because it is too large
Load diff
|
@ -63,18 +63,18 @@ extern unsigned long DebugTraceLevel;
|
|||
#endif//_MSC_VER
|
||||
|
||||
#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 */
|
||||
|
@ -121,108 +121,108 @@ extern unsigned long DebugTraceLevel;
|
|||
|
||||
typedef struct _CFHEADER
|
||||
{
|
||||
unsigned long Signature; // File signature 'MSCF' (CAB_SIGNATURE)
|
||||
unsigned long Reserved1; // Reserved field
|
||||
unsigned long CabinetSize; // Cabinet file size
|
||||
unsigned long Reserved2; // Reserved field
|
||||
unsigned long FileTableOffset; // Offset of first CFFILE
|
||||
unsigned long Reserved3; // Reserved field
|
||||
unsigned short Version; // Cabinet version (CAB_VERSION)
|
||||
unsigned short FolderCount; // Number of folders
|
||||
unsigned short FileCount; // Number of files
|
||||
unsigned short Flags; // Cabinet flags (CAB_FLAG_*)
|
||||
unsigned short SetID; // Cabinet set id
|
||||
unsigned short CabinetNumber; // Zero-based cabinet number
|
||||
unsigned long Signature; // File signature 'MSCF' (CAB_SIGNATURE)
|
||||
unsigned long Reserved1; // Reserved field
|
||||
unsigned long CabinetSize; // Cabinet file size
|
||||
unsigned long Reserved2; // Reserved field
|
||||
unsigned long FileTableOffset; // Offset of first CFFILE
|
||||
unsigned long Reserved3; // Reserved field
|
||||
unsigned short Version; // Cabinet version (CAB_VERSION)
|
||||
unsigned short FolderCount; // Number of folders
|
||||
unsigned short FileCount; // Number of files
|
||||
unsigned short Flags; // Cabinet flags (CAB_FLAG_*)
|
||||
unsigned short SetID; // Cabinet set id
|
||||
unsigned short CabinetNumber; // Zero-based cabinet number
|
||||
/* Optional fields (depends on Flags)
|
||||
unsigned short 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
|
||||
unsigned short 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
|
||||
{
|
||||
unsigned long DataOffset; // Absolute offset of first CFDATA block in this folder
|
||||
unsigned short DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet
|
||||
unsigned short CompressionType; // Type of compression used for all CFDATA blocks in this folder
|
||||
unsigned long DataOffset; // Absolute offset of first CFDATA block in this folder
|
||||
unsigned short DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet
|
||||
unsigned short 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
|
||||
{
|
||||
unsigned long FileSize; // Uncompressed file size in bytes
|
||||
unsigned long FileOffset; // Uncompressed offset of file in the folder
|
||||
unsigned short FileControlID; // File control ID (CAB_FILE_*)
|
||||
unsigned short FileDate; // File date stamp, as used by DOS
|
||||
unsigned short FileTime; // File time stamp, as used by DOS
|
||||
unsigned short Attributes; // File attributes (CAB_ATTRIB_*)
|
||||
unsigned long FileSize; // Uncompressed file size in bytes
|
||||
unsigned long FileOffset; // Uncompressed offset of file in the folder
|
||||
unsigned short FileControlID; // File control ID (CAB_FILE_*)
|
||||
unsigned short FileDate; // File date stamp, as used by DOS
|
||||
unsigned short FileTime; // File time stamp, as used by DOS
|
||||
unsigned short Attributes; // File attributes (CAB_ATTRIB_*)
|
||||
/* After this is the NULL terminated filename */
|
||||
} CFFILE, *PCFFILE;
|
||||
|
||||
|
||||
typedef struct _CFDATA
|
||||
{
|
||||
unsigned long Checksum; // Checksum of CFDATA entry
|
||||
unsigned short CompSize; // Number of compressed bytes in this block
|
||||
unsigned short UncompSize; // Number of uncompressed bytes in this block
|
||||
unsigned long Checksum; // Checksum of CFDATA entry
|
||||
unsigned short CompSize; // Number of compressed bytes in this block
|
||||
unsigned short 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;
|
||||
unsigned long ScratchFilePosition; // Absolute offset in scratch file
|
||||
unsigned long AbsoluteOffset; // Absolute offset in cabinet
|
||||
unsigned long UncompOffset; // Uncompressed offset in folder
|
||||
struct _CFDATA_NODE *Next;
|
||||
struct _CFDATA_NODE *Prev;
|
||||
unsigned long ScratchFilePosition; // Absolute offset in scratch file
|
||||
unsigned long AbsoluteOffset; // Absolute offset in cabinet
|
||||
unsigned long UncompOffset; // Uncompressed offset in folder
|
||||
CFDATA Data;
|
||||
} CFDATA_NODE, *PCFDATA_NODE;
|
||||
|
||||
typedef struct _CFFOLDER_NODE
|
||||
{
|
||||
struct _CFFOLDER_NODE *Next;
|
||||
struct _CFFOLDER_NODE *Prev;
|
||||
unsigned long UncompOffset; // File size accumulator
|
||||
unsigned long AbsoluteOffset;
|
||||
unsigned long TotalFolderSize; // Total size of folder in current disk
|
||||
PCFDATA_NODE DataListHead;
|
||||
PCFDATA_NODE DataListTail;
|
||||
unsigned long Index;
|
||||
bool Commit; // true if the folder should be committed
|
||||
bool Delete; // true if marked for deletion
|
||||
struct _CFFOLDER_NODE *Next;
|
||||
struct _CFFOLDER_NODE *Prev;
|
||||
unsigned long UncompOffset; // File size accumulator
|
||||
unsigned long AbsoluteOffset;
|
||||
unsigned long TotalFolderSize; // Total size of folder in current disk
|
||||
PCFDATA_NODE DataListHead;
|
||||
PCFDATA_NODE DataListTail;
|
||||
unsigned long 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;
|
||||
|
||||
|
||||
|
@ -247,20 +247,20 @@ typedef struct _CAB_SEARCH
|
|||
|
||||
class CCABCodec {
|
||||
public:
|
||||
/* Default constructor */
|
||||
CCABCodec() {};
|
||||
/* Default destructor */
|
||||
virtual ~CCABCodec() {};
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength) = 0;
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength) = 0;
|
||||
/* Default constructor */
|
||||
CCABCodec() {};
|
||||
/* Default destructor */
|
||||
virtual ~CCABCodec() {};
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength) = 0;
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -283,193 +283,193 @@ public:
|
|||
|
||||
class CCFDATAStorage {
|
||||
public:
|
||||
/* Default constructor */
|
||||
CCFDATAStorage();
|
||||
/* Default destructor */
|
||||
virtual ~CCFDATAStorage();
|
||||
unsigned long Create(char* FileName);
|
||||
unsigned long Destroy();
|
||||
unsigned long Truncate();
|
||||
unsigned long Position();
|
||||
unsigned long Seek(long Position);
|
||||
unsigned long ReadBlock(PCFDATA Data, void* Buffer, unsigned long* BytesRead);
|
||||
unsigned long WriteBlock(PCFDATA Data, void* Buffer, unsigned long* BytesWritten);
|
||||
/* Default constructor */
|
||||
CCFDATAStorage();
|
||||
/* Default destructor */
|
||||
virtual ~CCFDATAStorage();
|
||||
unsigned long Create(char* FileName);
|
||||
unsigned long Destroy();
|
||||
unsigned long Truncate();
|
||||
unsigned long Position();
|
||||
unsigned long Seek(long Position);
|
||||
unsigned long ReadBlock(PCFDATA Data, void* Buffer, unsigned long* BytesRead);
|
||||
unsigned long WriteBlock(PCFDATA Data, void* Buffer, unsigned long* 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, unsigned long 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 */
|
||||
unsigned long GetCurrentDiskNumber();
|
||||
/* Opens the current cabinet file */
|
||||
unsigned long Open();
|
||||
/* Closes the current open cabinet file */
|
||||
void Close();
|
||||
/* Locates the first file in the current cabinet file that matches a search criteria */
|
||||
unsigned long FindFirst(char* FileName, PCAB_SEARCH Search);
|
||||
/* Locates the next file in the current cabinet file */
|
||||
unsigned long FindNext(PCAB_SEARCH Search);
|
||||
/* Extracts a file from the current cabinet file */
|
||||
unsigned long ExtractFile(char* FileName);
|
||||
/* Select codec engine to use */
|
||||
void SelectCodec(unsigned long 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, unsigned long 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 */
|
||||
unsigned long GetCurrentDiskNumber();
|
||||
/* Opens the current cabinet file */
|
||||
unsigned long Open();
|
||||
/* Closes the current open cabinet file */
|
||||
void Close();
|
||||
/* Locates the first file in the current cabinet file that matches a search criteria */
|
||||
unsigned long FindFirst(char* FileName, PCAB_SEARCH Search);
|
||||
/* Locates the next file in the current cabinet file */
|
||||
unsigned long FindNext(PCAB_SEARCH Search);
|
||||
/* Extracts a file from the current cabinet file */
|
||||
unsigned long ExtractFile(char* FileName);
|
||||
/* Select codec engine to use */
|
||||
void SelectCodec(unsigned long Id);
|
||||
#ifndef CAB_READ_ONLY
|
||||
/* Creates a new cabinet file */
|
||||
unsigned long NewCabinet();
|
||||
/* Forces a new disk to be created */
|
||||
unsigned long NewDisk();
|
||||
/* Forces a new folder to be created */
|
||||
unsigned long NewFolder();
|
||||
/* Writes a file to scratch storage */
|
||||
unsigned long WriteFileToScratchStorage(PCFFILE_NODE FileNode);
|
||||
/* Forces the current disk to be written */
|
||||
unsigned long WriteDisk(unsigned long MoreDisks);
|
||||
/* Commits the current disk */
|
||||
unsigned long CommitDisk(unsigned long MoreDisks);
|
||||
/* Closes the current disk */
|
||||
unsigned long CloseDisk();
|
||||
/* Closes the current cabinet */
|
||||
unsigned long CloseCabinet();
|
||||
/* Adds a file to the current disk */
|
||||
unsigned long AddFile(char* FileName);
|
||||
/* Sets the maximum size of the current disk */
|
||||
void SetMaxDiskSize(unsigned long Size);
|
||||
/* Creates a new cabinet file */
|
||||
unsigned long NewCabinet();
|
||||
/* Forces a new disk to be created */
|
||||
unsigned long NewDisk();
|
||||
/* Forces a new folder to be created */
|
||||
unsigned long NewFolder();
|
||||
/* Writes a file to scratch storage */
|
||||
unsigned long WriteFileToScratchStorage(PCFFILE_NODE FileNode);
|
||||
/* Forces the current disk to be written */
|
||||
unsigned long WriteDisk(unsigned long MoreDisks);
|
||||
/* Commits the current disk */
|
||||
unsigned long CommitDisk(unsigned long MoreDisks);
|
||||
/* Closes the current disk */
|
||||
unsigned long CloseDisk();
|
||||
/* Closes the current cabinet */
|
||||
unsigned long CloseCabinet();
|
||||
/* Adds a file to the current disk */
|
||||
unsigned long AddFile(char* FileName);
|
||||
/* Sets the maximum size of the current disk */
|
||||
void SetMaxDiskSize(unsigned long 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(unsigned long Number, char* Name);
|
||||
/* Handler called when a disk needs a label */
|
||||
virtual bool OnDiskLabel(unsigned long 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(unsigned long Number, char* Name);
|
||||
/* Handler called when a disk needs a label */
|
||||
virtual bool OnDiskLabel(unsigned long Number, char* Label);
|
||||
#endif /* CAB_READ_ONLY */
|
||||
private:
|
||||
PCFFOLDER_NODE LocateFolderNode(unsigned long Index);
|
||||
unsigned long GetAbsoluteOffset(PCFFILE_NODE File);
|
||||
unsigned long LocateFile(char* FileName, PCFFILE_NODE *File);
|
||||
unsigned long ReadString(char* String, unsigned long MaxLength);
|
||||
unsigned long ReadFileTable();
|
||||
unsigned long 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();
|
||||
unsigned long ComputeChecksum(void* Buffer, unsigned int Size, unsigned long Seed);
|
||||
unsigned long ReadBlock(void* Buffer, unsigned long Size, unsigned long* BytesRead);
|
||||
PCFFOLDER_NODE LocateFolderNode(unsigned long Index);
|
||||
unsigned long GetAbsoluteOffset(PCFFILE_NODE File);
|
||||
unsigned long LocateFile(char* FileName, PCFFILE_NODE *File);
|
||||
unsigned long ReadString(char* String, unsigned long MaxLength);
|
||||
unsigned long ReadFileTable();
|
||||
unsigned long 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();
|
||||
unsigned long ComputeChecksum(void* Buffer, unsigned int Size, unsigned long Seed);
|
||||
unsigned long ReadBlock(void* Buffer, unsigned long Size, unsigned long* BytesRead);
|
||||
#ifndef CAB_READ_ONLY
|
||||
unsigned long InitCabinetHeader();
|
||||
unsigned long WriteCabinetHeader(bool MoreDisks);
|
||||
unsigned long WriteFolderEntries();
|
||||
unsigned long WriteFileEntries();
|
||||
unsigned long CommitDataBlocks(PCFFOLDER_NODE FolderNode);
|
||||
unsigned long WriteDataBlock();
|
||||
unsigned long GetAttributesOnFile(PCFFILE_NODE File);
|
||||
unsigned long SetAttributesOnFile(PCFFILE_NODE File);
|
||||
unsigned long GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
||||
unsigned long InitCabinetHeader();
|
||||
unsigned long WriteCabinetHeader(bool MoreDisks);
|
||||
unsigned long WriteFolderEntries();
|
||||
unsigned long WriteFileEntries();
|
||||
unsigned long CommitDataBlocks(PCFFOLDER_NODE FolderNode);
|
||||
unsigned long WriteDataBlock();
|
||||
unsigned long GetAttributesOnFile(PCFFILE_NODE File);
|
||||
unsigned long SetAttributesOnFile(PCFFILE_NODE File);
|
||||
unsigned long GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
||||
#if !defined(WIN32)
|
||||
void ConvertDateAndTime(time_t* Time, unsigned short* DosDate, unsigned short* DosTime);
|
||||
void ConvertDateAndTime(time_t* Time, unsigned short* DosDate, unsigned short* DosTime);
|
||||
#endif
|
||||
#endif /* CAB_READ_ONLY */
|
||||
unsigned long 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
|
||||
unsigned long TotalHeaderSize; // Size of header and optional fields
|
||||
unsigned long NextFieldsSize; // Size of next cabinet name and next disk label
|
||||
unsigned long TotalFolderSize; // Size of all folder entries
|
||||
unsigned long TotalFileSize; // Size of all file entries
|
||||
unsigned long FolderUncompSize; // Uncompressed size of folder
|
||||
unsigned long BytesLeftInBlock; // Number of bytes left in current block
|
||||
bool ReuseBlock;
|
||||
char DestPath[MAX_PATH];
|
||||
char CabinetReservedFile[MAX_PATH];
|
||||
void* CabinetReservedFileBuffer;
|
||||
unsigned long CabinetReservedFileSize;
|
||||
FILEHANDLE FileHandle;
|
||||
bool FileOpen;
|
||||
CFHEADER CABHeader;
|
||||
unsigned long CabinetReserved;
|
||||
unsigned long FolderReserved;
|
||||
unsigned long DataReserved;
|
||||
PCFFOLDER_NODE FolderListHead;
|
||||
PCFFOLDER_NODE FolderListTail;
|
||||
PCFFOLDER_NODE CurrentFolderNode;
|
||||
PCFDATA_NODE CurrentDataNode;
|
||||
PCFFILE_NODE FileListHead;
|
||||
PCFFILE_NODE FileListTail;
|
||||
CCABCodec *Codec;
|
||||
unsigned long CodecId;
|
||||
bool CodecSelected;
|
||||
void* InputBuffer;
|
||||
void* CurrentIBuffer; // Current offset in input buffer
|
||||
unsigned long CurrentIBufferSize; // Bytes left in input buffer
|
||||
void* OutputBuffer;
|
||||
unsigned long TotalCompSize; // Total size of current CFDATA block
|
||||
void* CurrentOBuffer; // Current offset in output buffer
|
||||
unsigned long CurrentOBufferSize; // Bytes left in output buffer
|
||||
unsigned long BytesLeftInCabinet;
|
||||
bool RestartSearch;
|
||||
unsigned long LastFileOffset; // Uncompressed offset of last extracted file
|
||||
unsigned long 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
|
||||
unsigned long TotalHeaderSize; // Size of header and optional fields
|
||||
unsigned long NextFieldsSize; // Size of next cabinet name and next disk label
|
||||
unsigned long TotalFolderSize; // Size of all folder entries
|
||||
unsigned long TotalFileSize; // Size of all file entries
|
||||
unsigned long FolderUncompSize; // Uncompressed size of folder
|
||||
unsigned long BytesLeftInBlock; // Number of bytes left in current block
|
||||
bool ReuseBlock;
|
||||
char DestPath[MAX_PATH];
|
||||
char CabinetReservedFile[MAX_PATH];
|
||||
void* CabinetReservedFileBuffer;
|
||||
unsigned long CabinetReservedFileSize;
|
||||
FILEHANDLE FileHandle;
|
||||
bool FileOpen;
|
||||
CFHEADER CABHeader;
|
||||
unsigned long CabinetReserved;
|
||||
unsigned long FolderReserved;
|
||||
unsigned long DataReserved;
|
||||
PCFFOLDER_NODE FolderListHead;
|
||||
PCFFOLDER_NODE FolderListTail;
|
||||
PCFFOLDER_NODE CurrentFolderNode;
|
||||
PCFDATA_NODE CurrentDataNode;
|
||||
PCFFILE_NODE FileListHead;
|
||||
PCFFILE_NODE FileListTail;
|
||||
CCABCodec *Codec;
|
||||
unsigned long CodecId;
|
||||
bool CodecSelected;
|
||||
void* InputBuffer;
|
||||
void* CurrentIBuffer; // Current offset in input buffer
|
||||
unsigned long CurrentIBufferSize; // Bytes left in input buffer
|
||||
void* OutputBuffer;
|
||||
unsigned long TotalCompSize; // Total size of current CFDATA block
|
||||
void* CurrentOBuffer; // Current offset in output buffer
|
||||
unsigned long CurrentOBufferSize; // Bytes left in output buffer
|
||||
unsigned long BytesLeftInCabinet;
|
||||
bool RestartSearch;
|
||||
unsigned long LastFileOffset; // Uncompressed offset of last extracted file
|
||||
#ifndef CAB_READ_ONLY
|
||||
unsigned long LastBlockStart; // Uncompressed offset of last block in folder
|
||||
unsigned long MaxDiskSize;
|
||||
unsigned long DiskSize;
|
||||
unsigned long PrevCabinetNumber; // Previous cabinet number (where split file starts)
|
||||
bool CreateNewDisk;
|
||||
bool CreateNewFolder;
|
||||
unsigned long LastBlockStart; // Uncompressed offset of last block in folder
|
||||
unsigned long MaxDiskSize;
|
||||
unsigned long DiskSize;
|
||||
unsigned long PrevCabinetNumber; // Previous cabinet number (where split file starts)
|
||||
bool CreateNewDisk;
|
||||
bool CreateNewFolder;
|
||||
|
||||
CCFDATAStorage *ScratchFile;
|
||||
FILEHANDLE SourceFile;
|
||||
bool ContinueFile;
|
||||
unsigned long TotalBytesLeft;
|
||||
bool BlockIsSplit; // true if current data block is split
|
||||
unsigned long NextFolderNumber; // Zero based folder number
|
||||
CCFDATAStorage *ScratchFile;
|
||||
FILEHANDLE SourceFile;
|
||||
bool ContinueFile;
|
||||
unsigned long TotalBytesLeft;
|
||||
bool BlockIsSplit; // true if current data block is split
|
||||
unsigned long NextFolderNumber; // Zero based folder number
|
||||
#endif /* CAB_READ_ONLY */
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
unsigned long 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;
|
||||
unsigned long Mode;
|
||||
bool PromptOnOverwrite;
|
||||
char Location[MAX_PATH];
|
||||
char FileName[MAX_PATH];
|
||||
};
|
||||
|
||||
#endif /* __CABMAN_H */
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,45 +10,45 @@
|
|||
#include "cabinet.h"
|
||||
|
||||
typedef struct _CABINET_NAME {
|
||||
struct _CABINET_NAME *Next;
|
||||
unsigned long DiskNumber;
|
||||
char Name[128];
|
||||
struct _CABINET_NAME *Next;
|
||||
unsigned long DiskNumber;
|
||||
char Name[128];
|
||||
} CABINET_NAME, *PCABINET_NAME;
|
||||
|
||||
typedef struct _DISK_NUMBER {
|
||||
struct _DISK_NUMBER *Next;
|
||||
unsigned long DiskNumber;
|
||||
unsigned long Number;
|
||||
struct _DISK_NUMBER *Next;
|
||||
unsigned long DiskNumber;
|
||||
unsigned long 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();
|
||||
unsigned long Load(char* FileName);
|
||||
unsigned long Parse();
|
||||
void SetFileRelativePath(char* Path);
|
||||
CDFParser();
|
||||
virtual ~CDFParser();
|
||||
unsigned long Load(char* FileName);
|
||||
unsigned long Parse();
|
||||
void SetFileRelativePath(char* Path);
|
||||
bool InfFileOnly;
|
||||
bool DontGenerateInf;
|
||||
char FileRelativePath[300];
|
||||
bool DontGenerateInf;
|
||||
char FileRelativePath[300];
|
||||
private:
|
||||
/* Event handlers */
|
||||
virtual bool OnDiskLabel(unsigned long Number, char* Label);
|
||||
virtual bool OnCabinetName(unsigned long Number, char* Name);
|
||||
/* Event handlers */
|
||||
virtual bool OnDiskLabel(unsigned long Number, char* Label);
|
||||
virtual bool OnCabinetName(unsigned long Number, char* Name);
|
||||
|
||||
void WriteInfLine(char* InfLine);
|
||||
bool SetDiskName(PCABINET_NAME *List, unsigned long Number, char* String);
|
||||
bool GetDiskName(PCABINET_NAME *List, unsigned long Number, char* String);
|
||||
bool SetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long Value);
|
||||
bool GetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long* Value);
|
||||
bool DoDiskLabel(unsigned long Number, char* Label);
|
||||
void DoDiskLabelTemplate(char* Template);
|
||||
bool DoCabinetName(unsigned long Number, char* Name);
|
||||
void DoCabinetNameTemplate(char* Template);
|
||||
void DoInfFileName(char* InfFileName);
|
||||
unsigned long DoMaxDiskSize(bool NumberValid, unsigned long Number);
|
||||
unsigned long SetupNewDisk();
|
||||
unsigned long PerformSetCommand();
|
||||
unsigned long PerformNewCommand();
|
||||
unsigned long PerformInfBeginCommand();
|
||||
unsigned long PerformInfEndCommand();
|
||||
unsigned long PerformCommand();
|
||||
unsigned long PerformFileCopy();
|
||||
void SkipSpaces();
|
||||
bool IsNextToken(DFP_TOKEN Token, bool NoSpaces);
|
||||
bool ReadLine();
|
||||
void NextToken();
|
||||
/* Parsing */
|
||||
bool FileLoaded;
|
||||
FILEHANDLE FileHandle;
|
||||
char* FileBuffer;
|
||||
unsigned long FileBufferSize;
|
||||
unsigned long CurrentOffset;
|
||||
char Line[128];
|
||||
unsigned long LineLength;
|
||||
unsigned long CurrentLine;
|
||||
unsigned long CurrentChar;
|
||||
/* Token */
|
||||
DFP_TOKEN CurrentToken;
|
||||
unsigned long CurrentInteger;
|
||||
char CurrentString[256];
|
||||
void WriteInfLine(char* InfLine);
|
||||
bool SetDiskName(PCABINET_NAME *List, unsigned long Number, char* String);
|
||||
bool GetDiskName(PCABINET_NAME *List, unsigned long Number, char* String);
|
||||
bool SetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long Value);
|
||||
bool GetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long* Value);
|
||||
bool DoDiskLabel(unsigned long Number, char* Label);
|
||||
void DoDiskLabelTemplate(char* Template);
|
||||
bool DoCabinetName(unsigned long Number, char* Name);
|
||||
void DoCabinetNameTemplate(char* Template);
|
||||
void DoInfFileName(char* InfFileName);
|
||||
unsigned long DoMaxDiskSize(bool NumberValid, unsigned long Number);
|
||||
unsigned long SetupNewDisk();
|
||||
unsigned long PerformSetCommand();
|
||||
unsigned long PerformNewCommand();
|
||||
unsigned long PerformInfBeginCommand();
|
||||
unsigned long PerformInfEndCommand();
|
||||
unsigned long PerformCommand();
|
||||
unsigned long PerformFileCopy();
|
||||
void SkipSpaces();
|
||||
bool IsNextToken(DFP_TOKEN Token, bool NoSpaces);
|
||||
bool ReadLine();
|
||||
void NextToken();
|
||||
/* Parsing */
|
||||
bool FileLoaded;
|
||||
FILEHANDLE FileHandle;
|
||||
char* FileBuffer;
|
||||
unsigned long FileBufferSize;
|
||||
unsigned long CurrentOffset;
|
||||
char Line[128];
|
||||
unsigned long LineLength;
|
||||
unsigned long CurrentLine;
|
||||
unsigned long CurrentChar;
|
||||
/* Token */
|
||||
DFP_TOKEN CurrentToken;
|
||||
unsigned long CurrentInteger;
|
||||
char CurrentString[256];
|
||||
|
||||
/* State */
|
||||
bool CabinetCreated;
|
||||
bool DiskCreated;
|
||||
bool FolderCreated;
|
||||
/* Standard directive variable */
|
||||
bool Cabinet;
|
||||
unsigned long CabinetFileCountThreshold;
|
||||
PCABINET_NAME CabinetName;
|
||||
bool CabinetNameTemplateSet;
|
||||
char CabinetNameTemplate[128];
|
||||
bool InfFileNameSet;
|
||||
char InfFileName[256];
|
||||
bool Compress;
|
||||
unsigned long CompressionType;
|
||||
PCABINET_NAME DiskLabel;
|
||||
bool DiskLabelTemplateSet;
|
||||
char DiskLabelTemplate[128];
|
||||
unsigned long FolderFileCountThreshold;
|
||||
unsigned long FolderSizeThreshold;
|
||||
unsigned long MaxCabinetSize;
|
||||
unsigned long MaxDiskFileCount;
|
||||
PDISK_NUMBER MaxDiskSize;
|
||||
bool MaxDiskSizeAllSet;
|
||||
unsigned long MaxDiskSizeAll;
|
||||
unsigned long ReservePerCabinetSize;
|
||||
unsigned long ReservePerDataBlockSize;
|
||||
unsigned long ReservePerFolderSize;
|
||||
char SourceDir[256];
|
||||
FILEHANDLE InfFileHandle;
|
||||
bool InfModeEnabled;
|
||||
/* State */
|
||||
bool CabinetCreated;
|
||||
bool DiskCreated;
|
||||
bool FolderCreated;
|
||||
/* Standard directive variable */
|
||||
bool Cabinet;
|
||||
unsigned long CabinetFileCountThreshold;
|
||||
PCABINET_NAME CabinetName;
|
||||
bool CabinetNameTemplateSet;
|
||||
char CabinetNameTemplate[128];
|
||||
bool InfFileNameSet;
|
||||
char InfFileName[256];
|
||||
bool Compress;
|
||||
unsigned long CompressionType;
|
||||
PCABINET_NAME DiskLabel;
|
||||
bool DiskLabelTemplateSet;
|
||||
char DiskLabelTemplate[128];
|
||||
unsigned long FolderFileCountThreshold;
|
||||
unsigned long FolderSizeThreshold;
|
||||
unsigned long MaxCabinetSize;
|
||||
unsigned long MaxDiskFileCount;
|
||||
PDISK_NUMBER MaxDiskSize;
|
||||
bool MaxDiskSizeAllSet;
|
||||
unsigned long MaxDiskSizeAll;
|
||||
unsigned long ReservePerCabinetSize;
|
||||
unsigned long ReservePerDataBlockSize;
|
||||
unsigned long ReservePerFolderSize;
|
||||
char SourceDir[256];
|
||||
FILEHANDLE InfFileHandle;
|
||||
bool InfModeEnabled;
|
||||
};
|
||||
|
||||
#endif /* __DFP_H */
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
* FILE: tools/cabman/main.cpp
|
||||
* PURPOSE: Main program
|
||||
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
||||
* Colin Finck <mail@colinfinck.de>
|
||||
* 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
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -40,15 +42,16 @@ char* Pad(char* Str, char PadChar, unsigned int Length)
|
|||
* Str must be at least Length + 1 bytes
|
||||
*/
|
||||
{
|
||||
unsigned int Len;
|
||||
unsigned int Len;
|
||||
|
||||
Len = strlen(Str);
|
||||
Len = 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,24 +65,24 @@ char* Date2Str(char* Str, unsigned short Date)
|
|||
* Pointer to string
|
||||
*/
|
||||
{
|
||||
unsigned long dw;
|
||||
unsigned long 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,33 +96,33 @@ char* Time2Str(char* Str, unsigned short Time)
|
|||
* Pointer to string
|
||||
*/
|
||||
{
|
||||
bool PM;
|
||||
unsigned long Hour;
|
||||
unsigned long dw;
|
||||
bool PM;
|
||||
unsigned long Hour;
|
||||
unsigned long 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,32 +136,32 @@ char* Attr2Str(char* Str, unsigned short 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -169,9 +172,9 @@ CCABManager::CCABManager()
|
|||
* FUNCTION: Default constructor
|
||||
*/
|
||||
{
|
||||
ProcessAll = false;
|
||||
InfFileOnly = false;
|
||||
Mode = CM_MODE_DISPLAY;
|
||||
ProcessAll = false;
|
||||
InfFileOnly = false;
|
||||
Mode = CM_MODE_DISPLAY;
|
||||
}
|
||||
|
||||
|
||||
|
@ -188,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[])
|
||||
|
@ -224,91 +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;
|
||||
case 'c':
|
||||
case 'C': Mode = CM_MODE_CREATE; break;
|
||||
case 'd':
|
||||
case 'D': Mode = CM_MODE_DISPLAY; break;
|
||||
case 'e':
|
||||
case 'E': Mode = CM_MODE_EXTRACT; 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]);
|
||||
}
|
||||
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;
|
||||
default:
|
||||
printf("Bad parameter %s.\n", argv[i]);
|
||||
return false;
|
||||
}
|
||||
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]);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
switch (argv[i][1])
|
||||
{
|
||||
case 'a':
|
||||
case 'A':
|
||||
ProcessAll = true;
|
||||
break;
|
||||
|
||||
if (ShowUsage) {
|
||||
Usage();
|
||||
return false;
|
||||
}
|
||||
case 'c':
|
||||
case 'C':
|
||||
Mode = CM_MODE_CREATE;
|
||||
break;
|
||||
|
||||
/* FIXME */
|
||||
SelectCodec(CAB_CODEC_MSZIP);
|
||||
case 'd':
|
||||
case 'D':
|
||||
Mode = CM_MODE_DISPLAY;
|
||||
break;
|
||||
|
||||
return true;
|
||||
case 'e':
|
||||
case 'E':
|
||||
Mode = CM_MODE_EXTRACT;
|
||||
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]);
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
printf("Bad parameter %s.\n", argv[i]);
|
||||
return false;
|
||||
}
|
||||
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]);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ShowUsage)
|
||||
{
|
||||
Usage();
|
||||
return false;
|
||||
}
|
||||
|
||||
/* FIXME */
|
||||
SelectCodec(CAB_CODEC_MSZIP);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -317,17 +364,18 @@ bool CCABManager::CreateCabinet()
|
|||
* FUNCTION: Create cabinet
|
||||
*/
|
||||
{
|
||||
unsigned long Status;
|
||||
unsigned long 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -336,31 +384,34 @@ bool CCABManager::CreateSimpleCabinet()
|
|||
* FUNCTION: Create cabinet
|
||||
*/
|
||||
{
|
||||
unsigned long Status;
|
||||
unsigned long Status;
|
||||
|
||||
Status = NewCabinet();
|
||||
if (Status != CAB_STATUS_SUCCESS) {
|
||||
DPRINT(MIN_TRACE, ("Cannot create cabinet (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
Status = NewCabinet();
|
||||
if (Status != CAB_STATUS_SUCCESS)
|
||||
{
|
||||
DPRINT(MIN_TRACE, ("Cannot create cabinet (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
|
||||
Status = AddFile(FileName);
|
||||
if (Status != CAB_STATUS_SUCCESS) {
|
||||
DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
Status = AddFile(FileName);
|
||||
if (Status != CAB_STATUS_SUCCESS)
|
||||
{
|
||||
DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
|
||||
Status = WriteDisk(false);
|
||||
if (Status == CAB_STATUS_SUCCESS)
|
||||
Status = CloseDisk();
|
||||
if (Status != CAB_STATUS_SUCCESS) {
|
||||
DPRINT(MIN_TRACE, ("Cannot write disk (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
Status = WriteDisk(false);
|
||||
if (Status == CAB_STATUS_SUCCESS)
|
||||
Status = CloseDisk();
|
||||
if (Status != CAB_STATUS_SUCCESS)
|
||||
{
|
||||
DPRINT(MIN_TRACE, ("Cannot write disk (%d).\n", (unsigned int)Status));
|
||||
return false;
|
||||
}
|
||||
|
||||
CloseCabinet();
|
||||
CloseCabinet();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -369,53 +420,62 @@ bool CCABManager::DisplayCabinet()
|
|||
* FUNCTION: Display cabinet contents
|
||||
*/
|
||||
{
|
||||
CAB_SEARCH Search;
|
||||
char Str[20];
|
||||
unsigned long FileCount = 0;
|
||||
unsigned long ByteCount = 0;
|
||||
CAB_SEARCH Search;
|
||||
char Str[20];
|
||||
unsigned long FileCount = 0;
|
||||
unsigned long 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -424,37 +484,44 @@ bool CCABManager::ExtractFromCabinet()
|
|||
* FUNCTION: Extract file(s) from cabinet
|
||||
*/
|
||||
{
|
||||
CAB_SEARCH Search;
|
||||
unsigned long Status;
|
||||
CAB_SEARCH Search;
|
||||
unsigned long 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;
|
||||
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_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 (%d).\n", (unsigned int)Status);
|
||||
return false;
|
||||
}
|
||||
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
printf("Cannot open file: %s.\n", GetCabinetName());
|
||||
if (FindFirst("", &Search) == CAB_STATUS_SUCCESS)
|
||||
{
|
||||
do
|
||||
{
|
||||
switch (Status = ExtractFile(Search.FileName)) {
|
||||
case CAB_STATUS_SUCCESS:
|
||||
break;
|
||||
|
||||
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_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 (%d).\n", (unsigned int)Status);
|
||||
return false;
|
||||
}
|
||||
} while (FindNext(&Search) == CAB_STATUS_SUCCESS);
|
||||
}
|
||||
return true;
|
||||
} else
|
||||
printf("Cannot open file: %s.\n", GetCabinetName());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -463,17 +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;
|
||||
case CM_MODE_DISPLAY: return DisplayCabinet(); break;
|
||||
case CM_MODE_EXTRACT: return ExtractFromCabinet(); break;
|
||||
case CM_MODE_CREATE_SIMPLE: return CreateSimpleCabinet(); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
switch (Mode)
|
||||
{
|
||||
case CM_MODE_CREATE:
|
||||
return CreateCabinet();
|
||||
break;
|
||||
|
||||
case CM_MODE_DISPLAY:
|
||||
return DisplayCabinet();
|
||||
break;
|
||||
|
||||
case CM_MODE_EXTRACT:
|
||||
return ExtractFromCabinet();
|
||||
break;
|
||||
|
||||
case CM_MODE_CREATE_SIMPLE:
|
||||
return CreateSimpleCabinet();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -490,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -507,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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -521,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -534,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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -546,14 +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 */
|
||||
|
|
|
@ -4,11 +4,13 @@
|
|||
* FILE: tools/cabman/mszip.cpp
|
||||
* PURPOSE: CAB codec for MSZIP compressed data
|
||||
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
||||
* Colin Finck <mail@colinfinck.de>
|
||||
* NOTES: The ZLIB does the real work. Get the full version
|
||||
* from http://www.cdrom.com/pub/infozip/zlib/
|
||||
* 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
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "mszip.h"
|
||||
|
@ -18,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,47 +65,50 @@ unsigned long CMSZipCodec::Compress(void* OutputBuffer,
|
|||
* OutputLength = Address of buffer to place size of compressed data
|
||||
*/
|
||||
{
|
||||
unsigned short* Magic;
|
||||
unsigned short* Magic;
|
||||
|
||||
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
|
||||
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
|
||||
|
||||
Magic = (unsigned short*)OutputBuffer;
|
||||
*Magic = MSZIP_MAGIC;
|
||||
Magic = (unsigned short*)OutputBuffer;
|
||||
*Magic = MSZIP_MAGIC;
|
||||
|
||||
ZStream.next_in = (unsigned char*)InputBuffer;
|
||||
ZStream.avail_in = InputLength;
|
||||
ZStream.next_out = (unsigned char*)((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*)((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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -120,53 +125,58 @@ unsigned long CMSZipCodec::Uncompress(void* OutputBuffer,
|
|||
* OutputLength = Address of buffer to place size of uncompressed data
|
||||
*/
|
||||
{
|
||||
unsigned short Magic;
|
||||
unsigned short Magic;
|
||||
|
||||
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
|
||||
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
|
||||
|
||||
Magic = *((unsigned short*)InputBuffer);
|
||||
Magic = *((unsigned short*)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*)((unsigned long)InputBuffer + 2);
|
||||
ZStream.avail_in = InputLength - 2;
|
||||
ZStream.next_out = (unsigned char*)OutputBuffer;
|
||||
ZStream.avail_out = CAB_BLOCKSIZE + 12;
|
||||
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 */
|
||||
|
|
|
@ -17,23 +17,23 @@
|
|||
|
||||
class CMSZipCodec : public CCABCodec {
|
||||
public:
|
||||
/* Default constructor */
|
||||
CMSZipCodec();
|
||||
/* Default destructor */
|
||||
virtual ~CMSZipCodec();
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Default constructor */
|
||||
CMSZipCodec();
|
||||
/* Default destructor */
|
||||
virtual ~CMSZipCodec();
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
private:
|
||||
int Status;
|
||||
z_stream ZStream; /* Zlib stream */
|
||||
int Status;
|
||||
z_stream ZStream; /* Zlib stream */
|
||||
};
|
||||
|
||||
#endif /* __MSZIP_H */
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
* FILE: tools/cabman/raw.cpp
|
||||
* PURPOSE: CAB codec for uncompressed "raw" data
|
||||
* PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
||||
* Colin Finck <mail@colinfinck.de>
|
||||
* 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
|
||||
*/
|
||||
#include "raw.h"
|
||||
|
||||
|
@ -30,9 +32,9 @@ CRawCodec::~CRawCodec()
|
|||
|
||||
|
||||
unsigned long CRawCodec::Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength)
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength)
|
||||
/*
|
||||
* FUNCTION: Compresses data in a buffer
|
||||
* ARGUMENTS:
|
||||
|
@ -42,15 +44,15 @@ unsigned long 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;
|
||||
}
|
||||
|
||||
unsigned long CRawCodec::Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength)
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength)
|
||||
/*
|
||||
* FUNCTION: Uncompresses data in a buffer
|
||||
* ARGUMENTS:
|
||||
|
@ -60,9 +62,9 @@ unsigned long 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 */
|
||||
|
|
|
@ -14,20 +14,20 @@
|
|||
|
||||
class CRawCodec : public CCABCodec {
|
||||
public:
|
||||
/* Default constructor */
|
||||
CRawCodec();
|
||||
/* Default destructor */
|
||||
virtual ~CRawCodec();
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Default constructor */
|
||||
CRawCodec();
|
||||
/* Default destructor */
|
||||
virtual ~CRawCodec();
|
||||
/* Compresses a data block */
|
||||
virtual unsigned long Compress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
/* Uncompresses a data block */
|
||||
virtual unsigned long Uncompress(void* OutputBuffer,
|
||||
void* InputBuffer,
|
||||
unsigned long InputLength,
|
||||
unsigned long* OutputLength);
|
||||
};
|
||||
|
||||
#endif /* __RAW_H */
|
||||
|
|
Loading…
Reference in a new issue