diff options
Diffstat (limited to 'plugins/Db3x_mmap/src/dbintf.cpp')
-rw-r--r-- | plugins/Db3x_mmap/src/dbintf.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 888d47e1d3..0e2187e993 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -43,10 +43,11 @@ static int stringCompare2(const char *p1, const char *p2) return strcmp(p1, p2);
}
-CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly) :
+CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, int iMode) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(true),
- m_bReadOnly(bReadOnly),
+ m_bReadOnly((iMode & DBMODE_READONLY) != 0),
+ m_bShared((iMode & DBMODE_SHARED) != 0),
m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
@@ -79,7 +80,7 @@ CDb3Mmap::~CDb3Mmap() }
DestroyServiceFunction(hService);
- UnhookEvent(hHook); + UnhookEvent(hHook);
if (m_crypto)
m_crypto->destroy();
@@ -93,7 +94,9 @@ CDb3Mmap::~CDb3Mmap() SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN);
WriteFile(m_hDbFile, &dbSignatureIM, 1, &bytesWritten, NULL);
}
- CloseHandle(m_hDbFile);
+
+ if (m_hDbFile != INVALID_HANDLE_VALUE)
+ CloseHandle(m_hDbFile);
DestroyHookableEvent(hContactDeletedEvent);
DestroyHookableEvent(hContactAddedEvent);
@@ -118,13 +121,16 @@ static TCHAR szMsgConvert[] = int CDb3Mmap::Load(bool bSkipInit)
{
log0("DB logging running");
-
- DWORD dummy = 0;
+
+ DWORD dummy = 0, dwMode = FILE_SHARE_READ;
+ if (m_bShared)
+ dwMode |= FILE_SHARE_WRITE;
if (m_bReadOnly)
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, dwMode, NULL, OPEN_EXISTING, 0, NULL);
else
- m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
- if ( m_hDbFile == INVALID_HANDLE_VALUE )
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, dwMode, NULL, OPEN_ALWAYS, 0, NULL);
+
+ if (m_hDbFile == INVALID_HANDLE_VALUE)
return EGROKPRF_CANTREAD;
if (!ReadFile(m_hDbFile, &m_dbHeader, sizeof(m_dbHeader), &dummy, NULL)) {
|