summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/Db_autobackups/src/main.cpp8
-rw-r--r--plugins/Db_autobackups/src/zip.cpp34
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