diff options
author | George Hazan <ghazan@miranda.im> | 2018-06-20 18:54:49 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-06-20 18:54:49 +0300 |
commit | 2079a83c7b01c68be4276d8c89d1a7967d07c3f9 (patch) | |
tree | e75f9ca98174cae5c7fa6f323f578f8c89661179 /plugins | |
parent | 9b60e6be3c41466e2beae22ef4cfd6f776f27b0f (diff) |
Db_autobackup:
- folder option isn't applied on the fly;
- code cleaning;
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Db_autobackups/src/backup.cpp | 46 | ||||
-rw-r--r-- | plugins/Db_autobackups/src/options.cpp | 23 |
2 files changed, 32 insertions, 37 deletions
diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp index d9b4dd5b5e..e27e9ff610 100644 --- a/plugins/Db_autobackups/src/backup.cpp +++ b/plugins/Db_autobackups/src/backup.cpp @@ -8,14 +8,14 @@ LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_COMMAND:
- {
- wchar_t* ptszPath = (wchar_t*)PUGetPluginData(hWnd);
- if (ptszPath != nullptr)
- ShellExecute(nullptr, L"open", ptszPath, nullptr, nullptr, SW_SHOW);
+ {
+ wchar_t* ptszPath = (wchar_t*)PUGetPluginData(hWnd);
+ if (ptszPath != nullptr)
+ ShellExecute(nullptr, L"open", ptszPath, nullptr, nullptr, SW_SHOW);
- PUDeletePopup(hWnd);
- break;
- }
+ PUDeletePopup(hWnd);
+ break;
+ }
case WM_CONTEXTMENU:
PUDeletePopup(hWnd);
break;
@@ -84,11 +84,9 @@ bool MakeZip_Dir(LPCSTR szDir, LPCTSTR szDest, LPCSTR /* szDbName */, HWND progr size_t count = 0;
OBJLIST<ZipFile> lstFiles(15);
- for (auto it = fs::recursive_directory_iterator(fs::path(szDir)); it != fs::recursive_directory_iterator(); ++it)
- {
+ for (auto it = fs::recursive_directory_iterator(fs::path(szDir)); it != fs::recursive_directory_iterator(); ++it) {
const auto& file = it->path();
- if (!fs::is_directory(file) && file.string().find(fs::path((char*)_T2A(szDest)).string().c_str()) == std::string::npos)
- {
+ if (!fs::is_directory(file) && file.string().find(fs::path((char*)_T2A(szDest)).string().c_str()) == std::string::npos) {
const std::string &filepath = file.string();
const std::string rpath = filepath.substr(filepath.find(szDir) + mir_strlen(szDir) + 1);
@@ -96,12 +94,11 @@ bool MakeZip_Dir(LPCSTR szDir, LPCTSTR szDest, LPCSTR /* szDbName */, HWND progr count++;
}
}
- if (count == 0)
+ if (count == 0)
return 1;
- CreateZipFile(_T2A(szDest), lstFiles, [&](size_t i)->bool
- {
- SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100 * i / count), 0);
+ CreateZipFile(_T2A(szDest), lstFiles, [&](size_t i)->bool {
+ SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100 * i / count), 0);
return GetWindowLongPtr(progress_dialog, GWLP_USERDATA) != 1;
});
@@ -117,7 +114,7 @@ bool MakeZip(wchar_t *tszSource, wchar_t *tszDest, wchar_t *dbname, HWND progres OBJLIST<ZipFile> lstFiles(15);
lstFiles.insert(new ZipFile((char*)_T2A(tszSource), (char*)szSourceName));
- CreateZipFile(_T2A(tszDest), lstFiles, [&](size_t)->bool{ SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100), 0); return true; });
+ CreateZipFile(_T2A(tszDest), lstFiles, [&](size_t)->bool { SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100), 0); return true; });
return true;
}
@@ -165,11 +162,11 @@ int RotateBackups(wchar_t *backupfolder, wchar_t *dbname) bf = bftmp;
wcsncpy_s(bf[i].Name, FindFileData.cFileName, _TRUNCATE);
bf[i].CreationTime = FindFileData.ftCreationTime;
- i ++;
+ i++;
} while (FindNextFile(hFind, &FindFileData));
if (i > 0)
qsort(bf, i, sizeof(backupFile), Comp); /* Sort the list of found files by date in descending order. */
- for (; i >= options.num_backups; i --) {
+ for (; i >= options.num_backups; i--) {
mir_snwprintf(backupfolderTmp, L"%s\\%s", backupfolder, bf[(i - 1)].Name);
DeleteFile(backupfolderTmp);
}
@@ -179,7 +176,6 @@ err_out: return 0;
}
-
int Backup(wchar_t *backup_filename)
{
bool bZip = false;
@@ -224,14 +220,13 @@ int Backup(wchar_t *backup_filename) VARSW profile_path(L"%miranda_userdata%");
mir_snwprintf(source_file, L"%s\\%s", profile_path, dbname);
BOOL res = 0;
- if (bZip)
- {
- res = options.backup_profile
+ if (bZip) {
+ res = options.backup_profile
? MakeZip_Dir(_T2A(profile_path), dest_file, _T2A(dbname), progress_dialog)
: MakeZip(source_file, dest_file, dbname, progress_dialog);
}
- else
- res = CopyFile(source_file, dest_file, 0);
+ else res = CopyFile(source_file, dest_file, 0);
+
if (res) {
if (!bZip) { // Set the backup file to the current time for rotator's correct work
FILETIME ft;
@@ -245,8 +240,7 @@ int Backup(wchar_t *backup_filename) UpdateWindow(progress_dialog);
db_set_dw(0, MODULENAME, "LastBackupTimestamp", (DWORD)time(0));
- if (options.use_cloudfile)
- {
+ if (options.use_cloudfile) {
CFUPLOADDATA ui =
{
options.cloudfile_service,
diff --git a/plugins/Db_autobackups/src/options.cpp b/plugins/Db_autobackups/src/options.cpp index be3543ea2e..ad70ed9a5f 100644 --- a/plugins/Db_autobackups/src/options.cpp +++ b/plugins/Db_autobackups/src/options.cpp @@ -123,19 +123,20 @@ void COptionsDlg::OnApply() options.period_type = m_periodType.GetCurSel();
ptrW folder(m_folder.GetText());
- {
- wchar_t backupfolder[MAX_PATH];
- PathToAbsoluteW(VARSW(folder), backupfolder);
- int err = CreateDirectoryTreeW(backupfolder);
- if (err != ERROR_ALREADY_EXISTS && err != 0) {
- wchar_t msg[512];
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, 0, msg, 512, nullptr);
- MessageBox(nullptr, msg, TranslateT("Error creating backup folder"), MB_OK | MB_ICONERROR);
- return;
- }
- db_set_ws(0, MODULENAME, "Folder", folder);
+
+ wchar_t backupfolder[MAX_PATH];
+ PathToAbsoluteW(VARSW(folder), backupfolder);
+ int err = CreateDirectoryTreeW(backupfolder);
+ if (err != ERROR_ALREADY_EXISTS && err != 0) {
+ wchar_t msg[512];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, 0, msg, 512, nullptr);
+ MessageBox(nullptr, msg, TranslateT("Error creating backup folder"), MB_OK | MB_ICONERROR);
+ return;
}
+ wcsncpy_s(options.folder, folder, _TRUNCATE);
+ db_set_ws(0, MODULENAME, "Folder", folder);
+
int currentService = m_cloudFileService.GetCurSel();
options.cloudfile_service = currentService >= 0
? (char*)m_cloudFileService.GetItemData(currentService)
|