Minor mods.
[reactos.git] / reactos / apps / utils / cabman / test.cpp
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Test program for cabinet classes
4 * FILE: apps/cabman/test.cpp
5 * PURPOSE: Test program
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * REVISIONS:
8 * CSH 21/03-2001 Created
9 */
10 #include <stdlib.h>
11 #include <stdarg.h>
12 #include <string.h>
13 #include <stdio.h>
14 #include <conio.h>
15 #include <windows.h>
16 #include "test.h"
17
18
19 #ifdef DBG
20
21 DWORD DebugTraceLevel = MIN_TRACE;
22 //DWORD DebugTraceLevel = MID_TRACE;
23 //DWORD DebugTraceLevel = MAX_TRACE;
24
25 #endif /* DBG */
26
27
28 /* CCABManager */
29
30 CCABTest::CCABTest()
31 /*
32 * FUNCTION: Default constructor
33 */
34 {
35 PromptOnOverwrite = FALSE;
36 }
37
38
39 CCABTest::~CCABTest()
40 /*
41 * FUNCTION: Default destructor
42 */
43 {
44 }
45
46
47 VOID CCABTest::ExtractFromCabinet()
48 /*
49 * FUNCTION: Extract file(s) from cabinet
50 */
51 {
52 CAB_SEARCH Search;
53 ULONG Status;
54
55 if (Open() == CAB_STATUS_SUCCESS) {
56 printf("Cabinet %s\n\n", GetCabinetName());
57
58 if (FindFirst("", &Search) == CAB_STATUS_SUCCESS) {
59 do {
60 switch (Status = ExtractFile(Search.FileName)) {
61 case CAB_STATUS_SUCCESS:
62 break;
63 case CAB_STATUS_INVALID_CAB:
64 printf("Cabinet contains errors.\n");
65 return;
66 case CAB_STATUS_UNSUPPCOMP:
67 printf("Cabinet uses unsupported compression type.\n");
68 return;
69 case CAB_STATUS_CANNOT_WRITE:
70 printf("You've run out of free space on the destination volume or the volume is damaged.\n");
71 return;
72 default:
73 printf("Unspecified error code (%d).\n", (UINT)Status);
74 return;
75 }
76 } while (FindNext(&Search) == CAB_STATUS_SUCCESS);
77 }
78 } else {
79 printf("Cannot not open file: %s.\n", GetCabinetName());
80 }
81 }
82
83
84 /* Event handlers */
85
86 BOOL CCABTest::OnOverwrite(PCFFILE File,
87 LPTSTR FileName)
88 /*
89 * FUNCTION: Called when extracting a file and it already exists
90 * ARGUMENTS:
91 * File = Pointer to CFFILE for file being extracted
92 * Filename = Pointer to buffer with name of file (full path)
93 * RETURNS
94 * TRUE if the file should be overwritten, FALSE if not
95 */
96 {
97 TCHAR ch;
98
99 /* Should we prompt on overwrite? */
100 if (!PromptOnOverwrite)
101 return TRUE;
102
103 /* Ask if file should be overwritten */
104 printf("Overwrite %s (Yes/No/All)? ", GetFileName(FileName));
105
106 for (;;) {
107 ch = _getch();
108 switch (ch) {
109 case 'Y':
110 case 'y': printf("%c\n", ch); return TRUE;
111 case 'N':
112 case 'n': printf("%c\n", ch); return FALSE;
113 case 'A':
114 case 'a': printf("%c\n", ch); PromptOnOverwrite = FALSE; return TRUE;
115 }
116 }
117 }
118
119
120 VOID CCABTest::OnExtract(PCFFILE File,
121 LPTSTR FileName)
122 /*
123 * FUNCTION: Called just before extracting a file
124 * ARGUMENTS:
125 * File = Pointer to CFFILE for file being extracted
126 * FileName = Pointer to buffer with name of file (full path)
127 */
128 {
129 printf("Extracting %s\n", GetFileName(FileName));
130 }
131
132
133
134 VOID CCABTest::OnDiskChange(LPTSTR CabinetName,
135 LPTSTR DiskLabel)
136 /*
137 * FUNCTION: Called when a new disk is to be processed
138 * ARGUMENTS:
139 * CabinetName = Pointer to buffer with name of cabinet
140 * DiskLabel = Pointer to buffer with label of disk
141 */
142 {
143 printf("\nChanging to cabinet %s - %s\n\n", CabinetName, DiskLabel);
144 }
145
146
147 INT main(INT argc, PCHAR argv[])
148 /*
149 * FUNCTION: Main entry point
150 * ARGUMENTS:
151 * argc = Number of arguments on command line
152 * argv = Pointer to list of command line arguments
153 */
154 {
155 CCABTest CABTest;
156
157 // Specify your cabinet filename here
158 CABTest.SetCabinetName("ros1.cab");
159 CABTest.ExtractFromCabinet();
160
161 return 0;
162 }
163
164 /* EOF */