ReactOS  0.4.15-dev-448-gd6c4411
CCABManager Class Reference

#include <cabman.h>

Inheritance diagram for CCABManager:
Collaboration diagram for CCABManager:

Public Member Functions

 CCABManager ()
 
virtual ~CCABManager ()
 
bool ParseCmdline (int argc, char *argv[])
 
bool Run ()
 
bool IsVerbose ()
 
- Public Member Functions inherited from CDFParser
 CDFParser ()
 
virtual ~CDFParser ()
 
ULONG Load (char *FileName)
 
ULONG Parse ()
 
void SetFileRelativePath (char *Path)
 
- Public Member Functions inherited from CCabinet
 CCabinet ()
 
virtual ~CCabinet ()
 
bool IsSeparator (char Char)
 
charConvertPath (char *Path, bool Allocate)
 
charGetFileName (char *Path)
 
void RemoveFileName (char *Path)
 
bool NormalizePath (char *Path, ULONG Length)
 
charGetCabinetName ()
 
void SetCabinetName (char *FileName)
 
void SetDestinationPath (char *DestinationPath)
 
bool SetCabinetReservedFile (char *FileName)
 
charGetCabinetReservedFile ()
 
charGetDestinationPath ()
 
ULONG GetCurrentDiskNumber ()
 
ULONG Open ()
 
void Close ()
 
ULONG FindFirst (PCAB_SEARCH Search)
 
ULONG FindNext (PCAB_SEARCH Search)
 
ULONG ExtractFile (char *FileName)
 
void SelectCodec (LONG Id)
 
bool IsCodecSelected ()
 
ULONG AddSearchCriteria (char *SearchCriteria)
 
void DestroySearchCriteria ()
 
bool HasSearchCriteria ()
 
bool CreateSimpleCabinet ()
 
bool SetCompressionCodec (char *CodecName)
 
ULONG NewCabinet ()
 
ULONG NewDisk ()
 
ULONG NewFolder ()
 
ULONG WriteFileToScratchStorage (PCFFILE_NODE FileNode)
 
ULONG WriteDisk (ULONG MoreDisks)
 
ULONG CommitDisk (ULONG MoreDisks)
 
ULONG CloseDisk ()
 
ULONG CloseCabinet ()
 
ULONG AddFile (char *FileName)
 
void SetMaxDiskSize (ULONG Size)
 

Private Member Functions

void Usage ()
 
bool CreateCabinet ()
 
bool DisplayCabinet ()
 
bool ExtractFromCabinet ()
 
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)
 

Private Attributes

bool ProcessAll
 
ULONG Mode
 
bool PromptOnOverwrite
 
char FileName [PATH_MAX]
 
bool Verbose
 

Additional Inherited Members

- Public Attributes inherited from CDFParser
bool InfFileOnly
 
bool DontGenerateInf
 
char FileRelativePath [300]
 

Detailed Description

Definition at line 21 of file cabman.h.

Constructor & Destructor Documentation

◆ CCABManager()

CCABManager::CCABManager ( )

Definition at line 167 of file main.cxx.

171 {
172  ProcessAll = false;
173  InfFileOnly = false;
175  FileName[0] = 0;
176  Verbose = false;
177 }
#define CM_MODE_DISPLAY
Definition: cabman.h:15
bool ProcessAll
Definition: cabman.h:40
ULONG Mode
Definition: cabman.h:41
bool InfFileOnly
Definition: dfp.h:70
bool Verbose
Definition: cabman.h:44

◆ ~CCABManager()

CCABManager::~CCABManager ( )
virtual

Definition at line 180 of file main.cxx.

184 {
185 }

Member Function Documentation

◆ CreateCabinet()

bool CCABManager::CreateCabinet ( )
private

Definition at line 408 of file main.cxx.

412 {
413  ULONG Status;
414 
415  Status = Load(FileName);
416  if (Status != CAB_STATUS_SUCCESS)
417  {
418  printf("ERROR: Specified directive file could not be found: %s.\n", FileName);
419  return false;
420  }
421 
422  Status = Parse();
423 
424  return (Status == CAB_STATUS_SUCCESS ? true : false);
425 }
ULONG Parse()
Definition: dfp.cxx:195
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
Status
Definition: gdiplustypes.h:24
unsigned int ULONG
Definition: retypes.h:1
ULONG Load(char *FileName)
Definition: dfp.cxx:140
#define printf
Definition: config.h:203

