From 93d627691da3569dd0582cc5ebaf425f4e8087d2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Jul 2012 07:35:57 +0000 Subject: read-only mode for databases git-svn-id: http://svn.miranda-ng.org/main/trunk@1237 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbevents.cpp | 4 +--- plugins/Db3x_mmap/src/dbintf.cpp | 15 ++++++++++----- plugins/Db3x_mmap/src/dbintf.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp index ef72fd3ebc..e6681d6a75 100644 --- a/plugins/Db3x_mmap/src/dbevents.cpp +++ b/plugins/Db3x_mmap/src/dbevents.cpp @@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" -extern BOOL m_safetyMode; - DWORD GetModuleNameOfs(const char *szName); char *GetModuleNameByOfs(DWORD ofs); @@ -47,7 +45,7 @@ STDMETHODIMP_(HANDLE) CDb3Base::AddEvent(HANDLE hContact, DBEVENTINFO *dbei) if (NotifyEventHooks(hEventFilterAddedEvent, (WPARAM)hContact, (LPARAM)dbei)) return 0; - BOOL neednotify; + bool neednotify; mir_cslockfull lck(m_csDbAccess); DWORD ofsContact = (hContact == 0) ? m_dbHeader.ofsUser : (DWORD)hContact; diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 84ddc64468..3decb9bc4b 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -52,7 +52,8 @@ static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2 ) CDb3Base::CDb3Base(const TCHAR* tszFileName) : m_hDbFile(INVALID_HANDLE_VALUE), - m_safetyMode(TRUE), + m_safetyMode(true), + m_bReadOnly(true), m_lSettings(100, stringCompare), m_lContacts(50, LIST::FTSortFunc(HandleKeySort)), m_lGlobalSettings(50, compareGlobals), @@ -98,9 +99,11 @@ CDb3Base::~CDb3Base() CloseHandle(m_hMap); // update profile last modified time - DWORD bytesWritten; - SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN); - WriteFile(m_hDbFile, &dbSignature, 1, &bytesWritten, NULL); + if (!m_bReadOnly) { + DWORD bytesWritten; + SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN); + WriteFile(m_hDbFile, &dbSignature, 1, &bytesWritten, NULL); + } CloseHandle(m_hDbFile); DeleteCriticalSection(&m_csDbAccess); @@ -126,6 +129,8 @@ int CDb3Base::Load(bool bSkipInit) if (InitCache()) return 1; if (InitModuleNames()) return 1; + m_bReadOnly = false; + hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED); hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED); hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED); @@ -146,7 +151,7 @@ int CDb3Base::Create() STDMETHODIMP_(void) CDb3Base::SetCacheSafetyMode(BOOL bIsSet) { { mir_cslock lck(m_csDbAccess); - m_safetyMode = bIsSet; + m_safetyMode = bIsSet != 0; } DBFlush(1); } diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index f3d04d0959..3a744427a8 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -243,7 +243,7 @@ protected: HANDLE m_hDbFile; DBHeader m_dbHeader; DWORD m_ChunkSize; - BOOL m_safetyMode; + bool m_safetyMode, m_bReadOnly; //////////////////////////////////////////////////////////////////////////// // database stuff -- cgit v1.2.3