diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-09 18:14:27 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-09 18:14:27 +0000 |
commit | 7200ed0e6db65ef17549004af7ed12b06b99d13a (patch) | |
tree | 9ecc312ca34ecfa9a28b678e08c6602fc1c814f5 /plugins | |
parent | d49739f87dd347d6a560dd834788b74cf520b931 (diff) |
db_autobackups: support backuping profile folder
git-svn-id: http://svn.miranda-ng.org/main/trunk@16252 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Db_autobackups/src/backup.cpp | 47 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/options.cpp | 12 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/options.h | 1 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/resource.h | 4 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/stdafx.h | 7 |
5 files changed, 68 insertions, 3 deletions
diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp index dad007daba..c32e30fca0 100644 --- a/plugins/Db_autobackups/src/backup.cpp +++ b/plugins/Db_autobackups/src/backup.cpp @@ -78,6 +78,47 @@ TCHAR* DoubleSlash(TCHAR *sorce) return ret;
}
+bool MakeZip_Dir(LPCSTR szDir, LPCTSTR szDest, LPCSTR szDbName, HWND progress_dialog)
+{
+ zipFile hZip = zipOpen2_64(szDest, APPEND_STATUS_CREATE, NULL, NULL);
+ zip_fileinfo fi = { 0 };
+ std::vector<std::string> files;
+ auto folder = fs::path(szDir);
+ auto it = fs::recursive_directory_iterator(folder);
+ HWND hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS);
+ size_t i = 0;
+ for (it; it != fs::recursive_directory_iterator(); ++it)
+ {
+ const auto& file = it->path();
+ if (!fs::is_directory(file) && !strstr(std::string(file).c_str(), _T2A(szDest)))
+ {
+ std::string filepath = file;
+ std::string rpath = filepath.substr(filepath.find(szDir) + mir_strlen(szDir));
+
+ HANDLE hSrc;
+ if (hSrc = CreateFile(_A2T(filepath.c_str()), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
+ {
+ if (zipOpenNewFileInZip(hZip, rpath.c_str(), &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION) == ZIP_OK)
+ {
+ DWORD dwRead;
+ uint8_t buf[(256 * 1024)];
+ while (ReadFile(hSrc, buf, sizeof(buf), &dwRead, nullptr) && dwRead)
+ {
+ if (zipWriteInFileInZip(hZip, buf, dwRead) != ZIP_OK)
+ break;
+ }
+ }
+ i++;
+ SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(i % 100), 0);
+ }
+ }
+ }
+ zipClose(hZip, CMStringA(FORMAT, "%s\r\n%s %s %d.%d.%d.%d\r\n",
+ Translate("Miranda NG database"), Translate("Created by:"),
+ __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM));
+ return true;
+}
+
bool MakeZip(TCHAR *tszSource, TCHAR *tszDest, TCHAR *dbname, HWND progress_dialog)
{
bool ret = false;
@@ -257,7 +298,11 @@ int Backup(TCHAR *backup_filename) TCHAR *pathtmp = Utils_ReplaceVarsT(source_file);
BOOL res = 0;
if (bZip)
- res = MakeZip(pathtmp, dest_file, dbname, progress_dialog);
+ {
+ res = options.backup_profile
+ ? MakeZip_Dir(_T2A(profilePath), dest_file, _T2A(dbname), progress_dialog)
+ : MakeZip(pathtmp, dest_file, dbname, progress_dialog);
+ }
else
res = CopyFile(pathtmp, dest_file, 0);
if (res) {
diff --git a/plugins/Db_autobackups/src/options.cpp b/plugins/Db_autobackups/src/options.cpp index 90e2fa5fdc..bb5175de23 100644 --- a/plugins/Db_autobackups/src/options.cpp +++ b/plugins/Db_autobackups/src/options.cpp @@ -61,6 +61,7 @@ int LoadOptions(void) options.disable_popups = (BOOL)db_get_b(0, "AutoBackups", "NoPopups", 0);
options.use_zip = (BOOL)db_get_b(0, "AutoBackups", "UseZip", 0);
options.use_dropbox = (BOOL)(db_get_b(0, "AutoBackups", "UseDropbox", 0) && ServiceExists(MS_DROPBOX_SEND_FILE));
+ options.backup_profile = (BOOL)db_get_b(0, "AutoBackups", "BackupProfile", 0);
SetBackupTimer();
return 0;
@@ -97,6 +98,7 @@ int SaveOptions(void) db_set_b(0, "AutoBackups", "NoPopups", (BYTE)options.disable_popups);
db_set_b(0, "AutoBackups", "UseZip", (BYTE)options.use_zip);
db_set_b(0, "AutoBackups", "UseDropbox", (BYTE)options.use_dropbox);
+ db_set_b(0, "AutoBackups", "BackupProfile", (BYTE)options.backup_profile);
SetBackupTimer();
return 0;
@@ -136,6 +138,8 @@ int SetDlgState(HWND hwndDlg) EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_USEZIP), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PERIOD), new_options.backup_types & BT_PERIODIC);
EnableWindow(GetDlgItem(hwndDlg, IDC_PT), new_options.backup_types & BT_PERIODIC);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_DROPBOX), ServiceExists(MS_DROPBOX_SEND_FILE));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BACKUPPROFILE), new_options.use_zip);
CheckDlgButton(hwndDlg, IDC_RAD_DISABLED, BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_RAD_START, new_options.backup_types & BT_START ? BST_CHECKED : BST_UNCHECKED);
@@ -154,7 +158,8 @@ int SetDlgState(HWND hwndDlg) CheckDlgButton(hwndDlg, IDC_CHK_NOPROG, new_options.disable_progress ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHK_NOPOPUP, new_options.disable_popups ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHK_USEZIP, new_options.use_zip ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg, IDC_DROPBOX, new_options.use_dropbox ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_DROPBOX, new_options.use_dropbox && ServiceExists(MS_DROPBOX_SEND_FILE) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_BACKUPPROFILE, new_options.backup_profile && new_options.use_zip ? BST_CHECKED : BST_UNCHECKED);
if (!ServiceExists(MS_POPUP_ADDPOPUPT))
ShowWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), SW_HIDE);
@@ -306,11 +311,16 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP case IDC_CHK_USEZIP:
new_options.use_zip = IsDlgButtonChecked(hwndDlg, IDC_CHK_USEZIP);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BACKUPPROFILE), new_options.use_zip);
break;
case IDC_DROPBOX:
new_options.use_dropbox = IsDlgButtonChecked(hwndDlg, IDC_DROPBOX);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
+ case IDC_BACKUPPROFILE:
+ new_options.backup_profile = IsDlgButtonChecked(hwndDlg, IDC_BACKUPPROFILE) && IsDlgButtonChecked(hwndDlg, IDC_CHK_USEZIP);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
case IDC_LNK_FOLDERS:
{
OPENOPTIONSDIALOG ood = { 0 };
diff --git a/plugins/Db_autobackups/src/options.h b/plugins/Db_autobackups/src/options.h index 733487e0af..991c109285 100644 --- a/plugins/Db_autobackups/src/options.h +++ b/plugins/Db_autobackups/src/options.h @@ -35,6 +35,7 @@ typedef struct Options_tag { BOOL disable_popups;
BOOL use_zip;
BOOL use_dropbox;
+ BOOL backup_profile;
} Options;
extern Options options;
\ No newline at end of file diff --git a/plugins/Db_autobackups/src/resource.h b/plugins/Db_autobackups/src/resource.h index b0628a3653..40fb887c76 100644 --- a/plugins/Db_autobackups/src/resource.h +++ b/plugins/Db_autobackups/src/resource.h @@ -23,6 +23,8 @@ #define IDC_CHK_USEZIP 1673
#define IDC_CHECK1 1674
#define IDC_DROPBOX 1674
+#define IDC_CHECK2 1675
+#define IDC_BACKUPPROFILE 1675
#define IDC_PROGRESSMESSAGE 0xDAED
#define IDC_PROGRESS 0xDEAD
@@ -32,7 +34,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 272
#define _APS_NEXT_COMMAND_VALUE 40018
-#define _APS_NEXT_CONTROL_VALUE 1675
+#define _APS_NEXT_CONTROL_VALUE 1676
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/Db_autobackups/src/stdafx.h b/plugins/Db_autobackups/src/stdafx.h index 9a4676583f..a415228ad9 100644 --- a/plugins/Db_autobackups/src/stdafx.h +++ b/plugins/Db_autobackups/src/stdafx.h @@ -6,6 +6,13 @@ #include <windows.h>
#include <shlobj.h>
#include <time.h>
+#include <filesystem>
+#include <vector>
+#if defined(_MSC_VER) && (_MSC_VER >= 1800) +namespace fs = std::tr2::sys; +#else +namespace fs = std::experimental::filesystem; +#endif
#include <newpluginapi.h>
#include <m_clist.h>
|