From 5f2f07636e5a9c416bf9c2f6e071f8d5a7e224f3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 30 Aug 2018 18:18:59 +0300 Subject: fixes #1450 (Db_autobackups produces archives with bugged headers) --- plugins/Db_autobackups/src/zip.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'plugins/Db_autobackups') diff --git a/plugins/Db_autobackups/src/zip.cpp b/plugins/Db_autobackups/src/zip.cpp index b360272855..4952cedc20 100644 --- a/plugins/Db_autobackups/src/zip.cpp +++ b/plugins/Db_autobackups/src/zip.cpp @@ -9,22 +9,29 @@ int CreateZipFile(const wchar_t *szDestPath, OBJLIST &lstFiles, const s zip_fileinfo fi = { 0 }; int ret = 0; - for (int i = 0; i < lstFiles.getCount(); i++) { - ZipFile &zf = lstFiles[i]; - - HANDLE hSrcFile = CreateFileW(zf.sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + for (auto &zf : lstFiles) { + HANDLE hSrcFile = CreateFileW(zf->sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hSrcFile != INVALID_HANDLE_VALUE) { - int iOpenRes = zipOpenNewFileInZip(hZip, _T2A(zf.sZipPath.c_str()), &fi, nullptr, 0, nullptr, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); + FILETIME ft; + GetFileTime(hSrcFile, 0, &ft, 0); + + WORD dosDate, dosTime; + FileTimeToDosDateTime(&ft, &dosDate, &dosTime); + fi.dosDate = MAKELONG(dosTime, dosDate); + int iOpenRes = zipOpenNewFileInZip(hZip, _T2A(zf->sZipPath.c_str()), &fi, nullptr, 0, nullptr, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); if (iOpenRes == ZIP_OK) { DWORD dwRead; BYTE buf[0x40000]; - while (ReadFile(hSrcFile, buf, sizeof(buf), &dwRead, nullptr) && dwRead && (zipWriteInFileInZip(hZip, buf, dwRead) == ZIP_OK)); + while (ReadFile(hSrcFile, buf, sizeof(buf), &dwRead, nullptr) && dwRead) + if (zipWriteInFileInZip(hZip, buf, dwRead) != ZIP_OK) + break; + zipCloseFileInZip(hZip); CloseHandle(hSrcFile); - if (!fnCallback(i)) { + if (!fnCallback(lstFiles.indexOf(&zf))) { ret = 3; break; } -- cgit v1.2.3