static int MoveGroupBefore(WPARAM wParam,LPARAM lParam)
{
	int i,shuffleFrom,shuffleTo,shuffleDir;
	char str[33];
	TCHAR *szMoveName;
	DBVARIANT dbv;

	if (wParam == 0 || (LPARAM) wParam == lParam)
		return 0;
	itoa(wParam-1,str,10);
	if (DBGetContactSettingTString(NULL, "CListGroups", str, &dbv))
		return 0;
	szMoveName = dbv.ptszVal;
	//shuffle list of groups up to fill gap
	if (lParam == 0) {
		shuffleFrom = wParam - 1;
		shuffleTo = -1;
		shuffleDir = -1;
	}
	else {
		if ((LPARAM) wParam < lParam) {
			shuffleFrom = wParam - 1;
			shuffleTo = lParam - 2;
			shuffleDir = -1;
		}
	else {
			shuffleFrom = wParam - 1;
			shuffleTo = lParam - 1;
			shuffleDir = 1;
		}
	}
	if(shuffleDir==-1) {
		for(i=shuffleFrom;i!=shuffleTo;i++) {
			itoa(i+1,str,10);
			if (DBGetContactSettingStringUtf(NULL, "CListGroups", str, &dbv)) {
				shuffleTo = i;
				break;
			}
			itoa(i,str,10);
			DBWriteContactSettingStringUtf(NULL, "CListGroups", str, dbv.pszVal);
			DBFreeVariant(&dbv);
		}
	}
	else {
		for(i=shuffleFrom;i!=shuffleTo;i--) {
			itoa(i-1,str,10);
			if (DBGetContactSettingStringUtf(NULL, "CListGroups", str, &dbv)) {
				mir_free(szMoveName);
				return 1;
			}                   //never happens
			itoa(i,str,10);
			DBWriteContactSettingStringUtf(NULL, "CListGroups", str, dbv.pszVal);
			DBFreeVariant(&dbv);
		}
	}
	itoa(shuffleTo,str,10);
	DBWriteContactSettingTString(NULL, "CListGroups", str, szMoveName);
	mir_free(szMoveName);
	return shuffleTo+1;
}
示例#2
0
/** Convert the contact chosen into a MetaContact.
*
* Create a new MetaContact, remove the selected contact from the \c CList
* and attach it to the MetaContact.
*
* @param wParam :	\c HANDLE to the contact that has been chosen.
* @param lParam :	Allways set to 0.
*/
INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam)
{
	HANDLE hMetaContact;
	DBVARIANT dbv;
	char *group = 0;//, *proto;
		
	// Get some information about the selected contact.
//	proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0);
	if(!DBGetContactSettingStringUtf((HANDLE)wParam,"CList","Group",&dbv)) {
		group = _strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}

	// Create a new metacontact
	hMetaContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0);
			
	// Add the info for the metacontact
	if(hMetaContact)
	{

		DBWriteContactSettingDword(hMetaContact,META_PROTO,META_ID,nextMetaID);
		DBWriteContactSettingDword(hMetaContact,META_PROTO,"NumContacts",0);
		DBWriteContactSettingDword(NULL,META_PROTO,"NextMetaID",++nextMetaID);

		// Add the MetaContact protocol to the new meta contact
		CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hMetaContact, ( LPARAM )META_PROTO );

		if(group) {
			if(ServiceExists(MS_DB_CONTACT_GETSETTING_STR))
				DBWriteContactSettingStringUtf(hMetaContact,"CList","Group",group);
			else
				DBWriteContactSettingString(hMetaContact,"CList","Group",group);
		}
		
		// Assign the contact to the MetaContact just created (and make default).
		if(!Meta_Assign((HANDLE)wParam,hMetaContact,TRUE)) {
			MessageBox(0,Translate("There was a problem in assigning the contact to the MetaContact"),Translate("Error"),MB_ICONEXCLAMATION);
			CallService(MS_DB_CONTACT_DELETE, (WPARAM)hMetaContact, 0);
			return 0;
		}

		// hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled)
		if(!Meta_IsEnabled())
			DBWriteContactSettingByte(hMetaContact, "CList", "Hidden", 1);

	}

	//	Update the graphics
	CallService(MS_CLUI_SORTLIST,0,0);

	free(group);
	return (int)hMetaContact;
}
static int SetGroupExpandedState(WPARAM wParam,LPARAM lParam)
{
	char idstr[33];
	DBVARIANT dbv;

	itoa(wParam-1,idstr,10);
	if (DBGetContactSettingStringUtf(NULL, "CListGroups", idstr, &dbv))
		return 1;
	if (lParam)
		dbv.pszVal[0] |= GROUPF_EXPANDED;
	else
		dbv.pszVal[0] = dbv.pszVal[0] & ~GROUPF_EXPANDED;
	DBWriteContactSettingStringUtf(NULL, "CListGroups", idstr, dbv.pszVal);
	DBFreeVariant(&dbv);
	return 0;
}
static int SetGroupFlags(WPARAM wParam,LPARAM lParam)
{
	char idstr[33];
	DBVARIANT dbv;
	int flags,oldval,newval;

	itoa(wParam-1,idstr,10);
	if (DBGetContactSettingStringUtf(NULL, "CListGroups", idstr, &dbv))
		return 1;
	flags=LOWORD(lParam)&HIWORD(lParam);
	oldval=dbv.pszVal[0];
	newval=dbv.pszVal[0]=(dbv.pszVal[0]&~HIWORD(lParam))|flags;
	DBWriteContactSettingStringUtf(NULL, "CListGroups", idstr, dbv.pszVal);
	DBFreeVariant(&dbv);
	if ((oldval & GROUPF_HIDEOFFLINE) != (newval & GROUPF_HIDEOFFLINE))
		LoadContactTree();
	return 0;
}
static int DeleteGroup(WPARAM wParam,LPARAM lParam)
{
	int i;
	char str[33];
	DBVARIANT dbv;
	HANDLE hContact;
	TCHAR name[256], szNewParent[256], *pszLastBackslash;

	//get the name
	itoa(wParam-1,str,10);
	if (DBGetContactSettingTString(NULL, "CListGroups", str, &dbv))
		return 1;
	if (DBGetContactSettingByte(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT))
		if (MessageBox((HWND)CallService(MS_CLUI_GETHWND, 0, 0), TranslateT("Are you sure you want to delete this group?  This operation can not be undone."), TranslateT("Delete Group"), MB_YESNO|MB_ICONQUESTION)==IDNO)
			return 1;
	lstrcpyn(name, (TCHAR*)dbv.ptszVal + 1, SIZEOF(name));
	DBFreeVariant(&dbv);
	SetCursor(LoadCursor(NULL,IDC_WAIT));
	//must remove setting from all child contacts too
	//children are demoted to the next group up, not deleted.
	lstrcpy(szNewParent, name);
	pszLastBackslash = _tcsrchr(szNewParent, '\\');
	if (pszLastBackslash)
		pszLastBackslash[0] = '\0';
	else
		szNewParent[0] = '\0';
	hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
	do {
		if (DBGetContactSettingTString(hContact, "CList", "Group", &dbv))
			continue;
		if (_tcscmp(dbv.ptszVal, name)) {
		DBFreeVariant(&dbv);
			continue;
		}
		DBFreeVariant(&dbv);
		if (szNewParent[0])
			DBWriteContactSettingTString(hContact, "CList", "Group", szNewParent);
		else
			DBDeleteContactSetting(hContact, "CList", "Group");
	} while((hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0))!=NULL);
	//shuffle list of groups up to fill gap
	for(i=wParam-1;;i++) {
		itoa(i+1,str,10);
		if (DBGetContactSettingStringUtf(NULL, "CListGroups", str, &dbv))
			break;
		itoa(i,str,10);
		DBWriteContactSettingStringUtf(NULL, "CListGroups", str, dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	itoa(i,str,10);
	DBDeleteContactSetting(NULL,"CListGroups",str);
	//rename subgroups
	{
		TCHAR szNewName[256];
		int len;

		len = lstrlen(name);
		for(i=0;;i++) {
			itoa(i,str,10);
			if (DBGetContactSettingTString(NULL, "CListGroups", str, &dbv))
				break;
			if (!_tcsncmp((TCHAR*)dbv.ptszVal + 1, name, len) && dbv.ptszVal[len + 1] == '\\' && _tcschr(dbv.ptszVal + len + 2, '\\') == NULL) {
				if (szNewParent[0])
					mir_sntprintf(szNewName, SIZEOF(szNewName), _T("%s\\%s"), szNewParent, dbv.ptszVal + len + 2);
				else
					lstrcpyn(szNewName, dbv.ptszVal + len + 2, SIZEOF(szNewName));
				RenameGroupT((WPARAM)(i + 1), (LPARAM)szNewName);
			}
			DBFreeVariant(&dbv);
		}
	}
	SetCursor(LoadCursor(NULL,IDC_ARROW));
	LoadContactTree();
	return 0;
}
示例#6
0
static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN)
{
	FILE *fp = _tfopen(szIniPath, _T("rt"));
	if ( fp == NULL )
		return;

	bool warnThisSection = false;
	char szSection[128]; szSection[0] = 0;

	while(!feof(fp)) {
		char szLine[2048];
		if (fgets(szLine,sizeof(szLine),fp) == NULL) 
			break;

		int lineLength = lstrlenA(szLine);
		while (lineLength && (BYTE)(szLine[lineLength-1])<=' ')
			szLine[--lineLength]='\0';

		if (szLine[0]==';' || szLine[0]<=' ') 
			continue;

		if (szLine[0]=='[') {
			char *szEnd = strchr(szLine+1,']');
			if (szEnd == NULL)
				continue;

			if (szLine[1] == '!')
				szSection[0] = '\0';
			else {
				lstrcpynA(szSection,szLine+1,min(sizeof(szSection),(int)(szEnd-szLine)));
				switch (secur) {
				case 0:
					warnThisSection = false;
					break;

				case 1:
					warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections);
					break;

				case 2:
					warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections);
					break;

				default:
					warnThisSection = true;
					break;
				}
				if (secFN) warnThisSection=0;
			}
			if (szLine[1] == '?') {
				DBCONTACTENUMSETTINGS dbces;
				dbces.pfnEnumProc=SettingsEnumProc;
				lstrcpynA(szSection,szLine+2,min(sizeof(szSection),(int)(szEnd-szLine-1)));
				dbces.szModule=szSection;
				dbces.ofsSettings=0;
				CallService(MS_DB_CONTACT_ENUMSETTINGS,0,(LPARAM)&dbces);
				while (setting_items) {
					SettingsList *next = setting_items->next;

					DBCONTACTGETSETTING dbcgs;
					dbcgs.szModule = szSection;
					dbcgs.szSetting = setting_items->name;
					CallService(MS_DB_CONTACT_DELETESETTING, 0, (LPARAM)&dbcgs);

					mir_free(setting_items->name);
					mir_free(setting_items);
					setting_items = next;
				}
			}
			continue;
		}

		if(szSection[0]=='\0')
			continue;

		char *szValue=strchr(szLine,'=');
		if ( szValue == NULL )
			continue;

		char szName[128];
		lstrcpynA(szName,szLine,min(sizeof(szName),(int)(szValue-szLine+1)));
		szValue++;
		{
			warnSettingChangeInfo_t warnInfo;
			warnInfo.szIniPath=szIniPath;
			warnInfo.szName=szName;
			warnInfo.szSafeSections=szSafeSections;
			warnInfo.szSection=szSection;
			warnInfo.szUnsafeSections=szUnsafeSections;
			warnInfo.szValue=szValue;
			warnInfo.warnNoMore=0;
			warnInfo.cancel=0;
			if(warnThisSection && IDNO==DialogBoxParam(hMirandaInst,MAKEINTRESOURCE(IDD_WARNINICHANGE),NULL,WarnIniChangeDlgProc,(LPARAM)&warnInfo))
				continue;
			if(warnInfo.cancel)
				break;
			if(warnInfo.warnNoMore)
				warnThisSection=0;
		}

		switch(szValue[0]) {
		case 'b':
		case 'B':
			DBWriteContactSettingByte(NULL,szSection,szName,(BYTE)strtol(szValue+1,NULL,0));
			break;
		case 'w':
		case 'W':
			DBWriteContactSettingWord(NULL,szSection,szName,(WORD)strtol(szValue+1,NULL,0));
			break;
		case 'd':
		case 'D':
			DBWriteContactSettingDword(NULL,szSection,szName,(DWORD)strtoul(szValue+1,NULL,0));
			break;
		case 'l':
		case 'L':
			DBDeleteContactSetting(NULL,szSection,szName);
			break;
		case 'e':
		case 'E':
			ConvertBackslashes(szValue+1, LangPackGetDefaultCodePage());
		case 's':
		case 'S':
			DBWriteContactSettingString(NULL,szSection,szName,szValue+1);
			break;
		case 'g':
		case 'G':
			{	char *pstr;
				for(pstr=szValue+1;*pstr;pstr++){
					if(*pstr=='\\'){
						switch(pstr[1]){
						case 'n': *pstr='\n'; break;
						case 't': *pstr='\t'; break;
						case 'r': *pstr='\r'; break;
						default:  *pstr=pstr[1]; break;
						}
						MoveMemory(pstr+1,pstr+2,lstrlenA(pstr+2)+1);
			}	}	}
		case 'u':
		case 'U':
			DBWriteContactSettingStringUtf(NULL,szSection,szName,szValue+1);
			break;
		case 'n':
		case 'h':
		case 'N':
		case 'H':
			{	PBYTE buf;
				int len;
				char *pszValue,*pszEnd;
				DBCONTACTWRITESETTING cws;

				buf=(PBYTE)mir_alloc(lstrlenA(szValue+1));
				for(len=0,pszValue=szValue+1;;len++) {
					buf[len]=(BYTE)strtol(pszValue,&pszEnd,0x10);
					if(pszValue==pszEnd) break;
					pszValue=pszEnd;
				}
				cws.szModule=szSection;
				cws.szSetting=szName;
				cws.value.type=DBVT_BLOB;
				cws.value.pbVal=buf;
				cws.value.cpbVal=len;
				CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)(HANDLE)NULL,(LPARAM)&cws);
				mir_free(buf);
			}
			break;
		default:
			MessageBox(NULL,TranslateT("Invalid setting type. The first character of every value must be b, w, d, l, s, e, u, g, h or n."),TranslateT("Install Database Settings"),MB_OK);
			break;
		}
	}
	fclose(fp);
}
INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_INITDIALOG:
		{
			char tmp[32];
			SetWindowLongPtr(hwnd,GWLP_USERDATA,(LPARAM)lParam);
			switch (((struct DBsetting*)lParam)->dbv.type)
			{
				case DBVT_BYTE:
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_HIDE);
					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New BYTE value"));
					}
					else
					{
						SetWindowText(hwnd, Translate("Edit BYTE value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
						SetDlgItemText(hwnd, IDC_SETTINGVALUE, itoa(((struct DBsetting*)lParam)->dbv.bVal, tmp, 10));
					}
					CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_DECIMAL);
					CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_BYTE);
				break;
				case DBVT_WORD:
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_HIDE);
					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New WORD value"));
					}
					else
					{
						SetWindowText(hwnd, Translate("Edit WORD value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
						SetDlgItemText(hwnd, IDC_SETTINGVALUE, itoa(((struct DBsetting*)lParam)->dbv.wVal, tmp, 10));
					}
					CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_DECIMAL);
					CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_WORD);
				break;
				case DBVT_DWORD:
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_HIDE);
					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New DWORD value"));
					}
					else
					{
						char text[32];
						SetWindowText(hwnd, Translate("Edit DWORD value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
						mir_snprintf(text, SIZEOF(text), "%X", ((struct DBsetting*)lParam)->dbv.dVal);
						SetDlgItemText(hwnd, IDC_SETTINGVALUE, text);
					}
					CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_HEX);
					CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_DWORD);
				break;
				case DBVT_ASCIIZ:
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_SHOW);
					ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_HEX),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_BASE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_TYPE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_BYTE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_WORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DWORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_STRING),SW_HIDE);
					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New STRING value"));
					}
					else
					{
						SetWindowText(hwnd, Translate("Edit STRING value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
						SetDlgItemText(hwnd, IDC_STRING, ((struct DBsetting*)lParam)->dbv.pszVal);
					}
				break;
				case DBVT_UTF8:
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_SHOW);
					ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_HEX),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_BASE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_TYPE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_BYTE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_WORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DWORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_STRING),SW_HIDE);
					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New UNICODE value"));
					}
					else
					{
						char *tmp = (((struct DBsetting*)lParam)->dbv.pszVal);
						if (UOS)
						{
							int length = (int)strlen(tmp) + 1;
							WCHAR *wc = (WCHAR*)_malloca(length*sizeof(WCHAR));
							MultiByteToWideChar(CP_UTF8, 0, tmp, -1, wc, length);
							SendMessageW(GetDlgItem(hwnd, IDC_STRING), WM_SETTEXT, 0, (LPARAM)wc);
						}
						else {
							// convert from UTF8
							SetDlgItemText(hwnd, IDC_STRING, tmp);
						}
						SetWindowText(hwnd, Translate("Edit UNICODE value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
					}
				break;
				case DBVT_BLOB:
				{
					ShowWindow(GetDlgItem(hwnd, IDC_STRING),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, IDC_BLOB),SW_SHOW);

					if (!((struct DBsetting*)lParam)->setting[0])
					{
						SetWindowText(hwnd, Translate("New BLOB value"));
					}
					else
					{
						int j;
						char tmp[16];
						int len = ((struct DBsetting*)lParam)->dbv.cpbVal;
						char *data = (char*)_malloca(3*(len+1)+10);
						BYTE *p = ((struct DBsetting*)lParam)->dbv.pbVal;

						if (!data) return TRUE;
						data[0] = '\0';

						for(j=0; j<len; j++)
						{
							mir_snprintf(tmp, SIZEOF(tmp), "%02X ", (BYTE)p[j]);
							strcat(data, tmp);
						}

						SetWindowText(hwnd, Translate("Edit BLOB value"));
						SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
						SetDlgItemText(hwnd, IDC_BLOB, data);
					}
					ShowWindow(GetDlgItem(hwnd, CHK_HEX),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_BASE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, GRP_TYPE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_BYTE),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_WORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_DWORD),SW_HIDE);
					ShowWindow(GetDlgItem(hwnd, CHK_STRING),SW_HIDE);
				}
				break;
				default: return TRUE;
			}
			TranslateDialogDefault(hwnd);
		}
		return TRUE;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case CHK_BYTE:
				case CHK_WORD:
				case CHK_DWORD:
					EnableWindow(GetDlgItem(hwnd, CHK_HEX),1);
					EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL),1);
					CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
				break;
				case CHK_STRING:
					EnableWindow(GetDlgItem(hwnd, CHK_HEX),0);
					EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL),0);
					CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
				break;

				case CHK_HEX:
				case CHK_DECIMAL:
					CheckRadioButton(hwnd,CHK_HEX, CHK_DECIMAL, LOWORD(wParam));
					{
						char *setting, temp[32];
						int settingLength, tmp;
						settingLength = GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGVALUE));
						if (settingLength)
						{
							setting = (char*)_malloca(settingLength + 1);
							if (setting)
							{
								// havta convert it with sprintf()
								GetWindowText(GetDlgItem(hwnd, IDC_SETTINGVALUE), setting, settingLength+1);
								if (LOWORD(wParam) == CHK_DECIMAL && IsDlgButtonChecked(hwnd, CHK_DECIMAL))
								{
									sscanf(setting, "%X", &tmp);
									mir_snprintf(temp, SIZEOF(temp), "%ld", tmp);
								}
								else
								{
									sscanf(setting, "%d", &tmp);
									mir_snprintf(temp, SIZEOF(temp), "%X", tmp);
								}
								SetWindowText(GetDlgItem(hwnd, IDC_SETTINGVALUE), temp);
							}
						}
					}
				break;
				case IDOK:
				{
					struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
					char *setting, *value;
					int settingLength, valueLength, valueID = IDC_SETTINGVALUE;
					settingLength = GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGNAME));

					if (IsWindowVisible(GetDlgItem(hwnd,IDC_STRING)))
						valueID = IDC_STRING;
					else
					if (IsWindowVisible(GetDlgItem(hwnd,IDC_SETTINGVALUE)))
						valueID = IDC_SETTINGVALUE;
					else
					if (IsWindowVisible(GetDlgItem(hwnd,IDC_BLOB)))
						valueID = IDC_BLOB;
					else
						break;

					valueLength = GetWindowTextLength(GetDlgItem(hwnd, valueID));

					if (dbsetting->dbv.type == DBVT_UTF8 && UOS)
						valueLength *= sizeof(WCHAR);

					if (settingLength)
					{
						int settingValue;
						setting = (char*)_malloca(settingLength + 1);

						if (valueLength)
							value = (char*)_malloca(valueLength + 2);
						else
							value = (char*)_malloca(2);

						if (!setting || !value)
						{
							msg(Translate("Couldnt allocate enough memory!"), modFullname);
							DestroyWindow(hwnd);
							break;
						}

						GetWindowText(GetDlgItem(hwnd, IDC_SETTINGNAME), setting, settingLength+1);

						if (valueLength)
						{
							if (dbsetting->dbv.type == DBVT_UTF8 && UOS)
								SendMessageW(GetDlgItem(hwnd, valueID), WM_GETTEXT, valueLength+2, (LPARAM)value);
							else
								GetWindowText(GetDlgItem(hwnd, valueID), value, valueLength+1);
						}
						else
						if (IsWindowVisible(GetDlgItem(hwnd,IDC_STRING)) || (saveAsType(hwnd)==3))
							memcpy(value,"\0\0",2);
						else
							strcpy(value,"0");

						// delete the old setting
						if (mir_strcmp(setting, dbsetting->setting) && dbsetting->setting && (dbsetting->setting)[0] != 0)
							DBDeleteContactSetting(dbsetting->hContact, dbsetting->module, dbsetting->setting);

						// delete the setting if we are saving as a different type
						switch (dbsetting->dbv.type)
						{
							case DBVT_BYTE:
								if (saveAsType(hwnd) != 0) DBDeleteContactSetting(dbsetting->hContact, dbsetting->module, setting);
							break;
							case DBVT_WORD:
								if (saveAsType(hwnd) != 1) DBDeleteContactSetting(dbsetting->hContact, dbsetting->module, setting);
							break;
							case DBVT_DWORD:
								if (saveAsType(hwnd) != 2) DBDeleteContactSetting(dbsetting->hContact, dbsetting->module, setting);
							break;
							//case DBVT_ASCIIZ:
								//DBWriteContactSettingString(dbsetting->hContact, dbsetting->module, setting, value);
							//break;
						}
						// write the setting
						switch (saveAsType(hwnd))
						{
							case 0:
								if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
								else sscanf(value, "%d", &settingValue);
								DBWriteContactSettingByte(dbsetting->hContact, dbsetting->module, setting, (BYTE)settingValue);
							break;
							case 1:
								if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
								else sscanf(value, "%d", &settingValue);
								DBWriteContactSettingWord(dbsetting->hContact, dbsetting->module, setting, (WORD)settingValue);
							break;
							case 2:
								if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
								else sscanf(value, "%d", &settingValue);
								DBWriteContactSettingDword(dbsetting->hContact, dbsetting->module, setting, (DWORD)settingValue);
							break;
							case 3:
								if (dbsetting->dbv.type == DBVT_UTF8)
								{
									if (UOS)
										DBWriteContactSettingWString(dbsetting->hContact, dbsetting->module, setting, (WCHAR*)value);
									else
										DBWriteContactSettingStringUtf(dbsetting->hContact, dbsetting->module, setting, value);
								}
								else
								if (dbsetting->dbv.type == DBVT_BLOB)
									WriteBlobFromString(dbsetting->hContact,dbsetting->module,setting,value,valueLength);
								else
								if (dbsetting->dbv.type == DBVT_ASCIIZ)
									DBWriteContactSettingString(dbsetting->hContact, dbsetting->module, setting, value);
							break;
						}

					}
				} // fall through
				case IDCANCEL:
				{
					struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
					mir_free(dbsetting->module);
					mir_free(dbsetting->setting);
					mir_free(dbsetting);
					DestroyWindow(hwnd);
				}
				break;
			}
		break;
		}
	return 0;
}
示例#8
0
void CMsnProto::setStringUtf(HANDLE hContact, const char* name, const char* value)
{	DBWriteContactSettingStringUtf(hContact, m_szModuleName, name, value);
}
示例#9
0
void importSettings(HANDLE hContact, char *importstring )
{
	char module[256] = "", setting[256] = "", *end;
	int i=0, value, type;
	importstring = strtok(importstring, "\n");

	SetCursor(LoadCursor(NULL,IDC_WAIT));

	while (importstring != NULL)
	{
		i=0;
		rtrim(importstring);
		if (importstring[i] == '\0')
		{
			importstring = strtok(NULL, "\n");
			continue;
		}
		else if (!strncmp(&importstring[i],"SETTINGS:",strlen("SETTINGS:")))
		{
			importstring = strtok(NULL, "\n");
			continue;
		}
		else if (!strncmp(&importstring[i],"CONTACT:", strlen("CONTACT:")))
		{
			int len, add = 1;
			hContact = INVALID_HANDLE_VALUE;

			i = i + (int)strlen("CONTACT:");
			len = (int)strlen(&importstring[i]);

			if (len > 10)
			{
				char uid[256]="",szUID[256]="",szProto[512]="";
				char *p1,*p2;

				p1 = strrchr(&importstring[i], '>*{');
				p2 = strrchr(&importstring[i], '}*');

				if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szUID))
				{
					strncpy(szUID, p1+1, p2-p1-2);

					p1 = strrchr(&importstring[i], ')*<');
					p2 = strrchr(&importstring[i], '>*{');

					if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(uid))
					{
						strncpy(uid, p1+1, p2-p1-3);

						p1 = strrchr(&importstring[i], ' *(');
						p2 = strrchr(&importstring[i], ')*<');

						if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szProto))
						{
							char *protouid;
							strncpy(szProto, p1+1, p2-p1-3);

							protouid = (char*)CallProtoService(szProto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
							if ((int)protouid!=CALLSERVICE_NOTFOUND)
							{
								if (!mir_strcmp(protouid, uid))
        							hContact = CheckNewContact(szProto, uid, szUID);
        					}
	        				else
        						hContact = CheckNewContact(szProto, uid, szUID);
						}
					}
				}
			}

 			if (hContact == INVALID_HANDLE_VALUE)
 			{
				HANDLE temp = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0);
				if (temp)
					hContact = temp;
			}
		}
		else if (importstring[i] == '[' && !strchr(&importstring[i+1],'=') )// get the module
		{
			if (end = strpbrk(&importstring[i+1], "]")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(module, &importstring[i+1]);
			}
		}
		else if (importstring[i] == '-' && importstring[i+1] == '[' &&
			!strchr(&importstring[i+2],'='))// get the module
		{
			if (end = strpbrk(&importstring[i+2], "]")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(module, &importstring[i+2]);
				deleteModule(module, hContact, 1);
			}
		}
		else if (strstr(&importstring[i], "=") && module[0]) // get the setting
		{
			if (end = strpbrk(&importstring[i+1], "=")) {
				if ((end+1) != '\0') *end = '\0';
				strcpy(setting, &importstring[i]);

				// get the type
				type = *(end+1);
				if (lstrcmp(module, "CList") == 0 && lstrcmp(setting, "Group") == 0)
				{
					WCHAR* GroupName = mir_a2u(end+2);
					if (!GroupName)
						continue;
					HANDLE GroupHandle = Clist_GroupExists(GroupName);
					if(GroupHandle == 0) {
						GroupHandle = (HANDLE)CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)GroupName);

						if(GroupHandle) {
							CallService(MS_CLUI_GROUPADDED, (WPARAM)GroupHandle, 0);
							CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)GroupHandle, 1);
						}
					}
					mir_free(GroupName);
				}
				switch (type)
				{
					case 'b':
					case 'B':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingByte(hContact, module, setting, (BYTE)value);
						break;
					case 'w':
					case 'W':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingWord(hContact, module, setting, (WORD)value);
						break;
					case 'd':
					case 'D':
						if (sscanf((end+2), "%d", &value) == 1)
							DBWriteContactSettingDword(hContact, module, setting, (DWORD)value);
						break;
					case 's':
					case 'S':
						DBWriteContactSettingString(hContact,module, setting, (end+2));
						break;
					case 'g':
					case 'G':
						{	char *pstr;
							for(pstr=end+2;*pstr;pstr++){
								if(*pstr=='\\'){
									switch(pstr[1]){
									case 'n': *pstr='\n'; break;
									case 't': *pstr='\t'; break;
									case 'r': *pstr='\r'; break;
									default:  *pstr=pstr[1]; break;
									}
									MoveMemory(pstr+1,pstr+2,lstrlenA(pstr+2)+1);
						}	}	}
					case 'u':
					case 'U':
						DBWriteContactSettingStringUtf(hContact,module, setting, (end+2));
						break;
					case 'l':
					case 'L':
						DBDeleteContactSetting(hContact, module, setting);
						break;
					case 'n':
					case 'N':
						WriteBlobFromString(hContact, module, setting, (end+2), (int)strlen((end+2)));
						break;
				}
			}
		}
		importstring = strtok(NULL, "\n");
	}
	SetCursor(LoadCursor(NULL,IDC_ARROW));
}
示例#10
0
DWORD CJabberProto::JSetStringUtf( HANDLE hContact, const char* valueName, const char* parValue )
{
	return DBWriteContactSettingStringUtf( hContact, m_szModuleName, valueName, parValue );
}
示例#11
0
int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *find, const char *replace, int mode)
{

	ModuleSettingLL msll;
	struct 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:
						DBWriteContactSettingByte(hContact, newModule, setting->name, dbv.bVal);
					break;
					case DBVT_WORD:
						DBWriteContactSettingWord(hContact, newModule, setting->name, dbv.wVal);
					break;
					case DBVT_DWORD:
						DBWriteContactSettingDword(hContact, newModule, setting->name, dbv.dVal);
					break;
					case DBVT_ASCIIZ:
						DBWriteContactSettingString(hContact, newModule, setting->name, dbv.pszVal);
					break;
					case DBVT_UTF8:
						DBWriteContactSettingStringUtf(hContact, newModule, setting->name, dbv.pszVal);
					break;
					case DBVT_BLOB:
						DBWriteContactSettingBlob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal);
					break;
				}

				DBFreeVariant(&dbv);
				DBDeleteContactSetting(hContact, module, setting->name);
			}

			setting = (struct ModSetLinkLinkItem *)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;
}