diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-18 16:05:10 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-18 16:05:10 +0000 |
commit | 3925fc13b2131e18801a5a0f787e6789bb580047 (patch) | |
tree | a33a7385eca2d2c5fc5aefe187df25c4844b460e /plugins/Db_autobackups | |
parent | 56fde48e71d039f0485d0ca8d593e0089859bb29 (diff) |
git-svn-id: http://svn.miranda-ng.org/main/trunk@16498 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db_autobackups')
-rw-r--r-- | plugins/Db_autobackups/src/main.cpp | 8 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/zip.cpp | 34 |
2 files changed, 38 insertions, 4 deletions
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<ZipFile> &lstFiles, const std::function<bool(size_t)> &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 |