Referenced by Run().

◆ DisplayCabinet()

bool CCABManager::DisplayCabinet ( )
private

Definition at line 427 of file main.cxx.

431 {
432  CAB_SEARCH Search;
433  char Str[20];
434  ULONG FileCount = 0;
435  ULONG ByteCount = 0;
436 
437  if (Open() == CAB_STATUS_SUCCESS)
438  {
439  if (Verbose)
440  {
441  printf("Cabinet %s\n\n", GetCabinetName());
442  }
443 
444  if (FindFirst(&Search) == CAB_STATUS_SUCCESS)
445  {
446  do
447  {
448  if (Search.File->FileControlID != CAB_FILE_CONTINUED)
449  {
450  printf("%s ", Date2Str(Str, Search.File->FileDate));
451  printf("%s ", Time2Str(Str, Search.File->FileTime));
452  printf("%s ", Attr2Str(Str, Search.File->Attributes));
453  sprintf(Str, "%u", (UINT)Search.File->FileSize);
454  printf("%s ", Pad(Str, ' ', 13));
455  printf("%s\n", Search.FileName);
456 
457  FileCount++;
458  ByteCount += Search.File->FileSize;
459  }
460  } while (FindNext(&Search) == CAB_STATUS_SUCCESS);
461  }
462 
464 
465  if (FileCount > 0) {
466  if (FileCount == 1)
467  printf(" 1 file ");
468  else
469  {
470  sprintf(Str, "%u", (UINT)FileCount);
471  printf(" %s files ", Pad(Str, ' ', 12));
472  }
473 
474  if (ByteCount == 1)
475  printf(" 1 byte\n");
476  else
477  {
478  sprintf(Str, "%u", (UINT)ByteCount);
479  printf("%s bytes\n", Pad(Str, ' ', 12));
480  }
481  }
482  else
483  {
484  /* There should be at least one file in a cabinet */
485  printf("WARNING: No files in cabinet.");
486  }
487  return true;
488  }
489  else
490  printf("ERROR: Cannot open file: %s\n", GetCabinetName());
491 
492  return false;
493 }
char * Pad(char *Str, char PadChar, ULONG Length)
Definition: main.cxx:29
ULONG FindFirst(PCAB_SEARCH Search)
Definition: cabinet.cxx:638
USHORT FileDate
Definition: cabinet.c:119
char * GetCabinetName()
Definition: cabinet.cxx:250
PULONG FileCount
Definition: SfcGetFiles.c:18
USHORT FileTime
Definition: cabinet.c:120
#define CAB_FILE_CONTINUED
Definition: cabinet.c:71
#define sprintf(buf, format,...)
Definition: sprintf.c:55
USHORT Attributes
Definition: cabinet.c:121
ULONG Open()
Definition: cabinet.cxx:471
char * Date2Str(char *Str, USHORT Date)
Definition: main.cxx:55
char * Time2Str(char *Str, USHORT Time)
Definition: main.cxx:86
void DestroySearchCriteria()
Definition: cabinet.cxx:327
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
ULONG FindNext(PCAB_SEARCH Search)
Definition: cabinet.cxx:653
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1061
char * Attr2Str(char *Str, USHORT Attr)
Definition: main.cxx:126
char * FileName
Definition: cabinet.h:241
unsigned int UINT
Definition: ndis.h:50
PCFFILE File
Definition: cabinet.h:79
unsigned int ULONG
Definition: retypes.h:1
ULONG FileSize
Definition: cabinet.c:116
bool Verbose
Definition: cabman.h:44
#define printf
Definition: config.h:203
USHORT FileControlID
Definition: blue.h:90

Referenced by Run().

◆ ExtractFromCabinet()

bool CCABManager::ExtractFromCabinet ( )
private

Definition at line 496 of file main.cxx.

