From b1d37b0e861eb16a97382369ef97f8b1df6b40c8 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Sat, 2 Feb 2008 14:32:44 +0000 Subject: [PATCH] - Add an -M option to specify, which compression codec shall be used (either "raw" or "mszip") - Enable the RAW codec in the SelectCodec() function - Don't initialize a codec in the CCabinet constructor, this will be done by the ParseCmdline() function - Fix parsing the -L and -P parameters, when there's no whitespace between the parameter and the value - Remove some unneeded casts - Remove the cabman vesion number, it was never updated, although there were many changes since the first version svn path=/trunk/; revision=32089 --- reactos/tools/cabman/cabinet.cxx | 44 +++++++++++++++++++----- reactos/tools/cabman/cabinet.h | 8 +++-- reactos/tools/cabman/dfp.cxx | 2 +- reactos/tools/cabman/main.cxx | 57 +++++++++++++++++++++----------- 4 files changed, 80 insertions(+), 31 deletions(-) diff --git a/reactos/tools/cabman/cabinet.cxx b/reactos/tools/cabman/cabinet.cxx index c4add557be1..1a1045880a2 100755 --- a/reactos/tools/cabman/cabinet.cxx +++ b/reactos/tools/cabman/cabinet.cxx @@ -320,9 +320,9 @@ CCabinet::CCabinet() FileListHead = NULL; FileListTail = NULL; - Codec = new CRawCodec(); - CodecId = CAB_CODEC_RAW; - CodecSelected = true; + Codec = NULL; + CodecId = -1; + CodecSelected = false; OutputBuffer = NULL; InputBuffer = NULL; @@ -359,7 +359,7 @@ bool CCabinet::IsSeparator(char Char) * ARGUMENTS: * Char = Character to check * RETURNS: - * Wether it is a separator + * Whether it is a separator */ { if ((Char == '\\') || (Char == '/')) @@ -511,6 +511,25 @@ void CCabinet::SetDestinationPath(char* DestinationPath) NormalizePath(DestPath, MAX_PATH); } +bool CCabinet::SetCompressionCodec(char* CodecName) +/* + * FUNCTION: Selects the codec to use for compression + * ARGUMENTS: + * CodecName = Pointer to a string with the name of the codec + */ +{ + if( !strcasecmp(CodecName, "raw") ) + SelectCodec(CAB_CODEC_RAW); + else if( !strcasecmp(CodecName, "mszip") ) + SelectCodec(CAB_CODEC_MSZIP); + else + { + printf("Invalid codec specified!\n"); + return false; + } + + return true; +} char* CCabinet::GetDestinationPath() /* @@ -1300,8 +1319,17 @@ ULONG CCabinet::ExtractFile(char* FileName) return CAB_STATUS_SUCCESS; } +bool CCabinet::IsCodecSelected() +/* + * FUNCTION: Returns the value of CodecSelected + * RETURNS: + * Whether a codec is selected + */ +{ + return CodecSelected; +} -void CCabinet::SelectCodec(ULONG Id) +void CCabinet::SelectCodec(LONG Id) /* * FUNCTION: Selects codec engine to use * ARGUMENTS: @@ -1320,9 +1348,7 @@ void CCabinet::SelectCodec(ULONG Id) switch (Id) { case CAB_CODEC_RAW: -#if 0 Codec = new CRawCodec(); -#endif break; case CAB_CODEC_MSZIP: @@ -2080,7 +2106,7 @@ ULONG CCabinet::GetAbsoluteOffset(PCFFILE_NODE File) PCFDATA_NODE Node; DPRINT(MAX_TRACE, ("FileName '%s' FileOffset (0x%lX) FileSize (%lu).\n", - (char*)File->FileName, + File->FileName, (ULONG)File->File.FileOffset, (ULONG)File->File.FileSize)); @@ -2291,7 +2317,7 @@ ULONG CCabinet::ReadFileTable() return Status; DPRINT(MAX_TRACE, ("Found file '%s' at uncompressed offset (0x%lX). Size (%lu bytes) ControlId (0x%lX).\n", - (char*)File->FileName, + File->FileName, (ULONG)File->File.FileOffset, (ULONG)File->File.FileSize, (ULONG)File->File.FileControlID)); diff --git a/reactos/tools/cabman/cabinet.h b/reactos/tools/cabman/cabinet.h index ff4161bdf8f..929acbf12df 100755 --- a/reactos/tools/cabman/cabinet.h +++ b/reactos/tools/cabman/cabinet.h @@ -347,8 +347,12 @@ public: /* Extracts a file from the current cabinet file */ ULONG ExtractFile(char* FileName); /* Select codec engine to use */ - void SelectCodec(ULONG Id); + void SelectCodec(LONG Id); + /* Returns if a codec engine is selected */ + bool IsCodecSelected(); #ifndef CAB_READ_ONLY + /* Sets the codec to use for compression (based on a string value) */ + bool SetCompressionCodec(char* CodecName); /* Creates a new cabinet file */ ULONG NewCabinet(); /* Forces a new disk to be created */ @@ -448,7 +452,7 @@ private: PCFFILE_NODE FileListHead; PCFFILE_NODE FileListTail; CCABCodec *Codec; - ULONG CodecId; + LONG CodecId; bool CodecSelected; void* InputBuffer; void* CurrentIBuffer; // Current offset in input buffer diff --git a/reactos/tools/cabman/dfp.cxx b/reactos/tools/cabman/dfp.cxx index 6f277b8ca29..1480bab87ce 100755 --- a/reactos/tools/cabman/dfp.cxx +++ b/reactos/tools/cabman/dfp.cxx @@ -1367,7 +1367,7 @@ void CDFParser::NextToken() if (i > 0) { CurrentString[i] = '\0'; - CurrentInteger = atoi((char*)CurrentString); + CurrentInteger = atoi(CurrentString); CurrentToken = TokenInteger; CurrentChar += i; return; diff --git a/reactos/tools/cabman/main.cxx b/reactos/tools/cabman/main.cxx index fc065cb2f03..7f3243f1b6f 100755 --- a/reactos/tools/cabman/main.cxx +++ b/reactos/tools/cabman/main.cxx @@ -26,9 +26,6 @@ ULONG DebugTraceLevel = MIN_TRACE; #endif /* DBG */ -#define CM_VERSION "0.9" - - char* Pad(char* Str, char PadChar, ULONG Length) /* * FUNCTION: Pads a string with a character to make a given length @@ -191,7 +188,7 @@ void CCABManager::Usage() * FUNCTION: Display usage information on screen */ { - printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); + printf("ReactOS Cabinet Manager\n\n"); 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"); @@ -210,6 +207,9 @@ void CCABManager::Usage() 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(" -M Specify the compression method to use\n"); + printf(" raw - No compression\n"); + printf(" mszip - MsZip compression (default)\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"); @@ -269,10 +269,28 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) if (argv[i][2] == 0) { i++; - SetDestinationPath((char*)&argv[i][0]); + SetDestinationPath(&argv[i][0]); } else - SetDestinationPath((char*)&argv[i][1]); + SetDestinationPath(&argv[i][2]); + + break; + + case 'm': + case 'M': + // Set the compression codec (only affects compression, not decompression) + if(argv[i][2] == 0) + { + i++; + + if( !SetCompressionCodec(&argv[i][0]) ) + return false; + } + else + { + if( !SetCompressionCodec(&argv[i][2]) ) + return false; + } break; @@ -288,7 +306,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) if (argv[i][3] == 0) { i++; - if (!SetCabinetReservedFile((char*)&argv[i][0])) + if (!SetCabinetReservedFile(&argv[i][0])) { printf("Cannot open cabinet reserved area file.\n"); return false; @@ -296,7 +314,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) } else { - if (!SetCabinetReservedFile((char*)&argv[i][3])) + if (!SetCabinetReservedFile(&argv[i][3])) { printf("Cannot open cabinet reserved area file.\n"); return false; @@ -319,10 +337,10 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) if (argv[i][2] == 0) { i++; - SetFileRelativePath((char*)&argv[i][0]); + SetFileRelativePath(&argv[i][0]); } else - SetFileRelativePath((char*)&argv[i][1]); + SetFileRelativePath(&argv[i][2]); break; @@ -336,7 +354,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) if ((FoundCabinet) || (Mode == CM_MODE_CREATE)) { /* FIXME: There may be many of these if Mode != CM_MODE_CREATE */ - strcpy((char*)FileName, argv[i]); + strcpy(FileName, argv[i]); } else { @@ -352,8 +370,9 @@ bool CCABManager::ParseCmdline(int argc, char* argv[]) return false; } - /* FIXME */ - SelectCodec(CAB_CODEC_MSZIP); + // Select MsZip by default for creating cabinets + if( (Mode == CM_MODE_CREATE || Mode == CM_MODE_CREATE_SIMPLE) && !IsCodecSelected() ) + SelectCodec(CAB_CODEC_MSZIP); return true; } @@ -366,10 +385,10 @@ bool CCABManager::CreateCabinet() { ULONG Status; - Status = Load((char*)&FileName); + Status = Load(FileName); if (Status != CAB_STATUS_SUCCESS) { - printf("Specified directive file could not be found: %s.\n", (char*)&FileName); + printf("Specified directive file could not be found: %s.\n", FileName); return false; } @@ -435,9 +454,9 @@ bool CCABManager::DisplayCabinet() { 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)); + printf("%s ", Date2Str(Str, Search.File->FileDate)); + printf("%s ", Time2Str(Str, Search.File->FileTime)); + printf("%s ", Attr2Str(Str, Search.File->Attributes)); sprintf(Str, "%lu", Search.File->FileSize); printf("%s ", Pad(Str, ' ', 13)); printf("%s\n", Search.FileName); @@ -530,7 +549,7 @@ bool CCABManager::Run() * FUNCTION: Process cabinet */ { - printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); + printf("ReactOS Cabinet Manager\n\n"); switch (Mode) {