64-Bit Fixes for cabman (patch from Colin Finck)

See issue #2236 for more details.

svn path=/trunk/; revision=26912
This commit is contained in:
Christoph von Wittich 2007-05-27 10:26:43 +00:00
parent cdda19fd20
commit a94fcd5985
10 changed files with 457 additions and 444 deletions

File diff suppressed because it is too large Load diff

View file

@ -19,6 +19,8 @@
#define MAX_PATH 260 #define MAX_PATH 260
#endif #endif
#endif #endif
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -56,7 +58,7 @@
#ifdef DBG #ifdef DBG
extern unsigned long DebugTraceLevel; extern uint32_t DebugTraceLevel;
#ifdef _MSC_VER #ifdef _MSC_VER
#define __FUNCTION__ "" #define __FUNCTION__ ""
@ -121,59 +123,59 @@ extern unsigned long DebugTraceLevel;
typedef struct _CFHEADER typedef struct _CFHEADER
{ {
unsigned long Signature; // File signature 'MSCF' (CAB_SIGNATURE) uint32_t Signature; // File signature 'MSCF' (CAB_SIGNATURE)
unsigned long Reserved1; // Reserved field uint32_t Reserved1; // Reserved field
unsigned long CabinetSize; // Cabinet file size uint32_t CabinetSize; // Cabinet file size
unsigned long Reserved2; // Reserved field uint32_t Reserved2; // Reserved field
unsigned long FileTableOffset; // Offset of first CFFILE uint32_t FileTableOffset; // Offset of first CFFILE
unsigned long Reserved3; // Reserved field uint32_t Reserved3; // Reserved field
unsigned short Version; // Cabinet version (CAB_VERSION) uint16_t Version; // Cabinet version (CAB_VERSION)
unsigned short FolderCount; // Number of folders uint16_t FolderCount; // Number of folders
unsigned short FileCount; // Number of files uint16_t FileCount; // Number of files
unsigned short Flags; // Cabinet flags (CAB_FLAG_*) uint16_t Flags; // Cabinet flags (CAB_FLAG_*)
unsigned short SetID; // Cabinet set id uint16_t SetID; // Cabinet set id
unsigned short CabinetNumber; // Zero-based cabinet number uint16_t CabinetNumber; // Zero-based cabinet number
/* Optional fields (depends on Flags) /* Optional fields (depends on Flags)
unsigned short CabinetResSize // Per-cabinet reserved area size uint16_t CabinetResSize // Per-cabinet reserved area size
char FolderResSize // Per-folder reserved area size char FolderResSize // Per-folder reserved area size
char FileResSize // Per-file reserved area size char FileResSize // Per-file reserved area size
char CabinetReserved[] // Per-cabinet reserved area char CabinetReserved[] // Per-cabinet reserved area
char CabinetPrev[] // Name of previous cabinet file char CabinetPrev[] // Name of previous cabinet file
char DiskPrev[] // Name of previous disk char DiskPrev[] // Name of previous disk
char CabinetNext[] // Name of next cabinet file char CabinetNext[] // Name of next cabinet file
char DiskNext[] // Name of next disk char DiskNext[] // Name of next disk
*/ */
} CFHEADER, *PCFHEADER; } CFHEADER, *PCFHEADER;
typedef struct _CFFOLDER typedef struct _CFFOLDER
{ {
unsigned long DataOffset; // Absolute offset of first CFDATA block in this folder uint32_t DataOffset; // Absolute offset of first CFDATA block in this folder
unsigned short DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet uint16_t 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 uint16_t CompressionType; // Type of compression used for all CFDATA blocks in this folder
/* Optional fields (depends on Flags) /* Optional fields (depends on Flags)
char FolderReserved[] // Per-folder reserved area char FolderReserved[] // Per-folder reserved area
*/ */
} CFFOLDER, *PCFFOLDER; } CFFOLDER, *PCFFOLDER;
typedef struct _CFFILE typedef struct _CFFILE
{ {
unsigned long FileSize; // Uncompressed file size in bytes uint32_t FileSize; // Uncompressed file size in bytes
unsigned long FileOffset; // Uncompressed offset of file in the folder uint32_t FileOffset; // Uncompressed offset of file in the folder
unsigned short FileControlID; // File control ID (CAB_FILE_*) uint16_t FileControlID; // File control ID (CAB_FILE_*)
unsigned short FileDate; // File date stamp, as used by DOS uint16_t FileDate; // File date stamp, as used by DOS
unsigned short FileTime; // File time stamp, as used by DOS uint16_t FileTime; // File time stamp, as used by DOS
unsigned short Attributes; // File attributes (CAB_ATTRIB_*) uint16_t Attributes; // File attributes (CAB_ATTRIB_*)
/* After this is the NULL terminated filename */ /* After this is the NULL terminated filename */
} CFFILE, *PCFFILE; } CFFILE, *PCFFILE;
typedef struct _CFDATA typedef struct _CFDATA
{ {
unsigned long Checksum; // Checksum of CFDATA entry uint32_t Checksum; // Checksum of CFDATA entry
unsigned short CompSize; // Number of compressed bytes in this block uint16_t CompSize; // Number of compressed bytes in this block
unsigned short UncompSize; // Number of uncompressed bytes in this block uint16_t UncompSize; // Number of uncompressed bytes in this block
/* Optional fields (depends on Flags) /* Optional fields (depends on Flags)
char DataReserved[] // Per-datablock reserved area char DataReserved[] // Per-datablock reserved area
*/ */
@ -183,25 +185,25 @@ typedef struct _CFDATA_NODE
{ {
struct _CFDATA_NODE *Next; struct _CFDATA_NODE *Next;
struct _CFDATA_NODE *Prev; struct _CFDATA_NODE *Prev;
unsigned long ScratchFilePosition; // Absolute offset in scratch file uint32_t ScratchFilePosition; // Absolute offset in scratch file
unsigned long AbsoluteOffset; // Absolute offset in cabinet uint32_t AbsoluteOffset; // Absolute offset in cabinet
unsigned long UncompOffset; // Uncompressed offset in folder uint32_t UncompOffset; // Uncompressed offset in folder
CFDATA Data; CFDATA Data;
} CFDATA_NODE, *PCFDATA_NODE; } CFDATA_NODE, *PCFDATA_NODE;
typedef struct _CFFOLDER_NODE typedef struct _CFFOLDER_NODE
{ {
struct _CFFOLDER_NODE *Next; struct _CFFOLDER_NODE *Next;
struct _CFFOLDER_NODE *Prev; struct _CFFOLDER_NODE *Prev;
unsigned long UncompOffset; // File size accumulator uint32_t UncompOffset; // File size accumulator
unsigned long AbsoluteOffset; uint32_t AbsoluteOffset;
unsigned long TotalFolderSize; // Total size of folder in current disk uint32_t TotalFolderSize; // Total size of folder in current disk
PCFDATA_NODE DataListHead; PCFDATA_NODE DataListHead;
PCFDATA_NODE DataListTail; PCFDATA_NODE DataListTail;
unsigned long Index; uint32_t Index;
bool Commit; // true if the folder should be committed bool Commit; // true if the folder should be committed
bool Delete; // true if marked for deletion bool Delete; // true if marked for deletion
CFFOLDER Folder; CFFOLDER Folder;
} CFFOLDER_NODE, *PCFFOLDER_NODE; } CFFOLDER_NODE, *PCFFOLDER_NODE;
typedef struct _CFFILE_NODE typedef struct _CFFILE_NODE
@ -213,7 +215,7 @@ typedef struct _CFFILE_NODE
PCFDATA_NODE DataBlock; // First data block of file. NULL if not known PCFDATA_NODE DataBlock; // First data block of file. NULL if not known
bool Commit; // true if the file data should be committed bool Commit; // true if the file data should be committed
bool Delete; // true if marked for deletion bool Delete; // true if marked for deletion
PCFFOLDER_NODE FolderNode; // Folder this file belong to PCFFOLDER_NODE FolderNode; // Folder this file belong to
} CFFILE_NODE, *PCFFILE_NODE; } CFFILE_NODE, *PCFFILE_NODE;
@ -252,15 +254,15 @@ public:
/* Default destructor */ /* Default destructor */
virtual ~CCABCodec() {}; virtual ~CCABCodec() {};
/* Compresses a data block */ /* Compresses a data block */
virtual unsigned long Compress(void* OutputBuffer, virtual uint32_t Compress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) = 0; uint32_t* OutputLength) = 0;
/* Uncompresses a data block */ /* Uncompresses a data block */
virtual unsigned long Uncompress(void* OutputBuffer, virtual uint32_t Uncompress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) = 0; uint32_t* OutputLength) = 0;
}; };
@ -287,13 +289,13 @@ public:
CCFDATAStorage(); CCFDATAStorage();
/* Default destructor */ /* Default destructor */
virtual ~CCFDATAStorage(); virtual ~CCFDATAStorage();
unsigned long Create(char* FileName); uint32_t Create(char* FileName);
unsigned long Destroy(); uint32_t Destroy();
unsigned long Truncate(); uint32_t Truncate();
unsigned long Position(); uint32_t Position();
unsigned long Seek(long Position); uint32_t Seek(int32_t Position);
unsigned long ReadBlock(PCFDATA Data, void* Buffer, unsigned long* BytesRead); uint32_t ReadBlock(PCFDATA Data, void* Buffer, uint32_t* BytesRead);
unsigned long WriteBlock(PCFDATA Data, void* Buffer, unsigned long* BytesWritten); uint32_t WriteBlock(PCFDATA Data, void* Buffer, uint32_t* BytesWritten);
private: private:
char FullName[MAX_PATH]; char FullName[MAX_PATH];
bool FileCreated; bool FileCreated;
@ -317,7 +319,7 @@ public:
/* Removes a filename from a fully qualified filename */ /* Removes a filename from a fully qualified filename */
void RemoveFileName(char* Path); void RemoveFileName(char* Path);
/* Normalizes a path */ /* Normalizes a path */
bool NormalizePath(char* Path, unsigned long Length); bool NormalizePath(char* Path, uint32_t Length);
/* Returns name of cabinet file */ /* Returns name of cabinet file */
char* GetCabinetName(); char* GetCabinetName();
/* Sets the name of the cabinet file */ /* Sets the name of the cabinet file */
@ -331,40 +333,40 @@ public:
/* Returns destination path */ /* Returns destination path */
char* GetDestinationPath(); char* GetDestinationPath();
/* Returns zero-based current disk number */ /* Returns zero-based current disk number */
unsigned long GetCurrentDiskNumber(); uint32_t GetCurrentDiskNumber();
/* Opens the current cabinet file */ /* Opens the current cabinet file */
unsigned long Open(); uint32_t Open();
/* Closes the current open cabinet file */ /* Closes the current open cabinet file */
void Close(); void Close();
/* Locates the first file in the current cabinet file that matches a search criteria */ /* Locates the first file in the current cabinet file that matches a search criteria */
unsigned long FindFirst(char* FileName, PCAB_SEARCH Search); uint32_t FindFirst(char* FileName, PCAB_SEARCH Search);
/* Locates the next file in the current cabinet file */ /* Locates the next file in the current cabinet file */
unsigned long FindNext(PCAB_SEARCH Search); uint32_t FindNext(PCAB_SEARCH Search);
/* Extracts a file from the current cabinet file */ /* Extracts a file from the current cabinet file */
unsigned long ExtractFile(char* FileName); uint32_t ExtractFile(char* FileName);
/* Select codec engine to use */ /* Select codec engine to use */
void SelectCodec(unsigned long Id); void SelectCodec(uint32_t Id);
#ifndef CAB_READ_ONLY #ifndef CAB_READ_ONLY
/* Creates a new cabinet file */ /* Creates a new cabinet file */
unsigned long NewCabinet(); uint32_t NewCabinet();
/* Forces a new disk to be created */ /* Forces a new disk to be created */
unsigned long NewDisk(); uint32_t NewDisk();
/* Forces a new folder to be created */ /* Forces a new folder to be created */
unsigned long NewFolder(); uint32_t NewFolder();
/* Writes a file to scratch storage */ /* Writes a file to scratch storage */
unsigned long WriteFileToScratchStorage(PCFFILE_NODE FileNode); uint32_t WriteFileToScratchStorage(PCFFILE_NODE FileNode);
/* Forces the current disk to be written */ /* Forces the current disk to be written */
unsigned long WriteDisk(unsigned long MoreDisks); uint32_t WriteDisk(uint32_t MoreDisks);
/* Commits the current disk */ /* Commits the current disk */
unsigned long CommitDisk(unsigned long MoreDisks); uint32_t CommitDisk(uint32_t MoreDisks);
/* Closes the current disk */ /* Closes the current disk */
unsigned long CloseDisk(); uint32_t CloseDisk();
/* Closes the current cabinet */ /* Closes the current cabinet */
unsigned long CloseCabinet(); uint32_t CloseCabinet();
/* Adds a file to the current disk */ /* Adds a file to the current disk */
unsigned long AddFile(char* FileName); uint32_t AddFile(char* FileName);
/* Sets the maximum size of the current disk */ /* Sets the maximum size of the current disk */
void SetMaxDiskSize(unsigned long Size); void SetMaxDiskSize(uint32_t Size);
#endif /* CAB_READ_ONLY */ #endif /* CAB_READ_ONLY */
/* Default event handlers */ /* Default event handlers */
@ -379,17 +381,17 @@ public:
/* Handler called when a file is about to be added */ /* Handler called when a file is about to be added */
virtual void OnAdd(PCFFILE Entry, char* FileName); virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Handler called when a cabinet need a name */ /* Handler called when a cabinet need a name */
virtual bool OnCabinetName(unsigned long Number, char* Name); virtual bool OnCabinetName(uint32_t Number, char* Name);
/* Handler called when a disk needs a label */ /* Handler called when a disk needs a label */
virtual bool OnDiskLabel(unsigned long Number, char* Label); virtual bool OnDiskLabel(uint32_t Number, char* Label);
#endif /* CAB_READ_ONLY */ #endif /* CAB_READ_ONLY */
private: private:
PCFFOLDER_NODE LocateFolderNode(unsigned long Index); PCFFOLDER_NODE LocateFolderNode(uint32_t Index);
unsigned long GetAbsoluteOffset(PCFFILE_NODE File); uint32_t GetAbsoluteOffset(PCFFILE_NODE File);
unsigned long LocateFile(char* FileName, PCFFILE_NODE *File); uint32_t LocateFile(char* FileName, PCFFILE_NODE *File);
unsigned long ReadString(char* String, unsigned long MaxLength); uint32_t ReadString(char* String, uint32_t MaxLength);
unsigned long ReadFileTable(); uint32_t ReadFileTable();
unsigned long ReadDataBlocks(PCFFOLDER_NODE FolderNode); uint32_t ReadDataBlocks(PCFFOLDER_NODE FolderNode);
PCFFOLDER_NODE NewFolderNode(); PCFFOLDER_NODE NewFolderNode();
PCFFILE_NODE NewFileNode(); PCFFILE_NODE NewFileNode();
PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode); PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode);
@ -398,45 +400,45 @@ private:
void DestroyDeletedFileNodes(); void DestroyDeletedFileNodes();
void DestroyFolderNodes(); void DestroyFolderNodes();
void DestroyDeletedFolderNodes(); void DestroyDeletedFolderNodes();
unsigned long ComputeChecksum(void* Buffer, unsigned int Size, unsigned long Seed); uint32_t ComputeChecksum(void* Buffer, unsigned int Size, uint32_t Seed);
unsigned long ReadBlock(void* Buffer, unsigned long Size, unsigned long* BytesRead); uint32_t ReadBlock(void* Buffer, uint32_t Size, uint32_t* BytesRead);
#ifndef CAB_READ_ONLY #ifndef CAB_READ_ONLY
unsigned long InitCabinetHeader(); uint32_t InitCabinetHeader();
unsigned long WriteCabinetHeader(bool MoreDisks); uint32_t WriteCabinetHeader(bool MoreDisks);
unsigned long WriteFolderEntries(); uint32_t WriteFolderEntries();
unsigned long WriteFileEntries(); uint32_t WriteFileEntries();
unsigned long CommitDataBlocks(PCFFOLDER_NODE FolderNode); uint32_t CommitDataBlocks(PCFFOLDER_NODE FolderNode);
unsigned long WriteDataBlock(); uint32_t WriteDataBlock();
unsigned long GetAttributesOnFile(PCFFILE_NODE File); uint32_t GetAttributesOnFile(PCFFILE_NODE File);
unsigned long SetAttributesOnFile(PCFFILE_NODE File); uint32_t SetAttributesOnFile(PCFFILE_NODE File);
unsigned long GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File); uint32_t GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
#if !defined(WIN32) #if !defined(WIN32)
void ConvertDateAndTime(time_t* Time, unsigned short* DosDate, unsigned short* DosTime); void ConvertDateAndTime(time_t* Time, uint16_t* DosDate, uint16_t* DosTime);
#endif #endif
#endif /* CAB_READ_ONLY */ #endif /* CAB_READ_ONLY */
unsigned long CurrentDiskNumber; // Zero based disk number uint32_t CurrentDiskNumber; // Zero based disk number
char CabinetName[256]; // Filename of current cabinet char CabinetName[256]; // Filename of current cabinet
char CabinetPrev[256]; // Filename of previous cabinet char CabinetPrev[256]; // Filename of previous cabinet
char DiskPrev[256]; // Label of cabinet in file CabinetPrev char DiskPrev[256]; // Label of cabinet in file CabinetPrev
char CabinetNext[256]; // Filename of next cabinet char CabinetNext[256]; // Filename of next cabinet
char DiskNext[256]; // Label of cabinet in file CabinetNext char DiskNext[256]; // Label of cabinet in file CabinetNext
unsigned long TotalHeaderSize; // Size of header and optional fields uint32_t TotalHeaderSize; // Size of header and optional fields
unsigned long NextFieldsSize; // Size of next cabinet name and next disk label uint32_t NextFieldsSize; // Size of next cabinet name and next disk label
unsigned long TotalFolderSize; // Size of all folder entries uint32_t TotalFolderSize; // Size of all folder entries
unsigned long TotalFileSize; // Size of all file entries uint32_t TotalFileSize; // Size of all file entries
unsigned long FolderUncompSize; // Uncompressed size of folder uint32_t FolderUncompSize; // Uncompressed size of folder
unsigned long BytesLeftInBlock; // Number of bytes left in current block uint32_t BytesLeftInBlock; // Number of bytes left in current block
bool ReuseBlock; bool ReuseBlock;
char DestPath[MAX_PATH]; char DestPath[MAX_PATH];
char CabinetReservedFile[MAX_PATH]; char CabinetReservedFile[MAX_PATH];
void* CabinetReservedFileBuffer; void* CabinetReservedFileBuffer;
unsigned long CabinetReservedFileSize; uint32_t CabinetReservedFileSize;
FILEHANDLE FileHandle; FILEHANDLE FileHandle;
bool FileOpen; bool FileOpen;
CFHEADER CABHeader; CFHEADER CABHeader;
unsigned long CabinetReserved; uint32_t CabinetReserved;
unsigned long FolderReserved; uint32_t FolderReserved;
unsigned long DataReserved; uint32_t DataReserved;
PCFFOLDER_NODE FolderListHead; PCFFOLDER_NODE FolderListHead;
PCFFOLDER_NODE FolderListTail; PCFFOLDER_NODE FolderListTail;
PCFFOLDER_NODE CurrentFolderNode; PCFFOLDER_NODE CurrentFolderNode;
@ -444,32 +446,32 @@ private:
PCFFILE_NODE FileListHead; PCFFILE_NODE FileListHead;
PCFFILE_NODE FileListTail; PCFFILE_NODE FileListTail;
CCABCodec *Codec; CCABCodec *Codec;
unsigned long CodecId; uint32_t CodecId;
bool CodecSelected; bool CodecSelected;
void* InputBuffer; void* InputBuffer;
void* CurrentIBuffer; // Current offset in input buffer void* CurrentIBuffer; // Current offset in input buffer
unsigned long CurrentIBufferSize; // Bytes left in input buffer uint32_t CurrentIBufferSize; // Bytes left in input buffer
void* OutputBuffer; void* OutputBuffer;
unsigned long TotalCompSize; // Total size of current CFDATA block uint32_t TotalCompSize; // Total size of current CFDATA block
void* CurrentOBuffer; // Current offset in output buffer void* CurrentOBuffer; // Current offset in output buffer
unsigned long CurrentOBufferSize; // Bytes left in output buffer uint32_t CurrentOBufferSize; // Bytes left in output buffer
unsigned long BytesLeftInCabinet; uint32_t BytesLeftInCabinet;
bool RestartSearch; bool RestartSearch;
unsigned long LastFileOffset; // Uncompressed offset of last extracted file uint32_t LastFileOffset; // Uncompressed offset of last extracted file
#ifndef CAB_READ_ONLY #ifndef CAB_READ_ONLY
unsigned long LastBlockStart; // Uncompressed offset of last block in folder uint32_t LastBlockStart; // Uncompressed offset of last block in folder
unsigned long MaxDiskSize; uint32_t MaxDiskSize;
unsigned long DiskSize; uint32_t DiskSize;
unsigned long PrevCabinetNumber; // Previous cabinet number (where split file starts) uint32_t PrevCabinetNumber; // Previous cabinet number (where split file starts)
bool CreateNewDisk; bool CreateNewDisk;
bool CreateNewFolder; bool CreateNewFolder;
CCFDATAStorage *ScratchFile; CCFDATAStorage *ScratchFile;
FILEHANDLE SourceFile; FILEHANDLE SourceFile;
bool ContinueFile; bool ContinueFile;
unsigned long TotalBytesLeft; uint32_t TotalBytesLeft;
bool BlockIsSplit; // true if current data block is split bool BlockIsSplit; // true if current data block is split
unsigned long NextFolderNumber; // Zero based folder number uint32_t NextFolderNumber; // Zero based folder number
#endif /* CAB_READ_ONLY */ #endif /* CAB_READ_ONLY */
}; };

