diff options
-rw-r--r-- | plugins/Import/res/resource.rc | 33 | ||||
-rw-r--r-- | plugins/Import/src/import.cpp | 74 | ||||
-rw-r--r-- | plugins/Import/src/mcontacts.cpp | 2 | ||||
-rw-r--r-- | plugins/Import/src/miranda.cpp | 119 | ||||
-rw-r--r-- | plugins/Import/src/patterns.cpp | 255 | ||||
-rw-r--r-- | plugins/Import/src/resource.h | 9 | ||||
-rw-r--r-- | plugins/Import/src/stdafx.h | 10 |
7 files changed, 344 insertions, 158 deletions
diff --git a/plugins/Import/res/resource.rc b/plugins/Import/res/resource.rc index ec28912e3c..844cd11fd7 100644 --- a/plugins/Import/res/resource.rc +++ b/plugins/Import/res/resource.rc @@ -24,14 +24,6 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL // Dialog
//
-IDD_IMPORTTYPE DIALOGEX 0, 0, 220, 114
-STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
-FONT 8, "MS Shell Dlg", 0, 0, 0x1
-BEGIN
- LTEXT "Choose how you would like to import:",IDC_STATIC,5,16,210,8
- CONTROL "From a Miranda NG database.",IDC_MIRANDA,"Button",BS_AUTORADIOBUTTON,11,31,204,10
-END
-
IDD_WIZARDINTRO DIALOGEX 0, 0, 220, 114
STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
@@ -58,11 +50,13 @@ IDD_MIRANDADB DIALOGEX 0, 0, 220, 114 STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- LTEXT "Miranda has found Miranda profiles with the following names. Please select the one you wish to import, or click ""Other Profile"" if your profile is not listed, or if the list is empty.",IDC_STATICTEXT1,5,10,210,24
- LISTBOX IDC_LIST,5,36,210,36,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
- PUSHBUTTON "&Other Profile...",IDC_OTHER,145,74,70,14
- RTEXT "&Filename:",IDC_STATICTEXT2,5,93,34,8
- EDITTEXT IDC_FILENAME,41,91,174,12,ES_AUTOHSCROLL
+ LTEXT "Choose import type:", IDC_STATICTEXT3,3,1,213,8
+ COMBOBOX IDC_FILETYPE,5,11,210,12,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ LISTBOX IDC_LIST,5,27,210,52,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
+ PUSHBUTTON "Choose directory",IDC_DIRECTORY,72,81,70,14
+ PUSHBUTTON "Choose file",IDC_OTHER,146,81,70,14
+ RTEXT "&Filename:",IDC_STATICTEXT2,5,100,34,8
+ EDITTEXT IDC_FILENAME,41,98,174,12,ES_AUTOHSCROLL
END
IDD_PROGRESS DIALOGEX 0, 0, 220, 114
@@ -185,14 +179,6 @@ IDI_IMPORT ICON "import.ico" #ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
- IDD_IMPORTTYPE, DIALOG
- BEGIN
- LEFTMARGIN, 5
- RIGHTMARGIN, 215
- TOPMARGIN, 5
- BOTTOMMARGIN, 109
- END
-
IDD_WIZARDINTRO, DIALOG
BEGIN
LEFTMARGIN, 5
@@ -324,6 +310,11 @@ BEGIN 0
END
+IDD_MIRANDADB AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 67c0d80fe2..e57a839b56 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -407,44 +407,52 @@ static PROTOACCOUNT* FindMyAccount(const char *szProto, const char *szBaseProto, bool ImportAccounts(OBJLIST<char> &arSkippedModules)
{
- int protoCount = myGetD(NULL, "Protocols", "ProtoCount", 0);
bool bNeedManualMerge = false;
+ if (g_pActivePattern == nullptr) {
+ int protoCount = myGetD(NULL, "Protocols", "ProtoCount", 0);
- for (int i = 0; i < protoCount; i++) {
- char szSetting[100], szProto[100];
- itoa(i, szSetting, 10);
- if (myGetS(NULL, "Protocols", szSetting, szProto))
- continue;
+ for (int i = 0; i < protoCount; i++) {
+ char szSetting[100], szProto[100];
+ itoa(i, szSetting, 10);
+ if (myGetS(NULL, "Protocols", szSetting, szProto))
+ continue;
- itoa(800 + i, szSetting, 10);
- ptrW tszName(myGetWs(NULL, "Protocols", szSetting));
- AccountMap *pNew = new AccountMap(szProto, i, tszName);
- arAccountMap.insert(pNew);
+ itoa(800 + i, szSetting, 10);
+ ptrW tszName(myGetWs(NULL, "Protocols", szSetting));
+ AccountMap* pNew = new AccountMap(szProto, i, tszName);
+ arAccountMap.insert(pNew);
- itoa(200 + i, szSetting, 10);
- pNew->iOrder = myGetD(NULL, "Protocols", szSetting, 0);
+ itoa(200 + i, szSetting, 10);
+ pNew->iOrder = myGetD(NULL, "Protocols", szSetting, 0);
- // check if it's an account-based proto or an old style proto
- char szBaseProto[100];
- if (myGetS(NULL, szProto, "AM_BaseProto", szBaseProto))
- continue;
+ // check if it's an account-based proto or an old style proto
+ char szBaseProto[100];
+ if (myGetS(NULL, szProto, "AM_BaseProto", szBaseProto))
+ continue;
- // save base proto for the future use
- pNew->szBaseProto = mir_strdup(szBaseProto);
+ // save base proto for the future use
+ pNew->szBaseProto = mir_strdup(szBaseProto);
- // try the precise match first
- PROTOACCOUNT *pa = FindMyAccount(szProto, szBaseProto, tszName, true);
- if (pa) {
- pNew->pa = pa;
- continue;
- }
+ // try the precise match first
+ PROTOACCOUNT* pa = FindMyAccount(szProto, szBaseProto, tszName, true);
+ if (pa) {
+ pNew->pa = pa;
+ continue;
+ }
- // if fail, try to found an account by its name
- if (pa = FindMyAccount(szProto, szBaseProto, tszName, false)) {
- pNew->pa = pa;
- bNeedManualMerge = true;
+ // if fail, try to found an account by its name
+ if (pa = FindMyAccount(szProto, szBaseProto, tszName, false)) {
+ pNew->pa = pa;
+ bNeedManualMerge = true;
+ }
}
}
+ else {
+ AccountMap* pNew = new AccountMap("Pattern", 0, g_pActivePattern->wszName);
+ arAccountMap.insert(pNew);
+
+ bNeedManualMerge = true;
+ }
// all accounts to be converted automatically, no need to raise a dialog
if (bNeedManualMerge)
@@ -744,7 +752,7 @@ static MCONTACT ImportContact(MCONTACT hSrc) return 0;
}
- // virtual protocols have no accounts and cannot change modul
+ // virtual protocols have no accounts and cannot change module
szSrcModuleName = szDstModuleName = pa->szModuleName;
}
else {
@@ -773,7 +781,7 @@ static MCONTACT ImportContact(MCONTACT hSrc) }
wchar_t *pszUniqueID = L"<Unknown>";
- DBVARIANT dbv;
+ DBVARIANT dbv = {};
if (!myGet(hSrc, cc->szProto, pszUniqueSetting, &dbv)) {
// Does the contact already exist?
MCONTACT hDst;
@@ -825,7 +833,11 @@ static MCONTACT ImportContact(MCONTACT hSrc) return INVALID_CONTACT_ID;
}
- db_set(hDst, szDstModuleName, pszUniqueSetting, &dbv);
+ if (dbv.type == 0)
+ srcDb->GetContactSetting(hSrc, cc->szProto, "ID", &dbv);
+
+ if (dbv.type != 0)
+ db_set(hDst, szDstModuleName, pszUniqueSetting, &dbv);
CreateGroup(tszGroup, hDst);
diff --git a/plugins/Import/src/mcontacts.cpp b/plugins/Import/src/mcontacts.cpp index 6ac718d878..e2829e41bd 100644 --- a/plugins/Import/src/mcontacts.cpp +++ b/plugins/Import/src/mcontacts.cpp @@ -228,7 +228,7 @@ public: else return 1; if (dbei->cbBlob && cbLen) { - int copySize = min(cbLen, dbei->cbBlob-1); + DWORD copySize = min(DWORD(cbLen), dbei->cbBlob-1); if (!ReadFile(m_hFile, dbei->pBlob, copySize, &dwRead, 0) || dwRead != copySize) return 0; diff --git a/plugins/Import/src/miranda.cpp b/plugins/Import/src/miranda.cpp index 7864c78e9d..762bacf5c5 100644 --- a/plugins/Import/src/miranda.cpp +++ b/plugins/Import/src/miranda.cpp @@ -33,33 +33,30 @@ CMirandaPageDlg::CMirandaPageDlg() : CWizardPageDlg(IDD_MIRANDADB),
m_list(this, IDC_LIST),
btnBack(this, IDC_BACK),
- btnOther(this, IDC_OTHER)
+ btnPath(this, IDC_DIRECTORY),
+ btnOther(this, IDC_OTHER),
+ m_cmbFileType(this, IDC_FILETYPE)
{
- m_list.OnSelChange = Callback(this, &CMirandaPageDlg::onSelChanged_list);
-
btnBack.OnClick = Callback(this, &CMirandaPageDlg::onClick_Back);
+ btnPath.OnClick = Callback(this, &CMirandaPageDlg::onClick_Path);
btnOther.OnClick = Callback(this, &CMirandaPageDlg::onClick_Other);
+
+ m_cmbFileType.OnChange = Callback(this, &CMirandaPageDlg::onChange_Pattern);
}
bool CMirandaPageDlg::OnInitDialog()
{
- VARSW pfd(L"%miranda_path%\\Profiles");
- VARSW pfd1(L"%miranda_path%");
- VARSW pfd2(L"%miranda_profilesdir%");
- VARSW pfn(L"%miranda_profilename%");
-
- SearchForLists(pfd2, pfn);
- SearchForLists(pfd1, nullptr);
- if (mir_wstrcmpi(pfd, pfd2))
- SearchForLists(pfd, nullptr);
-
- SendDlgItemMessage(m_hwnd, IDC_LIST, LB_SETCURSEL, 0, 0);
- SendMessage(m_hwnd, WM_COMMAND, MAKELONG(IDC_LIST, LBN_SELCHANGE), 0);
-
- wchar_t filename[MAX_PATH];
- GetDlgItemText(m_hwnd, IDC_FILENAME, filename, _countof(filename));
- if (_waccess(filename, 4))
- SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 1, 0);
+ m_cmbFileType.AddString(TranslateT("Miranda NG database"), -1);
+
+ int iType = 1;
+ for (auto& it : g_plugin.m_patterns)
+ m_cmbFileType.AddString(it->wszName, iType++);
+
+ btnPath.Hide();
+ m_list.Disable();
+ SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 1, 0);
+
+ m_cmbFileType.SetCurSel(0);
return true;
}
@@ -72,9 +69,15 @@ int CMirandaPageDlg::Resizer(UTILRESIZECONTROL *urc) case IDC_STATICTEXT2:
return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
+ case IDC_STATICTEXT3:
+ return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
+
case IDC_FILENAME:
return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
+ case IDC_FILETYPE:
+ return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
+
case IDC_LIST:
return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
}
@@ -133,44 +136,60 @@ void CMirandaPageDlg::onClick_Other(CCtrlButton*) }
}
-void CMirandaPageDlg::onSelChanged_list(CCtrlListBox*)
+void CMirandaPageDlg::onClick_Path(CCtrlButton*)
{
- int sel = m_list.GetCurSel();
- if (sel != -1) {
- SetDlgItemText(m_hwnd, IDC_FILENAME, (wchar_t*)m_list.GetItemData(sel));
- SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
- }
-}
+ wchar_t str[MAX_PATH];
-void CMirandaPageDlg::SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf)
-{
- // find in Miranda profile subfolders
- wchar_t searchspec[MAX_PATH];
- mir_snwprintf(searchspec, L"%s\\*.*", mirandaPath);
+ BROWSEINFOW br = {};
+ br.hwndOwner = m_hwnd;
+ br.pszDisplayName = str;
+ br.lpszTitle = TranslateT("Importing whole directory");
+ br.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(searchspec, &fd);
- if (hFind == INVALID_HANDLE_VALUE)
+ PIDLIST_ABSOLUTE pList = SHBrowseForFolderW(&br);
+ if (pList == nullptr)
return;
- do {
- // find all subfolders except "." and ".."
- if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || !mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L".."))
- continue;
+ SHGetPathFromIDListW(pList, str);
+ CoTaskMemFree(pList);
- // skip the current profile too
- if (mirandaProf != nullptr && !mir_wstrcmpi(mirandaProf, fd.cFileName))
- continue;
+ SetDlgItemText(m_hwnd, IDC_FILENAME, str);
- wchar_t buf[MAX_PATH], profile[MAX_PATH];
- mir_snwprintf(buf, L"%s\\%s\\%s.dat", mirandaPath, fd.cFileName, fd.cFileName);
- if (_waccess(buf, 0) == 0) {
- mir_snwprintf(profile, L"%s.dat", fd.cFileName);
- m_list.AddString(profile, (LPARAM)mir_wstrdup(buf));
- }
- } while (FindNextFile(hFind, &fd));
+ // find appropriate files and list them
+ wchar_t searchspec[MAX_PATH];
+ mir_snwprintf(searchspec, L"%s\\*.%s", str, g_pActivePattern->wszExt.c_str());
+ WIN32_FIND_DATA fd;
+ HANDLE hFind = FindFirstFile(searchspec, &fd);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ do {
+ // find all subfolders except "." and ".."
+ if (!mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L".."))
+ continue;
+
+ m_list.AddString(fd.cFileName);
+ } while (FindNextFile(hFind, &fd));
+ FindClose(hFind);
+ SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
+ }
+}
- FindClose(hFind);
+void CMirandaPageDlg::onChange_Pattern(CCtrlCombo*)
+{
+ int iCur = m_cmbFileType.GetCurSel();
+ if (iCur == -1)
+ return;
+
+ // standard import for Miranda
+ int iData = m_cmbFileType.GetItemData(iCur);
+ if (iData == -1) {
+ g_pActivePattern = nullptr;
+ btnPath.Hide();
+ }
+ // custom pattern import
+ else {
+ g_pActivePattern = &g_plugin.m_patterns[iData-1];
+ btnPath.Show();
+ }
}
//=======================================================================================
diff --git a/plugins/Import/src/patterns.cpp b/plugins/Import/src/patterns.cpp index 54afc1d5ca..7e3b239654 100644 --- a/plugins/Import/src/patterns.cpp +++ b/plugins/Import/src/patterns.cpp @@ -123,82 +123,155 @@ void CMPlugin::LoadPattern(const wchar_t *pwszFileName) class CDbxPattern : public MDatabaseReadonly, public MZeroedObject { - HANDLE m_hFile = INVALID_HANDLE_VALUE, m_hMap = nullptr; - uint32_t m_iFileLen; - char* m_pFile; - CMStringW m_buf; + CMStringW m_buf, m_folder; + MCONTACT m_hCurrContact; std::vector<DWORD> m_events; + std::vector<CMStringW> m_files; public: - CDbxPattern() + CDbxPattern() : + m_hCurrContact(0) {} ~CDbxPattern() { } - void Load() + bool Load(const wchar_t *pwszFileName) { - // mcontacts operates with the only contact with pseudo id=1 - m_cache->AddContactToCache(1); + m_buf.Empty(); + m_events.clear(); + + HANDLE hFile = ::CreateFileW(pwszFileName, GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, 0); + if (hFile == INVALID_HANDLE_VALUE) { + Netlib_Logf(0, "failed to open file <%S> for import: %d", pwszFileName, GetLastError()); + return false; + } + + HANDLE hMap = ::CreateFileMappingW(hFile, nullptr, PAGE_READONLY, 0, 0, L"ImportMapfile"); + if (hMap == nullptr) { + Netlib_Logf(0, "failed to mmap file <%S> for import: %d", pwszFileName, GetLastError()); + return false; + } + + char *pFile = (char*)::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0); + if (pFile == nullptr) { + Netlib_Logf(0, "failed to map view of file <%S> for import: %d", pwszFileName, GetLastError()); + return false; + } switch (g_pActivePattern->iCodePage) { case CP_UTF8: - m_buf = mir_utf8decodeW(m_pFile); + m_buf = mir_utf8decodeW(pFile); break; case 1200: - m_buf = mir_wstrdup((wchar_t*)m_pFile); + m_buf = mir_wstrdup((wchar_t*)pFile); break; default: - m_buf = mir_a2u_cp(m_pFile, g_pActivePattern->iCodePage); + m_buf = mir_a2u_cp(pFile, g_pActivePattern->iCodePage); break; } - if (m_buf.IsEmpty()) - return; - - 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)); - if (nMatch <= 0) - break; - - m_events.push_back(offsets[0]); - iOffset = offsets[1]; + bool bRes = false; + if (!m_buf.IsEmpty()) { + 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)); + if (nMatch <= 0) + break; + + m_events.push_back(offsets[0]); + iOffset = offsets[1]; + } + bRes = true; } - if (m_pFile != nullptr) - ::UnmapViewOfFile(m_pFile); + if (pFile != nullptr) + ::UnmapViewOfFile(pFile); - if (m_hMap != nullptr) - ::CloseHandle(m_hMap); + if (hMap != nullptr) + ::CloseHandle(hMap); - if (m_hFile != INVALID_HANDLE_VALUE) - ::CloseHandle(m_hFile); + if (hFile != INVALID_HANDLE_VALUE) + ::CloseHandle(hFile); + + return bRes; } int Open(const wchar_t *profile) { - m_hFile = ::CreateFileW(profile, GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, 0); - if (m_hFile == INVALID_HANDLE_VALUE) { - Netlib_Logf(0, "failed to open file <%S> for import: %d", profile, GetLastError()); - return EGROKPRF_CANTREAD; + CMStringW wszBaseFolder(profile); + + // 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()); + } + else { + int i = wszBaseFolder.ReverseFind('\\'); + if (i != -1) + wszBaseFolder = wszBaseFolder.Left(i - 1); + m_folder = profile; } - m_iFileLen = ::GetFileSize(m_hFile, 0); - m_hMap = ::CreateFileMappingW(m_hFile, nullptr, PAGE_READONLY, 0, 0, L"ImportMapfile"); - if (m_hMap == nullptr) { - Netlib_Logf(0, "failed to mmap file <%S> for import: %d", profile, GetLastError()); - return EGROKPRF_CANTREAD; + int hContact = 1; + WIN32_FIND_DATA fd; + HANDLE hFind = FindFirstFile(m_folder, &fd); + if (hFind != INVALID_HANDLE_VALUE) { + do { + // find all subfolders except "." and ".." + if (!mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L"..")) + continue; + + CMStringW wszFullName(wszBaseFolder + L"\\" + fd.cFileName); + m_files.push_back(wszFullName); + + auto *cc = m_cache->AddContactToCache(hContact); + cc->szProto = "Pattern"; + + // we try to restore user id from the file name + if (g_pActivePattern->iUseFilename) { + int offsets[100]; + int nMatch = pcre16_exec(g_pActivePattern->regFilename.pattern, g_pActivePattern->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) { + DBCONTACTWRITESETTING dbcws = {}; + dbcws.szModule = cc->szProto; + dbcws.value.type = DBVT_WCHAR; + + if (g_pActivePattern->iInUID && substrings[g_pActivePattern->iInUID]) { + dbcws.szSetting = "ID"; + dbcws.value.pwszVal = (wchar_t*)substrings[g_pActivePattern->iInUID]; + WriteContactSetting(hContact, &dbcws); + } + + if (g_pActivePattern->iInNick && substrings[g_pActivePattern->iInNick]) { + dbcws.szSetting = "Nick"; + dbcws.value.pwszVal = (wchar_t*)substrings[g_pActivePattern->iInNick]; + WriteContactSetting(hContact, &dbcws); + } + + pcre16_free_substring_list(substrings); + } + } + } + hContact++; + } + while (FindNextFile(hFind, &fd)); + + FindClose(hFind); } - m_pFile = (char*)::MapViewOfFile(m_hMap, FILE_MAP_READ, 0, 0, 0); - if (m_pFile == nullptr) { - Netlib_Logf(0, "failed to map view of file <%S> for import: %d", profile, GetLastError()); + if (m_files.empty()) + return EGROKPRF_CANTREAD; + + m_hCurrContact = 1; + if (!Load(m_files[0])) return EGROKPRF_CANTREAD; - } return EGROKPRF_NOERROR; } @@ -216,7 +289,7 @@ public: STDMETHODIMP_(LONG) GetContactCount(void) override { - return 1; + return (LONG)m_files.size(); } STDMETHODIMP_(LONG) GetEventCount(MCONTACT) override @@ -224,6 +297,81 @@ public: return (LONG)m_events.size(); } + STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT hContact, LPCSTR szModule, LPCSTR szSetting, DBVARIANT* dbv, int isStatic) + { + if (szSetting == nullptr || szModule == nullptr) + return 1; + + DBCachedContact *cc = nullptr; + if (hContact) { + cc = m_cache->GetCachedContact(hContact); + if (cc == nullptr) + return 1; + } + + size_t settingNameLen = strlen(szSetting); + size_t moduleNameLen = strlen(szModule); + char* szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen); + + DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(hContact, szCachedSettingName, 0); + if (pCachedValue != nullptr) { + if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) { + int cbOrigLen = dbv->cchVal; + char *cbOrigPtr = dbv->pszVal; + memcpy(dbv, pCachedValue, sizeof(DBVARIANT)); + if (isStatic) { + int cbLen = 0; + if (pCachedValue->pszVal != nullptr) + cbLen = (int)strlen(pCachedValue->pszVal); + + cbOrigLen--; + dbv->pszVal = cbOrigPtr; + if (cbLen < cbOrigLen) + cbOrigLen = cbLen; + memcpy(dbv->pszVal, pCachedValue->pszVal, cbOrigLen); + dbv->pszVal[cbOrigLen] = 0; + dbv->cchVal = cbLen; + } + else { + dbv->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal) + 1); + strcpy(dbv->pszVal, pCachedValue->pszVal); + } + } + else memcpy(dbv, pCachedValue, sizeof(DBVARIANT)); + + return (pCachedValue->type == DBVT_DELETED) ? 1 : 0; + } + + return 1; + } + + STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT hContact, DBCONTACTWRITESETTING *dbcws) + { + if (dbcws == nullptr || dbcws->szSetting == nullptr || dbcws->szModule == nullptr) + return 1; + + if (hContact) { + DBCachedContact* cc = m_cache->GetCachedContact(hContact); + if (cc == nullptr) + return 1; + } + + DBCONTACTWRITESETTING dbcwWork = *dbcws; + if (dbcwWork.value.type == DBVT_WCHAR) { + T2Utf value(dbcwWork.value.pwszVal); + dbcwWork.value.pszVal = NEWSTR_ALLOCA(value); + dbcwWork.value.type = DBVT_UTF8; + dbcwWork.value.cchVal = (WORD)strlen(dbcwWork.value.pszVal); + } + + char* cachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, mir_strlen(dbcwWork.szModule), mir_strlen(dbcwWork.szSetting)); + DBVARIANT* cachedValue = m_cache->GetCachedValuePtr(hContact, cachedSettingName, 1); + if (cachedValue != nullptr) + m_cache->SetCachedVariant(&dbcwWork.value, cachedValue); + + return 0; + } + //////////////////////////////////////////////////////////////////////////////////////// static int str2int(const wchar_t* str) @@ -300,8 +448,16 @@ public: return 0; } - STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT) override + STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT hContact) override { + // no system history + if (hContact == 0) + return 0; + + if (hContact != m_hCurrContact) + if (!Load(m_files[hContact-1])) + return 0; + return m_events.size() > 0 ? 1 : 0; } @@ -313,8 +469,16 @@ public: return idx + 1; } - STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT) override + STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT hContact) override { + // no system history + if (hContact == 0) + return 0; + + if (hContact != m_hCurrContact) + if (!Load(m_files[hContact - 1])) + return 0; + return m_events.size() > 0 ? (MEVENT)m_events.size() : 0; } @@ -343,7 +507,6 @@ static MDatabaseCommon* pattern_load(const wchar_t *profile, BOOL) if (db->Open(profile)) return nullptr; - db->Load(); return db.release(); } diff --git a/plugins/Import/src/resource.h b/plugins/Import/src/resource.h index a2f6bb7088..9a2835b7d9 100644 --- a/plugins/Import/src/resource.h +++ b/plugins/Import/src/resource.h @@ -6,7 +6,6 @@ #define IDD_WIZARD 101
#define IDD_OPTIONS 102
#define IDD_ACCMERGE 105
-#define IDD_IMPORTTYPE 106
#define IDD_WIZARDINTRO 107
#define IDD_FINISHED 108
#define IDD_MIRABILISDB 109
@@ -17,11 +16,12 @@ #define IDR_LIST 113
#define IDI_IMPORT 114
#define IDC_DONTLOADPLUGIN 1001
-#define IDC_MIRANDA 1002
#define IDC_OTHER 1005
#define IDC_LIST 1006
#define IDC_FILENAME 1007
#define IDC_PROGRESS 1008
+#define IDC_OTHER2 1008
+#define IDC_DIRECTORY 1008
#define IDC_STATUS 1009
#define IDC_SPLITTER 1010
#define IDC_STATICTEXT1 1011
@@ -51,7 +51,6 @@ #define IDC_FT 1040
#define IDC_OPEN_FILE 1042
#define IDC_CHECK_DUPS 1043
-#define IDC_COMBO1 1045
#define IDC_FILETYPE 1045
#define IDM_COPY 40001
#define IDC_STATIC -1
@@ -60,9 +59,9 @@ //
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 117
+#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_COMMAND_VALUE 40002
-#define _APS_NEXT_CONTROL_VALUE 1046
+#define _APS_NEXT_CONTROL_VALUE 1047
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h index 70c795a33d..f6a116503d 100644 --- a/plugins/Import/src/stdafx.h +++ b/plugins/Import/src/stdafx.h @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <windows.h>
#include <commctrl.h> // datetimepicker
+#include <ShlObj.h>
#include <malloc.h>
#include <time.h>
@@ -88,6 +89,7 @@ struct CImportPattern : public MZeroedObject struct CMPlugin : public PLUGIN<CMPlugin>
{
private:
+ friend class CMirandaPageDlg;
friend class CContactImportDlg;
void LoadPattern(const wchar_t *pwszFileName);
@@ -160,10 +162,9 @@ public: class CMirandaPageDlg : public CWizardPageDlg
{
- void SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf);
-
- CCtrlButton btnBack, btnOther;
+ CCtrlButton btnBack, btnOther, btnPath;
CCtrlListBox m_list;
+ CCtrlCombo m_cmbFileType;
public:
CMirandaPageDlg();
@@ -174,9 +175,10 @@ public: void OnNext() override;
void onClick_Back(CCtrlButton*);
+ void onClick_Path(CCtrlButton*);
void onClick_Other(CCtrlButton*);
- void onSelChanged_list(CCtrlListBox*);
+ void onChange_Pattern(CCtrlCombo*);
};
class CMirandaOptionsPageDlg : public CWizardPageDlg
|