summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-11 14:49:47 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-11 14:49:47 +0000
commit5dffb8d954968e1bd715bc62d0e3d51d5afb67c4 (patch)
treeeefc5feb1ee17a83c9598a92e9b5933ed5d230df /plugins/Db3x_mmap/src
parenta0a667fd07e912b1dc425748e58a72fa9a50512f (diff)
kinda final version of old MC convertor
git-svn-id: http://svn.miranda-ng.org/main/trunk@8558 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/src')
-rw-r--r--plugins/Db3x_mmap/src/dbcontacts.cpp63
-rw-r--r--plugins/Db3x_mmap/src/dbevents.cpp49
-rw-r--r--plugins/Db3x_mmap/src/dbintf.h8
3 files changed, 68 insertions, 52 deletions
diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp
index 4c2d03f758..7365fb5bd9 100644
--- a/plugins/Db3x_mmap/src/dbcontacts.cpp
+++ b/plugins/Db3x_mmap/src/dbcontacts.cpp
@@ -314,22 +314,13 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub)
if (dbMeta.ofsFirstEvent == 0) // nothing to do
return 0;
- // drop subContact's history if any
- for (DWORD dwOffset = dbSub.ofsFirstEvent; dwOffset != 0;) {
- DBEvent *pev = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
- if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it
- return 2;
-
- DWORD dwNext = pev->ofsNext;
- DeleteSpace(dwOffset, offsetof(DBEvent, blob) + pev->cbBlob);
- dwOffset = dwNext;
- }
-
BOOL ret = 0;
__try {
+ if (ret = WipeContactHistory(&dbSub))
+ __leave;
+
DWORD dwOffset = dbMeta.ofsFirstEvent;
DBEvent *evMeta = NULL, *evSub = NULL;
- dbSub.eventCount = 0; dbSub.ofsFirstEvent = dbSub.ofsLastEvent = dbSub.ofsFirstUnread = dbSub.tsFirstUnread = 0;
dbMeta.eventCount = 0; dbMeta.ofsFirstEvent = dbMeta.ofsLastEvent = dbMeta.ofsFirstUnread = dbMeta.tsFirstUnread = 0;
while (dwOffset != 0) {
@@ -471,33 +462,37 @@ void CDb3Mmap::FillContacts()
dwOffset = p->ofsNext;
}
- #if defined(_DEBUG)
- for (int i = 0; i < arMetas.getCount(); i++) {
- MCONTACT hContact = (MCONTACT)arMetas[i];
- DBCachedContact *ccMeta = m_cache->GetCachedContact(hContact);
- if (ccMeta == NULL)
- continue;
+ DBVARIANT dbv; dbv.type = DBVT_DWORD;
+ for (int i = 0; i < arMetas.getCount(); i++) {
+ MCONTACT hContact = (MCONTACT)arMetas[i];
+ DBCachedContact *ccMeta = m_cache->GetCachedContact(hContact);
+ if (ccMeta == NULL)
+ continue;
- // we don't need it anymore
+ // we don't need it anymore
+ if (!GetContactSetting(hContact, META_PROTO, "MetaID", &dbv)) {
DeleteContactSetting(hContact, META_PROTO, "MetaID");
+ WipeContactHistory((DBContact*)DBRead(ccMeta->dwDriverData, sizeof(DBContact), NULL));
+ }
- for (int k = 0; k < ccMeta->nSubs; k++) {
- // store contact id instead of the old mc number
- DBCONTACTWRITESETTING dbws = { META_PROTO, "ParentMeta" };
- dbws.value.type = DBVT_DWORD;
- dbws.value.dVal = hContact;
- WriteContactSetting(ccMeta->pSubs[k], &dbws);
-
- // wipe out old data from subcontacts
- DeleteContactSetting(ccMeta->pSubs[k], META_PROTO, "ContactNumber");
- DeleteContactSetting(ccMeta->pSubs[k], META_PROTO, "MetaLink");
-
- DBCachedContact *ccSub = m_cache->GetCachedContact(ccMeta->pSubs[k]);
- if (ccSub)
- MetaMergeHistory(ccMeta, ccSub);
+ for (int k = 0; k < ccMeta->nSubs; k++) {
+ // store contact id instead of the old mc number
+ DBCONTACTWRITESETTING dbws = { META_PROTO, "ParentMeta" };
+ dbws.value.type = DBVT_DWORD;
+ dbws.value.dVal = hContact;
+ WriteContactSetting(ccMeta->pSubs[k], &dbws);
+
+ // wipe out old data from subcontacts
+ DeleteContactSetting(ccMeta->pSubs[k], META_PROTO, "ContactNumber");
+ DeleteContactSetting(ccMeta->pSubs[k], META_PROTO, "MetaLink");
+
+ DBCachedContact *ccSub = m_cache->GetCachedContact(ccMeta->pSubs[k]);
+ if (ccSub) {
+ ccSub->parentID = hContact;
+ MetaMergeHistory(ccMeta, ccSub);
}
}
- #endif
+ }
}
DWORD CDb3Mmap::GetContactOffset(MCONTACT contactID)
diff --git a/plugins/Db3x_mmap/src/dbevents.cpp b/plugins/Db3x_mmap/src/dbevents.cpp
index 9a9672f689..3c237c98a4 100644
--- a/plugins/Db3x_mmap/src/dbevents.cpp
+++ b/plugins/Db3x_mmap/src/dbevents.cpp
@@ -365,15 +365,34 @@ STDMETHODIMP_(HANDLE) CDb3Mmap::FindPrevEvent(HANDLE hDbEvent)
}
/////////////////////////////////////////////////////////////////////////////////////////
+// low-level history cleaner
+
+int CDb3Mmap::WipeContactHistory(DBContact *dbc)
+{
+ // drop subContact's history if any
+ for (DWORD dwOffset = dbc->ofsFirstEvent; dwOffset != 0;) {
+ DBEvent *pev = (DBEvent*)DBRead(dwOffset, sizeof(DBEvent), NULL);
+ if (pev->signature != DBEVENT_SIGNATURE) // broken chain, don't touch it
+ return 2;
+
+ DWORD dwNext = pev->ofsNext;
+ DeleteSpace(dwOffset, offsetof(DBEvent, blob) + pev->cbBlob);
+ dwOffset = dwNext;
+ }
+ dbc->eventCount = 0; dbc->ofsFirstEvent = dbc->ofsLastEvent = dbc->ofsFirstUnread = dbc->tsFirstUnread = 0;
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// events convertor for DB_095_1_VERSION
-void CDb3Mmap::ConvertContactEvents(DBContact *cc)
+void CDb3Mmap::ConvertContactEvents(DBContact *dbc)
{
BYTE *pBlob = (PBYTE)mir_alloc(65536);
DWORD ofsPrev = 0;
__try {
- for (DWORD ofsEvent = cc->ofsFirstEvent; ofsEvent != 0;) {
+ for (DWORD ofsEvent = dbc->ofsFirstEvent; ofsEvent != 0;) {
DBEvent_094 pOld = *(DBEvent_094*)DBRead(ofsEvent, sizeof(DBEvent_094), NULL);
if (pOld.signature != DBEVENT_SIGNATURE)
break;
@@ -387,21 +406,21 @@ void CDb3Mmap::ConvertContactEvents(DBContact *cc)
DWORD ofsNew = ReallocSpace(ofsEvent, offsetof(DBEvent_094, blob) + pOld.cbBlob, offsetof(DBEvent, blob) + pOld.cbBlob);
DBEvent *pNew = (DBEvent*)&m_pDbCache[ofsNew];
pNew->signature = pOld.signature;
- pNew->contactID = cc->dwContactID;
+ pNew->contactID = dbc->dwContactID;
memcpy(&pNew->ofsPrev, &pOld.ofsPrev, offsetof(DBEvent_094, blob) - sizeof(DWORD));
memcpy(&pNew->blob, pBlob, pNew->cbBlob);
if (ofsPrev == 0) // first event
- cc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0;
+ dbc->ofsFirstEvent = ofsNew, pNew->ofsPrev = 0;
else {
DBEvent *pPrev = (DBEvent*)&m_pDbCache[ofsPrev];
pPrev->ofsNext = ofsNew, pNew->ofsPrev = ofsPrev;
}
- if (cc->ofsFirstUnread == ofsEvent)
- cc->ofsFirstUnread = ofsNew;
- if (cc->ofsLastEvent == ofsEvent)
- cc->ofsLastEvent = ofsNew;
+ if (dbc->ofsFirstUnread == ofsEvent)
+ dbc->ofsFirstUnread = ofsNew;
+ if (dbc->ofsLastEvent == ofsEvent)
+ dbc->ofsLastEvent = ofsNew;
ofsPrev = ofsNew;
ofsEvent = pNew->ofsNext;
@@ -415,15 +434,15 @@ void CDb3Mmap::ConvertContactEvents(DBContact *cc)
void CDb3Mmap::ConvertEvents()
{
- DBContact cc = *(DBContact*)DBRead(m_dbHeader.ofsUser, sizeof(DBContact), NULL);
- ConvertContactEvents(&cc);
- DBWrite(m_dbHeader.ofsUser, &cc, sizeof(cc));
+ DBContact dbc = *(DBContact*)DBRead(m_dbHeader.ofsUser, sizeof(DBContact), NULL);
+ ConvertContactEvents(&dbc);
+ DBWrite(m_dbHeader.ofsUser, &dbc, sizeof(dbc));
for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) {
- DBContact cc = *(DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL);
- ConvertContactEvents(&cc);
- DBWrite(dwOffset, &cc, sizeof(cc));
- dwOffset = cc.ofsNext;
+ DBContact dbc = *(DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL);
+ ConvertContactEvents(&dbc);
+ DBWrite(dwOffset, &dbc, sizeof(dbc));
+ dwOffset = dbc.ofsNext;
}
FlushViewOfFile(m_pDbCache, 0);
diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h
index 63df6f6a9b..d1e44e56cd 100644
--- a/plugins/Db3x_mmap/src/dbintf.h
+++ b/plugins/Db3x_mmap/src/dbintf.h
@@ -309,6 +309,11 @@ protected:
OBJLIST<ConvertedContact> m_contactsMap;
+ void ConvertContacts(void);
+ void ConvertContactEvents(DBContact *dbc);
+ void ConvertEvents(void);
+ int WipeContactHistory(DBContact *dbc);
+
////////////////////////////////////////////////////////////////////////////
// modules
@@ -352,9 +357,6 @@ protected:
////////////////////////////////////////////////////////////////////////////
// encryption
- void ConvertContacts(void);
- void ConvertContactEvents(DBContact *dbc);
- void ConvertEvents(void);
int InitCrypt(void);
void ToggleEventsEncryption(MCONTACT contactID);
void ToggleSettingsEncryption(MCONTACT contactID);