diff options
author | George Hazan <george.hazan@gmail.com> | 2015-01-10 12:39:54 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-01-10 12:39:54 +0000 |
commit | ed3d8bba1b542e0bbf382a6f2eb4b78147d10bc0 (patch) | |
tree | 1aa1aa2cff7f8bcb6ac8a6883f3b7ce280cad072 /plugins/Dbx_mdb/src/dbintf.cpp | |
parent | ef65d01f2525cf6d52a59c0df06b4f8e4cf924ec (diff) |
- writeable module names;
- compilation fix for 32 bits build;
- DatabaseCorruption() returned
git-svn-id: http://svn.miranda-ng.org/main/trunk@11812 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src/dbintf.cpp')
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.cpp | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index 880c0c80fd..43a15b6457 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -95,11 +95,11 @@ int CDbxMdb::Load(bool bSkipInit) return EGROKPRF_CANTREAD;
if (!bSkipInit) {
- mdb_txn_begin(m_pMdbEnv, NULL, 0, &m_txn); -
- mdb_open(m_txn, "modules", MDB_CREATE | MDB_INTEGERKEY, &m_dbModules); - mdb_open(m_txn, "contacts", MDB_CREATE | MDB_INTEGERKEY, &m_dbContacts); - mdb_open(m_txn, "events", MDB_CREATE | MDB_INTEGERKEY, &m_dbEvents); + MDB_txn *txn;
+ mdb_txn_begin(m_pMdbEnv, NULL, 0, &txn); + mdb_open(txn, "contacts", MDB_CREATE | MDB_INTEGERKEY, &m_dbContacts); + mdb_open(txn, "events", MDB_CREATE | MDB_INTEGERKEY, &m_dbEvents); + mdb_txn_commit(txn); if (InitModuleNames()) return EGROKPRF_CANTREAD;
if (InitCrypt()) return EGROKPRF_CANTREAD;
@@ -156,7 +156,7 @@ int CDbxMdb::Check(void) return (memcmp(buf + 16, "\xDE\xC0\xEF\xBE", 4)) ? EGROKPRF_UNKHEADER : 0;
}
-int CDbxMdb::PrepareCheck(int *error)
+int CDbxMdb::PrepareCheck(int*)
{
InitModuleNames();
return InitCrypt();
@@ -168,6 +168,53 @@ STDMETHODIMP_(void) CDbxMdb::SetCacheSafetyMode(BOOL bIsSet) m_safetyMode = bIsSet != 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static DWORD DatabaseCorrupted = 0;
+static const TCHAR *msg = NULL;
+static DWORD dwErr = 0;
+static TCHAR tszPanic[] = LPGENT("Miranda has detected corruption in your database. This corruption may be fixed by DbChecker plugin. Please download it from http://miranda-ng.org/p/DbChecker/. Miranda will now shut down.");
+
+void __cdecl dbpanic(void *)
+{
+ if (msg) {
+ if (dwErr == ERROR_DISK_FULL)
+ msg = TranslateT("Disk is full. Miranda will now shut down.");
+
+ TCHAR err[256];
+ mir_sntprintf(err, SIZEOF(err), msg, TranslateT("Database failure. Miranda will now shut down."), dwErr);
+
+ MessageBox(0, err, TranslateT("Database Error"), MB_SETFOREGROUND | MB_TOPMOST | MB_APPLMODAL | MB_ICONWARNING | MB_OK);
+ }
+ else MessageBox(0, TranslateTS(tszPanic), TranslateT("Database Panic"), MB_SETFOREGROUND | MB_TOPMOST | MB_APPLMODAL | MB_ICONWARNING | MB_OK);
+ TerminateProcess(GetCurrentProcess(), 255);
+}
+
+void CDbxMdb::DatabaseCorruption(const TCHAR *text)
+{
+ int kill = 0;
+
+ mir_cslockfull lck(m_csDbAccess);
+ if (DatabaseCorrupted == 0) {
+ DatabaseCorrupted++;
+ kill++;
+ msg = text;
+ dwErr = GetLastError();
+ }
+ else {
+ /* db is already corrupted, someone else is dealing with it, wait here
+ so that we don't do any more damage */
+ Sleep(INFINITE);
+ return;
+ }
+ lck.unlock();
+
+ if (kill) {
+ _beginthread(dbpanic, 0, NULL);
+ Sleep(INFINITE);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
// MIDatabaseChecker
@@ -179,7 +226,7 @@ int CDbxMdb::Start(DBCHeckCallback *callback) return ERROR_SUCCESS;
}
-int CDbxMdb::CheckDb(int phase, int firstTime)
+int CDbxMdb::CheckDb(int, int)
{
return ERROR_OUT_OF_PAPER;
|