From 3925fc13b2131e18801a5a0f787e6789bb580047 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Fri, 18 Mar 2016 16:05:10 +0000 Subject: git-svn-id: http://svn.miranda-ng.org/main/trunk@16498 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db_autobackups/src/main.cpp | 8 ++++---- plugins/Db_autobackups/src/zip.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 plugins/Db_autobackups/src/zip.cpp diff --git a/plugins/Db_autobackups/src/main.cpp b/plugins/Db_autobackups/src/main.cpp index dc104cc7f6..9fcb46970a 100644 --- a/plugins/Db_autobackups/src/main.cpp +++ b/plugins/Db_autobackups/src/main.cpp @@ -38,10 +38,10 @@ static INT_PTR DBSaveAs(WPARAM, LPARAM) OPENFILENAME ofn = { 0 }; CallService(MS_DB_GETPROFILENAMET, _countof(fname_buff), (LPARAM)fname_buff); - mir_sntprintf(tszFilter, _T("%s (*.dat)\0*.dat\0%s (*.zip)\0*.zip\0%s (*.*)\0*\0"), - TranslateT("Miranda NG databases"), - TranslateT("Compressed Miranda NG databases"), - TranslateT("All files")); + mir_sntprintf(tszFilter, _T("%s (*.dat)%c*.dat%c%s (*.zip)%c*.zip%c%s (*.*)%c*%c"), + TranslateT("Miranda NG databases"), 0, 0, + TranslateT("Compressed Miranda NG databases"), 0, 0, + TranslateT("All files"), 0, 0); ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = fname_buff; diff --git a/plugins/Db_autobackups/src/zip.cpp b/plugins/Db_autobackups/src/zip.cpp new file mode 100644 index 0000000000..2b30fa7430 --- /dev/null +++ b/plugins/Db_autobackups/src/zip.cpp @@ -0,0 +1,34 @@ +#include "stdafx.h" +#include "..\..\libs\zlib\src\zip.h" + +int CreateZipFile(const char *szDestPath, OBJLIST &lstFiles, const std::function &fnCallback) +{ + zipFile hZip = zipOpen2_64(_A2T(szDestPath), APPEND_STATUS_CREATE, NULL, NULL); + if (!hZip) return 1; + + zip_fileinfo fi = { 0 }; + + for (int i = 0; i < lstFiles.getCount(); i++) + { + ZipFile &zf = lstFiles[i]; + + HANDLE hSrcFile = CreateFileA(zf.sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + int iOpenRes = zipOpenNewFileInZip(hZip, zf.sZipPath.c_str(), &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); + + if (hSrcFile != INVALID_HANDLE_VALUE && iOpenRes == ZIP_OK) + { + DWORD dwRead; + BYTE buf[0x40000]; + + while (ReadFile(hSrcFile, buf, sizeof(buf), &dwRead, nullptr) && dwRead && (zipWriteInFileInZip(hZip, buf, dwRead) == ZIP_OK)); + zipCloseFileInZip(hZip); + CloseHandle(hSrcFile); + + if (!fnCallback(i)) + return 3; + } + } + + zipClose(hZip, CMStringA(FORMAT, Translate("Miranda NG [%s] Database Backup"), g_szMirVer)); + return 0; +} \ No newline at end of file -- cgit v1.2.3