500 {
501  bool bRet = true;
502  CAB_SEARCH Search;
503  ULONG Status;
504 
505  if (Open() == CAB_STATUS_SUCCESS)
506  {
507  if (Verbose)
508  {
509  printf("Cabinet %s\n\n", GetCabinetName());
510  }
511 
512  if (FindFirst(&Search) == CAB_STATUS_SUCCESS)
513  {
514  do
515  {
516  switch (Status = ExtractFile(Search.FileName))
517  {
518  case CAB_STATUS_SUCCESS:
519  break;
520 
522  printf("ERROR: Cabinet contains errors.\n");
523  bRet = false;
524  break;
525 
527  printf("ERROR: Cabinet uses unsupported compression type.\n");
528  bRet = false;
529  break;
530 
532  printf("ERROR: You've run out of free space on the destination volume or the volume is damaged.\n");
533  bRet = false;
534  break;
535 
536  default:
537  printf("ERROR: Unspecified error code (%u).\n", (UINT)Status);
538  bRet = false;
539  break;
540  }
541 
542  if(!bRet)
543  break;
544  } while (FindNext(&Search) == CAB_STATUS_SUCCESS);
545 
547  }
548 
549  return bRet;
550  }
551  else
552  printf("ERROR: Cannot open file: %s.\n", GetCabinetName());
553 
554  return false;
555 }
#define CAB_STATUS_INVALID_CAB
Definition: cabinet.h:31
ULONG FindFirst(PCAB_SEARCH Search)
Definition: cabinet.cxx:638
char * GetCabinetName()
Definition: cabinet.cxx:250
ULONG Open()
Definition: cabinet.cxx:471
#define CAB_STATUS_CANNOT_WRITE
Definition: cabinet.h:29
#define CAB_STATUS_UNSUPPCOMP
Definition: cabinet.h:33
void DestroySearchCriteria()
Definition: cabinet.cxx:327
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
ULONG FindNext(PCAB_SEARCH Search)
Definition: cabinet.cxx:653
ULONG ExtractFile(char *FileName)
Definition: cabinet.cxx:739
Status
Definition: gdiplustypes.h:24
char * FileName
Definition: cabinet.h:241
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
bool Verbose
Definition: cabman.h:44
#define printf
Definition: config.h:203

Referenced by Run().

◆ IsVerbose()

bool CCABManager::IsVerbose ( )
inline

Definition at line 28 of file cabman.h.

28 { return Verbose; }
bool Verbose
Definition: cabman.h:44

Referenced by CDFParser::Parse().

◆ OnAdd()

void CCABManager::OnAdd ( PCFFILE  Entry,
char FileName 
)
privatevirtual

Reimplemented from CCabinet.

Definition at line 643 of file main.cxx.

651 {
652  if (Verbose)
653  {
654  printf("Adding %s\n", GetFileName(FileName));
655  }
656 }
char * GetFileName(char *Path)
Definition: cabinet.cxx:183
bool Verbose
Definition: cabman.h:44
#define printf
Definition: config.h:203

◆ OnDiskChange()

void CCABManager::OnDiskChange ( char CabinetName,
char DiskLabel 
)
privatevirtual

Reimplemented from CCabinet.

Definition at line 627 of file main.cxx.

635 {
636  if (Verbose)
637  {
638  printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel);
639  }
640 }
PCABINET_NAME CabinetName
Definition: dfp.h:122
bool Verbose
Definition: cabman.h:44
#define printf
Definition: config.h:203
PCABINET_NAME DiskLabel
Definition: dfp.h:129

◆ OnExtract()

void CCABManager::OnExtract ( PCFFILE  File,
char FileName 
)
privatevirtual

Reimplemented from CCabinet.

Definition at line 610 of file main.cxx.

618 {
619  if (Verbose)
620  {
621  printf("Extracting %s\n", GetFileName(FileName));
622  }
623 }
char * GetFileName(char *Path)
Definition: cabinet.cxx:183
bool Verbose
Definition: cabman.h:44
#define printf
Definition: config.h:203

◆ OnOverwrite()

bool CCABManager::OnOverwrite ( PCFFILE  File,
char FileName 
)
privatevirtual

Reimplemented from CCabinet.

Definition at line 591 of file main.cxx.

601 {
602  if (Mode == CM_MODE_CREATE)
603  return true;
604 
605  /* Always overwrite */
606  return true;
607 }
ULONG Mode
Definition: cabman.h:41
#define CM_MODE_CREATE
Definition: cabman.h:14

◆ ParseCmdline()

bool CCABManager::ParseCmdline ( int  argc,
char argv[] 
)

Definition at line 223 of file main.cxx.

