/*
Version 1.1, February 14h, 2010
sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support on both zip and unzip
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
*/
#ifndef __USE_FILE_OFFSET64
#define __USE_FILE_OFFSET64
#endif
#ifndef __USE_LARGEFILE64
#define __USE_LARGEFILE64
#endif
#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE
#endif
#ifndef _FILE_OFFSET_BIT
#endif
#endif
#ifdef __APPLE__
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
#else
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
# include <direct.h>
# include <io.h>
#else
# include <unistd.h>
# include <utime.h>
#endif
#include "zip.h"
#ifdef _WIN32
#define USEWIN32IOAPI
#include "iowin32.h"
#endif
#ifdef _WIN32
char *f; /* name of file to get info on */
{
int ret = 0;
{
if (hFind != INVALID_HANDLE_VALUE)
{
ret = 1;
}
}
return ret;
}
#else
char *f; /* name of file to get info on */
{
int ret=0;
struct stat s; /* results of stat() */
if (strcmp(f,"-")!=0)
{
if (len > MAXFILENAME)
len = MAXFILENAME;
/* strncpy doesnt append the trailing NULL, of the string is too long. */
/* not all systems allow stat'ing a file with / appended */
{
ret = 1;
}
}
return ret;
}
#else
char *f; /* name of file to get info on */
{
return 0;
}
#endif
#endif
const char* filename;
{
if (ftestexist==NULL)
ret = 0;
else
return ret;
}
void do_banner()
{
printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
}
void do_help()
{
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
" -o Overwrite existing file.zip\n" \
" -a Append to existing file.zip\n" \
" -0 Store only\n" \
" -1 Compress faster\n" \
" -9 Compress better\n\n" \
" -j exclude path. store only the file name.\n\n");
}
/* calculate the CRC32 of a file,
because to encrypt a file, we need known the CRC32 of the file before */
{
unsigned long calculate_crc=0;
unsigned long size_read = 0;
unsigned long total_read = 0;
{
}
do
{
{
}
if (size_read>0)
total_read += size_read;
if (fin)
return err;
}
{
int largeFile = 0;
{
if(pos >= 0xffffffff)
largeFile = 1;
}
return largeFile;
}
int argc;
char *argv[];
{
int i;
int opt_overwrite=0;
int opt_exclude_path=0;
int zipfilenamearg = 0;
int zipok;
int err=0;
int size_buf=0;
do_banner();
if (argc==1)
{
do_help();
return 0;
}
else
{
for (i=1;i<argc;i++)
{
if ((*argv[i])=='-')
{
const char *p=argv[i]+1;
while ((*p)!='\0')
{
char c=*(p++);;
if ((c=='o') || (c=='O'))
opt_overwrite = 1;
if ((c=='a') || (c=='A'))
opt_overwrite = 2;
if ((c>='0') && (c<='9'))
opt_compress_level = c-'0';
if ((c=='j') || (c=='J'))
opt_exclude_path = 1;
{
i++;
}
}
}
else
{
if (zipfilenamearg == 0)
{
zipfilenamearg = i ;
}
}
}
}
{
printf("Error allocating memory\n");
return ZIP_INTERNALERROR;
}
if (zipfilenamearg==0)
{
zipok=0;
}
else
{
int i,len;
int dot_found=0;
zipok = 1 ;
/* strncpy doesnt append the trailing NULL, of the string is too long. */
for (i=0;i<len;i++)
if (filename_try[i]=='.')
dot_found=1;
if (dot_found==0)
if (opt_overwrite==2)
{
/* if the file don't exist, we not append file */
if (check_exist_file(filename_try)==0)
}
else
if (opt_overwrite==0)
if (check_exist_file(filename_try)!=0)
{
char rep=0;
do
{
int ret;
if (ret != 1)
{
}
rep -= 0x20;
}
if (rep=='N')
zipok = 0;
if (rep=='A')
opt_overwrite = 2;
}
}
if (zipok==1)
{
int errclose;
# ifdef USEWIN32IOAPI
# else
# endif
{
}
else
{
{
int size_read;
const char *savefilenameinzip;
unsigned long crcFile=0;
int zip64 = 0;
zi.internal_fa = 0;
zi.external_fa = 0;
/*
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
NULL,0,NULL,0,NULL / * comment * /,
(opt_compress_level != 0) ? Z_DEFLATED : 0,
opt_compress_level);
*/
/* The path name saved, should not include a leading slash. */
{
}
/*should the zip file contain any path at all?*/
if( opt_exclude_path )
{
const char *tmpptr;
const char *lastslash = 0;
{
{
}
}
{
}
}
/**/
(opt_compress_level != 0) ? Z_DEFLATED : 0,
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
else
{
{
}
}
do
{
{
}
if (size_read>0)
{
if (err<0)
{
printf("error in writing %s in the zipfile\n",
}
}
if (fin)
if (err<0)
else
{
printf("error in closing %s in the zipfile\n",
}
}
}
}
else
{
do_help();
}
return 0;
}