int CloneContact(HANDLE hContact) { HANDLE newContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!newContact) return 0; // enum all the modules ModuleSettingLL modlist; if (!EnumModules(&modlist)) { msg(Translate("Error Loading Module List"), modFullname); return 0; } ModSetLinkLinkItem *mod = modlist.first; while (mod) { copyModule(mod->name, hContact, newContact); mod = (ModSetLinkLinkItem *)mod->next; } FreeModuleSettingLL(&modlist); return 1; }
void __cdecl PopulateModuleDropListThreadFunc(LPVOID di) { HWND hwnd = (HWND)di; ModuleSettingLL msll; ModSetLinkLinkItem *module; int moduleEmpty; if (!EnumModules(&msll)) DestroyWindow(hwnd); module = msll.first; while (module && working) { moduleEmpty = 1; // check the null if (!IsModuleEmpty(NULL,module->name)) { SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_ADDSTRING,0,(LPARAM)module->name); moduleEmpty = 0; module = module->next; continue; } for (MCONTACT hContact = db_find_first();moduleEmpty && hContact;hContact = db_find_next(hContact)) { if (!IsModuleEmpty(hContact,module->name)) { SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_ADDSTRING,0,(LPARAM)module->name); moduleEmpty = 0; break; } } module = module->next; SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_SETCURSEL,0,0); } SendDlgItemMessage(hwnd,IDC_CONTACTS,CB_SETCURSEL,0,0); FreeModuleSettingLL(&msll); SetWindowText(hwnd,Translate("Delete module from Database")); EnableWindow(GetDlgItem(hwnd,IDC_CONTACTS),1); EnableWindow(GetDlgItem(hwnd,IDOK),1); EnableWindow(GetDlgItem(hwnd,IDCANCEL),1); if (!working) PostMessage(hwnd, WM_COMMAND, (WPARAM)IDCANCEL, 0); else working = 2; }
void __cdecl FindSettings(LPVOID param) { FindInfo* fi = (FindInfo*)param; HWND hwndParent = GetParent(fi->hwnd); ModuleSettingLL ModuleList, SettingList; ModSetLinkLinkItem *module, *setting; MCONTACT hContact; DBVARIANT dbv = { 0 }; int foundCount = 0, replaceCount = 0, deleteCount = 0; DWORD numsearch = 0, numreplace = 0; int NULLContactDone = 0; if (!fi->search || !EnumModules(&ModuleList)) { fi_free(fi); return; } _T2A search(fi->search); _T2A replace(fi->replace); // skip modules and setting names on unicode search or replace if (IsRealUnicode(fi->search) || IsRealUnicode(fi->replace)) { fi->options &= ~(F_SETNAME | F_MODNAME); fi->options |= F_UNICODE; } if (!(fi->options & F_UNICODE) && (fi->options & F_SETVAL)) { char val[16]; numsearch = strtoul(search, NULL, 10); _ultoa(numsearch, val, 10); if (!mir_strcmp(search, val)) { fi->options |= F_NUMSRCH; // replace numeric values only entirely if (replace && (fi->options & F_ENTIRE)) { numreplace = strtoul(replace, NULL, 10); _ultoa(numreplace, val, 10); if (!replace[0] || !mir_strcmp(replace, val)) fi->options |= F_NUMREPL; } } } SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)TranslateT("Searching...")); hContact = 0; while (GetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA)) { if (!hContact) { if (NULLContactDone) break; else { NULLContactDone = 1; hContact = db_find_first(); } } else hContact = db_find_next(hContact); for (module = ModuleList.first; module; module = module->next) { if (IsModuleEmpty(hContact, module->name)) continue; if (fi->options & (F_SETVAL | F_SETNAME)) { if (!EnumSettings(hContact, module->name, &SettingList)) { fi_free(fi); FreeModuleSettingLL(&ModuleList); return; } for (setting = SettingList.first; setting; setting = setting->next) { dbv.type = 0; if (db_get_s(hContact, module->name, setting->name, &dbv, 0)) continue; // check in settings value if (fi->options & F_SETVAL) { TCHAR *value = NULL; switch(dbv.type) { case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD: if ((fi->options & F_NUMSRCH) && numsearch == getNumericValue(&dbv)) { TCHAR *val = fi->search; int flag = F_SETVAL; if (fi->options & F_NUMREPL) { if (replace[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; deleteCount++; } else if (setNumericValue(hContact, module->name, setting->name, numreplace, dbv.type)) { val = fi->replace; flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, module->name, setting->name, val, flag); } break; case DBVT_WCHAR: if (!value) value = mir_u2t(dbv.pwszVal); case DBVT_UTF8: if (!value) value = mir_utf8decodeT(dbv.pszVal); case DBVT_ASCIIZ: if (!value) value = mir_a2t(dbv.pszVal); if (FindMatchT(value, fi->search, fi->options)) { foundCount++; ptrT ptr; TCHAR *newValue = value; int flag = F_SETVAL; if (fi->replace) { newValue = (fi->options & F_ENTIRE) ? fi->replace : ptr = multiReplaceT(value, fi->search, fi->replace, fi->options & F_CASE); // !!!! delete or make empty ? if (!newValue[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; newValue = value; deleteCount++; } else { #ifdef _UNICODE // save as unicode if needed if (dbv.type != DBVT_ASCIIZ || IsRealUnicode(newValue)) db_set_ws(hContact, module->name, setting->name, newValue); else #endif db_set_s(hContact, module->name, setting->name, _T2A(newValue)); flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, module->name, setting->name, newValue, flag); } mir_free(value); break; } // switch } // check in setting name if ((fi->options & F_SETNAME) && FindMatchA(setting->name, search, fi->options)) { foundCount++; ptrA ptr; char *newSetting = setting->name; int flag = F_SETNAME; if (replace) { newSetting = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(setting->name, search, replace, fi->options & F_CASE); if (!newSetting[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; newSetting = setting->name; deleteCount++; } else { DBVARIANT dbv2; // skip if exist if (!db_get_s(hContact, module->name, newSetting, &dbv2, 0)) db_free(&dbv2); else if (!db_set(hContact, module->name, newSetting, &dbv)) { db_unset(hContact, module->name, setting->name); flag |= F_REPLACED; replaceCount++; } } } ItemFound(fi->hwnd, hContact, module->name, newSetting, NULL, flag); } db_free(&dbv); } // for(setting) FreeModuleSettingLL(&SettingList); } // check in module name if ((fi->options & F_MODNAME) && FindMatchA(module->name, search, fi->options)) { foundCount++; char *newModule = module->name; int flag = F_MODNAME; ptrA ptr; if (replace) { newModule = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(module->name, search, replace, fi->options & F_CASE); if (!newModule[0]) { deleteModule(hContact, module->name, 0); replaceTreeItem(hContact, module->name, NULL); flag |= F_DELETED; newModule = module->name; deleteCount++; } else if (renameModule(hContact, module->name, newModule)) { replaceTreeItem(hContact, module->name, NULL); flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, newModule, 0, 0, flag); } } // for(module) } TCHAR msg[MSG_SIZE]; mir_sntprintf(msg, TranslateT("Finished. Items found: %d / replaced: %d / deleted: %d"), foundCount, replaceCount, deleteCount); SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)msg); if (fi->replace) { EnableWindow(GetDlgItem(hwndParent, IDC_SEARCH), 1); SetDlgItemText(hwndParent, IDOK, TranslateT("&Replace")); } else { SetDlgItemText(hwndParent, IDC_SEARCH, TranslateT("&Search")); EnableWindow(GetDlgItem(hwndParent, IDOK), 1); } fi_free(fi); FreeModuleSettingLL(&ModuleList); SetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA, 0); EnableWindow(GetDlgItem(hwndParent, IDCANCEL), 1); }
// previously saved in DB resident settings are unaccessible. // so let's find them and delete from DB int fixResidentSettings() { if (!m_lResidentSettings.getCount() || fixing) return 0; ModuleSettingLL ModuleList, SettingList; ModSetLinkLinkItem *module, *setting; MCONTACT hContact = 0; int NULLContactDone = 0; char str[2*FLD_SIZE]; int cnt = 0; if (!EnumModules(&ModuleList)) return 0; fixing = 1; while (hwnd2mainWindow) { if (!hContact) { if (NULLContactDone) break; else { NULLContactDone = 1; hContact = db_find_first(); } } else hContact = db_find_next(hContact); for (module = ModuleList.first; module; module = module->next) { if (IsModuleEmpty(hContact, module->name) || m_lResidentModules.getIndex(module->name) == -1) continue; if (!EnumSettings(hContact, module->name, &SettingList)) continue; for (setting = SettingList.first; setting; setting = setting->next) { mir_strncpy(str, module->name, _countof(str)-1); mir_strcat(str, "/"); mir_strncat(str, setting->name, _countof(str)); int idx = m_lResidentSettings.getIndex(str); if (idx == -1) continue; g_db->SetSettingResident(0, str); db_unset(hContact, module->name, setting->name); g_db->SetSettingResident(1, str); cnt++; } // for(setting) FreeModuleSettingLL(&SettingList); } // for(module) } FreeModuleSettingLL(&ModuleList); fixing = 0; return cnt; }
void moduleListWM_NOTIFY(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)// hwnd here is to the main window, NOT the treview { switch (((NMHDR *)lParam)->code) { case TVN_ITEMEXPANDINGA: case TVN_ITEMEXPANDINGW: if (populating && ((LPNMTREEVIEW)lParam)->action == TVE_EXPAND) { ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)((LPNMTREEVIEW)lParam)->itemNew.lParam; if (mtis && (mtis->type == (CONTACT | EMPTY))) { TVINSERTSTRUCT tvi; HTREEITEM item = {0}; ModuleTreeInfoStruct *_lParam; HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES); ModSetLinkLinkItem *module; ModuleSettingLL modlist; MCONTACT hContact = mtis->hContact; mtis->type = CONTACT; if (!EnumModules(&modlist)) { msg(Translate("Error loading module list"), modFullname); break; } module = modlist.first; while (module && hwnd2mainWindow) { if (module->name[0] && !IsModuleEmpty(hContact, module->name)) { tvi.hParent = ((LPNMTREEVIEW)lParam)->itemNew.hItem; tvi.hInsertAfter = TVI_SORT; tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; tvi.item.pszText = module->name; _lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct)); _lParam->hContact = hContact; tvi.item.iImage = 5; tvi.item.iSelectedImage = 6; _lParam->type = KNOWN_MODULE; tvi.item.lParam = (LPARAM)_lParam; TreeView_InsertItem(hwnd2Tree, &tvi); } module = (ModSetLinkLinkItem *)module->next; } FreeModuleSettingLL(&modlist); } } break; case TVN_SELCHANGEDA: case TVN_SELCHANGEDW: { ModuleTreeInfoStruct *mtis; LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam; TVITEM tvi = {0}; char text[264]; MCONTACT hContact; HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS); tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT; tvi.hItem = pnmtv->itemNew.hItem; tvi.pszText = text; tvi.cchTextMax = 264; TreeView_GetItem(pnmtv->hdr.hwndFrom, &tvi); if (tvi.lParam) { mtis = (ModuleTreeInfoStruct *)tvi.lParam; hContact = mtis->hContact; if (mtis->type == STUB) break; if (populating) Select = 0; if (mtis->type == MODULE) { SettingListInfo *info = (SettingListInfo *)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA); BOOL refresh = 1; if (info) { if (info->hContact == hContact && !mir_strcmp(info->module, text)) refresh = 0; } if (refresh) PopulateSettings(hwnd2Settings, hContact, text); } else if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) { char data[32], szProto[256]; int index, loaded, multi = 0; LVITEM lvi = {0}; lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM; lvi.iImage = 6; ClearListview(hwnd2Settings); SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0); if (himl2) ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL); if (mtis->type == CONTACT_ROOT_ITEM && !hContact) { multi = 1; hContact = db_find_first(); } while (hContact && hwnd2mainWindow) { if (multi) { // filter if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto))) loaded = IsProtocolLoaded(szProto); else loaded = 0; if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) { hContact = db_find_next(hContact); continue; } } lvi.iItem = 0; lvi.pszText = (char *)GetContactName(hContact, NULL, FALSE); index = ListView_InsertItem(hwnd2Settings, &lvi); mir_snprintf(data, SIZEOF(data), "0x%08X (%ld)", hContact, hContact); ListView_SetItemText(hwnd2Settings, index, 1, data); ListView_SetItemText(hwnd2Settings, index, 2, Translate("HANDLE")); ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)"); if (!multi) break; hContact = db_find_next(hContact); } } else ClearListview(hwnd2Settings); } else // clear any settings that may be there... ClearListview(hwnd2Settings); } break; //TVN_SELCHANGED: case NM_RCLICK: if (((NMHDR *)lParam)->code == NM_RCLICK) moduleListRightClick(hwnd, wParam, lParam); break; case TVN_BEGINLABELEDITA: // subclass it.. case TVN_BEGINLABELEDITW: { LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam; ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam; HWND hwnd2Edit = TreeView_GetEditControl(GetDlgItem(hwnd, IDC_MODULES)); if (!mtis->type || (mtis->type == CONTACT)) { SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE); break; } mir_subclassWindow(hwnd2Edit, ModuleTreeLabelEditSubClassProc); SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE); } break; case TVN_ENDLABELEDITA: case TVN_ENDLABELEDITW: LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam; TVITEM tvi = {0}; char text[264]; char *newtext; ModuleTreeInfoStruct *mtis; tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM; tvi.hItem = ptvdi->item.hItem; tvi.pszText = text; tvi.cchTextMax = 264; TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam; newtext = u2a((WCHAR *)ptvdi->item.pszText); if (!newtext // edit control failed || !mtis->type // its a root item || mtis->type == CONTACT // its a contact || *newtext == 0) // empty string SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE); else { if (mir_strcmp(tvi.pszText, newtext)) { renameModule(tvi.pszText, newtext, mtis->hContact); findAndRemoveDuplicates(((LPNMHDR)lParam)->hwndFrom, mtis->hContact, newtext); if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi)) { tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.iImage = 1; tvi.iSelectedImage = 2; TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); PopulateSettings(GetDlgItem(hwnd, IDC_SETTINGS), mtis->hContact, newtext); } } SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE); } mir_free(newtext); break; } }
void __cdecl PopulateModuleTreeThreadFunc(LPVOID di) { TVINSERTSTRUCT tvi; HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES); char SelectedModule[256] = {0}; char SelectedSetting[256] = {0}; MCONTACT hSelectedContact = hRestore; MCONTACT hContact; HTREEITEM contact, contactsRoot; int count; // item lParams ModuleTreeInfoStruct *lParam; // module list ModSetLinkLinkItem *module; ModuleSettingLL modlist; hRestore = NULL; if (!hwnd2Tree) { msg(Translate("Module tree not found"), modFullname); return; } Select = 0; switch ((int)di) { case 1: // restore after rebuild if (HTREEITEM item = TreeView_GetSelection(hwnd2Tree)) { TVITEM tvi = {0}; tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT; tvi.pszText = SelectedModule; tvi.cchTextMax = 255; tvi.hItem = item; TreeView_GetItem(hwnd2Tree, &tvi); if (tvi.lParam) { ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam; hSelectedContact = mtis->hContact; if (mtis->type == CONTACT) SelectedModule[0] = 0; Select = 1; } } break; case 2: // restore saved if (GetValue(NULL, modname, "LastModule", SelectedModule, SIZEOF(SelectedModule))) { hSelectedContact = db_get_dw(NULL, modname, "LastContact", (DWORD)INVALID_HANDLE_VALUE); if (hSelectedContact != INVALID_CONTACT_ID) Select = 1; GetValue(NULL, modname, "LastSetting", SelectedSetting, SIZEOF(SelectedSetting)); } break; case 3: // restore from user menu case 4: // jump from user menu if (hSelectedContact && hSelectedContact != INVALID_CONTACT_ID) Select = 1; break; } if ((int)di != 4) { // do not rebuild on just going to another setting if (!EnumModules(&modlist)) { msg(Translate("Error loading module list"), modFullname); return; } // remove all items (incase there are items there... freeTree(hwnd2Tree, 0); TreeView_DeleteAllItems(hwnd2Tree); TreeView_SelectItem(hwnd2Tree, 0); //image list TreeView_SetImageList(hwnd2Tree, himl, TVSIL_NORMAL); /// contact root item contacts_mtis.type = CONTACT_ROOT_ITEM; tvi.item.lParam = (LPARAM)&contacts_mtis; tvi.hParent = NULL; tvi.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_STATE | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.item.state = TVIS_BOLD; tvi.item.stateMask = TVIS_BOLD; tvi.item.cChildren = 1; tvi.hInsertAfter = TVI_FIRST; tvi.item.pszText = Translate("Contacts"); tvi.item.iImage = 3; tvi.item.iSelectedImage = 3; contactsRoot = TreeView_InsertItem(hwnd2Tree, &tvi); // add the settings item settings_mtis.type = STUB; tvi.item.lParam = (LPARAM)&settings_mtis; tvi.item.mask = TVIF_TEXT | TVIF_CHILDREN | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.item.cChildren = 1; tvi.hParent = NULL; tvi.hInsertAfter = TVI_FIRST; tvi.item.pszText = Translate("Settings"); tvi.item.iImage = 0; tvi.item.iSelectedImage = 0; contact = TreeView_InsertItem(hwnd2Tree, &tvi); // to fix bug with CHANGE NOTIFY on window activation TreeView_SelectItem(hwnd2Tree, contact); settings_mtis.type = CONTACT; hContact = 0; module = modlist.first; while (module) { if (!IsModuleEmpty(hContact, module->name)) { tvi.hParent = contact; tvi.hInsertAfter = TVI_SORT; tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; tvi.item.pszText = module->name; lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct)); lParam->hContact = hContact; tvi.item.iImage = 1; tvi.item.iSelectedImage = 2; lParam->type = KNOWN_MODULE; tvi.item.lParam = (LPARAM)lParam; TreeView_InsertItem(hwnd2Tree, &tvi); } module = (ModSetLinkLinkItem *)module->next; } if (db_get_b(NULL, modname, "ExpandSettingsOnOpen", 0)) TreeView_Expand(hwnd2Tree, contact, TVE_EXPAND); if (Select && hSelectedContact == NULL) { int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule); if (hItem != -1) { TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem); TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND); if (SelectedSetting[0]) SelectSetting(SelectedSetting); } Select = 0; } count = doContacts(hwnd2Tree, contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting); Select = 0; doItems(hwnd2Tree, &modlist, count); FreeModuleSettingLL(&modlist); } if (Select) { int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule); if (hItem != -1) { TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem); TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND); if (SelectedSetting[0]) SelectSetting(SelectedSetting); } } populating = 0; }
void __cdecl FindSettings(LPVOID di) { char* text = ((FindInfo*)di)->text; char* replace = ((FindInfo*)di)->replace; int mode = ((FindInfo*)di)->mode; HWND hwnd = ((FindInfo*)di)->hwnd; HWND prnthwnd = GetParent(hwnd); int options = ((FindInfo*)di)->options; ModuleSettingLL ModuleList, SettingList; ModSetLinkLinkItem *module, *setting; HANDLE hContact; DBVARIANT dbv = { 0 }; int caseSensitive = options & FW_CASE; int exactMatch = options & FW_EXACT; int inModuleName = options & FW_MODNAME; int inSettingName = options & FW_SETNAME; int inSettingValue = options & FW_SETVAL; int foundCount = 0; int replaceCount = 0; char szTmp[128]; int settingValue, isNumber, NULLContactDone = 0; freeItems(hwnd); if (!text) return; if (!EnumModules(&ModuleList)) { msg(Translate("Error Loading Module List"), modFullname); mir_free(di); return; } SendMessage(GetDlgItem(GetParent(hwnd), IDC_SBAR), SB_SETTEXT, 0, (LPARAM)Translate("Searching...")); hContact = 0; isNumber = sscanf(text, "%d", &settingValue); while (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA)) { if (!hContact) { if (NULLContactDone) break; else { NULLContactDone = 1; hContact = db_find_first(); } } else hContact = db_find_next(hContact); module = ModuleList.first; while (module) { if (IsModuleEmpty(hContact, module->name)) { module = module->next; continue; } if (!EnumSettings(hContact, module->name, &SettingList)) { msg(Translate("Error Loading Setting List"), modFullname); mir_free(text); mir_free(di); FreeModuleSettingLL(&ModuleList); return; } setting = SettingList.first; // check in settings value while (setting) { if (inSettingValue) { dbv.type = 0; // check the setting value if (!GetSetting(hContact, module->name, setting->name, &dbv)) { switch (dbv.type) { case DBVT_UTF8: // no conversion atm case DBVT_ASCIIZ: if ((exactMatch && !(caseSensitive ? strcmp(dbv.pszVal, text) : strcmpi(dbv.pszVal, text))) || (!exactMatch && (caseSensitive ? strstr(dbv.pszVal, text) : StrStrI(dbv.pszVal, text)))) { if ((mode & RW_FOUND) || (mode & RW_SETVAL)) replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode); else ItemFound(hwnd, hContact, module->name, setting->name, dbv.pszVal, FW_SETTINGVALUE); foundCount++; } break; case DBVT_BYTE: if (isNumber && settingValue == dbv.bVal) { if ((mode & RW_FOUND) || (mode & RW_SETVAL)) replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); else ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); foundCount++; } break; case DBVT_WORD: if (isNumber && settingValue == dbv.wVal) { if ((mode & RW_FOUND) || (mode & RW_SETVAL)) replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); else ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); foundCount++; } break; case DBVT_DWORD: if (isNumber && settingValue == (int)dbv.dVal) { if ((mode & RW_FOUND) || (mode & RW_SETVAL)) replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode); else ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE); foundCount++; } break; } db_free(&dbv); } } // check in setting name if (inSettingName) { if ((exactMatch && !(caseSensitive ? strcmp(setting->name, text) : strcmpi(setting->name, text))) || (!exactMatch && (caseSensitive ? StrStrI(setting->name, text) : StrStrI(setting->name, text)))) { if ((mode & RW_FOUND) || (mode & RW_SETNAME)) { if (!GetSetting(hContact, module->name, setting->name, &dbv)) { replaceCount += replaceSetting(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode); db_free(&dbv); } } else ItemFound(hwnd, hContact, module->name, setting->name, NULL, FW_SETTINGNAME); foundCount++; } } setting = (ModSetLinkLinkItem *)setting->next; } // check in module name if (inModuleName) { if ((exactMatch && !(caseSensitive ? strcmp(module->name, text) : strcmpi(module->name, text))) || (!exactMatch && (caseSensitive ? strstr(module->name, text) : StrStrI(module->name, text)))) { if ((mode & RW_FOUND) || (mode & RW_MODULE)) replaceCount += replaceModule(hwnd, hContact, module->name, text, replace, mode); else ItemFound(hwnd, hContact, module->name, 0, 0, FW_MODULE); foundCount++; } } FreeModuleSettingLL(&SettingList); module = (ModSetLinkLinkItem *)module->next; } } if (mode) { if (!replace[0]) mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were deleted."), foundCount, replaceCount); else mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found, %d items were replaced."), foundCount, replaceCount); } else mir_snprintf(szTmp, SIZEOF(szTmp), Translate("Finished. %d items were found."), foundCount); SendMessage(GetDlgItem(prnthwnd, IDC_SBAR), SB_SETTEXT, 0, (LPARAM)szTmp); SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA, 0); if (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA)) { SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA, 0); EnableWindow(GetDlgItem(prnthwnd, IDC_SEARCH), 1); SetWindowText(GetDlgItem(prnthwnd, IDOK), Translate("&Replace")); } else { SetWindowText(GetDlgItem(prnthwnd, IDC_SEARCH), Translate("&Search")); EnableWindow(GetDlgItem(prnthwnd, IDOK), 1); } mir_free(replace); mir_free(text); mir_free(di); FreeModuleSettingLL(&ModuleList); EnableWindow(GetDlgItem(prnthwnd, IDCANCEL), 1); }
void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. module == NULL export entire contact. { // hContact == -1, module == "" - all contacts FILE* file = NULL; char fileName[MAX_PATH]; int nullcontactDone = 0; ModuleSettingLL modlist; struct ModSetLinkLinkItem *mod; // enum all the modules if (!EnumModules(&modlist)) { msg(Translate("Error Loading Module List"),modFullname); return;} if (Openfile(fileName, ((int)hContact==-1)?NULL:module)) { if (!(file = fopen(fileName, "wt"))) { msg(Translate("Couldn't open file for writing"), modFullname); return; } SetCursor(LoadCursor(NULL,IDC_WAIT)); // exporting entire db if (hContact == INVALID_HANDLE_VALUE) { hContact = NULL; if (module == NULL) { fprintf(file, "SETTINGS:\n"); mod = modlist.first; while(mod) { if (IsModuleEmpty(hContact, mod->name)) { mod = (struct ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } } else { if (module == "") module = NULL; // reset module for all contacts export } hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); while (hContact) { if (!hContact) continue; // filter if (Mode != MODE_ALL) { char szProto[256]; int loaded = 0; if (GetValue(hContact,"Protocol","p",szProto,SIZEOF(szProto))) loaded = IsProtocolLoaded(szProto); if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) { hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); continue; } } fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact)); if (module == NULL) // export all modules { mod = modlist.first; while(mod) { if (IsModuleEmpty(hContact, mod->name)) { mod = (struct ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } } else // export module { exportModule(hContact, module, file); } hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)(HANDLE)hContact, 0); } } // exporting a contact else { if (!module) // exporting every module { if (hContact) fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact)); else fprintf(file, "SETTINGS:\n"); mod = modlist.first; while(mod) { if (IsModuleEmpty(hContact, mod->name)) { mod = (struct ModSetLinkLinkItem *)mod->next; continue; } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; if (mod) fprintf(file, "\n"); } } else { if (hContact) fprintf(file, "FROM CONTACT: %s\n", NickFromHContact(hContact)); else fprintf(file, "SETTINGS:\n"); exportModule(hContact, module, file); } } fclose(file); SetCursor(LoadCursor(NULL,IDC_ARROW)); } FreeModuleSettingLL(&modlist); }