ReactOS 0.4.15-dev-7704-gc07eb9f
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)
 
void ConvertPath (std::string &Path)
 
std::string GetFileName (const std::string &Path)
 
void NormalizePath (std::string &Path)
 
charGetCabinetName ()
 
void SetCabinetName (const char *FileName)
 
void SetDestinationPath (const char *DestinationPath)
 
bool SetCabinetReservedFile (const char *FileName)
 
const charGetDestinationPath ()
 
ULONG GetCurrentDiskNumber ()
 
ULONG Open ()
 
void Close ()
 
ULONG FindFirst (PCAB_SEARCH Search)
 
ULONG FindNext (PCAB_SEARCH Search)
 
ULONG ExtractFile (const char *FileName)
 
void SelectCodec (LONG Id)
 
bool IsCodecSelected ()
 
ULONG AddSearchCriteria (const std::string &SearchCriteria, const std::string &TargetFolder)
 
void DestroySearchCriteria ()
 
bool HasSearchCriteria ()
 
std::string CreateCabFilename (PCFFILE_NODE Node)
 
bool CreateSimpleCabinet ()
 
bool SetCompressionCodec (const 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 (const std::string &FileName, const std::string &TargetFolder)
 
void SetMaxDiskSize (ULONG Size)
 
virtual bool OnOverwrite (PCFFILE Entry, const char *FileName)
 
virtual void OnExtract (PCFFILE Entry, const char *FileName)
 
virtual void OnDiskChange (const char *CabinetName, const char *DiskLabel)
 
virtual void OnVerboseMessage (const char *Message)
 
virtual void OnAdd (PCFFILE Entry, const char *FileName)
 
virtual bool OnCabinetName (ULONG Number, char *Name)
 
virtual bool OnDiskLabel (ULONG Number, char *Label)
 

Private Member Functions

void Usage ()
 
bool CreateCabinet ()
 
bool DisplayCabinet ()
 
bool ExtractFromCabinet ()
 
virtual bool OnOverwrite (PCFFILE File, const char *FileName) override
 
virtual void OnExtract (PCFFILE File, const char *FileName) override
 
virtual void OnDiskChange (const char *CabinetName, const char *DiskLabel) override
 
virtual void OnAdd (PCFFILE Entry, const char *FileName) override
 
virtual void OnVerboseMessage (const char *Message) override
 

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
 
std::string FileRelativePath
 

Detailed Description

Definition at line 21 of file cabman.h.

Constructor & Destructor Documentation

◆ CCABManager()

CCABManager::CCABManager ( )

Definition at line 167 of file cabman.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:43
bool Verbose
Definition: cabman.h:47
ULONG Mode
Definition: cabman.h:44
bool InfFileOnly
Definition: dfp.h:70

◆ ~CCABManager()

CCABManager::~CCABManager ( )
virtual

Definition at line 180 of file cabman.cxx.

184{
185}

Member Function Documentation

◆ CreateCabinet()

bool CCABManager::CreateCabinet ( )
private

Definition at line 423 of file cabman.cxx.

427{
429
432 {
433 printf("ERROR: Specified directive file could not be found: %s.\n", FileName);
434 return false;
435 }
436
437 Status = Parse();
438
439 return (Status == CAB_STATUS_SUCCESS ? true : false);
440}
#define CAB_STATUS_SUCCESS
Definition: cabinet.h:23
ULONG Parse()
Definition: dfp.cxx:193
ULONG Load(char *FileName)
Definition: dfp.cxx:138
#define printf
Definition: freeldr.h:94
Status
Definition: gdiplustypes.h:25
uint32_t ULONG
Definition: typedefs.h:59

Referenced by Run().

◆ DisplayCabinet()

bool CCABManager::DisplayCabinet ( )
private

Definition at line 442 of file cabman.cxx.

446{
447 CAB_SEARCH Search;
448 char Str[20];
449 ULONG FileCount = 0;
450 ULONG ByteCount = 0;
451
452 if (Open() == CAB_STATUS_SUCCESS)
453 {
454 if (Verbose)
455 {
456 printf("Cabinet %s\n\n", GetCabinetName());
457 }
458
459 if (FindFirst(&Search) == CAB_STATUS_SUCCESS)
460 {
461 do
462 {
464 {
465 printf("%s ", Date2Str(Str, Search.File->FileDate));
466 printf("%s ", Time2Str(Str, Search.File->FileTime));
467 printf("%s ", Attr2Str(Str, Search.File->Attributes));
468 sprintf(Str, "%u", (UINT)Search.File->FileSize);
469 printf("%s ", Pad(Str, ' ', 13));
470 printf("%s\n", Search.FileName.c_str());
471
472 FileCount++;
473 ByteCount += Search.File->FileSize;
474 }
475 } while (FindNext(&Search) == CAB_STATUS_SUCCESS);
476 }
477
479
480 if (FileCount > 0) {
481 if (FileCount == 1)
482 printf(" 1 file ");
483 else
484 {
485 sprintf(Str, "%u", (UINT)FileCount);
486 printf(" %s files ", Pad(Str, ' ', 12));
487 }
488
489 if (ByteCount == 1)
490 printf(" 1 byte\n");
491 else
492 {
493 sprintf(Str, "%u", (UINT)ByteCount);
494 printf("%s bytes\n", Pad(Str, ' ', 12));
495 }
496 }
497 else
498 {
499 /* There should be at least one file in a cabinet */
500 printf("WARNING: No files in cabinet.");
501 }
502 return true;
503 }
504 else
505 printf("ERROR: Cannot open file: %s\n", GetCabinetName());
506
507 return false;
508}
PULONG FileCount
Definition: SfcGetFiles.c:18
#define CAB_FILE_CONTINUED
Definition: cabinet.c:73
char * Date2Str(char *Str, USHORT Date)
Definition: cabman.cxx:55
char * Time2Str(char *Str, USHORT Time)
Definition: cabman.cxx:86
char * Pad(char *Str, char PadChar, ULONG Length)
Definition: cabman.cxx:29
char * Attr2Str(char *Str, USHORT Attr)
Definition: cabman.cxx:126
void DestroySearchCriteria()
Definition: cabinet.cxx:256
ULONG FindFirst(PCAB_SEARCH Search)
Definition: cabinet.cxx:551
ULONG Open()
Definition: cabinet.cxx:387
ULONG FindNext(PCAB_SEARCH Search)
Definition: cabinet.cxx:566
char * GetCabinetName()
Definition: cabinet.cxx:194
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int UINT
Definition: ndis.h:50
std::string FileName
Definition: cabinet.h:247
PCFFILE File
Definition: cabinet.h:79
USHORT FileControlID
Definition: cabinet.h:183
ULONG FileSize
Definition: cabinet.c:118
USHORT FileTime
Definition: cabinet.c:122
USHORT FileDate
Definition: cabinet.c:121
USHORT Attributes
Definition: cabinet.c:123
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099

Referenced by Run().

◆ ExtractFromCabinet()

bool CCABManager::ExtractFromCabinet ( )
private

Definition at line 511 of file cabman.cxx.

515{
516 bool bRet = true;
517 CAB_SEARCH Search;
519
520 if (Open() == CAB_STATUS_SUCCESS)
521 {
522 if (Verbose)
523 {
524 printf("Cabinet %s\n\n", GetCabinetName());
525 }
526
527 if (FindFirst(&Search) == CAB_STATUS_SUCCESS)
528 {
529 do
530 {
531 switch (Status = ExtractFile(Search.FileName.c_str()))
532 {
534 break;
535
537 printf("ERROR: Cabinet contains errors.\n");
538 bRet = false;
539 break;
540
542 printf("ERROR: Cabinet uses unsupported compression type.\n");
543 bRet = false;
544 break;
545
547 printf("ERROR: You've run out of free space on the destination volume or the volume is damaged.\n");
548 bRet = false;
549 break;
550
551 default:
552 printf("ERROR: Unspecified error code (%u).\n", (UINT)Status);
553 bRet = false;
554 break;
555 }
556
557 if(!bRet)
558 break;
559 } while (FindNext(&Search) == CAB_STATUS_SUCCESS);
560
562 }
563
564 return bRet;
565 }
566 else
567 printf("ERROR: Cannot open file: %s.\n", GetCabinetName());
568
569 return false;
570}
#define CAB_STATUS_UNSUPPCOMP
Definition: cabinet.h:33
#define CAB_STATUS_CANNOT_WRITE
Definition: cabinet.h:29
#define CAB_STATUS_INVALID_CAB
Definition: cabinet.h:31
ULONG ExtractFile(const char *FileName)
Definition: cabinet.cxx:648

Referenced by Run().

◆ IsVerbose()

bool CCABManager::IsVerbose ( )
inline

Definition at line 28 of file cabman.h.

28{ return Verbose; }

◆ OnAdd()

void CCABManager::OnAdd ( PCFFILE  Entry,
const char FileName 
)
overrideprivatevirtual

Reimplemented from CCabinet.

Definition at line 658 of file cabman.cxx.

666{
667 if (Verbose)
668 {
669 printf("Adding %s\n", GetFileName(FileName).c_str());
670 }
671}
std::string GetFileName(const std::string &Path)
Definition: cabinet.cxx:158

◆ OnDiskChange()

void CCABManager::OnDiskChange ( const char CabinetName,
const char DiskLabel 
)
overrideprivatevirtual

Reimplemented from CCabinet.

Definition at line 642 of file cabman.cxx.

650{
651 if (Verbose)
652 {
653 printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel);
654 }
655}
PCABINET_NAME DiskLabel
Definition: dfp.h:129
PCABINET_NAME CabinetName
Definition: dfp.h:122

