summaryrefslogtreecommitdiff
path: root/plugins/Db_autobackups
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Db_autobackups')
-rw-r--r--plugins/Db_autobackups/src/backup.cpp20
-rw-r--r--plugins/Db_autobackups/src/main.cpp18
-rw-r--r--plugins/Db_autobackups/src/stdafx.h4
-rw-r--r--plugins/Db_autobackups/src/version.h2
4 files changed, 24 insertions, 20 deletions
diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp
index 34b13ca302..dbbb416260 100644
--- a/plugins/Db_autobackups/src/backup.cpp
+++ b/plugins/Db_autobackups/src/backup.cpp
@@ -28,7 +28,7 @@ static LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM
static void ShowPopup(const wchar_t *ptszText, wchar_t *ptszHeader, wchar_t *ptszPath)
{
- if (g_plugin.bTerminated)
+ if (Miranda_IsTerminated())
return;
POPUPDATAW ppd;
@@ -304,22 +304,20 @@ static void BackupThread(void *backup_filename)
mir_free(backup_filename);
}
-void BackupStart(wchar_t *backup_filename, bool bInThread)
+int BackupStatus()
{
- LONG cur_state = InterlockedCompareExchange(&g_iState, 1, 0);
- if (cur_state != 0) { // Backup allready in process.
+ return InterlockedCompareExchange(&g_iState, 1, 0);
+}
+
+void BackupStart(wchar_t *backup_filename)
+{
+ if (BackupStatus() != 0) { // Backup allready in process.
ShowPopup(TranslateT("Database back up in process..."), TranslateT("Error"), nullptr);
return;
}
- if (bInThread) {
- if (mir_forkthread(BackupThread, mir_wstrdup(backup_filename)) == INVALID_HANDLE_VALUE)
- InterlockedExchange(&g_iState, 0); // Backup done.
- }
- else {
- Backup(backup_filename);
+ if (mir_forkthread(BackupThread, mir_wstrdup(backup_filename)) == INVALID_HANDLE_VALUE)
InterlockedExchange(&g_iState, 0); // Backup done.
- }
}
VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD)
diff --git a/plugins/Db_autobackups/src/main.cpp b/plugins/Db_autobackups/src/main.cpp
index b315b4a9a4..3695a19350 100644
--- a/plugins/Db_autobackups/src/main.cpp
+++ b/plugins/Db_autobackups/src/main.cpp
@@ -140,12 +140,18 @@ static int ModulesLoad(WPARAM, LPARAM)
// can't do this on unload, since other plugins will be have already been unloaded, but their hooks
// for setting changed event not cleared. the backup on exit function will write to the db, calling those hooks.
-static int PreShutdown(WPARAM, LPARAM)
-{
- g_plugin.bTerminated = true;
+static bool bStarted = false;
- if (g_plugin.backup_types & BT_EXIT)
- BackupStart(nullptr, false);
+static int OkToExit(WPARAM, LPARAM)
+{
+ if (g_plugin.backup_types & BT_EXIT) {
+ if (bStarted)
+ return BackupStatus() ? 1 : 0;
+
+ bStarted = true;
+ BackupStart(nullptr);
+ return 1;
+ }
return 0;
}
@@ -153,7 +159,7 @@ int CMPlugin::Load()
{
Miranda_GetVersionText(g_szMirVer, sizeof(g_szMirVer));
- HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
+ HookEvent(ME_SYSTEM_OKTOEXIT, OkToExit);
HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoad);
g_plugin.registerIcon(LPGEN("Database") "/" LPGEN("Database backups"), iconList);
diff --git a/plugins/Db_autobackups/src/stdafx.h b/plugins/Db_autobackups/src/stdafx.h
index f4dd0be3bc..ad48212350 100644
--- a/plugins/Db_autobackups/src/stdafx.h
+++ b/plugins/Db_autobackups/src/stdafx.h
@@ -34,7 +34,6 @@ struct CMPlugin : public PLUGIN<CMPlugin>
{
CMPlugin();
- bool bTerminated;
CMOption<BYTE> backup_types;
CMOption<WORD> period;
CMOption<BYTE> period_type;
@@ -60,7 +59,8 @@ struct CMPlugin : public PLUGIN<CMPlugin>
int SetBackupTimer(void);
int OptionsInit(WPARAM wParam, LPARAM lParam);
-void BackupStart(wchar_t *backup_filename, bool bInThread = true);
+void BackupStart(wchar_t *backup_filename);
+int BackupStatus(void);
struct ZipFile
{
diff --git a/plugins/Db_autobackups/src/version.h b/plugins/Db_autobackups/src/version.h
index 4f3f7f9111..0b7695160f 100644
--- a/plugins/Db_autobackups/src/version.h
+++ b/plugins/Db_autobackups/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __BUILD_NUM 4
#include <stdver.h>