ReactOS 0.4.16-dev-336-gb667d82
expand.c File Reference
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <lzexpand.h>
#include <setupapi.h>
Include dependency graph for expand.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 

Functions

static int myprintf (const char *format,...)
 
static UINT CALLBACK set_outfile (PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2)
 
static UINT CALLBACK extract_callback (PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2)
 
static BOOL option_equal (LPCSTR str1, LPCSTR str2)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 21 of file expand.c.

Function Documentation

◆ extract_callback()

static UINT CALLBACK extract_callback ( PVOID  context,
UINT  notification,
UINT_PTR  param1,
UINT_PTR  param2 
)
static

Definition at line 68 of file expand.c.

69{
71
72 switch (notification)
73 {
75 {
76 LPCSTR targetname = context;
77
78 strcpy( info->FullTargetName, targetname );
79 return FILEOP_DOIT;
80 }
81 default: return NO_ERROR;
82 }
83}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define NO_ERROR
Definition: dderror.h:5
#define FILEOP_DOIT
Definition: fileqsup.h:48
#define SPFILENOTIFY_FILEINCABINET
Definition: setupapi.h:562
Definition: http.c:7252
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 92 of file expand.c.

93{
94 int ret = 0;
95 char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
96 char outfile_basename[MAX_PATH], *basename_index;
97 UINT comp;
98
99 if (argc < 3)
100 {
101 myprintf( "Usage:\n" );
102 myprintf( "\t%s infile outfile\n", argv[0] );
103 myprintf( "\t%s /r infile\n", argv[0] );
104 return 1;
105 }
106
107 if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
108 GetFullPathNameA( argv[2], sizeof(infile), infile, NULL );
109 else
110 GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );
111
112 if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
113 {
114 myprintf( "%s: can't open input file %s\n", argv[0], infile );
115 return 1;
116 }
117
118 if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
119 {
120 switch (comp)
121 {
123 outfile_basename[0] = 0;
124 if (!SetupIterateCabinetA( infile, 0, set_outfile, outfile_basename ))
125 {
126 myprintf( "%s: can't determine original name\n", argv[0] );
127 return 1;
128 }
129 GetFullPathNameA( infile, sizeof(outfile), outfile, &basename_index );
130 *basename_index = 0;
131 strcat( outfile, outfile_basename );
132 break;
134 GetExpandedNameA( infile, outfile_basename );
135 break;
136 default:
137 myprintf( "%s: can't determine original\n", argv[0] );
138 return 1;
139 }
140 }
141 else
142 GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );
143
144 if (!lstrcmpiA( infile, outfile ))
145 {
146 myprintf( "%s: can't expand file to itself\n", argv[0] );
147 return 1;
148 }
149
150 switch (comp)
151 {
154 {
155 myprintf( "%s: cabinet extraction failed\n", argv[0] );
156 return 1;
157 }
158 break;
160 {
161 INT hin, hout;
162 OFSTRUCT ofin, ofout;
163 LONG error;
164
165 if ((hin = LZOpenFileA( infile, &ofin, OF_READ )) < 0)
166 {
167 myprintf( "%s: can't open input file %s\n", argv[0], infile );
168 return 1;
169 }
170 if ((hout = LZOpenFileA( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
171 {
172 LZClose( hin );
173 myprintf( "%s: can't open output file %s\n", argv[0], outfile );
174 return 1;
175 }
176 error = LZCopy( hin, hout );
177
178 LZClose( hin );
179 LZClose( hout );
180
181 if (error < 0)
182 {
183 myprintf( "%s: LZCopy failed, error is %d\n", argv[0], error );
184 return 1;
185 }
186 break;
187 }
188 default:
189 if (!CopyFileA( infile, outfile, FALSE ))
190 {
191 myprintf( "%s: CopyFileA failed\n", argv[0] );
192 return 1;
193 }
194 break;
195 }
196 return ret;
197}
static int argc
Definition: ServiceArgs.c:12
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI CopyFileA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copy.c:404
DWORD WINAPI GetFullPathNameA(IN LPCSTR lpFileName, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart)
Definition: path.c:993
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4224
BOOL WINAPI SetupGetFileCompressionInfoExA(PCSTR source, PSTR name, DWORD len, PDWORD required, PDWORD source_size, PDWORD target_size, PUINT type)
Definition: misc.c:1411
BOOL WINAPI SetupIterateCabinetA(PCSTR CabinetFile, DWORD Reserved, PSP_FILE_CALLBACK_A MsgHandler, PVOID Context)
Definition: setupcab.c:510
static BOOL option_equal(LPCSTR str1, LPCSTR str2)
Definition: expand.c:85
static UINT CALLBACK set_outfile(PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2)
Definition: expand.c:44
static int myprintf(const char *format,...)
Definition: expand.c:29
static UINT CALLBACK extract_callback(PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2)
Definition: expand.c:68
LONG WINAPI LZCopy(HFILE src, HFILE dest)
Definition: lzexpand.c:467
void WINAPI LZClose(HFILE fd)
Definition: lzexpand.c:595
HFILE WINAPI LZOpenFileA(LPSTR fn, LPOFSTRUCT ofs, WORD mode)
Definition: lzexpand.c:551
INT WINAPI GetExpandedNameA(LPSTR in, LPSTR out)
Definition: lzexpand.c:257
#define error(str)
Definition: mkdosfs.c:1605
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
long LONG
Definition: pedump.c:60
static FILE * infile
Definition: rdjpgcom.c:65
#define FILE_COMPRESSION_WINLZA
Definition: setupapi.h:359
#define FILE_COMPRESSION_MSZIP
Definition: setupapi.h:362
int32_t INT
Definition: typedefs.h:58
int ret
#define OF_READ
Definition: winbase.h:117
#define OF_CREATE
Definition: winbase.h:126
#define OF_WRITE
Definition: winbase.h:119
static FILE * outfile
Definition: wrjpgcom.c:81

◆ myprintf()

static int myprintf ( const char format,
  ... 
)
static

Definition at line 29 of file expand.c.

30{
31 va_list va;
32 char tmp[8192];
33 DWORD w = 0;
34 int len;
35
36 va_start(va, format);
37 len = vsnprintf(tmp, sizeof(tmp), format, va);
38 if (len > 0)
40 va_end(va);
41 return w;
42}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
Definition: format.c:58
#define vsnprintf
Definition: tif_win32.c:406
#define STD_ERROR_HANDLE
Definition: winbase.h:295

Referenced by main().

◆ option_equal()

static BOOL option_equal ( LPCSTR  str1,
LPCSTR  str2 
)
static

Definition at line 85 of file expand.c.

86{
87 if (str1[0] != '/' && str1[0] != '-')
88 return FALSE;
89 return !lstrcmpA( str1 + 1, str2 );
90}
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4195

Referenced by main().

◆ set_outfile()

static UINT CALLBACK set_outfile ( PVOID  context,
UINT  notification,
UINT_PTR  param1,
UINT_PTR  param2 
)
static

Definition at line 44 of file expand.c.

45{
47 char buffer[MAX_PATH];
48 char* basename;
49
50 switch (notification)
51 {
53 {
55 if (outfile[0] != 0)
56 {
58 return FILEOP_ABORT;
59 }
60 GetFullPathNameA( info->NameInCabinet, sizeof(buffer), buffer, &basename );
62 return FILEOP_SKIP;
63 }
64 default: return NO_ERROR;
65 }
66}
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
static void basename(LPCWSTR path, LPWSTR name)
Definition: profile.c:38
#define FILEOP_SKIP
Definition: fileqsup.h:49
#define FILEOP_ABORT
Definition: fileqsup.h:47
GLuint buffer
Definition: glext.h:5915
char * LPSTR
Definition: xmlstorage.h:182

Referenced by main().