◆ OnExtract()

void CCABManager::OnExtract ( PCFFILE  File,
const char FileName 
)
overrideprivatevirtual

Reimplemented from CCabinet.

Definition at line 625 of file cabman.cxx.

633{
634 if (Verbose)
635 {
636 printf("Extracting %s\n", GetFileName(FileName).c_str());
637 }
638}

◆ OnOverwrite()

bool CCABManager::OnOverwrite ( PCFFILE  File,
const char FileName 
)
overrideprivatevirtual

Reimplemented from CCabinet.

Definition at line 606 of file cabman.cxx.

616{
617 if (Mode == CM_MODE_CREATE)
618 return true;
619
620 /* Always overwrite */
621 return true;
622}
#define CM_MODE_CREATE
Definition: cabman.h:14

◆ OnVerboseMessage()

void CCABManager::OnVerboseMessage ( const char Message)
overrideprivatevirtual

Reimplemented from CCabinet.

Definition at line 673 of file cabman.cxx.

674{
675 if (Verbose)
676 {
677 printf("%s", Message);
678 }
679}
static const WCHAR Message[]
Definition: register.c:74

◆ ParseCmdline()

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

Definition at line 224 of file cabman.cxx.

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

Referenced by main().

◆ Run()

bool CCABManager::Run ( )

