Ejemplo n.º 1
0
int deleteModule(char* module, MCONTACT hContact, int fromMenu)
{
	char msg[1024];
	ModuleSettingLL settinglist;
	ModSetLinkLinkItem *setting;

	if (!module) return 0;

	if (!fromMenu) {
		mir_snprintf(msg, SIZEOF(msg), Translate("Are you sure you want to delete module \"%s\"?"), module);
		if (db_get_b(NULL,modname, "WarnOnDelete",1))
			if (MessageBox(0,msg, Translate("Confirm Module Deletion"), MB_YESNO|MB_ICONEXCLAMATION) == IDNO)
				return 0;
	}

	if (!EnumSettings(hContact,module,&settinglist)) return 0;

	setting = settinglist.first;
	while (setting)
	{
		db_unset(hContact, module, setting->name);
		setting = setting->next;
	}
	FreeModuleSettingLL(&settinglist);
	return 1;
}
Ejemplo n.º 2
0
int renameModule(MCONTACT hContact, const char *oldName, const char *newName)
{
	ModuleSettingLL settinglist;
	if (IsModuleEmpty(hContact, oldName) || !EnumSettings(hContact, oldName, &settinglist))
		return 0;

	int cnt = 0;

	for (ModSetLinkLinkItem *setting = settinglist.first; setting; setting = setting->next) {
		DBVARIANT dbv;
		if (!db_get_s(hContact, oldName, setting->name, &dbv, 0)) {
			db_set(hContact, newName, setting->name, &dbv);
			db_unset(hContact, oldName, setting->name);
			db_free(&dbv);
			cnt++;
		}
	}
	FreeModuleSettingLL(&settinglist);
	return cnt;
}
Ejemplo n.º 3
0
void renameModule(char* oldName, char* newName, HANDLE hContact)
{
	DBVARIANT dbv;
	ModuleSettingLL settinglist;
	ModSetLinkLinkItem *setting;

	if (!EnumSettings(hContact, oldName, &settinglist)) { msg(Translate("Error Loading Setting List"), modFullname); return; }

	setting = settinglist.first;
	while (setting) {
		if (!GetSetting(hContact, oldName, setting->name, &dbv)) {
			switch (dbv.type) {
			case DBVT_BYTE:
				db_set_b(hContact, newName, setting->name, dbv.bVal);
				break;
			case DBVT_WORD:
				db_set_w(hContact, newName, setting->name, dbv.wVal);
				break;
			case DBVT_DWORD:
				db_set_dw(hContact, newName, setting->name, dbv.dVal);
				break;
			case DBVT_ASCIIZ:
				db_set_s(hContact, newName, setting->name, dbv.pszVal);
				break;
			case DBVT_UTF8:
				db_set_utf(hContact, newName, setting->name, dbv.pszVal);
				break;
			case DBVT_BLOB:
				db_set_blob(hContact, newName, setting->name, dbv.pbVal, dbv.cpbVal);
				break;

			}
			db_unset(hContact, oldName, setting->name);
		}
		db_free(&dbv);
		setting = (ModSetLinkLinkItem *)setting->next;
	}
	FreeModuleSettingLL(&settinglist);
}
Ejemplo n.º 4
0
void copyModule(char* module, MCONTACT hContactFrom, MCONTACT hContactTo)
{
	ModuleSettingLL msll;

	EnumSettings(hContactFrom, module, &msll);

	ModSetLinkLinkItem *setting = msll.first;
	while (setting) {
		DBVARIANT dbv;
		if (!GetSetting(hContactFrom, module, setting->name, &dbv)) {
			switch (dbv.type) {
			case DBVT_BYTE:
				db_set_b(hContactTo, module, setting->name, dbv.bVal);
				break;
			case DBVT_WORD:
				db_set_w(hContactTo, module, setting->name, dbv.wVal);
				break;
			case DBVT_DWORD:
				db_set_dw(hContactTo, module, setting->name, dbv.dVal);
				break;
			case DBVT_ASCIIZ:
				db_set_s(hContactTo, module, setting->name, dbv.pszVal);
				break;
			case DBVT_UTF8:
				db_set_utf(hContactTo, module, setting->name, dbv.pszVal);
				break;
			case DBVT_BLOB:
				db_set_blob(hContactTo, module, setting->name, dbv.pbVal, dbv.cpbVal);
				break;
			}
		}
		db_free(&dbv);
		setting = setting->next;
	}
	FreeModuleSettingLL(&msll);
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
// 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;
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *find, const char *replace, int mode)
{
	ModuleSettingLL msll;
	ModSetLinkLinkItem *setting;
	char *myreplace = NULL;
	char *newModule;
	int count = 0;

	if (mode & RW_FULL)
		newModule = (char*)replace;
	else {
		myreplace = multiReplace(module, find, replace, mode & RW_CASE);
		newModule = myreplace;
	}

	if (newModule[0] == 0) {
		ItemFound(hwnd, hContact, module, NULL, NULL, FW_MODULE | FW_DELETED);
		deleteModule((char*)module, hContact, 1);
		replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, NULL);
		mir_free(myreplace);
		return 1;
	}

	if (!IsModuleEmpty(hContact, newModule))
		return 0;

	if (EnumSettings(hContact, (char*)module, &msll)) {
		setting = msll.first;

		while (setting) {
			DBVARIANT dbv;

			if (!GetSetting(hContact, module, setting->name, &dbv)) {
				switch (dbv.type) {
				case DBVT_BYTE:
					db_set_b(hContact, newModule, setting->name, dbv.bVal);
					break;
				case DBVT_WORD:
					db_set_w(hContact, newModule, setting->name, dbv.wVal);
					break;
				case DBVT_DWORD:
					db_set_dw(hContact, newModule, setting->name, dbv.dVal);
					break;
				case DBVT_ASCIIZ:
					db_set_s(hContact, newModule, setting->name, dbv.pszVal);
					break;
				case DBVT_UTF8:
					db_set_utf(hContact, newModule, setting->name, dbv.pszVal);
					break;
				case DBVT_BLOB:
					db_set_blob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal);
					break;
				}

				db_free(&dbv);
				db_unset(hContact, module, setting->name);
			}

			setting = setting->next;
		}
		FreeModuleSettingLL(&msll);

		replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, newModule);

		ItemFound(hwnd, hContact, newModule, NULL, NULL, FW_MODULE | FW_REPLACED);
		count++;
	}

	mir_free(myreplace);
	return count;
}
Ejemplo n.º 9
0
void exportModule(HANDLE hContact, char* module, FILE* file)
{
	char tmp[32];
	ModuleSettingLL settinglist;
	struct ModSetLinkLinkItem *setting;

	EnumSettings(hContact,module,&settinglist);

	// print the module header..
	fprintf(file, "\n[%s]", module);
	setting = settinglist.first;
	while(setting)
	{
		DBVARIANT dbv;
		if (!GetSetting(hContact, module, setting->name, &dbv))
		{
			switch (dbv.type)
			{
				case DBVT_BYTE:
					fprintf(file, "\n%s=b%s", setting->name, itoa(dbv.bVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_WORD:
					fprintf(file, "\n%s=w%s", setting->name, itoa(dbv.wVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_DWORD:
					fprintf(file, "\n%s=d%s", setting->name, itoa(dbv.dVal,tmp,10));
					DBFreeVariant(&dbv);
					break;
				case DBVT_ASCIIZ:
				case DBVT_UTF8:
						if (strchr(dbv.pszVal, '\r'))
						{
							char *end = StrReplace("\\", "\\\\", dbv.pszVal);
							end = StrReplace("\r", "\\r", end);
							end = StrReplace("\n", "\\n", end);
							fprintf(file, "\n%s=g%s", setting->name, end);
							break;
						}
						if (dbv.type == DBVT_UTF8)
							fprintf(file, "\n%s=u%s", setting->name, dbv.pszVal);
						else
							fprintf(file, "\n%s=s%s", setting->name, dbv.pszVal);
						DBFreeVariant(&dbv);
						break;
				case DBVT_BLOB:
				{
					int j;
					char *data = NULL;
					if (!(data = (char*)mir_alloc( 3*(dbv.cpbVal+1)*sizeof(char)) ))
						break;
					data[0] = '\0';
					for (j=0; j<dbv.cpbVal; j++)
					{
						char tmp[16];
						mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv.pbVal[j]);
						strcat(data, tmp);
					}
					fprintf(file,"\n%s=n%s",setting->name , data);
					mir_free(data);
				}
				DBFreeVariant(&dbv);
				break;
			}
		}
		setting = (struct ModSetLinkLinkItem *)setting->next;
	}
	FreeModuleSettingLL(&settinglist);
}
Ejemplo n.º 10
0
void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam)
{
	LVITEM lvItem;
	int index;
	char data[32], tmp[32];
	DBVARIANT *dbv = &(lParam->dbv);
	MCONTACT hContact = lParam->hContact;
	char *module = lParam->module;
	char *setting = lParam->setting;
	if (!module) return;
	lvItem.lParam = (LPARAM)lParam->hContact;
	lvItem.mask = LVIF_TEXT|LVIF_PARAM;
	lvItem.iItem = 0;
	lvItem.iSubItem = 0;

	if (!setting || (int)(lParam->setting) == WATCH_MODULE) // add every item in the module and return
	{
		ModuleSettingLL settinglist;
		struct DBsetting dummy;
		ModSetLinkLinkItem *setting;
		if (!EnumSettings(hContact,module,&settinglist)) return;
		dummy.hContact = hContact;
		dummy.module = mir_tstrdup(module);
		setting = settinglist.first;
		while (setting)
		{
			dummy.setting = setting->name;
			addwatchtolist(hwnd2list, &dummy);
			setting = (ModSetLinkLinkItem *)setting->next;
		}
		mir_free(dummy.module);
		FreeModuleSettingLL(&settinglist);
		return;
	}
	db_free(&(lParam->dbv));
	if (GetSetting(hContact, module, setting, &(lParam->dbv))) return;

	if (!hContact)
		lvItem.pszText = "NULL";
	else
		lvItem.pszText = (char*)GetContactName(hContact, NULL, 1);

	index = ListView_InsertItem(hwnd2list,&lvItem);

	WCHAR* ptszText = mir_a2u(lvItem.pszText);
	ListView_SetItemTextW(hwnd2list, index, 0, ptszText);
	mir_free(ptszText);

	ListView_SetItemText(hwnd2list,index,1,module);
	ListView_SetItemText(hwnd2list,index,2,setting);

	switch (dbv->type) {
	case DBVT_BLOB:
		{
			int j;
			char *data = NULL;
			if (!(data = (char*)mir_realloc(data, 3*(dbv->cpbVal+1))    ))
				return;
			data[0] = '\0';
			for (j=0; j<dbv->cpbVal; j++)
			{
				char tmp[16];
				mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)dbv->pbVal[j]);
				strcat(data, tmp);
			}
			ListView_SetItemText(hwnd2list,index,4,data);
			ListView_SetItemText(hwnd2list,index,3,"BLOB");
			mir_free(data);
		}
		break;

	case DBVT_BYTE:
		mir_snprintf(data, 32, "0x%02X (%s)", dbv->bVal, itoa(dbv->bVal,tmp,10));
		ListView_SetItemText(hwnd2list,index,4,data);
		ListView_SetItemText(hwnd2list,index,3,"BYTE");
		break;

	case DBVT_WORD:
		mir_snprintf(data, 32, "0x%04X (%s)", dbv->wVal, itoa(dbv->wVal,tmp,10));
		ListView_SetItemText(hwnd2list,index,4,data);
		ListView_SetItemText(hwnd2list,index,3,"WORD");
		break;

	case DBVT_DWORD:
		mir_snprintf(data, 32, "0x%08X (%s)", dbv->dVal, itoa(dbv->dVal,tmp,10));
		ListView_SetItemText(hwnd2list,index,4,data);
		ListView_SetItemText(hwnd2list,index,3,"DWORD");
		break;

	case DBVT_ASCIIZ:
		ListView_SetItemText(hwnd2list,index,4,dbv->pszVal);
		ListView_SetItemText(hwnd2list,index,3,"STRING");
		break;

	case DBVT_UTF8:
		int length = (int)strlen(dbv->pszVal) + 1;
		WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
		MultiByteToWideChar(CP_UTF8, 0, dbv->pszVal, -1, wc, length);
		ListView_SetItemTextW(hwnd2list,index,4,wc);
		ListView_SetItemText(hwnd2list,index,3,"UNICODE");
		break;
	}
}