summaryrefslogtreecommitdiff
path: root/plugins/Import/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Import/src')
-rw-r--r--plugins/Import/src/import.cpp232
-rw-r--r--plugins/Import/src/main.cpp28
-rw-r--r--plugins/Import/src/miranda.cpp52
-rw-r--r--plugins/Import/src/patterns.cpp53
-rw-r--r--plugins/Import/src/progress.cpp4
-rw-r--r--plugins/Import/src/stdafx.h85
-rw-r--r--plugins/Import/src/ui.cpp35
-rw-r--r--plugins/Import/src/wizard.cpp3
8 files changed, 263 insertions, 229 deletions
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp
index e57a839b56..567771fd82 100644
--- a/plugins/Import/src/import.cpp
+++ b/plugins/Import/src/import.cpp
@@ -22,23 +22,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-struct AccountMap
+static bool CompareDb(DBVARIANT &dbv1, DBVARIANT &dbv2)
{
- AccountMap(const char *_src, int _origIdx, const wchar_t *_srcName) :
- szSrcAcc(mir_strdup(_src)),
- iSrcIndex(_origIdx),
- tszSrcName(mir_wstrdup(_srcName)),
- pa(nullptr)
- {}
-
- ~AccountMap() {}
+ if (dbv1.type == dbv2.type) {
+ switch (dbv1.type) {
+ case DBVT_DWORD:
+ return dbv1.dVal == dbv2.dVal;
- ptrA szSrcAcc, szBaseProto;
- ptrW tszSrcName;
- int iSrcIndex;
- int iOrder;
- PROTOACCOUNT *pa;
-};
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ return 0 == mir_strcmp(dbv1.pszVal, dbv2.pszVal);
+ }
+ }
+ return false;
+}
static int CompareAccs(const AccountMap *p1, const AccountMap *p2)
{
@@ -52,73 +49,53 @@ static int CompareAccByIds(const AccountMap *p1, const AccountMap *p2)
/////////////////////////////////////////////////////////////////////////////////////////
-struct ContactMap
+CImportBatch::CImportBatch() :
+ m_accounts(5, CompareAccs),
+ m_contacts(50, NumericKeySortT),
+ m_metas(10)
{
- ContactMap(MCONTACT _src, MCONTACT _dst) :
- srcID(_src),
- dstID(_dst)
- {}
-
- MCONTACT srcID, dstID;
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static OBJLIST<AccountMap> arAccountMap(5, CompareAccs);
-static OBJLIST<ContactMap> arContactMap(50, NumericKeySortT);
-static LIST<DBCachedContact> arMetas(10);
-
-/////////////////////////////////////////////////////////////////////////////////////////
-// local data
-
-static DWORD nDupes, nContactsCount, nMessagesCount, nGroupsCount, nSkippedEvents, nSkippedContacts;
-static MDatabaseCommon *srcDb, *dstDb;
+}
/////////////////////////////////////////////////////////////////////////////////////////
-static bool CompareDb(DBVARIANT &dbv1, DBVARIANT &dbv2)
-{
- if (dbv1.type == dbv2.type) {
- switch (dbv1.type) {
- case DBVT_DWORD:
- return dbv1.dVal == dbv2.dVal;
-
- case DBVT_ASCIIZ:
- case DBVT_UTF8:
- return 0 == mir_strcmp(dbv1.pszVal, dbv2.pszVal);
- }
- }
- return false;
-}
-
-static int myGet(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
+int CImportBatch::myGet(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
{
dbv->type = 0;
return srcDb->GetContactSetting(hContact, szModule, szSetting, dbv);
}
-static int myGetD(MCONTACT hContact, const char *szModule, const char *szSetting, int iDefault)
+int CImportBatch::myGetD(MCONTACT hContact, const char *szModule, const char *szSetting, int iDefault)
{
DBVARIANT dbv = { DBVT_DWORD };
return srcDb->GetContactSetting(hContact, szModule, szSetting, &dbv) ? iDefault : dbv.dVal;
}
-static wchar_t* myGetWs(MCONTACT hContact, const char *szModule, const char *szSetting)
-{
- DBVARIANT dbv = { DBVT_WCHAR };
- return srcDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pwszVal;
-}
-
-static BOOL myGetS(MCONTACT hContact, const char *szModule, const char *szSetting, char *dest)
+BOOL CImportBatch::myGetS(MCONTACT hContact, const char *szModule, const char *szSetting, char *dest)
{
DBVARIANT dbv = { DBVT_ASCIIZ };
dbv.pszVal = dest; dbv.cchVal = 100;
return srcDb->GetContactSettingStatic(hContact, szModule, szSetting, &dbv);
}
+wchar_t* CImportBatch::myGetWs(MCONTACT hContact, const char *szModule, const char *szSetting)
+{
+ DBVARIANT dbv = { DBVT_WCHAR };
+ return srcDb->GetContactSettingStr(hContact, szModule, szSetting, &dbv) ? nullptr : dbv.pwszVal;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
-static MCONTACT HContactFromChatID(const char *pszProtoName, const wchar_t *pszChatID)
+MCONTACT CImportBatch::HContactFromID(const char *pszProtoName, const char *pszSetting, wchar_t *pwszID)
+{
+ for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName)) {
+ ptrW id(db_get_wsa(hContact, pszProtoName, pszSetting));
+ if (!mir_wstrcmp(pwszID, id))
+ return hContact;
+ }
+ return INVALID_CONTACT_ID;
+}
+
+MCONTACT CImportBatch::HContactFromChatID(const char *pszProtoName, const wchar_t *pszChatID)
{
for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName)) {
if (!db_get_b(hContact, pszProtoName, "ChatRoom", 0))
@@ -132,7 +109,7 @@ static MCONTACT HContactFromChatID(const char *pszProtoName, const wchar_t *pszC
return INVALID_CONTACT_ID;
}
-static MCONTACT HContactFromNumericID(const char *pszProtoName, const char *pszSetting, DWORD dwID)
+MCONTACT CImportBatch::HContactFromNumericID(const char *pszProtoName, const char *pszSetting, DWORD dwID)
{
for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName))
if (db_get_dw(hContact, pszProtoName, pszSetting, 0) == dwID)
@@ -141,16 +118,6 @@ static MCONTACT HContactFromNumericID(const char *pszProtoName, const char *pszS
return INVALID_CONTACT_ID;
}
-static MCONTACT HContactFromID(const char *pszProtoName, const char *pszSetting, wchar_t *pwszID)
-{
- for (MCONTACT hContact = dstDb->FindFirstContact(pszProtoName); hContact; hContact = dstDb->FindNextContact(hContact, pszProtoName)) {
- ptrW id(db_get_wsa(hContact, pszProtoName, pszSetting));
- if (!mir_wstrcmp(pwszID, id))
- return hContact;
- }
- return INVALID_CONTACT_ID;
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
static int CopySettingsEnum(const char *szSetting, void *param)
@@ -160,7 +127,7 @@ static int CopySettingsEnum(const char *szSetting, void *param)
return 0;
}
-void CopySettings(MCONTACT srcID, const char *szSrcModule, MCONTACT dstID, const char *szDstModule)
+void CImportBatch::CopySettings(MCONTACT srcID, const char *szSrcModule, MCONTACT dstID, const char *szDstModule)
{
LIST<char> arSettings(50);
srcDb->EnumContactSettings(srcID, CopySettingsEnum, szSrcModule, &arSettings);
@@ -267,7 +234,7 @@ static LRESULT CALLBACK ListWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
return mir_callNextSubclass(hwnd, ListWndProc, uMsg, wParam, lParam);
}
-static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM)
{
switch (uMsg) {
case WM_INITDIALOG:
@@ -286,10 +253,12 @@ static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
col.pszText = TranslateT("New account");
ListView_InsertColumn(hwndList, 1, &col);
+ auto &accs = g_pBatch->AccountsMap();
+
LVITEM lvi = { 0 };
lvi.mask = LVIF_TEXT | LVIF_PARAM;
- for (int i = 0; i < arAccountMap.getCount(); i++) {
- AccountMap &p = arAccountMap[i];
+ for (int i = 0; i < accs.getCount(); i++) {
+ AccountMap &p = accs[i];
lvi.iItem = i;
lvi.iSubItem = 0;
lvi.pszText = p.tszSrcName;
@@ -325,17 +294,6 @@ static INT_PTR CALLBACK AccountsMatcherProc(HWND hwndDlg, UINT uMsg, WPARAM wPar
case WM_DESTROY:
g_hwndAccMerge = nullptr;
break;
-
- case WM_NOTIFY:
- LPNMHDR hdr = (LPNMHDR)lParam;
- if (hdr->idFrom != IDC_LIST)
- break;
-
- switch (hdr->code) {
- case LVN_ITEMCHANGED:
- case LVN_ITEMACTIVATE:
- ;
- }
}
return FALSE;
@@ -348,9 +306,9 @@ static char* newStr(const char *s)
return (s == nullptr) ? nullptr : mir_strcpy(new char[mir_strlen(s) + 1], s);
}
-static bool FindDestAccount(const char *szProto)
+bool CImportBatch::FindDestAccount(const char *szProto)
{
- for (auto &pam : arAccountMap) {
+ for (auto &pam : m_accounts) {
if (pam->pa == nullptr)
continue;
@@ -361,7 +319,7 @@ static bool FindDestAccount(const char *szProto)
return false;
}
-static PROTOACCOUNT* FindMyAccount(const char *szProto, const char *szBaseProto, const wchar_t *ptszName, bool bStrict)
+PROTOACCOUNT* CImportBatch::FindMyAccount(const char *szProto, const char *szBaseProto, const wchar_t *ptszName, bool bStrict)
{
PROTOACCOUNT *pProto = nullptr;
for (auto &pa : Accounts()) {
@@ -405,10 +363,10 @@ static PROTOACCOUNT* FindMyAccount(const char *szProto, const char *szBaseProto,
return (bStrict) ? nullptr : pProto;
}
-bool ImportAccounts(OBJLIST<char> &arSkippedModules)
+bool CImportBatch::ImportAccounts(OBJLIST<char> &arSkippedModules)
{
bool bNeedManualMerge = false;
- if (g_pActivePattern == nullptr) {
+ if (m_pPattern == nullptr) {
int protoCount = myGetD(NULL, "Protocols", "ProtoCount", 0);
for (int i = 0; i < protoCount; i++) {
@@ -420,7 +378,7 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules)
itoa(800 + i, szSetting, 10);
ptrW tszName(myGetWs(NULL, "Protocols", szSetting));
AccountMap* pNew = new AccountMap(szProto, i, tszName);
- arAccountMap.insert(pNew);
+ m_accounts.insert(pNew);
itoa(200 + i, szSetting, 10);
pNew->iOrder = myGetD(NULL, "Protocols", szSetting, 0);
@@ -434,7 +392,7 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules)
pNew->szBaseProto = mir_strdup(szBaseProto);
// try the precise match first
- PROTOACCOUNT* pa = FindMyAccount(szProto, szBaseProto, tszName, true);
+ PROTOACCOUNT *pa = FindMyAccount(szProto, szBaseProto, tszName, true);
if (pa) {
pNew->pa = pa;
continue;
@@ -448,10 +406,12 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules)
}
}
else {
- AccountMap* pNew = new AccountMap("Pattern", 0, g_pActivePattern->wszName);
- arAccountMap.insert(pNew);
+ AccountMap *pNew = new AccountMap("Pattern", 0, m_pPattern->wszName);
+ if (m_hContact)
+ pNew->pa = Proto_GetAccount(GetContactProto(m_hContact));
+ m_accounts.insert(pNew);
- bNeedManualMerge = true;
+ bNeedManualMerge = pNew->pa == nullptr;
}
// all accounts to be converted automatically, no need to raise a dialog
@@ -459,10 +419,10 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules)
if (DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_ACCMERGE), nullptr, AccountsMatcherProc) != IDOK)
return false;
- bool bImportSysAll = (g_iImportOptions & IOPT_SYS_SETTINGS) != 0;
+ bool bImportSysAll = (m_iOptions & IOPT_SYS_SETTINGS) != 0;
- LIST<AccountMap> arIndexedMap(arAccountMap.getCount(), CompareAccByIds);
- for (auto &it : arAccountMap)
+ LIST<AccountMap> arIndexedMap(m_accounts.getCount(), CompareAccByIds);
+ for (auto &it : m_accounts)
arIndexedMap.insert(it);
for (auto &p : arIndexedMap) {
@@ -523,12 +483,12 @@ bool ImportAccounts(OBJLIST<char> &arSkippedModules)
/////////////////////////////////////////////////////////////////////////////////////////
-static MCONTACT MapContact(MCONTACT hSrc)
+MCONTACT CImportBatch::MapContact(MCONTACT hSrc)
{
- if (g_hImportContact != 0 && hSrc == 1)
- return g_hImportContact;
+ if (m_hContact != 0 && hSrc == 1)
+ return m_hContact;
- ContactMap *pDestContact = arContactMap.find((ContactMap*)&hSrc);
+ ContactMap *pDestContact = m_contacts.find((ContactMap*)&hSrc);
return (pDestContact == nullptr) ? INVALID_CONTACT_ID : pDestContact->dstID;
}
@@ -547,9 +507,9 @@ int ModulesEnumProc(const char *szModuleName, void *pParam)
ImportContactData *icd = (ImportContactData*)pParam;
if (!mir_strcmp(icd->szSrcProto, szModuleName)) {
if (!icd->bSkipProto)
- CopySettings(icd->from, szModuleName, icd->to, icd->szDstProto);
+ g_pBatch->CopySettings(icd->from, szModuleName, icd->to, icd->szDstProto);
}
- else CopySettings(icd->from, szModuleName, icd->to, szModuleName);
+ else g_pBatch->CopySettings(icd->from, szModuleName, icd->to, szModuleName);
return 0;
}
@@ -570,13 +530,13 @@ struct MImportGroup
static int ImportGroup(const char* szSettingName, void *param)
{
OBJLIST<MImportGroup> *pArray = (OBJLIST<MImportGroup>*)param;
- wchar_t *wszGroupName = myGetWs(NULL, "CListGroups", szSettingName);
+ wchar_t *wszGroupName = g_pBatch->myGetWs(NULL, "CListGroups", szSettingName);
if (wszGroupName != nullptr)
pArray->insert(new MImportGroup(atoi(szSettingName), wszGroupName));
return 0;
}
-static int ImportGroups()
+int CImportBatch::ImportGroups()
{
OBJLIST<MImportGroup> arGroups(10, NumericKeySortT);
srcDb->EnumContactSettings(NULL, ImportGroup, "CListGroups", &arGroups);
@@ -594,7 +554,7 @@ static int ImportGroups()
/////////////////////////////////////////////////////////////////////////////////////////
-DBCachedContact* FindDestMeta(DBCachedContact *ccSrc)
+DBCachedContact* CImportBatch::FindDestMeta(DBCachedContact *ccSrc)
{
for (MCONTACT hMeta = dstDb->FindFirstContact(META_PROTO); hMeta != 0; hMeta = dstDb->FindNextContact(hMeta, META_PROTO)) {
DBCachedContact *cc = dstDb->getCache()->GetCachedContact(hMeta);
@@ -615,7 +575,7 @@ DBCachedContact* FindDestMeta(DBCachedContact *ccSrc)
return nullptr;
}
-MCONTACT FindExistingMeta(DBCachedContact *ccSrc)
+MCONTACT CImportBatch::FindExistingMeta(DBCachedContact *ccSrc)
{
MCONTACT hResult = INVALID_CONTACT_ID;
@@ -638,7 +598,7 @@ MCONTACT FindExistingMeta(DBCachedContact *ccSrc)
return hResult;
}
-void ImportMeta(DBCachedContact *ccSrc)
+void CImportBatch::ImportMeta(DBCachedContact *ccSrc)
{
if (!ccSrc->IsMeta() || !ccSrc->nSubs || !ccSrc->pSubs)
return;
@@ -722,12 +682,12 @@ void ImportMeta(DBCachedContact *ccSrc)
ImportContactData icd = { ccSrc->contactID, ccDst->contactID, META_PROTO, META_PROTO, true };
db_enum_modules(ModulesEnumProc, &icd);
- arContactMap.insert(new ContactMap(ccSrc->contactID, ccDst->contactID));
+ m_contacts.insert(new ContactMap(ccSrc->contactID, ccDst->contactID));
}
/////////////////////////////////////////////////////////////////////////////////////////
-static MCONTACT ImportContact(MCONTACT hSrc)
+MCONTACT CImportBatch::ImportContact(MCONTACT hSrc)
{
// Check what protocol this contact belongs to
DBCachedContact *cc = srcDb->getCache()->GetCachedContact(hSrc);
@@ -737,13 +697,13 @@ static MCONTACT ImportContact(MCONTACT hSrc)
}
if (cc->IsMeta()) {
- arMetas.insert(cc);
+ m_metas.insert(cc);
return 0;
}
const char *szSrcModuleName, *szDstModuleName;
{
- AccountMap *pda = arAccountMap.find((AccountMap*)&cc->szProto);
+ AccountMap *pda = m_accounts.find((AccountMap*)&cc->szProto);
if (pda == nullptr || pda->pa == nullptr) {
// it might be a virtual protocol not included into the general account map
PROTOACCOUNT *pa = Proto_GetAccount(cc->szProto);
@@ -816,7 +776,7 @@ static MCONTACT ImportContact(MCONTACT hSrc)
if (hDst != INVALID_CONTACT_ID) {
AddMessage(LPGENW("Skipping duplicate %S contact %s"), cc->szProto, pszUniqueID);
srcDb->FreeVariant(&dbv);
- arContactMap.insert(new ContactMap(hSrc, hDst));
+ m_contacts.insert(new ContactMap(hSrc, hDst));
return 0;
}
}
@@ -852,7 +812,7 @@ static MCONTACT ImportContact(MCONTACT hSrc)
if (bIsChat)
db_set_b(hDst, szDstModuleName, "ChatRoom", 1);
- arContactMap.insert(new ContactMap(hSrc, hDst));
+ m_contacts.insert(new ContactMap(hSrc, hDst));
// also copy settings
ImportContactData icd = { hSrc, hDst, szSrcModuleName, szDstModuleName, false };
@@ -867,14 +827,14 @@ static int CopySystemSettings(const char *szModuleName, void *param)
{
LIST<char> *arSkippedAccs = (LIST<char>*)param;
if (!arSkippedAccs->find((char*)szModuleName))
- CopySettings(NULL, szModuleName, NULL, szModuleName);
+ g_pBatch->CopySettings(NULL, szModuleName, NULL, szModuleName);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// contact's history import
-static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoCount)
+void CImportBatch::ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoCount)
{
MCONTACT hDst;
bool bIsMeta = false;
@@ -950,7 +910,7 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC
if (!bSkipThis) {
bool bIsSent = (dbei.flags & DBEF_SENT) != 0;
- if (dbei.timestamp < (DWORD)dwSinceDate)
+ if (dbei.timestamp < (DWORD)m_dwSinceDate)
bSkipThis = true;
if (!bSkipThis) {
@@ -958,20 +918,20 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC
bSkipThis = 1;
switch (dbei.eventType) {
case EVENTTYPE_MESSAGE:
- if ((bIsSent ? IOPT_MSGSENT : IOPT_MSGRECV) & g_iImportOptions)
+ if ((bIsSent ? IOPT_MSGSENT : IOPT_MSGRECV) & m_iOptions)
bSkipThis = false;
break;
case EVENTTYPE_FILE:
- if ((bIsSent ? IOPT_FILESENT : IOPT_FILERECV) & g_iImportOptions)
+ if ((bIsSent ? IOPT_FILESENT : IOPT_FILERECV) & m_iOptions)
bSkipThis = false;
break;
default:
- if ((bIsSent ? IOPT_OTHERSENT : IOPT_OTHERRECV) & g_iImportOptions)
+ if ((bIsSent ? IOPT_OTHERSENT : IOPT_OTHERRECV) & m_iOptions)
bSkipThis = false;
break;
}
}
- else if (!(g_iImportOptions & IOPT_SYSTEM))
+ else if (!(m_iOptions & IOPT_SYSTEM))
bSkipThis = true;
}
@@ -983,7 +943,7 @@ static void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoC
continue;
// check for duplicate entries
- if ((g_iImportOptions & IOPT_CHECKDUPS) != 0 && IsDuplicateEvent(hDst, dbei)) {
+ if ((m_iOptions & IOPT_CHECKDUPS) != 0 && IsDuplicateEvent(hDst, dbei)) {
nDupes++;
continue;
}
@@ -1025,7 +985,7 @@ static int CompareModules(const char *p1, const char *p2)
return mir_strcmpi(p1, p2);
}
-void MirandaImport()
+void CImportBatch::DoImport()
{
if ((dstDb = (MDatabaseCommon*)db_get_current()) == nullptr) {
AddMessage(LPGENW("Error retrieving current profile, exiting."));
@@ -1033,8 +993,8 @@ void MirandaImport()
}
DATABASELINK *dblink;
- if (g_pActivePattern == nullptr) {
- dblink = FindDatabasePlugin(g_wszImportFile);
+ if (m_pPattern == nullptr) {
+ dblink = FindDatabasePlugin(m_wszFileName);
if (dblink == nullptr) {
AddMessage(LPGENW("There's no database driver to open the input file, exiting."));
return;
@@ -1042,7 +1002,7 @@ void MirandaImport()
}
else dblink = &g_patternDbLink;
- if ((srcDb = dblink->Load(g_wszImportFile, TRUE)) == nullptr) {
+ if ((srcDb = dblink->Load(m_wszFileName, TRUE)) == nullptr) {
AddMessage(LPGENW("Error loading source file, exiting."));
return;
}
@@ -1075,12 +1035,12 @@ void MirandaImport()
}
// copy system settings if needed
- if (g_iImportOptions & IOPT_SYS_SETTINGS)
+ if (m_iOptions & IOPT_SYS_SETTINGS)
srcDb->EnumModuleNames(CopySystemSettings, &arSkippedAccs);
arSkippedAccs.destroy();
// Import Groups
- if (g_iImportOptions & IOPT_GROUPS) {
+ if (m_iOptions & IOPT_GROUPS) {
AddMessage(LPGENW("Importing groups."));
nGroupsCount = ImportGroups();
if (nGroupsCount == -1)
@@ -1091,7 +1051,7 @@ void MirandaImport()
// End of Import Groups
// Import Contacts
- if (g_iImportOptions & IOPT_CONTACTS) {
+ if (m_iOptions & IOPT_CONTACTS) {
AddMessage(LPGENW("Importing contacts."));
int i = 1;
MCONTACT hContact = srcDb->FindFirstContact();
@@ -1113,7 +1073,7 @@ void MirandaImport()
hContact = srcDb->FindNextContact(hContact);
}
- for (auto &it : arMetas)
+ for (auto &it : m_metas)
ImportMeta(it);
}
else AddMessage(LPGENW("Skipping new contacts import."));
@@ -1121,7 +1081,7 @@ void MirandaImport()
// End of Import Contacts
// Import NULL contact message chain
- if (g_iImportOptions & IOPT_SYSTEM) {
+ if (m_iOptions & IOPT_SYSTEM) {
AddMessage(LPGENW("Importing system history."));
int protoCount;
@@ -1135,7 +1095,7 @@ void MirandaImport()
AddMessage(L"");
// Import other contact messages
- if (g_iImportOptions & IOPT_HISTORY) {
+ if (m_iOptions & IOPT_HISTORY) {
AddMessage(LPGENW("Importing history."));
MCONTACT hContact = srcDb->FindFirstContact();
for (int i = 1; hContact != NULL; i++) {
@@ -1170,8 +1130,4 @@ void MirandaImport()
if (nDupes || nSkippedEvents)
AddMessage(LPGENW("Skipped %d duplicates and %d filtered events."), nDupes, nSkippedEvents);
-
- arMetas.destroy();
- arAccountMap.destroy();
- arContactMap.destroy();
}
diff --git a/plugins/Import/src/main.cpp b/plugins/Import/src/main.cpp
index 812c5aaa5d..c9112d7388 100644
--- a/plugins/Import/src/main.cpp
+++ b/plugins/Import/src/main.cpp
@@ -22,14 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-int g_iImportOptions;
-MCONTACT g_hImportContact;
-CImportPattern *g_pActivePattern;
-
-bool g_bServiceMode = false, g_bSendQuit = false;
HWND g_hwndWizard, g_hwndAccMerge;
-
+bool g_bServiceMode = false, g_bSendQuit = false;
CMPlugin g_plugin;
+CImportBatch *g_pBatch;
/////////////////////////////////////////////////////////////////////////////////////////
@@ -101,8 +97,9 @@ static INT_PTR ServiceMode(WPARAM wParam, LPARAM)
if (wParam == 1) {
ptrW wszFullName(Utils_ReplaceVarsW(L"%miranda_userdata%\\%miranda_profilename%.dat.bak"));
if (!_waccess(wszFullName, 0)) {
- g_iImportOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE;
- wcsncpy_s(g_wszImportFile, MAX_PATH, wszFullName, _TRUNCATE);
+ g_pBatch = new CImportBatch();
+ g_pBatch->m_iOptions = IOPT_ADDUNKNOWN + IOPT_COMPLETE;
+ wcsncpy_s(g_pBatch->m_wszFileName, MAX_PATH, wszFullName, _TRUNCATE);
RunWizard(new CProgressPageDlg(), true);
}
return SERVICE_CONTINUE;
@@ -117,10 +114,9 @@ static INT_PTR ServiceMode(WPARAM wParam, LPARAM)
static INT_PTR CustomImport(WPARAM wParam, LPARAM)
{
MImportOptions *opts = (MImportOptions*)wParam;
- wcsncpy_s(g_wszImportFile, MAX_PATH, opts->pwszFileName, _TRUNCATE);
- g_iImportOptions = opts->dwFlags;
- g_hImportContact = 0;
- g_pActivePattern = nullptr;
+ g_pBatch = new CImportBatch();
+ wcsncpy_s(g_pBatch->m_wszFileName, MAX_PATH, opts->pwszFileName, _TRUNCATE);
+ g_pBatch->m_iOptions = opts->dwFlags;
return RunWizard(new CProgressPageDlg(), true);
}
@@ -130,7 +126,11 @@ static INT_PTR ImportCommand(WPARAM, LPARAM)
SetForegroundWindow(g_hwndWizard);
SetFocus(g_hwndWizard);
}
- else RunWizard(new CIntroPageDlg(), false);
+ else {
+ // no default options, lauch the dialog
+ g_pBatch = new CImportBatch();
+ RunWizard(new CIntroPageDlg(), false);
+ }
return 0;
}
@@ -144,7 +144,7 @@ int CMPlugin::Load()
RegisterIcons();
HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
- HookEvent(ME_SYSTEM_OKTOEXIT, OnExit);
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, OnExit);
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(icex);
diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp
index 9ab373832e..0aa2355aee 100644
--- a/plugins/Import/src/miranda.cpp
+++ b/plugins/Import/src/miranda.cpp
@@ -22,10 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-time_t dwSinceDate = 0;
-
-wchar_t g_wszImportFile[MAX_PATH];
-
//=======================================================================================
// Profile selection dialog
@@ -98,7 +94,7 @@ void CMirandaPageDlg::OnNext()
MessageBox(m_hwnd, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK);
return;
}
- mir_wstrcpy(g_wszImportFile, filename);
+ mir_wstrcpy(g_pBatch->m_wszFileName, filename);
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaOptionsPageDlg());
}
@@ -121,7 +117,7 @@ void CMirandaPageDlg::onClick_Other(CCtrlButton*)
}
else {
mir_snwprintf(ext, L"*.%s", g_plugin.m_patterns[m_iFileType - 1].wszExt.c_str());
- pwszName = g_pActivePattern->wszName;
+ pwszName = g_pBatch->m_pPattern->wszName;
}
mir_snwprintf(text, L"%s (%s)%c%s%c%s (*.*)%c*.*%c%c", pwszName, ext, 0, ext, 0, TranslateT("All Files"), 0, 0, 0);
@@ -168,7 +164,7 @@ void CMirandaPageDlg::onClick_Path(CCtrlButton*)
// find appropriate files and list them
wchar_t searchspec[MAX_PATH];
- mir_snwprintf(searchspec, L"%s\\*.%s", str, g_pActivePattern->wszExt.c_str());
+ mir_snwprintf(searchspec, L"%s\\*.%s", str, g_pBatch->m_pPattern->wszExt.c_str());
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(searchspec, &fd);
if (hFind != INVALID_HANDLE_VALUE) {
@@ -194,12 +190,12 @@ void CMirandaPageDlg::onChange_Pattern(CCtrlCombo*)
// standard import for Miranda
m_iFileType = m_cmbFileType.GetItemData(iCur);
if (m_iFileType == -1) {
- g_pActivePattern = nullptr;
+ g_pBatch->m_pPattern = nullptr;
btnPath.Hide();
}
// custom pattern import
else {
- g_pActivePattern = &g_plugin.m_patterns[m_iFileType-1];
+ g_pBatch->m_pPattern = &g_plugin.m_patterns[m_iFileType-1];
btnPath.Show();
}
}
@@ -251,19 +247,19 @@ void CMirandaOptionsPageDlg::OnNext()
int iFlags = chkDups.IsChecked() ? IOPT_CHECKDUPS : 0;
if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_COMPLETE)) {
- g_iImportOptions = IOPT_ADDUNKNOWN | IOPT_COMPLETE | iFlags;
+ g_pBatch->m_iOptions = IOPT_ADDUNKNOWN | IOPT_COMPLETE | iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_ALL)) {
- g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | iFlags;
+ g_pBatch->m_iOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CONTACTS)) {
- g_iImportOptions = IOPT_CONTACTS;
+ g_pBatch->m_iOptions = IOPT_CONTACTS;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CUSTOM)) {
- g_iImportOptions = iFlags;
+ g_pBatch->m_iOptions = iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_ADVOPTIONS, (LPARAM)new CMirandaAdvOptionsPageDlg());
}
}
@@ -297,8 +293,8 @@ CMirandaAdvOptionsPageDlg::CMirandaAdvOptionsPageDlg() :
bool CMirandaAdvOptionsPageDlg::OnInitDialog()
{
- dwSinceDate = g_plugin.getDword("ImportSinceTS", time(0));
- struct tm *TM = localtime(&dwSinceDate);
+ g_pBatch->m_dwSinceDate = g_plugin.getDword("ImportSinceTS", time(0));
+ struct tm *TM = localtime(&g_pBatch->m_dwSinceDate);
SYSTEMTIME ST = { 0 };
ST.wYear = TM->tm_year + 1900;
@@ -316,31 +312,31 @@ void CMirandaAdvOptionsPageDlg::onClick_Back(CCtrlButton*)
void CMirandaAdvOptionsPageDlg::OnNext()
{
// clear all another flags but duplicates
- g_iImportOptions &= IOPT_CHECKDUPS;
+ g_pBatch->m_iOptions &= IOPT_CHECKDUPS;
if (IsDlgButtonChecked(m_hwnd, IDC_CONTACTS))
- g_iImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
+ g_pBatch->m_iOptions |= IOPT_CONTACTS | IOPT_GROUPS;
if (IsDlgButtonChecked(m_hwnd, IDC_SYSTEM))
- g_iImportOptions |= IOPT_SYSTEM;
+ g_pBatch->m_iOptions |= IOPT_SYSTEM;
// incoming
if (IsDlgButtonChecked(m_hwnd, IDC_IN_MSG))
- g_iImportOptions |= IOPT_MSGRECV;
+ g_pBatch->m_iOptions |= IOPT_MSGRECV;
if (IsDlgButtonChecked(m_hwnd, IDC_IN_FT))
- g_iImportOptions |= IOPT_FILERECV;
+ g_pBatch->m_iOptions |= IOPT_FILERECV;
if (IsDlgButtonChecked(m_hwnd, IDC_IN_OTHER))
- g_iImportOptions |= IOPT_OTHERRECV;
+ g_pBatch->m_iOptions |= IOPT_OTHERRECV;
// outgoing
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_MSG))
- g_iImportOptions |= IOPT_MSGSENT;
+ g_pBatch->m_iOptions |= IOPT_MSGSENT;
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_FT))
- g_iImportOptions |= IOPT_FILESENT;
+ g_pBatch->m_iOptions |= IOPT_FILESENT;
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_OTHER))
- g_iImportOptions |= IOPT_OTHERSENT;
+ g_pBatch->m_iOptions |= IOPT_OTHERSENT;
// since date
- dwSinceDate = 0;
+ g_pBatch->m_dwSinceDate = 0;
if (chkSince.IsChecked()) {
SYSTEMTIME ST = { 0 };
@@ -352,13 +348,13 @@ void CMirandaAdvOptionsPageDlg::OnNext()
TM.tm_mon = ST.wMonth - 1;
TM.tm_year = ST.wYear - 1900;
- dwSinceDate = mktime(&TM);
+ g_pBatch->m_dwSinceDate = mktime(&TM);
- g_plugin.setDword("ImportSinceTS", dwSinceDate);
+ g_plugin.setDword("ImportSinceTS", g_pBatch->m_dwSinceDate);
}
}
- if (g_iImportOptions)
+ if (g_pBatch->m_iOptions)
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CProgressPageDlg());
}
diff --git a/plugins/Import/src/patterns.cpp b/plugins/Import/src/patterns.cpp
index 15fcf4d725..91ad72932f 100644
--- a/plugins/Import/src/patterns.cpp
+++ b/plugins/Import/src/patterns.cpp
@@ -181,7 +181,9 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
bool LoadTextFile(const uint8_t *pFile)
{
- switch (g_pActivePattern->iCodePage) {
+ auto *pPattern = g_pBatch->m_pPattern;
+
+ switch (pPattern->iCodePage) {
case CP_UTF8:
m_buf = mir_utf8decodeW((char*)pFile);
break;
@@ -189,7 +191,7 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
m_buf = mir_wstrdup((wchar_t*)pFile);
break;
default:
- m_buf = mir_a2u_cp((char*)pFile, g_pActivePattern->iCodePage);
+ m_buf = mir_a2u_cp((char*)pFile, pPattern->iCodePage);
break;
}
@@ -200,7 +202,7 @@ class CDbxPattern : public MDatabaseReadonly, public MZeroedObject
int iOffset = 0;
while (true) {
int offsets[99];
- int nMatch = pcre16_exec(g_pActivePattern->regMessage.pattern, g_pActivePattern->regMessage.extra, m_buf, m_buf.GetLength(), iOffset, PCRE_NEWLINE_ANYCRLF, offsets, _countof(offsets));
+ int nMatch = pcre16_exec(pPattern->regMessage.pattern, pPattern->regMessage.extra, m_buf, m_buf.GetLength(), iOffset, PCRE_NEWLINE_ANYCRLF, offsets, _countof(offsets));
if (nMatch <= 0)
break;
@@ -256,7 +258,7 @@ public:
return false;
}
- if (g_pActivePattern->iType == 1) // text file
+ if (g_pBatch->m_pPattern->iType == 1) // text file
return LoadTextFile(m_pFile);
return LoadBinaryFile(m_pFile, cbLen);
}
@@ -264,12 +266,13 @@ public:
int Open(const wchar_t *profile)
{
CMStringW wszBaseFolder(profile);
+ auto *pPattern = g_pBatch->m_pPattern;
// create a mask for loading multiple data files for a folder
DWORD dwAttr = GetFileAttributesW(profile);
if (dwAttr & FILE_ATTRIBUTE_DIRECTORY) {
wszBaseFolder = profile;
- m_folder.AppendFormat(L"%s\\*.%s", profile, g_pActivePattern->wszExt.c_str());
+ m_folder.AppendFormat(L"%s\\*.%s", profile, pPattern->wszExt.c_str());
}
else {
int i = wszBaseFolder.ReverseFind('\\');
@@ -294,9 +297,9 @@ public:
cc->szProto = "Pattern";
// we try to restore user id from the file name
- if (g_pActivePattern->iUseFilename) {
+ if (pPattern->iUseFilename) {
int offsets[100];
- int nMatch = pcre16_exec(g_pActivePattern->regFilename.pattern, g_pActivePattern->regFilename.extra, wszFullName, wszFullName.GetLength(), 0, 0, offsets, _countof(offsets));
+ int nMatch = pcre16_exec(pPattern->regFilename.pattern, pPattern->regFilename.extra, wszFullName, wszFullName.GetLength(), 0, 0, offsets, _countof(offsets));
if (nMatch > 0) {
const wchar_t **substrings;
if (pcre16_get_substring_list(wszFullName, offsets, nMatch, &substrings) >= 0) {
@@ -304,15 +307,15 @@ public:
dbcws.szModule = cc->szProto;
dbcws.value.type = DBVT_WCHAR;
- if (g_pActivePattern->iInUID && substrings[g_pActivePattern->iInUID]) {
+ if (pPattern->iInUID && substrings[pPattern->iInUID]) {
dbcws.szSetting = "ID";
- dbcws.value.pwszVal = (wchar_t*)substrings[g_pActivePattern->iInUID];
+ dbcws.value.pwszVal = (wchar_t*)substrings[pPattern->iInUID];
WriteContactSetting(hContact, &dbcws);
}
- if (g_pActivePattern->iInNick && substrings[g_pActivePattern->iInNick]) {
+ if (pPattern->iInNick && substrings[pPattern->iInNick]) {
dbcws.szSetting = "Nick";
- dbcws.value.pwszVal = (wchar_t*)substrings[g_pActivePattern->iInNick];
+ dbcws.value.pwszVal = (wchar_t*)substrings[pPattern->iInNick];
WriteContactSetting(hContact, &dbcws);
}
@@ -343,7 +346,7 @@ public:
if (m_events.size() == 0 || idx < 1 || idx > m_events.size())
return 0;
- if (g_pActivePattern->iType == 1) {
+ if (g_pBatch->m_pPattern->iType == 1) {
int iStart = m_events[idx-1], iEnd = (idx == m_events.size()) ? m_buf.GetLength() : m_events[idx];
CMStringW msg = m_buf.Mid(iStart, iEnd - iStart);
return (LONG)mir_strlen(ptrA(mir_utf8encodeW(msg))) + 1;
@@ -478,8 +481,10 @@ public:
int getTextEvent(MEVENT idx, DBEVENTINFO *dbei)
{
+ auto *pPattern = g_pBatch->m_pPattern;
+
int offsets[99];
- int nMatch = pcre16_exec(g_pActivePattern->regMessage.pattern, g_pActivePattern->regMessage.extra, m_buf, m_buf.GetLength(), m_events[idx-1], PCRE_NEWLINE_ANYCRLF, offsets, _countof(offsets));
+ int nMatch = pcre16_exec(pPattern->regMessage.pattern, pPattern->regMessage.extra, m_buf, m_buf.GetLength(), m_events[idx-1], PCRE_NEWLINE_ANYCRLF, offsets, _countof(offsets));
if (nMatch <= 0)
return 1;
@@ -488,8 +493,8 @@ public:
int h1 = offsets[1], h2 = (idx == m_events.size()) ? m_buf.GetLength() : m_events[idx];
int prn = -1, arn = -1;
- if (g_pActivePattern->iUsePreMsg)
- prn = g_pActivePattern->preRN, arn = g_pActivePattern->afterRN;
+ if (pPattern->iUsePreMsg)
+ prn = pPattern->preRN, arn = pPattern->afterRN;
if (prn != 0) {
int i = 0;
@@ -518,18 +523,18 @@ public:
const wchar_t **substrings;
if (pcre16_get_substring_list(m_buf, offsets, nMatch, &substrings) >= 0) {
struct tm st = {};
- st.tm_year = str2int(substrings[g_pActivePattern->iYear]);
+ st.tm_year = str2int(substrings[pPattern->iYear]);
if (st.tm_year > 1900)
st.tm_year -= 1900;
- st.tm_mon = str2int(substrings[g_pActivePattern->iMonth]) - 1;
- st.tm_mday = str2int(substrings[g_pActivePattern->iDay]);
- st.tm_hour = str2int(substrings[g_pActivePattern->iHours]);
- st.tm_min = str2int(substrings[g_pActivePattern->iMinutes]);
- st.tm_sec = (g_pActivePattern->iSeconds) ? str2int(substrings[g_pActivePattern->iSeconds]) : 0;
+ st.tm_mon = str2int(substrings[pPattern->iMonth]) - 1;
+ st.tm_mday = str2int(substrings[pPattern->iDay]);
+ st.tm_hour = str2int(substrings[pPattern->iHours]);
+ st.tm_min = str2int(substrings[pPattern->iMinutes]);
+ st.tm_sec = (pPattern->iSeconds) ? str2int(substrings[pPattern->iSeconds]) : 0;
dbei->timestamp = mktime(&st);
- if (g_pActivePattern->iDirection)
- if (g_pActivePattern->wszOutgoing == substrings[g_pActivePattern->iDirection])
+ if (pPattern->iDirection)
+ if (pPattern->wszOutgoing == substrings[pPattern->iDirection])
dbei->flags |= DBEF_SENT;
@@ -543,7 +548,7 @@ public:
if (dbei == nullptr || m_events.size() == 0 || idx < 1 || idx > m_events.size())
return 1;
- if (g_pActivePattern->iType == 1)
+ if (g_pBatch->m_pPattern->iType == 1)
return getTextEvent(idx, dbei);
return getBinaryEvent(idx, dbei);
diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp
index 7b81afaa69..d2bd80a47d 100644
--- a/plugins/Import/src/progress.cpp
+++ b/plugins/Import/src/progress.cpp
@@ -26,8 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static CProgressPageDlg *pDlg;
-void MirandaImport(void);
-
CProgressPageDlg::CProgressPageDlg() :
CWizardPageDlg(IDD_PROGRESS),
m_list(this, IDC_STATUS),
@@ -113,7 +111,7 @@ void CProgressPageDlg::OnTimer(CTimer*)
{
m_timer.Stop();
- MirandaImport();
+ g_pBatch->DoImport();
if (g_bServiceMode && !g_bSendQuit)
DestroyWindow(g_hwndWizard);
else {
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h
index e0698a3fbd..43bac7697d 100644
--- a/plugins/Import/src/stdafx.h
+++ b/plugins/Import/src/stdafx.h
@@ -228,6 +228,82 @@ public:
void OnCancel() override;
};
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct AccountMap
+{
+ AccountMap(const char *_src, int _origIdx, const wchar_t *_srcName) :
+ szSrcAcc(mir_strdup(_src)),
+ iSrcIndex(_origIdx),
+ tszSrcName(mir_wstrdup(_srcName))
+ {
+ }
+
+ ptrA szSrcAcc, szBaseProto;
+ ptrW tszSrcName;
+ int iSrcIndex;
+ int iOrder = 0;
+ PROTOACCOUNT *pa = nullptr;
+};
+
+struct ContactMap
+{
+ ContactMap(MCONTACT _src, MCONTACT _dst) :
+ srcID(_src),
+ dstID(_dst)
+ {
+ }
+
+ MCONTACT srcID, dstID;
+};
+
+class CImportBatch : public MZeroedObject
+{
+ OBJLIST<AccountMap> m_accounts;
+ OBJLIST<ContactMap> m_contacts;
+ LIST<DBCachedContact> m_metas;
+
+ DWORD nDupes, nContactsCount, nMessagesCount, nGroupsCount, nSkippedEvents, nSkippedContacts;
+ MDatabaseCommon *srcDb, *dstDb;
+
+ bool ImportAccounts(OBJLIST<char> &arSkippedModules);
+ MCONTACT ImportContact(MCONTACT hSrc);
+ void ImportHistory(MCONTACT hContact, PROTOACCOUNT **protocol, int protoCount);
+ int ImportGroups();
+ void ImportMeta(DBCachedContact *ccSrc);
+
+ MCONTACT MapContact(MCONTACT hSrc);
+
+ bool FindDestAccount(const char *szProto);
+ DBCachedContact* FindDestMeta(DBCachedContact *ccSrc);
+ MCONTACT FindExistingMeta(DBCachedContact *ccSrc);
+ PROTOACCOUNT* FindMyAccount(const char *szProto, const char *szBaseProto, const wchar_t *ptszName, bool bStrict);
+
+ MCONTACT HContactFromID(const char *pszProtoName, const char *pszSetting, wchar_t *pwszID);
+ MCONTACT HContactFromChatID(const char *pszProtoName, const wchar_t *pszChatID);
+ MCONTACT HContactFromNumericID(const char *pszProtoName, const char *pszSetting, DWORD dwID);
+
+public:
+ CImportBatch();
+
+ __forceinline const OBJLIST<AccountMap> &AccountsMap() const { return m_accounts; }
+
+ void CopySettings(MCONTACT srcID, const char *szSrcModule, MCONTACT dstID, const char *szDstModule);
+ void DoImport();
+
+ int myGet(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv);
+ int myGetD(MCONTACT hContact, const char *szModule, const char *szSetting, int iDefault);
+ BOOL myGetS(MCONTACT hContact, const char *szModule, const char *szSetting, char *dest);
+ wchar_t* myGetWs(MCONTACT hContact, const char *szModule, const char *szSetting);
+
+ wchar_t m_wszFileName[MAX_PATH];
+ time_t m_dwSinceDate;
+ int m_iOptions; // set of IOPT_* flags
+ bool m_bSendQuit;
+ MCONTACT m_hContact;
+ CImportPattern *m_pPattern;
+};
+
bool IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO dbei);
int CreateGroup(const wchar_t *name, MCONTACT hContact);
@@ -235,15 +311,10 @@ int CreateGroup(const wchar_t *name, MCONTACT hContact);
uint32_t RLInteger(const uint8_t *p);
uint32_t RLWord(const uint8_t *p);
-extern HWND g_hwndWizard, g_hwndAccMerge;
-extern wchar_t g_wszImportFile[MAX_PATH];
-extern time_t dwSinceDate;
extern bool g_bServiceMode, g_bSendQuit;
-extern int g_iImportOptions;
-extern MCONTACT g_hImportContact;
-
-extern CImportPattern *g_pActivePattern;
extern DATABASELINK g_patternDbLink;
+extern CImportBatch *g_pBatch;
+extern HWND g_hwndWizard, g_hwndAccMerge;
void RegisterIcons(void);
void RegisterMContacts();
diff --git a/plugins/Import/src/ui.cpp b/plugins/Import/src/ui.cpp
index 18bfe73a10..ff3559e596 100644
--- a/plugins/Import/src/ui.cpp
+++ b/plugins/Import/src/ui.cpp
@@ -24,8 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
class CContactImportDlg : public CDlgBase
{
+ friend INT_PTR ImportContact(WPARAM hContact, LPARAM);
+
MCONTACT m_hContact;
int m_flags = 0;
+ CImportPattern *m_pPattern = 0;
+ wchar_t m_wszFileName[MAX_PATH];
CCtrlButton m_btnOpenFile, m_btnOk;
CCtrlCombo m_cmbFileType;
@@ -40,12 +44,12 @@ public:
m_btnOk(this, IDOK),
m_btnOpenFile(this, IDC_OPEN_FILE)
{
+ m_wszFileName[0] = 0;
+
m_btnOk.OnClick = Callback(this, &CContactImportDlg::onClick_Ok);
m_btnOpenFile.OnClick = Callback(this, &CContactImportDlg::onClick_OpenFile);
}
- int getFlags() const { return m_flags; }
-
bool OnInitDialog() override
{
CMStringW wszTitle(FORMAT, TranslateT("Import history for %s"), Clist_GetContactDisplayName(m_hContact));
@@ -63,8 +67,8 @@ public:
bool OnApply() override
{
- edtFileName.GetText(g_wszImportFile, _countof(g_wszImportFile));
- if (g_wszImportFile[0] == 0)
+ edtFileName.GetText(m_wszFileName, _countof(m_wszFileName));
+ if (m_wszFileName[0] == 0)
return false;
if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_DUPS))
@@ -87,18 +91,18 @@ public:
switch(int idx = m_cmbFileType.GetItemData(iCur)) {
case -1:
text.AppendFormat(L"%s (*.dat,*.bak)%c*.dat;*.bak%c", cmbText.c_str(), 0, 0);
- g_pActivePattern = nullptr;
+ m_pPattern = nullptr;
break;
case -2:
text.AppendFormat(L"%s (*.json)%c*.json%c", cmbText.c_str(), 0, 0);
- g_pActivePattern = nullptr;
+ m_pPattern = nullptr;
break;
default:
auto &p = g_plugin.m_patterns[idx-1];
text.AppendFormat(L"%s (*.%s)%c*.%s%c", cmbText.c_str(), p.wszExt.c_str(), 0, p.wszExt.c_str(), 0);
- g_pActivePattern = &p;
+ m_pPattern = &p;
break;
}
text.AppendFormat(L"%s (*.*)%c*.*%c%c", TranslateT("All Files"), 0, 0, 0);
@@ -108,13 +112,13 @@ public:
ofn.lpstrFilter = text;
ofn.lpstrDefExt = L"dat";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
- ofn.lpstrFile = g_wszImportFile;
- ofn.nMaxFile = _countof(g_wszImportFile);
+ ofn.lpstrFile = m_wszFileName;
+ ofn.nMaxFile = _countof(m_wszFileName);
if (!GetOpenFileNameW(&ofn)) {
- g_wszImportFile[0] = 0;
- g_pActivePattern = nullptr;
+ m_wszFileName[0] = 0;
+ m_pPattern = nullptr;
}
- else edtFileName.SetText(g_wszImportFile);
+ else edtFileName.SetText(m_wszFileName);
}
};
@@ -124,7 +128,10 @@ INT_PTR ImportContact(WPARAM hContact, LPARAM)
if (!dlg.DoModal())
return 0;
- g_hImportContact = hContact;
- g_iImportOptions = IOPT_HISTORY + dlg.getFlags();
+ g_pBatch = new CImportBatch();
+ wcsncpy_s(g_pBatch->m_wszFileName, dlg.m_wszFileName, _TRUNCATE);
+ g_pBatch->m_pPattern = dlg.m_pPattern;
+ g_pBatch->m_hContact = hContact;
+ g_pBatch->m_iOptions = IOPT_HISTORY + dlg.m_flags;
return RunWizard(new CProgressPageDlg(), true);
}
diff --git a/plugins/Import/src/wizard.cpp b/plugins/Import/src/wizard.cpp
index 5ca204bd72..6caa05ac4c 100644
--- a/plugins/Import/src/wizard.cpp
+++ b/plugins/Import/src/wizard.cpp
@@ -28,7 +28,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
CIntroPageDlg::CIntroPageDlg() :
CWizardPageDlg(IDD_WIZARDINTRO)
{
- g_pActivePattern = nullptr;
}
bool CIntroPageDlg::OnInitDialog()
@@ -159,6 +158,8 @@ public:
void OnDestroy() override
{
g_hwndWizard = nullptr;
+ delete g_pBatch; g_pBatch = nullptr;
+
if (g_bSendQuit)
PostQuitMessage(0);
}