2024年4月1日发(作者:)
pos = ftello64(pFile);
printf("File : %s is %lld bytesn", filename.c_str(), pos);
if (pos >= 0xffffffff)
largeFile = 1;
fclose(pFile);
}
return largeFile;
}
uLong CFileZipper::filetime(const char* f, tm_zip *tmzip, uLong *dt)
{
int ret = 0;
{
FILETIME ftLocal;
HANDLE hFind;
WIN32_FIND_DATAA ff32;
hFind = FindFirstFileA(f, &ff32);
if (hFind != INVALID_HANDLE_VALUE)
{
FileTimeToLocalFileTime(&(WriteTime), &ftLocal);
FileTimeToDosDateTime(&ftLocal, ((LPWORD)dt) + 1, ((LPWORD)dt) + 0);
FindClose(hFind);
ret = 1;
}
}
return ret;
}
int CFileZipper::ZipFiles(std::string &zipFileName, std::vector
{
int size_buf = WRITEBUFFERSIZE;
void* buf = NULL;
buf = (void*)malloc(size_buf);
if (buf == NULL)
{
printf("Error allocating memoryn");
return ZIP_INTERNALERROR;
}
zipFile zf;
int err, errclose;
zlib_filefunc64_def ffunc;
fill_win32_filefunc64A(&ffunc);
zf = zipOpen2_64(zipFileName.c_str(), (bAppendFile) ? 2 : 0, NULL, &ffunc);
if (zf == NULL)
{
printf("error opening %sn", zipFileName.c_str());
err = ZIP_ERRNO;
}
else
{
printf("creating %sn", zipFileName.c_str());
err = ZIP_OK;
}
int i = 0;
for (; i < () && (err == ZIP_OK); i++)
{
FILE* fin = NULL;
int size_read;
std::string filenameinzip = files[i];
std::string savefilenameinzip;
zip_fileinfo zi;
unsigned long crcFile = 0;
int zip64 = 0;
__sec = __min = __hour =
__mday = __mon = __year = 0;
e = 0;
al_fa = 0;
al_fa = 0;
filetime(filenameinzip.c_str(), &_date, &e);
zip64 = isLargeFile(filenameinzip);
savefilenameinzip = ((('') + 1));
err = zipOpenNewFileInZip3_64(zf, savefilenameinzip.c_str(), &zi,
NULL, 0, NULL, 0, NULL /* comment*/,
(nCompressLevel != 0) ? Z_DEFLATED : 0,
nCompressLevel, 0,
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
NULL, crcFile, zip64);
if (err != ZIP_OK)
printf("error in opening %s in zipfilen", filenameinzip.c_str());
else
{
//fin = fopen64(filenameinzip.c_str(), "rb");
fopen_s(&fin, filenameinzip.c_str(), "rb");
if (fin == NULL)
{
err = ZIP_ERRNO;
printf("error in opening %s for readingn", filenameinzip.c_str());
}
}
if (err == ZIP_OK)
{
do
{
err = ZIP_OK;
size_read = (int)fread(buf, 1, size_buf, fin);
if (size_read < size_buf)
if (feof(fin) == 0)
{
printf("error in reading %sn", filenameinzip.c_str());
err = ZIP_ERRNO;
}
if (size_read > 0)
{
err = zipWriteInFileInZip(zf, buf, size_read);
if (err < 0)
{
printf("error in writing %s in the zipfilen",
filenameinzip.c_str());
}
}
} while ((err == ZIP_OK) && (size_read > 0));
}
if (fin)
fclose(fin);
if (err < 0)
err = ZIP_ERRNO;
else
{
err = zipCloseFileInZip(zf);
if (err != ZIP_OK)
printf("error in closing %s in the zipfilen",
filenameinzip.c_str());
}
}
errclose = zipClose(zf, NULL);
if (errclose != ZIP_OK)
printf("error in closing %sn", zipFileName.c_str());
if (buf != NULL)
free(buf);
return err;
}
#include "pch.h"
#include
#include
#include
#include
#include ""


发布评论