Definition at line 573 of file cabman.cxx.

577{
578 if (Verbose)
579 {
580 printf("ReactOS Cabinet Manager\n\n");
581 }
582
583 switch (Mode)
584 {
585 case CM_MODE_CREATE:
586 return CreateCabinet();
587
588 case CM_MODE_DISPLAY:
589 return DisplayCabinet();
590
591 case CM_MODE_EXTRACT:
592 return ExtractFromCabinet();
593
595 return CreateSimpleCabinet();
596
597 default:
598 break;
599 }
600 return false;
601}
bool ExtractFromCabinet()
Definition: cabman.cxx:511
bool CreateCabinet()
Definition: cabman.cxx:423
bool DisplayCabinet()
Definition: cabman.cxx:442
bool CreateSimpleCabinet()
Definition: cabinet.cxx:1581

Referenced by main().

◆ Usage()

void CCABManager::Usage ( )
private

Definition at line 188 of file cabman.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 [-F folder] [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(" -F Put the files from the next 'filename' filter in the cab in folder\filename.\n");
210 printf(" -I Don't create the cabinet, only the .inf file.\n");
211 printf(" -L dir Location to place extracted or generated files\n");
212 printf(" (default is current directory).\n");
213 printf(" -M mode Specify the compression method to use:\n");
214 printf(" raw - No compression\n");
215 printf(" mszip - MsZip compression (default)\n");
216 printf(" -N Don't create the .inf file, only the cabinet.\n");
217 printf(" -RC Specify file to put in cabinet reserved area\n");
218 printf(" (size must be less than 64KB).\n");
219 printf(" -S Create simple cabinet.\n");
220 printf(" -P dir Files in the .dff are relative to this directory.\n");
221 printf(" -V Verbose mode (prints more messages).\n");
222}

Referenced by ParseCmdline().

Member Data Documentation

◆ FileName

char CCABManager::FileName[PATH_MAX]
private

Definition at line 46 of file cabman.h.

◆ Mode

ULONG CCABManager::Mode
private

Definition at line 44 of file cabman.h.

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

◆ ProcessAll

bool CCABManager::ProcessAll
private

Definition at line 43 of file cabman.h.

Referenced by CCABManager(), and ParseCmdline().

◆ PromptOnOverwrite

bool CCABManager::PromptOnOverwrite
private

Definition at line 45 of file cabman.h.

◆ Verbose

bool CCABManager::Verbose
private

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