summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-05-17 17:45:20 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-05-17 17:45:20 +0300
commit0571f742235a957a59248f466ed9a111d0e9fdde (patch)
treead8bf140d9609ca7ed686ea767aec0d0142011a8 /plugins
parent00cf855c5afebc8ec4c9d95a54b955ca0cb57c20 (diff)
Import: fix for duplicate contacts
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Import/src/import.cpp2
-rw-r--r--plugins/Import/src/patterns.cpp62
2 files changed, 50 insertions, 14 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index 567771fd82..5b6c728eed 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -742,7 +742,7 @@ MCONTACT CImportBatch::ImportContact(MCONTACT hSrc)
wchar_t *pszUniqueID = L"<Unknown>";
DBVARIANT dbv = {};
- if (!myGet(hSrc, cc->szProto, pszUniqueSetting, &dbv)) {
+ if (!myGet(hSrc, cc->szProto, (m_pPattern != nullptr) ? "ID" : pszUniqueSetting, &dbv)) {
// Does the contact already exist?
MCONTACT hDst;
wchar_t id[40];
diff --git a/plugins/Import/src/patterns.cpp b/plugins/Import/src/patterns.cpp
index 91ad72932f..7f40a6eafc 100644
--- a/plugins/Import/src/patterns.cpp
+++ b/plugins/Import/src/patterns.cpp
@@ -127,8 +127,10 @@ void CMPlugin::LoadPattern(const wchar_t *pwszFileName)
class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
{
+ typedef MDatabaseReadonly CSuper;
+
CMStringW m_buf, m_folder;
- MCONTACT m_hCurrContact = 0;
+ MCONTACT m_hCurrContact = INVALID_CONTACT_ID;
HANDLE m_hFile = INVALID_HANDLE_VALUE, m_hMap = 0;
const uint8_t *m_pFile = 0;
int m_iFileVersion = 0, m_iMsgHeaderSize = 0;
@@ -136,6 +138,16 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
std::vector<DWORD> m_events;
std::vector<CMStringW> m_files;
+ bool CheckContact(MCONTACT hContact)
+ {
+ if (hContact != m_hCurrContact) {
+ m_hCurrContact = hContact;
+ if (!Load(m_files[hContact - 1]))
+ return false;
+ }
+ return true;
+ }
+
////////////////////////////////////////////////////////////////////////////////////////
// QHF file format
@@ -150,9 +162,9 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
uint32_t UIDLen = RLWord(pFile); pFile += 2;
char *UIDStr = (char*)_alloca(UIDLen + 2);
if (m_iFileVersion <= 2)
- strncpy_s(UIDStr, UIDLen+2, (char*)pFile, UIDLen);
+ strncpy_s(UIDStr, UIDLen + 2, (char *)pFile, UIDLen);
else
- strncpy_s(UIDStr, UIDLen+2, (char*)pFile, UIDLen+1);
+ strncpy_s(UIDStr, UIDLen + 2, (char *)pFile, UIDLen + 1);
pFile += UIDLen;
uint32_t NickLen = RLWord(pFile); pFile += 2;
@@ -163,6 +175,18 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
strncpy_s(NickStr, NickLen + 2, (char*)pFile, NickLen + 1);
pFile += NickLen;
+ DBCONTACTWRITESETTING dbcws = {};
+ dbcws.szModule = "Pattern";
+ dbcws.value.type = DBVT_UTF8;
+
+ dbcws.szSetting = "ID";
+ dbcws.value.pszVal = UIDStr;
+ WriteContactSetting(m_hCurrContact, &dbcws);
+
+ dbcws.szSetting = "Nick";
+ dbcws.value.pszVal = NickStr;
+ WriteContactSetting(m_hCurrContact, &dbcws);
+
uint32_t iHeaderSize = 0x30 + NickLen + UIDLen;
if (fsz != iSize - iHeaderSize)
fsz = iSize - iHeaderSize;
@@ -333,10 +357,6 @@ public:
if (m_files.empty())
return EGROKPRF_CANTREAD;
- m_hCurrContact = 1;
- if (!Load(m_files[0]))
- return EGROKPRF_CANTREAD;
-
return EGROKPRF_NOERROR;
}
@@ -364,6 +384,24 @@ public:
return (LONG)m_files.size();
}
+ STDMETHODIMP_(MCONTACT) FindFirstContact(const char *szProto) override
+ {
+ MCONTACT ret = CSuper::FindFirstContact(szProto);
+ if (ret != 0)
+ if (!CheckContact(ret))
+ return 0;
+ return ret;
+ }
+
+ STDMETHODIMP_(MCONTACT) FindNextContact(MCONTACT contactID, const char *szProto) override
+ {
+ MCONTACT ret = CSuper::FindNextContact(contactID, szProto);
+ if (ret != 0)
+ if (!CheckContact(ret))
+ return 0;
+ return ret;
+ }
+
STDMETHODIMP_(LONG) GetEventCount(MCONTACT) override
{
return (LONG)m_events.size();
@@ -560,9 +598,8 @@ public:
if (hContact == 0)
return 0;
- if (hContact != m_hCurrContact)
- if (!Load(m_files[hContact-1]))
- return 0;
+ if (!CheckContact(hContact))
+ return 0;
return m_events.size() > 0 ? 1 : 0;
}
@@ -581,9 +618,8 @@ public:
if (hContact == 0)
return 0;
- if (hContact != m_hCurrContact)
- if (!Load(m_files[hContact - 1]))
- return 0;
+ if (!CheckContact(hContact))
+ return 0;
return m_events.size() > 0 ? (MEVENT)m_events.size() : 0;
}