summaryrefslogtreecommitdiff
path: root/plugins/Db_autobackups
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-08-30 18:18:59 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-08-30 18:18:59 +0300
commit5f2f07636e5a9c416bf9c2f6e071f8d5a7e224f3 (patch)
tree5b1c0359d0c3f7e28333d7f8c3be58784caefd4f /plugins/Db_autobackups
parent2bdf44d25898918f372956cc27ec1c589d76da97 (diff)
fixes #1450 (Db_autobackups produces archives with bugged headers)
Diffstat (limited to 'plugins/Db_autobackups')
-rw-r--r--plugins/Db_autobackups/src/zip.cpp21
1 files changed, 14 insertions, 7 deletions
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<ZipFile> &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;
}