diff --git a/reactos/tools/cabman/cabinet.cxx b/reactos/tools/cabman/cabinet.cxx index 8dd92484371..c4add557be1 100755 --- a/reactos/tools/cabman/cabinet.cxx +++ b/reactos/tools/cabman/cabinet.cxx @@ -9,9 +9,7 @@ * REVISIONS: * CSH 21/03-2001 Created * CSH 15/08-2003 Made it portable - * CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces * CF 04/05-2007 Made it compatible with 64-bit operating systems - * CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems * TODO: * - Checksum of datablocks should be calculated * - EXTRACT.EXE complains if a disk is created manually @@ -31,32 +29,32 @@ #define GetSizeOfFile(handle) _GetSizeOfFile(handle) static LONG _GetSizeOfFile(FILEHANDLE handle) { - ULONG size = GetFileSize(handle, NULL); - if (size == INVALID_FILE_SIZE) - return -1; + ULONG size = GetFileSize(handle, NULL); + if (size == INVALID_FILE_SIZE) + return -1; - return size; + return size; } #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread) { - return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL) != 0; + return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL) != 0; } #else #define GetSizeOfFile(handle) _GetSizeOfFile(handle) static LONG _GetSizeOfFile(FILEHANDLE handle) { - LONG size; - fseek(handle, 0, SEEK_END); - size = ftell(handle); - fseek(handle, 0, SEEK_SET); - return size; + LONG size; + fseek(handle, 0, SEEK_END); + size = ftell(handle); + fseek(handle, 0, SEEK_SET); + return size; } #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread) { - *bytesread = fread(buffer, 1, size, handle); - return *bytesread == size; + *bytesread = fread(buffer, 1, size, handle); + return *bytesread == size; } #endif @@ -67,29 +65,29 @@ static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG by void DumpBuffer(void* Buffer, ULONG Size) { - FILEHANDLE FileHandle; - ULONG BytesWritten; + FILEHANDLE FileHandle; + ULONG BytesWritten; - /* Create file, overwrite if it already exists */ - FileHandle = CreateFile("dump.bin", // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - CREATE_ALWAYS, // Create or overwrite - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("ERROR OPENING '%lu'.\n", (ULONG)GetLastError())); - return; - } + /* Create file, overwrite if it already exists */ + FileHandle = CreateFile("dump.bin", // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + CREATE_ALWAYS, // Create or overwrite + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("ERROR OPENING '%lu'.\n", (ULONG)GetLastError())); + return; + } - if (!WriteFile(FileHandle, Buffer, Size, &BytesWritten, NULL)) - { - DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); - } + if (!WriteFile(FileHandle, Buffer, Size, &BytesWritten, NULL)) + { + DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); + } - CloseFile(FileHandle); + CloseFile(FileHandle); } #endif /* DBG */ @@ -102,7 +100,7 @@ CCFDATAStorage::CCFDATAStorage() * FUNCTION: Default constructor */ { - FileCreated = false; + FileCreated = false; } @@ -111,7 +109,7 @@ CCFDATAStorage::~CCFDATAStorage() * FUNCTION: Default destructor */ { - ASSERT(!FileCreated); + ASSERT(!FileCreated); } @@ -124,45 +122,45 @@ ULONG CCFDATAStorage::Create(char* FileName) * Status of operation */ { - ASSERT(!FileCreated); + ASSERT(!FileCreated); #if defined(WIN32) - if (GetTempPath(MAX_PATH, FullName) == 0) - return CAB_STATUS_CANNOT_CREATE; + if (GetTempPath(MAX_PATH, FullName) == 0) + return CAB_STATUS_CANNOT_CREATE; - strcat(FullName, FileName); + strcat(FullName, FileName); - /* Create file, overwrite if it already exists */ - FileHandle = CreateFile(FullName, // Create this file - GENERIC_READ | GENERIC_WRITE, // Open for reading/writing - 0, // No sharing - NULL, // No security - CREATE_ALWAYS, // Create or overwrite - FILE_FLAG_SEQUENTIAL_SCAN | // Optimize for sequential scans - FILE_FLAG_DELETE_ON_CLOSE | // Delete file when closed - FILE_ATTRIBUTE_TEMPORARY, // Temporary file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)GetLastError())); - return CAB_STATUS_CANNOT_CREATE; - } + /* Create file, overwrite if it already exists */ + FileHandle = CreateFile(FullName, // Create this file + GENERIC_READ | GENERIC_WRITE, // Open for reading/writing + 0, // No sharing + NULL, // No security + CREATE_ALWAYS, // Create or overwrite + FILE_FLAG_SEQUENTIAL_SCAN | // Optimize for sequential scans + FILE_FLAG_DELETE_ON_CLOSE | // Delete file when closed + FILE_ATTRIBUTE_TEMPORARY, // Temporary file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)GetLastError())); + return CAB_STATUS_CANNOT_CREATE; + } #else /* !WIN32 */ - /*if (tmpnam(FullName) == NULL)*/ - if ((FileHandle = tmpfile()) == NULL) - return CAB_STATUS_CANNOT_CREATE; - /* - FileHandle = fopen(FullName, "w+b"); - if (FileHandle == NULL) { - DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)errno)); - return CAB_STATUS_CANNOT_CREATE; - } - */ + /*if (tmpnam(FullName) == NULL)*/ + if ((FileHandle = tmpfile()) == NULL) + return CAB_STATUS_CANNOT_CREATE; + /* + FileHandle = fopen(FullName, "w+b"); + if (FileHandle == NULL) { + DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)errno)); + return CAB_STATUS_CANNOT_CREATE; + } + */ #endif - FileCreated = true; + FileCreated = true; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -173,13 +171,13 @@ ULONG CCFDATAStorage::Destroy() * Status of operation */ { - ASSERT(FileCreated); + ASSERT(FileCreated); - CloseFile(FileHandle); + CloseFile(FileHandle); - FileCreated = false; + FileCreated = false; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -191,20 +189,20 @@ ULONG CCFDATAStorage::Truncate() */ { #if defined(WIN32) - if (!SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN)) - return CAB_STATUS_FAILURE; - if (!SetEndOfFile(FileHandle)) - return CAB_STATUS_FAILURE; + if (!SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN)) + return CAB_STATUS_FAILURE; + if (!SetEndOfFile(FileHandle)) + return CAB_STATUS_FAILURE; #else /* !WIN32 */ - fclose(FileHandle); - FileHandle = tmpfile(); - if (FileHandle == NULL) - { - DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)errno)); - return CAB_STATUS_FAILURE; - } + fclose(FileHandle); + FileHandle = tmpfile(); + if (FileHandle == NULL) + { + DPRINT(MID_TRACE, ("ERROR '%lu'.\n", (ULONG)errno)); + return CAB_STATUS_FAILURE; + } #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -216,9 +214,9 @@ ULONG CCFDATAStorage::Position() */ { #if defined(WIN32) - return SetFilePointer(FileHandle, 0, NULL, FILE_CURRENT); + return SetFilePointer(FileHandle, 0, NULL, FILE_CURRENT); #else - return (ULONG)ftell(FileHandle); + return (ULONG)ftell(FileHandle); #endif } @@ -233,18 +231,18 @@ ULONG CCFDATAStorage::Seek(LONG Position) */ { #if defined(WIN32) - if (SetFilePointer(FileHandle, - Position, - NULL, - FILE_BEGIN) == 0xFFFFFFFF) - return CAB_STATUS_FAILURE; - else - return CAB_STATUS_SUCCESS; + if (SetFilePointer(FileHandle, + Position, + NULL, + FILE_BEGIN) == 0xFFFFFFFF) + return CAB_STATUS_FAILURE; + else + return CAB_STATUS_SUCCESS; #else - if (fseek(FileHandle, (off_t)Position, SEEK_SET) != 0) - return CAB_STATUS_FAILURE; - else - return CAB_STATUS_SUCCESS; + if (fseek(FileHandle, (off_t)Position, SEEK_SET) != 0) + return CAB_STATUS_FAILURE; + else + return CAB_STATUS_SUCCESS; #endif } @@ -261,15 +259,15 @@ ULONG CCFDATAStorage::ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead) */ { #if defined(WIN32) - if (!ReadFile(FileHandle, Buffer, Data->CompSize, (LPDWORD)BytesRead, NULL)) - return CAB_STATUS_CANNOT_READ; + if (!ReadFile(FileHandle, Buffer, Data->CompSize, (LPDWORD)BytesRead, NULL)) + return CAB_STATUS_CANNOT_READ; #else - *BytesRead = fread(Buffer, 1, Data->CompSize, FileHandle); - if (*BytesRead != Data->CompSize) - return CAB_STATUS_CANNOT_READ; + *BytesRead = fread(Buffer, 1, Data->CompSize, FileHandle); + if (*BytesRead != Data->CompSize) + return CAB_STATUS_CANNOT_READ; #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -285,14 +283,14 @@ ULONG CCFDATAStorage::WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten */ { #if defined(WIN32) - if (!WriteFile(FileHandle, Buffer, Data->CompSize, (LPDWORD)BytesWritten, NULL)) - return CAB_STATUS_CANNOT_WRITE; + if (!WriteFile(FileHandle, Buffer, Data->CompSize, (LPDWORD)BytesWritten, NULL)) + return CAB_STATUS_CANNOT_WRITE; #else - *BytesWritten = fwrite(Buffer, 1, Data->CompSize, FileHandle); - if (*BytesWritten != Data->CompSize) - return CAB_STATUS_CANNOT_WRITE; + *BytesWritten = fwrite(Buffer, 1, Data->CompSize, FileHandle); + if (*BytesWritten != Data->CompSize) + return CAB_STATUS_CANNOT_WRITE; #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } #endif /* CAB_READ_ONLY */ @@ -305,37 +303,37 @@ CCabinet::CCabinet() * FUNCTION: Default constructor */ { - *CabinetName = '\0'; - *CabinetPrev = '\0'; - *DiskPrev = '\0'; - *CabinetNext = '\0'; - *DiskNext = '\0'; - *DestPath = '\0'; - *CabinetReservedFile = '\0'; + *CabinetName = '\0'; + *CabinetPrev = '\0'; + *DiskPrev = '\0'; + *CabinetNext = '\0'; + *DiskNext = '\0'; + *DestPath = '\0'; + *CabinetReservedFile = '\0'; - FileOpen = false; - CabinetReservedFileBuffer = NULL; - CabinetReservedFileSize = 0; + FileOpen = false; + CabinetReservedFileBuffer = NULL; + CabinetReservedFileSize = 0; - FolderListHead = NULL; - FolderListTail = NULL; - FileListHead = NULL; - FileListTail = NULL; + FolderListHead = NULL; + FolderListTail = NULL; + FileListHead = NULL; + FileListTail = NULL; - Codec = new CRawCodec(); - CodecId = CAB_CODEC_RAW; - CodecSelected = true; + Codec = new CRawCodec(); + CodecId = CAB_CODEC_RAW; + CodecSelected = true; - OutputBuffer = NULL; - InputBuffer = NULL; - MaxDiskSize = 0; - BlockIsSplit = false; - ScratchFile = NULL; + OutputBuffer = NULL; + InputBuffer = NULL; + MaxDiskSize = 0; + BlockIsSplit = false; + ScratchFile = NULL; - FolderUncompSize = 0; - BytesLeftInBlock = 0; - ReuseBlock = false; - CurrentDataNode = NULL; + FolderUncompSize = 0; + BytesLeftInBlock = 0; + ReuseBlock = false; + CurrentDataNode = NULL; } @@ -344,15 +342,15 @@ CCabinet::~CCabinet() * FUNCTION: Default destructor */ { - if (CabinetReservedFileBuffer != NULL) - { - FreeMemory(CabinetReservedFileBuffer); - CabinetReservedFileBuffer = NULL; - CabinetReservedFileSize = 0; - } + if (CabinetReservedFileBuffer != NULL) + { + FreeMemory(CabinetReservedFileBuffer); + CabinetReservedFileBuffer = NULL; + CabinetReservedFileSize = 0; + } - if (CodecSelected) - delete Codec; + if (CodecSelected) + delete Codec; } bool CCabinet::IsSeparator(char Char) @@ -364,10 +362,10 @@ bool CCabinet::IsSeparator(char Char) * Wether it is a separator */ { - if ((Char == '\\') || (Char == '/')) - return true; - else - return false; + if ((Char == '\\') || (Char == '/')) + return true; + else + return false; } char* CCabinet::ConvertPath(char* Path, bool Allocate) @@ -381,33 +379,33 @@ char* CCabinet::ConvertPath(char* Path, bool Allocate) * Pointer to new path */ { - char *newpath; - int i; + char *newpath; + int i; - if (Allocate) - newpath = strdup(Path); - else - newpath = Path; + if (Allocate) + newpath = strdup(Path); + else + newpath = Path; - i = 0; - while (Path[i] != 0) - { + i = 0; + while (Path[i] != 0) + { #if defined(WIN32) - if (Path[i] == '/') - newpath[i] = '\\'; - else + if (Path[i] == '/') + newpath[i] = '\\'; + else #else - if (Path[i] == '\\') - newpath[i] = '/'; - else + if (Path[i] == '\\') + newpath[i] = '/'; + else #endif - newpath[i] = Path[i]; + newpath[i] = Path[i]; - i++; - } - newpath[i] = 0; + i++; + } + newpath[i] = 0; - return(newpath); + return(newpath); } @@ -420,15 +418,15 @@ char* CCabinet::GetFileName(char* Path) * Pointer to filename */ { - ULONG i, j; + ULONG i, j; - j = i = (Path[0] ? (Path[1] == ':' ? 2 : 0) : 0); + j = i = (Path[0] ? (Path[1] == ':' ? 2 : 0) : 0); - while (Path [i++]) - if (IsSeparator(Path [i - 1])) - j = i; + while (Path [i++]) + if (IsSeparator(Path [i - 1])) + j = i; - return Path + j; + return Path + j; } @@ -439,17 +437,17 @@ void CCabinet::RemoveFileName(char* Path) * Path = Pointer to string with path */ { - char* FileName; - ULONG i; + char* FileName; + ULONG i; - i = (Path [0] ? (Path[1] == ':' ? 2 : 0) : 0); - FileName = GetFileName(Path + i); + i = (Path [0] ? (Path[1] == ':' ? 2 : 0) : 0); + FileName = GetFileName(Path + i); - if ((FileName != (Path + i)) && (IsSeparator(FileName [-1]))) - FileName--; - if ((FileName == (Path + i)) && (IsSeparator(FileName [0]))) - FileName++; - FileName[0] = 0; + if ((FileName != (Path + i)) && (IsSeparator(FileName [-1]))) + FileName--; + if ((FileName == (Path + i)) && (IsSeparator(FileName [0]))) + FileName++; + FileName[0] = 0; } @@ -464,17 +462,17 @@ bool CCabinet::NormalizePath(char* Path, * true if there was enough room in Path, or false */ { - ULONG n; - bool OK = true; + ULONG n; + bool OK = true; - if ((n = (ULONG)strlen(Path)) && - (!IsSeparator(Path[n - 1])) && - (OK = ((n + 1) < Length))) - { - Path[n] = DIR_SEPARATOR_CHAR; - Path[n + 1] = 0; - } - return OK; + if ((n = (ULONG)strlen(Path)) && + (!IsSeparator(Path[n - 1])) && + (OK = ((n + 1) < Length))) + { + Path[n] = DIR_SEPARATOR_CHAR; + Path[n + 1] = 0; + } + return OK; } @@ -485,7 +483,7 @@ char* CCabinet::GetCabinetName() * Pointer to string with name of cabinet */ { - return CabinetName; + return CabinetName; } @@ -496,7 +494,7 @@ void CCabinet::SetCabinetName(char* FileName) * FileName = Pointer to string with name of cabinet */ { - strcpy(CabinetName, FileName); + strcpy(CabinetName, FileName); } @@ -507,10 +505,10 @@ void CCabinet::SetDestinationPath(char* DestinationPath) * DestinationPath = Pointer to string with name of destination path */ { - strcpy(DestPath, DestinationPath); - ConvertPath(DestPath, false); - if (strlen(DestPath) > 0) - NormalizePath(DestPath, MAX_PATH); + strcpy(DestPath, DestinationPath); + ConvertPath(DestPath, false); + if (strlen(DestPath) > 0) + NormalizePath(DestPath, MAX_PATH); } @@ -521,7 +519,7 @@ char* CCabinet::GetDestinationPath() * Pointer to string with name of destination path */ { - return DestPath; + return DestPath; } @@ -532,62 +530,62 @@ bool CCabinet::SetCabinetReservedFile(char* FileName) * FileName = Pointer to string with name of cabinet reserved file */ { - FILEHANDLE FileHandle; - ULONG BytesRead; + FILEHANDLE FileHandle; + ULONG BytesRead; #if defined(WIN32) - FileHandle = CreateFile(ConvertPath(FileName, true), // Open this file - GENERIC_READ, // Open for reading - FILE_SHARE_READ, // Share for reading - NULL, // No security - OPEN_EXISTING, // Existing file only - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); - return false; - } + FileHandle = CreateFile(ConvertPath(FileName, true), // Open this file + GENERIC_READ, // Open for reading + FILE_SHARE_READ, // Share for reading + NULL, // No security + OPEN_EXISTING, // Existing file only + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); + return false; + } #else /* !WIN32 */ - FileHandle = fopen(ConvertPath(FileName, true), "rb"); - if (FileHandle == NULL) - { - DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); - return false; - } + FileHandle = fopen(ConvertPath(FileName, true), "rb"); + if (FileHandle == NULL) + { + DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); + return false; + } #endif - CabinetReservedFileSize = GetSizeOfFile(FileHandle); - if (CabinetReservedFileSize == (ULONG)-1) - { - DPRINT(MIN_TRACE, ("Cannot read from cabinet reserved file.\n")); - return false; - } + CabinetReservedFileSize = GetSizeOfFile(FileHandle); + if (CabinetReservedFileSize == (ULONG)-1) + { + DPRINT(MIN_TRACE, ("Cannot read from cabinet reserved file.\n")); + return false; + } - if (CabinetReservedFileSize == 0) - { - CloseFile(FileHandle); - return false; - } + if (CabinetReservedFileSize == 0) + { + CloseFile(FileHandle); + return false; + } - CabinetReservedFileBuffer = AllocateMemory(CabinetReservedFileSize); - if (!CabinetReservedFileBuffer) - { - CloseFile(FileHandle); - return false; - } + CabinetReservedFileBuffer = AllocateMemory(CabinetReservedFileSize); + if (!CabinetReservedFileBuffer) + { + CloseFile(FileHandle); + return false; + } - if (!ReadFileData(FileHandle, CabinetReservedFileBuffer, CabinetReservedFileSize, &BytesRead)) - { - CloseFile(FileHandle); - return false; - } + if (!ReadFileData(FileHandle, CabinetReservedFileBuffer, CabinetReservedFileSize, &BytesRead)) + { + CloseFile(FileHandle); + return false; + } - CloseFile(FileHandle); + CloseFile(FileHandle); - strcpy(CabinetReservedFile, FileName); + strcpy(CabinetReservedFile, FileName); - return true; + return true; } @@ -598,7 +596,7 @@ char* CCabinet::GetCabinetReservedFile() * Pointer to string with name of cabinet reserved file */ { - return CabinetReservedFile; + return CabinetReservedFile; } @@ -609,7 +607,7 @@ ULONG CCabinet::GetCurrentDiskNumber() * Current disk number */ { - return CurrentDiskNumber; + return CurrentDiskNumber; } @@ -620,175 +618,175 @@ ULONG CCabinet::Open() * Status of operation */ { - PCFFOLDER_NODE FolderNode; - ULONG Status; - ULONG Index; + PCFFOLDER_NODE FolderNode; + ULONG Status; + ULONG Index; - if (!FileOpen) - { - ULONG BytesRead; - ULONG Size; + if (!FileOpen) + { + ULONG BytesRead; + ULONG Size; - OutputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough - if (!OutputBuffer) - return CAB_STATUS_NOMEMORY; + OutputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough + if (!OutputBuffer) + return CAB_STATUS_NOMEMORY; #if defined(WIN32) - FileHandle = CreateFile(CabinetName, // Open this file - GENERIC_READ, // Open for reading - FILE_SHARE_READ, // Share for reading - NULL, // No security - OPEN_EXISTING, // Existing file only - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template + FileHandle = CreateFile(CabinetName, // Open this file + GENERIC_READ, // Open for reading + FILE_SHARE_READ, // Share for reading + NULL, // No security + OPEN_EXISTING, // Existing file only + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("Cannot open file.\n")); - return CAB_STATUS_CANNOT_OPEN; - } + if (FileHandle == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("Cannot open file.\n")); + return CAB_STATUS_CANNOT_OPEN; + } #else /* !WIN32 */ - FileHandle = fopen(CabinetName, "rb"); - if (FileHandle == NULL) - { - DPRINT(MID_TRACE, ("Cannot open file.\n")); - return CAB_STATUS_CANNOT_OPEN; - } + FileHandle = fopen(CabinetName, "rb"); + if (FileHandle == NULL) + { + DPRINT(MID_TRACE, ("Cannot open file.\n")); + return CAB_STATUS_CANNOT_OPEN; + } #endif - FileOpen = true; + FileOpen = true; - /* Load CAB header */ - if ((Status = ReadBlock(&CABHeader, sizeof(CFHEADER), &BytesRead)) - != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + /* Load CAB header */ + if ((Status = ReadBlock(&CABHeader, sizeof(CFHEADER), &BytesRead)) + != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - /* Check header */ - if ((BytesRead != sizeof(CFHEADER)) || - (CABHeader.Signature != CAB_SIGNATURE ) || - (CABHeader.Version != CAB_VERSION ) || - (CABHeader.FolderCount == 0 ) || - (CABHeader.FileCount == 0 ) || - (CABHeader.FileTableOffset < sizeof(CFHEADER))) - { - CloseCabinet(); - DPRINT(MID_TRACE, ("File has invalid header.\n")); - return CAB_STATUS_INVALID_CAB; - } + /* Check header */ + if ((BytesRead != sizeof(CFHEADER)) || + (CABHeader.Signature != CAB_SIGNATURE ) || + (CABHeader.Version != CAB_VERSION ) || + (CABHeader.FolderCount == 0 ) || + (CABHeader.FileCount == 0 ) || + (CABHeader.FileTableOffset < sizeof(CFHEADER))) + { + CloseCabinet(); + DPRINT(MID_TRACE, ("File has invalid header.\n")); + return CAB_STATUS_INVALID_CAB; + } - Size = 0; + Size = 0; - /* Read/skip any reserved bytes */ - if (CABHeader.Flags & CAB_FLAG_RESERVE) - { - if ((Status = ReadBlock(&Size, sizeof(ULONG), &BytesRead)) - != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } - CabinetReserved = Size & 0xFFFF; - FolderReserved = (Size >> 16) & 0xFF; - DataReserved = (Size >> 24) & 0xFF; + /* Read/skip any reserved bytes */ + if (CABHeader.Flags & CAB_FLAG_RESERVE) + { + if ((Status = ReadBlock(&Size, sizeof(ULONG), &BytesRead)) + != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } + CabinetReserved = Size & 0xFFFF; + FolderReserved = (Size >> 16) & 0xFF; + DataReserved = (Size >> 24) & 0xFF; #if defined(WIN32) - SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_FAILURE; - } + SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_FAILURE; + } #else - if (fseek(FileHandle, (off_t)CabinetReserved, SEEK_CUR) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_FAILURE; - } + if (fseek(FileHandle, (off_t)CabinetReserved, SEEK_CUR) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_FAILURE; + } #endif - } + } - if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) - { - /* Read name of previous cabinet */ - Status = ReadString(CabinetPrev, 256); - if (Status != CAB_STATUS_SUCCESS) - return Status; - /* Read label of previous disk */ - Status = ReadString(DiskPrev, 256); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - else - { - strcpy(CabinetPrev, ""); - strcpy(DiskPrev, ""); - } + if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) + { + /* Read name of previous cabinet */ + Status = ReadString(CabinetPrev, 256); + if (Status != CAB_STATUS_SUCCESS) + return Status; + /* Read label of previous disk */ + Status = ReadString(DiskPrev, 256); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + else + { + strcpy(CabinetPrev, ""); + strcpy(DiskPrev, ""); + } - if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) - { - /* Read name of next cabinet */ - Status = ReadString(CabinetNext, 256); - if (Status != CAB_STATUS_SUCCESS) - return Status; - /* Read label of next disk */ - Status = ReadString(DiskNext, 256); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - else - { - strcpy(CabinetNext, ""); - strcpy(DiskNext, ""); - } + if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) + { + /* Read name of next cabinet */ + Status = ReadString(CabinetNext, 256); + if (Status != CAB_STATUS_SUCCESS) + return Status; + /* Read label of next disk */ + Status = ReadString(DiskNext, 256); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + else + { + strcpy(CabinetNext, ""); + strcpy(DiskNext, ""); + } - /* Read all folders */ - for (Index = 0; Index < CABHeader.FolderCount; Index++) - { - FolderNode = NewFolderNode(); - if (!FolderNode) - { - DPRINT(MIN_TRACE, ("Insufficient resources.\n")); - return CAB_STATUS_NOMEMORY; - } + /* Read all folders */ + for (Index = 0; Index < CABHeader.FolderCount; Index++) + { + FolderNode = NewFolderNode(); + if (!FolderNode) + { + DPRINT(MIN_TRACE, ("Insufficient resources.\n")); + return CAB_STATUS_NOMEMORY; + } - if (Index == 0) - FolderNode->UncompOffset = FolderUncompSize; + if (Index == 0) + FolderNode->UncompOffset = FolderUncompSize; - FolderNode->Index = Index; + FolderNode->Index = Index; - if ((Status = ReadBlock(&FolderNode->Folder, - sizeof(CFFOLDER), &BytesRead)) != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } - } + if ((Status = ReadBlock(&FolderNode->Folder, + sizeof(CFFOLDER), &BytesRead)) != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } + } - /* Read file entries */ - Status = ReadFileTable(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("ReadFileTable() failed (%lu).\n", (ULONG)Status)); - return Status; - } + /* Read file entries */ + Status = ReadFileTable(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("ReadFileTable() failed (%lu).\n", (ULONG)Status)); + return Status; + } - /* Read data blocks for all folders */ - FolderNode = FolderListHead; - while (FolderNode != NULL) - { - Status = ReadDataBlocks(FolderNode); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("ReadDataBlocks() failed (%lu).\n", (ULONG)Status)); - return Status; - } - FolderNode = FolderNode->Next; - } - } - return CAB_STATUS_SUCCESS; + /* Read data blocks for all folders */ + FolderNode = FolderListHead; + while (FolderNode != NULL) + { + Status = ReadDataBlocks(FolderNode); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("ReadDataBlocks() failed (%lu).\n", (ULONG)Status)); + return Status; + } + FolderNode = FolderNode->Next; + } + } + return CAB_STATUS_SUCCESS; } @@ -797,11 +795,11 @@ void CCabinet::Close() * FUNCTION: Closes the cabinet file */ { - if (FileOpen) - { - CloseFile(FileHandle); - FileOpen = false; - } + if (FileOpen) + { + CloseFile(FileHandle); + FileOpen = false; + } } @@ -816,10 +814,10 @@ ULONG CCabinet::FindFirst(char* FileName, * Status of operation */ { - RestartSearch = false; - strncpy(Search->Search, FileName, MAX_PATH); - Search->Next = FileListHead; - return FindNext(Search); + RestartSearch = false; + strncpy(Search->Search, FileName, MAX_PATH); + Search->Next = FileListHead; + return FindNext(Search); } @@ -832,53 +830,53 @@ ULONG CCabinet::FindNext(PCAB_SEARCH Search) * Status of operation */ { - ULONG Status; + ULONG Status; - if (RestartSearch) - { - Search->Next = FileListHead; + if (RestartSearch) + { + Search->Next = FileListHead; - /* Skip split files already extracted */ - while ((Search->Next) && - (Search->Next->File.FileControlID > CAB_FILE_MAX_FOLDER) && - (Search->Next->File.FileOffset <= LastFileOffset)) - { - DPRINT(MAX_TRACE, ("Skipping file (%s) FileOffset (0x%lX) LastFileOffset (0x%lX).\n", - Search->Next->FileName, Search->Next->File.FileOffset, LastFileOffset)); - Search->Next = Search->Next->Next; - } + /* Skip split files already extracted */ + while ((Search->Next) && + (Search->Next->File.FileControlID > CAB_FILE_MAX_FOLDER) && + (Search->Next->File.FileOffset <= LastFileOffset)) + { + DPRINT(MAX_TRACE, ("Skipping file (%s) FileOffset (0x%lX) LastFileOffset (0x%lX).\n", + Search->Next->FileName, Search->Next->File.FileOffset, LastFileOffset)); + Search->Next = Search->Next->Next; + } - RestartSearch = false; - } + RestartSearch = false; + } - /* FIXME: Check search criteria */ + /* FIXME: Check search criteria */ - if (!Search->Next) - { - if (strlen(DiskNext) > 0) - { - CloseCabinet(); + if (!Search->Next) + { + if (strlen(DiskNext) > 0) + { + CloseCabinet(); - SetCabinetName(CabinetNext); + SetCabinetName(CabinetNext); - OnDiskChange(CabinetNext, DiskNext); + OnDiskChange(CabinetNext, DiskNext); - Status = Open(); - if (Status != CAB_STATUS_SUCCESS) - return Status; + Status = Open(); + if (Status != CAB_STATUS_SUCCESS) + return Status; - Search->Next = FileListHead; - if (!Search->Next) - return CAB_STATUS_NOFILE; - } - else - return CAB_STATUS_NOFILE; - } + Search->Next = FileListHead; + if (!Search->Next) + return CAB_STATUS_NOFILE; + } + else + return CAB_STATUS_NOFILE; + } - Search->File = &Search->Next->File; - Search->FileName = Search->Next->FileName; - Search->Next = Search->Next->Next; - return CAB_STATUS_SUCCESS; + Search->File = &Search->Next->File; + Search->FileName = Search->Next->FileName; + Search->Next = Search->Next->Next; + return CAB_STATUS_SUCCESS; } @@ -891,415 +889,415 @@ ULONG CCabinet::ExtractFile(char* FileName) * Status of operation */ { - ULONG Size; - ULONG Offset; - ULONG BytesRead; - ULONG BytesToRead; - ULONG BytesWritten; - ULONG BytesSkipped; - ULONG BytesToWrite; - ULONG TotalBytesRead; - ULONG CurrentOffset; - unsigned char* Buffer; - unsigned char* CurrentBuffer; - FILEHANDLE DestFile; - PCFFILE_NODE File; - CFDATA CFData; - ULONG Status; - bool Skip; + ULONG Size; + ULONG Offset; + ULONG BytesRead; + ULONG BytesToRead; + ULONG BytesWritten; + ULONG BytesSkipped; + ULONG BytesToWrite; + ULONG TotalBytesRead; + ULONG CurrentOffset; + unsigned char* Buffer; + unsigned char* CurrentBuffer; + FILEHANDLE DestFile; + PCFFILE_NODE File; + CFDATA CFData; + ULONG Status; + bool Skip; #if defined(WIN32) - FILETIME FileTime; + FILETIME FileTime; #endif - char DestName[MAX_PATH]; - char TempName[MAX_PATH]; + char DestName[MAX_PATH]; + char TempName[MAX_PATH]; - Status = LocateFile(FileName, &File); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MID_TRACE, ("Cannot locate file (%lu).\n", (ULONG)Status)); - return Status; - } + Status = LocateFile(FileName, &File); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MID_TRACE, ("Cannot locate file (%lu).\n", (ULONG)Status)); + return Status; + } - LastFileOffset = File->File.FileOffset; + LastFileOffset = File->File.FileOffset; - switch (CurrentFolderNode->Folder.CompressionType & CAB_COMP_MASK) - { - case CAB_COMP_NONE: - SelectCodec(CAB_CODEC_RAW); - break; + switch (CurrentFolderNode->Folder.CompressionType & CAB_COMP_MASK) + { + case CAB_COMP_NONE: + SelectCodec(CAB_CODEC_RAW); + break; - case CAB_COMP_MSZIP: - SelectCodec(CAB_CODEC_MSZIP); - break; + case CAB_COMP_MSZIP: + SelectCodec(CAB_CODEC_MSZIP); + break; - default: - return CAB_STATUS_UNSUPPCOMP; - } + default: + return CAB_STATUS_UNSUPPCOMP; + } - DPRINT(MAX_TRACE, ("Extracting file at uncompressed offset (0x%lX) Size (%lu bytes) AO (0x%lX) UO (0x%lX).\n", - (ULONG)File->File.FileOffset, - (ULONG)File->File.FileSize, - (ULONG)File->DataBlock->AbsoluteOffset, - (ULONG)File->DataBlock->UncompOffset)); + DPRINT(MAX_TRACE, ("Extracting file at uncompressed offset (0x%lX) Size (%lu bytes) AO (0x%lX) UO (0x%lX).\n", + (ULONG)File->File.FileOffset, + (ULONG)File->File.FileSize, + (ULONG)File->DataBlock->AbsoluteOffset, + (ULONG)File->DataBlock->UncompOffset)); - strcpy(DestName, DestPath); - strcat(DestName, FileName); + strcpy(DestName, DestPath); + strcat(DestName, FileName); - /* Create destination file, fail if it already exists */ + /* Create destination file, fail if it already exists */ #if defined(WIN32) - DestFile = CreateFile(DestName, // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - CREATE_NEW, // New file only - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (DestFile == INVALID_HANDLE_VALUE) - { - /* If file exists, ask to overwrite file */ - if (((Status = GetLastError()) == ERROR_FILE_EXISTS) && - (OnOverwrite(&File->File, FileName))) - { - /* Create destination file, overwrite if it already exists */ - DestFile = CreateFile(DestName, // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - TRUNCATE_EXISTING, // Truncate the file - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (DestFile == INVALID_HANDLE_VALUE) - return CAB_STATUS_CANNOT_CREATE; - } - else - { - if (Status == ERROR_FILE_EXISTS) - return CAB_STATUS_FILE_EXISTS; - else - return CAB_STATUS_CANNOT_CREATE; - } - } + DestFile = CreateFile(DestName, // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + CREATE_NEW, // New file only + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (DestFile == INVALID_HANDLE_VALUE) + { + /* If file exists, ask to overwrite file */ + if (((Status = GetLastError()) == ERROR_FILE_EXISTS) && + (OnOverwrite(&File->File, FileName))) + { + /* Create destination file, overwrite if it already exists */ + DestFile = CreateFile(DestName, // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + TRUNCATE_EXISTING, // Truncate the file + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (DestFile == INVALID_HANDLE_VALUE) + return CAB_STATUS_CANNOT_CREATE; + } + else + { + if (Status == ERROR_FILE_EXISTS) + return CAB_STATUS_FILE_EXISTS; + else + return CAB_STATUS_CANNOT_CREATE; + } + } #else /* !WIN32 */ - DestFile = fopen(DestName, "rb"); - if (DestFile != NULL) - { - fclose(DestFile); - /* If file exists, ask to overwrite file */ - if (OnOverwrite(&File->File, FileName)) - { - DestFile = fopen(DestName, "w+b"); - if (DestFile == NULL) - return CAB_STATUS_CANNOT_CREATE; - } - else - return CAB_STATUS_FILE_EXISTS; - } - else - { - DestFile = fopen(DestName, "w+b"); - if (DestFile == NULL) - return CAB_STATUS_CANNOT_CREATE; - } + DestFile = fopen(DestName, "rb"); + if (DestFile != NULL) + { + fclose(DestFile); + /* If file exists, ask to overwrite file */ + if (OnOverwrite(&File->File, FileName)) + { + DestFile = fopen(DestName, "w+b"); + if (DestFile == NULL) + return CAB_STATUS_CANNOT_CREATE; + } + else + return CAB_STATUS_FILE_EXISTS; + } + else + { + DestFile = fopen(DestName, "w+b"); + if (DestFile == NULL) + return CAB_STATUS_CANNOT_CREATE; + } #endif #if defined(WIN32) - if (!DosDateTimeToFileTime(File->File.FileDate, File->File.FileTime, &FileTime)) - { - CloseFile(DestFile); - DPRINT(MIN_TRACE, ("DosDateTimeToFileTime() failed (%lu).\n", GetLastError())); - return CAB_STATUS_CANNOT_WRITE; - } + if (!DosDateTimeToFileTime(File->File.FileDate, File->File.FileTime, &FileTime)) + { + CloseFile(DestFile); + DPRINT(MIN_TRACE, ("DosDateTimeToFileTime() failed (%lu).\n", GetLastError())); + return CAB_STATUS_CANNOT_WRITE; + } - SetFileTime(DestFile, NULL, &FileTime, NULL); + SetFileTime(DestFile, NULL, &FileTime, NULL); #else - //DPRINT(MIN_TRACE, ("FIXME: DosDateTimeToFileTime\n")); + //DPRINT(MIN_TRACE, ("FIXME: DosDateTimeToFileTime\n")); #endif - SetAttributesOnFile(File); + SetAttributesOnFile(File); - Buffer = (unsigned char*)AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough - if (!Buffer) - { - CloseFile(DestFile); - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + Buffer = (unsigned char*)AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough + if (!Buffer) + { + CloseFile(DestFile); + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - /* Call OnExtract event handler */ - OnExtract(&File->File, FileName); + /* Call OnExtract event handler */ + OnExtract(&File->File, FileName); - /* Search to start of file */ + /* Search to start of file */ #if defined(WIN32) - Offset = SetFilePointer(FileHandle, - File->DataBlock->AbsoluteOffset, - NULL, - FILE_BEGIN); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + Offset = SetFilePointer(FileHandle, + File->DataBlock->AbsoluteOffset, + NULL, + FILE_BEGIN); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)File->DataBlock->AbsoluteOffset, SEEK_SET) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_FAILURE; - } - Offset = ftell(FileHandle); + if (fseek(FileHandle, (off_t)File->DataBlock->AbsoluteOffset, SEEK_SET) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_FAILURE; + } + Offset = ftell(FileHandle); #endif - Size = File->File.FileSize; - Offset = File->File.FileOffset; - CurrentOffset = File->DataBlock->UncompOffset; + Size = File->File.FileSize; + Offset = File->File.FileOffset; + CurrentOffset = File->DataBlock->UncompOffset; - Skip = true; + Skip = true; - ReuseBlock = (CurrentDataNode == File->DataBlock); - if (Size > 0) - { - do - { - DPRINT(MAX_TRACE, ("CO (0x%lX) ReuseBlock (%lu) Offset (0x%lX) Size (%ld) BytesLeftInBlock (%ld)\n", - File->DataBlock->UncompOffset, (ULONG)ReuseBlock, Offset, Size, - BytesLeftInBlock)); + ReuseBlock = (CurrentDataNode == File->DataBlock); + if (Size > 0) + { + do + { + DPRINT(MAX_TRACE, ("CO (0x%lX) ReuseBlock (%lu) Offset (0x%lX) Size (%ld) BytesLeftInBlock (%ld)\n", + File->DataBlock->UncompOffset, (ULONG)ReuseBlock, Offset, Size, + BytesLeftInBlock)); - if (/*(CurrentDataNode != File->DataBlock) &&*/ (!ReuseBlock) || (BytesLeftInBlock <= 0)) - { - DPRINT(MAX_TRACE, ("Filling buffer. ReuseBlock (%lu)\n", (ULONG)ReuseBlock)); + if (/*(CurrentDataNode != File->DataBlock) &&*/ (!ReuseBlock) || (BytesLeftInBlock <= 0)) + { + DPRINT(MAX_TRACE, ("Filling buffer. ReuseBlock (%lu)\n", (ULONG)ReuseBlock)); - CurrentBuffer = Buffer; - TotalBytesRead = 0; - do - { - DPRINT(MAX_TRACE, ("Size (%lu bytes).\n", Size)); + CurrentBuffer = Buffer; + TotalBytesRead = 0; + do + { + DPRINT(MAX_TRACE, ("Size (%lu bytes).\n", Size)); - if (((Status = ReadBlock(&CFData, sizeof(CFDATA), &BytesRead)) != - CAB_STATUS_SUCCESS) || (BytesRead != sizeof(CFDATA))) - { - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + if (((Status = ReadBlock(&CFData, sizeof(CFDATA), &BytesRead)) != + CAB_STATUS_SUCCESS) || (BytesRead != sizeof(CFDATA))) + { + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - DPRINT(MAX_TRACE, ("Data block: Checksum (0x%lX) CompSize (%lu bytes) UncompSize (%lu bytes)\n", - (ULONG)CFData.Checksum, - (ULONG)CFData.CompSize, - (ULONG)CFData.UncompSize)); + DPRINT(MAX_TRACE, ("Data block: Checksum (0x%lX) CompSize (%lu bytes) UncompSize (%lu bytes)\n", + (ULONG)CFData.Checksum, + (ULONG)CFData.CompSize, + (ULONG)CFData.UncompSize)); - ASSERT(CFData.CompSize <= CAB_BLOCKSIZE + 12); + ASSERT(CFData.CompSize <= CAB_BLOCKSIZE + 12); - BytesToRead = CFData.CompSize; + BytesToRead = CFData.CompSize; - DPRINT(MAX_TRACE, ("Read: (0x%lX,0x%lX).\n", - (_W64 unsigned long)CurrentBuffer, (_W64 unsigned long)Buffer)); + DPRINT(MAX_TRACE, ("Read: (0x%lX,0x%lX).\n", + (_W64 unsigned long)CurrentBuffer, (_W64 unsigned long)Buffer)); - if (((Status = ReadBlock(CurrentBuffer, BytesToRead, &BytesRead)) != - CAB_STATUS_SUCCESS) || (BytesToRead != BytesRead)) - { - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + if (((Status = ReadBlock(CurrentBuffer, BytesToRead, &BytesRead)) != + CAB_STATUS_SUCCESS) || (BytesToRead != BytesRead)) + { + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - /* FIXME: Does not work with files generated by makecab.exe */ + /* FIXME: Does not work with files generated by makecab.exe */ /* - if (CFData.Checksum != 0) - { - ULONG Checksum = ComputeChecksum(CurrentBuffer, BytesRead, 0); - if (Checksum != CFData.Checksum) - { - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MIN_TRACE, ("Bad checksum (is 0x%X, should be 0x%X).\n", - Checksum, CFData.Checksum)); - return CAB_STATUS_INVALID_CAB; - } - } + if (CFData.Checksum != 0) + { + ULONG Checksum = ComputeChecksum(CurrentBuffer, BytesRead, 0); + if (Checksum != CFData.Checksum) + { + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MIN_TRACE, ("Bad checksum (is 0x%X, should be 0x%X).\n", + Checksum, CFData.Checksum)); + return CAB_STATUS_INVALID_CAB; + } + } */ - TotalBytesRead += BytesRead; + TotalBytesRead += BytesRead; - CurrentBuffer += BytesRead; + CurrentBuffer += BytesRead; - if (CFData.UncompSize == 0) - { - if (strlen(DiskNext) == 0) - return CAB_STATUS_NOFILE; + if (CFData.UncompSize == 0) + { + if (strlen(DiskNext) == 0) + return CAB_STATUS_NOFILE; - /* CloseCabinet() will destroy all file entries so in case - FileName refers to the FileName field of a CFFOLDER_NODE - structure, we have to save a copy of the filename */ - strcpy(TempName, FileName); + /* CloseCabinet() will destroy all file entries so in case + FileName refers to the FileName field of a CFFOLDER_NODE + structure, we have to save a copy of the filename */ + strcpy(TempName, FileName); - CloseCabinet(); + CloseCabinet(); - SetCabinetName(CabinetNext); + SetCabinetName(CabinetNext); - OnDiskChange(CabinetNext, DiskNext); + OnDiskChange(CabinetNext, DiskNext); - Status = Open(); - if (Status != CAB_STATUS_SUCCESS) - return Status; + Status = Open(); + if (Status != CAB_STATUS_SUCCESS) + return Status; - /* The first data block of the file will not be - found as it is located in the previous file */ - Status = LocateFile(TempName, &File); - if (Status == CAB_STATUS_NOFILE) - { - DPRINT(MID_TRACE, ("Cannot locate file (%lu).\n", (ULONG)Status)); - return Status; - } + /* The first data block of the file will not be + found as it is located in the previous file */ + Status = LocateFile(TempName, &File); + if (Status == CAB_STATUS_NOFILE) + { + DPRINT(MID_TRACE, ("Cannot locate file (%lu).\n", (ULONG)Status)); + return Status; + } - /* The file is continued in the first data block in the folder */ - File->DataBlock = CurrentFolderNode->DataListHead; + /* The file is continued in the first data block in the folder */ + File->DataBlock = CurrentFolderNode->DataListHead; - /* Search to start of file */ + /* Search to start of file */ #if defined(WIN32) - SetFilePointer(FileHandle, - File->DataBlock->AbsoluteOffset, - NULL, - FILE_BEGIN); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + SetFilePointer(FileHandle, + File->DataBlock->AbsoluteOffset, + NULL, + FILE_BEGIN); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)File->DataBlock->AbsoluteOffset, SEEK_SET) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (fseek(FileHandle, (off_t)File->DataBlock->AbsoluteOffset, SEEK_SET) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #endif - DPRINT(MAX_TRACE, ("Continuing extraction of file at uncompressed offset (0x%lX) Size (%lu bytes) AO (0x%lX) UO (0x%lX).\n", - (ULONG)File->File.FileOffset, - (ULONG)File->File.FileSize, - (ULONG)File->DataBlock->AbsoluteOffset, - (ULONG)File->DataBlock->UncompOffset)); + DPRINT(MAX_TRACE, ("Continuing extraction of file at uncompressed offset (0x%lX) Size (%lu bytes) AO (0x%lX) UO (0x%lX).\n", + (ULONG)File->File.FileOffset, + (ULONG)File->File.FileSize, + (ULONG)File->DataBlock->AbsoluteOffset, + (ULONG)File->DataBlock->UncompOffset)); - CurrentDataNode = File->DataBlock; - ReuseBlock = true; + CurrentDataNode = File->DataBlock; + ReuseBlock = true; - RestartSearch = true; - } - } while (CFData.UncompSize == 0); + RestartSearch = true; + } + } while (CFData.UncompSize == 0); - DPRINT(MAX_TRACE, ("TotalBytesRead (%lu).\n", TotalBytesRead)); + DPRINT(MAX_TRACE, ("TotalBytesRead (%lu).\n", TotalBytesRead)); - Status = Codec->Uncompress(OutputBuffer, Buffer, TotalBytesRead, &BytesToWrite); - if (Status != CS_SUCCESS) - { - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MID_TRACE, ("Cannot uncompress block.\n")); - if (Status == CS_NOMEMORY) - return CAB_STATUS_NOMEMORY; - return CAB_STATUS_INVALID_CAB; - } + Status = Codec->Uncompress(OutputBuffer, Buffer, TotalBytesRead, &BytesToWrite); + if (Status != CS_SUCCESS) + { + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MID_TRACE, ("Cannot uncompress block.\n")); + if (Status == CS_NOMEMORY) + return CAB_STATUS_NOMEMORY; + return CAB_STATUS_INVALID_CAB; + } - if (BytesToWrite != CFData.UncompSize) - { - DPRINT(MID_TRACE, ("BytesToWrite (%lu) != CFData.UncompSize (%d)\n", - BytesToWrite, CFData.UncompSize)); - return CAB_STATUS_INVALID_CAB; - } + if (BytesToWrite != CFData.UncompSize) + { + DPRINT(MID_TRACE, ("BytesToWrite (%lu) != CFData.UncompSize (%d)\n", + BytesToWrite, CFData.UncompSize)); + return CAB_STATUS_INVALID_CAB; + } - BytesLeftInBlock = BytesToWrite; - } - else - { - DPRINT(MAX_TRACE, ("Using same buffer. ReuseBlock (%lu)\n", (ULONG)ReuseBlock)); + BytesLeftInBlock = BytesToWrite; + } + else + { + DPRINT(MAX_TRACE, ("Using same buffer. ReuseBlock (%lu)\n", (ULONG)ReuseBlock)); - BytesToWrite = BytesLeftInBlock; + BytesToWrite = BytesLeftInBlock; - DPRINT(MAX_TRACE, ("Seeking to absolute offset 0x%lX.\n", - CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + - CurrentDataNode->Data.CompSize)); + DPRINT(MAX_TRACE, ("Seeking to absolute offset 0x%lX.\n", + CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + + CurrentDataNode->Data.CompSize)); - if (((Status = ReadBlock(&CFData, sizeof(CFDATA), &BytesRead)) != - CAB_STATUS_SUCCESS) || (BytesRead != sizeof(CFDATA))) - { - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + if (((Status = ReadBlock(&CFData, sizeof(CFDATA), &BytesRead)) != + CAB_STATUS_SUCCESS) || (BytesRead != sizeof(CFDATA))) + { + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - DPRINT(MAX_TRACE, ("CFData.CompSize 0x%X CFData.UncompSize 0x%X.\n", - CFData.CompSize, CFData.UncompSize)); + DPRINT(MAX_TRACE, ("CFData.CompSize 0x%X CFData.UncompSize 0x%X.\n", + CFData.CompSize, CFData.UncompSize)); - /* Go to next data block */ + /* Go to next data block */ #if defined(WIN32) - SetFilePointer(FileHandle, - CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + - CurrentDataNode->Data.CompSize, - NULL, - FILE_BEGIN); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + SetFilePointer(FileHandle, + CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + + CurrentDataNode->Data.CompSize, + NULL, + FILE_BEGIN); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + - CurrentDataNode->Data.CompSize, SEEK_SET) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (fseek(FileHandle, (off_t)CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) + + CurrentDataNode->Data.CompSize, SEEK_SET) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #endif - ReuseBlock = false; - } + ReuseBlock = false; + } - if (Skip) - BytesSkipped = (Offset - CurrentOffset); - else - BytesSkipped = 0; + if (Skip) + BytesSkipped = (Offset - CurrentOffset); + else + BytesSkipped = 0; - BytesToWrite -= BytesSkipped; + BytesToWrite -= BytesSkipped; - if (Size < BytesToWrite) - BytesToWrite = Size; + if (Size < BytesToWrite) + BytesToWrite = Size; - DPRINT(MAX_TRACE, ("Offset (0x%lX) CurrentOffset (0x%lX) ToWrite (%lu) Skipped (%lu)(%lu) Size (%lu).\n", - (ULONG)Offset, - (ULONG)CurrentOffset, - (ULONG)BytesToWrite, - (ULONG)BytesSkipped, (ULONG)Skip, - (ULONG)Size)); + DPRINT(MAX_TRACE, ("Offset (0x%lX) CurrentOffset (0x%lX) ToWrite (%lu) Skipped (%lu)(%lu) Size (%lu).\n", + (ULONG)Offset, + (ULONG)CurrentOffset, + (ULONG)BytesToWrite, + (ULONG)BytesSkipped, (ULONG)Skip, + (ULONG)Size)); #if defined(WIN32) - if (!WriteFile(DestFile, (void*)((unsigned long *)OutputBuffer + BytesSkipped), - BytesToWrite, (LPDWORD)&BytesWritten, NULL) || - (BytesToWrite != BytesWritten)) - { - DPRINT(MIN_TRACE, ("Status 0x%lX.\n", GetLastError())); + if (!WriteFile(DestFile, (void*)((unsigned long *)OutputBuffer + BytesSkipped), + BytesToWrite, (LPDWORD)&BytesWritten, NULL) || + (BytesToWrite != BytesWritten)) + { + DPRINT(MIN_TRACE, ("Status 0x%lX.\n", GetLastError())); #else - BytesWritten = BytesToWrite; - if (fwrite((void*)((unsigned long *)OutputBuffer + BytesSkipped), - BytesToWrite, 1, DestFile) < 1) - { + BytesWritten = BytesToWrite; + if (fwrite((void*)((unsigned long *)OutputBuffer + BytesSkipped), + BytesToWrite, 1, DestFile) < 1) + { #endif - CloseFile(DestFile); - FreeMemory(Buffer); - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } - Size -= BytesToWrite; + CloseFile(DestFile); + FreeMemory(Buffer); + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } + Size -= BytesToWrite; - CurrentOffset += BytesToWrite; + CurrentOffset += BytesToWrite; - /* Don't skip any more bytes */ - Skip = false; - } while (Size > 0); - } + /* Don't skip any more bytes */ + Skip = false; + } while (Size > 0); + } - CloseFile(DestFile); + CloseFile(DestFile); - FreeMemory(Buffer); + FreeMemory(Buffer); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1310,33 +1308,33 @@ void CCabinet::SelectCodec(ULONG Id) * Id = Codec identifier */ { - if (CodecSelected) - { - if (Id == CodecId) - return; + if (CodecSelected) + { + if (Id == CodecId) + return; - CodecSelected = false; - delete Codec; - } + CodecSelected = false; + delete Codec; + } - switch (Id) - { - case CAB_CODEC_RAW: + switch (Id) + { + case CAB_CODEC_RAW: #if 0 - Codec = new CRawCodec(); + Codec = new CRawCodec(); #endif - break; + break; - case CAB_CODEC_MSZIP: - Codec = new CMSZipCodec(); - break; + case CAB_CODEC_MSZIP: + Codec = new CMSZipCodec(); + break; - default: - return; - } + default: + return; + } - CodecId = Id; - CodecSelected = true; + CodecId = Id; + CodecSelected = true; } @@ -1351,67 +1349,67 @@ ULONG CCabinet::NewCabinet() * Status of operation */ { - ULONG Status; + ULONG Status; - CurrentDiskNumber = 0; + CurrentDiskNumber = 0; - OutputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough - InputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough - if ((!OutputBuffer) || (!InputBuffer)) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } - CurrentIBuffer = InputBuffer; - CurrentIBufferSize = 0; + OutputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough + InputBuffer = AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough + if ((!OutputBuffer) || (!InputBuffer)) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } + CurrentIBuffer = InputBuffer; + CurrentIBufferSize = 0; - CABHeader.Signature = CAB_SIGNATURE; - CABHeader.Reserved1 = 0; // Not used - CABHeader.CabinetSize = 0; // Not yet known - CABHeader.Reserved2 = 0; // Not used - CABHeader.Reserved3 = 0; // Not used - CABHeader.Version = CAB_VERSION; - CABHeader.FolderCount = 0; // Not yet known - CABHeader.FileCount = 0; // Not yet known - CABHeader.Flags = 0; // Not yet known - // FIXME: Should be random - CABHeader.SetID = 0x534F; - CABHeader.CabinetNumber = 0; + CABHeader.Signature = CAB_SIGNATURE; + CABHeader.Reserved1 = 0; // Not used + CABHeader.CabinetSize = 0; // Not yet known + CABHeader.Reserved2 = 0; // Not used + CABHeader.Reserved3 = 0; // Not used + CABHeader.Version = CAB_VERSION; + CABHeader.FolderCount = 0; // Not yet known + CABHeader.FileCount = 0; // Not yet known + CABHeader.Flags = 0; // Not yet known + // FIXME: Should be random + CABHeader.SetID = 0x534F; + CABHeader.CabinetNumber = 0; - TotalFolderSize = 0; - TotalFileSize = 0; + TotalFolderSize = 0; + TotalFileSize = 0; - DiskSize = sizeof(CFHEADER); + DiskSize = sizeof(CFHEADER); - InitCabinetHeader(); + InitCabinetHeader(); - // NextFolderNumber is 0-based - NextFolderNumber = 0; + // NextFolderNumber is 0-based + NextFolderNumber = 0; - CurrentFolderNode = NULL; - Status = NewFolder(); - if (Status != CAB_STATUS_SUCCESS) - return Status; + CurrentFolderNode = NULL; + Status = NewFolder(); + if (Status != CAB_STATUS_SUCCESS) + return Status; - CurrentFolderNode->Folder.DataOffset = DiskSize - TotalHeaderSize; + CurrentFolderNode->Folder.DataOffset = DiskSize - TotalHeaderSize; - ScratchFile = new CCFDATAStorage; - if (!ScratchFile) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + ScratchFile = new CCFDATAStorage; + if (!ScratchFile) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - Status = ScratchFile->Create("~CAB.tmp"); + Status = ScratchFile->Create("~CAB.tmp"); - CreateNewFolder = false; + CreateNewFolder = false; - CreateNewDisk = false; + CreateNewDisk = false; - PrevCabinetNumber = 0; + PrevCabinetNumber = 0; - return Status; + return Status; } @@ -1422,20 +1420,20 @@ ULONG CCabinet::NewDisk() * Status of operation */ { - // NextFolderNumber is 0-based - NextFolderNumber = 1; + // NextFolderNumber is 0-based + NextFolderNumber = 1; - CreateNewDisk = false; + CreateNewDisk = false; - DiskSize = sizeof(CFHEADER) + TotalFolderSize + TotalFileSize; + DiskSize = sizeof(CFHEADER) + TotalFolderSize + TotalFileSize; - InitCabinetHeader(); + InitCabinetHeader(); - CurrentFolderNode->TotalFolderSize = 0; + CurrentFolderNode->TotalFolderSize = 0; - CurrentFolderNode->Folder.DataBlockCount = 0; + CurrentFolderNode->Folder.DataBlockCount = 0; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1446,41 +1444,41 @@ ULONG CCabinet::NewFolder() * Status of operation */ { - DPRINT(MAX_TRACE, ("Creating new folder.\n")); + DPRINT(MAX_TRACE, ("Creating new folder.\n")); - CurrentFolderNode = NewFolderNode(); - if (!CurrentFolderNode) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + CurrentFolderNode = NewFolderNode(); + if (!CurrentFolderNode) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - switch (CodecId) { - case CAB_CODEC_RAW: - CurrentFolderNode->Folder.CompressionType = CAB_COMP_NONE; - break; + switch (CodecId) { + case CAB_CODEC_RAW: + CurrentFolderNode->Folder.CompressionType = CAB_COMP_NONE; + break; - case CAB_CODEC_MSZIP: - CurrentFolderNode->Folder.CompressionType = CAB_COMP_MSZIP; - break; + case CAB_CODEC_MSZIP: + CurrentFolderNode->Folder.CompressionType = CAB_COMP_MSZIP; + break; - default: - return CAB_STATUS_UNSUPPCOMP; - } + default: + return CAB_STATUS_UNSUPPCOMP; + } - /* FIXME: This won't work if no files are added to the new folder */ + /* FIXME: This won't work if no files are added to the new folder */ - DiskSize += sizeof(CFFOLDER); + DiskSize += sizeof(CFFOLDER); - TotalFolderSize += sizeof(CFFOLDER); + TotalFolderSize += sizeof(CFFOLDER); - NextFolderNumber++; + NextFolderNumber++; - CABHeader.FolderCount++; + CABHeader.FolderCount++; - LastBlockStart = 0; + LastBlockStart = 0; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1493,125 +1491,125 @@ ULONG CCabinet::WriteFileToScratchStorage(PCFFILE_NODE FileNode) * Status of operation */ { - ULONG BytesToRead; - ULONG BytesRead; - ULONG Status; - ULONG Size; + ULONG BytesToRead; + ULONG BytesRead; + ULONG Status; + ULONG Size; - if (!ContinueFile) - { - /* Try to open file */ + if (!ContinueFile) + { + /* Try to open file */ #if defined(WIN32) - SourceFile = CreateFile( - FileNode->FileName, // Open this file - GENERIC_READ, // Open for reading - FILE_SHARE_READ, // Share for reading - NULL, // No security - OPEN_EXISTING, // File must exist - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (SourceFile == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("File not found (%s).\n", FileNode->FileName)); - return CAB_STATUS_NOFILE; - } + SourceFile = CreateFile( + FileNode->FileName, // Open this file + GENERIC_READ, // Open for reading + FILE_SHARE_READ, // Share for reading + NULL, // No security + OPEN_EXISTING, // File must exist + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (SourceFile == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("File not found (%s).\n", FileNode->FileName)); + return CAB_STATUS_NOFILE; + } #else /* !WIN32 */ - SourceFile = fopen(FileNode->FileName, "rb"); - if (SourceFile == NULL) - { - DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); - return CAB_STATUS_NOFILE; - } + SourceFile = fopen(FileNode->FileName, "rb"); + if (SourceFile == NULL) + { + DPRINT(MID_TRACE, ("Cannot open cabinet reserved file.\n")); + return CAB_STATUS_NOFILE; + } #endif - if (CreateNewFolder) - { - /* There is always a new folder after - a split file is completely stored */ - Status = NewFolder(); - if (Status != CAB_STATUS_SUCCESS) - return Status; - CreateNewFolder = false; - } + if (CreateNewFolder) + { + /* There is always a new folder after + a split file is completely stored */ + Status = NewFolder(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + CreateNewFolder = false; + } - /* Call OnAdd event handler */ - OnAdd(&FileNode->File, FileNode->FileName); + /* Call OnAdd event handler */ + OnAdd(&FileNode->File, FileNode->FileName); - TotalBytesLeft = FileNode->File.FileSize; + TotalBytesLeft = FileNode->File.FileSize; - FileNode->File.FileOffset = CurrentFolderNode->UncompOffset; - CurrentFolderNode->UncompOffset += TotalBytesLeft; - FileNode->File.FileControlID = (USHORT)(NextFolderNumber - 1); - CurrentFolderNode->Commit = true; - PrevCabinetNumber = CurrentDiskNumber; + FileNode->File.FileOffset = CurrentFolderNode->UncompOffset; + CurrentFolderNode->UncompOffset += TotalBytesLeft; + FileNode->File.FileControlID = (USHORT)(NextFolderNumber - 1); + CurrentFolderNode->Commit = true; + PrevCabinetNumber = CurrentDiskNumber; - Size = sizeof(CFFILE) + (ULONG)strlen(GetFileName(FileNode->FileName)) + 1; - CABHeader.FileTableOffset += Size; - TotalFileSize += Size; - DiskSize += Size; - } + Size = sizeof(CFFILE) + (ULONG)strlen(GetFileName(FileNode->FileName)) + 1; + CABHeader.FileTableOffset += Size; + TotalFileSize += Size; + DiskSize += Size; + } - FileNode->Commit = true; + FileNode->Commit = true; - if (TotalBytesLeft > 0) - { - do - { - if (TotalBytesLeft > (ULONG)CAB_BLOCKSIZE - CurrentIBufferSize) - BytesToRead = CAB_BLOCKSIZE - CurrentIBufferSize; - else - BytesToRead = TotalBytesLeft; + if (TotalBytesLeft > 0) + { + do + { + if (TotalBytesLeft > (ULONG)CAB_BLOCKSIZE - CurrentIBufferSize) + BytesToRead = CAB_BLOCKSIZE - CurrentIBufferSize; + else + BytesToRead = TotalBytesLeft; - if (!ReadFileData(SourceFile, CurrentIBuffer, BytesToRead, &BytesRead) || (BytesToRead != BytesRead)) - { - DPRINT(MIN_TRACE, ("Cannot read from file. BytesToRead (%lu) BytesRead (%lu) CurrentIBufferSize (%lu).\n", - BytesToRead, BytesRead, CurrentIBufferSize)); - return CAB_STATUS_INVALID_CAB; - } + if (!ReadFileData(SourceFile, CurrentIBuffer, BytesToRead, &BytesRead) || (BytesToRead != BytesRead)) + { + DPRINT(MIN_TRACE, ("Cannot read from file. BytesToRead (%lu) BytesRead (%lu) CurrentIBufferSize (%lu).\n", + BytesToRead, BytesRead, CurrentIBufferSize)); + return CAB_STATUS_INVALID_CAB; + } - *(unsigned char**)&CurrentIBuffer += BytesRead; + *(unsigned char**)&CurrentIBuffer += BytesRead; - CurrentIBufferSize += (USHORT)BytesRead; + CurrentIBufferSize += (USHORT)BytesRead; - if (CurrentIBufferSize == CAB_BLOCKSIZE) - { - Status = WriteDataBlock(); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - TotalBytesLeft -= BytesRead; - } while ((TotalBytesLeft > 0) && (!CreateNewDisk)); - } + if (CurrentIBufferSize == CAB_BLOCKSIZE) + { + Status = WriteDataBlock(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + TotalBytesLeft -= BytesRead; + } while ((TotalBytesLeft > 0) && (!CreateNewDisk)); + } - if (TotalBytesLeft == 0) - { - CloseFile(SourceFile); - FileNode->Delete = true; + if (TotalBytesLeft == 0) + { + CloseFile(SourceFile); + FileNode->Delete = true; - if (FileNode->File.FileControlID > CAB_FILE_MAX_FOLDER) - { - FileNode->File.FileControlID = CAB_FILE_CONTINUED; - CurrentFolderNode->Delete = true; + if (FileNode->File.FileControlID > CAB_FILE_MAX_FOLDER) + { + FileNode->File.FileControlID = CAB_FILE_CONTINUED; + CurrentFolderNode->Delete = true; - if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) - { - Status = WriteDataBlock(); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } + if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) + { + Status = WriteDataBlock(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } - CreateNewFolder = true; - } - } - else - { - if (FileNode->File.FileControlID <= CAB_FILE_MAX_FOLDER) - FileNode->File.FileControlID = CAB_FILE_SPLIT; - else - FileNode->File.FileControlID = CAB_FILE_PREV_NEXT; - } + CreateNewFolder = true; + } + } + else + { + if (FileNode->File.FileControlID <= CAB_FILE_MAX_FOLDER) + FileNode->File.FileControlID = CAB_FILE_SPLIT; + else + FileNode->File.FileControlID = CAB_FILE_PREV_NEXT; + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1624,80 +1622,80 @@ ULONG CCabinet::WriteDisk(ULONG MoreDisks) * Status of operation */ { - PCFFILE_NODE FileNode; - ULONG Status; + PCFFILE_NODE FileNode; + ULONG Status; - ContinueFile = false; - FileNode = FileListHead; - while (FileNode != NULL) - { - Status = WriteFileToScratchStorage(FileNode); - if (Status != CAB_STATUS_SUCCESS) - return Status; + ContinueFile = false; + FileNode = FileListHead; + while (FileNode != NULL) + { + Status = WriteFileToScratchStorage(FileNode); + if (Status != CAB_STATUS_SUCCESS) + return Status; - if (CreateNewDisk) - { - /* A data block could span more than two - disks if MaxDiskSize is very small */ - while (CreateNewDisk) - { - DPRINT(MAX_TRACE, ("Creating new disk.\n")); - CommitDisk(true); - CloseDisk(); - NewDisk(); + if (CreateNewDisk) + { + /* A data block could span more than two + disks if MaxDiskSize is very small */ + while (CreateNewDisk) + { + DPRINT(MAX_TRACE, ("Creating new disk.\n")); + CommitDisk(true); + CloseDisk(); + NewDisk(); - ContinueFile = true; - CreateNewDisk = false; + ContinueFile = true; + CreateNewDisk = false; - DPRINT(MAX_TRACE, ("First on new disk. CurrentIBufferSize (%lu) CurrentOBufferSize (%lu).\n", - CurrentIBufferSize, CurrentOBufferSize)); + DPRINT(MAX_TRACE, ("First on new disk. CurrentIBufferSize (%lu) CurrentOBufferSize (%lu).\n", + CurrentIBufferSize, CurrentOBufferSize)); - if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) - { - Status = WriteDataBlock(); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - } - } - else - { - ContinueFile = false; - FileNode = FileNode->Next; - } - } + if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) + { + Status = WriteDataBlock(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + } + } + else + { + ContinueFile = false; + FileNode = FileNode->Next; + } + } - if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) - { - /* A data block could span more than two - disks if MaxDiskSize is very small */ + if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) + { + /* A data block could span more than two + disks if MaxDiskSize is very small */ - ASSERT(CreateNewDisk == false); + ASSERT(CreateNewDisk == false); - do - { - if (CreateNewDisk) - { - DPRINT(MID_TRACE, ("Creating new disk 2.\n")); - CommitDisk(true); - CloseDisk(); - NewDisk(); - CreateNewDisk = false; + do + { + if (CreateNewDisk) + { + DPRINT(MID_TRACE, ("Creating new disk 2.\n")); + CommitDisk(true); + CloseDisk(); + NewDisk(); + CreateNewDisk = false; - ASSERT(FileNode == FileListHead); - } + ASSERT(FileNode == FileListHead); + } - if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) - { - Status = WriteDataBlock(); - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - } while (CreateNewDisk); - } - CommitDisk(MoreDisks); + if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) + { + Status = WriteDataBlock(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + } while (CreateNewDisk); + } + CommitDisk(MoreDisks); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1710,100 +1708,100 @@ ULONG CCabinet::CommitDisk(ULONG MoreDisks) * Status of operation */ { - PCFFOLDER_NODE FolderNode; - ULONG Status; + PCFFOLDER_NODE FolderNode; + ULONG Status; - OnCabinetName(CurrentDiskNumber, CabinetName); + OnCabinetName(CurrentDiskNumber, CabinetName); - /* Create file, fail if it already exists */ + /* Create file, fail if it already exists */ #if defined(WIN32) - FileHandle = CreateFile(CabinetName, // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - CREATE_NEW, // New file only - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - { - ULONG Status; - /* If file exists, ask to overwrite file */ - if (((Status = GetLastError()) == ERROR_FILE_EXISTS) && - (OnOverwrite(NULL, CabinetName))) - { + FileHandle = CreateFile(CabinetName, // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + CREATE_NEW, // New file only + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + { + ULONG Status; + /* If file exists, ask to overwrite file */ + if (((Status = GetLastError()) == ERROR_FILE_EXISTS) && + (OnOverwrite(NULL, CabinetName))) + { - /* Create cabinet file, overwrite if it already exists */ - FileHandle = CreateFile(CabinetName, // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - TRUNCATE_EXISTING, // Truncate the file - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - return CAB_STATUS_CANNOT_CREATE; - } - else - { - if (Status == ERROR_FILE_EXISTS) - return CAB_STATUS_FILE_EXISTS; - else - return CAB_STATUS_CANNOT_CREATE; - } - } + /* Create cabinet file, overwrite if it already exists */ + FileHandle = CreateFile(CabinetName, // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + TRUNCATE_EXISTING, // Truncate the file + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + return CAB_STATUS_CANNOT_CREATE; + } + else + { + if (Status == ERROR_FILE_EXISTS) + return CAB_STATUS_FILE_EXISTS; + else + return CAB_STATUS_CANNOT_CREATE; + } + } #else /* !WIN32 */ - FileHandle = fopen(CabinetName, "rb"); - if (FileHandle != NULL) - { - fclose(FileHandle); - /* If file exists, ask to overwrite file */ - if (OnOverwrite(NULL, CabinetName)) - { - FileHandle = fopen(CabinetName, "w+b"); - if (FileHandle == NULL) - return CAB_STATUS_CANNOT_CREATE; - } - else - return CAB_STATUS_FILE_EXISTS; + FileHandle = fopen(CabinetName, "rb"); + if (FileHandle != NULL) + { + fclose(FileHandle); + /* If file exists, ask to overwrite file */ + if (OnOverwrite(NULL, CabinetName)) + { + FileHandle = fopen(CabinetName, "w+b"); + if (FileHandle == NULL) + return CAB_STATUS_CANNOT_CREATE; + } + else + return CAB_STATUS_FILE_EXISTS; - } - else - { - FileHandle = fopen(CabinetName, "w+b"); - if (FileHandle == NULL) - return CAB_STATUS_CANNOT_CREATE; - } + } + else + { + FileHandle = fopen(CabinetName, "w+b"); + if (FileHandle == NULL) + return CAB_STATUS_CANNOT_CREATE; + } #endif - WriteCabinetHeader(MoreDisks != 0); + WriteCabinetHeader(MoreDisks != 0); - Status = WriteFolderEntries(); - if (Status != CAB_STATUS_SUCCESS) - return Status; + Status = WriteFolderEntries(); + if (Status != CAB_STATUS_SUCCESS) + return Status; - /* Write file entries */ - WriteFileEntries(); + /* Write file entries */ + WriteFileEntries(); - /* Write data blocks */ - FolderNode = FolderListHead; - while (FolderNode != NULL) - { - if (FolderNode->Commit) - { - Status = CommitDataBlocks(FolderNode); - if (Status != CAB_STATUS_SUCCESS) - return Status; - /* Remove data blocks for folder */ - DestroyDataNodes(FolderNode); - } - FolderNode = FolderNode->Next; - } + /* Write data blocks */ + FolderNode = FolderListHead; + while (FolderNode != NULL) + { + if (FolderNode->Commit) + { + Status = CommitDataBlocks(FolderNode); + if (Status != CAB_STATUS_SUCCESS) + return Status; + /* Remove data blocks for folder */ + DestroyDataNodes(FolderNode); + } + FolderNode = FolderNode->Next; + } - CloseFile(FileHandle); + CloseFile(FileHandle); - ScratchFile->Truncate(); + ScratchFile->Truncate(); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1814,14 +1812,14 @@ ULONG CCabinet::CloseDisk() * Status of operation */ { - DestroyDeletedFileNodes(); + DestroyDeletedFileNodes(); - /* Destroy folder nodes that are completely stored */ - DestroyDeletedFolderNodes(); + /* Destroy folder nodes that are completely stored */ + DestroyDeletedFolderNodes(); - CurrentDiskNumber++; + CurrentDiskNumber++; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1832,34 +1830,34 @@ ULONG CCabinet::CloseCabinet() * Status of operation */ { - ULONG Status; + ULONG Status; - DestroyFileNodes(); + DestroyFileNodes(); - DestroyFolderNodes(); + DestroyFolderNodes(); - if (InputBuffer) - { - FreeMemory(InputBuffer); - InputBuffer = NULL; - } + if (InputBuffer) + { + FreeMemory(InputBuffer); + InputBuffer = NULL; + } - if (OutputBuffer) - { - FreeMemory(OutputBuffer); - OutputBuffer = NULL; - } + if (OutputBuffer) + { + FreeMemory(OutputBuffer); + OutputBuffer = NULL; + } - Close(); + Close(); - if (ScratchFile) - { - Status = ScratchFile->Destroy(); - delete ScratchFile; - return Status; - } + if (ScratchFile) + { + Status = ScratchFile->Destroy(); + delete ScratchFile; + return Status; + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1872,72 +1870,72 @@ ULONG CCabinet::AddFile(char* FileName) * Status of operation */ { - FILEHANDLE SrcFile; - PCFFILE_NODE FileNode; - char* NewFileName; + FILEHANDLE SrcFile; + PCFFILE_NODE FileNode; + char* NewFileName; - NewFileName = (char*)AllocateMemory(strlen(FileName) + 1); - if (!NewFileName) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } - strcpy(NewFileName, FileName); - ConvertPath(NewFileName, false); + NewFileName = (char*)AllocateMemory(strlen(FileName) + 1); + if (!NewFileName) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } + strcpy(NewFileName, FileName); + ConvertPath(NewFileName, false); - /* Try to open file */ + /* Try to open file */ #if defined(WIN32) - SrcFile = CreateFile( - NewFileName, // Open this file - GENERIC_READ, // Open for reading - FILE_SHARE_READ, // Share for reading - NULL, // No security - OPEN_EXISTING, // File must exist - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (SrcFile == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("File not found (%s).\n", NewFileName)); - FreeMemory(NewFileName); - return CAB_STATUS_CANNOT_OPEN; - } + SrcFile = CreateFile( + NewFileName, // Open this file + GENERIC_READ, // Open for reading + FILE_SHARE_READ, // Share for reading + NULL, // No security + OPEN_EXISTING, // File must exist + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (SrcFile == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("File not found (%s).\n", NewFileName)); + FreeMemory(NewFileName); + return CAB_STATUS_CANNOT_OPEN; + } #else /* !WIN32 */ - SrcFile = fopen(NewFileName, "rb"); - if (SrcFile == NULL) - { - DPRINT(MID_TRACE, ("File not found (%s).\n", NewFileName)); - FreeMemory(NewFileName); - return CAB_STATUS_CANNOT_OPEN; - } + SrcFile = fopen(NewFileName, "rb"); + if (SrcFile == NULL) + { + DPRINT(MID_TRACE, ("File not found (%s).\n", NewFileName)); + FreeMemory(NewFileName); + return CAB_STATUS_CANNOT_OPEN; + } #endif - FileNode = NewFileNode(); - if (!FileNode) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - FreeMemory(NewFileName); - return CAB_STATUS_NOMEMORY; - } + FileNode = NewFileNode(); + if (!FileNode) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + FreeMemory(NewFileName); + return CAB_STATUS_NOMEMORY; + } - FileNode->FolderNode = CurrentFolderNode; - FileNode->FileName = NewFileName; + FileNode->FolderNode = CurrentFolderNode; + FileNode->FileName = NewFileName; - /* FIXME: Check for and handle large files (>= 2GB) */ - FileNode->File.FileSize = GetSizeOfFile(SrcFile); - if (FileNode->File.FileSize == (ULONG)-1) - { - DPRINT(MIN_TRACE, ("Cannot read from file.\n")); - FreeMemory(NewFileName); - return CAB_STATUS_CANNOT_READ; - } + /* FIXME: Check for and handle large files (>= 2GB) */ + FileNode->File.FileSize = GetSizeOfFile(SrcFile); + if (FileNode->File.FileSize == (ULONG)-1) + { + DPRINT(MIN_TRACE, ("Cannot read from file.\n")); + FreeMemory(NewFileName); + return CAB_STATUS_CANNOT_READ; + } - GetFileTimes(SrcFile, FileNode); + GetFileTimes(SrcFile, FileNode); - GetAttributesOnFile(FileNode); + GetAttributesOnFile(FileNode); - CloseFile(SrcFile); + CloseFile(SrcFile); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -1948,7 +1946,7 @@ void CCabinet::SetMaxDiskSize(ULONG Size) * Size = Maximum size of current disk (0 means no maximum size) */ { - MaxDiskSize = Size; + MaxDiskSize = Size; } #endif /* CAB_READ_ONLY */ @@ -1967,7 +1965,7 @@ bool CCabinet::OnOverwrite(PCFFILE File, * true if the file should be overwritten, false if not */ { - return false; + return false; } @@ -2019,7 +2017,7 @@ bool CCabinet::OnDiskLabel(ULONG Number, char* Label) * true if a disk label was returned, false if not */ { - return false; + return false; } @@ -2033,7 +2031,7 @@ bool CCabinet::OnCabinetName(ULONG Number, char* Name) * true if a cabinet name was returned, false if not */ { - return false; + return false; } #endif /* CAB_READ_ONLY */ @@ -2047,26 +2045,26 @@ PCFFOLDER_NODE CCabinet::LocateFolderNode(ULONG Index) * Pointer to folder node or NULL if the folder node was not found */ { - PCFFOLDER_NODE Node; + PCFFOLDER_NODE Node; - switch (Index) - { - case CAB_FILE_SPLIT: - return FolderListTail; + switch (Index) + { + case CAB_FILE_SPLIT: + return FolderListTail; - case CAB_FILE_CONTINUED: - case CAB_FILE_PREV_NEXT: - return FolderListHead; - } + case CAB_FILE_CONTINUED: + case CAB_FILE_PREV_NEXT: + return FolderListHead; + } - Node = FolderListHead; - while (Node != NULL) - { - if (Node->Index == Index) - return Node; - Node = Node->Next; - } - return NULL; + Node = FolderListHead; + while (Node != NULL) + { + if (Node->Index == Index) + return Node; + Node = Node->Next; + } + return NULL; } @@ -2079,35 +2077,35 @@ ULONG CCabinet::GetAbsoluteOffset(PCFFILE_NODE File) * Status of operation */ { - PCFDATA_NODE Node; + PCFDATA_NODE Node; - DPRINT(MAX_TRACE, ("FileName '%s' FileOffset (0x%lX) FileSize (%lu).\n", - (char*)File->FileName, - (ULONG)File->File.FileOffset, - (ULONG)File->File.FileSize)); + DPRINT(MAX_TRACE, ("FileName '%s' FileOffset (0x%lX) FileSize (%lu).\n", + (char*)File->FileName, + (ULONG)File->File.FileOffset, + (ULONG)File->File.FileSize)); - Node = CurrentFolderNode->DataListHead; - while (Node != NULL) - { - DPRINT(MAX_TRACE, ("GetAbsoluteOffset(): Comparing (0x%lX, 0x%lX) (%lu).\n", - (ULONG)Node->UncompOffset, - (ULONG)Node->UncompOffset + Node->Data.UncompSize, - (ULONG)Node->Data.UncompSize)); + Node = CurrentFolderNode->DataListHead; + while (Node != NULL) + { + DPRINT(MAX_TRACE, ("GetAbsoluteOffset(): Comparing (0x%lX, 0x%lX) (%lu).\n", + (ULONG)Node->UncompOffset, + (ULONG)Node->UncompOffset + Node->Data.UncompSize, + (ULONG)Node->Data.UncompSize)); - /* Node->Data.UncompSize will be 0 if the block is split - (ie. it is the last block in this cabinet) */ - if ((Node->Data.UncompSize == 0) || - ((File->File.FileOffset >= Node->UncompOffset) && - (File->File.FileOffset < Node->UncompOffset + - Node->Data.UncompSize))) - { - File->DataBlock = Node; - return CAB_STATUS_SUCCESS; - } + /* Node->Data.UncompSize will be 0 if the block is split + (ie. it is the last block in this cabinet) */ + if ((Node->Data.UncompSize == 0) || + ((File->File.FileOffset >= Node->UncompOffset) && + (File->File.FileOffset < Node->UncompOffset + + Node->Data.UncompSize))) + { + File->DataBlock = Node; + return CAB_STATUS_SUCCESS; + } - Node = Node->Next; - } - return CAB_STATUS_INVALID_CAB; + Node = Node->Next; + } + return CAB_STATUS_INVALID_CAB; } @@ -2124,35 +2122,35 @@ ULONG CCabinet::LocateFile(char* FileName, * Current folder is set to the folder of the file */ { - PCFFILE_NODE Node; - ULONG Status; + PCFFILE_NODE Node; + ULONG Status; - DPRINT(MAX_TRACE, ("FileName '%s'\n", FileName)); + DPRINT(MAX_TRACE, ("FileName '%s'\n", FileName)); - Node = FileListHead; - while (Node != NULL) - { - if (strcasecmp(FileName, Node->FileName) == 0) - { - CurrentFolderNode = LocateFolderNode(Node->File.FileControlID); - if (!CurrentFolderNode) - { - DPRINT(MID_TRACE, ("Folder with index number (%lu) not found.\n", - (ULONG)Node->File.FileControlID)); - return CAB_STATUS_INVALID_CAB; - } + Node = FileListHead; + while (Node != NULL) + { + if (strcasecmp(FileName, Node->FileName) == 0) + { + CurrentFolderNode = LocateFolderNode(Node->File.FileControlID); + if (!CurrentFolderNode) + { + DPRINT(MID_TRACE, ("Folder with index number (%lu) not found.\n", + (ULONG)Node->File.FileControlID)); + return CAB_STATUS_INVALID_CAB; + } - if (Node->DataBlock == NULL) - Status = GetAbsoluteOffset(Node); - else - Status = CAB_STATUS_SUCCESS; + if (Node->DataBlock == NULL) + Status = GetAbsoluteOffset(Node); + else + Status = CAB_STATUS_SUCCESS; - *File = Node; - return Status; - } - Node = Node->Next; - } - return CAB_STATUS_NOFILE; + *File = Node; + return Status; + } + Node = Node->Next; + } + return CAB_STATUS_NOFILE; } @@ -2166,65 +2164,65 @@ ULONG CCabinet::ReadString(char* String, ULONG MaxLength) * Status of operation */ { - ULONG BytesRead; - ULONG Offset; - ULONG Status; - ULONG Size; - bool Found; + ULONG BytesRead; + ULONG Offset; + ULONG Status; + ULONG Size; + bool Found; - Offset = 0; - Found = false; - do - { - Size = ((Offset + 32) <= MaxLength)? 32 : MaxLength - Offset; + Offset = 0; + Found = false; + do + { + Size = ((Offset + 32) <= MaxLength)? 32 : MaxLength - Offset; - if (Size == 0) - { - DPRINT(MIN_TRACE, ("Too long a filename.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (Size == 0) + { + DPRINT(MIN_TRACE, ("Too long a filename.\n")); + return CAB_STATUS_INVALID_CAB; + } - Status = ReadBlock(&String[Offset], Size, &BytesRead); - if ((Status != CAB_STATUS_SUCCESS) || (BytesRead != Size)) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + Status = ReadBlock(&String[Offset], Size, &BytesRead); + if ((Status != CAB_STATUS_SUCCESS) || (BytesRead != Size)) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - for (Size = Offset; Size < Offset + BytesRead; Size++) - { - if (String[Size] == '\0') - { - Found = true; - break; - } - } + for (Size = Offset; Size < Offset + BytesRead; Size++) + { + if (String[Size] == '\0') + { + Found = true; + break; + } + } - Offset += BytesRead; + Offset += BytesRead; - } while (!Found); + } while (!Found); - /* Back up some bytes */ - Size = (BytesRead - Size) - 1; + /* Back up some bytes */ + Size = (BytesRead - Size) - 1; #if defined(WIN32) - SetLastError(NO_ERROR); - (ULONG)SetFilePointer(FileHandle, - -(LONG)Size, - NULL, - FILE_CURRENT); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + SetLastError(NO_ERROR); + (ULONG)SetFilePointer(FileHandle, + -(LONG)Size, + NULL, + FILE_CURRENT); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)(-(LONG)Size), SEEK_CUR) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (fseek(FileHandle, (off_t)(-(LONG)Size), SEEK_CUR) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -2235,71 +2233,71 @@ ULONG CCabinet::ReadFileTable() * Status of operation */ { - ULONG i; - ULONG Status; - ULONG BytesRead; - PCFFILE_NODE File; + ULONG i; + ULONG Status; + ULONG BytesRead; + PCFFILE_NODE File; - DPRINT(MAX_TRACE, ("Reading file table at absolute offset (0x%lX).\n", - CABHeader.FileTableOffset)); + DPRINT(MAX_TRACE, ("Reading file table at absolute offset (0x%lX).\n", + CABHeader.FileTableOffset)); - /* Seek to file table */ + /* Seek to file table */ #if defined(WIN32) - SetLastError(NO_ERROR); - SetFilePointer(FileHandle, - CABHeader.FileTableOffset, - NULL, - FILE_BEGIN); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - DPRINT(MIN_TRACE, ("Error: %lu\n", GetLastError())); - return CAB_STATUS_INVALID_CAB; - } + SetLastError(NO_ERROR); + SetFilePointer(FileHandle, + CABHeader.FileTableOffset, + NULL, + FILE_BEGIN); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + DPRINT(MIN_TRACE, ("Error: %lu\n", GetLastError())); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)CABHeader.FileTableOffset, SEEK_SET) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (fseek(FileHandle, (off_t)CABHeader.FileTableOffset, SEEK_SET) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #endif - for (i = 0; i < CABHeader.FileCount; i++) - { - File = NewFileNode(); - if (!File) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + for (i = 0; i < CABHeader.FileCount; i++) + { + File = NewFileNode(); + if (!File) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - if ((Status = ReadBlock(&File->File, sizeof(CFFILE), - &BytesRead)) != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + if ((Status = ReadBlock(&File->File, sizeof(CFFILE), + &BytesRead)) != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - File->FileName = (char*)AllocateMemory(MAX_PATH); - if (!File->FileName) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + File->FileName = (char*)AllocateMemory(MAX_PATH); + if (!File->FileName) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - /* Read file name */ - Status = ReadString(File->FileName, MAX_PATH); - if (Status != CAB_STATUS_SUCCESS) - return Status; + /* Read file name */ + Status = ReadString(File->FileName, MAX_PATH); + if (Status != CAB_STATUS_SUCCESS) + return Status; - DPRINT(MAX_TRACE, ("Found file '%s' at uncompressed offset (0x%lX). Size (%lu bytes) ControlId (0x%lX).\n", - (char*)File->FileName, - (ULONG)File->File.FileOffset, - (ULONG)File->File.FileSize, - (ULONG)File->File.FileControlID)); + DPRINT(MAX_TRACE, ("Found file '%s' at uncompressed offset (0x%lX). Size (%lu bytes) ControlId (0x%lX).\n", + (char*)File->FileName, + (ULONG)File->File.FileOffset, + (ULONG)File->File.FileSize, + (ULONG)File->File.FileControlID)); - } - return CAB_STATUS_SUCCESS; + } + return CAB_STATUS_SUCCESS; } @@ -2312,72 +2310,72 @@ ULONG CCabinet::ReadDataBlocks(PCFFOLDER_NODE FolderNode) * Status of operation */ { - ULONG AbsoluteOffset; - ULONG UncompOffset; - PCFDATA_NODE Node; - ULONG BytesRead; - ULONG Status; - ULONG i; + ULONG AbsoluteOffset; + ULONG UncompOffset; + PCFDATA_NODE Node; + ULONG BytesRead; + ULONG Status; + ULONG i; - DPRINT(MAX_TRACE, ("Reading data blocks for folder (%lu) at absolute offset (0x%lX).\n", - FolderNode->Index, FolderNode->Folder.DataOffset)); + DPRINT(MAX_TRACE, ("Reading data blocks for folder (%lu) at absolute offset (0x%lX).\n", + FolderNode->Index, FolderNode->Folder.DataOffset)); - AbsoluteOffset = FolderNode->Folder.DataOffset; - UncompOffset = FolderNode->UncompOffset; + AbsoluteOffset = FolderNode->Folder.DataOffset; + UncompOffset = FolderNode->UncompOffset; - for (i = 0; i < FolderNode->Folder.DataBlockCount; i++) - { - Node = NewDataNode(FolderNode); - if (!Node) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + for (i = 0; i < FolderNode->Folder.DataBlockCount; i++) + { + Node = NewDataNode(FolderNode); + if (!Node) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - /* Seek to data block */ + /* Seek to data block */ #if defined(WIN32) - SetLastError(NO_ERROR); - SetFilePointer(FileHandle, - AbsoluteOffset, - NULL, - FILE_BEGIN); - if (GetLastError() != NO_ERROR) - { - DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + SetLastError(NO_ERROR); + SetFilePointer(FileHandle, + AbsoluteOffset, + NULL, + FILE_BEGIN); + if (GetLastError() != NO_ERROR) + { + DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #else - if (fseek(FileHandle, (off_t)AbsoluteOffset, SEEK_SET) != 0) - { - DPRINT(MIN_TRACE, ("fseek() failed.\n")); - return CAB_STATUS_INVALID_CAB; - } + if (fseek(FileHandle, (off_t)AbsoluteOffset, SEEK_SET) != 0) + { + DPRINT(MIN_TRACE, ("fseek() failed.\n")); + return CAB_STATUS_INVALID_CAB; + } #endif - if ((Status = ReadBlock(&Node->Data, sizeof(CFDATA), - &BytesRead)) != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); - return CAB_STATUS_INVALID_CAB; - } + if ((Status = ReadBlock(&Node->Data, sizeof(CFDATA), + &BytesRead)) != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from file (%lu).\n", (ULONG)Status)); + return CAB_STATUS_INVALID_CAB; + } - DPRINT(MAX_TRACE, ("AbsOffset (0x%lX) UncompOffset (0x%lX) Checksum (0x%lX) CompSize (%lu) UncompSize (%lu).\n", - (ULONG)AbsoluteOffset, - (ULONG)UncompOffset, - (ULONG)Node->Data.Checksum, - (ULONG)Node->Data.CompSize, - (ULONG)Node->Data.UncompSize)); + DPRINT(MAX_TRACE, ("AbsOffset (0x%lX) UncompOffset (0x%lX) Checksum (0x%lX) CompSize (%lu) UncompSize (%lu).\n", + (ULONG)AbsoluteOffset, + (ULONG)UncompOffset, + (ULONG)Node->Data.Checksum, + (ULONG)Node->Data.CompSize, + (ULONG)Node->Data.UncompSize)); - Node->AbsoluteOffset = AbsoluteOffset; - Node->UncompOffset = UncompOffset; + Node->AbsoluteOffset = AbsoluteOffset; + Node->UncompOffset = UncompOffset; - AbsoluteOffset += sizeof(CFDATA) + Node->Data.CompSize; - UncompOffset += Node->Data.UncompSize; - } + AbsoluteOffset += sizeof(CFDATA) + Node->Data.CompSize; + UncompOffset += Node->Data.UncompSize; + } - FolderUncompSize = UncompOffset; + FolderUncompSize = UncompOffset; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -2388,26 +2386,26 @@ PCFFOLDER_NODE CCabinet::NewFolderNode() * Pointer to node if there was enough free memory available, otherwise NULL */ { - PCFFOLDER_NODE Node; + PCFFOLDER_NODE Node; - Node = (PCFFOLDER_NODE)AllocateMemory(sizeof(CFFOLDER_NODE)); - if (!Node) - return NULL; + Node = (PCFFOLDER_NODE)AllocateMemory(sizeof(CFFOLDER_NODE)); + if (!Node) + return NULL; - memset(Node, 0, sizeof(CFFOLDER_NODE)); + memset(Node, 0, sizeof(CFFOLDER_NODE)); - Node->Folder.CompressionType = CAB_COMP_NONE; + Node->Folder.CompressionType = CAB_COMP_NONE; - Node->Prev = FolderListTail; + Node->Prev = FolderListTail; - if (FolderListTail != NULL) - FolderListTail->Next = Node; - else - FolderListHead = Node; + if (FolderListTail != NULL) + FolderListTail->Next = Node; + else + FolderListHead = Node; - FolderListTail = Node; + FolderListTail = Node; - return Node; + return Node; } @@ -2420,24 +2418,24 @@ PCFFILE_NODE CCabinet::NewFileNode() * Pointer to node if there was enough free memory available, otherwise NULL */ { - PCFFILE_NODE Node; + PCFFILE_NODE Node; - Node = (PCFFILE_NODE)AllocateMemory(sizeof(CFFILE_NODE)); - if (!Node) - return NULL; + Node = (PCFFILE_NODE)AllocateMemory(sizeof(CFFILE_NODE)); + if (!Node) + return NULL; - memset(Node, 0, sizeof(CFFILE_NODE)); + memset(Node, 0, sizeof(CFFILE_NODE)); - Node->Prev = FileListTail; + Node->Prev = FileListTail; - if (FileListTail != NULL) - FileListTail->Next = Node; - else - FileListHead = Node; + if (FileListTail != NULL) + FileListTail->Next = Node; + else + FileListHead = Node; - FileListTail = Node; + FileListTail = Node; - return Node; + return Node; } @@ -2450,24 +2448,24 @@ PCFDATA_NODE CCabinet::NewDataNode(PCFFOLDER_NODE FolderNode) * Pointer to node if there was enough free memory available, otherwise NULL */ { - PCFDATA_NODE Node; + PCFDATA_NODE Node; - Node = (PCFDATA_NODE)AllocateMemory(sizeof(CFDATA_NODE)); - if (!Node) - return NULL; + Node = (PCFDATA_NODE)AllocateMemory(sizeof(CFDATA_NODE)); + if (!Node) + return NULL; - memset(Node, 0, sizeof(CFDATA_NODE)); + memset(Node, 0, sizeof(CFDATA_NODE)); - Node->Prev = FolderNode->DataListTail; + Node->Prev = FolderNode->DataListTail; - if (FolderNode->DataListTail != NULL) - FolderNode->DataListTail->Next = Node; - else - FolderNode->DataListHead = Node; + if (FolderNode->DataListTail != NULL) + FolderNode->DataListTail->Next = Node; + else + FolderNode->DataListHead = Node; - FolderNode->DataListTail = Node; + FolderNode->DataListTail = Node; - return Node; + return Node; } @@ -2478,18 +2476,18 @@ void CCabinet::DestroyDataNodes(PCFFOLDER_NODE FolderNode) * FolderNode = Pointer to folder node */ { - PCFDATA_NODE PrevNode; - PCFDATA_NODE NextNode; + PCFDATA_NODE PrevNode; + PCFDATA_NODE NextNode; - NextNode = FolderNode->DataListHead; - while (NextNode != NULL) - { - PrevNode = NextNode->Next; - FreeMemory(NextNode); - NextNode = PrevNode; - } - FolderNode->DataListHead = NULL; - FolderNode->DataListTail = NULL; + NextNode = FolderNode->DataListHead; + while (NextNode != NULL) + { + PrevNode = NextNode->Next; + FreeMemory(NextNode); + NextNode = PrevNode; + } + FolderNode->DataListHead = NULL; + FolderNode->DataListTail = NULL; } @@ -2500,20 +2498,20 @@ void CCabinet::DestroyFileNodes() * FolderNode = Pointer to folder node */ { - PCFFILE_NODE PrevNode; - PCFFILE_NODE NextNode; + PCFFILE_NODE PrevNode; + PCFFILE_NODE NextNode; - NextNode = FileListHead; - while (NextNode != NULL) - { - PrevNode = NextNode->Next; - if (NextNode->FileName) - FreeMemory(NextNode->FileName); - FreeMemory(NextNode); - NextNode = PrevNode; - } - FileListHead = NULL; - FileListTail = NULL; + NextNode = FileListHead; + while (NextNode != NULL) + { + PrevNode = NextNode->Next; + if (NextNode->FileName) + FreeMemory(NextNode->FileName); + FreeMemory(NextNode); + NextNode = PrevNode; + } + FileListHead = NULL; + FileListTail = NULL; } @@ -2522,44 +2520,44 @@ void CCabinet::DestroyDeletedFileNodes() * FUNCTION: Destroys file nodes that are marked for deletion */ { - PCFFILE_NODE CurNode; - PCFFILE_NODE NextNode; + PCFFILE_NODE CurNode; + PCFFILE_NODE NextNode; - CurNode = FileListHead; - while (CurNode != NULL) - { - NextNode = CurNode->Next; + CurNode = FileListHead; + while (CurNode != NULL) + { + NextNode = CurNode->Next; - if (CurNode->Delete) - { - if (CurNode->Prev != NULL) - CurNode->Prev->Next = CurNode->Next; - else - { - FileListHead = CurNode->Next; - if (FileListHead) - FileListHead->Prev = NULL; - } + if (CurNode->Delete) + { + if (CurNode->Prev != NULL) + CurNode->Prev->Next = CurNode->Next; + else + { + FileListHead = CurNode->Next; + if (FileListHead) + FileListHead->Prev = NULL; + } - if (CurNode->Next != NULL) - CurNode->Next->Prev = CurNode->Prev; - else - { - FileListTail = CurNode->Prev; - if (FileListTail) - FileListTail->Next = NULL; - } + if (CurNode->Next != NULL) + CurNode->Next->Prev = CurNode->Prev; + else + { + FileListTail = CurNode->Prev; + if (FileListTail) + FileListTail->Next = NULL; + } - DPRINT(MAX_TRACE, ("Deleting file: '%s'\n", CurNode->FileName)); + DPRINT(MAX_TRACE, ("Deleting file: '%s'\n", CurNode->FileName)); - TotalFileSize -= (sizeof(CFFILE) + (ULONG)strlen(GetFileName(CurNode->FileName)) + 1); + TotalFileSize -= (sizeof(CFFILE) + (ULONG)strlen(GetFileName(CurNode->FileName)) + 1); - if (CurNode->FileName) - FreeMemory(CurNode->FileName); - FreeMemory(CurNode); - } - CurNode = NextNode; - } + if (CurNode->FileName) + FreeMemory(CurNode->FileName); + FreeMemory(CurNode); + } + CurNode = NextNode; + } } @@ -2568,19 +2566,19 @@ void CCabinet::DestroyFolderNodes() * FUNCTION: Destroys folder nodes */ { - PCFFOLDER_NODE PrevNode; - PCFFOLDER_NODE NextNode; + PCFFOLDER_NODE PrevNode; + PCFFOLDER_NODE NextNode; - NextNode = FolderListHead; - while (NextNode != NULL) - { - PrevNode = NextNode->Next; - DestroyDataNodes(NextNode); - FreeMemory(NextNode); - NextNode = PrevNode; - } - FolderListHead = NULL; - FolderListTail = NULL; + NextNode = FolderListHead; + while (NextNode != NULL) + { + PrevNode = NextNode->Next; + DestroyDataNodes(NextNode); + FreeMemory(NextNode); + NextNode = PrevNode; + } + FolderListHead = NULL; + FolderListTail = NULL; } @@ -2589,41 +2587,41 @@ void CCabinet::DestroyDeletedFolderNodes() * FUNCTION: Destroys folder nodes that are marked for deletion */ { - PCFFOLDER_NODE CurNode; - PCFFOLDER_NODE NextNode; + PCFFOLDER_NODE CurNode; + PCFFOLDER_NODE NextNode; - CurNode = FolderListHead; - while (CurNode != NULL) - { - NextNode = CurNode->Next; + CurNode = FolderListHead; + while (CurNode != NULL) + { + NextNode = CurNode->Next; - if (CurNode->Delete) - { - if (CurNode->Prev != NULL) - CurNode->Prev->Next = CurNode->Next; - else - { - FolderListHead = CurNode->Next; - if (FolderListHead) - FolderListHead->Prev = NULL; - } + if (CurNode->Delete) + { + if (CurNode->Prev != NULL) + CurNode->Prev->Next = CurNode->Next; + else + { + FolderListHead = CurNode->Next; + if (FolderListHead) + FolderListHead->Prev = NULL; + } - if (CurNode->Next != NULL) - CurNode->Next->Prev = CurNode->Prev; - else - { - FolderListTail = CurNode->Prev; - if (FolderListTail) - FolderListTail->Next = NULL; - } + if (CurNode->Next != NULL) + CurNode->Next->Prev = CurNode->Prev; + else + { + FolderListTail = CurNode->Prev; + if (FolderListTail) + FolderListTail->Next = NULL; + } - DestroyDataNodes(CurNode); - FreeMemory(CurNode); + DestroyDataNodes(CurNode); + FreeMemory(CurNode); - TotalFolderSize -= sizeof(CFFOLDER); - } - CurNode = NextNode; - } + TotalFolderSize -= sizeof(CFFOLDER); + } + CurNode = NextNode; + } } @@ -2640,49 +2638,49 @@ ULONG CCabinet::ComputeChecksum(void* Buffer, * Checksum of buffer */ { - int UlongCount; // Number of ULONGs in block - ULONG Checksum; // Checksum accumulator - unsigned char* pb; - ULONG ul; + int UlongCount; // Number of ULONGs in block + ULONG Checksum; // Checksum accumulator + unsigned char* pb; + ULONG ul; - /* FIXME: Doesn't seem to be correct. EXTRACT.EXE - won't accept checksums computed by this routine */ + /* FIXME: Doesn't seem to be correct. EXTRACT.EXE + won't accept checksums computed by this routine */ - DPRINT(MIN_TRACE, ("Checksumming buffer (0x%p) Size (%lu)\n", Buffer, Size)); + DPRINT(MIN_TRACE, ("Checksumming buffer (0x%p) Size (%lu)\n", Buffer, Size)); - UlongCount = Size / 4; // Number of ULONGs - Checksum = Seed; // Init checksum - pb = (unsigned char*)Buffer; // Start at front of data block + UlongCount = Size / 4; // Number of ULONGs + Checksum = Seed; // Init checksum + pb = (unsigned char*)Buffer; // Start at front of data block - /* Checksum integral multiple of ULONGs */ - while (UlongCount-- > 0) - { - /* NOTE: Build ULONG in big/little-endian independent manner */ - ul = *pb++; // Get low-order byte - ul |= (((ULONG)(*pb++)) << 8); // Add 2nd byte - ul |= (((ULONG)(*pb++)) << 16); // Add 3nd byte - ul |= (((ULONG)(*pb++)) << 24); // Add 4th byte + /* Checksum integral multiple of ULONGs */ + while (UlongCount-- > 0) + { + /* NOTE: Build ULONG in big/little-endian independent manner */ + ul = *pb++; // Get low-order byte + ul |= (((ULONG)(*pb++)) << 8); // Add 2nd byte + ul |= (((ULONG)(*pb++)) << 16); // Add 3nd byte + ul |= (((ULONG)(*pb++)) << 24); // Add 4th byte - Checksum ^= ul; // Update checksum - } + Checksum ^= ul; // Update checksum + } - /* Checksum remainder bytes */ - ul = 0; - switch (Size % 4) - { - case 3: - ul |= (((ULONG)(*pb++)) << 16); // Add 3rd byte - case 2: - ul |= (((ULONG)(*pb++)) << 8); // Add 2nd byte - case 1: - ul |= *pb++; // Get low-order byte - default: - break; - } - Checksum ^= ul; // Update checksum + /* Checksum remainder bytes */ + ul = 0; + switch (Size % 4) + { + case 3: + ul |= (((ULONG)(*pb++)) << 16); // Add 3rd byte + case 2: + ul |= (((ULONG)(*pb++)) << 8); // Add 2nd byte + case 1: + ul |= *pb++; // Get low-order byte + default: + break; + } + Checksum ^= ul; // Update checksum - /* Return computed checksum */ - return Checksum; + /* Return computed checksum */ + return Checksum; } @@ -2700,9 +2698,9 @@ ULONG CCabinet::ReadBlock(void* Buffer, * Status of operation */ { - if (!ReadFileData(FileHandle, Buffer, Size, BytesRead)) - return CAB_STATUS_INVALID_CAB; - return CAB_STATUS_SUCCESS; + if (!ReadFileData(FileHandle, Buffer, Size, BytesRead)) + return CAB_STATUS_INVALID_CAB; + return CAB_STATUS_SUCCESS; } #ifndef CAB_READ_ONLY @@ -2714,75 +2712,75 @@ ULONG CCabinet::InitCabinetHeader() * Status of operation */ { - ULONG TotalSize; - ULONG Size; + ULONG TotalSize; + ULONG Size; - CABHeader.FileTableOffset = 0; // Not known yet - CABHeader.FolderCount = 0; // Not known yet - CABHeader.FileCount = 0; // Not known yet - CABHeader.Flags = 0; // Not known yet + CABHeader.FileTableOffset = 0; // Not known yet + CABHeader.FolderCount = 0; // Not known yet + CABHeader.FileCount = 0; // Not known yet + CABHeader.Flags = 0; // Not known yet - CABHeader.CabinetNumber = (USHORT)CurrentDiskNumber; + CABHeader.CabinetNumber = (USHORT)CurrentDiskNumber; - if ((CurrentDiskNumber > 0) && (OnCabinetName(PrevCabinetNumber, CabinetPrev))) - { - CABHeader.Flags |= CAB_FLAG_HASPREV; - if (!OnDiskLabel(PrevCabinetNumber, DiskPrev)) - strcpy(CabinetPrev, ""); - } + if ((CurrentDiskNumber > 0) && (OnCabinetName(PrevCabinetNumber, CabinetPrev))) + { + CABHeader.Flags |= CAB_FLAG_HASPREV; + if (!OnDiskLabel(PrevCabinetNumber, DiskPrev)) + strcpy(CabinetPrev, ""); + } - if (OnCabinetName(CurrentDiskNumber + 1, CabinetNext)) - { - CABHeader.Flags |= CAB_FLAG_HASNEXT; - if (!OnDiskLabel(CurrentDiskNumber + 1, DiskNext)) - strcpy(DiskNext, ""); - } + if (OnCabinetName(CurrentDiskNumber + 1, CabinetNext)) + { + CABHeader.Flags |= CAB_FLAG_HASNEXT; + if (!OnDiskLabel(CurrentDiskNumber + 1, DiskNext)) + strcpy(DiskNext, ""); + } - TotalSize = 0; + TotalSize = 0; - if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) - { + if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) + { - DPRINT(MAX_TRACE, ("CabinetPrev '%s'.\n", CabinetPrev)); + DPRINT(MAX_TRACE, ("CabinetPrev '%s'.\n", CabinetPrev)); - /* Calculate size of name of previous cabinet */ - TotalSize += (ULONG)strlen(CabinetPrev) + 1; + /* Calculate size of name of previous cabinet */ + TotalSize += (ULONG)strlen(CabinetPrev) + 1; - /* Calculate size of label of previous disk */ - TotalSize += (ULONG)strlen(DiskPrev) + 1; - } + /* Calculate size of label of previous disk */ + TotalSize += (ULONG)strlen(DiskPrev) + 1; + } - if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) - { + if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) + { - DPRINT(MAX_TRACE, ("CabinetNext '%s'.\n", CabinetNext)); + DPRINT(MAX_TRACE, ("CabinetNext '%s'.\n", CabinetNext)); - /* Calculate size of name of next cabinet */ - Size = (ULONG)strlen(CabinetNext) + 1; - TotalSize += Size; - NextFieldsSize = Size; + /* Calculate size of name of next cabinet */ + Size = (ULONG)strlen(CabinetNext) + 1; + TotalSize += Size; + NextFieldsSize = Size; - /* Calculate size of label of next disk */ - Size = (ULONG)strlen(DiskNext) + 1; - TotalSize += Size; - NextFieldsSize += Size; - } - else - NextFieldsSize = 0; + /* Calculate size of label of next disk */ + Size = (ULONG)strlen(DiskNext) + 1; + TotalSize += Size; + NextFieldsSize += Size; + } + else + NextFieldsSize = 0; - /* Add cabinet reserved area size if present */ - if (CabinetReservedFileSize > 0) - { - CABHeader.Flags |= CAB_FLAG_RESERVE; - TotalSize += CabinetReservedFileSize; - TotalSize += sizeof(ULONG); /* For CabinetResSize, FolderResSize, and FileResSize fields */ - } + /* Add cabinet reserved area size if present */ + if (CabinetReservedFileSize > 0) + { + CABHeader.Flags |= CAB_FLAG_RESERVE; + TotalSize += CabinetReservedFileSize; + TotalSize += sizeof(ULONG); /* For CabinetResSize, FolderResSize, and FileResSize fields */ + } - DiskSize += TotalSize; + DiskSize += TotalSize; - TotalHeaderSize = sizeof(CFHEADER) + TotalSize; + TotalHeaderSize = sizeof(CFHEADER) + TotalSize; - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -2795,191 +2793,191 @@ ULONG CCabinet::WriteCabinetHeader(bool MoreDisks) * Status of operation */ { - PCFFOLDER_NODE FolderNode; - PCFFILE_NODE FileNode; - ULONG BytesWritten; - ULONG Size; + PCFFOLDER_NODE FolderNode; + PCFFILE_NODE FileNode; + ULONG BytesWritten; + ULONG Size; - if (MoreDisks) - { - CABHeader.Flags |= CAB_FLAG_HASNEXT; - Size = TotalHeaderSize; - } - else - { - CABHeader.Flags &= ~CAB_FLAG_HASNEXT; - DiskSize -= NextFieldsSize; - Size = TotalHeaderSize - NextFieldsSize; - } + if (MoreDisks) + { + CABHeader.Flags |= CAB_FLAG_HASNEXT; + Size = TotalHeaderSize; + } + else + { + CABHeader.Flags &= ~CAB_FLAG_HASNEXT; + DiskSize -= NextFieldsSize; + Size = TotalHeaderSize - NextFieldsSize; + } - /* Set absolute folder offsets */ - BytesWritten = Size + TotalFolderSize + TotalFileSize; - CABHeader.FolderCount = 0; - FolderNode = FolderListHead; - while (FolderNode != NULL) - { - FolderNode->Folder.DataOffset = BytesWritten; + /* Set absolute folder offsets */ + BytesWritten = Size + TotalFolderSize + TotalFileSize; + CABHeader.FolderCount = 0; + FolderNode = FolderListHead; + while (FolderNode != NULL) + { + FolderNode->Folder.DataOffset = BytesWritten; - BytesWritten += FolderNode->TotalFolderSize; + BytesWritten += FolderNode->TotalFolderSize; - CABHeader.FolderCount++; + CABHeader.FolderCount++; - FolderNode = FolderNode->Next; - } + FolderNode = FolderNode->Next; + } - /* Set absolute offset of file table */ - CABHeader.FileTableOffset = Size + TotalFolderSize; + /* Set absolute offset of file table */ + CABHeader.FileTableOffset = Size + TotalFolderSize; - /* Count number of files to be committed */ - CABHeader.FileCount = 0; - FileNode = FileListHead; - while (FileNode != NULL) - { - if (FileNode->Commit) - CABHeader.FileCount++; - FileNode = FileNode->Next; - } + /* Count number of files to be committed */ + CABHeader.FileCount = 0; + FileNode = FileListHead; + while (FileNode != NULL) + { + if (FileNode->Commit) + CABHeader.FileCount++; + FileNode = FileNode->Next; + } - CABHeader.CabinetSize = DiskSize; + CABHeader.CabinetSize = DiskSize; - /* Write header */ + /* Write header */ #if defined(WIN32) - if (!WriteFile(FileHandle, &CABHeader, sizeof(CFHEADER), (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, &CABHeader, sizeof(CFHEADER), (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = sizeof(CFHEADER); - if (fwrite(&CABHeader, sizeof(CFHEADER), 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = sizeof(CFHEADER); + if (fwrite(&CABHeader, sizeof(CFHEADER), 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - /* Write per-cabinet reserved area if present */ - if (CABHeader.Flags & CAB_FLAG_RESERVE) - { - ULONG ReservedSize; + /* Write per-cabinet reserved area if present */ + if (CABHeader.Flags & CAB_FLAG_RESERVE) + { + ULONG ReservedSize; - ReservedSize = CabinetReservedFileSize & 0xffff; - ReservedSize |= (0 << 16); /* Folder reserved area size */ - ReservedSize |= (0 << 24); /* Folder reserved area size */ + ReservedSize = CabinetReservedFileSize & 0xffff; + ReservedSize |= (0 << 16); /* Folder reserved area size */ + ReservedSize |= (0 << 24); /* Folder reserved area size */ #if defined(WIN32) - if (!WriteFile(FileHandle, &ReservedSize, sizeof(ULONG), (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, &ReservedSize, sizeof(ULONG), (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = sizeof(ULONG); - if (fwrite(&ReservedSize, sizeof(ULONG), 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = sizeof(ULONG); + if (fwrite(&ReservedSize, sizeof(ULONG), 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif #if defined(WIN32) - if (!WriteFile(FileHandle, CabinetReservedFileBuffer, CabinetReservedFileSize, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, CabinetReservedFileBuffer, CabinetReservedFileSize, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = CabinetReservedFileSize; - if (fwrite(CabinetReservedFileBuffer, CabinetReservedFileSize, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = CabinetReservedFileSize; + if (fwrite(CabinetReservedFileBuffer, CabinetReservedFileSize, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - } + } - if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) - { - DPRINT(MAX_TRACE, ("CabinetPrev '%s'.\n", CabinetPrev)); + if ((CABHeader.Flags & CAB_FLAG_HASPREV) > 0) + { + DPRINT(MAX_TRACE, ("CabinetPrev '%s'.\n", CabinetPrev)); - /* Write name of previous cabinet */ - Size = (ULONG)strlen(CabinetPrev) + 1; + /* Write name of previous cabinet */ + Size = (ULONG)strlen(CabinetPrev) + 1; #if defined(WIN32) - if (!WriteFile(FileHandle, CabinetPrev, Size, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, CabinetPrev, Size, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = Size; - if (fwrite(CabinetPrev, Size, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = Size; + if (fwrite(CabinetPrev, Size, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - DPRINT(MAX_TRACE, ("DiskPrev '%s'.\n", DiskPrev)); + DPRINT(MAX_TRACE, ("DiskPrev '%s'.\n", DiskPrev)); - /* Write label of previous disk */ - Size = (ULONG)strlen(DiskPrev) + 1; + /* Write label of previous disk */ + Size = (ULONG)strlen(DiskPrev) + 1; #if defined(WIN32) - if (!WriteFile(FileHandle, DiskPrev, Size, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, DiskPrev, Size, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = Size; - if (fwrite(DiskPrev, Size, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = Size; + if (fwrite(DiskPrev, Size, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - } + } - if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) - { - DPRINT(MAX_TRACE, ("CabinetNext '%s'.\n", CabinetNext)); + if ((CABHeader.Flags & CAB_FLAG_HASNEXT) > 0) + { + DPRINT(MAX_TRACE, ("CabinetNext '%s'.\n", CabinetNext)); - /* Write name of next cabinet */ - Size = (ULONG)strlen(CabinetNext) + 1; + /* Write name of next cabinet */ + Size = (ULONG)strlen(CabinetNext) + 1; #if defined(WIN32) - if (!WriteFile(FileHandle, CabinetNext, Size, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, CabinetNext, Size, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = Size; - if (fwrite(CabinetNext, Size, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = Size; + if (fwrite(CabinetNext, Size, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - DPRINT(MAX_TRACE, ("DiskNext '%s'.\n", DiskNext)); + DPRINT(MAX_TRACE, ("DiskNext '%s'.\n", DiskNext)); - /* Write label of next disk */ - Size = (ULONG)strlen(DiskNext) + 1; + /* Write label of next disk */ + Size = (ULONG)strlen(DiskNext) + 1; #if defined(WIN32) - if (!WriteFile(FileHandle, DiskNext, Size, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, DiskNext, Size, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = Size; - if (fwrite(DiskNext, Size, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = Size; + if (fwrite(DiskNext, Size, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - } + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -2990,42 +2988,42 @@ ULONG CCabinet::WriteFolderEntries() * Status of operation */ { - PCFFOLDER_NODE FolderNode; - ULONG BytesWritten; + PCFFOLDER_NODE FolderNode; + ULONG BytesWritten; - DPRINT(MAX_TRACE, ("Writing folder table.\n")); + DPRINT(MAX_TRACE, ("Writing folder table.\n")); - FolderNode = FolderListHead; - while (FolderNode != NULL) - { - if (FolderNode->Commit) - { - DPRINT(MAX_TRACE, ("Writing folder entry. CompressionType (0x%X) DataBlockCount (%d) DataOffset (0x%lX).\n", - FolderNode->Folder.CompressionType, FolderNode->Folder.DataBlockCount, FolderNode->Folder.DataOffset)); + FolderNode = FolderListHead; + while (FolderNode != NULL) + { + if (FolderNode->Commit) + { + DPRINT(MAX_TRACE, ("Writing folder entry. CompressionType (0x%X) DataBlockCount (%d) DataOffset (0x%lX).\n", + FolderNode->Folder.CompressionType, FolderNode->Folder.DataBlockCount, FolderNode->Folder.DataOffset)); #if defined(WIN32) - if (!WriteFile(FileHandle, - &FolderNode->Folder, - sizeof(CFFOLDER), - (LPDWORD)&BytesWritten, - NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, + &FolderNode->Folder, + sizeof(CFFOLDER), + (LPDWORD)&BytesWritten, + NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = sizeof(CFFOLDER); - if (fwrite(&FolderNode->Folder, sizeof(CFFOLDER), 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = sizeof(CFFOLDER); + if (fwrite(&FolderNode->Folder, sizeof(CFFOLDER), 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - } - FolderNode = FolderNode->Next; - } + } + FolderNode = FolderNode->Next; + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -3036,77 +3034,77 @@ ULONG CCabinet::WriteFileEntries() * Status of operation */ { - PCFFILE_NODE File; - ULONG BytesWritten; - bool SetCont = false; + PCFFILE_NODE File; + ULONG BytesWritten; + bool SetCont = false; - DPRINT(MAX_TRACE, ("Writing file table.\n")); + DPRINT(MAX_TRACE, ("Writing file table.\n")); - File = FileListHead; - while (File != NULL) - { - if (File->Commit) - { - /* Remove any continued files that ends in this disk */ - if (File->File.FileControlID == CAB_FILE_CONTINUED) - File->Delete = true; + File = FileListHead; + while (File != NULL) + { + if (File->Commit) + { + /* Remove any continued files that ends in this disk */ + if (File->File.FileControlID == CAB_FILE_CONTINUED) + File->Delete = true; - /* The file could end in the last (split) block and should therefore - appear in the next disk too */ + /* The file could end in the last (split) block and should therefore + appear in the next disk too */ - if ((File->File.FileOffset + File->File.FileSize >= LastBlockStart) && - (File->File.FileControlID <= CAB_FILE_MAX_FOLDER) && (BlockIsSplit)) - { - File->File.FileControlID = CAB_FILE_SPLIT; - File->Delete = false; - SetCont = true; - } + if ((File->File.FileOffset + File->File.FileSize >= LastBlockStart) && + (File->File.FileControlID <= CAB_FILE_MAX_FOLDER) && (BlockIsSplit)) + { + File->File.FileControlID = CAB_FILE_SPLIT; + File->Delete = false; + SetCont = true; + } - DPRINT(MAX_TRACE, ("Writing file entry. FileControlID (0x%X) FileOffset (0x%lX) FileSize (%lu) FileName (%s).\n", - File->File.FileControlID, File->File.FileOffset, File->File.FileSize, File->FileName)); + DPRINT(MAX_TRACE, ("Writing file entry. FileControlID (0x%X) FileOffset (0x%lX) FileSize (%lu) FileName (%s).\n", + File->File.FileControlID, File->File.FileOffset, File->File.FileSize, File->FileName)); #if defined(WIN32) - if (!WriteFile(FileHandle, - &File->File, - sizeof(CFFILE), - (LPDWORD)&BytesWritten, - NULL)) - return CAB_STATUS_CANNOT_WRITE; + if (!WriteFile(FileHandle, + &File->File, + sizeof(CFFILE), + (LPDWORD)&BytesWritten, + NULL)) + return CAB_STATUS_CANNOT_WRITE; #else - BytesWritten = sizeof(CFFILE); - if (fwrite(&File->File, sizeof(CFFILE), 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = sizeof(CFFILE); + if (fwrite(&File->File, sizeof(CFFILE), 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif #if defined(WIN32) - if (!WriteFile(FileHandle, - GetFileName(File->FileName), - (DWORD)strlen(GetFileName(File->FileName)) + 1, - (LPDWORD)&BytesWritten, - NULL)) - return CAB_STATUS_CANNOT_WRITE; + if (!WriteFile(FileHandle, + GetFileName(File->FileName), + (DWORD)strlen(GetFileName(File->FileName)) + 1, + (LPDWORD)&BytesWritten, + NULL)) + return CAB_STATUS_CANNOT_WRITE; #else - BytesWritten = strlen(GetFileName(File->FileName)) + 1; - if (fwrite(GetFileName(File->FileName), strlen(GetFileName(File->FileName)) + 1, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = strlen(GetFileName(File->FileName)) + 1; + if (fwrite(GetFileName(File->FileName), strlen(GetFileName(File->FileName)) + 1, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - if (SetCont) - { - File->File.FileControlID = CAB_FILE_CONTINUED; - SetCont = false; - } - } + if (SetCont) + { + File->File.FileControlID = CAB_FILE_CONTINUED; + SetCont = false; + } + } - File = File->Next; - } - return CAB_STATUS_SUCCESS; + File = File->Next; + } + return CAB_STATUS_SUCCESS; } @@ -3119,67 +3117,67 @@ ULONG CCabinet::CommitDataBlocks(PCFFOLDER_NODE FolderNode) * Status of operation */ { - PCFDATA_NODE DataNode; - ULONG BytesWritten; - ULONG BytesRead; - ULONG Status; + PCFDATA_NODE DataNode; + ULONG BytesWritten; + ULONG BytesRead; + ULONG Status; - DataNode = FolderNode->DataListHead; - if (DataNode != NULL) - Status = ScratchFile->Seek(DataNode->ScratchFilePosition); + DataNode = FolderNode->DataListHead; + if (DataNode != NULL) + Status = ScratchFile->Seek(DataNode->ScratchFilePosition); - while (DataNode != NULL) - { - DPRINT(MAX_TRACE, ("Reading block at (0x%lX) CompSize (%d) UncompSize (%d).\n", - DataNode->ScratchFilePosition, - DataNode->Data.CompSize, - DataNode->Data.UncompSize)); + while (DataNode != NULL) + { + DPRINT(MAX_TRACE, ("Reading block at (0x%lX) CompSize (%d) UncompSize (%d).\n", + DataNode->ScratchFilePosition, + DataNode->Data.CompSize, + DataNode->Data.UncompSize)); - /* InputBuffer is free for us to use here, so we use it and avoid a - memory allocation. OutputBuffer can't be used here because it may - still contain valid data (if a data block spans two or more disks) */ - Status = ScratchFile->ReadBlock(&DataNode->Data, InputBuffer, &BytesRead); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot read from scratch file (%lu).\n", (ULONG)Status)); - return Status; - } + /* InputBuffer is free for us to use here, so we use it and avoid a + memory allocation. OutputBuffer can't be used here because it may + still contain valid data (if a data block spans two or more disks) */ + Status = ScratchFile->ReadBlock(&DataNode->Data, InputBuffer, &BytesRead); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot read from scratch file (%lu).\n", (ULONG)Status)); + return Status; + } #if defined(WIN32) - if (!WriteFile(FileHandle, &DataNode->Data, - sizeof(CFDATA), (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, &DataNode->Data, + sizeof(CFDATA), (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = sizeof(CFDATA); - if (fwrite(&DataNode->Data, sizeof(CFDATA), 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = sizeof(CFDATA); + if (fwrite(&DataNode->Data, sizeof(CFDATA), 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif #if defined(WIN32) - if (!WriteFile(FileHandle, InputBuffer, - DataNode->Data.CompSize, (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + if (!WriteFile(FileHandle, InputBuffer, + DataNode->Data.CompSize, (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #else - BytesWritten = DataNode->Data.CompSize; - if (fwrite(InputBuffer, DataNode->Data.CompSize, 1, FileHandle) < 1) - { - DPRINT(MIN_TRACE, ("Cannot write to file.\n")); - return CAB_STATUS_CANNOT_WRITE; - } + BytesWritten = DataNode->Data.CompSize; + if (fwrite(InputBuffer, DataNode->Data.CompSize, 1, FileHandle) < 1) + { + DPRINT(MIN_TRACE, ("Cannot write to file.\n")); + return CAB_STATUS_CANNOT_WRITE; + } #endif - DataNode = DataNode->Next; - } - return CAB_STATUS_SUCCESS; + DataNode = DataNode->Next; + } + return CAB_STATUS_SUCCESS; } @@ -3190,84 +3188,84 @@ ULONG CCabinet::WriteDataBlock() * Status of operation */ { - ULONG Status; - ULONG BytesWritten; - PCFDATA_NODE DataNode; + ULONG Status; + ULONG BytesWritten; + PCFDATA_NODE DataNode; - if (!BlockIsSplit) - { - Status = Codec->Compress(OutputBuffer, - InputBuffer, - CurrentIBufferSize, - &TotalCompSize); + if (!BlockIsSplit) + { + Status = Codec->Compress(OutputBuffer, + InputBuffer, + CurrentIBufferSize, + &TotalCompSize); - DPRINT(MAX_TRACE, ("Block compressed. CurrentIBufferSize (%lu) TotalCompSize(%lu).\n", - CurrentIBufferSize, TotalCompSize)); + DPRINT(MAX_TRACE, ("Block compressed. CurrentIBufferSize (%lu) TotalCompSize(%lu).\n", + CurrentIBufferSize, TotalCompSize)); - CurrentOBuffer = OutputBuffer; - CurrentOBufferSize = TotalCompSize; - } + CurrentOBuffer = OutputBuffer; + CurrentOBufferSize = TotalCompSize; + } - DataNode = NewDataNode(CurrentFolderNode); - if (!DataNode) - { - DPRINT(MIN_TRACE, ("Insufficient memory.\n")); - return CAB_STATUS_NOMEMORY; - } + DataNode = NewDataNode(CurrentFolderNode); + if (!DataNode) + { + DPRINT(MIN_TRACE, ("Insufficient memory.\n")); + return CAB_STATUS_NOMEMORY; + } - DiskSize += sizeof(CFDATA); + DiskSize += sizeof(CFDATA); - if (MaxDiskSize > 0) - /* Disk size is limited */ - BlockIsSplit = (DiskSize + CurrentOBufferSize > MaxDiskSize); - else - BlockIsSplit = false; + if (MaxDiskSize > 0) + /* Disk size is limited */ + BlockIsSplit = (DiskSize + CurrentOBufferSize > MaxDiskSize); + else + BlockIsSplit = false; - if (BlockIsSplit) - { - DataNode->Data.CompSize = (USHORT)(MaxDiskSize - DiskSize); - DataNode->Data.UncompSize = 0; - CreateNewDisk = true; - } - else - { - DataNode->Data.CompSize = (USHORT)CurrentOBufferSize; - DataNode->Data.UncompSize = (USHORT)CurrentIBufferSize; - } + if (BlockIsSplit) + { + DataNode->Data.CompSize = (USHORT)(MaxDiskSize - DiskSize); + DataNode->Data.UncompSize = 0; + CreateNewDisk = true; + } + else + { + DataNode->Data.CompSize = (USHORT)CurrentOBufferSize; + DataNode->Data.UncompSize = (USHORT)CurrentIBufferSize; + } - DataNode->Data.Checksum = 0; - DataNode->ScratchFilePosition = ScratchFile->Position(); + DataNode->Data.Checksum = 0; + DataNode->ScratchFilePosition = ScratchFile->Position(); - // FIXME: MAKECAB.EXE does not like this checksum algorithm - //DataNode->Data.Checksum = ComputeChecksum(CurrentOBuffer, DataNode->Data.CompSize, 0); + // FIXME: MAKECAB.EXE does not like this checksum algorithm + //DataNode->Data.Checksum = ComputeChecksum(CurrentOBuffer, DataNode->Data.CompSize, 0); - DPRINT(MAX_TRACE, ("Writing block. Checksum (0x%lX) CompSize (%lu) UncompSize (%lu).\n", - (ULONG)DataNode->Data.Checksum, - (ULONG)DataNode->Data.CompSize, - (ULONG)DataNode->Data.UncompSize)); + DPRINT(MAX_TRACE, ("Writing block. Checksum (0x%lX) CompSize (%lu) UncompSize (%lu).\n", + (ULONG)DataNode->Data.Checksum, + (ULONG)DataNode->Data.CompSize, + (ULONG)DataNode->Data.UncompSize)); - Status = ScratchFile->WriteBlock(&DataNode->Data, - CurrentOBuffer, &BytesWritten); - if (Status != CAB_STATUS_SUCCESS) - return Status; + Status = ScratchFile->WriteBlock(&DataNode->Data, + CurrentOBuffer, &BytesWritten); + if (Status != CAB_STATUS_SUCCESS) + return Status; - DiskSize += BytesWritten; + DiskSize += BytesWritten; - CurrentFolderNode->TotalFolderSize += (BytesWritten + sizeof(CFDATA)); - CurrentFolderNode->Folder.DataBlockCount++; + CurrentFolderNode->TotalFolderSize += (BytesWritten + sizeof(CFDATA)); + CurrentFolderNode->Folder.DataBlockCount++; - *(unsigned char**)&CurrentOBuffer += DataNode->Data.CompSize; - CurrentOBufferSize -= DataNode->Data.CompSize; + *(unsigned char**)&CurrentOBuffer += DataNode->Data.CompSize; + CurrentOBufferSize -= DataNode->Data.CompSize; - LastBlockStart += DataNode->Data.UncompSize; + LastBlockStart += DataNode->Data.UncompSize; - if (!BlockIsSplit) - { - CurrentIBufferSize = 0; - CurrentIBuffer = InputBuffer; - } + if (!BlockIsSplit) + { + CurrentIBufferSize = 0; + CurrentIBuffer = InputBuffer; + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } #if !defined(WIN32) @@ -3284,21 +3282,21 @@ void CCabinet::ConvertDateAndTime(time_t* Time, * Status of operation */ { - struct tm *timedef; + struct tm *timedef; - timedef = localtime(Time); + timedef = localtime(Time); - DPRINT(MAX_TRACE, ("day: %d, mon: %d, year:%d, hour: %d, min: %d, sec: %d\n", - timedef->tm_mday, timedef->tm_mon, timedef->tm_year, - timedef->tm_sec, timedef->tm_min, timedef->tm_hour)); + DPRINT(MAX_TRACE, ("day: %d, mon: %d, year:%d, hour: %d, min: %d, sec: %d\n", + timedef->tm_mday, timedef->tm_mon, timedef->tm_year, + timedef->tm_sec, timedef->tm_min, timedef->tm_hour)); - *DosDate = ((timedef->tm_mday + 1) << 0) - | ((timedef->tm_mon + 1) << 5) - | (((timedef->tm_year + 1900) - 1980) << 9); + *DosDate = ((timedef->tm_mday + 1) << 0) + | ((timedef->tm_mon + 1) << 5) + | (((timedef->tm_year + 1900) - 1980) << 9); - *DosTime = (timedef->tm_sec << 0) - | (timedef->tm_min << 5) - | (timedef->tm_hour << 11); + *DosTime = (timedef->tm_sec << 0) + | (timedef->tm_min << 5) + | (timedef->tm_hour << 11); } #endif // !WIN32 @@ -3315,32 +3313,32 @@ ULONG CCabinet::GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File) */ { #if defined(WIN32) - FILETIME FileTime; + FILETIME FileTime; - if (GetFileTime(FileHandle, NULL, NULL, &FileTime)) - FileTimeToDosDateTime(&FileTime, - &File->File.FileDate, - &File->File.FileTime); + if (GetFileTime(FileHandle, NULL, NULL, &FileTime)) + FileTimeToDosDateTime(&FileTime, + &File->File.FileDate, + &File->File.FileTime); #else - struct stat stbuf; - char buf[MAX_PATH]; + struct stat stbuf; + char buf[MAX_PATH]; - // Check for an absolute path - if (IsSeparator(File->FileName[0])) - strcpy(buf, File->FileName); - else - { - getcwd(buf, sizeof(buf)); - strcat(buf, DIR_SEPARATOR_STRING); - strcat(buf, File->FileName); - } + // Check for an absolute path + if (IsSeparator(File->FileName[0])) + strcpy(buf, File->FileName); + else + { + getcwd(buf, sizeof(buf)); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, File->FileName); + } - if (stat(buf, &stbuf) == -1) - return CAB_STATUS_CANNOT_READ; + if (stat(buf, &stbuf) == -1) + return CAB_STATUS_CANNOT_READ; - ConvertDateAndTime(&stbuf.st_mtime, &File->File.FileDate, &File->File.FileTime); + ConvertDateAndTime(&stbuf.st_mtime, &File->File.FileDate, &File->File.FileTime); #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -3354,56 +3352,56 @@ ULONG CCabinet::GetAttributesOnFile(PCFFILE_NODE File) */ { #if defined(WIN32) - LONG Attributes; + LONG Attributes; - Attributes = GetFileAttributes(File->FileName); - if (Attributes == -1) - return CAB_STATUS_CANNOT_READ; + Attributes = GetFileAttributes(File->FileName); + if (Attributes == -1) + return CAB_STATUS_CANNOT_READ; - if (Attributes & FILE_ATTRIBUTE_READONLY) - File->File.Attributes |= CAB_ATTRIB_READONLY; + if (Attributes & FILE_ATTRIBUTE_READONLY) + File->File.Attributes |= CAB_ATTRIB_READONLY; - if (Attributes & FILE_ATTRIBUTE_HIDDEN) - File->File.Attributes |= CAB_ATTRIB_HIDDEN; + if (Attributes & FILE_ATTRIBUTE_HIDDEN) + File->File.Attributes |= CAB_ATTRIB_HIDDEN; - if (Attributes & FILE_ATTRIBUTE_SYSTEM) - File->File.Attributes |= CAB_ATTRIB_SYSTEM; + if (Attributes & FILE_ATTRIBUTE_SYSTEM) + File->File.Attributes |= CAB_ATTRIB_SYSTEM; - if (Attributes & FILE_ATTRIBUTE_DIRECTORY) - File->File.Attributes |= CAB_ATTRIB_DIRECTORY; + if (Attributes & FILE_ATTRIBUTE_DIRECTORY) + File->File.Attributes |= CAB_ATTRIB_DIRECTORY; - if (Attributes & FILE_ATTRIBUTE_ARCHIVE) - File->File.Attributes |= CAB_ATTRIB_ARCHIVE; + if (Attributes & FILE_ATTRIBUTE_ARCHIVE) + File->File.Attributes |= CAB_ATTRIB_ARCHIVE; #else - struct stat stbuf; - char buf[MAX_PATH]; + struct stat stbuf; + char buf[MAX_PATH]; - // Check for an absolute path - if (IsSeparator(File->FileName[0])) - strcpy(buf, File->FileName); - else - { - getcwd(buf, sizeof(buf)); - strcat(buf, DIR_SEPARATOR_STRING); - strcat(buf, File->FileName); - } + // Check for an absolute path + if (IsSeparator(File->FileName[0])) + strcpy(buf, File->FileName); + else + { + getcwd(buf, sizeof(buf)); + strcat(buf, DIR_SEPARATOR_STRING); + strcat(buf, File->FileName); + } - if (stat(buf, &stbuf) == -1) - return CAB_STATUS_CANNOT_READ; + if (stat(buf, &stbuf) == -1) + return CAB_STATUS_CANNOT_READ; #if 0 - File->File.Attributes |= CAB_ATTRIB_READONLY; - File->File.Attributes |= CAB_ATTRIB_HIDDEN; - File->File.Attributes |= CAB_ATTRIB_SYSTEM; + File->File.Attributes |= CAB_ATTRIB_READONLY; + File->File.Attributes |= CAB_ATTRIB_HIDDEN; + File->File.Attributes |= CAB_ATTRIB_SYSTEM; #endif - if (stbuf.st_mode & S_IFDIR) - File->File.Attributes |= CAB_ATTRIB_DIRECTORY; + if (stbuf.st_mode & S_IFDIR) + File->File.Attributes |= CAB_ATTRIB_DIRECTORY; - File->File.Attributes |= CAB_ATTRIB_ARCHIVE; + File->File.Attributes |= CAB_ATTRIB_ARCHIVE; #endif - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -3417,29 +3415,29 @@ ULONG CCabinet::SetAttributesOnFile(PCFFILE_NODE File) */ { #if defined(WIN32) - ULONG Attributes = 0; + ULONG Attributes = 0; - if (File->File.Attributes & CAB_ATTRIB_READONLY) - Attributes |= FILE_ATTRIBUTE_READONLY; + if (File->File.Attributes & CAB_ATTRIB_READONLY) + Attributes |= FILE_ATTRIBUTE_READONLY; - if (File->File.Attributes & CAB_ATTRIB_HIDDEN) - Attributes |= FILE_ATTRIBUTE_HIDDEN; + if (File->File.Attributes & CAB_ATTRIB_HIDDEN) + Attributes |= FILE_ATTRIBUTE_HIDDEN; - if (File->File.Attributes & CAB_ATTRIB_SYSTEM) - Attributes |= FILE_ATTRIBUTE_SYSTEM; + if (File->File.Attributes & CAB_ATTRIB_SYSTEM) + Attributes |= FILE_ATTRIBUTE_SYSTEM; - if (File->File.Attributes & CAB_ATTRIB_DIRECTORY) - Attributes |= FILE_ATTRIBUTE_DIRECTORY; + if (File->File.Attributes & CAB_ATTRIB_DIRECTORY) + Attributes |= FILE_ATTRIBUTE_DIRECTORY; - if (File->File.Attributes & CAB_ATTRIB_ARCHIVE) - Attributes |= FILE_ATTRIBUTE_ARCHIVE; + if (File->File.Attributes & CAB_ATTRIB_ARCHIVE) + Attributes |= FILE_ATTRIBUTE_ARCHIVE; - SetFileAttributes(File->FileName, Attributes); + SetFileAttributes(File->FileName, Attributes); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; #else - //DPRINT(MIN_TRACE, ("FIXME: SetAttributesOnFile() is unimplemented\n")); - return CAB_STATUS_SUCCESS; + //DPRINT(MIN_TRACE, ("FIXME: SetAttributesOnFile() is unimplemented\n")); + return CAB_STATUS_SUCCESS; #endif } diff --git a/reactos/tools/cabman/cabinet.h b/reactos/tools/cabman/cabinet.h index 3a3756053af..dc85c651694 100755 --- a/reactos/tools/cabman/cabinet.h +++ b/reactos/tools/cabman/cabinet.h @@ -65,18 +65,18 @@ extern ULONG DebugTraceLevel; #define DPRINT(_t_, _x_) \ - if (((DebugTraceLevel & NORMAL_MASK) >= _t_) || \ - ((DebugTraceLevel & _t_) > NORMAL_MASK)) { \ - printf("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \ - printf _x_ ; \ - } + if (((DebugTraceLevel & NORMAL_MASK) >= _t_) || \ + ((DebugTraceLevel & _t_) > NORMAL_MASK)) { \ + printf("(%s:%d)(%s) ", __FILE__, __LINE__, __FUNCTION__); \ + printf _x_ ; \ + } #define ASSERT(_b_) { \ - if (!(_b_)) { \ - printf("(%s:%d)(%s) ASSERTION: ", __FILE__, __LINE__, __FUNCTION__); \ - printf(#_b_); \ - exit(0); \ - } \ + if (!(_b_)) { \ + printf("(%s:%d)(%s) ASSERTION: ", __FILE__, __LINE__, __FUNCTION__); \ + printf(#_b_); \ + exit(0); \ + } \ } #else /* DBG */ @@ -123,108 +123,108 @@ extern ULONG DebugTraceLevel; typedef struct _CFHEADER { - ULONG Signature; // File signature 'MSCF' (CAB_SIGNATURE) - ULONG Reserved1; // Reserved field - ULONG CabinetSize; // Cabinet file size - ULONG Reserved2; // Reserved field - ULONG FileTableOffset; // Offset of first CFFILE - ULONG Reserved3; // Reserved field - USHORT Version; // Cabinet version (CAB_VERSION) - USHORT FolderCount; // Number of folders - USHORT FileCount; // Number of files - USHORT Flags; // Cabinet flags (CAB_FLAG_*) - USHORT SetID; // Cabinet set id - USHORT CabinetNumber; // Zero-based cabinet number + ULONG Signature; // File signature 'MSCF' (CAB_SIGNATURE) + ULONG Reserved1; // Reserved field + ULONG CabinetSize; // Cabinet file size + ULONG Reserved2; // Reserved field + ULONG FileTableOffset; // Offset of first CFFILE + ULONG Reserved3; // Reserved field + USHORT Version; // Cabinet version (CAB_VERSION) + USHORT FolderCount; // Number of folders + USHORT FileCount; // Number of files + USHORT Flags; // Cabinet flags (CAB_FLAG_*) + USHORT SetID; // Cabinet set id + USHORT CabinetNumber; // Zero-based cabinet number /* Optional fields (depends on Flags) - USHORT CabinetResSize // Per-cabinet reserved area size - char FolderResSize // Per-folder reserved area size - char FileResSize // Per-file reserved area size - char CabinetReserved[] // Per-cabinet reserved area - char CabinetPrev[] // Name of previous cabinet file - char DiskPrev[] // Name of previous disk - char CabinetNext[] // Name of next cabinet file - char DiskNext[] // Name of next disk + USHORT CabinetResSize // Per-cabinet reserved area size + char FolderResSize // Per-folder reserved area size + char FileResSize // Per-file reserved area size + char CabinetReserved[] // Per-cabinet reserved area + char CabinetPrev[] // Name of previous cabinet file + char DiskPrev[] // Name of previous disk + char CabinetNext[] // Name of next cabinet file + char DiskNext[] // Name of next disk */ } CFHEADER, *PCFHEADER; typedef struct _CFFOLDER { - ULONG DataOffset; // Absolute offset of first CFDATA block in this folder - USHORT DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet - USHORT CompressionType; // Type of compression used for all CFDATA blocks in this folder + ULONG DataOffset; // Absolute offset of first CFDATA block in this folder + USHORT DataBlockCount; // Number of CFDATA blocks in this folder in this cabinet + USHORT CompressionType; // Type of compression used for all CFDATA blocks in this folder /* Optional fields (depends on Flags) - char FolderReserved[] // Per-folder reserved area + char FolderReserved[] // Per-folder reserved area */ } CFFOLDER, *PCFFOLDER; typedef struct _CFFILE { - ULONG FileSize; // Uncompressed file size in bytes - ULONG FileOffset; // Uncompressed offset of file in the folder - USHORT FileControlID; // File control ID (CAB_FILE_*) - USHORT FileDate; // File date stamp, as used by DOS - USHORT FileTime; // File time stamp, as used by DOS - USHORT Attributes; // File attributes (CAB_ATTRIB_*) + ULONG FileSize; // Uncompressed file size in bytes + ULONG FileOffset; // Uncompressed offset of file in the folder + USHORT FileControlID; // File control ID (CAB_FILE_*) + USHORT FileDate; // File date stamp, as used by DOS + USHORT FileTime; // File time stamp, as used by DOS + USHORT Attributes; // File attributes (CAB_ATTRIB_*) /* After this is the NULL terminated filename */ } CFFILE, *PCFFILE; typedef struct _CFDATA { - ULONG Checksum; // Checksum of CFDATA entry - USHORT CompSize; // Number of compressed bytes in this block - USHORT UncompSize; // Number of uncompressed bytes in this block + ULONG Checksum; // Checksum of CFDATA entry + USHORT CompSize; // Number of compressed bytes in this block + USHORT UncompSize; // Number of uncompressed bytes in this block /* Optional fields (depends on Flags) - char DataReserved[] // Per-datablock reserved area + char DataReserved[] // Per-datablock reserved area */ } CFDATA, *PCFDATA; typedef struct _CFDATA_NODE { - struct _CFDATA_NODE *Next; - struct _CFDATA_NODE *Prev; - ULONG ScratchFilePosition; // Absolute offset in scratch file - ULONG AbsoluteOffset; // Absolute offset in cabinet - ULONG UncompOffset; // Uncompressed offset in folder - CFDATA Data; + struct _CFDATA_NODE *Next; + struct _CFDATA_NODE *Prev; + ULONG ScratchFilePosition; // Absolute offset in scratch file + ULONG AbsoluteOffset; // Absolute offset in cabinet + ULONG UncompOffset; // Uncompressed offset in folder + CFDATA Data; } CFDATA_NODE, *PCFDATA_NODE; typedef struct _CFFOLDER_NODE { - struct _CFFOLDER_NODE *Next; - struct _CFFOLDER_NODE *Prev; - ULONG UncompOffset; // File size accumulator - ULONG AbsoluteOffset; - ULONG TotalFolderSize; // Total size of folder in current disk - PCFDATA_NODE DataListHead; - PCFDATA_NODE DataListTail; - ULONG Index; - bool Commit; // true if the folder should be committed - bool Delete; // true if marked for deletion - CFFOLDER Folder; + struct _CFFOLDER_NODE *Next; + struct _CFFOLDER_NODE *Prev; + ULONG UncompOffset; // File size accumulator + ULONG AbsoluteOffset; + ULONG TotalFolderSize; // Total size of folder in current disk + PCFDATA_NODE DataListHead; + PCFDATA_NODE DataListTail; + ULONG Index; + bool Commit; // true if the folder should be committed + bool Delete; // true if marked for deletion + CFFOLDER Folder; } CFFOLDER_NODE, *PCFFOLDER_NODE; typedef struct _CFFILE_NODE { - struct _CFFILE_NODE *Next; - struct _CFFILE_NODE *Prev; - CFFILE File; - char* FileName; - PCFDATA_NODE DataBlock; // First data block of file. NULL if not known - bool Commit; // true if the file data should be committed - bool Delete; // true if marked for deletion - PCFFOLDER_NODE FolderNode; // Folder this file belong to + struct _CFFILE_NODE *Next; + struct _CFFILE_NODE *Prev; + CFFILE File; + char* FileName; + PCFDATA_NODE DataBlock; // First data block of file. NULL if not known + bool Commit; // true if the file data should be committed + bool Delete; // true if marked for deletion + PCFFOLDER_NODE FolderNode; // Folder this file belong to } CFFILE_NODE, *PCFFILE_NODE; typedef struct _CAB_SEARCH { - char Search[MAX_PATH]; // Search criteria - PCFFILE_NODE Next; // Pointer to next node - PCFFILE File; // Pointer to current CFFILE - char* FileName; // Current filename + char Search[MAX_PATH]; // Search criteria + PCFFILE_NODE Next; // Pointer to next node + PCFFILE File; // Pointer to current CFFILE + char* FileName; // Current filename } CAB_SEARCH, *PCAB_SEARCH; @@ -249,20 +249,20 @@ typedef struct _CAB_SEARCH class CCABCodec { public: - /* Default constructor */ - CCABCodec() {}; - /* Default destructor */ - virtual ~CCABCodec() {}; - /* Compresses a data block */ - virtual ULONG Compress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength) = 0; - /* Uncompresses a data block */ - virtual ULONG Uncompress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength) = 0; + /* Default constructor */ + CCABCodec() {}; + /* Default destructor */ + virtual ~CCABCodec() {}; + /* Compresses a data block */ + virtual ULONG Compress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength) = 0; + /* Uncompresses a data block */ + virtual ULONG Uncompress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength) = 0; }; @@ -285,193 +285,193 @@ public: class CCFDATAStorage { public: - /* Default constructor */ - CCFDATAStorage(); - /* Default destructor */ - virtual ~CCFDATAStorage(); - ULONG Create(char* FileName); - ULONG Destroy(); - ULONG Truncate(); - ULONG Position(); - ULONG Seek(LONG Position); - ULONG ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead); - ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten); + /* Default constructor */ + CCFDATAStorage(); + /* Default destructor */ + virtual ~CCFDATAStorage(); + ULONG Create(char* FileName); + ULONG Destroy(); + ULONG Truncate(); + ULONG Position(); + ULONG Seek(LONG Position); + ULONG ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead); + ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten); private: - char FullName[MAX_PATH]; - bool FileCreated; - FILEHANDLE FileHandle; + char FullName[MAX_PATH]; + bool FileCreated; + FILEHANDLE FileHandle; }; #endif /* CAB_READ_ONLY */ class CCabinet { public: - /* Default constructor */ - CCabinet(); - /* Default destructor */ - virtual ~CCabinet(); - /* Determines if a character is a separator */ - bool IsSeparator(char Char); - /* Replaces \ or / with the one used be the host environment */ - char* ConvertPath(char* Path, bool Allocate); - /* Returns a pointer to the filename part of a fully qualified filename */ - char* GetFileName(char* Path); - /* Removes a filename from a fully qualified filename */ - void RemoveFileName(char* Path); - /* Normalizes a path */ - bool NormalizePath(char* Path, ULONG Length); - /* Returns name of cabinet file */ - char* GetCabinetName(); - /* Sets the name of the cabinet file */ - void SetCabinetName(char* FileName); - /* Sets destination path for extracted files */ - void SetDestinationPath(char* DestinationPath); - /* Sets cabinet reserved file */ - bool SetCabinetReservedFile(char* FileName); - /* Returns cabinet reserved file */ - char* GetCabinetReservedFile(); - /* Returns destination path */ - char* GetDestinationPath(); - /* Returns zero-based current disk number */ - ULONG GetCurrentDiskNumber(); - /* Opens the current cabinet file */ - ULONG Open(); - /* Closes the current open cabinet file */ - void Close(); - /* Locates the first file in the current cabinet file that matches a search criteria */ - ULONG FindFirst(char* FileName, PCAB_SEARCH Search); - /* Locates the next file in the current cabinet file */ - ULONG FindNext(PCAB_SEARCH Search); - /* Extracts a file from the current cabinet file */ - ULONG ExtractFile(char* FileName); - /* Select codec engine to use */ - void SelectCodec(ULONG Id); + /* Default constructor */ + CCabinet(); + /* Default destructor */ + virtual ~CCabinet(); + /* Determines if a character is a separator */ + bool IsSeparator(char Char); + /* Replaces \ or / with the one used be the host environment */ + char* ConvertPath(char* Path, bool Allocate); + /* Returns a pointer to the filename part of a fully qualified filename */ + char* GetFileName(char* Path); + /* Removes a filename from a fully qualified filename */ + void RemoveFileName(char* Path); + /* Normalizes a path */ + bool NormalizePath(char* Path, ULONG Length); + /* Returns name of cabinet file */ + char* GetCabinetName(); + /* Sets the name of the cabinet file */ + void SetCabinetName(char* FileName); + /* Sets destination path for extracted files */ + void SetDestinationPath(char* DestinationPath); + /* Sets cabinet reserved file */ + bool SetCabinetReservedFile(char* FileName); + /* Returns cabinet reserved file */ + char* GetCabinetReservedFile(); + /* Returns destination path */ + char* GetDestinationPath(); + /* Returns zero-based current disk number */ + ULONG GetCurrentDiskNumber(); + /* Opens the current cabinet file */ + ULONG Open(); + /* Closes the current open cabinet file */ + void Close(); + /* Locates the first file in the current cabinet file that matches a search criteria */ + ULONG FindFirst(char* FileName, PCAB_SEARCH Search); + /* Locates the next file in the current cabinet file */ + ULONG FindNext(PCAB_SEARCH Search); + /* Extracts a file from the current cabinet file */ + ULONG ExtractFile(char* FileName); + /* Select codec engine to use */ + void SelectCodec(ULONG Id); #ifndef CAB_READ_ONLY - /* Creates a new cabinet file */ - ULONG NewCabinet(); - /* Forces a new disk to be created */ - ULONG NewDisk(); - /* Forces a new folder to be created */ - ULONG NewFolder(); - /* Writes a file to scratch storage */ - ULONG WriteFileToScratchStorage(PCFFILE_NODE FileNode); - /* Forces the current disk to be written */ - ULONG WriteDisk(ULONG MoreDisks); - /* Commits the current disk */ - ULONG CommitDisk(ULONG MoreDisks); - /* Closes the current disk */ - ULONG CloseDisk(); - /* Closes the current cabinet */ - ULONG CloseCabinet(); - /* Adds a file to the current disk */ - ULONG AddFile(char* FileName); - /* Sets the maximum size of the current disk */ - void SetMaxDiskSize(ULONG Size); + /* Creates a new cabinet file */ + ULONG NewCabinet(); + /* Forces a new disk to be created */ + ULONG NewDisk(); + /* Forces a new folder to be created */ + ULONG NewFolder(); + /* Writes a file to scratch storage */ + ULONG WriteFileToScratchStorage(PCFFILE_NODE FileNode); + /* Forces the current disk to be written */ + ULONG WriteDisk(ULONG MoreDisks); + /* Commits the current disk */ + ULONG CommitDisk(ULONG MoreDisks); + /* Closes the current disk */ + ULONG CloseDisk(); + /* Closes the current cabinet */ + ULONG CloseCabinet(); + /* Adds a file to the current disk */ + ULONG AddFile(char* FileName); + /* Sets the maximum size of the current disk */ + void SetMaxDiskSize(ULONG Size); #endif /* CAB_READ_ONLY */ - /* Default event handlers */ + /* Default event handlers */ - /* Handler called when a file is about to be overridden */ - virtual bool OnOverwrite(PCFFILE Entry, char* FileName); - /* Handler called when a file is about to be extracted */ - virtual void OnExtract(PCFFILE Entry, char* FileName); - /* Handler called when a new disk is to be processed */ - virtual void OnDiskChange(char* CabinetName, char* DiskLabel); + /* Handler called when a file is about to be overridden */ + virtual bool OnOverwrite(PCFFILE Entry, char* FileName); + /* Handler called when a file is about to be extracted */ + virtual void OnExtract(PCFFILE Entry, char* FileName); + /* Handler called when a new disk is to be processed */ + virtual void OnDiskChange(char* CabinetName, char* DiskLabel); #ifndef CAB_READ_ONLY - /* Handler called when a file is about to be added */ - virtual void OnAdd(PCFFILE Entry, char* FileName); - /* Handler called when a cabinet need a name */ - virtual bool OnCabinetName(ULONG Number, char* Name); - /* Handler called when a disk needs a label */ - virtual bool OnDiskLabel(ULONG Number, char* Label); + /* Handler called when a file is about to be added */ + virtual void OnAdd(PCFFILE Entry, char* FileName); + /* Handler called when a cabinet need a name */ + virtual bool OnCabinetName(ULONG Number, char* Name); + /* Handler called when a disk needs a label */ + virtual bool OnDiskLabel(ULONG Number, char* Label); #endif /* CAB_READ_ONLY */ private: - PCFFOLDER_NODE LocateFolderNode(ULONG Index); - ULONG GetAbsoluteOffset(PCFFILE_NODE File); - ULONG LocateFile(char* FileName, PCFFILE_NODE *File); - ULONG ReadString(char* String, ULONG MaxLength); - ULONG ReadFileTable(); - ULONG ReadDataBlocks(PCFFOLDER_NODE FolderNode); - PCFFOLDER_NODE NewFolderNode(); - PCFFILE_NODE NewFileNode(); - PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode); - void DestroyDataNodes(PCFFOLDER_NODE FolderNode); - void DestroyFileNodes(); - void DestroyDeletedFileNodes(); - void DestroyFolderNodes(); - void DestroyDeletedFolderNodes(); - ULONG ComputeChecksum(void* Buffer, ULONG Size, ULONG Seed); - ULONG ReadBlock(void* Buffer, ULONG Size, PULONG BytesRead); + PCFFOLDER_NODE LocateFolderNode(ULONG Index); + ULONG GetAbsoluteOffset(PCFFILE_NODE File); + ULONG LocateFile(char* FileName, PCFFILE_NODE *File); + ULONG ReadString(char* String, ULONG MaxLength); + ULONG ReadFileTable(); + ULONG ReadDataBlocks(PCFFOLDER_NODE FolderNode); + PCFFOLDER_NODE NewFolderNode(); + PCFFILE_NODE NewFileNode(); + PCFDATA_NODE NewDataNode(PCFFOLDER_NODE FolderNode); + void DestroyDataNodes(PCFFOLDER_NODE FolderNode); + void DestroyFileNodes(); + void DestroyDeletedFileNodes(); + void DestroyFolderNodes(); + void DestroyDeletedFolderNodes(); + ULONG ComputeChecksum(void* Buffer, ULONG Size, ULONG Seed); + ULONG ReadBlock(void* Buffer, ULONG Size, PULONG BytesRead); #ifndef CAB_READ_ONLY - ULONG InitCabinetHeader(); - ULONG WriteCabinetHeader(bool MoreDisks); - ULONG WriteFolderEntries(); - ULONG WriteFileEntries(); - ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode); - ULONG WriteDataBlock(); - ULONG GetAttributesOnFile(PCFFILE_NODE File); - ULONG SetAttributesOnFile(PCFFILE_NODE File); - ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File); + ULONG InitCabinetHeader(); + ULONG WriteCabinetHeader(bool MoreDisks); + ULONG WriteFolderEntries(); + ULONG WriteFileEntries(); + ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode); + ULONG WriteDataBlock(); + ULONG GetAttributesOnFile(PCFFILE_NODE File); + ULONG SetAttributesOnFile(PCFFILE_NODE File); + ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File); #if !defined(WIN32) - void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime); + void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime); #endif #endif /* CAB_READ_ONLY */ - ULONG CurrentDiskNumber; // Zero based disk number - char CabinetName[256]; // Filename of current cabinet - char CabinetPrev[256]; // Filename of previous cabinet - char DiskPrev[256]; // Label of cabinet in file CabinetPrev - char CabinetNext[256]; // Filename of next cabinet - char DiskNext[256]; // Label of cabinet in file CabinetNext - ULONG TotalHeaderSize; // Size of header and optional fields - ULONG NextFieldsSize; // Size of next cabinet name and next disk label - ULONG TotalFolderSize; // Size of all folder entries - ULONG TotalFileSize; // Size of all file entries - ULONG FolderUncompSize; // Uncompressed size of folder - ULONG BytesLeftInBlock; // Number of bytes left in current block - bool ReuseBlock; - char DestPath[MAX_PATH]; - char CabinetReservedFile[MAX_PATH]; - void* CabinetReservedFileBuffer; - ULONG CabinetReservedFileSize; - FILEHANDLE FileHandle; - bool FileOpen; - CFHEADER CABHeader; - ULONG CabinetReserved; - ULONG FolderReserved; - ULONG DataReserved; - PCFFOLDER_NODE FolderListHead; - PCFFOLDER_NODE FolderListTail; - PCFFOLDER_NODE CurrentFolderNode; - PCFDATA_NODE CurrentDataNode; - PCFFILE_NODE FileListHead; - PCFFILE_NODE FileListTail; - CCABCodec *Codec; - ULONG CodecId; - bool CodecSelected; - void* InputBuffer; - void* CurrentIBuffer; // Current offset in input buffer - ULONG CurrentIBufferSize; // Bytes left in input buffer - void* OutputBuffer; - ULONG TotalCompSize; // Total size of current CFDATA block - void* CurrentOBuffer; // Current offset in output buffer - ULONG CurrentOBufferSize; // Bytes left in output buffer - ULONG BytesLeftInCabinet; - bool RestartSearch; - ULONG LastFileOffset; // Uncompressed offset of last extracted file + ULONG CurrentDiskNumber; // Zero based disk number + char CabinetName[256]; // Filename of current cabinet + char CabinetPrev[256]; // Filename of previous cabinet + char DiskPrev[256]; // Label of cabinet in file CabinetPrev + char CabinetNext[256]; // Filename of next cabinet + char DiskNext[256]; // Label of cabinet in file CabinetNext + ULONG TotalHeaderSize; // Size of header and optional fields + ULONG NextFieldsSize; // Size of next cabinet name and next disk label + ULONG TotalFolderSize; // Size of all folder entries + ULONG TotalFileSize; // Size of all file entries + ULONG FolderUncompSize; // Uncompressed size of folder + ULONG BytesLeftInBlock; // Number of bytes left in current block + bool ReuseBlock; + char DestPath[MAX_PATH]; + char CabinetReservedFile[MAX_PATH]; + void* CabinetReservedFileBuffer; + ULONG CabinetReservedFileSize; + FILEHANDLE FileHandle; + bool FileOpen; + CFHEADER CABHeader; + ULONG CabinetReserved; + ULONG FolderReserved; + ULONG DataReserved; + PCFFOLDER_NODE FolderListHead; + PCFFOLDER_NODE FolderListTail; + PCFFOLDER_NODE CurrentFolderNode; + PCFDATA_NODE CurrentDataNode; + PCFFILE_NODE FileListHead; + PCFFILE_NODE FileListTail; + CCABCodec *Codec; + ULONG CodecId; + bool CodecSelected; + void* InputBuffer; + void* CurrentIBuffer; // Current offset in input buffer + ULONG CurrentIBufferSize; // Bytes left in input buffer + void* OutputBuffer; + ULONG TotalCompSize; // Total size of current CFDATA block + void* CurrentOBuffer; // Current offset in output buffer + ULONG CurrentOBufferSize; // Bytes left in output buffer + ULONG BytesLeftInCabinet; + bool RestartSearch; + ULONG LastFileOffset; // Uncompressed offset of last extracted file #ifndef CAB_READ_ONLY - ULONG LastBlockStart; // Uncompressed offset of last block in folder - ULONG MaxDiskSize; - ULONG DiskSize; - ULONG PrevCabinetNumber; // Previous cabinet number (where split file starts) - bool CreateNewDisk; - bool CreateNewFolder; + ULONG LastBlockStart; // Uncompressed offset of last block in folder + ULONG MaxDiskSize; + ULONG DiskSize; + ULONG PrevCabinetNumber; // Previous cabinet number (where split file starts) + bool CreateNewDisk; + bool CreateNewFolder; - CCFDATAStorage *ScratchFile; - FILEHANDLE SourceFile; - bool ContinueFile; - ULONG TotalBytesLeft; - bool BlockIsSplit; // true if current data block is split - ULONG NextFolderNumber; // Zero based folder number + CCFDATAStorage *ScratchFile; + FILEHANDLE SourceFile; + bool ContinueFile; + ULONG TotalBytesLeft; + bool BlockIsSplit; // true if current data block is split + ULONG NextFolderNumber; // Zero based folder number #endif /* CAB_READ_ONLY */ }; diff --git a/reactos/tools/cabman/cabman.h b/reactos/tools/cabman/cabman.h index 8d3ddb14bf7..02d60f01ba2 100755 --- a/reactos/tools/cabman/cabman.h +++ b/reactos/tools/cabman/cabman.h @@ -20,27 +20,27 @@ class CCABManager : public CDFParser { public: - CCABManager(); - virtual ~CCABManager(); - bool ParseCmdline(int argc, char* argv[]); - bool Run(); + CCABManager(); + virtual ~CCABManager(); + bool ParseCmdline(int argc, char* argv[]); + bool Run(); private: - void Usage(); - bool CreateCabinet(); - bool CreateSimpleCabinet(); - bool DisplayCabinet(); - bool ExtractFromCabinet(); - /* Event handlers */ - virtual bool OnOverwrite(PCFFILE File, char* FileName); - virtual void OnExtract(PCFFILE File, char* FileName); - virtual void OnDiskChange(char* CabinetName, char* DiskLabel); - virtual void OnAdd(PCFFILE Entry, char* FileName); - /* Configuration */ - bool ProcessAll; - ULONG Mode; - bool PromptOnOverwrite; - char Location[MAX_PATH]; - char FileName[MAX_PATH]; + void Usage(); + bool CreateCabinet(); + bool CreateSimpleCabinet(); + bool DisplayCabinet(); + bool ExtractFromCabinet(); + /* Event handlers */ + virtual bool OnOverwrite(PCFFILE File, char* FileName); + virtual void OnExtract(PCFFILE File, char* FileName); + virtual void OnDiskChange(char* CabinetName, char* DiskLabel); + virtual void OnAdd(PCFFILE Entry, char* FileName); + /* Configuration */ + bool ProcessAll; + ULONG Mode; + bool PromptOnOverwrite; + char Location[MAX_PATH]; + char FileName[MAX_PATH]; }; #endif /* __CABMAN_H */ diff --git a/reactos/tools/cabman/dfp.cxx b/reactos/tools/cabman/dfp.cxx index 09652290b12..b44201409ab 100755 --- a/reactos/tools/cabman/dfp.cxx +++ b/reactos/tools/cabman/dfp.cxx @@ -10,9 +10,7 @@ * REVISIONS: * CSH 21/03-2001 Created * CSH 15/08-2003 Made it portable - * CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces * CF 04/05-2007 Made it compatible with 64-bit operating systems - * CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems */ #include #include @@ -24,32 +22,32 @@ #define GetSizeOfFile(handle) _GetSizeOfFile(handle) static LONG _GetSizeOfFile(FILEHANDLE handle) { - ULONG size = GetFileSize(handle, NULL); - if (size == INVALID_FILE_SIZE) - return -1; + ULONG size = GetFileSize(handle, NULL); + if (size == INVALID_FILE_SIZE) + return -1; - return size; + return size; } #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread) { - return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL); + return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL); } #else #define GetSizeOfFile(handle) _GetSizeOfFile(handle) static LONG _GetSizeOfFile(FILEHANDLE handle) { - LONG size; - fseek(handle, 0, SEEK_END); - size = ftell(handle); - fseek(handle, 0, SEEK_SET); - return size; + LONG size; + fseek(handle, 0, SEEK_END); + size = ftell(handle); + fseek(handle, 0, SEEK_SET); + return size; } #define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread) static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread) { - *bytesread = fread(buffer, 1, size, handle); - return *bytesread == size; + *bytesread = fread(buffer, 1, size, handle); + return *bytesread == size; } #endif @@ -60,29 +58,29 @@ CDFParser::CDFParser() * FUNCTION: Default constructor */ { - InfFileOnly = false; - DontGenerateInf = false; + InfFileOnly = false; + DontGenerateInf = false; - FileBuffer = NULL; - FileLoaded = false; - CurrentOffset = 0; - CurrentLine = 0; - CabinetCreated = false; - DiskCreated = false; - FolderCreated = false; - CabinetName = NULL; - DiskLabel = NULL; - MaxDiskSize = NULL; + FileBuffer = NULL; + FileLoaded = false; + CurrentOffset = 0; + CurrentLine = 0; + CabinetCreated = false; + DiskCreated = false; + FolderCreated = false; + CabinetName = NULL; + DiskLabel = NULL; + MaxDiskSize = NULL; - MaxDiskSizeAllSet = false; - CabinetNameTemplateSet = false; - DiskLabelTemplateSet = false; - InfFileNameSet = false; + MaxDiskSizeAllSet = false; + CabinetNameTemplateSet = false; + DiskLabelTemplateSet = false; + InfFileNameSet = false; - InfModeEnabled = false; - InfFileHandle = NULL; + InfModeEnabled = false; + InfFileHandle = NULL; - strcpy(FileRelativePath, ""); + strcpy(FileRelativePath, ""); } CDFParser::~CDFParser() @@ -90,113 +88,113 @@ CDFParser::~CDFParser() * FUNCTION: Default destructor */ { - PCABINET_NAME CNPrev; - PCABINET_NAME CNNext; - PDISK_NUMBER DNPrev; - PDISK_NUMBER DNNext; + PCABINET_NAME CNPrev; + PCABINET_NAME CNNext; + PDISK_NUMBER DNPrev; + PDISK_NUMBER DNNext; - if (FileBuffer) - FreeMemory(FileBuffer); - CNNext = CabinetName; - while (CNNext != NULL) - { - CNPrev = CNNext->Next; - FreeMemory(CNNext); - CNNext = CNPrev; - } - CNNext = DiskLabel; - while (CNNext != NULL) - { - CNPrev = CNNext->Next; - FreeMemory(CNNext); - CNNext = CNPrev; - } - DNNext = MaxDiskSize; - while (DNNext != NULL) - { - DNPrev = DNNext->Next; - FreeMemory(DNNext); - DNNext = DNPrev; - } + if (FileBuffer) + FreeMemory(FileBuffer); + CNNext = CabinetName; + while (CNNext != NULL) + { + CNPrev = CNNext->Next; + FreeMemory(CNNext); + CNNext = CNPrev; + } + CNNext = DiskLabel; + while (CNNext != NULL) + { + CNPrev = CNNext->Next; + FreeMemory(CNNext); + CNNext = CNPrev; + } + DNNext = MaxDiskSize; + while (DNNext != NULL) + { + DNPrev = DNNext->Next; + FreeMemory(DNNext); + DNNext = DNPrev; + } - if (InfFileHandle != NULL) - CloseFile(InfFileHandle); + if (InfFileHandle != NULL) + CloseFile(InfFileHandle); } void CDFParser::WriteInfLine(char* InfLine) { - char buf[MAX_PATH]; - char eolbuf[2]; - char* destpath; + char buf[MAX_PATH]; + char eolbuf[2]; + char* destpath; #if defined(WIN32) - ULONG BytesWritten; + ULONG BytesWritten; #endif - if (DontGenerateInf) - return; + if (DontGenerateInf) + return; - if (InfFileHandle == NULL) - { - if (!InfFileNameSet) - /* FIXME: Use cabinet name with extension .inf */ - return; + if (InfFileHandle == NULL) + { + if (!InfFileNameSet) + /* FIXME: Use cabinet name with extension .inf */ + return; - destpath = GetDestinationPath(); - if (strlen(destpath) > 0) - { - strcpy(buf, destpath); - strcat(buf, InfFileName); - } - else - strcpy(buf, InfFileName); + destpath = GetDestinationPath(); + if (strlen(destpath) > 0) + { + strcpy(buf, destpath); + strcat(buf, InfFileName); + } + else + strcpy(buf, InfFileName); - /* Create .inf file, overwrite if it already exists */ + /* Create .inf file, overwrite if it already exists */ #if defined(WIN32) - InfFileHandle = CreateFile(buf, // Create this file - GENERIC_WRITE, // Open for writing - 0, // No sharing - NULL, // No security - CREATE_ALWAYS, // Create or overwrite - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (InfFileHandle == INVALID_HANDLE_VALUE) - { - DPRINT(MID_TRACE, ("Error creating '%lu'.\n", (ULONG)GetLastError())); - return; - } + InfFileHandle = CreateFile(buf, // Create this file + GENERIC_WRITE, // Open for writing + 0, // No sharing + NULL, // No security + CREATE_ALWAYS, // Create or overwrite + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (InfFileHandle == INVALID_HANDLE_VALUE) + { + DPRINT(MID_TRACE, ("Error creating '%lu'.\n", (ULONG)GetLastError())); + return; + } #else /* !WIN32 */ - InfFileHandle = fopen(buf, "wb"); - if (InfFileHandle == NULL) - { - DPRINT(MID_TRACE, ("Error creating '%lu'.\n", (ULONG)errno)); - return; - } + InfFileHandle = fopen(buf, "wb"); + if (InfFileHandle == NULL) + { + DPRINT(MID_TRACE, ("Error creating '%lu'.\n", (ULONG)errno)); + return; + } #endif - } + } #if defined(WIN32) - if (!WriteFile(InfFileHandle, InfLine, (DWORD)strlen(InfLine), (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); - return; - } + if (!WriteFile(InfFileHandle, InfLine, (DWORD)strlen(InfLine), (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); + return; + } #else - if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1) - return; + if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1) + return; #endif - eolbuf[0] = 0x0d; - eolbuf[1] = 0x0a; + eolbuf[0] = 0x0d; + eolbuf[1] = 0x0a; #if defined(WIN32) - if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), (LPDWORD)&BytesWritten, NULL)) - { - DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); - return; - } + if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), (LPDWORD)&BytesWritten, NULL)) + { + DPRINT(MID_TRACE, ("ERROR WRITING '%lu'.\n", (ULONG)GetLastError())); + return; + } #else - if (fwrite(eolbuf, 1, sizeof(eolbuf), InfFileHandle) < 1) - return; + if (fwrite(eolbuf, 1, sizeof(eolbuf), InfFileHandle) < 1) + return; #endif } @@ -210,60 +208,60 @@ ULONG CDFParser::Load(char* FileName) * Status of operation */ { - ULONG BytesRead; - LONG FileSize; + ULONG BytesRead; + LONG FileSize; - if (FileLoaded) - return CAB_STATUS_SUCCESS; + if (FileLoaded) + return CAB_STATUS_SUCCESS; - /* Create cabinet file, overwrite if it already exists */ + /* Create cabinet file, overwrite if it already exists */ #if defined(WIN32) - FileHandle = CreateFile(FileName, // Create this file - GENERIC_READ, // Open for reading - 0, // No sharing - NULL, // No security - OPEN_EXISTING, // Open the file - FILE_ATTRIBUTE_NORMAL, // Normal file - NULL); // No attribute template - if (FileHandle == INVALID_HANDLE_VALUE) - return CAB_STATUS_CANNOT_OPEN; + FileHandle = CreateFile(FileName, // Create this file + GENERIC_READ, // Open for reading + 0, // No sharing + NULL, // No security + OPEN_EXISTING, // Open the file + FILE_ATTRIBUTE_NORMAL, // Normal file + NULL); // No attribute template + if (FileHandle == INVALID_HANDLE_VALUE) + return CAB_STATUS_CANNOT_OPEN; #else /* !WIN32 */ - FileHandle = fopen(FileName, "rb"); - if (FileHandle == NULL) - return CAB_STATUS_CANNOT_OPEN; + FileHandle = fopen(FileName, "rb"); + if (FileHandle == NULL) + return CAB_STATUS_CANNOT_OPEN; #endif - FileSize = GetSizeOfFile(FileHandle); - if (FileSize == -1) - { - CloseFile(FileHandle); - return CAB_STATUS_CANNOT_OPEN; - } + FileSize = GetSizeOfFile(FileHandle); + if (FileSize == -1) + { + CloseFile(FileHandle); + return CAB_STATUS_CANNOT_OPEN; + } - FileBufferSize = (ULONG)FileSize; + FileBufferSize = (ULONG)FileSize; - FileBuffer = (char*)AllocateMemory(FileBufferSize); - if (!FileBuffer) - { - CloseFile(FileHandle); - return CAB_STATUS_NOMEMORY; - } + FileBuffer = (char*)AllocateMemory(FileBufferSize); + if (!FileBuffer) + { + CloseFile(FileHandle); + return CAB_STATUS_NOMEMORY; + } - if (!ReadFileData(FileHandle, FileBuffer, FileBufferSize, &BytesRead)) - { - CloseFile(FileHandle); - FreeMemory(FileBuffer); - FileBuffer = NULL; - return CAB_STATUS_CANNOT_READ; - } + if (!ReadFileData(FileHandle, FileBuffer, FileBufferSize, &BytesRead)) + { + CloseFile(FileHandle); + FreeMemory(FileBuffer); + FileBuffer = NULL; + return CAB_STATUS_CANNOT_READ; + } - CloseFile(FileHandle); + CloseFile(FileHandle); - FileLoaded = true; + FileLoaded = true; - DPRINT(MAX_TRACE, ("File (%lu bytes)\n", FileBufferSize)); + DPRINT(MAX_TRACE, ("File (%lu bytes)\n", FileBufferSize)); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -274,153 +272,153 @@ ULONG CDFParser::Parse() * Status of operation */ { - bool Command; - ULONG Status; + bool Command; + ULONG Status; - if (!FileLoaded) - return CAB_STATUS_NOFILE; + if (!FileLoaded) + return CAB_STATUS_NOFILE; - while (ReadLine()) - { - Command = false; + while (ReadLine()) + { + Command = false; - if (InfModeEnabled) - { - bool WriteLine = true; - while (CurrentToken != TokenEnd) - { - switch (CurrentToken) - { - case TokenIdentifier: - if (Command) - { - /* Command */ - Status = PerformCommand(); - if (Status == CAB_STATUS_FAILURE) - WriteLine = true; - else - if (!InfModeEnabled) - WriteLine = false; + if (InfModeEnabled) + { + bool WriteLine = true; + while (CurrentToken != TokenEnd) + { + switch (CurrentToken) + { + case TokenIdentifier: + if (Command) + { + /* Command */ + Status = PerformCommand(); + if (Status == CAB_STATUS_FAILURE) + WriteLine = true; + else + if (!InfModeEnabled) + WriteLine = false; - CurrentToken = TokenEnd; - continue; - } - else - { - WriteLine = true; - CurrentToken = TokenEnd; - continue; - } - break; + CurrentToken = TokenEnd; + continue; + } + else + { + WriteLine = true; + CurrentToken = TokenEnd; + continue; + } + break; - case TokenSpace: - break; + case TokenSpace: + break; - case TokenPeriod: - Command = true; - break; + case TokenPeriod: + Command = true; + break; - default: - WriteLine = true; - CurrentToken = TokenEnd; - continue; - } - NextToken(); - } - if (WriteLine) - WriteInfLine(Line); - } - else - { - while (CurrentToken != TokenEnd) - { - switch (CurrentToken) - { - case TokenInteger: - sprintf(CurrentString, "%lu", CurrentInteger); - case TokenIdentifier: - case TokenString: - if (Command) - { - /* Command */ - Status = PerformCommand(); + default: + WriteLine = true; + CurrentToken = TokenEnd; + continue; + } + NextToken(); + } + if (WriteLine) + WriteInfLine(Line); + } + else + { + while (CurrentToken != TokenEnd) + { + switch (CurrentToken) + { + case TokenInteger: + sprintf(CurrentString, "%lu", CurrentInteger); + case TokenIdentifier: + case TokenString: + if (Command) + { + /* Command */ + Status = PerformCommand(); - if (Status == CAB_STATUS_FAILURE) - { - printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); - DPRINT(MID_TRACE, ("Error while executing command.\n")); - } + if (Status == CAB_STATUS_FAILURE) + { + printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); + DPRINT(MID_TRACE, ("Error while executing command.\n")); + } - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - else - { - /* File copy */ - Status = PerformFileCopy(); + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + else + { + /* File copy */ + Status = PerformFileCopy(); - if (Status != CAB_STATUS_SUCCESS) - { - printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); - DPRINT(MID_TRACE, ("Error while copying file.\n")); - } + if (Status != CAB_STATUS_SUCCESS) + { + printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); + DPRINT(MID_TRACE, ("Error while copying file.\n")); + } - if (Status != CAB_STATUS_SUCCESS) - return Status; - } - break; + if (Status != CAB_STATUS_SUCCESS) + return Status; + } + break; - case TokenSpace: - break; + case TokenSpace: + break; - case TokenSemi: - CurrentToken = TokenEnd; - continue; + case TokenSemi: + CurrentToken = TokenEnd; + continue; - case TokenPeriod: - Command = true; - break; + case TokenPeriod: + Command = true; + break; - default: - printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); - DPRINT(MID_TRACE, ("Token is (%lu).\n", (ULONG)CurrentToken)); - return CAB_STATUS_SUCCESS; - } - NextToken(); - } - } - } + default: + printf("Directive file contains errors at line %lu.\n", (ULONG)CurrentLine); + DPRINT(MID_TRACE, ("Token is (%lu).\n", (ULONG)CurrentToken)); + return CAB_STATUS_SUCCESS; + } + NextToken(); + } + } + } - if (!InfFileOnly) - { - printf("\nWriting cabinet. This may take a while...\n\n"); + if (!InfFileOnly) + { + printf("\nWriting cabinet. This may take a while...\n\n"); - if (DiskCreated) - { - Status = WriteDisk(false); - if (Status == CAB_STATUS_SUCCESS) - Status = CloseDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); - return Status; - } - } + if (DiskCreated) + { + Status = WriteDisk(false); + if (Status == CAB_STATUS_SUCCESS) + Status = CloseDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); + return Status; + } + } - if (CabinetCreated) - { - Status = CloseCabinet(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot close cabinet (%lu).\n", (ULONG)Status)); - return Status; - } - } + if (CabinetCreated) + { + Status = CloseCabinet(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot close cabinet (%lu).\n", (ULONG)Status)); + return Status; + } + } - printf("\nDone.\n"); - } + printf("\nDone.\n"); + } - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -431,10 +429,10 @@ void CDFParser::SetFileRelativePath(char* Path) * Path = Pointer to string with path */ { - strcpy(FileRelativePath, Path); - ConvertPath(FileRelativePath, false); - if (strlen(FileRelativePath) > 0) - NormalizePath(FileRelativePath, MAX_PATH); + strcpy(FileRelativePath, Path); + ConvertPath(FileRelativePath, false); + if (strlen(FileRelativePath) > 0) + NormalizePath(FileRelativePath, MAX_PATH); } @@ -448,45 +446,45 @@ bool CDFParser::OnDiskLabel(ULONG Number, char* Label) * true if a disk label was returned, false if not */ { - char Buffer[20]; - ULONG i; - int j; - char ch; + char Buffer[20]; + ULONG i; + int j; + char ch; - Number += 1; + Number += 1; - DPRINT(MID_TRACE, ("Giving disk (%lu) a label...\n", (ULONG)Number)); + DPRINT(MID_TRACE, ("Giving disk (%lu) a label...\n", (ULONG)Number)); - if (GetDiskName(&DiskLabel, Number, Label)) - return true; + if (GetDiskName(&DiskLabel, Number, Label)) + return true; - if (DiskLabelTemplateSet) - { - j = 0; - strcpy(Label, ""); - for (i = 0; i < strlen(DiskLabelTemplate); i++) - { - ch = DiskLabelTemplate[i]; - if (ch == '*') - { - sprintf(Buffer, "%lu", Number); - strcat(Label, Buffer); - j += (LONG)strlen(Buffer); - } - else - { - Label[j] = ch; - j++; - } - Label[j] = '\0'; - } + if (DiskLabelTemplateSet) + { + j = 0; + strcpy(Label, ""); + for (i = 0; i < strlen(DiskLabelTemplate); i++) + { + ch = DiskLabelTemplate[i]; + if (ch == '*') + { + sprintf(Buffer, "%lu", Number); + strcat(Label, Buffer); + j += (LONG)strlen(Buffer); + } + else + { + Label[j] = ch; + j++; + } + Label[j] = '\0'; + } - DPRINT(MID_TRACE, ("Giving disk (%s) as a label...\n", Label)); + DPRINT(MID_TRACE, ("Giving disk (%s) as a label...\n", Label)); - return true; - } - else - return false; + return true; + } + else + return false; } @@ -500,48 +498,48 @@ bool CDFParser::OnCabinetName(ULONG Number, char* Name) * true if a cabinet name was returned, false if not */ { - char Buffer[MAX_PATH]; - ULONG i; - int j; - char ch; + char Buffer[MAX_PATH]; + ULONG i; + int j; + char ch; - Number += 1; + Number += 1; - DPRINT(MID_TRACE, ("Giving cabinet (%lu) a name...\n", (ULONG)Number)); + DPRINT(MID_TRACE, ("Giving cabinet (%lu) a name...\n", (ULONG)Number)); - if (GetDiskName(&CabinetName, Number, Buffer)) - { - strcpy(Name, GetDestinationPath()); - strcat(Name, Buffer); - return true; - } + if (GetDiskName(&CabinetName, Number, Buffer)) + { + strcpy(Name, GetDestinationPath()); + strcat(Name, Buffer); + return true; + } - if (CabinetNameTemplateSet) - { - strcpy(Name, GetDestinationPath()); - j = (LONG)strlen(Name); - for (i = 0; i < strlen(CabinetNameTemplate); i++) - { - ch = CabinetNameTemplate[i]; - if (ch == '*') - { - sprintf(Buffer, "%lu", Number); - strcat(Name, Buffer); - j += (LONG)strlen(Buffer); - } - else - { - Name[j] = ch; - j++; - } - Name[j] = '\0'; - } + if (CabinetNameTemplateSet) + { + strcpy(Name, GetDestinationPath()); + j = (LONG)strlen(Name); + for (i = 0; i < strlen(CabinetNameTemplate); i++) + { + ch = CabinetNameTemplate[i]; + if (ch == '*') + { + sprintf(Buffer, "%lu", Number); + strcat(Name, Buffer); + j += (LONG)strlen(Buffer); + } + else + { + Name[j] = ch; + j++; + } + Name[j] = '\0'; + } - DPRINT(MID_TRACE, ("Giving cabinet (%s) as a name...\n", Name)); - return true; - } - else - return false; + DPRINT(MID_TRACE, ("Giving cabinet (%s) as a name...\n", Name)); + return true; + } + else + return false; } @@ -556,30 +554,30 @@ bool CDFParser::SetDiskName(PCABINET_NAME *List, ULONG Number, char* String) * false if there was not enough free memory available */ { - PCABINET_NAME CN; + PCABINET_NAME CN; - CN = *List; - while (CN != NULL) - { - if (CN->DiskNumber == Number) - { - strcpy(CN->Name, String); - return true; - } - CN = CN->Next; - } + CN = *List; + while (CN != NULL) + { + if (CN->DiskNumber == Number) + { + strcpy(CN->Name, String); + return true; + } + CN = CN->Next; + } - CN = (PCABINET_NAME)AllocateMemory(sizeof(CABINET_NAME)); - if (!CN) - return false; + CN = (PCABINET_NAME)AllocateMemory(sizeof(CABINET_NAME)); + if (!CN) + return false; - CN->DiskNumber = Number; - strcpy(CN->Name, String); + CN->DiskNumber = Number; + strcpy(CN->Name, String); - CN->Next = *List; - *List = CN; + CN->Next = *List; + *List = CN; - return true; + return true; } @@ -594,20 +592,20 @@ bool CDFParser::GetDiskName(PCABINET_NAME *List, ULONG Number, char* String) * false if there was not enough free memory available */ { - PCABINET_NAME CN; + PCABINET_NAME CN; - CN = *List; - while (CN != NULL) - { - if (CN->DiskNumber == Number) - { - strcpy(String, CN->Name); - return true; - } - CN = CN->Next; - } + CN = *List; + while (CN != NULL) + { + if (CN->DiskNumber == Number) + { + strcpy(String, CN->Name); + return true; + } + CN = CN->Next; + } - return false; + return false; } @@ -622,30 +620,30 @@ bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value) * false if there was not enough free memory available */ { - PDISK_NUMBER DN; + PDISK_NUMBER DN; - DN = *List; - while (DN != NULL) - { - if (DN->DiskNumber == Number) - { - DN->Number = Value; - return true; - } - DN = DN->Next; - } + DN = *List; + while (DN != NULL) + { + if (DN->DiskNumber == Number) + { + DN->Number = Value; + return true; + } + DN = DN->Next; + } - DN = (PDISK_NUMBER)AllocateMemory(sizeof(DISK_NUMBER)); - if (!DN) - return false; + DN = (PDISK_NUMBER)AllocateMemory(sizeof(DISK_NUMBER)); + if (!DN) + return false; - DN->DiskNumber = Number; - DN->Number = Value; + DN->DiskNumber = Number; + DN->Number = Value; - DN->Next = *List; - *List = DN; + DN->Next = *List; + *List = DN; - return true; + return true; } @@ -660,20 +658,20 @@ bool CDFParser::GetDiskNumber(PDISK_NUMBER *List, ULONG Number, PULONG Value) * true if the entry was found */ { - PDISK_NUMBER DN; + PDISK_NUMBER DN; - DN = *List; - while (DN != NULL) - { - if (DN->DiskNumber == Number) - { - *Value = DN->Number; - return true; - } - DN = DN->Next; - } + DN = *List; + while (DN != NULL) + { + if (DN->DiskNumber == Number) + { + *Value = DN->Number; + return true; + } + DN = DN->Next; + } - return false; + return false; } @@ -687,9 +685,9 @@ bool CDFParser::DoDiskLabel(ULONG Number, char* Label) * false if there was not enough free memory available */ { - DPRINT(MID_TRACE, ("Setting label of disk (%lu) to '%s'\n", (ULONG)Number, Label)); + DPRINT(MID_TRACE, ("Setting label of disk (%lu) to '%s'\n", (ULONG)Number, Label)); - return SetDiskName(&DiskLabel, Number, Label); + return SetDiskName(&DiskLabel, Number, Label); } @@ -700,10 +698,10 @@ void CDFParser::DoDiskLabelTemplate(char* Template) * Template = Pointer to disk label template */ { - DPRINT(MID_TRACE, ("Setting disk label template to '%s'\n", Template)); + DPRINT(MID_TRACE, ("Setting disk label template to '%s'\n", Template)); - strcpy(DiskLabelTemplate, Template); - DiskLabelTemplateSet = true; + strcpy(DiskLabelTemplate, Template); + DiskLabelTemplateSet = true; } @@ -717,9 +715,9 @@ bool CDFParser::DoCabinetName(ULONG Number, char* Name) * false if there was not enough free memory available */ { - DPRINT(MID_TRACE, ("Setting name of cabinet (%lu) to '%s'\n", (ULONG)Number, Name)); + DPRINT(MID_TRACE, ("Setting name of cabinet (%lu) to '%s'\n", (ULONG)Number, Name)); - return SetDiskName(&CabinetName, Number, Name); + return SetDiskName(&CabinetName, Number, Name); } @@ -730,10 +728,10 @@ void CDFParser::DoCabinetNameTemplate(char* Template) * Template = Pointer to cabinet name template */ { - DPRINT(MID_TRACE, ("Setting cabinet name template to '%s'\n", Template)); + DPRINT(MID_TRACE, ("Setting cabinet name template to '%s'\n", Template)); - strcpy(CabinetNameTemplate, Template); - CabinetNameTemplateSet = true; + strcpy(CabinetNameTemplate, Template); + CabinetNameTemplateSet = true; } @@ -749,95 +747,95 @@ ULONG CDFParser::DoMaxDiskSize(bool NumberValid, ULONG Number) * Standard sizes are 2.88M, 1.44M, 1.25M, 1.2M, 720K, 360K, and CDROM */ { - ULONG A, B, Value; + ULONG A, B, Value; - if (IsNextToken(TokenInteger, true)) - { - A = CurrentInteger; + if (IsNextToken(TokenInteger, true)) + { + A = CurrentInteger; - if (IsNextToken(TokenPeriod, false)) - { - if (!IsNextToken(TokenInteger, false)) - return CAB_STATUS_FAILURE; + if (IsNextToken(TokenPeriod, false)) + { + if (!IsNextToken(TokenInteger, false)) + return CAB_STATUS_FAILURE; - B = CurrentInteger; + B = CurrentInteger; - } - else - B = 0; + } + else + B = 0; - if (CurrentToken == TokenIdentifier) - { - switch (CurrentString[0]) - { - case 'K': - if (B != 0) - return CAB_STATUS_FAILURE; + if (CurrentToken == TokenIdentifier) + { + switch (CurrentString[0]) + { + case 'K': + if (B != 0) + return CAB_STATUS_FAILURE; - if (A == 720) - /* 720K disk */ - Value = 730112; - else if (A == 360) - /* 360K disk */ - Value = 362496; - else - return CAB_STATUS_FAILURE; - break; + if (A == 720) + /* 720K disk */ + Value = 730112; + else if (A == 360) + /* 360K disk */ + Value = 362496; + else + return CAB_STATUS_FAILURE; + break; - case 'M': - if (A == 1) - { - if (B == 44) - /* 1.44M disk */ - Value = 1457664; - else if (B == 25) - /* 1.25M disk */ - Value = 1300000; // FIXME: Value? - else if (B == 2) - /* 1.2M disk */ - Value = 1213952; - else - return CAB_STATUS_FAILURE; - } - else if (A == 2) - { - if (B == 88) - /* 2.88M disk */ - Value = 2915328; - else - return CAB_STATUS_FAILURE; - } - else - return CAB_STATUS_FAILURE; - break; + case 'M': + if (A == 1) + { + if (B == 44) + /* 1.44M disk */ + Value = 1457664; + else if (B == 25) + /* 1.25M disk */ + Value = 1300000; // FIXME: Value? + else if (B == 2) + /* 1.2M disk */ + Value = 1213952; + else + return CAB_STATUS_FAILURE; + } + else if (A == 2) + { + if (B == 88) + /* 2.88M disk */ + Value = 2915328; + else + return CAB_STATUS_FAILURE; + } + else + return CAB_STATUS_FAILURE; + break; - default: - DPRINT(MID_TRACE, ("Bad suffix (%c)\n", CurrentString[0])); - return CAB_STATUS_FAILURE; - } - } - else - Value = A; - } - else - { - if ((CurrentToken != TokenString) && - (strcasecmp(CurrentString, "CDROM") != 0)) - return CAB_STATUS_FAILURE; - /* CDROM */ - Value = 640*1024*1024; // FIXME: Correct size for CDROM? - } + default: + DPRINT(MID_TRACE, ("Bad suffix (%c)\n", CurrentString[0])); + return CAB_STATUS_FAILURE; + } + } + else + Value = A; + } + else + { + if ((CurrentToken != TokenString) && + (strcasecmp(CurrentString, "CDROM") != 0)) + return CAB_STATUS_FAILURE; + /* CDROM */ + Value = 640*1024*1024; // FIXME: Correct size for CDROM? + } - if (NumberValid) - return (SetDiskNumber(&MaxDiskSize, Number, Value)? - CAB_STATUS_SUCCESS : CAB_STATUS_FAILURE); + if (NumberValid) + return (SetDiskNumber(&MaxDiskSize, Number, Value)? + CAB_STATUS_SUCCESS : CAB_STATUS_FAILURE); - MaxDiskSizeAll = Value; - MaxDiskSizeAllSet = true; + MaxDiskSizeAll = Value; + MaxDiskSizeAllSet = true; - SetMaxDiskSize(Value); + SetMaxDiskSize(Value); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -848,10 +846,10 @@ void CDFParser::DoInfFileName(char* FileName) * FileName = Pointer to .inf filename */ { - DPRINT(MID_TRACE, ("Setting .inf filename to '%s'\n", FileName)); + DPRINT(MID_TRACE, ("Setting .inf filename to '%s'\n", FileName)); - strcpy(InfFileName, FileName); - InfFileNameSet = true; + strcpy(InfFileName, FileName); + InfFileNameSet = true; } ULONG CDFParser::SetupNewDisk() @@ -861,18 +859,18 @@ ULONG CDFParser::SetupNewDisk() * Status of operation */ { - ULONG Value; + ULONG Value; - if (!GetDiskNumber(&MaxDiskSize, GetCurrentDiskNumber(), &Value)) - { - if (MaxDiskSizeAllSet) - Value = MaxDiskSizeAll; - else - Value = 0; - } - SetMaxDiskSize(Value); + if (!GetDiskNumber(&MaxDiskSize, GetCurrentDiskNumber(), &Value)) + { + if (MaxDiskSizeAllSet) + Value = MaxDiskSizeAll; + else + Value = 0; + } + SetMaxDiskSize(Value); - return CAB_STATUS_SUCCESS; + return CAB_STATUS_SUCCESS; } @@ -883,92 +881,92 @@ ULONG CDFParser::PerformSetCommand() * Status of operation */ { - SETTYPE SetType; - bool NumberValid = false; - ULONG Number = 0; + SETTYPE SetType; + bool NumberValid = false; + ULONG Number = 0; - if (!IsNextToken(TokenIdentifier, true)) - return CAB_STATUS_FAILURE; + if (!IsNextToken(TokenIdentifier, true)) + return CAB_STATUS_FAILURE; - if (strcasecmp(CurrentString, "DiskLabel") == 0) - SetType = stDiskLabel; - else if (strcasecmp(CurrentString, "DiskLabelTemplate") == 0) - SetType = stDiskLabelTemplate; - else if (strcasecmp(CurrentString, "CabinetName") == 0) - SetType = stCabinetName; - else if (strcasecmp(CurrentString, "CabinetNameTemplate") == 0) - SetType = stCabinetNameTemplate; - else if (strcasecmp(CurrentString, "MaxDiskSize") == 0) - SetType = stMaxDiskSize; - else if (strcasecmp(CurrentString, "InfFileName") == 0) - SetType = stInfFileName; - else - return CAB_STATUS_FAILURE; + if (strcasecmp(CurrentString, "DiskLabel") == 0) + SetType = stDiskLabel; + else if (strcasecmp(CurrentString, "DiskLabelTemplate") == 0) + SetType = stDiskLabelTemplate; + else if (strcasecmp(CurrentString, "CabinetName") == 0) + SetType = stCabinetName; + else if (strcasecmp(CurrentString, "CabinetNameTemplate") == 0) + SetType = stCabinetNameTemplate; + else if (strcasecmp(CurrentString, "MaxDiskSize") == 0) + SetType = stMaxDiskSize; + else if (strcasecmp(CurrentString, "InfFileName") == 0) + SetType = stInfFileName; + else + return CAB_STATUS_FAILURE; - if ((SetType == stDiskLabel) || (SetType == stCabinetName)) - { - if (!IsNextToken(TokenInteger, false)) - return CAB_STATUS_FAILURE; - Number = CurrentInteger; + if ((SetType == stDiskLabel) || (SetType == stCabinetName)) + { + if (!IsNextToken(TokenInteger, false)) + return CAB_STATUS_FAILURE; + Number = CurrentInteger; - if (!IsNextToken(TokenEqual, true)) - return CAB_STATUS_FAILURE; - } - else if (SetType == stMaxDiskSize) - { - if (IsNextToken(TokenInteger, false)) - { - NumberValid = true; - Number = CurrentInteger; - } - else - { - NumberValid = false; - while (CurrentToken == TokenSpace) - NextToken(); - if (CurrentToken != TokenEqual) - return CAB_STATUS_FAILURE; - } - } - else if (!IsNextToken(TokenEqual, true)) - return CAB_STATUS_FAILURE; + if (!IsNextToken(TokenEqual, true)) + return CAB_STATUS_FAILURE; + } + else if (SetType == stMaxDiskSize) + { + if (IsNextToken(TokenInteger, false)) + { + NumberValid = true; + Number = CurrentInteger; + } + else + { + NumberValid = false; + while (CurrentToken == TokenSpace) + NextToken(); + if (CurrentToken != TokenEqual) + return CAB_STATUS_FAILURE; + } + } + else if (!IsNextToken(TokenEqual, true)) + return CAB_STATUS_FAILURE; - if (SetType != stMaxDiskSize) - { - if (!IsNextToken(TokenString, true)) - return CAB_STATUS_FAILURE; - } + if (SetType != stMaxDiskSize) + { + if (!IsNextToken(TokenString, true)) + return CAB_STATUS_FAILURE; + } - switch (SetType) - { - case stDiskLabel: - if (!DoDiskLabel(Number, CurrentString)) - DPRINT(MIN_TRACE, ("Not enough available free memory.\n")); - return CAB_STATUS_SUCCESS; + switch (SetType) + { + case stDiskLabel: + if (!DoDiskLabel(Number, CurrentString)) + DPRINT(MIN_TRACE, ("Not enough available free memory.\n")); + return CAB_STATUS_SUCCESS; - case stCabinetName: - if (!DoCabinetName(Number, CurrentString)) - DPRINT(MIN_TRACE, ("Not enough available free memory.\n")); - return CAB_STATUS_SUCCESS; + case stCabinetName: + if (!DoCabinetName(Number, CurrentString)) + DPRINT(MIN_TRACE, ("Not enough available free memory.\n")); + return CAB_STATUS_SUCCESS; - case stDiskLabelTemplate: - DoDiskLabelTemplate(CurrentString); - return CAB_STATUS_SUCCESS; + case stDiskLabelTemplate: + DoDiskLabelTemplate(CurrentString); + return CAB_STATUS_SUCCESS; - case stCabinetNameTemplate: - DoCabinetNameTemplate(CurrentString); - return CAB_STATUS_SUCCESS; + case stCabinetNameTemplate: + DoCabinetNameTemplate(CurrentString); + return CAB_STATUS_SUCCESS; - case stMaxDiskSize: - return DoMaxDiskSize(NumberValid, Number); + case stMaxDiskSize: + return DoMaxDiskSize(NumberValid, Number); - case stInfFileName: - DoInfFileName(CurrentString); - return CAB_STATUS_SUCCESS; + case stInfFileName: + DoInfFileName(CurrentString); + return CAB_STATUS_SUCCESS; - default: - return CAB_STATUS_FAILURE; - } + default: + return CAB_STATUS_FAILURE; + } } @@ -979,79 +977,79 @@ ULONG CDFParser::PerformNewCommand() * Status of operation */ { - NEWTYPE NewType; - ULONG Status; + NEWTYPE NewType; + ULONG Status; - if (!IsNextToken(TokenIdentifier, true)) - return CAB_STATUS_FAILURE; + if (!IsNextToken(TokenIdentifier, true)) + return CAB_STATUS_FAILURE; - if (strcasecmp(CurrentString, "Disk") == 0) - NewType = ntDisk; - else if (strcasecmp(CurrentString, "Cabinet") == 0) - NewType = ntCabinet; - else if (strcasecmp(CurrentString, "Folder") == 0) - NewType = ntFolder; - else - return CAB_STATUS_FAILURE; + if (strcasecmp(CurrentString, "Disk") == 0) + NewType = ntDisk; + else if (strcasecmp(CurrentString, "Cabinet") == 0) + NewType = ntCabinet; + else if (strcasecmp(CurrentString, "Folder") == 0) + NewType = ntFolder; + else + return CAB_STATUS_FAILURE; - switch (NewType) - { - case ntDisk: - if (DiskCreated) - { - Status = WriteDisk(true); - if (Status == CAB_STATUS_SUCCESS) - Status = CloseDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); - return CAB_STATUS_SUCCESS; - } - DiskCreated = false; - } + switch (NewType) + { + case ntDisk: + if (DiskCreated) + { + Status = WriteDisk(true); + if (Status == CAB_STATUS_SUCCESS) + Status = CloseDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); + return CAB_STATUS_SUCCESS; + } + DiskCreated = false; + } - Status = NewDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot create disk (%lu).\n", (ULONG)Status)); - return CAB_STATUS_SUCCESS; - } - DiskCreated = true; - SetupNewDisk(); - return CAB_STATUS_SUCCESS; + Status = NewDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot create disk (%lu).\n", (ULONG)Status)); + return CAB_STATUS_SUCCESS; + } + DiskCreated = true; + SetupNewDisk(); + return CAB_STATUS_SUCCESS; - case ntCabinet: - if (DiskCreated) - { - Status = WriteDisk(true); - if (Status == CAB_STATUS_SUCCESS) - Status = CloseDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); - return CAB_STATUS_SUCCESS; - } - DiskCreated = false; - } + case ntCabinet: + if (DiskCreated) + { + Status = WriteDisk(true); + if (Status == CAB_STATUS_SUCCESS) + Status = CloseDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); + return CAB_STATUS_SUCCESS; + } + DiskCreated = false; + } - Status = NewCabinet(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); - return CAB_STATUS_SUCCESS; - } - DiskCreated = true; - SetupNewDisk(); - return CAB_STATUS_SUCCESS; + Status = NewCabinet(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); + return CAB_STATUS_SUCCESS; + } + DiskCreated = true; + SetupNewDisk(); + return CAB_STATUS_SUCCESS; - case ntFolder: - Status = NewFolder(); - ASSERT(Status == CAB_STATUS_SUCCESS); - return CAB_STATUS_SUCCESS; + case ntFolder: + Status = NewFolder(); + ASSERT(Status == CAB_STATUS_SUCCESS); + return CAB_STATUS_SUCCESS; - default: - return CAB_STATUS_FAILURE; - } + default: + return CAB_STATUS_FAILURE; + } } @@ -1062,8 +1060,8 @@ ULONG CDFParser::PerformInfBeginCommand() * Status of operation */ { - InfModeEnabled = true; - return CAB_STATUS_SUCCESS; + InfModeEnabled = true; + return CAB_STATUS_SUCCESS; } @@ -1074,8 +1072,8 @@ ULONG CDFParser::PerformInfEndCommand() * Status of operation */ { - InfModeEnabled = false; - return CAB_STATUS_SUCCESS; + InfModeEnabled = false; + return CAB_STATUS_SUCCESS; } @@ -1086,16 +1084,16 @@ ULONG CDFParser::PerformCommand() * Status of operation */ { - if (strcasecmp(CurrentString, "Set") == 0) - return PerformSetCommand(); - if (strcasecmp(CurrentString, "New") == 0) - return PerformNewCommand(); - if (strcasecmp(CurrentString, "InfBegin") == 0) - return PerformInfBeginCommand(); - if (strcasecmp(CurrentString, "InfEnd") == 0) - return PerformInfEndCommand(); + if (strcasecmp(CurrentString, "Set") == 0) + return PerformSetCommand(); + if (strcasecmp(CurrentString, "New") == 0) + return PerformNewCommand(); + if (strcasecmp(CurrentString, "InfBegin") == 0) + return PerformInfBeginCommand(); + if (strcasecmp(CurrentString, "InfEnd") == 0) + return PerformInfEndCommand(); - return CAB_STATUS_FAILURE; + return CAB_STATUS_FAILURE; } @@ -1106,137 +1104,137 @@ ULONG CDFParser::PerformFileCopy() * Status of operation */ { - ULONG Status; - ULONG i, j; - char ch; - char SrcName[MAX_PATH]; - char DstName[MAX_PATH]; - char InfLine[MAX_PATH]; - char Options[128]; - char BaseFilename[MAX_PATH]; + ULONG Status; + ULONG i, j; + char ch; + char SrcName[MAX_PATH]; + char DstName[MAX_PATH]; + char InfLine[MAX_PATH]; + char Options[128]; + char BaseFilename[MAX_PATH]; - *SrcName = '\0'; - *DstName = '\0'; - *Options = '\0'; + *SrcName = '\0'; + *DstName = '\0'; + *Options = '\0'; - // source file - i = CurrentChar; - while ((i < LineLength) && - ((ch = Line[i]) != ' ') && - (ch != 0x09) && - (ch != ';')) - { - CurrentString[i] = ch; - i++; - } - CurrentString[i] = '\0'; - CurrentToken = TokenString; - CurrentChar = i + 1; - strcpy(BaseFilename, CurrentString); - strcat(SrcName, BaseFilename); + // source file + i = CurrentChar; + while ((i < LineLength) && + ((ch = Line[i]) != ' ') && + (ch != 0x09) && + (ch != ';')) + { + CurrentString[i] = ch; + i++; + } + CurrentString[i] = '\0'; + CurrentToken = TokenString; + CurrentChar = i + 1; + strcpy(BaseFilename, CurrentString); + strcat(SrcName, BaseFilename); - // destination - SkipSpaces(); + // destination + SkipSpaces(); - if (CurrentToken != TokenEnd) - { - j = (ULONG)strlen(CurrentString); i = 0; - while ((CurrentChar + i < LineLength) && - ((ch = Line[CurrentChar + i]) != ' ') && - (ch != 0x09) && - (ch != ';')) - { - CurrentString[j + i] = ch; - i++; - } - CurrentString[j + i] = '\0'; - CurrentToken = TokenString; - CurrentChar += i + 1; - strcpy(DstName, CurrentString); - } + if (CurrentToken != TokenEnd) + { + j = (ULONG)strlen(CurrentString); i = 0; + while ((CurrentChar + i < LineLength) && + ((ch = Line[CurrentChar + i]) != ' ') && + (ch != 0x09) && + (ch != ';')) + { + CurrentString[j + i] = ch; + i++; + } + CurrentString[j + i] = '\0'; + CurrentToken = TokenString; + CurrentChar += i + 1; + strcpy(DstName, CurrentString); + } - // options (it may be empty) - SkipSpaces (); + // options (it may be empty) + SkipSpaces (); - if (CurrentToken != TokenEnd) - { - j = (ULONG)strlen(CurrentString); i = 0; - while ((CurrentChar + i < LineLength) && - ((ch = Line[CurrentChar + i]) != ' ') && - (ch != 0x09) && - (ch != ';')) - { - CurrentString[j + i] = ch; - i++; - } - CurrentString[j + i] = '\0'; - CurrentToken = TokenString; - CurrentChar += i + 1; - strcpy(Options, CurrentString); - } + if (CurrentToken != TokenEnd) + { + j = (ULONG)strlen(CurrentString); i = 0; + while ((CurrentChar + i < LineLength) && + ((ch = Line[CurrentChar + i]) != ' ') && + (ch != 0x09) && + (ch != ';')) + { + CurrentString[j + i] = ch; + i++; + } + CurrentString[j + i] = '\0'; + CurrentToken = TokenString; + CurrentChar += i + 1; + strcpy(Options, CurrentString); + } - if (!CabinetCreated) - { - DPRINT(MID_TRACE, ("Creating cabinet.\n")); + if (!CabinetCreated) + { + DPRINT(MID_TRACE, ("Creating cabinet.\n")); - Status = NewCabinet(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); - printf("Cannot create cabinet.\n"); - return CAB_STATUS_FAILURE; - } - CabinetCreated = true; + Status = NewCabinet(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); + printf("Cannot create cabinet.\n"); + return CAB_STATUS_FAILURE; + } + CabinetCreated = true; - DPRINT(MID_TRACE, ("Creating disk.\n")); + DPRINT(MID_TRACE, ("Creating disk.\n")); - Status = NewDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot create disk (%lu).\n", (ULONG)Status)); - printf("Cannot create disk.\n"); - return CAB_STATUS_FAILURE; - } - DiskCreated = true; - SetupNewDisk(); - } + Status = NewDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot create disk (%lu).\n", (ULONG)Status)); + printf("Cannot create disk.\n"); + return CAB_STATUS_FAILURE; + } + DiskCreated = true; + SetupNewDisk(); + } - DPRINT(MID_TRACE, ("Adding file: '%s' destination: '%s'.\n", SrcName, DstName)); + DPRINT(MID_TRACE, ("Adding file: '%s' destination: '%s'.\n", SrcName, DstName)); - Status = AddFile(SrcName); - if (Status == CAB_STATUS_CANNOT_OPEN) - { - strcpy(SrcName, FileRelativePath); - strcat(SrcName, BaseFilename); - Status = AddFile(SrcName); - } - switch (Status) - { - case CAB_STATUS_SUCCESS: - sprintf(InfLine, "%s=%s", GetFileName(SrcName), DstName); - WriteInfLine(InfLine); - break; + Status = AddFile(SrcName); + if (Status == CAB_STATUS_CANNOT_OPEN) + { + strcpy(SrcName, FileRelativePath); + strcat(SrcName, BaseFilename); + Status = AddFile(SrcName); + } + switch (Status) + { + case CAB_STATUS_SUCCESS: + sprintf(InfLine, "%s=%s", GetFileName(SrcName), DstName); + WriteInfLine(InfLine); + break; - case CAB_STATUS_CANNOT_OPEN: - if (strstr(Options,"optional")) - { - Status = CAB_STATUS_SUCCESS; - printf("Optional file does not exist: %s.\n", SrcName); - } - else - printf("File does not exist: %s.\n", SrcName); - - break; + case CAB_STATUS_CANNOT_OPEN: + if (strstr(Options,"optional")) + { + Status = CAB_STATUS_SUCCESS; + printf("Optional file does not exist: %s.\n", SrcName); + } + else + printf("File does not exist: %s.\n", SrcName); + + break; - case CAB_STATUS_NOMEMORY: - printf("Insufficient memory to add file: %s.\n", SrcName); - break; + case CAB_STATUS_NOMEMORY: + printf("Insufficient memory to add file: %s.\n", SrcName); + break; - default: - printf("Cannot add file: %s (%lu).\n", SrcName, Status); - break; - } - return Status; + default: + printf("Cannot add file: %s (%lu).\n", SrcName, Status); + break; + } + return Status; } @@ -1245,9 +1243,9 @@ void CDFParser::SkipSpaces() * FUNCTION: Skips any spaces in the current line */ { - NextToken(); - while (CurrentToken == TokenSpace) - NextToken(); + NextToken(); + while (CurrentToken == TokenSpace) + NextToken(); } @@ -1261,11 +1259,11 @@ bool CDFParser::IsNextToken(DFP_TOKEN Token, bool NoSpaces) * false if next token is diffrent from Token */ { - if (NoSpaces) - SkipSpaces(); - else - NextToken(); - return (CurrentToken == Token); + if (NoSpaces) + SkipSpaces(); + else + NextToken(); + return (CurrentToken == Token); } @@ -1276,35 +1274,35 @@ bool CDFParser::ReadLine() * true if there is a new line, false if not */ { - ULONG i, j; - char ch; + ULONG i, j; + char ch; - if (CurrentOffset >= FileBufferSize) - return false; + if (CurrentOffset >= FileBufferSize) + return false; - i = 0; - while (((j = CurrentOffset + i) < FileBufferSize) && (i < 127) && - ((ch = FileBuffer[j]) != 0x0D && (ch = FileBuffer[j]) != 0x0A)) - { - Line[i] = ch; - i++; - } + i = 0; + while (((j = CurrentOffset + i) < FileBufferSize) && (i < 127) && + ((ch = FileBuffer[j]) != 0x0D && (ch = FileBuffer[j]) != 0x0A)) + { + Line[i] = ch; + i++; + } - Line[i] = '\0'; - LineLength = i; + Line[i] = '\0'; + LineLength = i; - if ((FileBuffer[CurrentOffset + i] == 0x0D) && (FileBuffer[CurrentOffset + i + 1] == 0x0A)) - CurrentOffset++; + if ((FileBuffer[CurrentOffset + i] == 0x0D) && (FileBuffer[CurrentOffset + i + 1] == 0x0A)) + CurrentOffset++; - CurrentOffset += i + 1; + CurrentOffset += i + 1; - CurrentChar = 0; + CurrentChar = 0; - CurrentLine++; + CurrentLine++; - NextToken(); + NextToken(); - return true; + return true; } @@ -1313,85 +1311,85 @@ void CDFParser::NextToken() * FUNCTION: Reads the next token from the current line */ { - ULONG i; - char ch = ' '; + ULONG i; + char ch = ' '; - if (CurrentChar >= LineLength) - { - CurrentToken = TokenEnd; - return; - } + if (CurrentChar >= LineLength) + { + CurrentToken = TokenEnd; + return; + } - switch (Line[CurrentChar]) - { - case ' ': - case 0x09: - CurrentToken = TokenSpace; - break; + switch (Line[CurrentChar]) + { + case ' ': + case 0x09: + CurrentToken = TokenSpace; + break; - case ';': - CurrentToken = TokenSemi; - break; + case ';': + CurrentToken = TokenSemi; + break; - case '=': - CurrentToken = TokenEqual; - break; + case '=': + CurrentToken = TokenEqual; + break; - case '.': - CurrentToken = TokenPeriod; - break; + case '.': + CurrentToken = TokenPeriod; + break; - case '\\': - CurrentToken = TokenBackslash; - break; + case '\\': + CurrentToken = TokenBackslash; + break; - case '"': - i = 0; - while ((CurrentChar + i + 1 < LineLength) && - ((ch = Line[CurrentChar + i + 1]) != '"')) - { - CurrentString[i] = ch; - i++; - } - CurrentString[i] = '\0'; - CurrentToken = TokenString; - CurrentChar += i + 2; - return; + case '"': + i = 0; + while ((CurrentChar + i + 1 < LineLength) && + ((ch = Line[CurrentChar + i + 1]) != '"')) + { + CurrentString[i] = ch; + i++; + } + CurrentString[i] = '\0'; + CurrentToken = TokenString; + CurrentChar += i + 2; + return; - default: - i = 0; - while ((CurrentChar + i < LineLength) && - ((ch = Line[CurrentChar + i]) >= '0') && (ch <= '9')) - { - CurrentString[i] = ch; - i++; - } - if (i > 0) - { - CurrentString[i] = '\0'; - CurrentInteger = atoi((char*)CurrentString); - CurrentToken = TokenInteger; - CurrentChar += i; - return; - } - i = 0; - while (((CurrentChar + i < LineLength) && - (((ch = Line[CurrentChar + i]) >= 'a') && (ch <= 'z')) || - ((ch >= 'A') && (ch <= 'Z')) || (ch == '_'))) - { - CurrentString[i] = ch; - i++; - } - if (i > 0) - { - CurrentString[i] = '\0'; - CurrentToken = TokenIdentifier; - CurrentChar += i; - return; - } - CurrentToken = TokenEnd; - } - CurrentChar++; + default: + i = 0; + while ((CurrentChar + i < LineLength) && + ((ch = Line[CurrentChar + i]) >= '0') && (ch <= '9')) + { + CurrentString[i] = ch; + i++; + } + if (i > 0) + { + CurrentString[i] = '\0'; + CurrentInteger = atoi((char*)CurrentString); + CurrentToken = TokenInteger; + CurrentChar += i; + return; + } + i = 0; + while (((CurrentChar + i < LineLength) && + (((ch = Line[CurrentChar + i]) >= 'a') && (ch <= 'z')) || + ((ch >= 'A') && (ch <= 'Z')) || (ch == '_'))) + { + CurrentString[i] = ch; + i++; + } + if (i > 0) + { + CurrentString[i] = '\0'; + CurrentToken = TokenIdentifier; + CurrentChar += i; + return; + } + CurrentToken = TokenEnd; + } + CurrentChar++; } /* EOF */ diff --git a/reactos/tools/cabman/dfp.h b/reactos/tools/cabman/dfp.h index 22176cdd1d3..4c94fd34f1e 100755 --- a/reactos/tools/cabman/dfp.h +++ b/reactos/tools/cabman/dfp.h @@ -10,45 +10,45 @@ #include "cabinet.h" typedef struct _CABINET_NAME { - struct _CABINET_NAME *Next; - ULONG DiskNumber; - char Name[128]; + struct _CABINET_NAME *Next; + ULONG DiskNumber; + char Name[128]; } CABINET_NAME, *PCABINET_NAME; typedef struct _DISK_NUMBER { - struct _DISK_NUMBER *Next; - ULONG DiskNumber; - ULONG Number; + struct _DISK_NUMBER *Next; + ULONG DiskNumber; + ULONG Number; } DISK_NUMBER, *PDISK_NUMBER; typedef enum { - TokenUnknown, - TokenInteger, - TokenIdentifier, - TokenString, - TokenSpace, - TokenSemi, - TokenEqual, - TokenPeriod, - TokenBackslash, - TokenEnd, + TokenUnknown, + TokenInteger, + TokenIdentifier, + TokenString, + TokenSpace, + TokenSemi, + TokenEqual, + TokenPeriod, + TokenBackslash, + TokenEnd, } DFP_TOKEN; typedef enum { - stCabinetName, - stCabinetNameTemplate, - stDiskLabel, - stDiskLabelTemplate, - stMaxDiskSize, - stInfFileName + stCabinetName, + stCabinetNameTemplate, + stDiskLabel, + stDiskLabelTemplate, + stMaxDiskSize, + stInfFileName } SETTYPE; typedef enum { - ntDisk, - ntCabinet, - ntFolder, + ntDisk, + ntCabinet, + ntFolder, } NEWTYPE; @@ -56,86 +56,86 @@ typedef enum { class CDFParser : public CCabinet { public: - CDFParser(); - virtual ~CDFParser(); - ULONG Load(char* FileName); - ULONG Parse(); - void SetFileRelativePath(char* Path); - bool InfFileOnly; - bool DontGenerateInf; - char FileRelativePath[300]; + CDFParser(); + virtual ~CDFParser(); + ULONG Load(char* FileName); + ULONG Parse(); + void SetFileRelativePath(char* Path); + bool InfFileOnly; + bool DontGenerateInf; + char FileRelativePath[300]; private: - /* Event handlers */ - virtual bool OnDiskLabel(ULONG Number, char* Label); - virtual bool OnCabinetName(ULONG Number, char* Name); + /* Event handlers */ + virtual bool OnDiskLabel(ULONG Number, char* Label); + virtual bool OnCabinetName(ULONG Number, char* Name); - void WriteInfLine(char* InfLine); - bool SetDiskName(PCABINET_NAME *List, ULONG Number, char* String); - bool GetDiskName(PCABINET_NAME *List, ULONG Number, char* String); - bool SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value); - bool GetDiskNumber(PDISK_NUMBER *List, ULONG Number, PULONG Value); - bool DoDiskLabel(ULONG Number, char* Label); - void DoDiskLabelTemplate(char* Template); - bool DoCabinetName(ULONG Number, char* Name); - void DoCabinetNameTemplate(char* Template); - void DoInfFileName(char* InfFileName); - ULONG DoMaxDiskSize(bool NumberValid, ULONG Number); - ULONG SetupNewDisk(); - ULONG PerformSetCommand(); - ULONG PerformNewCommand(); - ULONG PerformInfBeginCommand(); - ULONG PerformInfEndCommand(); - ULONG PerformCommand(); - ULONG PerformFileCopy(); - void SkipSpaces(); - bool IsNextToken(DFP_TOKEN Token, bool NoSpaces); - bool ReadLine(); - void NextToken(); - /* Parsing */ - bool FileLoaded; - FILEHANDLE FileHandle; - char* FileBuffer; - ULONG FileBufferSize; - ULONG CurrentOffset; - char Line[128]; - ULONG LineLength; - ULONG CurrentLine; - ULONG CurrentChar; - /* Token */ - DFP_TOKEN CurrentToken; - ULONG CurrentInteger; - char CurrentString[256]; + void WriteInfLine(char* InfLine); + bool SetDiskName(PCABINET_NAME *List, ULONG Number, char* String); + bool GetDiskName(PCABINET_NAME *List, ULONG Number, char* String); + bool SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value); + bool GetDiskNumber(PDISK_NUMBER *List, ULONG Number, PULONG Value); + bool DoDiskLabel(ULONG Number, char* Label); + void DoDiskLabelTemplate(char* Template); + bool DoCabinetName(ULONG Number, char* Name); + void DoCabinetNameTemplate(char* Template); + void DoInfFileName(char* InfFileName); + ULONG DoMaxDiskSize(bool NumberValid, ULONG Number); + ULONG SetupNewDisk(); + ULONG PerformSetCommand(); + ULONG PerformNewCommand(); + ULONG PerformInfBeginCommand(); + ULONG PerformInfEndCommand(); + ULONG PerformCommand(); + ULONG PerformFileCopy(); + void SkipSpaces(); + bool IsNextToken(DFP_TOKEN Token, bool NoSpaces); + bool ReadLine(); + void NextToken(); + /* Parsing */ + bool FileLoaded; + FILEHANDLE FileHandle; + char* FileBuffer; + ULONG FileBufferSize; + ULONG CurrentOffset; + char Line[128]; + ULONG LineLength; + ULONG CurrentLine; + ULONG CurrentChar; + /* Token */ + DFP_TOKEN CurrentToken; + ULONG CurrentInteger; + char CurrentString[256]; - /* State */ - bool CabinetCreated; - bool DiskCreated; - bool FolderCreated; - /* Standard directive variable */ - bool Cabinet; - ULONG CabinetFileCountThreshold; - PCABINET_NAME CabinetName; - bool CabinetNameTemplateSet; - char CabinetNameTemplate[128]; - bool InfFileNameSet; - char InfFileName[256]; - bool Compress; - ULONG CompressionType; - PCABINET_NAME DiskLabel; - bool DiskLabelTemplateSet; - char DiskLabelTemplate[128]; - ULONG FolderFileCountThreshold; - ULONG FolderSizeThreshold; - ULONG MaxCabinetSize; - ULONG MaxDiskFileCount; - PDISK_NUMBER MaxDiskSize; - bool MaxDiskSizeAllSet; - ULONG MaxDiskSizeAll; - ULONG ReservePerCabinetSize; - ULONG ReservePerDataBlockSize; - ULONG ReservePerFolderSize; - char SourceDir[256]; - FILEHANDLE InfFileHandle; - bool InfModeEnabled; + /* State */ + bool CabinetCreated; + bool DiskCreated; + bool FolderCreated; + /* Standard directive variable */ + bool Cabinet; + ULONG CabinetFileCountThreshold; + PCABINET_NAME CabinetName; + bool CabinetNameTemplateSet; + char CabinetNameTemplate[128]; + bool InfFileNameSet; + char InfFileName[256]; + bool Compress; + ULONG CompressionType; + PCABINET_NAME DiskLabel; + bool DiskLabelTemplateSet; + char DiskLabelTemplate[128]; + ULONG FolderFileCountThreshold; + ULONG FolderSizeThreshold; + ULONG MaxCabinetSize; + ULONG MaxDiskFileCount; + PDISK_NUMBER MaxDiskSize; + bool MaxDiskSizeAllSet; + ULONG MaxDiskSizeAll; + ULONG ReservePerCabinetSize; + ULONG ReservePerDataBlockSize; + ULONG ReservePerFolderSize; + char SourceDir[256]; + FILEHANDLE InfFileHandle; + bool InfModeEnabled; }; #endif /* __DFP_H */ diff --git a/reactos/tools/cabman/main.cxx b/reactos/tools/cabman/main.cxx index d5502c65c6c..fc065cb2f03 100755 --- a/reactos/tools/cabman/main.cxx +++ b/reactos/tools/cabman/main.cxx @@ -8,9 +8,7 @@ * REVISIONS: * CSH 21/03-2001 Created * CSH 15/08-2003 Made it portable - * CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces * CF 04/05-2007 Made it compatible with 64-bit operating systems - * CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems */ #include #include @@ -44,16 +42,16 @@ char* Pad(char* Str, char PadChar, ULONG Length) * Str must be at least Length + 1 bytes */ { - ULONG Len; + ULONG Len; - Len = (ULONG)strlen(Str); + Len = (ULONG)strlen(Str); - if (Len < Length) - { - memcpy(&Str[Length - Len], Str, Len + 1); - memset(Str, PadChar, Length - Len); - } - return Str; + if (Len < Length) + { + memcpy(&Str[Length - Len], Str, Len + 1); + memset(Str, PadChar, Length - Len); + } + return Str; } @@ -67,24 +65,24 @@ char* Date2Str(char* Str, USHORT Date) * Pointer to string */ { - ULONG dw; + ULONG dw; - /* Month */ - Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10); - Str[1] = (char)('0' + ((Date & 0x01E0) >> 5) % 10); - Str[2] = '-'; - /* Day */ - Str[3] = (char)('0' + (Date & 0x001F) / 10); - Str[4] = (char)('0' + (Date & 0x001F) % 10); - Str[5] = '-'; - /* Year */ - dw = 1980 + ((Date & 0xFE00) >> 9); - Str[6] = (char)('0' + dw / 1000); dw %= 1000; - Str[7] = (char)('0' + dw / 100); dw %= 100; - Str[8] = (char)('0' + dw / 10); dw %= 10; - Str[9] = (char)('0' + dw % 10); - Str[10] = '\0'; - return Str; + /* Month */ + Str[0] = (char)('0' + ((Date & 0x01E0) >> 5) / 10); + Str[1] = (char)('0' + ((Date & 0x01E0) >> 5) % 10); + Str[2] = '-'; + /* Day */ + Str[3] = (char)('0' + (Date & 0x001F) / 10); + Str[4] = (char)('0' + (Date & 0x001F) % 10); + Str[5] = '-'; + /* Year */ + dw = 1980 + ((Date & 0xFE00) >> 9); + Str[6] = (char)('0' + dw / 1000); dw %= 1000; + Str[7] = (char)('0' + dw / 100); dw %= 100; + Str[8] = (char)('0' + dw / 10); dw %= 10; + Str[9] = (char)('0' + dw % 10); + Str[10] = '\0'; + return Str; } @@ -98,33 +96,33 @@ char* Time2Str(char* Str, USHORT Time) * Pointer to string */ { - bool PM; - ULONG Hour; - ULONG dw; + bool PM; + ULONG Hour; + ULONG dw; - Hour = ((Time & 0xF800) >> 11); - PM = (Hour >= 12); - Hour %= 12; - if (Hour == 0) - Hour = 12; + Hour = ((Time & 0xF800) >> 11); + PM = (Hour >= 12); + Hour %= 12; + if (Hour == 0) + Hour = 12; - if (Hour >= 10) - Str[0] = (char)('0' + Hour / 10); - else Str[0] = ' '; - Str[1] = (char)('0' + Hour % 10); - Str[2] = ':'; - /* Minute */ - Str[3] = (char)('0' + ((Time & 0x07E0) >> 5) / 10); - Str[4] = (char)('0' + ((Time & 0x07E0) >> 5) % 10); - Str[5] = ':'; - /* Second */ - dw = 2 * (Time & 0x001F); - Str[6] = (char)('0' + dw / 10); - Str[7] = (char)('0' + dw % 10); + if (Hour >= 10) + Str[0] = (char)('0' + Hour / 10); + else Str[0] = ' '; + Str[1] = (char)('0' + Hour % 10); + Str[2] = ':'; + /* Minute */ + Str[3] = (char)('0' + ((Time & 0x07E0) >> 5) / 10); + Str[4] = (char)('0' + ((Time & 0x07E0) >> 5) % 10); + Str[5] = ':'; + /* Second */ + dw = 2 * (Time & 0x001F); + Str[6] = (char)('0' + dw / 10); + Str[7] = (char)('0' + dw % 10); - Str[8] = PM? 'p' : 'a'; - Str[9] = '\0'; - return Str; + Str[8] = PM? 'p' : 'a'; + Str[9] = '\0'; + return Str; } @@ -138,32 +136,32 @@ char* Attr2Str(char* Str, USHORT Attr) * Pointer to string */ { - /* Archive */ - if (Attr & CAB_ATTRIB_ARCHIVE) - Str[0] = 'A'; - else - Str[0] = '-'; + /* Archive */ + if (Attr & CAB_ATTRIB_ARCHIVE) + Str[0] = 'A'; + else + Str[0] = '-'; - /* Hidden */ - if (Attr & CAB_ATTRIB_HIDDEN) - Str[1] = 'H'; - else - Str[1] = '-'; + /* Hidden */ + if (Attr & CAB_ATTRIB_HIDDEN) + Str[1] = 'H'; + else + Str[1] = '-'; - /* Read only */ - if (Attr & CAB_ATTRIB_READONLY) - Str[2] = 'R'; - else - Str[2] = '-'; + /* Read only */ + if (Attr & CAB_ATTRIB_READONLY) + Str[2] = 'R'; + else + Str[2] = '-'; - /* System */ - if (Attr & CAB_ATTRIB_SYSTEM) - Str[3] = 'S'; - else - Str[3] = '-'; + /* System */ + if (Attr & CAB_ATTRIB_SYSTEM) + Str[3] = 'S'; + else + Str[3] = '-'; - Str[4] = '\0'; - return Str; + Str[4] = '\0'; + return Str; } @@ -174,9 +172,9 @@ CCABManager::CCABManager() * FUNCTION: Default constructor */ { - ProcessAll = false; - InfFileOnly = false; - Mode = CM_MODE_DISPLAY; + ProcessAll = false; + InfFileOnly = false; + Mode = CM_MODE_DISPLAY; } @@ -193,30 +191,30 @@ void CCABManager::Usage() * FUNCTION: Display usage information on screen */ { - printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); - printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n"); - printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n"); - printf("CABMAN -S cabinet filename\n"); - printf(" cabinet Cabinet file.\n"); - printf(" filename Name of the file to extract from the cabinet.\n"); - printf(" Wild cards and multiple filenames\n"); - printf(" (separated by blanks) may be used.\n\n"); + printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); + printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n"); + printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n"); + printf("CABMAN -S cabinet filename\n"); + printf(" cabinet Cabinet file.\n"); + printf(" filename Name of the file to extract from the cabinet.\n"); + printf(" Wild cards and multiple filenames\n"); + printf(" (separated by blanks) may be used.\n\n"); - printf(" dirfile Name of the directive file to use.\n"); + printf(" dirfile Name of the directive file to use.\n"); - printf(" -A Process ALL cabinets. Follows cabinet chain\n"); - printf(" starting in first cabinet mentioned.\n"); - printf(" -C Create cabinet.\n"); - printf(" -D Display cabinet directory.\n"); - printf(" -E Extract files from cabinet.\n"); - printf(" -I Don't create the cabinet, only the .inf file.\n"); - printf(" -L dir Location to place extracted or generated files\n"); - printf(" (default is current directory).\n"); - printf(" -N Don't create the .inf file, only the cabinet.\n"); - printf(" -RC Specify file to put in cabinet reserved area\n"); - printf(" (size must be less than 64KB).\n"); - printf(" -S Create simple cabinet.\n"); - printf(" -P dir Files in the .dff are relative to this directory\n"); + printf(" -A Process ALL cabinets. Follows cabinet chain\n"); + printf(" starting in first cabinet mentioned.\n"); + printf(" -C Create cabinet.\n"); + printf(" -D Display cabinet directory.\n"); + printf(" -E Extract files from cabinet.\n"); + printf(" -I Don't create the cabinet, only the .inf file.\n"); + printf(" -L dir Location to place extracted or generated files\n"); + printf(" (default is current directory).\n"); + printf(" -N Don't create the .inf file, only the cabinet.\n"); + printf(" -RC Specify file to put in cabinet reserved area\n"); + printf(" (size must be less than 64KB).\n"); + printf(" -S Create simple cabinet.\n"); + printf(" -P dir Files in the .dff are relative to this directory\n"); } bool CCABManager::ParseCmdline(int argc, char* argv[]) @@ -229,135 +227,135 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) * true if command line arguments was successfully parsed, false if not */ { - int i; - bool ShowUsage; - bool FoundCabinet = false; + int i; + bool ShowUsage; + bool FoundCabinet = false; - ShowUsage = (argc < 2); + ShowUsage = (argc < 2); - for (i = 1; i < argc; i++) - { - if (argv[i][0] == '-') - { - switch (argv[i][1]) - { - case 'a': - case 'A': - ProcessAll = true; - break; + for (i = 1; i < argc; i++) + { + if (argv[i][0] == '-') + { + switch (argv[i][1]) + { + case 'a': + case 'A': + ProcessAll = true; + break; - case 'c': - case 'C': - Mode = CM_MODE_CREATE; - break; + case 'c': + case 'C': + Mode = CM_MODE_CREATE; + break; - case 'd': - case 'D': - Mode = CM_MODE_DISPLAY; - break; + case 'd': + case 'D': + Mode = CM_MODE_DISPLAY; + break; - case 'e': - case 'E': - Mode = CM_MODE_EXTRACT; - break; + case 'e': + case 'E': + Mode = CM_MODE_EXTRACT; + break; - case 'i': - case 'I': - InfFileOnly = true; - break; + case 'i': + case 'I': + InfFileOnly = true; + break; - case 'l': - case 'L': - if (argv[i][2] == 0) - { - i++; - SetDestinationPath((char*)&argv[i][0]); - } - else - SetDestinationPath((char*)&argv[i][1]); + case 'l': + case 'L': + if (argv[i][2] == 0) + { + i++; + SetDestinationPath((char*)&argv[i][0]); + } + else + SetDestinationPath((char*)&argv[i][1]); - break; + break; - case 'n': - case 'N': - DontGenerateInf = true; - break; + case 'n': + case 'N': + DontGenerateInf = true; + break; - case 'R': - switch (argv[i][2]) - { - case 'C': /* File to put in cabinet reserved area */ - if (argv[i][3] == 0) - { - i++; - if (!SetCabinetReservedFile((char*)&argv[i][0])) - { - printf("Cannot open cabinet reserved area file.\n"); - return false; - } - } - else - { - if (!SetCabinetReservedFile((char*)&argv[i][3])) - { - printf("Cannot open cabinet reserved area file.\n"); - return false; - } - } - break; + case 'R': + switch (argv[i][2]) + { + case 'C': /* File to put in cabinet reserved area */ + if (argv[i][3] == 0) + { + i++; + if (!SetCabinetReservedFile((char*)&argv[i][0])) + { + printf("Cannot open cabinet reserved area file.\n"); + return false; + } + } + else + { + if (!SetCabinetReservedFile((char*)&argv[i][3])) + { + printf("Cannot open cabinet reserved area file.\n"); + return false; + } + } + break; - default: - printf("Bad parameter %s.\n", argv[i]); - return false; - } - break; + default: + printf("Bad parameter %s.\n", argv[i]); + return false; + } + break; - case 's': - case 'S': - Mode = CM_MODE_CREATE_SIMPLE; - break; + case 's': + case 'S': + Mode = CM_MODE_CREATE_SIMPLE; + break; - case 'P': - if (argv[i][2] == 0) - { - i++; - SetFileRelativePath((char*)&argv[i][0]); - } - else - SetFileRelativePath((char*)&argv[i][1]); + case 'P': + if (argv[i][2] == 0) + { + i++; + SetFileRelativePath((char*)&argv[i][0]); + } + else + SetFileRelativePath((char*)&argv[i][1]); - break; + break; - default: - printf("Bad parameter %s.\n", argv[i]); - return false; - } - } - else - { - if ((FoundCabinet) || (Mode == CM_MODE_CREATE)) - { - /* FIXME: There may be many of these if Mode != CM_MODE_CREATE */ - strcpy((char*)FileName, argv[i]); - } - else - { - SetCabinetName(argv[i]); - FoundCabinet = true; - } - } - } + default: + printf("Bad parameter %s.\n", argv[i]); + return false; + } + } + else + { + if ((FoundCabinet) || (Mode == CM_MODE_CREATE)) + { + /* FIXME: There may be many of these if Mode != CM_MODE_CREATE */ + strcpy((char*)FileName, argv[i]); + } + else + { + SetCabinetName(argv[i]); + FoundCabinet = true; + } + } + } - if (ShowUsage) - { - Usage(); - return false; - } + if (ShowUsage) + { + Usage(); + return false; + } - /* FIXME */ - SelectCodec(CAB_CODEC_MSZIP); + /* FIXME */ + SelectCodec(CAB_CODEC_MSZIP); - return true; + return true; } @@ -366,18 +364,18 @@ bool CCABManager::CreateCabinet() * FUNCTION: Create cabinet */ { - ULONG Status; + ULONG Status; - Status = Load((char*)&FileName); - if (Status != CAB_STATUS_SUCCESS) - { - printf("Specified directive file could not be found: %s.\n", (char*)&FileName); - return false; - } + Status = Load((char*)&FileName); + if (Status != CAB_STATUS_SUCCESS) + { + printf("Specified directive file could not be found: %s.\n", (char*)&FileName); + return false; + } - Status = Parse(); + Status = Parse(); - return (Status == CAB_STATUS_SUCCESS ? true : false); + return (Status == CAB_STATUS_SUCCESS ? true : false); } @@ -386,34 +384,34 @@ bool CCABManager::CreateSimpleCabinet() * FUNCTION: Create cabinet */ { - ULONG Status; + ULONG Status; - Status = NewCabinet(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); - return false; - } + Status = NewCabinet(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot create cabinet (%lu).\n", (ULONG)Status)); + return false; + } - Status = AddFile(FileName); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%lu).\n", (ULONG)Status)); - return false; - } + Status = AddFile(FileName); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot add file to cabinet (%lu).\n", (ULONG)Status)); + return false; + } - Status = WriteDisk(false); - if (Status == CAB_STATUS_SUCCESS) - Status = CloseDisk(); - if (Status != CAB_STATUS_SUCCESS) - { - DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); - return false; - } + Status = WriteDisk(false); + if (Status == CAB_STATUS_SUCCESS) + Status = CloseDisk(); + if (Status != CAB_STATUS_SUCCESS) + { + DPRINT(MIN_TRACE, ("Cannot write disk (%lu).\n", (ULONG)Status)); + return false; + } - CloseCabinet(); + CloseCabinet(); - return true; + return true; } @@ -422,62 +420,62 @@ bool CCABManager::DisplayCabinet() * FUNCTION: Display cabinet contents */ { - CAB_SEARCH Search; - char Str[20]; - ULONG FileCount = 0; - ULONG ByteCount = 0; + CAB_SEARCH Search; + char Str[20]; + ULONG FileCount = 0; + ULONG ByteCount = 0; - if (Open() == CAB_STATUS_SUCCESS) - { - printf("Cabinet %s\n\n", GetCabinetName()); + if (Open() == CAB_STATUS_SUCCESS) + { + printf("Cabinet %s\n\n", GetCabinetName()); - if (FindFirst("", &Search) == CAB_STATUS_SUCCESS) - { - do - { - if (Search.File->FileControlID != CAB_FILE_CONTINUED) - { - printf("%s ", Date2Str((char*)&Str, Search.File->FileDate)); - printf("%s ", Time2Str((char*)&Str, Search.File->FileTime)); - printf("%s ", Attr2Str((char*)&Str, Search.File->Attributes)); - sprintf(Str, "%lu", Search.File->FileSize); - printf("%s ", Pad(Str, ' ', 13)); - printf("%s\n", Search.FileName); + if (FindFirst("", &Search) == CAB_STATUS_SUCCESS) + { + do + { + if (Search.File->FileControlID != CAB_FILE_CONTINUED) + { + printf("%s ", Date2Str((char*)&Str, Search.File->FileDate)); + printf("%s ", Time2Str((char*)&Str, Search.File->FileTime)); + printf("%s ", Attr2Str((char*)&Str, Search.File->Attributes)); + sprintf(Str, "%lu", Search.File->FileSize); + printf("%s ", Pad(Str, ' ', 13)); + printf("%s\n", Search.FileName); - FileCount++; - ByteCount += Search.File->FileSize; - } - } while (FindNext(&Search) == CAB_STATUS_SUCCESS); - } + FileCount++; + ByteCount += Search.File->FileSize; + } + } while (FindNext(&Search) == CAB_STATUS_SUCCESS); + } - if (FileCount > 0) { - if (FileCount == 1) - printf(" 1 file "); - else - { - sprintf(Str, "%lu", FileCount); - printf(" %s files ", Pad(Str, ' ', 12)); - } + if (FileCount > 0) { + if (FileCount == 1) + printf(" 1 file "); + else + { + sprintf(Str, "%lu", FileCount); + printf(" %s files ", Pad(Str, ' ', 12)); + } - if (ByteCount == 1) - printf(" 1 byte\n"); - else - { - sprintf(Str, "%lu", ByteCount); - printf("%s bytes\n", Pad(Str, ' ', 12)); - } - } - else - { - /* There should be at least one file in a cabinet */ - printf("No files in cabinet."); - } - return true; - } - else - printf("Cannot open file: %s\n", GetCabinetName()); + if (ByteCount == 1) + printf(" 1 byte\n"); + else + { + sprintf(Str, "%lu", ByteCount); + printf("%s bytes\n", Pad(Str, ' ', 12)); + } + } + else + { + /* There should be at least one file in a cabinet */ + printf("No files in cabinet."); + } + return true; + } + else + printf("Cannot open file: %s\n", GetCabinetName()); - return false; + return false; } @@ -486,44 +484,44 @@ bool CCABManager::ExtractFromCabinet() * FUNCTION: Extract file(s) from cabinet */ { - CAB_SEARCH Search; - ULONG Status; + CAB_SEARCH Search; + ULONG Status; - if (Open() == CAB_STATUS_SUCCESS) - { - printf("Cabinet %s\n\n", GetCabinetName()); + if (Open() == CAB_STATUS_SUCCESS) + { + printf("Cabinet %s\n\n", GetCabinetName()); - if (FindFirst("", &Search) == CAB_STATUS_SUCCESS) - { - do - { - switch (Status = ExtractFile(Search.FileName)) { - case CAB_STATUS_SUCCESS: - break; + if (FindFirst("", &Search) == CAB_STATUS_SUCCESS) + { + do + { + switch (Status = ExtractFile(Search.FileName)) { + case CAB_STATUS_SUCCESS: + break; - case CAB_STATUS_INVALID_CAB: - printf("Cabinet contains errors.\n"); - return false; + case CAB_STATUS_INVALID_CAB: + printf("Cabinet contains errors.\n"); + return false; - case CAB_STATUS_UNSUPPCOMP: - printf("Cabinet uses unsupported compression type.\n"); - return false; + case CAB_STATUS_UNSUPPCOMP: + printf("Cabinet uses unsupported compression type.\n"); + return false; - case CAB_STATUS_CANNOT_WRITE: - printf("You've run out of free space on the destination volume or the volume is damaged.\n"); - return false; + case CAB_STATUS_CANNOT_WRITE: + printf("You've run out of free space on the destination volume or the volume is damaged.\n"); + return false; - default: - printf("Unspecified error code (%lu).\n", (ULONG)Status); - return false; - } - } while (FindNext(&Search) == CAB_STATUS_SUCCESS); - } - return true; - } else - printf("Cannot open file: %s.\n", GetCabinetName()); + default: + printf("Unspecified error code (%lu).\n", (ULONG)Status); + return false; + } + } while (FindNext(&Search) == CAB_STATUS_SUCCESS); + } + return true; + } else + printf("Cannot open file: %s.\n", GetCabinetName()); - return false; + return false; } @@ -532,30 +530,30 @@ bool CCABManager::Run() * FUNCTION: Process cabinet */ { - printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); + printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); - switch (Mode) - { - case CM_MODE_CREATE: - return CreateCabinet(); - break; + switch (Mode) + { + case CM_MODE_CREATE: + return CreateCabinet(); + break; - case CM_MODE_DISPLAY: - return DisplayCabinet(); - break; + case CM_MODE_DISPLAY: + return DisplayCabinet(); + break; - case CM_MODE_EXTRACT: - return ExtractFromCabinet(); - break; + case CM_MODE_EXTRACT: + return ExtractFromCabinet(); + break; - case CM_MODE_CREATE_SIMPLE: - return CreateSimpleCabinet(); - break; + case CM_MODE_CREATE_SIMPLE: + return CreateSimpleCabinet(); + break; - default: - break; - } - return false; + default: + break; + } + return false; } @@ -572,11 +570,11 @@ bool CCABManager::OnOverwrite(PCFFILE File, * true if the file should be overwritten, false if not */ { - if (Mode == CM_MODE_CREATE) - return true; + if (Mode == CM_MODE_CREATE) + return true; - /* Always overwrite */ - return true; + /* Always overwrite */ + return true; } @@ -589,7 +587,7 @@ void CCABManager::OnExtract(PCFFILE File, * FileName = Pointer to buffer with name of file (full path) */ { - printf("Extracting %s\n", GetFileName(FileName)); + printf("Extracting %s\n", GetFileName(FileName)); } @@ -603,7 +601,7 @@ void CCABManager::OnDiskChange(char* CabinetName, * DiskLabel = Pointer to buffer with label of disk */ { - printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel); + printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel); } @@ -616,7 +614,7 @@ void CCABManager::OnAdd(PCFFILE File, * FileName = Pointer to buffer with name of file (full path) */ { - printf("Adding %s\n", GetFileName(FileName)); + printf("Adding %s\n", GetFileName(FileName)); } @@ -628,13 +626,13 @@ int main(int argc, char * argv[]) * argv = Pointer to list of command line arguments */ { - CCABManager CABMgr; - bool status = false; + CCABManager CABMgr; + bool status = false; - if (CABMgr.ParseCmdline(argc, argv)) - status = CABMgr.Run(); + if (CABMgr.ParseCmdline(argc, argv)) + status = CABMgr.Run(); - return (status ? 0 : 1); + return (status ? 0 : 1); } /* EOF */ diff --git a/reactos/tools/cabman/mszip.cxx b/reactos/tools/cabman/mszip.cxx index d129fc5645c..131639a2b40 100755 --- a/reactos/tools/cabman/mszip.cxx +++ b/reactos/tools/cabman/mszip.cxx @@ -10,9 +10,7 @@ * REVISIONS: * CSH 21/03-2001 Created * CSH 15/08-2003 Made it portable - * CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces * CF 04/05-2007 Made it compatible with 64-bit operating systems - * CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems */ #include #include "mszip.h" @@ -22,14 +20,14 @@ voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size) { - DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size)); - return AllocateMemory(items * size); + DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size)); + return AllocateMemory(items * size); } void MSZipFree (voidpf opaque, voidpf address) { - DPRINT(DEBUG_MEMORY, ("\n")); - FreeMemory(address); + DPRINT(DEBUG_MEMORY, ("\n")); + FreeMemory(address); } @@ -40,9 +38,9 @@ CMSZipCodec::CMSZipCodec() * FUNCTION: Default constructor */ { - ZStream.zalloc = MSZipAlloc; - ZStream.zfree = MSZipFree; - ZStream.opaque = (voidpf)0; + ZStream.zalloc = MSZipAlloc; + ZStream.zfree = MSZipFree; + ZStream.opaque = (voidpf)0; } @@ -67,50 +65,50 @@ ULONG CMSZipCodec::Compress(void* OutputBuffer, * OutputLength = Address of buffer to place size of compressed data */ { - PUSHORT Magic; + PUSHORT Magic; - DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); + DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); - Magic = (PUSHORT)OutputBuffer; - *Magic = MSZIP_MAGIC; + Magic = (PUSHORT)OutputBuffer; + *Magic = MSZIP_MAGIC; - ZStream.next_in = (unsigned char*)InputBuffer; - ZStream.avail_in = InputLength; - ZStream.next_out = (unsigned char*)((_W64 unsigned long)OutputBuffer + 2); - ZStream.avail_out = CAB_BLOCKSIZE + 12; + ZStream.next_in = (unsigned char*)InputBuffer; + ZStream.avail_in = InputLength; + ZStream.next_out = (unsigned char*)((_W64 unsigned long)OutputBuffer + 2); + ZStream.avail_out = CAB_BLOCKSIZE + 12; - /* WindowBits is passed < 0 to tell that there is no zlib header */ - Status = deflateInit2(&ZStream, - Z_BEST_COMPRESSION, - Z_DEFLATED, - -MAX_WBITS, - 8, /* memLevel */ - Z_DEFAULT_STRATEGY); - if (Status != Z_OK) - { - DPRINT(MIN_TRACE, ("deflateInit() returned (%d).\n", Status)); - return CS_NOMEMORY; - } + /* WindowBits is passed < 0 to tell that there is no zlib header */ + Status = deflateInit2(&ZStream, + Z_BEST_COMPRESSION, + Z_DEFLATED, + -MAX_WBITS, + 8, /* memLevel */ + Z_DEFAULT_STRATEGY); + if (Status != Z_OK) + { + DPRINT(MIN_TRACE, ("deflateInit() returned (%d).\n", Status)); + return CS_NOMEMORY; + } - Status = deflate(&ZStream, Z_FINISH); - if ((Status != Z_OK) && (Status != Z_STREAM_END)) - { - DPRINT(MIN_TRACE, ("deflate() returned (%d) (%s).\n", Status, ZStream.msg)); - if (Status == Z_MEM_ERROR) - return CS_NOMEMORY; - return CS_BADSTREAM; - } + Status = deflate(&ZStream, Z_FINISH); + if ((Status != Z_OK) && (Status != Z_STREAM_END)) + { + DPRINT(MIN_TRACE, ("deflate() returned (%d) (%s).\n", Status, ZStream.msg)); + if (Status == Z_MEM_ERROR) + return CS_NOMEMORY; + return CS_BADSTREAM; + } - *OutputLength = ZStream.total_out + 2; + *OutputLength = ZStream.total_out + 2; - Status = deflateEnd(&ZStream); - if (Status != Z_OK) - { - DPRINT(MIN_TRACE, ("deflateEnd() returned (%d).\n", Status)); - return CS_BADSTREAM; - } + Status = deflateEnd(&ZStream); + if (Status != Z_OK) + { + DPRINT(MIN_TRACE, ("deflateEnd() returned (%d).\n", Status)); + return CS_BADSTREAM; + } - return CS_SUCCESS; + return CS_SUCCESS; } @@ -127,58 +125,58 @@ ULONG CMSZipCodec::Uncompress(void* OutputBuffer, * OutputLength = Address of buffer to place size of uncompressed data */ { - USHORT Magic; + USHORT Magic; - DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); + DPRINT(MAX_TRACE, ("InputLength (%lu).\n", InputLength)); - Magic = *((PUSHORT)InputBuffer); + Magic = *((PUSHORT)InputBuffer); - if (Magic != MSZIP_MAGIC) - { - DPRINT(MID_TRACE, ("Bad MSZIP block header magic (0x%X)\n", Magic)); - return CS_BADSTREAM; - } + if (Magic != MSZIP_MAGIC) + { + DPRINT(MID_TRACE, ("Bad MSZIP block header magic (0x%X)\n", Magic)); + return CS_BADSTREAM; + } - ZStream.next_in = (unsigned char*)((_W64 unsigned long)InputBuffer + 2); - ZStream.avail_in = InputLength - 2; - ZStream.next_out = (unsigned char*)OutputBuffer; - ZStream.avail_out = CAB_BLOCKSIZE + 12; + ZStream.next_in = (unsigned char*)((_W64 unsigned long)InputBuffer + 2); + ZStream.avail_in = InputLength - 2; + ZStream.next_out = (unsigned char*)OutputBuffer; + ZStream.avail_out = CAB_BLOCKSIZE + 12; - /* WindowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - */ - Status = inflateInit2(&ZStream, -MAX_WBITS); - if (Status != Z_OK) - { - DPRINT(MIN_TRACE, ("inflateInit2() returned (%d).\n", Status)); - return CS_BADSTREAM; - } + /* WindowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + */ + Status = inflateInit2(&ZStream, -MAX_WBITS); + if (Status != Z_OK) + { + DPRINT(MIN_TRACE, ("inflateInit2() returned (%d).\n", Status)); + return CS_BADSTREAM; + } - while ((ZStream.total_out < CAB_BLOCKSIZE + 12) && - (ZStream.total_in < InputLength - 2)) - { - Status = inflate(&ZStream, Z_NO_FLUSH); - if (Status == Z_STREAM_END) break; - if (Status != Z_OK) - { - DPRINT(MIN_TRACE, ("inflate() returned (%d) (%s).\n", Status, ZStream.msg)); - if (Status == Z_MEM_ERROR) - return CS_NOMEMORY; - return CS_BADSTREAM; - } - } + while ((ZStream.total_out < CAB_BLOCKSIZE + 12) && + (ZStream.total_in < InputLength - 2)) + { + Status = inflate(&ZStream, Z_NO_FLUSH); + if (Status == Z_STREAM_END) break; + if (Status != Z_OK) + { + DPRINT(MIN_TRACE, ("inflate() returned (%d) (%s).\n", Status, ZStream.msg)); + if (Status == Z_MEM_ERROR) + return CS_NOMEMORY; + return CS_BADSTREAM; + } + } - *OutputLength = ZStream.total_out; + *OutputLength = ZStream.total_out; - Status = inflateEnd(&ZStream); - if (Status != Z_OK) - { - DPRINT(MIN_TRACE, ("inflateEnd() returned (%d).\n", Status)); - return CS_BADSTREAM; - } - return CS_SUCCESS; + Status = inflateEnd(&ZStream); + if (Status != Z_OK) + { + DPRINT(MIN_TRACE, ("inflateEnd() returned (%d).\n", Status)); + return CS_BADSTREAM; + } + return CS_SUCCESS; } /* EOF */ diff --git a/reactos/tools/cabman/mszip.h b/reactos/tools/cabman/mszip.h index 291ddde251e..ebe83fccae7 100755 --- a/reactos/tools/cabman/mszip.h +++ b/reactos/tools/cabman/mszip.h @@ -17,23 +17,23 @@ class CMSZipCodec : public CCABCodec { public: - /* Default constructor */ - CMSZipCodec(); - /* Default destructor */ - virtual ~CMSZipCodec(); - /* Compresses a data block */ - virtual ULONG Compress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength); - /* Uncompresses a data block */ - virtual ULONG Uncompress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength); + /* Default constructor */ + CMSZipCodec(); + /* Default destructor */ + virtual ~CMSZipCodec(); + /* Compresses a data block */ + virtual ULONG Compress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength); + /* Uncompresses a data block */ + virtual ULONG Uncompress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength); private: - int Status; - z_stream ZStream; /* Zlib stream */ + int Status; + z_stream ZStream; /* Zlib stream */ }; #endif /* __MSZIP_H */ diff --git a/reactos/tools/cabman/raw.cxx b/reactos/tools/cabman/raw.cxx index 60281c85da6..bf4b0fe9871 100755 --- a/reactos/tools/cabman/raw.cxx +++ b/reactos/tools/cabman/raw.cxx @@ -8,9 +8,7 @@ * REVISIONS: * CSH 21/03-2001 Created * CSH 15/08-2003 Made it portable - * CF 04/05-2007 Reformatted the code to be more consistent and use TABs instead of spaces * CF 04/05-2007 Made it compatible with 64-bit operating systems - * CF 18/08-2007 Use typedefs64.h and the Windows types for compatibility with 64-bit operating systems */ #include "raw.h" @@ -46,9 +44,9 @@ ULONG CRawCodec::Compress(void* OutputBuffer, * OutputLength = Address of buffer to place size of compressed data */ { - memcpy(OutputBuffer, InputBuffer, InputLength); - *OutputLength = InputLength; - return CS_SUCCESS; + memcpy(OutputBuffer, InputBuffer, InputLength); + *OutputLength = InputLength; + return CS_SUCCESS; } ULONG CRawCodec::Uncompress(void* OutputBuffer, @@ -64,9 +62,9 @@ ULONG CRawCodec::Uncompress(void* OutputBuffer, * OutputLength = Address of buffer to place size of uncompressed data */ { - memcpy(OutputBuffer, InputBuffer, InputLength); - *OutputLength = InputLength; - return CS_SUCCESS; + memcpy(OutputBuffer, InputBuffer, InputLength); + *OutputLength = InputLength; + return CS_SUCCESS; } /* EOF */ diff --git a/reactos/tools/cabman/raw.h b/reactos/tools/cabman/raw.h index e26eadfce91..635712f3a9d 100755 --- a/reactos/tools/cabman/raw.h +++ b/reactos/tools/cabman/raw.h @@ -14,20 +14,20 @@ class CRawCodec : public CCABCodec { public: - /* Default constructor */ - CRawCodec(); - /* Default destructor */ - virtual ~CRawCodec(); - /* Compresses a data block */ - virtual ULONG Compress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength); - /* Uncompresses a data block */ - virtual ULONG Uncompress(void* OutputBuffer, - void* InputBuffer, - ULONG InputLength, - PULONG OutputLength); + /* Default constructor */ + CRawCodec(); + /* Default destructor */ + virtual ~CRawCodec(); + /* Compresses a data block */ + virtual ULONG Compress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength); + /* Uncompresses a data block */ + virtual ULONG Uncompress(void* OutputBuffer, + void* InputBuffer, + ULONG InputLength, + PULONG OutputLength); }; #endif /* __RAW_H */