- 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
This commit is contained in:
Colin Finck 2008-02-02 14:32:44 +00:00
parent 982e1cf181
commit b1d37b0e86
4 changed files with 80 additions and 31 deletions

View file

@ -320,9 +320,9 @@ CCabinet::CCabinet()
FileListHead = NULL; FileListHead = NULL;
FileListTail = NULL; FileListTail = NULL;
Codec = new CRawCodec(); Codec = NULL;
CodecId = CAB_CODEC_RAW; CodecId = -1;
CodecSelected = true; CodecSelected = false;
OutputBuffer = NULL; OutputBuffer = NULL;
InputBuffer = NULL; InputBuffer = NULL;
@ -359,7 +359,7 @@ bool CCabinet::IsSeparator(char Char)
* ARGUMENTS: * ARGUMENTS:
* Char = Character to check * Char = Character to check
* RETURNS: * RETURNS:
* Wether it is a separator * Whether it is a separator
*/ */
{ {
if ((Char == '\\') || (Char == '/')) if ((Char == '\\') || (Char == '/'))
@ -511,6 +511,25 @@ void CCabinet::SetDestinationPath(char* DestinationPath)
NormalizePath(DestPath, MAX_PATH); 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() char* CCabinet::GetDestinationPath()
/* /*
@ -1300,8 +1319,17 @@ ULONG CCabinet::ExtractFile(char* FileName)
return CAB_STATUS_SUCCESS; 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 * FUNCTION: Selects codec engine to use
* ARGUMENTS: * ARGUMENTS:
@ -1320,9 +1348,7 @@ void CCabinet::SelectCodec(ULONG Id)
switch (Id) switch (Id)
{ {
case CAB_CODEC_RAW: case CAB_CODEC_RAW:
#if 0
Codec = new CRawCodec(); Codec = new CRawCodec();
#endif
break; break;
case CAB_CODEC_MSZIP: case CAB_CODEC_MSZIP:
@ -2080,7 +2106,7 @@ ULONG CCabinet::GetAbsoluteOffset(PCFFILE_NODE File)
PCFDATA_NODE Node; PCFDATA_NODE Node;
DPRINT(MAX_TRACE, ("FileName '%s' FileOffset (0x%lX) FileSize (%lu).\n", DPRINT(MAX_TRACE, ("FileName '%s' FileOffset (0x%lX) FileSize (%lu).\n",
(char*)File->FileName, File->FileName,
(ULONG)File->File.FileOffset, (ULONG)File->File.FileOffset,
(ULONG)File->File.FileSize)); (ULONG)File->File.FileSize));
@ -2291,7 +2317,7 @@ ULONG CCabinet::ReadFileTable()
return Status; return Status;
DPRINT(MAX_TRACE, ("Found file '%s' at uncompressed offset (0x%lX). Size (%lu bytes) ControlId (0x%lX).\n", 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.FileOffset,
(ULONG)File->File.FileSize, (ULONG)File->File.FileSize,
(ULONG)File->File.FileControlID)); (ULONG)File->File.FileControlID));

View file

@ -347,8 +347,12 @@ public:
/* Extracts a file from the current cabinet file */ /* Extracts a file from the current cabinet file */
ULONG ExtractFile(char* FileName); ULONG ExtractFile(char* FileName);
/* Select codec engine to use */ /* 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 #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 */ /* Creates a new cabinet file */
ULONG NewCabinet(); ULONG NewCabinet();
/* Forces a new disk to be created */ /* Forces a new disk to be created */
@ -448,7 +452,7 @@ private:
PCFFILE_NODE FileListHead; PCFFILE_NODE FileListHead;
PCFFILE_NODE FileListTail; PCFFILE_NODE FileListTail;
CCABCodec *Codec; CCABCodec *Codec;
ULONG CodecId; LONG CodecId;
bool CodecSelected; bool CodecSelected;
void* InputBuffer; void* InputBuffer;
void* CurrentIBuffer; // Current offset in input buffer void* CurrentIBuffer; // Current offset in input buffer

View file

@ -1367,7 +1367,7 @@ void CDFParser::NextToken()
if (i > 0) if (i > 0)
{ {
CurrentString[i] = '\0'; CurrentString[i] = '\0';
CurrentInteger = atoi((char*)CurrentString); CurrentInteger = atoi(CurrentString);
CurrentToken = TokenInteger; CurrentToken = TokenInteger;
CurrentChar += i; CurrentChar += i;
return; return;

View file

@ -26,9 +26,6 @@ ULONG DebugTraceLevel = MIN_TRACE;
#endif /* DBG */ #endif /* DBG */
#define CM_VERSION "0.9"
char* Pad(char* Str, char PadChar, ULONG Length) char* Pad(char* Str, char PadChar, ULONG Length)
/* /*
* FUNCTION: Pads a string with a character to make a given 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 * 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 [-D | -E] [-A] [-L dir] cabinet [filename ...]\n");
printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n"); printf("CABMAN -C dirfile [-I] [-RC file] [-P dir]\n");
printf("CABMAN -S cabinet filename\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(" -I Don't create the cabinet, only the .inf file.\n");
printf(" -L dir Location to place extracted or generated files\n"); printf(" -L dir Location to place extracted or generated files\n");
printf(" (default is current directory).\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(" -N Don't create the .inf file, only the cabinet.\n");
printf(" -RC Specify file to put in cabinet reserved area\n"); printf(" -RC Specify file to put in cabinet reserved area\n");
printf(" (size must be less than 64KB).\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) if (argv[i][2] == 0)
{ {
i++; i++;
SetDestinationPath((char*)&argv[i][0]); SetDestinationPath(&argv[i][0]);
} }
else 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; break;
@ -288,7 +306,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
if (argv[i][3] == 0) if (argv[i][3] == 0)
{ {
i++; i++;
if (!SetCabinetReservedFile((char*)&argv[i][0])) if (!SetCabinetReservedFile(&argv[i][0]))
{ {
printf("Cannot open cabinet reserved area file.\n"); printf("Cannot open cabinet reserved area file.\n");
return false; return false;
@ -296,7 +314,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
} }
else else
{ {
if (!SetCabinetReservedFile((char*)&argv[i][3])) if (!SetCabinetReservedFile(&argv[i][3]))
{ {
printf("Cannot open cabinet reserved area file.\n"); printf("Cannot open cabinet reserved area file.\n");
return false; return false;
@ -319,10 +337,10 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
if (argv[i][2] == 0) if (argv[i][2] == 0)
{ {
i++; i++;
SetFileRelativePath((char*)&argv[i][0]); SetFileRelativePath(&argv[i][0]);
} }
else else
SetFileRelativePath((char*)&argv[i][1]); SetFileRelativePath(&argv[i][2]);
break; break;
@ -336,7 +354,7 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
if ((FoundCabinet) || (Mode == CM_MODE_CREATE)) if ((FoundCabinet) || (Mode == CM_MODE_CREATE))
{ {
/* FIXME: There may be many of these if 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 else
{ {
@ -352,8 +370,9 @@ bool CCABManager::ParseCmdline(int argc, char* argv[])
return false; return false;
} }
/* FIXME */ // Select MsZip by default for creating cabinets
SelectCodec(CAB_CODEC_MSZIP); if( (Mode == CM_MODE_CREATE || Mode == CM_MODE_CREATE_SIMPLE) && !IsCodecSelected() )
SelectCodec(CAB_CODEC_MSZIP);
return true; return true;
} }
@ -366,10 +385,10 @@ bool CCABManager::CreateCabinet()
{ {
ULONG Status; ULONG Status;
Status = Load((char*)&FileName); Status = Load(FileName);
if (Status != CAB_STATUS_SUCCESS) 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; return false;
} }
@ -435,9 +454,9 @@ bool CCABManager::DisplayCabinet()
{ {
if (Search.File->FileControlID != CAB_FILE_CONTINUED) if (Search.File->FileControlID != CAB_FILE_CONTINUED)
{ {
printf("%s ", Date2Str((char*)&Str, Search.File->FileDate)); printf("%s ", Date2Str(Str, Search.File->FileDate));
printf("%s ", Time2Str((char*)&Str, Search.File->FileTime)); printf("%s ", Time2Str(Str, Search.File->FileTime));
printf("%s ", Attr2Str((char*)&Str, Search.File->Attributes)); printf("%s ", Attr2Str(Str, Search.File->Attributes));
sprintf(Str, "%lu", Search.File->FileSize); sprintf(Str, "%lu", Search.File->FileSize);
printf("%s ", Pad(Str, ' ', 13)); printf("%s ", Pad(Str, ' ', 13));
printf("%s\n", Search.FileName); printf("%s\n", Search.FileName);
@ -530,7 +549,7 @@ bool CCABManager::Run()
* FUNCTION: Process cabinet * FUNCTION: Process cabinet
*/ */
{ {
printf("ReactOS Cabinet Manager - Version %s\n\n", CM_VERSION); printf("ReactOS Cabinet Manager\n\n");
switch (Mode) switch (Mode)
{ {