232 {
233  int i;
234  bool ShowUsage;
235  bool FoundCabinet = false;
236 
237  ShowUsage = (argc < 2);
238 
239  for (i = 1; i < argc; i++)
240  {
241  if (argv[i][0] == '-')
242  {
243  switch (argv[i][1])
244  {
245  case 'a':
246  case 'A':
247  ProcessAll = true;
248  break;
249 
250  case 'c':
251  case 'C':
253  break;
254 
255  case 'd':
256  case 'D':
258  break;
259 
260  case 'e':
261  case 'E':
263  break;
264 
265  case 'i':
266  case 'I':
267  InfFileOnly = true;
268  break;
269 
270  case 'l':
271  case 'L':
272  if (argv[i][2] == 0)
273  {
274  i++;
275  SetDestinationPath(&argv[i][0]);
276  }
277  else
278  SetDestinationPath(&argv[i][2]);
279 
280  break;
281 
282  case 'm':
283  case 'M':
284  // Set the compression codec (only affects compression, not decompression)
285  if(argv[i][2] == 0)
286  {
287  i++;
288 
289  if( !SetCompressionCodec(&argv[i][0]) )
290  return false;
291  }
292  else
293  {
294  if( !SetCompressionCodec(&argv[i][2]) )
295  return false;
296  }
297 
298  break;
299 
300  case 'n':
301  case 'N':
302  DontGenerateInf = true;
303  break;
304 
305  case 'R':
306  switch (argv[i][2])
307  {
308  case 'C': /* File to put in cabinet reserved area */
309  if (argv[i][3] == 0)
310  {
311  i++;
312  if (!SetCabinetReservedFile(&argv[i][0]))
313  {
314  printf("ERROR: Cannot open cabinet reserved area file.\n");
315  return false;
316  }
317  }
318  else
319  {
320  if (!SetCabinetReservedFile(&argv[i][3]))
321  {
322  printf("ERROR: Cannot open cabinet reserved area file.\n");
323  return false;
324  }
325  }
326  break;
327 
328  default:
329  printf("ERROR: Bad parameter %s.\n", argv[i]);
330  return false;
331  }
332  break;
333 
334  case 's':
335  case 'S':
337  break;
338 
339  case 'P':
340  if (argv[i][2] == 0)
341  {
342  i++;
343  SetFileRelativePath(&argv[i][0]);
344  }
345  else
346  SetFileRelativePath(&argv[i][2]);
347 
348  break;
349 
350  case 'V':
351  Verbose = true;
352  break;
353 
354  default:
355  printf("ERROR: Bad parameter %s.\n", argv[i]);
356  return false;
357  }
358  }
359  else
360  {
361  if(Mode == CM_MODE_CREATE)
362  {
363  if(FileName[0])
364  {
365  printf("ERROR: You may only specify one directive file!\n");
366  return false;
367  }
368  else
369  {
370  // For creating cabinets, this argument is the path to the directive file
371  strcpy(FileName, argv[i]);
372  }
373  }
374  else if(FoundCabinet)
375  {
376  // For creating simple cabinets, displaying or extracting them, add the argument as a search criteria
378  }
379  else
380  {
382  FoundCabinet = true;
383  }
384  }
385  }
386 
387  if (ShowUsage)
388  {
389  Usage();
390  return false;
391  }
392 
393  // Select MsZip by default for creating cabinets
396 
397  // Search criteria (= the filename argument) is necessary for creating a simple cabinet
399  {
400  printf("ERROR: You have to enter input file names!\n");
401  return false;
402  }
403 
404  return true;
405 }
void SetDestinationPath(char *DestinationPath)
Definition: cabinet.cxx:272
static int argc
Definition: ServiceArgs.c:12
#define CM_MODE_DISPLAY
Definition: cabman.h:15
bool DontGenerateInf
Definition: dfp.h:71
bool IsCodecSelected()
Definition: cabinet.cxx:1099
void SetFileRelativePath(char *Path)
Definition: dfp.cxx:356
#define CM_MODE_CREATE_SIMPLE
Definition: cabman.h:17
bool SetCompressionCodec(char *CodecName)
Definition: cabinet.cxx:361
#define argv
Definition: mplay32.c:18
bool ProcessAll
Definition: cabman.h:40
#define CAB_CODEC_MSZIP
Definition: cabinet.h:48
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
bool SetCabinetReservedFile(char *FileName)
Definition: cabinet.cxx:392
ULONG Mode
Definition: cabman.h:41
void Usage()
Definition: main.cxx:188
#define CM_MODE_CREATE
Definition: cabman.h:14
bool InfFileOnly
Definition: dfp.h:70
ULONG AddSearchCriteria(char *SearchCriteria)
Definition: cabinet.cxx:285
void SelectCodec(LONG Id)
Definition: cabinet.cxx:1109
static void ShowUsage(int ExitCode)
Definition: msiexec.c:59
bool HasSearchCriteria()
Definition: cabinet.cxx:351
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
bool Verbose
Definition: cabman.h:44
void SetCabinetName(char *FileName)
Definition: cabinet.cxx:261
#define CM_MODE_EXTRACT
Definition: cabman.h:16
#define printf
Definition: config.h:203

