15#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
16 #ifndef __USE_FILE_OFFSET64
17 #define __USE_FILE_OFFSET64
19 #ifndef __USE_LARGEFILE64
20 #define __USE_LARGEFILE64
22 #ifndef _LARGEFILE64_SOURCE
23 #define _LARGEFILE64_SOURCE
25 #ifndef _FILE_OFFSET_BIT
26 #define _FILE_OFFSET_BIT 64
32#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
33#define FTELLO_FUNC(stream) ftello(stream)
34#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
36#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
37#define FTELLO_FUNC(stream) ftello64(stream)
38#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
61#define CASESENSITIVITY (0)
62#define WRITEBUFFERSIZE (8192)
63#define MAXFILENAME (256)
84static void change_file_date(
filename,dosdate,tmu_date)
91 FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;
93 hFile = CreateFileA(
filename,GENERIC_READ | GENERIC_WRITE,
95 GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
96 DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
97 LocalFileTimeToFileTime(&ftLocal,&ftm);
98 SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
101#if defined(unix) || defined(__APPLE__)
105 newdate.tm_sec = tmu_date.
tm_sec;
106 newdate.tm_min=tmu_date.
tm_min;
107 newdate.tm_hour=tmu_date.
tm_hour;
108 newdate.tm_mday=tmu_date.
tm_mday;
109 newdate.tm_mon=tmu_date.
tm_mon;
111 newdate.tm_year=tmu_date.
tm_year - 1900;
113 newdate.tm_year=tmu_date.
tm_year ;
126static int mymkdir(dirname)
131 ret = _mkdir(dirname);
133 ret = mkdir (dirname,0775);
135 ret = mkdir (dirname,0775);
140static int makedir (newdir)
153 printf(
"Error allocating memory\n");
156 strcpy(buffer,newdir);
158 if (buffer[
len-1] ==
'/') {
159 buffer[
len-1] =
'\0';
161 if (mymkdir(buffer) == 0)
172 while(*p && *p !=
'\\' && *p !=
'/')
176 if ((mymkdir(buffer) == -1) && (errno == ENOENT))
178 printf(
"couldn't create directory %s\n",buffer);
190static void do_banner()
192 printf(
"MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
193 printf(
"more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
198 printf(
"Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
199 " -e Extract without pathname (junk paths)\n" \
200 " -x Extract with pathname\n" \
203 " -d directory to extract into\n" \
204 " -o overwrite files without prompting\n" \
205 " -p extract crypted file using password\n\n");
208static void Display64BitsSize(
ZPOS64_T n,
int size_char)
216 number[
offset]=(char)((n%10)+
'0');
217 if (number[
offset] !=
'0')
225 int size_display_string = 19-pos_string;
226 while (size_char > size_display_string)
233 printf(
"%s",&number[pos_string]);
236static int do_list(uf)
245 printf(
"error %d with zipfile in unzGetGlobalInfo \n",
err);
246 printf(
" Length Method Size Ratio Date Time CRC-32 Name\n");
247 printf(
" ------ ------ ---- ----- ---- ---- ------ ----\n");
250 char filename_inzip[256];
253 const char *string_method;
258 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
265 if ((file_info.
flag & 1) != 0)
269 string_method=
"Stored";
275 string_method=
"Defl:N";
277 string_method=
"Defl:X";
278 else if ((iLevel==2) || (iLevel==3))
279 string_method=
"Defl:F";
284 string_method=
"BZip2 ";
287 string_method=
"Unkn. ";
290 printf(
" %6s%c",string_method,charCrypt);
292 printf(
" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n",
298 (
uLong)file_info.
crc,filename_inzip);
304 printf(
"error %d with zipfile in unzGoToNextFile\n",
err);
314static int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
316 const int* popt_extract_without_path;
318 const char* password;
320 char filename_inzip[256];
321 char* filename_withoutpath;
333 printf(
"error %d with zipfile in unzGetCurrentFileInfo\n",
err);
341 printf(
"Error allocating memory\n");
345 p = filename_withoutpath = filename_inzip;
348 if (((*p)==
'/') || ((*p)==
'\\'))
349 filename_withoutpath = p+1;
353 if ((*filename_withoutpath)==
'\0')
355 if ((*popt_extract_without_path)==0)
357 printf(
"creating directory: %s\n",filename_inzip);
358 mymkdir(filename_inzip);
363 const char* write_filename;
366 if ((*popt_extract_without_path)==0)
367 write_filename = filename_inzip;
369 write_filename = filename_withoutpath;
374 printf(
"error %d with zipfile in unzOpenCurrentFilePassword\n",
err);
377 if (((*popt_overwrite)==0) && (
err==
UNZ_OK))
382 if (ftestexist!=
NULL)
390 printf(
"The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
391 ret = scanf(
"%1s",answer);
397 if ((rep>=
'a') && (rep<=
'z'))
400 while ((rep!=
'Y') && (rep!=
'N') && (rep!=
'A'));
414 if ((fout==
NULL) && ((*popt_extract_without_path)==0) &&
415 (filename_withoutpath!=(
char*)filename_inzip))
417 char c=*(filename_withoutpath-1);
418 *(filename_withoutpath-1)=
'\0';
419 makedir(write_filename);
420 *(filename_withoutpath-1)=c;
426 printf(
"error opening %s\n",write_filename);
432 printf(
" extracting: %s\n",write_filename);
439 printf(
"error %d with zipfile in unzReadCurrentFile\n",
err);
443 if (fwrite(
buf,(
unsigned)
err,1,fout)!=1)
445 printf(
"error in writing extracted file\n");
455 change_file_date(write_filename,file_info.
dosDate,
464 printf(
"error %d with zipfile in unzCloseCurrentFile\n",
err);
476static int do_extract(uf,opt_extract_without_path,opt_overwrite,password)
478 int opt_extract_without_path;
480 const char* password;
488 printf(
"error %d with zipfile in unzGetGlobalInfo \n",
err);
492 if (do_extract_currentfile(uf,&opt_extract_without_path,
502 printf(
"error %d with zipfile in unzGoToNextFile\n",
err);
511static int do_extract_onefile(uf,
filename,opt_extract_without_path,opt_overwrite,password)
514 int opt_extract_without_path;
516 const char* password;
520 printf(
"file %s not found in the zipfile\n",
filename);
524 if (do_extract_currentfile(uf,&opt_extract_without_path,
537 const char *zipfilename=
NULL;
538 const char *filename_to_extract=
NULL;
539 const char *password=
NULL;
544 int opt_do_extract=1;
545 int opt_do_extract_withoutpath=0;
547 int opt_extractdir=0;
548 const char *dirname=
NULL;
563 const char *p=
argv[i]+1;
568 if ((c==
'l') || (c==
'L'))
570 if ((c==
'v') || (c==
'V'))
572 if ((c==
'x') || (c==
'X'))
574 if ((c==
'e') || (c==
'E'))
575 opt_do_extract = opt_do_extract_withoutpath = 1;
576 if ((c==
'o') || (c==
'O'))
578 if ((c==
'd') || (c==
'D'))
584 if (((c==
'p') || (c==
'P')) && (i+1<
argc))
593 if (zipfilename ==
NULL)
594 zipfilename =
argv[i];
595 else if ((filename_to_extract==
NULL) && (!opt_extractdir))
596 filename_to_extract =
argv[i] ;
601 if (zipfilename!=
NULL)
620 strcat(filename_try,
".zip");
631 printf(
"Cannot open %s or %s.zip\n",zipfilename,zipfilename);
634 printf(
"%s opened\n",filename_try);
637 ret_value = do_list(uf);
638 else if (opt_do_extract==1)
641 if (opt_extractdir && _chdir(dirname))
643 if (opt_extractdir && chdir(dirname))
646 printf(
"Error changing into %s, aborting\n", dirname);
650 if (filename_to_extract ==
NULL)
651 ret_value = do_extract(uf, opt_do_extract_withoutpath, opt_overwrite, password);
653 ret_value = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
void skip(file *in, unsigned n)
unsigned __int64 ZPOS64_T
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
#define FOPEN_FUNC(filename, mode)
size_t strlen(const char *)
ZPOS64_T uncompressed_size
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
Addition for GDAL : END.
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
unzFile ZEXPORT unzOpen64(const void *path)
int ZEXPORT unzCloseCurrentFile(unzFile file)
int ZEXPORT unzGoToNextFile(unzFile file)
int ZEXPORT unzClose(unzFile file)
#define UNZ_INTERNALERROR