summaryrefslogtreecommitdiff
path: root/plugins/Db_autobackups/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db_autobackups/src')
-rw-r--r--plugins/Db_autobackups/src/backup.cpp122
-rw-r--r--plugins/Db_autobackups/src/headers.h1
-rw-r--r--plugins/Db_autobackups/src/options.cpp9
-rw-r--r--plugins/Db_autobackups/src/options.h1
-rw-r--r--plugins/Db_autobackups/src/resource.h1
-rw-r--r--plugins/Db_autobackups/src/version.h22
6 files changed, 132 insertions, 24 deletions
diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp
index 3050b4d050..8ae4384bac 100644
--- a/plugins/Db_autobackups/src/backup.cpp
+++ b/plugins/Db_autobackups/src/backup.cpp
@@ -1,6 +1,8 @@
#include "headers.h"
+#include "..\Zlib\src\zip.h"
TCHAR dbname[MAX_PATH];
+HWND progress_dialog;
static UINT_PTR timer_id;
@@ -24,6 +26,95 @@ INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
}
return FALSE;
}
+TCHAR* DoubleSlash(TCHAR *sorce)
+{
+ TCHAR *ret = (TCHAR*)mir_calloc(MAX_PATH);
+ TCHAR *r, *s;
+ for (s = sorce, r = ret; *s && r - ret < MAX_PATH; s++, r++){
+ if (*s != _T('\\'))
+ *r = *s;
+ else{
+ *r = _T('\\');
+ r++;
+ *r = _T('\\');
+ }
+ }
+ return ret;
+}
+
+bool MakeZip(LPCTSTR tszSource, LPCTSTR tszDest)
+{
+ bool ret = false;
+
+ char* tmp = mir_u2a(tszSource);
+
+ ptrA szSourceName(mir_strdup(strrchr(tmp, '\\') + 1));
+ ptrT tszDestPath(DoubleSlash((TCHAR*)tszDest));
+
+ mir_free(tmp);
+
+ WIN32_FILE_ATTRIBUTE_DATA fad = {0};
+ if ( GetFileAttributesEx( tszSource, GetFileExInfoStandard, &fad ) )
+ {
+ SYSTEMTIME st;
+ FileTimeToLocalFileTime( &fad.ftLastWriteTime, &fad.ftLastWriteTime );
+ FileTimeToSystemTime( &fad.ftLastWriteTime, &st );
+
+ HANDLE hSrc = CreateFile( tszSource, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+ if ( hSrc != INVALID_HANDLE_VALUE )
+ {
+ if ( zipFile hZip = zipOpen2_64(tszDestPath, APPEND_STATUS_CREATE, NULL, NULL) )
+ {
+ zip_fileinfo fi = {0};
+ fi.tmz_date.tm_sec = st.wSecond;
+ fi.tmz_date.tm_min = st.wMinute;
+ fi.tmz_date.tm_hour = st.wHour;
+ fi.tmz_date.tm_mday = st.wDay;
+ fi.tmz_date.tm_mon = st.wMonth;
+ fi.tmz_date.tm_year = st.wYear;
+
+ int res = zipOpenNewFileInZip( hZip, szSourceName, &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION );
+ if ( res == ZIP_OK )
+ {
+ DWORD buf_length = 256 * 1024; // 256 KB
+ HWND hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS);
+ UINT i = 0;
+ if ( void* buf = mir_alloc( buf_length ) )
+ {
+ for (;;)
+ {
+ DWORD read = 0;
+ if ( ! ReadFile( hSrc, buf, buf_length, &read, NULL ) )
+ break;
+
+ if ( read == 0 )
+ {
+ // EOF
+ ret = true;
+ break;
+ }
+
+ res = zipWriteInFileInZip( hZip, buf, read );
+ if ( res != ZIP_OK )
+ break;
+
+ SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100 / ((int)fad.nFileSizeLow / buf_length) * ++i), 0);
+ }
+
+ mir_free( buf );
+ }
+ zipCloseFileInZip( hZip );
+ }
+ char szComment[128];
+ mir_snprintf(szComment, SIZEOF(szComment), "Miranda NG Database\r\nCreated by: %s %d.%d.%d.%d\r\n", __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM);
+ zipClose( hZip, szComment);
+ }
+ CloseHandle( hSrc );
+ }
+ }
+
+ return ret;
+}
INT_PTR DBSaveAs(WPARAM wParam, LPARAM lParam)
{
@@ -58,11 +149,11 @@ struct FileNameFound_Tag
FILETIME CreationTime;
}FileNameFound;
-int RotateBackups(HWND progress_dialog, DWORD start_time)
+int RotateBackups(DWORD start_time)
{
TCHAR backupfilename1[MAX_PATH] = {0}, backupfolderTmp[MAX_PATH] = {0};
unsigned int i = 0;
- HWND prog = GetDlgItem(progress_dialog, IDC_PROGRESS);
+ HWND hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS);
MSG msg;
WIN32_FIND_DATA FindFileData;
@@ -78,7 +169,7 @@ int RotateBackups(HWND progress_dialog, DWORD start_time)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
continue;
- else if (_tcsicmp(&FindFileData.cFileName[_tcslen(FindFileData.cFileName)-4], _T(".bak")) == 0)
+ else if (_tcsicmp(&FindFileData.cFileName[_tcslen(FindFileData.cFileName)-4], _T(".bak")) == 0 || _tcsicmp(&FindFileData.cFileName[_tcslen(FindFileData.cFileName)-4], _T(".zip")) == 0)
{
if (_tcsicmp(FileNameFound.Name, _T("")) == 0)
{
@@ -90,7 +181,6 @@ int RotateBackups(HWND progress_dialog, DWORD start_time)
_tcscpy(FileNameFound.Name, FindFileData.cFileName);
FileNameFound.CreationTime = FindFileData.ftCreationTime;
}
- i++;
while(PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0)
{
if (!IsDialogMessage(progress_dialog, &msg))
@@ -100,8 +190,8 @@ int RotateBackups(HWND progress_dialog, DWORD start_time)
}
}
- SendMessage(prog, PBM_SETPOS, (WPARAM)(int)(100 * (options.num_backups - i) / options.num_backups), 0);
- UpdateWindow(progress_dialog);
+ SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100 / options.num_backups * ++i), 0);
+ //UpdateWindow(progress_dialog);
}
}
@@ -123,8 +213,8 @@ void BackupThread(void* backup_filename)
int Backup(TCHAR* backup_filename)
{
TCHAR source_file[MAX_PATH] = {0}, dest_file[MAX_PATH] = {0};
- HWND progress_dialog;
DWORD start_time = GetTickCount();
+ BOOL bZip = FALSE;
CallService(MS_DB_GETPROFILENAMET, MAX_PATH, (LPARAM)dbname);
@@ -133,6 +223,7 @@ int Backup(TCHAR* backup_filename)
SYSTEMTIME st;
TCHAR buffer[MAX_COMPUTERNAME_LENGTH+1];
DWORD size = sizeof(buffer);
+ bZip = options.use_zip;
TCHAR *backupfolder = Utils_ReplaceVarsT(options.folder);
// ensure the backup folder exists (either create it or return non-zero signifying error)
@@ -143,7 +234,7 @@ int Backup(TCHAR* backup_filename)
GetLocalTime(&st);
GetComputerName(buffer, &size);
- mir_sntprintf(dest_file, MAX_PATH, _T("%s\\%s_%02d.%02d.%02d@%02d-%02d-%02d_%s.bak"), backupfolder, dbname, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, buffer);
+ mir_sntprintf(dest_file, MAX_PATH, _T("%s\\%s_%02d.%02d.%02d@%02d-%02d-%02d_%s.%s"), backupfolder, dbname, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, buffer, bZip? _T("zip") : _T("bak"));
mir_free(backupfolder);
}
else
@@ -157,17 +248,22 @@ int Backup(TCHAR* backup_filename)
SetDlgItemText(progress_dialog, IDC_PROGRESSMESSAGE, TranslateT("Rotating backup files..."));
}
- RotateBackups(progress_dialog, start_time);
+ RotateBackups(start_time);
- SetDlgItemText(progress_dialog, 0xDAED, TranslateT("Copying database file..."));
- SendMessage(progress_dialog, PBM_SETPOS, (WPARAM)(int)(0), 0);
+ SetDlgItemText(progress_dialog, IDC_PROGRESSMESSAGE, TranslateT("Copying database file..."));
+ SendMessage(GetDlgItem(progress_dialog, IDC_PROGRESS), PBM_SETPOS, (WPARAM)0, 0);
UpdateWindow(progress_dialog);
mir_sntprintf(source_file, MAX_PATH, _T("%s\\%s"), profilePath, dbname);
TCHAR *pathtmp = Utils_ReplaceVarsT(source_file);
- if (CopyFile(pathtmp, dest_file, 0))
+ BOOL res = 0;
+ if(bZip)
+ res = MakeZip(pathtmp, dest_file);
+ else
+ res = CopyFile(pathtmp, dest_file, 0);
+ if (res)
{
- SendMessage(progress_dialog, PBM_SETPOS, (WPARAM)(int)(100), 0);
+ SendMessage(GetDlgItem(progress_dialog, IDC_PROGRESS), PBM_SETPOS, (WPARAM)(100), 0);
UpdateWindow(progress_dialog);
db_set_dw(0, "AutoBackups", "LastBackupTimestamp", (DWORD)time(0));
if (!options.disable_popups)
diff --git a/plugins/Db_autobackups/src/headers.h b/plugins/Db_autobackups/src/headers.h
index 8195df1c36..447c2bd885 100644
--- a/plugins/Db_autobackups/src/headers.h
+++ b/plugins/Db_autobackups/src/headers.h
@@ -38,6 +38,7 @@ int OptionsInit(WPARAM wParam, LPARAM lParam);
int LoadOptions(void);
HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle);
void BackupThread(void* backup_filename);
+bool MakeZip(LPCTSTR szSource, LPCTSTR szDest);
extern HINSTANCE hInst;
extern TCHAR* profilePath;
diff --git a/plugins/Db_autobackups/src/options.cpp b/plugins/Db_autobackups/src/options.cpp
index e76707a904..e547b3f6c4 100644
--- a/plugins/Db_autobackups/src/options.cpp
+++ b/plugins/Db_autobackups/src/options.cpp
@@ -29,6 +29,7 @@ int LoadOptions(void)
options.disable_progress = (BOOL)db_get_b(0, "AutoBackups", "NoProgress", 0);
options.disable_popups = (BOOL)db_get_b(0, "AutoBackups", "NoPopups", 0);
+ options.use_zip = (BOOL)db_get_b(0, "AutoBackups", "UseZip", 0);
SetBackupTimer();
return 0;
@@ -63,6 +64,7 @@ int SaveOptions(void)
db_set_w(0, "AutoBackups", "NumBackups", (WORD)options.num_backups);
db_set_b(0, "AutoBackups", "NoProgress", (BYTE)options.disable_progress);
db_set_b(0, "AutoBackups", "NoPopups", (BYTE)options.disable_popups);
+ db_set_b(0, "AutoBackups", "UseZip", (BYTE)options.use_zip);
SetBackupTimer();
return 0;
@@ -83,6 +85,7 @@ int SetDlgState(HWND hwndDlg)
EnableWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPROG), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_USEZIP), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PERIOD), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_PT), FALSE);
@@ -97,6 +100,7 @@ int SetDlgState(HWND hwndDlg)
EnableWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPROG), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), TRUE);
+ 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);
@@ -116,6 +120,7 @@ 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);
if ( !ServiceExists(MS_POPUP_ADDPOPUP))
ShowWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), SW_HIDE);
@@ -264,6 +269,10 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
new_options.disable_popups = IsDlgButtonChecked(hwndDlg, IDC_CHK_NOPOPUP);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
+ case IDC_CHK_USEZIP:
+ new_options.use_zip = 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 240fc9566e..2a40fef27f 100644
--- a/plugins/Db_autobackups/src/options.h
+++ b/plugins/Db_autobackups/src/options.h
@@ -32,6 +32,7 @@ typedef struct Options_tag {
unsigned int num_backups;
BOOL disable_progress;
BOOL disable_popups;
+ BOOL use_zip;
} 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 fe3f28621c..c1e0c84d7d 100644
--- a/plugins/Db_autobackups/src/resource.h
+++ b/plugins/Db_autobackups/src/resource.h
@@ -20,6 +20,7 @@
#define IDC_CHK_NOPROG 1670
#define IDC_BUT_NOW 1671
#define IDC_CHK_NOPOPUP 1672
+#define IDC_CHK_USEZIP 1673
#define IDC_PROGRESSMESSAGE 0xDAED
#define IDC_PROGRESS 0xDEAD
diff --git a/plugins/Db_autobackups/src/version.h b/plugins/Db_autobackups/src/version.h
index e0a5f3290c..b883b2e917 100644
--- a/plugins/Db_autobackups/src/version.h
+++ b/plugins/Db_autobackups/src/version.h
@@ -1,14 +1,14 @@
-#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 9
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 0
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 10
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
-#define __PLUGIN_NAME "Db autobackuper"
-#define __FILENAME "Db_autobackups.dll"
-#define __DESCRIPTION "Db autobackuper plugin."
-#define __AUTHOR "chaos.persei, sje, Kildor, Billy_Bons"
-#define __AUTHOREMAIL "chaos.persei@gmail.com"
-#define __AUTHORWEB "http://miranda-ng.org/p/Db_autobackups/"
-#define __COPYRIGHT "© 2005-2011 chaos.persei, sje, Kildor, Billy_Bons, Vasilich"
+#define __PLUGIN_NAME "Db autobackuper"
+#define __FILENAME "Db_autobackups.dll"
+#define __DESCRIPTION "Db autobackuper plugin."
+#define __AUTHOR "chaos.persei, sje, Kildor, Billy_Bons"
+#define __AUTHOREMAIL "chaos.persei@gmail.com"
+#define __AUTHORWEB "http://miranda-ng.org/p/Db_autobackups/"
+#define __COPYRIGHT "© 2005-2013 chaos.persei, sje, Kildor, Billy_Bons, Vasilich"