View file

@ -37,7 +37,7 @@ private:
virtual void OnAdd(PCFFILE Entry, char* FileName); virtual void OnAdd(PCFFILE Entry, char* FileName);
/* Configuration */ /* Configuration */
bool ProcessAll; bool ProcessAll;
unsigned long Mode; uint32_t Mode;
bool PromptOnOverwrite; bool PromptOnOverwrite;
char Location[MAX_PATH]; char Location[MAX_PATH];
char FileName[MAX_PATH]; char FileName[MAX_PATH];

View file

@ -11,6 +11,7 @@
* CSH 21/03-2001 Created * CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable * 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 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
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -20,31 +21,31 @@
#if defined(WIN32) #if defined(WIN32)
#define GetSizeOfFile(handle) _GetSizeOfFile(handle) #define GetSizeOfFile(handle) _GetSizeOfFile(handle)
static long _GetSizeOfFile(FILEHANDLE handle) static int32_t _GetSizeOfFile(FILEHANDLE handle)
{ {
unsigned long size = GetFileSize(handle, NULL); uint32_t size = GetFileSize(handle, NULL);
if (size == INVALID_FILE_SIZE) if (size == INVALID_FILE_SIZE)
return -1; return -1;
return size; return size;
} }
#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
static bool _ReadFileData(FILEHANDLE handle, void* buffer, unsigned long size, unsigned long* bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, uint32_t size, uint32_t* bytesread)
{ {
return ReadFile(handle, buffer, size, bytesread, NULL); return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL);
} }
#else #else
#define GetSizeOfFile(handle) _GetSizeOfFile(handle) #define GetSizeOfFile(handle) _GetSizeOfFile(handle)
static long _GetSizeOfFile(FILEHANDLE handle) static int32_t _GetSizeOfFile(FILEHANDLE handle)
{ {
long size; int32_t size;
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
size = ftell(handle); size = ftell(handle);
fseek(handle, 0, SEEK_SET); fseek(handle, 0, SEEK_SET);
return size; return size;
} }
#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
static bool _ReadFileData(FILEHANDLE handle, void* buffer, unsigned long size, unsigned long* bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, uint32_t size, uint32_t* bytesread)
{ {
*bytesread = fread(buffer, 1, size, handle); *bytesread = fread(buffer, 1, size, handle);
return *bytesread == size; return *bytesread == size;
@ -127,7 +128,7 @@ void CDFParser::WriteInfLine(char* InfLine)
char eolbuf[2]; char eolbuf[2];
char* destpath; char* destpath;
#if defined(WIN32) #if defined(WIN32)
unsigned long BytesWritten; uint32_t BytesWritten;
#endif #endif
if (DontGenerateInf) if (DontGenerateInf)
@ -173,7 +174,7 @@ void CDFParser::WriteInfLine(char* InfLine)
} }
#if defined(WIN32) #if defined(WIN32)
if (!WriteFile(InfFileHandle, InfLine, strlen(InfLine), &BytesWritten, NULL)) if (!WriteFile(InfFileHandle, InfLine, (DWORD)strlen(InfLine), (LPDWORD)&BytesWritten, NULL))
{ {
DPRINT(MID_TRACE, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError())); DPRINT(MID_TRACE, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError()));
return; return;
@ -187,7 +188,7 @@ void CDFParser::WriteInfLine(char* InfLine)
eolbuf[1] = 0x0a; eolbuf[1] = 0x0a;
#if defined(WIN32) #if defined(WIN32)
if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), &BytesWritten, NULL)) if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), (LPDWORD)&BytesWritten, NULL))
{ {
DPRINT(MID_TRACE, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError())); DPRINT(MID_TRACE, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError()));
return; return;
@ -199,7 +200,7 @@ void CDFParser::WriteInfLine(char* InfLine)
} }
unsigned long CDFParser::Load(char* FileName) uint32_t CDFParser::Load(char* FileName)
/* /*
* FUNCTION: Loads a directive file into memory * FUNCTION: Loads a directive file into memory
* ARGUMENTS: * ARGUMENTS:
@ -208,8 +209,8 @@ unsigned long CDFParser::Load(char* FileName)
* Status of operation * Status of operation
*/ */
{ {
unsigned long BytesRead; uint32_t BytesRead;
long FileSize; int32_t FileSize;
if (FileLoaded) if (FileLoaded)
return CAB_STATUS_SUCCESS; return CAB_STATUS_SUCCESS;
@ -238,7 +239,7 @@ unsigned long CDFParser::Load(char* FileName)
return CAB_STATUS_CANNOT_OPEN; return CAB_STATUS_CANNOT_OPEN;
} }
FileBufferSize = (unsigned long)FileSize; FileBufferSize = (uint32_t)FileSize;
FileBuffer = (char*)AllocateMemory(FileBufferSize); FileBuffer = (char*)AllocateMemory(FileBufferSize);
if (!FileBuffer) if (!FileBuffer)
@ -265,7 +266,7 @@ unsigned long CDFParser::Load(char* FileName)
} }
unsigned long CDFParser::Parse() uint32_t CDFParser::Parse()
/* /*
* FUNCTION: Parses a loaded directive file * FUNCTION: Parses a loaded directive file
* RETURNS: * RETURNS:
@ -273,7 +274,7 @@ unsigned long CDFParser::Parse()
*/ */
{ {
bool Command; bool Command;
unsigned long Status; uint32_t Status;
if (!FileLoaded) if (!FileLoaded)
return CAB_STATUS_NOFILE; return CAB_STATUS_NOFILE;
@ -436,7 +437,7 @@ void CDFParser::SetFileRelativePath(char* Path)
} }
bool CDFParser::OnDiskLabel(unsigned long Number, char* Label) bool CDFParser::OnDiskLabel(uint32_t Number, char* Label)
/* /*
* FUNCTION: Called when a disk needs a label * FUNCTION: Called when a disk needs a label
* ARGUMENTS: * ARGUMENTS:
@ -469,7 +470,7 @@ bool CDFParser::OnDiskLabel(unsigned long Number, char* Label)
{ {
sprintf(Buffer, "%lu", Number); sprintf(Buffer, "%lu", Number);
strcat(Label, Buffer); strcat(Label, Buffer);
j += strlen(Buffer); j += (int)strlen(Buffer);
} }
else else
{ {
@ -488,7 +489,7 @@ bool CDFParser::OnDiskLabel(unsigned long Number, char* Label)
} }
bool CDFParser::OnCabinetName(unsigned long Number, char* Name) bool CDFParser::OnCabinetName(uint32_t Number, char* Name)
/* /*
* FUNCTION: Called when a cabinet needs a name * FUNCTION: Called when a cabinet needs a name
* ARGUMENTS: * ARGUMENTS:
@ -517,7 +518,7 @@ bool CDFParser::OnCabinetName(unsigned long Number, char* Name)
if (CabinetNameTemplateSet) if (CabinetNameTemplateSet)
{ {
strcpy(Name, GetDestinationPath()); strcpy(Name, GetDestinationPath());
j = strlen(Name); j = (int)strlen(Name);
for (i = 0; i < strlen(CabinetNameTemplate); i++) for (i = 0; i < strlen(CabinetNameTemplate); i++)
{ {
ch = CabinetNameTemplate[i]; ch = CabinetNameTemplate[i];
@ -525,7 +526,7 @@ bool CDFParser::OnCabinetName(unsigned long Number, char* Name)
{ {
sprintf(Buffer, "%lu", Number); sprintf(Buffer, "%lu", Number);
strcat(Name, Buffer); strcat(Name, Buffer);
j += strlen(Buffer); j += (int)strlen(Buffer);
} }
else else
{ {
@ -543,7 +544,7 @@ bool CDFParser::OnCabinetName(unsigned long Number, char* Name)
} }
bool CDFParser::SetDiskName(PCABINET_NAME *List, unsigned long Number, char* String) bool CDFParser::SetDiskName(PCABINET_NAME *List, uint32_t Number, char* String)
/* /*
* FUNCTION: Sets an entry in a list * FUNCTION: Sets an entry in a list
* ARGUMENTS: * ARGUMENTS:
@ -581,7 +582,7 @@ bool CDFParser::SetDiskName(PCABINET_NAME *List, unsigned long Number, char* Str
} }
bool CDFParser::GetDiskName(PCABINET_NAME *List, unsigned long Number, char* String) bool CDFParser::GetDiskName(PCABINET_NAME *List, uint32_t Number, char* String)
/* /*
* FUNCTION: Returns an entry in a list * FUNCTION: Returns an entry in a list
* ARGUMENTS: * ARGUMENTS:
@ -609,7 +610,7 @@ bool CDFParser::GetDiskName(PCABINET_NAME *List, unsigned long Number, char* Str
} }
bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long Value) bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, uint32_t Number, uint32_t Value)
/* /*
* FUNCTION: Sets an entry in a list * FUNCTION: Sets an entry in a list
* ARGUMENTS: * ARGUMENTS:
@ -647,7 +648,7 @@ bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned
} }
bool CDFParser::GetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long* Value) bool CDFParser::GetDiskNumber(PDISK_NUMBER *List, uint32_t Number, uint32_t* Value)
/* /*
* FUNCTION: Returns an entry in a list * FUNCTION: Returns an entry in a list
* ARGUMENTS: * ARGUMENTS:
@ -675,7 +676,7 @@ bool CDFParser::GetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned
} }
bool CDFParser::DoDiskLabel(unsigned long Number, char* Label) bool CDFParser::DoDiskLabel(uint32_t Number, char* Label)
/* /*
* FUNCTION: Sets the label of a disk * FUNCTION: Sets the label of a disk
* ARGUMENTS: * ARGUMENTS:
@ -705,7 +706,7 @@ void CDFParser::DoDiskLabelTemplate(char* Template)
} }
bool CDFParser::DoCabinetName(unsigned long Number, char* Name) bool CDFParser::DoCabinetName(uint32_t Number, char* Name)
/* /*
* FUNCTION: Sets the name of a cabinet * FUNCTION: Sets the name of a cabinet
* ARGUMENTS: * ARGUMENTS:
@ -735,7 +736,7 @@ void CDFParser::DoCabinetNameTemplate(char* Template)
} }
unsigned long CDFParser::DoMaxDiskSize(bool NumberValid, unsigned long Number) uint32_t CDFParser::DoMaxDiskSize(bool NumberValid, uint32_t Number)
/* /*
* FUNCTION: Sets the maximum disk size * FUNCTION: Sets the maximum disk size
* ARGUMENTS: * ARGUMENTS:
@ -747,7 +748,7 @@ unsigned long CDFParser::DoMaxDiskSize(bool NumberValid, unsigned long Number)
* Standard sizes are 2.88M, 1.44M, 1.25M, 1.2M, 720K, 360K, and CDROM * Standard sizes are 2.88M, 1.44M, 1.25M, 1.2M, 720K, 360K, and CDROM
*/ */
{ {
unsigned long A, B, Value; uint32_t A, B, Value;
if (IsNextToken(TokenInteger, true)) if (IsNextToken(TokenInteger, true))
{ {
@ -852,14 +853,14 @@ void CDFParser::DoInfFileName(char* FileName)
InfFileNameSet = true; InfFileNameSet = true;
} }
unsigned long CDFParser::SetupNewDisk() uint32_t CDFParser::SetupNewDisk()
/* /*
* FUNCTION: Sets up parameters for a new disk * FUNCTION: Sets up parameters for a new disk
* RETURNS: * RETURNS:
* Status of operation * Status of operation
*/ */
{ {
unsigned long Value; uint32_t Value;
if (!GetDiskNumber(&MaxDiskSize, GetCurrentDiskNumber(), &Value)) if (!GetDiskNumber(&MaxDiskSize, GetCurrentDiskNumber(), &Value))
{ {
@ -874,7 +875,7 @@ unsigned long CDFParser::SetupNewDisk()
} }
unsigned long CDFParser::PerformSetCommand() uint32_t CDFParser::PerformSetCommand()
/* /*
* FUNCTION: Performs a set variable command * FUNCTION: Performs a set variable command
* RETURNS: * RETURNS:
@ -883,7 +884,7 @@ unsigned long CDFParser::PerformSetCommand()
{ {
SETTYPE SetType; SETTYPE SetType;
bool NumberValid = false; bool NumberValid = false;
unsigned long Number = 0; uint32_t Number = 0;
if (!IsNextToken(TokenIdentifier, true)) if (!IsNextToken(TokenIdentifier, true))
return CAB_STATUS_FAILURE; return CAB_STATUS_FAILURE;
@ -970,7 +971,7 @@ unsigned long CDFParser::PerformSetCommand()
} }
unsigned long CDFParser::PerformNewCommand() uint32_t CDFParser::PerformNewCommand()
/* /*
* FUNCTION: Performs a new disk|cabinet|folder command * FUNCTION: Performs a new disk|cabinet|folder command
* RETURNS: * RETURNS:
@ -978,7 +979,7 @@ unsigned long CDFParser::PerformNewCommand()
*/ */
{ {
NEWTYPE NewType; NEWTYPE NewType;
unsigned long Status; uint32_t Status;
if (!IsNextToken(TokenIdentifier, true)) if (!IsNextToken(TokenIdentifier, true))
return CAB_STATUS_FAILURE; return CAB_STATUS_FAILURE;
@ -1053,7 +1054,7 @@ unsigned long CDFParser::PerformNewCommand()
} }
unsigned long CDFParser::PerformInfBeginCommand() uint32_t CDFParser::PerformInfBeginCommand()
/* /*
* FUNCTION: Begins inf mode * FUNCTION: Begins inf mode
* RETURNS: * RETURNS:
@ -1065,7 +1066,7 @@ unsigned long CDFParser::PerformInfBeginCommand()
} }
unsigned long CDFParser::PerformInfEndCommand() uint32_t CDFParser::PerformInfEndCommand()
/* /*
* FUNCTION: Begins inf mode * FUNCTION: Begins inf mode
* RETURNS: * RETURNS:
@ -1077,7 +1078,7 @@ unsigned long CDFParser::PerformInfEndCommand()
} }
unsigned long CDFParser::PerformCommand() uint32_t CDFParser::PerformCommand()
/* /*
* FUNCTION: Performs a command * FUNCTION: Performs a command
* RETURNS: * RETURNS:
@ -1097,15 +1098,15 @@ unsigned long CDFParser::PerformCommand()
} }
unsigned long CDFParser::PerformFileCopy() uint32_t CDFParser::PerformFileCopy()
/* /*
* FUNCTION: Performs a file copy * FUNCTION: Performs a file copy
* RETURNS: * RETURNS:
* Status of operation * Status of operation
*/ */
{ {
unsigned long Status; uint32_t Status;
unsigned long i, j; uint32_t i, j;
char ch; char ch;
char SrcName[MAX_PATH]; char SrcName[MAX_PATH];
char DstName[MAX_PATH]; char DstName[MAX_PATH];
@ -1137,7 +1138,7 @@ unsigned long CDFParser::PerformFileCopy()
if (CurrentToken != TokenEnd) if (CurrentToken != TokenEnd)
{ {
j = strlen(CurrentString); i = 0; j = (uint32_t)strlen(CurrentString); i = 0;
while ((CurrentChar + i < LineLength) && while ((CurrentChar + i < LineLength) &&
((ch = Line[CurrentChar + i]) != ' ') && ((ch = Line[CurrentChar + i]) != ' ') &&
(ch != 0x09) && (ch != 0x09) &&
@ -1157,7 +1158,7 @@ unsigned long CDFParser::PerformFileCopy()
if (CurrentToken != TokenEnd) if (CurrentToken != TokenEnd)
{ {
j = strlen(CurrentString); i = 0; j = (uint32_t)strlen(CurrentString); i = 0;
while ((CurrentChar + i < LineLength) && while ((CurrentChar + i < LineLength) &&
((ch = Line[CurrentChar + i]) != ' ') && ((ch = Line[CurrentChar + i]) != ' ') &&
(ch != 0x09) && (ch != 0x09) &&
@ -1273,7 +1274,7 @@ bool CDFParser::ReadLine()
* true if there is a new line, false if not * true if there is a new line, false if not
*/ */
{ {
unsigned long i, j; uint32_t i, j;
char ch; char ch;
if (CurrentOffset >= FileBufferSize) if (CurrentOffset >= FileBufferSize)
@ -1310,7 +1311,7 @@ void CDFParser::NextToken()
* FUNCTION: Reads the next token from the current line * FUNCTION: Reads the next token from the current line
*/ */
{ {
unsigned long i; uint32_t i;
char ch = ' '; char ch = ' ';
if (CurrentChar >= LineLength) if (CurrentChar >= LineLength)

View file

@ -11,14 +11,14 @@
typedef struct _CABINET_NAME { typedef struct _CABINET_NAME {
struct _CABINET_NAME *Next; struct _CABINET_NAME *Next;
unsigned long DiskNumber; uint32_t DiskNumber;
char Name[128]; char Name[128];
} CABINET_NAME, *PCABINET_NAME; } CABINET_NAME, *PCABINET_NAME;
typedef struct _DISK_NUMBER { typedef struct _DISK_NUMBER {
struct _DISK_NUMBER *Next; struct _DISK_NUMBER *Next;
unsigned long DiskNumber; uint32_t DiskNumber;
unsigned long Number; uint32_t Number;
} DISK_NUMBER, *PDISK_NUMBER; } DISK_NUMBER, *PDISK_NUMBER;
typedef enum { typedef enum {
@ -58,35 +58,35 @@ class CDFParser : public CCabinet {
public: public:
CDFParser(); CDFParser();
virtual ~CDFParser(); virtual ~CDFParser();
unsigned long Load(char* FileName); uint32_t Load(char* FileName);
unsigned long Parse(); uint32_t Parse();
void SetFileRelativePath(char* Path); void SetFileRelativePath(char* Path);
bool InfFileOnly; bool InfFileOnly;
bool DontGenerateInf; bool DontGenerateInf;
char FileRelativePath[300]; char FileRelativePath[300];
private: private:
/* Event handlers */ /* Event handlers */
virtual bool OnDiskLabel(unsigned long Number, char* Label); virtual bool OnDiskLabel(uint32_t Number, char* Label);
virtual bool OnCabinetName(unsigned long Number, char* Name); virtual bool OnCabinetName(uint32_t Number, char* Name);
void WriteInfLine(char* InfLine); void WriteInfLine(char* InfLine);
bool SetDiskName(PCABINET_NAME *List, unsigned long Number, char* String); bool SetDiskName(PCABINET_NAME *List, uint32_t Number, char* String);
bool GetDiskName(PCABINET_NAME *List, unsigned long Number, char* String); bool GetDiskName(PCABINET_NAME *List, uint32_t Number, char* String);
bool SetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long Value); bool SetDiskNumber(PDISK_NUMBER *List, uint32_t Number, uint32_t Value);
bool GetDiskNumber(PDISK_NUMBER *List, unsigned long Number, unsigned long* Value); bool GetDiskNumber(PDISK_NUMBER *List, uint32_t Number, uint32_t* Value);
bool DoDiskLabel(unsigned long Number, char* Label); bool DoDiskLabel(uint32_t Number, char* Label);
void DoDiskLabelTemplate(char* Template); void DoDiskLabelTemplate(char* Template);
bool DoCabinetName(unsigned long Number, char* Name); bool DoCabinetName(uint32_t Number, char* Name);
void DoCabinetNameTemplate(char* Template); void DoCabinetNameTemplate(char* Template);
void DoInfFileName(char* InfFileName); void DoInfFileName(char* InfFileName);
unsigned long DoMaxDiskSize(bool NumberValid, unsigned long Number); uint32_t DoMaxDiskSize(bool NumberValid, uint32_t Number);
unsigned long SetupNewDisk(); uint32_t SetupNewDisk();
unsigned long PerformSetCommand(); uint32_t PerformSetCommand();
unsigned long PerformNewCommand(); uint32_t PerformNewCommand();
unsigned long PerformInfBeginCommand(); uint32_t PerformInfBeginCommand();
unsigned long PerformInfEndCommand(); uint32_t PerformInfEndCommand();
unsigned long PerformCommand(); uint32_t PerformCommand();
unsigned long PerformFileCopy(); uint32_t PerformFileCopy();
void SkipSpaces(); void SkipSpaces();
bool IsNextToken(DFP_TOKEN Token, bool NoSpaces); bool IsNextToken(DFP_TOKEN Token, bool NoSpaces);
bool ReadLine(); bool ReadLine();
@ -95,15 +95,15 @@ private:
bool FileLoaded; bool FileLoaded;
FILEHANDLE FileHandle; FILEHANDLE FileHandle;
char* FileBuffer; char* FileBuffer;
unsigned long FileBufferSize; uint32_t FileBufferSize;
unsigned long CurrentOffset; uint32_t CurrentOffset;
char Line[128]; char Line[128];
unsigned long LineLength; uint32_t LineLength;
unsigned long CurrentLine; uint32_t CurrentLine;
unsigned long CurrentChar; uint32_t CurrentChar;
/* Token */ /* Token */
DFP_TOKEN CurrentToken; DFP_TOKEN CurrentToken;
unsigned long CurrentInteger; uint32_t CurrentInteger;
char CurrentString[256]; char CurrentString[256];
/* State */ /* State */
@ -112,27 +112,27 @@ private:
bool FolderCreated; bool FolderCreated;
/* Standard directive variable */ /* Standard directive variable */
bool Cabinet; bool Cabinet;
unsigned long CabinetFileCountThreshold; uint32_t CabinetFileCountThreshold;
PCABINET_NAME CabinetName; PCABINET_NAME CabinetName;
bool CabinetNameTemplateSet; bool CabinetNameTemplateSet;
char CabinetNameTemplate[128]; char CabinetNameTemplate[128];
bool InfFileNameSet; bool InfFileNameSet;
char InfFileName[256]; char InfFileName[256];
bool Compress; bool Compress;
unsigned long CompressionType; uint32_t CompressionType;
PCABINET_NAME DiskLabel; PCABINET_NAME DiskLabel;
bool DiskLabelTemplateSet; bool DiskLabelTemplateSet;
char DiskLabelTemplate[128]; char DiskLabelTemplate[128];
unsigned long FolderFileCountThreshold; uint32_t FolderFileCountThreshold;
unsigned long FolderSizeThreshold; uint32_t FolderSizeThreshold;
unsigned long MaxCabinetSize; uint32_t MaxCabinetSize;
unsigned long MaxDiskFileCount; uint32_t MaxDiskFileCount;
PDISK_NUMBER MaxDiskSize; PDISK_NUMBER MaxDiskSize;
bool MaxDiskSizeAllSet; bool MaxDiskSizeAllSet;
unsigned long MaxDiskSizeAll; uint32_t MaxDiskSizeAll;
unsigned long ReservePerCabinetSize; uint32_t ReservePerCabinetSize;
unsigned long ReservePerDataBlockSize; uint32_t ReservePerDataBlockSize;
unsigned long ReservePerFolderSize; uint32_t ReservePerFolderSize;
char SourceDir[256]; char SourceDir[256];
FILEHANDLE InfFileHandle; FILEHANDLE InfFileHandle;
bool InfModeEnabled; bool InfModeEnabled;

View file

@ -9,6 +9,7 @@
* CSH 21/03-2001 Created * CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable * 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 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
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
@ -19,9 +20,9 @@
#ifdef DBG #ifdef DBG
unsigned long DebugTraceLevel = MIN_TRACE; uint32_t DebugTraceLevel = MIN_TRACE;
//unsigned long DebugTraceLevel = MID_TRACE; //uint32_t DebugTraceLevel = MID_TRACE;
//unsigned long DebugTraceLevel = MAX_TRACE; //uint32_t DebugTraceLevel = MAX_TRACE;
#endif /* DBG */ #endif /* DBG */
@ -44,7 +45,7 @@ char* Pad(char* Str, char PadChar, unsigned int Length)
{ {
unsigned int Len; unsigned int Len;
Len = strlen(Str); Len = (uint32_t)strlen(Str);
if (Len < Length) if (Len < Length)
{ {
@ -55,7 +56,7 @@ char* Pad(char* Str, char PadChar, unsigned int Length)
} }
char* Date2Str(char* Str, unsigned short Date) char* Date2Str(char* Str, uint16_t Date)
/* /*
* FUNCTION: Converts a DOS style date to a string * FUNCTION: Converts a DOS style date to a string
* ARGUMENTS: * ARGUMENTS:
@ -65,7 +66,7 @@ char* Date2Str(char* Str, unsigned short Date)
* Pointer to string * Pointer to string
*/ */
{ {
unsigned long dw; uint32_t dw;
/* Month */ /* Month */
Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10); Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10);
@ -86,7 +87,7 @@ char* Date2Str(char* Str, unsigned short Date)
} }
char* Time2Str(char* Str, unsigned short Time) char* Time2Str(char* Str, uint16_t Time)
/* /*
* FUNCTION: Converts a DOS style time to a string * FUNCTION: Converts a DOS style time to a string
* ARGUMENTS: * ARGUMENTS:
@ -97,8 +98,8 @@ char* Time2Str(char* Str, unsigned short Time)
*/ */
{ {
bool PM; bool PM;
unsigned long Hour; uint32_t Hour;
unsigned long dw; uint32_t dw;
Hour = ((Time & 0xF800) >> 11); Hour = ((Time & 0xF800) >> 11);
PM = (Hour >= 12); PM = (Hour >= 12);
@ -126,7 +127,7 @@ char* Time2Str(char* Str, unsigned short Time)
} }
char* Attr2Str(char* Str, unsigned short Attr) char* Attr2Str(char* Str, uint16_t Attr)
/* /*
* FUNCTION: Converts attributes to a string * FUNCTION: Converts attributes to a string
* ARGUMENTS: * ARGUMENTS:
@ -364,7 +365,7 @@ bool CCABManager::CreateCabinet()
* FUNCTION: Create cabinet * FUNCTION: Create cabinet
*/ */
{ {
unsigned long Status; uint32_t Status;
Status = Load((char*)&FileName); Status = Load((char*)&FileName);
if (Status != CAB_STATUS_SUCCESS) if (Status != CAB_STATUS_SUCCESS)
@ -384,7 +385,7 @@ bool CCABManager::CreateSimpleCabinet()
* FUNCTION: Create cabinet * FUNCTION: Create cabinet
*/ */
{ {
unsigned long Status; uint32_t Status;
Status = NewCabinet(); Status = NewCabinet();
if (Status != CAB_STATUS_SUCCESS) if (Status != CAB_STATUS_SUCCESS)
@ -422,8 +423,8 @@ bool CCABManager::DisplayCabinet()
{ {
CAB_SEARCH Search; CAB_SEARCH Search;
char Str[20]; char Str[20];
unsigned long FileCount = 0; uint32_t FileCount = 0;
unsigned long ByteCount = 0; uint32_t ByteCount = 0;
if (Open() == CAB_STATUS_SUCCESS) if (Open() == CAB_STATUS_SUCCESS)
{ {
@ -485,7 +486,7 @@ bool CCABManager::ExtractFromCabinet()
*/ */
{ {
CAB_SEARCH Search; CAB_SEARCH Search;
unsigned long Status; uint32_t Status;
if (Open() == CAB_STATUS_SUCCESS) if (Open() == CAB_STATUS_SUCCESS)
{ {

View file

@ -11,6 +11,7 @@
* CSH 21/03-2001 Created * CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable * 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 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
*/ */
#include <stdio.h> #include <stdio.h>
#include "mszip.h" #include "mszip.h"
@ -52,10 +53,10 @@ CMSZipCodec::~CMSZipCodec()
} }
unsigned long CMSZipCodec::Compress(void* OutputBuffer, uint32_t CMSZipCodec::Compress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) uint32_t* OutputLength)
/* /*
* FUNCTION: Compresses data in a buffer * FUNCTION: Compresses data in a buffer
* ARGUMENTS: * ARGUMENTS:
@ -65,16 +66,16 @@ unsigned long CMSZipCodec::Compress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of compressed data * OutputLength = Address of buffer to place size of compressed data
*/ */
{ {
unsigned short* Magic; uint16_t* Magic;
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
Magic = (unsigned short*)OutputBuffer; Magic = (uint16_t*)OutputBuffer;
*Magic = MSZIP_MAGIC; *Magic = MSZIP_MAGIC;
ZStream.next_in = (unsigned char*)InputBuffer; ZStream.next_in = (unsigned char*)InputBuffer;
ZStream.avail_in = InputLength; ZStream.avail_in = InputLength;
ZStream.next_out = (unsigned char*)((unsigned long)OutputBuffer + 2); ZStream.next_out = (unsigned char*)((uintptr_t)OutputBuffer + 2);
ZStream.avail_out = CAB_BLOCKSIZE + 12; ZStream.avail_out = CAB_BLOCKSIZE + 12;
/* WindowBits is passed < 0 to tell that there is no zlib header */ /* WindowBits is passed < 0 to tell that there is no zlib header */
@ -112,10 +113,10 @@ unsigned long CMSZipCodec::Compress(void* OutputBuffer,
} }
unsigned long CMSZipCodec::Uncompress(void* OutputBuffer, uint32_t CMSZipCodec::Uncompress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) uint32_t* OutputLength)
/* /*
* FUNCTION: Uncompresses data in a buffer * FUNCTION: Uncompresses data in a buffer
* ARGUMENTS: * ARGUMENTS:
@ -125,11 +126,11 @@ unsigned long CMSZipCodec::Uncompress(void* OutputBuffer,
* OutputLength = Address of buffer to place size of uncompressed data * OutputLength = Address of buffer to place size of uncompressed data
*/ */
{ {
unsigned short Magic; uint16_t Magic;
DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength));
Magic = *((unsigned short*)InputBuffer); Magic = *((uint16_t*)InputBuffer);
if (Magic != MSZIP_MAGIC) if (Magic != MSZIP_MAGIC)
{ {
@ -137,7 +138,7 @@ unsigned long CMSZipCodec::Uncompress(void* OutputBuffer,
return CS_BADSTREAM; return CS_BADSTREAM;
} }
ZStream.next_in = (unsigned char*)((unsigned long)InputBuffer + 2); ZStream.next_in = (unsigned char*)((uintptr_t)InputBuffer + 2);
ZStream.avail_in = InputLength - 2; ZStream.avail_in = InputLength - 2;
ZStream.next_out = (unsigned char*)OutputBuffer; ZStream.next_out = (unsigned char*)OutputBuffer;
ZStream.avail_out = CAB_BLOCKSIZE + 12; ZStream.avail_out = CAB_BLOCKSIZE + 12;

View file

@ -22,15 +22,15 @@ public:
/* Default destructor */ /* Default destructor */
virtual ~CMSZipCodec(); virtual ~CMSZipCodec();
/* Compresses a data block */ /* Compresses a data block */
virtual unsigned long Compress(void* OutputBuffer, virtual uint32_t Compress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength); uint32_t* OutputLength);
/* Uncompresses a data block */ /* Uncompresses a data block */
virtual unsigned long Uncompress(void* OutputBuffer, virtual uint32_t Uncompress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength); uint32_t* OutputLength);
private: private:
int Status; int Status;
z_stream ZStream; /* Zlib stream */ z_stream ZStream; /* Zlib stream */

View file

@ -9,6 +9,7 @@
* CSH 21/03-2001 Created * CSH 21/03-2001 Created
* CSH 15/08-2003 Made it portable * 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 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
*/ */
#include "raw.h" #include "raw.h"
@ -31,10 +32,10 @@ CRawCodec::~CRawCodec()
} }
unsigned long CRawCodec::Compress(void* OutputBuffer, uint32_t CRawCodec::Compress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) uint32_t* OutputLength)
/* /*
* FUNCTION: Compresses data in a buffer * FUNCTION: Compresses data in a buffer
* ARGUMENTS: * ARGUMENTS:
@ -49,10 +50,10 @@ unsigned long CRawCodec::Compress(void* OutputBuffer,
return CS_SUCCESS; return CS_SUCCESS;
} }
unsigned long CRawCodec::Uncompress(void* OutputBuffer, uint32_t CRawCodec::Uncompress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength) uint32_t* OutputLength)
/* /*
* FUNCTION: Uncompresses data in a buffer * FUNCTION: Uncompresses data in a buffer
* ARGUMENTS: * ARGUMENTS:

View file

@ -19,15 +19,15 @@ public:
/* Default destructor */ /* Default destructor */
virtual ~CRawCodec(); virtual ~CRawCodec();
/* Compresses a data block */ /* Compresses a data block */
virtual unsigned long Compress(void* OutputBuffer, virtual uint32_t Compress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength); uint32_t* OutputLength);
/* Uncompresses a data block */ /* Uncompresses a data block */
virtual unsigned long Uncompress(void* OutputBuffer, virtual uint32_t Uncompress(void* OutputBuffer,
void* InputBuffer, void* InputBuffer,
unsigned long InputLength, uint32_t InputLength,
unsigned long* OutputLength); uint32_t* OutputLength);
}; };
#endif /* __RAW_H */ #endif /* __RAW_H */