From 42112cede8ed785b450334f1296f0a94f439c2cb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 21 Jul 2014 18:36:00 +0000 Subject: dbx_mmap: - m_contactsMap became useless and therefore was eliminated; - fix for the metacontacts convertor git-svn-id: http://svn.miranda-ng.org/main/trunk@9906 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db3x_mmap/src/dbcontacts.cpp | 86 ++++++++++++++++++--------- plugins/Db3x_mmap/src/dbintf.cpp | 3 +- plugins/Db3x_mmap/src/dbintf.h | 10 ---- plugins/Db3x_mmap/src/dbtool/contactchain.cpp | 3 - plugins/Db3x_mmap/src/version.h | 2 +- 5 files changed, 61 insertions(+), 43 deletions(-) (limited to 'plugins/Db3x_mmap') diff --git a/plugins/Db3x_mmap/src/dbcontacts.cpp b/plugins/Db3x_mmap/src/dbcontacts.cpp index 44af1cdc95..2fdf598252 100644 --- a/plugins/Db3x_mmap/src/dbcontacts.cpp +++ b/plugins/Db3x_mmap/src/dbcontacts.cpp @@ -298,6 +298,8 @@ BOOL CDb3Mmap::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) return ret; } +///////////////////////////////////////////////////////////////////////////////////////// + BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) { mir_cslock lck(m_csDbAccess); @@ -376,10 +378,22 @@ BOOL CDb3Mmap::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) return ret; } +///////////////////////////////////////////////////////////////////////////////////////// +// initial cycle to fill the contacts' cache + +struct COldMeta +{ + COldMeta(DWORD _id, DBCachedContact *_cc) : + hMetaID(_id), cc(_cc) + {} + + DWORD hMetaID; + DBCachedContact *cc; +}; void CDb3Mmap::FillContacts() { - LIST arMetas(10); + OBJLIST arMetas(10, NumericKeySortT); for (DWORD dwOffset = m_dbHeader.ofsFirstContact; dwOffset != 0;) { DBContact *p = (DBContact*)DBRead(dwOffset, sizeof(DBContact), NULL); @@ -401,17 +415,7 @@ void CDb3Mmap::FillContacts() for (int i = 0; i < cc->nSubs; i++) { char setting[100]; mir_snprintf(setting, sizeof(setting), "Handle%d", i); - MCONTACT hSub = (0 != GetContactSetting(dwContactID, META_PROTO, setting, &dbv)) ? NULL : dbv.dVal; - ConvertedContact *pcc = m_contactsMap.find((ConvertedContact*)&hSub); - if (pcc != NULL) { - hSub = pcc->hNew; - - DBCONTACTWRITESETTING dbws = { META_PROTO, setting }; - dbws.value.type = DBVT_DWORD; - dbws.value.dVal = hSub; - WriteContactSetting(dwContactID, &dbws); - } - cc->pSubs[i] = hSub; + cc->pSubs[i] = (0 != GetContactSetting(dwContactID, META_PROTO, setting, &dbv)) ? NULL : dbv.dVal; } } cc->nDefault = (0 != GetContactSetting(dwContactID, META_PROTO, "Default", &dbv)) ? -1 : dbv.dVal; @@ -419,18 +423,56 @@ void CDb3Mmap::FillContacts() // whether we need conversion or not if (!GetContactSetting(dwContactID, META_PROTO, "MetaID", &dbv)) - arMetas.insert((void*)dwContactID); + arMetas.insert(new COldMeta(dbv.dVal, cc)); dwOffset = p->ofsNext; } + // no need in conversion? quit then + if (arMetas.getCount() == 0) + return; + 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) + for (MCONTACT hh = FindFirstContact(); hh; hh = FindNextContact(hh)) { + if (GetContactSetting(hh, META_PROTO, "MetaLink", &dbv)) + continue; + + COldMeta *p = arMetas.find((COldMeta*)&dbv.dVal); + if (p == NULL) + continue; + + if (GetContactSetting(hh, META_PROTO, "ContactNumber", &dbv)) continue; + DBCONTACTWRITESETTING dbws = { META_PROTO }; + dbws.value.type = DBVT_DWORD; + + DBCachedContact *ccMeta = p->cc; + if (dbv.dVal < ccMeta->nSubs) { + ccMeta->pSubs[dbv.dVal] = hh; + + char setting[100]; + mir_snprintf(setting, sizeof(setting), "Handle%d", dbv.dVal); + dbws.szSetting = setting; + dbws.value.dVal = hh; + WriteContactSetting(ccMeta->contactID, &dbws); + } + + // store contact id instead of the old mc number + dbws.szSetting = "ParentMeta"; + dbws.value.dVal = ccMeta->contactID; + WriteContactSetting(hh, &dbws); + + // wipe out old data from subcontacts + DeleteContactSetting(hh, META_PROTO, "ContactNumber"); + DeleteContactSetting(hh, META_PROTO, "MetaLink"); + } + + for (int i = 0; i < arMetas.getCount(); i++) { + COldMeta &p = arMetas[i]; + DBCachedContact *ccMeta = p.cc; + MCONTACT hContact = ccMeta->contactID; + // we don't need it anymore if (!GetContactSetting(hContact, META_PROTO, "MetaID", &dbv)) { DeleteContactSetting(hContact, META_PROTO, "MetaID"); @@ -438,16 +480,6 @@ void CDb3Mmap::FillContacts() } 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; diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp index 99d0126696..96fee79626 100644 --- a/plugins/Db3x_mmap/src/dbintf.cpp +++ b/plugins/Db3x_mmap/src/dbintf.cpp @@ -52,8 +52,7 @@ CDb3Mmap::CDb3Mmap(const TCHAR *tszFileName, int iMode) : m_dwMaxContactId(1), m_lMods(50, ModCompare), m_lOfs(50, OfsCompare), - m_lResidentSettings(50, stringCompare2), - m_contactsMap(50, NumericKeySortT) + m_lResidentSettings(50, stringCompare2) { m_tszProfileName = mir_tstrdup(tszFileName); InitDbInstance(this); diff --git a/plugins/Db3x_mmap/src/dbintf.h b/plugins/Db3x_mmap/src/dbintf.h index 7765644baf..700fc465b0 100644 --- a/plugins/Db3x_mmap/src/dbintf.h +++ b/plugins/Db3x_mmap/src/dbintf.h @@ -173,14 +173,6 @@ struct DBEvent #include -struct ConvertedContact -{ - ConvertedContact(MCONTACT _old, MCONTACT _new) : - hOld(_old), hNew(_new) {} - - MCONTACT hOld, hNew; -}; - struct CDb3Mmap : public MIDatabase, public MIDatabaseChecker, public MZeroedObject { CDb3Mmap(const TCHAR *tszFileName, int mode); @@ -317,8 +309,6 @@ protected: //////////////////////////////////////////////////////////////////////////// // contacts - OBJLIST m_contactsMap; - int WipeContactHistory(DBContact *dbc); //////////////////////////////////////////////////////////////////////////// diff --git a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp index d149bd0e86..36dc7cf239 100644 --- a/plugins/Db3x_mmap/src/dbtool/contactchain.cpp +++ b/plugins/Db3x_mmap/src/dbtool/contactchain.cpp @@ -72,9 +72,6 @@ LBL_FinishUp: WriteSegment(ofsDestPrevContact + offsetof(DBContact, ofsNext), &ofsDestThis, sizeof(DWORD)); else m_dbHeader.ofsFirstContact = ofsDestThis; - - if (m_dbHeader.version < DB_095_VERSION) - m_contactsMap.insert(new ConvertedContact(ofsThisContact, ofsDestThis)); } else ofsDestThis = ofsThisContact; // needed in event chain worker diff --git a/plugins/Db3x_mmap/src/version.h b/plugins/Db3x_mmap/src/version.h index 3622fa9133..0e20cc7daf 100644 --- a/plugins/Db3x_mmap/src/version.h +++ b/plugins/Db3x_mmap/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 95 #define __RELEASE_NUM 1 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3