summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-02-19 11:48:12 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-02-19 11:48:12 +0000
commit8dc7456651251bc112b9edd9b5fd1c4849d7c83d (patch)
tree3e2e376197c49e77488c109a129ea269b08cb38f /plugins
parent8d428350dc3307f8ada75fafece2049cca84e969 (diff)
import to open a database in read-only mode
git-svn-id: http://svn.miranda-ng.org/main/trunk@8172 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp11
-rw-r--r--plugins/Db3x_mmap/src/dbcrypt.cpp3
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp3
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp44
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h2
-rw-r--r--plugins/Db3x_mmap/src/dbmodulechain.cpp27
-rw-r--r--plugins/Db3x_mmap/src/init.cpp10
-rw-r--r--plugins/Import/src/import.cpp4
8 files changed, 55 insertions, 49 deletions
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index ae0ef7fd36..0f305a2532 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -234,10 +234,15 @@ void CDb3Mmap::FillContacts()
if (p->signature != DBCONTACT_SIGNATURE)
break;
- if (p->dwContactID > m_dwMaxContactId)
- m_dwMaxContactId = p->dwContactID + 1;
+ DWORD dwContactID;
+ if (m_dbHeader.version == DB_095_VERSION) {
+ dwContactID = p->dwContactID;
+ if (dwContactID > m_dwMaxContactId)
+ m_dwMaxContactId = dwContactID + 1;
+ }
+ else dwContactID = m_dwMaxContactId++;
- DBCachedContact *cc = m_cache->AddContactToCache(p->dwContactID);
+ DBCachedContact *cc = m_cache->AddContactToCache(dwContactID);
cc->dwDriverData = dwOffset;
CheckProto(cc, "");
diff --git a/plugins/Db3x_mmap/src/dbcrypt.cpp b/plugins/Db3x_mmap/src/dbcrypt.cpp
index 7b0d1af539..fcd4fd2017 100644
--- a/plugins/Db3x_mmap/src/dbcrypt.cpp
+++ b/plugins/Db3x_mmap/src/dbcrypt.cpp
@@ -128,6 +128,9 @@ int sttModuleEnum(const char *szModule, DWORD, LPARAM lParam)
int CDb3Mmap::InitCrypt()
{
+ if (m_dbHeader.version == DB_OLD_VERSION)
+ return 0;
+
CRYPTO_PROVIDER *pProvider;
DBVARIANT dbv = { 0 };
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index 5610e90e2f..2866dc6bc2 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -23,9 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "commonheaders.h"
-DWORD GetModuleNameOfs(const char *szName);
-char *GetModuleNameByOfs(DWORD ofs);
-
static HANDLE hEventDeletedEvent, hEventAddedEvent, hEventFilterAddedEvent;
STDMETHODIMP_(LONG) CDb3Mmap::GetEventCount(MCONTACT contactID)
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
index e17dd576f2..2a6b3be65c 100644
--- a/plugins/Db3x_mmap/src/dbintf.cpp
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -43,10 +43,10 @@ static int stringCompare2(const char *p1, const char *p2)
return strcmp(p1, p2);
}
-CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName) :
+CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, bool bReadOnly) :
m_hDbFile(INVALID_HANDLE_VALUE),
m_safetyMode(true),
- m_bReadOnly(true),
+ m_bReadOnly(bReadOnly),
m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
@@ -113,7 +113,7 @@ int CDb3Mmap::Load(bool bSkipInit)
log0("DB logging running");
DWORD dummy = 0;
- if (bSkipInit)
+ if (m_bReadOnly)
m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
else
m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
@@ -129,33 +129,33 @@ int CDb3Mmap::Load(bool bSkipInit)
memcpy(&m_dbHeader.signature, &dbSignatureIM, sizeof(m_dbHeader.signature));
if (!bSkipInit) {
- m_bReadOnly = false;
-
if (InitMap()) return 1;
if (InitModuleNames()) return 1;
if (InitCrypt()) return EGROKPRF_CANTREAD;
// everything is ok, go on
- if (m_dbHeader.version < DB_095_VERSION) {
- ConvertContacts();
-
- m_dbHeader.version = DB_095_VERSION;
- DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
+ if (!m_bReadOnly) {
+ if (m_dbHeader.version < DB_095_VERSION) {
+ ConvertContacts();
+
+ m_dbHeader.version = DB_095_VERSION;
+ DBWrite(sizeof(dbSignatureU), &m_dbHeader.version, sizeof(m_dbHeader.version));
+ }
+
+ // we don't need events in the service mode
+ if (ServiceExists(MS_DB_SETSAFETYMODE)) {
+ hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
+ hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
+ hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
+ hEventMarkedRead = CreateHookableEvent(ME_DB_EVENT_MARKED_READ);
+
+ hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
+ hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
+ hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
+ }
}
FillContacts();
-
- // we don't need events in the service mode
- if (ServiceExists(MS_DB_SETSAFETYMODE)) {
- hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
- hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
- hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
- hEventMarkedRead = CreateHookableEvent(ME_DB_EVENT_MARKED_READ);
-
- hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
- hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
- hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
- }
}
return ERROR_SUCCESS;
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 361c91dffa..ff42141458 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -157,7 +157,7 @@ struct DBEvent
struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject
{
- CDb3Mmap(const TCHAR* tszFileName);
+ CDb3Mmap(const TCHAR* tszFileName, bool bReadOnly);
~CDb3Mmap();
int Load(bool bSkipInit);
diff --git a/plugins/Db3x_mmap/src/dbmodulechain.cpp b/plugins/Db3x_mmap/src/dbmodulechain.cpp
index bf193717bd..2eedd6653a 100644
--- a/plugins/Db3x_mmap/src/dbmodulechain.cpp
+++ b/plugins/Db3x_mmap/src/dbmodulechain.cpp
@@ -76,21 +76,22 @@ DWORD CDb3Mmap::FindExistingModuleNameOfs(const char *szName)
return 0;
}
-//will create the offset if it needs to
+// will create the offset if it needs to
DWORD CDb3Mmap::GetModuleNameOfs(const char *szName)
{
- struct DBModuleName dbmn;
- int nameLen;
- DWORD ofsNew,ofsExisting;
- char *mod;
+ DWORD ofsExisting = FindExistingModuleNameOfs(szName);
+ if (ofsExisting)
+ return ofsExisting;
- ofsExisting = FindExistingModuleNameOfs(szName);
- if (ofsExisting) return ofsExisting;
+ if (m_bReadOnly)
+ return 0;
- nameLen = (int)strlen(szName);
+ int nameLen = (int)strlen(szName);
- //need to create the module name
- ofsNew = CreateNewSpace(nameLen+offsetof(struct DBModuleName,name));
+ // need to create the module name
+ DWORD ofsNew = CreateNewSpace(nameLen + offsetof(struct DBModuleName, name));
+
+ DBModuleName dbmn;
dbmn.signature = DBMODULENAME_SIGNATURE;
dbmn.cbName = nameLen;
dbmn.ofsNext = m_dbHeader.ofsFirstModuleName;
@@ -100,12 +101,12 @@ DWORD CDb3Mmap::GetModuleNameOfs(const char *szName)
DBWrite(ofsNew + offsetof(struct DBModuleName, name), (PVOID)szName, nameLen);
DBFlush(0);
- //add to cache
- mod = (char*)HeapAlloc(m_hModHeap,0,nameLen+1);
+ // add to cache
+ char *mod = (char*)HeapAlloc(m_hModHeap, 0, nameLen + 1);
strcpy(mod,szName);
AddToList(mod, nameLen, ofsNew);
- //quit
+ // quit
return ofsNew;
}
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp
index 8b1664d5aa..f2236976a6 100644
--- a/plugins/Db3x_mmap/src/init.cpp
+++ b/plugins/Db3x_mmap/src/init.cpp
@@ -49,7 +49,7 @@ LIST<CDb3Mmap> g_Dbs(1, HandleKeySortT);
// returns 0 if the profile is created, EMKPRF*
static int makeDatabase(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, false));
if (db->Create() != ERROR_SUCCESS)
return EMKPRF_CREATEFAILED;
@@ -59,7 +59,7 @@ static int makeDatabase(const TCHAR *profile)
// returns 0 if the given profile has a valid header
static int grokHeader(const TCHAR *profile)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
if (db->Load(true) != ERROR_SUCCESS)
return EGROKPRF_CANTREAD;
@@ -67,12 +67,12 @@ static int grokHeader(const TCHAR *profile)
}
// returns 0 if all the APIs are injected otherwise, 1
-static MIDatabase* LoadDatabase(const TCHAR *profile)
+static MIDatabase* LoadDatabase(const TCHAR *profile, BOOL bReadOnly)
{
// set the memory, lists & UTF8 manager
mir_getLP(&pluginInfo);
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, bReadOnly != 0));
if (db->Load(false) != ERROR_SUCCESS)
return NULL;
@@ -89,7 +89,7 @@ static int UnloadDatabase(MIDatabase* db)
MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
- std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile));
+ std::auto_ptr<CDb3Mmap> db(new CDb3Mmap(profile, true));
if (db->Load(true) != ERROR_SUCCESS) {
*error = EGROKPRF_CANTREAD;
return NULL;
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index bece09a02c..3c9e413a22 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -451,13 +451,13 @@ void MirandaImport(HWND hdlg)
return;
}
- DATABASELINK* dblink = FindDatabasePlugin(importFile);
+ DATABASELINK *dblink = FindDatabasePlugin(importFile);
if (dblink == NULL) {
AddMessage(LPGENT("There's no database driver to open the input file, exiting."));
return;
}
- if ((srcDb = dblink->Load(importFile)) == NULL) {
+ if ((srcDb = dblink->Load(importFile, TRUE)) == NULL) {
AddMessage(LPGENT("Error loading source file, exiting."));
return;
}