Referenced by main().

◆ Run()

bool CCABManager::Run ( void  )

Definition at line 558 of file main.cxx.

562 {
563  if (Verbose)
564  {
565  printf("ReactOS Cabinet Manager\n\n");
566  }
567 
568  switch (Mode)
569  {
570  case CM_MODE_CREATE:
571  return CreateCabinet();
572 
573  case CM_MODE_DISPLAY:
574  return DisplayCabinet();
575 
576  case CM_MODE_EXTRACT:
577  return ExtractFromCabinet();
578 
580  return CreateSimpleCabinet();
581 
582  default:
583  break;
584  }
585  return false;
586 }
#define CM_MODE_DISPLAY
Definition: cabman.h:15
#define CM_MODE_CREATE_SIMPLE
Definition: cabman.h:17
bool ExtractFromCabinet()
Definition: main.cxx:496
ULONG Mode
Definition: cabman.h:41
bool DisplayCabinet()
Definition: main.cxx:427
#define CM_MODE_CREATE
Definition: cabman.h:14
bool CreateCabinet()
Definition: main.cxx:408
bool CreateSimpleCabinet()
Definition: cabinet.cxx:1684
bool Verbose
Definition: cabman.h:44
#define CM_MODE_EXTRACT
Definition: cabman.h:16
#define printf
Definition: config.h:203

Referenced by main().

◆ Usage()

void CCABManager::Usage ( )
private

Definition at line 188 of file main.cxx.

192 {
193  printf("ReactOS Cabinet Manager\n\n");
194  printf("CABMAN [-D | -E] [-A] [-L dir] cabinet [filename ...]\n");
195  printf("CABMAN [-M mode] -C dirfile [-I] [-RC file] [-P dir]\n");
196  printf("CABMAN [-M mode] -S cabinet filename [...]\n");
197  printf(" cabinet Cabinet file.\n");
198  printf(" filename Name of the file to add to or extract from the cabinet.\n");
199  printf(" Wild cards and multiple filenames\n");
200  printf(" (separated by blanks) may be used.\n\n");
201 
202  printf(" dirfile Name of the directive file to use.\n");
203 
204  printf(" -A Process ALL cabinets. Follows cabinet chain\n");
205  printf(" starting in first cabinet mentioned.\n");
206  printf(" -C Create cabinet.\n");
207  printf(" -D Display cabinet directory.\n");
208  printf(" -E Extract files from cabinet.\n");
209  printf(" -I Don't create the cabinet, only the .inf file.\n");
210  printf(" -L dir Location to place extracted or generated files\n");
211  printf(" (default is current directory).\n");
212  printf(" -M mode Specify the compression method to use:\n");
213  printf(" raw - No compression\n");
214  printf(" mszip - MsZip compression (default)\n");
215  printf(" -N Don't create the .inf file, only the cabinet.\n");
216  printf(" -RC Specify file to put in cabinet reserved area\n");
217  printf(" (size must be less than 64KB).\n");
218  printf(" -S Create simple cabinet.\n");
219  printf(" -P dir Files in the .dff are relative to this directory.\n");
220  printf(" -V Verbose mode (prints more messages).\n");
221 }
#define printf
Definition: config.h:203

Referenced by ParseCmdline().

Member Data Documentation

◆ FileName

char CCABManager::FileName[PATH_MAX]
private

Definition at line 43 of file cabman.h.

◆ Mode

ULONG CCABManager::Mode
private

Definition at line 41 of file cabman.h.

Referenced by CCABManager(), OnOverwrite(), ParseCmdline(), and Run().

◆ ProcessAll

bool CCABManager::ProcessAll
private

Definition at line 40 of file cabman.h.

Referenced by CCABManager(), and ParseCmdline().

◆ PromptOnOverwrite

bool CCABManager::PromptOnOverwrite
private

Definition at line 42 of file cabman.h.

◆ Verbose

bool CCABManager::Verbose
private

The documentation for this class was generated from the following files: