diff options
Diffstat (limited to 'contrib/minizip/miniunz.c')
-rw-r--r-- | contrib/minizip/miniunz.c | 609 |
1 files changed, 322 insertions, 287 deletions
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index f3b7832..938d4ef 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c | |||
@@ -17,7 +17,12 @@ | |||
17 | 17 | ||
18 | #define CASESENSITIVITY (0) | 18 | #define CASESENSITIVITY (0) |
19 | #define WRITEBUFFERSIZE (8192) | 19 | #define WRITEBUFFERSIZE (8192) |
20 | #define MAXFILENAME (256) | ||
20 | 21 | ||
22 | #ifdef WIN32 | ||
23 | #define USEWIN32IOAPI | ||
24 | #include "iowin32.h" | ||
25 | #endif | ||
21 | /* | 26 | /* |
22 | mini unzip, demo of unzip package | 27 | mini unzip, demo of unzip package |
23 | 28 | ||
@@ -34,9 +39,9 @@ | |||
34 | dosdate : the new date at the MSDos format (4 bytes) | 39 | dosdate : the new date at the MSDos format (4 bytes) |
35 | tmu_date : the SAME new date at the tm_unz format */ | 40 | tmu_date : the SAME new date at the tm_unz format */ |
36 | void change_file_date(filename,dosdate,tmu_date) | 41 | void change_file_date(filename,dosdate,tmu_date) |
37 | const char *filename; | 42 | const char *filename; |
38 | uLong dosdate; | 43 | uLong dosdate; |
39 | tm_unz tmu_date; | 44 | tm_unz tmu_date; |
40 | { | 45 | { |
41 | #ifdef WIN32 | 46 | #ifdef WIN32 |
42 | HANDLE hFile; | 47 | HANDLE hFile; |
@@ -75,17 +80,17 @@ void change_file_date(filename,dosdate,tmu_date) | |||
75 | As I don't know well Unix, I wait feedback for the unix portion */ | 80 | As I don't know well Unix, I wait feedback for the unix portion */ |
76 | 81 | ||
77 | int mymkdir(dirname) | 82 | int mymkdir(dirname) |
78 | const char* dirname; | 83 | const char* dirname; |
79 | { | 84 | { |
80 | int ret=0; | 85 | int ret=0; |
81 | #ifdef WIN32 | 86 | #ifdef WIN32 |
82 | ret = mkdir(dirname); | 87 | ret = mkdir(dirname); |
83 | #else | 88 | #else |
84 | #ifdef unix | 89 | #ifdef unix |
85 | ret = mkdir (dirname,0775); | 90 | ret = mkdir (dirname,0775); |
86 | #endif | 91 | #endif |
87 | #endif | 92 | #endif |
88 | return ret; | 93 | return ret; |
89 | } | 94 | } |
90 | 95 | ||
91 | int makedir (newdir) | 96 | int makedir (newdir) |
@@ -93,14 +98,14 @@ int makedir (newdir) | |||
93 | { | 98 | { |
94 | char *buffer ; | 99 | char *buffer ; |
95 | char *p; | 100 | char *p; |
96 | int len = strlen(newdir); | 101 | int len = (int)strlen(newdir); |
97 | 102 | ||
98 | if (len <= 0) | 103 | if (len <= 0) |
99 | return 0; | 104 | return 0; |
100 | 105 | ||
101 | buffer = (char*)malloc(len+1); | 106 | buffer = (char*)malloc(len+1); |
102 | strcpy(buffer,newdir); | 107 | strcpy(buffer,newdir); |
103 | 108 | ||
104 | if (buffer[len-1] == '/') { | 109 | if (buffer[len-1] == '/') { |
105 | buffer[len-1] = '\0'; | 110 | buffer[len-1] = '\0'; |
106 | } | 111 | } |
@@ -135,104 +140,105 @@ int makedir (newdir) | |||
135 | 140 | ||
136 | void do_banner() | 141 | void do_banner() |
137 | { | 142 | { |
138 | printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n"); | 143 | printf("MiniUnz 0.15, demo of zLib + Unz package written by Gilles Vollant\n"); |
139 | printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n"); | 144 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
140 | } | 145 | } |
141 | 146 | ||
142 | void do_help() | 147 | void do_help() |
143 | { | 148 | { |
144 | printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ; | 149 | printf("Usage : miniunz [-exvlo] file.zip [file_to_extract]\n\n") ; |
145 | } | 150 | } |
146 | 151 | ||
147 | 152 | ||
148 | int do_list(uf) | 153 | int do_list(uf) |
149 | unzFile uf; | 154 | unzFile uf; |
150 | { | 155 | { |
151 | uLong i; | 156 | uLong i; |
152 | unz_global_info gi; | 157 | unz_global_info gi; |
153 | int err; | 158 | int err; |
154 | 159 | ||
155 | err = unzGetGlobalInfo (uf,&gi); | 160 | err = unzGetGlobalInfo (uf,&gi); |
156 | if (err!=UNZ_OK) | 161 | if (err!=UNZ_OK) |
157 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); | 162 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); |
158 | printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); | 163 | printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); |
159 | printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); | 164 | printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); |
160 | for (i=0;i<gi.number_entry;i++) | 165 | for (i=0;i<gi.number_entry;i++) |
161 | { | 166 | { |
162 | char filename_inzip[256]; | 167 | char filename_inzip[256]; |
163 | unz_file_info file_info; | 168 | unz_file_info file_info; |
164 | uLong ratio=0; | 169 | uLong ratio=0; |
165 | const char *string_method; | 170 | const char *string_method; |
166 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); | 171 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); |
167 | if (err!=UNZ_OK) | 172 | if (err!=UNZ_OK) |
168 | { | 173 | { |
169 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); | 174 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); |
170 | break; | 175 | break; |
171 | } | 176 | } |
172 | if (file_info.uncompressed_size>0) | 177 | if (file_info.uncompressed_size>0) |
173 | ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; | 178 | ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; |
174 | 179 | ||
175 | if (file_info.compression_method==0) | 180 | if (file_info.compression_method==0) |
176 | string_method="Stored"; | 181 | string_method="Stored"; |
177 | else | 182 | else |
178 | if (file_info.compression_method==Z_DEFLATED) | 183 | if (file_info.compression_method==Z_DEFLATED) |
179 | { | 184 | { |
180 | uInt iLevel=(uInt)((file_info.flag & 0x6)/2); | 185 | uInt iLevel=(uInt)((file_info.flag & 0x6)/2); |
181 | if (iLevel==0) | 186 | if (iLevel==0) |
182 | string_method="Defl:N"; | 187 | string_method="Defl:N"; |
183 | else if (iLevel==1) | 188 | else if (iLevel==1) |
184 | string_method="Defl:X"; | 189 | string_method="Defl:X"; |
185 | else if ((iLevel==2) || (iLevel==3)) | 190 | else if ((iLevel==2) || (iLevel==3)) |
186 | string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ | 191 | string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ |
187 | } | 192 | } |
188 | else | 193 | else |
189 | string_method="Unkn. "; | 194 | string_method="Unkn. "; |
190 | 195 | ||
191 | printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", | 196 | printf("%7lu %6s %7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", |
192 | file_info.uncompressed_size,string_method,file_info.compressed_size, | 197 | file_info.uncompressed_size,string_method,file_info.compressed_size, |
193 | ratio, | 198 | ratio, |
194 | (uLong)file_info.tmu_date.tm_mon + 1, | 199 | (uLong)file_info.tmu_date.tm_mon + 1, |
195 | (uLong)file_info.tmu_date.tm_mday, | 200 | (uLong)file_info.tmu_date.tm_mday, |
196 | (uLong)file_info.tmu_date.tm_year % 100, | 201 | (uLong)file_info.tmu_date.tm_year % 100, |
197 | (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, | 202 | (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, |
198 | (uLong)file_info.crc,filename_inzip); | 203 | (uLong)file_info.crc,filename_inzip); |
199 | if ((i+1)<gi.number_entry) | 204 | if ((i+1)<gi.number_entry) |
200 | { | 205 | { |
201 | err = unzGoToNextFile(uf); | 206 | err = unzGoToNextFile(uf); |
202 | if (err!=UNZ_OK) | 207 | if (err!=UNZ_OK) |
203 | { | 208 | { |
204 | printf("error %d with zipfile in unzGoToNextFile\n",err); | 209 | printf("error %d with zipfile in unzGoToNextFile\n",err); |
205 | break; | 210 | break; |
206 | } | 211 | } |
207 | } | 212 | } |
208 | } | 213 | } |
209 | 214 | ||
210 | return 0; | 215 | return 0; |
211 | } | 216 | } |
212 | 217 | ||
213 | 218 | ||
214 | int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite) | 219 | int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) |
215 | unzFile uf; | 220 | unzFile uf; |
216 | const int* popt_extract_without_path; | 221 | const int* popt_extract_without_path; |
217 | int* popt_overwrite; | 222 | int* popt_overwrite; |
223 | const char* password; | ||
218 | { | 224 | { |
219 | char filename_inzip[256]; | 225 | char filename_inzip[256]; |
220 | char* filename_withoutpath; | 226 | char* filename_withoutpath; |
221 | char* p; | 227 | char* p; |
222 | int err=UNZ_OK; | 228 | int err=UNZ_OK; |
223 | FILE *fout=NULL; | 229 | FILE *fout=NULL; |
224 | void* buf; | 230 | void* buf; |
225 | uInt size_buf; | 231 | uInt size_buf; |
226 | |||
227 | unz_file_info file_info; | ||
228 | uLong ratio=0; | ||
229 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); | ||
230 | 232 | ||
231 | if (err!=UNZ_OK) | 233 | unz_file_info file_info; |
232 | { | 234 | uLong ratio=0; |
233 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); | 235 | err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); |
234 | return err; | 236 | |
235 | } | 237 | if (err!=UNZ_OK) |
238 | { | ||
239 | printf("error %d with zipfile in unzGetCurrentFileInfo\n",err); | ||
240 | return err; | ||
241 | } | ||
236 | 242 | ||
237 | size_buf = WRITEBUFFERSIZE; | 243 | size_buf = WRITEBUFFERSIZE; |
238 | buf = (void*)malloc(size_buf); | 244 | buf = (void*)malloc(size_buf); |
@@ -242,71 +248,71 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite) | |||
242 | return UNZ_INTERNALERROR; | 248 | return UNZ_INTERNALERROR; |
243 | } | 249 | } |
244 | 250 | ||
245 | p = filename_withoutpath = filename_inzip; | 251 | p = filename_withoutpath = filename_inzip; |
246 | while ((*p) != '\0') | 252 | while ((*p) != '\0') |
247 | { | 253 | { |
248 | if (((*p)=='/') || ((*p)=='\\')) | 254 | if (((*p)=='/') || ((*p)=='\\')) |
249 | filename_withoutpath = p+1; | 255 | filename_withoutpath = p+1; |
250 | p++; | 256 | p++; |
251 | } | 257 | } |
252 | 258 | ||
253 | if ((*filename_withoutpath)=='\0') | 259 | if ((*filename_withoutpath)=='\0') |
254 | { | 260 | { |
255 | if ((*popt_extract_without_path)==0) | 261 | if ((*popt_extract_without_path)==0) |
256 | { | 262 | { |
257 | printf("creating directory: %s\n",filename_inzip); | 263 | printf("creating directory: %s\n",filename_inzip); |
258 | mymkdir(filename_inzip); | 264 | mymkdir(filename_inzip); |
259 | } | 265 | } |
260 | } | 266 | } |
261 | else | 267 | else |
262 | { | 268 | { |
263 | const char* write_filename; | 269 | const char* write_filename; |
264 | int skip=0; | 270 | int skip=0; |
265 | 271 | ||
266 | if ((*popt_extract_without_path)==0) | 272 | if ((*popt_extract_without_path)==0) |
267 | write_filename = filename_inzip; | 273 | write_filename = filename_inzip; |
268 | else | 274 | else |
269 | write_filename = filename_withoutpath; | 275 | write_filename = filename_withoutpath; |
270 | 276 | ||
271 | err = unzOpenCurrentFile(uf); | 277 | err = unzOpenCurrentFilePassword(uf,password); |
272 | if (err!=UNZ_OK) | 278 | if (err!=UNZ_OK) |
273 | { | 279 | { |
274 | printf("error %d with zipfile in unzOpenCurrentFile\n",err); | 280 | printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err); |
275 | } | 281 | } |
276 | 282 | ||
277 | if (((*popt_overwrite)==0) && (err==UNZ_OK)) | 283 | if (((*popt_overwrite)==0) && (err==UNZ_OK)) |
278 | { | 284 | { |
279 | char rep; | 285 | char rep=0; |
280 | FILE* ftestexist; | 286 | FILE* ftestexist; |
281 | ftestexist = fopen(write_filename,"rb"); | 287 | ftestexist = fopen(write_filename,"rb"); |
282 | if (ftestexist!=NULL) | 288 | if (ftestexist!=NULL) |
283 | { | 289 | { |
284 | fclose(ftestexist); | 290 | fclose(ftestexist); |
285 | do | 291 | do |
286 | { | 292 | { |
287 | char answer[128]; | 293 | char answer[128]; |
288 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | 294 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); |
289 | scanf("%1s",answer); | 295 | scanf("%1s",answer); |
290 | rep = answer[0] ; | 296 | rep = answer[0] ; |
291 | if ((rep>='a') && (rep<='z')) | 297 | if ((rep>='a') && (rep<='z')) |
292 | rep -= 0x20; | 298 | rep -= 0x20; |
293 | } | 299 | } |
294 | while ((rep!='Y') && (rep!='N') && (rep!='A')); | 300 | while ((rep!='Y') && (rep!='N') && (rep!='A')); |
295 | } | 301 | } |
296 | 302 | ||
297 | if (rep == 'N') | 303 | if (rep == 'N') |
298 | skip = 1; | 304 | skip = 1; |
299 | 305 | ||
300 | if (rep == 'A') | 306 | if (rep == 'A') |
301 | *popt_overwrite=1; | 307 | *popt_overwrite=1; |
302 | } | 308 | } |
303 | 309 | ||
304 | if ((skip==0) && (err==UNZ_OK)) | 310 | if ((skip==0) && (err==UNZ_OK)) |
305 | { | 311 | { |
306 | fout=fopen(write_filename,"wb"); | 312 | fout=fopen(write_filename,"wb"); |
307 | 313 | ||
308 | /* some zipfile don't contain directory alone before file */ | 314 | /* some zipfile don't contain directory alone before file */ |
309 | if ((fout==NULL) && ((*popt_extract_without_path)==0) && | 315 | if ((fout==NULL) && ((*popt_extract_without_path)==0) && |
310 | (filename_withoutpath!=(char*)filename_inzip)) | 316 | (filename_withoutpath!=(char*)filename_inzip)) |
311 | { | 317 | { |
312 | char c=*(filename_withoutpath-1); | 318 | char c=*(filename_withoutpath-1); |
@@ -316,95 +322,100 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite) | |||
316 | fout=fopen(write_filename,"wb"); | 322 | fout=fopen(write_filename,"wb"); |
317 | } | 323 | } |
318 | 324 | ||
319 | if (fout==NULL) | 325 | if (fout==NULL) |
320 | { | 326 | { |
321 | printf("error opening %s\n",write_filename); | 327 | printf("error opening %s\n",write_filename); |
322 | } | 328 | } |
323 | } | 329 | } |
324 | 330 | ||
325 | if (fout!=NULL) | 331 | if (fout!=NULL) |
326 | { | 332 | { |
327 | printf(" extracting: %s\n",write_filename); | 333 | printf(" extracting: %s\n",write_filename); |
328 | 334 | ||
329 | do | 335 | do |
330 | { | 336 | { |
331 | err = unzReadCurrentFile(uf,buf,size_buf); | 337 | err = unzReadCurrentFile(uf,buf,size_buf); |
332 | if (err<0) | 338 | if (err<0) |
333 | { | 339 | { |
334 | printf("error %d with zipfile in unzReadCurrentFile\n",err); | 340 | printf("error %d with zipfile in unzReadCurrentFile\n",err); |
335 | break; | 341 | break; |
336 | } | 342 | } |
337 | if (err>0) | 343 | if (err>0) |
338 | if (fwrite(buf,err,1,fout)!=1) | 344 | if (fwrite(buf,err,1,fout)!=1) |
339 | { | 345 | { |
340 | printf("error in writing extracted file\n"); | 346 | printf("error in writing extracted file\n"); |
341 | err=UNZ_ERRNO; | 347 | err=UNZ_ERRNO; |
342 | break; | 348 | break; |
343 | } | 349 | } |
344 | } | 350 | } |
345 | while (err>0); | 351 | while (err>0); |
346 | fclose(fout); | 352 | if (fout) |
347 | if (err==0) | 353 | fclose(fout); |
348 | change_file_date(write_filename,file_info.dosDate, | 354 | |
349 | file_info.tmu_date); | 355 | if (err==0) |
350 | } | 356 | change_file_date(write_filename,file_info.dosDate, |
357 | file_info.tmu_date); | ||
358 | } | ||
351 | 359 | ||
352 | if (err==UNZ_OK) | 360 | if (err==UNZ_OK) |
353 | { | 361 | { |
354 | err = unzCloseCurrentFile (uf); | 362 | err = unzCloseCurrentFile (uf); |
355 | if (err!=UNZ_OK) | 363 | if (err!=UNZ_OK) |
356 | { | 364 | { |
357 | printf("error %d with zipfile in unzCloseCurrentFile\n",err); | 365 | printf("error %d with zipfile in unzCloseCurrentFile\n",err); |
358 | } | 366 | } |
359 | } | 367 | } |
360 | else | 368 | else |
361 | unzCloseCurrentFile(uf); /* don't lose the error */ | 369 | unzCloseCurrentFile(uf); /* don't lose the error */ |
362 | } | 370 | } |
363 | 371 | ||
364 | free(buf); | 372 | free(buf); |
365 | return err; | 373 | return err; |
366 | } | 374 | } |
367 | 375 | ||
368 | 376 | ||
369 | int do_extract(uf,opt_extract_without_path,opt_overwrite) | 377 | int do_extract(uf,opt_extract_without_path,opt_overwrite,password) |
370 | unzFile uf; | 378 | unzFile uf; |
371 | int opt_extract_without_path; | 379 | int opt_extract_without_path; |
372 | int opt_overwrite; | 380 | int opt_overwrite; |
381 | const char* password; | ||
373 | { | 382 | { |
374 | uLong i; | 383 | uLong i; |
375 | unz_global_info gi; | 384 | unz_global_info gi; |
376 | int err; | 385 | int err; |
377 | FILE* fout=NULL; | 386 | FILE* fout=NULL; |
378 | 387 | ||
379 | err = unzGetGlobalInfo (uf,&gi); | 388 | err = unzGetGlobalInfo (uf,&gi); |
380 | if (err!=UNZ_OK) | 389 | if (err!=UNZ_OK) |
381 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); | 390 | printf("error %d with zipfile in unzGetGlobalInfo \n",err); |
382 | 391 | ||
383 | for (i=0;i<gi.number_entry;i++) | 392 | for (i=0;i<gi.number_entry;i++) |
384 | { | 393 | { |
385 | if (do_extract_currentfile(uf,&opt_extract_without_path, | 394 | if (do_extract_currentfile(uf,&opt_extract_without_path, |
386 | &opt_overwrite) != UNZ_OK) | 395 | &opt_overwrite, |
396 | password) != UNZ_OK) | ||
387 | break; | 397 | break; |
388 | 398 | ||
389 | if ((i+1)<gi.number_entry) | 399 | if ((i+1)<gi.number_entry) |
390 | { | 400 | { |
391 | err = unzGoToNextFile(uf); | 401 | err = unzGoToNextFile(uf); |
392 | if (err!=UNZ_OK) | 402 | if (err!=UNZ_OK) |
393 | { | 403 | { |
394 | printf("error %d with zipfile in unzGoToNextFile\n",err); | 404 | printf("error %d with zipfile in unzGoToNextFile\n",err); |
395 | break; | 405 | break; |
396 | } | 406 | } |
397 | } | 407 | } |
398 | } | 408 | } |
399 | 409 | ||
400 | return 0; | 410 | return 0; |
401 | } | 411 | } |
402 | 412 | ||
403 | int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite) | 413 | int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password) |
404 | unzFile uf; | 414 | unzFile uf; |
405 | const char* filename; | 415 | const char* filename; |
406 | int opt_extract_without_path; | 416 | int opt_extract_without_path; |
407 | int opt_overwrite; | 417 | int opt_overwrite; |
418 | const char* password; | ||
408 | { | 419 | { |
409 | int err = UNZ_OK; | 420 | int err = UNZ_OK; |
410 | if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) | 421 | if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) |
@@ -414,7 +425,8 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite) | |||
414 | } | 425 | } |
415 | 426 | ||
416 | if (do_extract_currentfile(uf,&opt_extract_without_path, | 427 | if (do_extract_currentfile(uf,&opt_extract_without_path, |
417 | &opt_overwrite) == UNZ_OK) | 428 | &opt_overwrite, |
429 | password) == UNZ_OK) | ||
418 | return 0; | 430 | return 0; |
419 | else | 431 | else |
420 | return 1; | 432 | return 1; |
@@ -422,87 +434,110 @@ int do_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite) | |||
422 | 434 | ||
423 | 435 | ||
424 | int main(argc,argv) | 436 | int main(argc,argv) |
425 | int argc; | 437 | int argc; |
426 | char *argv[]; | 438 | char *argv[]; |
427 | { | 439 | { |
428 | const char *zipfilename=NULL; | 440 | const char *zipfilename=NULL; |
429 | const char *filename_to_extract=NULL; | 441 | const char *filename_to_extract=NULL; |
430 | int i; | 442 | const char *password=NULL; |
431 | int opt_do_list=0; | 443 | char filename_try[MAXFILENAME+16] = ""; |
432 | int opt_do_extract=1; | 444 | int i; |
433 | int opt_do_extract_withoutpath=0; | 445 | int opt_do_list=0; |
434 | int opt_overwrite=0; | 446 | int opt_do_extract=1; |
435 | char filename_try[512]; | 447 | int opt_do_extract_withoutpath=0; |
436 | unzFile uf=NULL; | 448 | int opt_overwrite=0; |
437 | 449 | unzFile uf=NULL; | |
438 | do_banner(); | 450 | |
439 | if (argc==1) | 451 | do_banner(); |
440 | { | 452 | if (argc==1) |
441 | do_help(); | 453 | { |
442 | exit(0); | 454 | do_help(); |
443 | } | 455 | return 0; |
444 | else | 456 | } |
445 | { | 457 | else |
446 | for (i=1;i<argc;i++) | 458 | { |
447 | { | 459 | for (i=1;i<argc;i++) |
448 | if ((*argv[i])=='-') | 460 | { |
449 | { | 461 | if ((*argv[i])=='-') |
450 | const char *p=argv[i]+1; | 462 | { |
451 | 463 | const char *p=argv[i]+1; | |
452 | while ((*p)!='\0') | 464 | |
453 | { | 465 | while ((*p)!='\0') |
454 | char c=*(p++);; | 466 | { |
455 | if ((c=='l') || (c=='L')) | 467 | char c=*(p++);; |
456 | opt_do_list = 1; | 468 | if ((c=='l') || (c=='L')) |
457 | if ((c=='v') || (c=='V')) | 469 | opt_do_list = 1; |
458 | opt_do_list = 1; | 470 | if ((c=='v') || (c=='V')) |
459 | if ((c=='x') || (c=='X')) | 471 | opt_do_list = 1; |
460 | opt_do_extract = 1; | 472 | if ((c=='x') || (c=='X')) |
461 | if ((c=='e') || (c=='E')) | 473 | opt_do_extract = 1; |
462 | opt_do_extract = opt_do_extract_withoutpath = 1; | 474 | if ((c=='e') || (c=='E')) |
463 | if ((c=='o') || (c=='O')) | 475 | opt_do_extract = opt_do_extract_withoutpath = 1; |
464 | opt_overwrite=1; | 476 | if ((c=='o') || (c=='O')) |
465 | } | 477 | opt_overwrite=1; |
466 | } | 478 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
467 | else | 479 | { |
480 | password=argv[i+1]; | ||
481 | i++; | ||
482 | } | ||
483 | } | ||
484 | } | ||
485 | else | ||
468 | { | 486 | { |
469 | if (zipfilename == NULL) | 487 | if (zipfilename == NULL) |
470 | zipfilename = argv[i]; | 488 | zipfilename = argv[i]; |
471 | else if (filename_to_extract==NULL) | 489 | else if (filename_to_extract==NULL) |
472 | filename_to_extract = argv[i] ; | 490 | filename_to_extract = argv[i] ; |
473 | } | 491 | } |
474 | } | 492 | } |
475 | } | 493 | } |
476 | 494 | ||
477 | if (zipfilename!=NULL) | 495 | if (zipfilename!=NULL) |
478 | { | 496 | { |
479 | strcpy(filename_try,zipfilename); | 497 | |
480 | uf = unzOpen(zipfilename); | 498 | #ifdef USEWIN32IOAPI |
481 | if (uf==NULL) | 499 | zlib_filefunc_def ffunc; |
482 | { | 500 | #endif |
483 | strcat(filename_try,".zip"); | 501 | |
484 | uf = unzOpen(filename_try); | 502 | strncpy(filename_try, zipfilename,MAXFILENAME-1); |
485 | } | 503 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ |
486 | } | 504 | filename_try[ MAXFILENAME ] = '\0'; |
487 | 505 | ||
488 | if (uf==NULL) | 506 | #ifdef USEWIN32IOAPI |
489 | { | 507 | fill_win32_filefunc(&ffunc); |
490 | printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); | 508 | uf = unzOpen2(zipfilename,&ffunc); |
491 | exit (1); | 509 | #else |
492 | } | 510 | uf = unzOpen(zipfilename); |
511 | #endif | ||
512 | if (uf==NULL) | ||
513 | { | ||
514 | strcat(filename_try,".zip"); | ||
515 | #ifdef USEWIN32IOAPI | ||
516 | uf = unzOpen2(filename_try,&ffunc); | ||
517 | #else | ||
518 | uf = unzOpen(filename_try); | ||
519 | #endif | ||
520 | } | ||
521 | } | ||
522 | |||
523 | if (uf==NULL) | ||
524 | { | ||
525 | printf("Cannot open %s or %s.zip\n",zipfilename,zipfilename); | ||
526 | return 1; | ||
527 | } | ||
493 | printf("%s opened\n",filename_try); | 528 | printf("%s opened\n",filename_try); |
494 | 529 | ||
495 | if (opt_do_list==1) | 530 | if (opt_do_list==1) |
496 | return do_list(uf); | 531 | return do_list(uf); |
497 | else if (opt_do_extract==1) | 532 | else if (opt_do_extract==1) |
498 | { | 533 | { |
499 | if (filename_to_extract == NULL) | 534 | if (filename_to_extract == NULL) |
500 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite); | 535 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); |
501 | else | 536 | else |
502 | return do_extract_onefile(uf,filename_to_extract, | 537 | return do_extract_onefile(uf,filename_to_extract, |
503 | opt_do_extract_withoutpath,opt_overwrite); | 538 | opt_do_extract_withoutpath,opt_overwrite,password); |
504 | } | 539 | } |
505 | unzCloseCurrentFile(uf); | 540 | unzCloseCurrentFile(uf); |
506 | 541 | ||
507 | return 0; /* to avoid warning */ | 542 | return 0; |
508 | } | 543 | } |