diff options
| -rw-r--r-- | plugins/Non-IM Contact/src/contactinfo.cpp | 51 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/dialog.cpp | 14 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/files.cpp | 107 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/http.cpp | 3 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/main.cpp | 23 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/namereplacing.cpp | 34 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/services.cpp | 22 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/stdafx.h | 2 | ||||
| -rw-r--r-- | plugins/Non-IM Contact/src/timer.cpp | 10 | 
9 files changed, 128 insertions, 138 deletions
diff --git a/plugins/Non-IM Contact/src/contactinfo.cpp b/plugins/Non-IM Contact/src/contactinfo.cpp index 855d2eef6f..1c028354a3 100644 --- a/plugins/Non-IM Contact/src/contactinfo.cpp +++ b/plugins/Non-IM Contact/src/contactinfo.cpp @@ -10,9 +10,11 @@ INT_PTR CALLBACK DlgProcContactInfo(HWND hwnd, UINT msg, WPARAM, LPARAM lParam)  			char name[2048];
  			SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)hContact);
 -			if (!db_get_static(hContact, MODNAME, "Name", name, _countof(name))) break;
 +			if (db_get_static(hContact, MODNAME, "Name", name, _countof(name)))
 +				break;
  			SetDlgItemTextA(hwnd, IDC_DISPLAY_NAME, name);
 -			if (!db_get_static(hContact, MODNAME, "ToolTip", name, _countof(name))) break;
 +			if (db_get_static(hContact, MODNAME, "ToolTip", name, _countof(name)))
 +				break;
  			SetDlgItemTextA(hwnd, IDC_TOOLTIP, name);
  		}
  		return TRUE;
 @@ -310,8 +312,8 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  				char dbVar1[2000], dbVar2[2000];
  				int i = 0, j = 0, k = 0;
  				char *string = oldString[k];
 -				MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA), hContact2;
 -				if (db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) {
 +				MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
 +				if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) {
  					char *replace = (char*)malloc(GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1);
  					GetDlgItemTextA(hwnd, IDC_STRING_REPLACE, replace, GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) + 1);
  					// get the list of replace strings
 @@ -323,7 +325,8 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  						else if (!strncmp(replace + i, "\r\n", 2)) {
  							if (string == newString[k])
  								k--;
 -							if (k == MAX_REPLACES) break;
 +							if (k == MAX_REPLACES)
 +								break;
  							string = oldString[++k];
  							i += 2;
  							continue;
 @@ -335,19 +338,19 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  						i++;
  					}
  					free(replace);
 -					hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
 +					MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
  					Proto_AddToContact(hContact2, MODNAME);
  					CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE);
  					db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact"));
  					// blank dbVar2 so the replaceing doesnt crash..
  					mir_strcpy(dbVar2, "");
  					// copy the name (dbVar1 is the name)
 -					for (i = 0; i <= k; i++)
 +					for (i = 0; i < k; i++)
  						copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]);
  					db_set_s(hContact2, MODNAME, "Name", dbVar2);
  					// copy the ProgramString
 -					if (db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) {
 +					if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1))) {
  						mir_strcpy(dbVar2, "");
  						for (i = 0; i <= k; i++)
  							copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]);
 @@ -355,7 +358,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  						db_set_s(hContact2, MODNAME, "ProgramString", dbVar2);
  					}
  					// copy the ProgramParamString
 -					if (db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) {
 +					if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1))) {
  						mir_strcpy(dbVar2, "");
  						for (i = 0; i <= k; i++)
  							copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]);
 @@ -363,7 +366,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  						db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar2);
  					}
  					// copy the group
 -					if (db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) {
 +					if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1))) {
  						mir_strcpy(dbVar2, "");
  						for (i = 0; i <= k; i++)
  							copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]);
 @@ -371,7 +374,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  						db_set_s(hContact2, "CList", "Group", dbVar2);
  					}
  					// copy the ToolTip
 -					if (db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) {
 +					if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1))) {
  						mir_strcpy(dbVar2, "");
  						for (i = 0; i <= k; i++)
  							copyReplaceString(dbVar1, dbVar2, oldString[i], newString[i]);
 @@ -390,7 +393,7 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  			else {
  				char dbVar1[2000];
  				MCONTACT hContact1 = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
 -				if (db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) {
 +				if (!db_get_static(hContact1, MODNAME, "Name", dbVar1, _countof(dbVar1))) {
  					MCONTACT hContact2 = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
  					if (!hContact2) {
  						msg("contact did not get created", "");
 @@ -400,19 +403,19 @@ INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  					CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE);
  					db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact"));
  					db_set_s(hContact2, MODNAME, "Name", dbVar1);
 -					if (db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1)))
 +					if (!db_get_static(hContact1, MODNAME, "ProgramString", dbVar1, _countof(dbVar1)))
  						db_set_s(hContact2, MODNAME, "ProgramString", dbVar1);
  					// copy the ProgramParamString
 -					if (db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1)))
 +					if (!db_get_static(hContact1, MODNAME, "ProgramParamString", dbVar1, _countof(dbVar1)))
  						db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar1);
  					// copy the group
 -					if (db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1)))
 +					if (!db_get_static(hContact1, "CList", "Group", dbVar1, _countof(dbVar1)))
  						db_set_s(hContact2, "CList", "Group", dbVar1);
  					// copy the ToolTip
 -					if (db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1)))
 +					if (!db_get_static(hContact1, MODNAME, "ToolTip", dbVar1, _countof(dbVar1)))
  						db_set_s(hContact2, MODNAME, "ToolTip", dbVar1);
  					// timer
 @@ -453,15 +456,15 @@ void ExportContact(MCONTACT hContact)  		//	else 
  		FILE *file = fopen(szFileName, "a");
  		if (file) {
 -			if (db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) {
 +			if (!db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) {
  				fprintf(file, "\r\n[Non-IM Contact]\r\nName=%s\r\n", DBVar);
 -				if (db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar)))
 +				if (!db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar)))
  					fprintf(file, "ProgramString=%s\r\n", DBVar);
 -				if (db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar)))
 +				if (!db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar)))
  					fprintf(file, "ProgramParamString=%s\r\n", DBVar);
 -				if (db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar)))
 +				if (!db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar)))
  					fprintf(file, "ToolTip=%s</tooltip>\r\n", DBVar);
 -				if (db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar)))
 +				if (!db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar)))
  					fprintf(file, "Group=%s\r\n", DBVar);
  				if (tmp = db_get_w(hContact, MODNAME, "Icon", 40072))
  					fprintf(file, "Icon=%d\r\n", tmp);
 @@ -561,13 +564,13 @@ INT_PTR ImportContacts(WPARAM, LPARAM)  			size_t size = mir_strlen(name) + mir_strlen("Do you want to import this Non-IM Contact?\r\n\r\nName: \r\n") + 1;
  			char *msg = (char*)malloc(size);
  			mir_snprintf(msg, size, "Do you want to import this Non-IM Contact?\r\n\r\nName: %s\r\n", name);
 -			if (program) {
 +			if (program[0] != '\0') {
  				msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(program) + mir_strlen("Program: \r\n") + 1);
  				mir_strcat(msg, "Program: ");
  				mir_strcat(msg, program);
  				mir_strcat(msg, "\r\n");
  			}
 -			if (programparam) {
 +			if (programparam[0] != '\0') {
  				msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(programparam) + mir_strlen("Program Parameters: \r\n") + 1);
  				mir_strcat(msg, "Program Parameters: ");
  				mir_strcat(msg, programparam);
 @@ -579,7 +582,7 @@ INT_PTR ImportContacts(WPARAM, LPARAM)  				mir_strcat(msg, tooltip);
  				mir_strcat(msg, "\r\n");
  			}
 -			if (group) {
 +			if (group[0] != '\0') {
  				msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(group) + mir_strlen("Group: \r\n") + 1);
  				mir_strcat(msg, "Group: ");
  				mir_strcat(msg, group);
 diff --git a/plugins/Non-IM Contact/src/dialog.cpp b/plugins/Non-IM Contact/src/dialog.cpp index 469fd1ee73..95a8552781 100644 --- a/plugins/Non-IM Contact/src/dialog.cpp +++ b/plugins/Non-IM Contact/src/dialog.cpp @@ -235,7 +235,7 @@ static int CALLBACK PropSheetProc(HWND, UINT uMsg, LPARAM lParam)  void DoPropertySheet(MCONTACT hContact)
  {
 -	char title[256], nick[256];
 +	char nick[256];
  	PROPSHEETPAGEA psp[4] = { 0 };
  	/* contact info */
 @@ -287,9 +287,11 @@ void DoPropertySheet(MCONTACT hContact)  	psh.dwFlags = PSH_USEICONID | PSH_PROPSHEETPAGE | PSH_USECALLBACK;
  	psh.hInstance = g_hInst;
  	psh.pszIcon = MAKEINTRESOURCEA(IDI_MAIN);
 -	db_get_static(hContact, MODNAME, "Nick", nick, _countof(nick));
 -	mir_snprintf(title, Translate("Edit Non-IM Contact \"%s\""), nick);
 -	psh.pszCaption = title;
 +	if (!db_get_static(hContact, MODNAME, "Nick", nick, _countof(nick))) {
 +		char title[256];
 +		mir_snprintf(title, Translate("Edit Non-IM Contact \"%s\""), nick);
 +		psh.pszCaption = title;
 +	}
  	psh.nPages = _countof(psp);
  	psh.ppsp = (LPCPROPSHEETPAGEA)&psp;
  	psh.pfnCallback = PropSheetProc;
 @@ -306,7 +308,7 @@ INT_PTR addContact(WPARAM, LPARAM)  	CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE);
  	db_set_ts(hContact, MODNAME, "Nick", TranslateT("New Non-IM Contact"));
  	DoPropertySheet(hContact);
 -	if (!db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp)))
 +	if (db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp)))
  		CallService(MS_DB_CONTACT_DELETE, hContact, 0);
  	replaceAllStrings(hContact);
  	return 0;
 @@ -323,7 +325,7 @@ INT_PTR editContact(WPARAM wParam, LPARAM)  		db_set_s(hContact, MODNAME, "Nick", Translate("New Non-IM Contact"));
  	}
  	DoPropertySheet(hContact);
 -	if (!db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp)))
 +	if (db_get_static(hContact, MODNAME, "Name", tmp, _countof(tmp)))
  		CallService(MS_DB_CONTACT_DELETE, hContact, 0);
  	replaceAllStrings(hContact);
  	return 0;
 diff --git a/plugins/Non-IM Contact/src/files.cpp b/plugins/Non-IM Contact/src/files.cpp index 9f37274b1f..4bc5520225 100644 --- a/plugins/Non-IM Contact/src/files.cpp +++ b/plugins/Non-IM Contact/src/files.cpp @@ -17,15 +17,15 @@ INT_PTR exportContacts(WPARAM, LPARAM)  	for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) {
  		int tmp;
  		char DBVar[1024];
 -		if (db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) {
 +		if (!db_get_static(hContact, MODNAME, "Name", DBVar, _countof(DBVar))) {
  			fprintf(file, "\r\n[Non-IM Contact]\r\nName=%s\r\n", DBVar);
 -			if (db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar)))
 +			if (!db_get_static(hContact, MODNAME, "ProgramString", DBVar, _countof(DBVar)))
  				fprintf(file, "ProgramString=%s\r\n", DBVar);
 -			if (db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar)))
 +			if (!db_get_static(hContact, MODNAME, "ProgramParamString", DBVar, _countof(DBVar)))
  				fprintf(file, "ProgramParamString=%s\r\n", DBVar);
 -			if (db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar)))
 +			if (!db_get_static(hContact, MODNAME, "ToolTip", DBVar, _countof(DBVar)))
  				fprintf(file, "ToolTip=%s</tooltip>\r\n", DBVar);
 -			if (db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar)))
 +			if (!db_get_static(hContact, "CList", "Group", DBVar, _countof(DBVar)))
  				fprintf(file, "Group=%s\r\n", DBVar);
  			if (tmp = db_get_w(hContact, MODNAME, "Icon", 40072))
  				fprintf(file, "Icon=%d\r\n", tmp);
 @@ -71,19 +71,18 @@ int Openfile(char *outputFile, int saveOpen) //0=save, 1=open  void reloadFiles(HWND fileList)
  {
 -	int i, index;
 -	char file[MAX_PATH], fn[6];
  	SendMessage(fileList, CB_RESETCONTENT, 0, 0);
 -	for (i = 0;; i++) {
 +	for (int i = 0;; i++) {
 +		char file[MAX_PATH], fn[6];
  		mir_snprintf(fn, "fn%d", i);
 -		if (db_get_static(NULL, MODNAME, fn, file, _countof(file))) {
 -			index = SendMessageA(fileList, CB_ADDSTRING, 0, (LPARAM)file);
 -			SendMessage(fileList, CB_SETITEMDATA, index, (LPARAM)i);
 -			SendMessage(fileList, CB_SETCURSEL, index, 0);
 -			SetDlgItemTextA(GetParent(fileList), IDC_FN, _itoa(i, fn, 10));
 -			/* add the file contents to the edit box */
 -		}
 -		else break;
 +		if (db_get_static(NULL, MODNAME, fn, file, _countof(file))) 
 +			return;
 +
 +		/* add the file contents to the edit box */
 +		int index = SendMessageA(fileList, CB_ADDSTRING, 0, (LPARAM)file);
 +		SendMessage(fileList, CB_SETITEMDATA, index, (LPARAM)i);
 +		SendMessage(fileList, CB_SETCURSEL, index, 0);
 +		SetDlgItemTextA(GetParent(fileList), IDC_FN, _itoa(i, fn, 10));
  	}
  }
 @@ -91,7 +90,6 @@ int savehtml(char* outFile)  {
  	FILE* file = fopen(outFile, "w");
  	if (!file) {
 -		fclose(file);
  		return 0;
  	}
  	fprintf(file, "%s", szInfo);
 @@ -107,7 +105,7 @@ void readFile(HWND hwnd)  	{
  		char fn[10];
  		mir_snprintf(fn, "fn%d", fileNumber);
 -		if (!db_get_static(NULL, MODNAME, fn, szFileName, _countof(szFileName))) {
 +		if (db_get_static(NULL, MODNAME, fn, szFileName, _countof(szFileName))) {
  			msg(Translate("File couldn't be opened"), fn);
  			return;
  		}
 @@ -155,7 +153,7 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  			int i = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCURSEL, 0, 0);
  			mir_snprintf(fn, "fn%d", i);
  			SendDlgItemMessage(hwnd, IDC_FILE_CONTENTS, LB_RESETCONTENT, 0, 0);
 -			if (db_get_static(NULL, MODNAME, fn, string, _countof(string))) {
 +			if (!db_get_static(NULL, MODNAME, fn, string, _countof(string))) {
  				if ((!strncmp("http://", string, mir_strlen("http://"))) || (!strncmp("https://", string, mir_strlen("https://")))) {
  					SetDlgItemTextA(hwnd, IDC_URL, string);
  					mir_snprintf(fn, "fn%d_timer", i);
 @@ -177,28 +175,29 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  		case IDC_ADD_URL:
  			if (GetWindowTextLength(GetDlgItem(hwnd, IDC_URL))) {
  				char text[512], url[512], szFileName[MAX_PATH], temp[512];
 -				int i, timer;
  				GetDlgItemTextA(hwnd, IDC_URL, text, _countof(text));
  				mir_strcpy(url, text);
  				if (!InternetDownloadFile(text)) {
 -					for (i = 0;; i++) {
 +					for (int i = 0;; i++) {
  						mir_snprintf(fn, "fn%d", i);
 -						if (!db_get_static(NULL, MODNAME, fn, text, _countof(text)))
 +						if (!db_get_static(NULL, MODNAME, fn, text, _countof(text))) {
 +							mir_snprintf(szFileName, "%s\\plugins\\%s.html", getMimDir(temp), fn);
 +							if (savehtml(szFileName)) {
 +								mir_snprintf(fn, "fn%d", i);
 +								db_set_s(NULL, MODNAME, fn, url);
 +								int timer;
 +								if (!GetWindowTextLength(GetDlgItem(hwnd, IDC_WWW_TIMER)))
 +									timer = 60;
 +								else {
 +									GetDlgItemTextA(hwnd, IDC_WWW_TIMER, text, _countof(text));
 +									timer = atoi(text);
 +								}
 +								mir_snprintf(fn, "fn%d_timer", i);
 +								db_set_w(NULL, MODNAME, fn, (WORD)timer);
 +								SendMessage(hwnd, WM_RELOADWINDOW, 0, 0);
 +							}
  							break;
 -					}
 -					mir_snprintf(szFileName, "%s\\plugins\\%s.html", getMimDir(temp), fn);
 -					if (savehtml(szFileName)) {
 -						mir_snprintf(fn, "fn%d", i);
 -						db_set_s(NULL, MODNAME, fn, url);
 -						if (!GetWindowTextLength(GetDlgItem(hwnd, IDC_WWW_TIMER)))
 -							timer = 60;
 -						else {
 -							GetDlgItemTextA(hwnd, IDC_WWW_TIMER, text, _countof(text));
 -							timer = atoi(text);
  						}
 -						mir_snprintf(fn, "fn%d_timer", i);
 -						db_set_w(NULL, MODNAME, fn, (WORD)timer);
 -						SendMessage(hwnd, WM_RELOADWINDOW, 0, 0);
  					}
  				}
  			}
 @@ -210,27 +209,27 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  			break;
  		case IDC_ADD_FILE:
 -			int i, index;
 -			char file[MAX_PATH];
 -			for (i = 0;; i++) {
 +			for (int i = 0;; i++) {
 +				char file[MAX_PATH];
  				mir_snprintf(fn, "fn%d", i);
 -				if (!db_get_static(NULL, MODNAME, fn, file, _countof(file)))
 +				if (!db_get_static(NULL, MODNAME, fn, file, _countof(file))) {
 +					if (Openfile(file, 1)) {
 +						db_set_s(NULL, MODNAME, fn, file);
 +						int index = SendDlgItemMessageA(hwnd, IDC_FILE_LIST, CB_ADDSTRING, 0, (LPARAM)file);
 +						SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_SETITEMDATA, index, (LPARAM)i);
 +						SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_SETCURSEL, index, 0);
 +						SetDlgItemTextA(hwnd, IDC_FN, _itoa(i, fn, 10));
 +						mir_snprintf(fn, "fn%d", index);
 +						readFile(hwnd);
 +					}
  					break;
 -			}
 -			if (Openfile(file, 1)) {
 -				db_set_s(NULL, MODNAME, fn, file);
 -				index = SendDlgItemMessageA(hwnd, IDC_FILE_LIST, CB_ADDSTRING, 0, (LPARAM)file);
 -				SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_SETITEMDATA, index, (LPARAM)i);
 -				SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_SETCURSEL, index, 0);
 -				SetDlgItemTextA(hwnd, IDC_FN, _itoa(i, fn, 10));
 -				mir_snprintf(fn, "fn%d", index);
 -				readFile(hwnd);
 +				}
  			}
  			break;
  		case IDC_DEL_FILE:
 -			index = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCURSEL, 0, 0), i = (int)SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETITEMDATA, index, 0);
  			{
 +				int index = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCURSEL, 0, 0), i = (int)SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETITEMDATA, index, 0);
  				int count = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCOUNT, 0, 0) - 1;
  				if (index == count) {
  					mir_snprintf(fn, "fn%d", index);
 @@ -245,8 +244,8 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  				}
  				else {
  					mir_snprintf(fn, "fn%d", i);
 -					char fn1[4];
 -					while (db_get_static(NULL, MODNAME, fn, tmp, _countof(tmp))) {
 +					while (!db_get_static(NULL, MODNAME, fn, tmp, _countof(tmp))) {
 +						char fn1[4];
  						mir_snprintf(fn1, "fn%d", i - 1);
  						db_set_s(NULL, MODNAME, fn1, tmp);
  						mir_snprintf(fn, "fn%d", ++i);
 @@ -261,10 +260,10 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  		case IDC_FILE_LIST:
  			if (HIWORD(wParam) == CBN_SELCHANGE) {
 -				index = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCURSEL, 0, 0);
 +				int index = SendDlgItemMessage(hwnd, IDC_FILE_LIST, CB_GETCURSEL, 0, 0);
  				SetDlgItemTextA(hwnd, IDC_FN, _itoa(index, fn, 10));
  				mir_snprintf(fn, "fn%d", index);
 -				if (db_get_static(NULL, MODNAME, fn, tmp, _countof(tmp))) {
 +				if (!db_get_static(NULL, MODNAME, fn, tmp, _countof(tmp))) {
  					if (!strncmp("http://", tmp, mir_strlen("http://")) || !strncmp("https://", tmp, mir_strlen("https://"))) {
  						SetDlgItemTextA(hwnd, IDC_URL, tmp);
  						mir_snprintf(fn, "fn%d_timer", index);
 @@ -300,7 +299,7 @@ INT_PTR CALLBACK DlgProcFiles(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)  				}
  				else timer = 60;
 -				if (db_get_static(NULL, MODNAME, fn, string, _countof(string)))
 +				if (!db_get_static(NULL, MODNAME, fn, string, _countof(string)))
  					if (!strncmp("http://", string, mir_strlen("http://")) || !strncmp("https://", string, mir_strlen("https://"))) {
  						mir_snprintf(fn, "fn%d_timer", i);
  						db_set_w(NULL, MODNAME, fn, (WORD)timer);
 diff --git a/plugins/Non-IM Contact/src/http.cpp b/plugins/Non-IM Contact/src/http.cpp index 23b1064236..912f16eac3 100644 --- a/plugins/Non-IM Contact/src/http.cpp +++ b/plugins/Non-IM Contact/src/http.cpp @@ -31,7 +31,7 @@ HANDLE hNetlibUser;  // szUrl = URL of the webpage to be retrieved
  // return value = 0 for success, 1 or HTTP error code for failure
  // global var used: szData, szInfo = containing the retrieved data
 -
 +//
  int InternetDownloadFile(char *szUrl)
  {
  	NETLIBHTTPREQUEST nlhr = { 0 };
 @@ -44,7 +44,6 @@ int InternetDownloadFile(char *szUrl)  	// change the header so the plugin is pretended to be IE 6 + WinXP
  	nlhr.headersCount++;
  	nlhr.headers = (NETLIBHTTPHEADER*)malloc(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount);
 -	memcpy(nlhr.headers, nlhr.headers, sizeof(NETLIBHTTPHEADER)*nlhr.headersCount);
  	nlhr.headers[nlhr.headersCount - 1].szName = "User-Agent";
  	nlhr.headers[nlhr.headersCount - 1].szValue = NETLIB_USER_AGENT;
 diff --git a/plugins/Non-IM Contact/src/main.cpp b/plugins/Non-IM Contact/src/main.cpp index 6c0f92dc6a..c4f2c281e9 100644 --- a/plugins/Non-IM Contact/src/main.cpp +++ b/plugins/Non-IM Contact/src/main.cpp @@ -32,8 +32,8 @@ INT_PTR doubleClick(WPARAM wParam, LPARAM)  	if (proto && !mir_strcmp(proto, MODNAME)) {
  		if (GetKeyState(VK_CONTROL) & 0x8000) // ctrl is pressed
  			editContact(wParam, 0);		// for later when i add a second double click setting
 -		else if (db_get_static(wParam, MODNAME, "Program", program, _countof(program)) && mir_strcmp(program, "")) {
 -			if (!db_get_static(wParam, MODNAME, "ProgramParams", params, _countof(params)))
 +		else if (!db_get_static(wParam, MODNAME, "Program", program, _countof(program)) && mir_strcmp(program, "")) {
 +			if (db_get_static(wParam, MODNAME, "ProgramParams", params, _countof(params)))
  				mir_strcpy(params, "");
  			if (strstr(program, "http://") || strstr(program, "https://"))
  				Utils_OpenUrl(program);
 @@ -60,6 +60,7 @@ int LCStatus = ID_STATUS_OFFLINE;  // Returns : int
  // Description : Called at very beginning of plugin
  //=====================================================
 +//
  int NimcOptInit(WPARAM wParam, LPARAM)
  {
  	OPTIONSDIALOGPAGE odp = { 0 };
 @@ -77,7 +78,7 @@ int NimcOptInit(WPARAM wParam, LPARAM)  // Returns :
  // Description : Sets plugin info
  //=====================================================
 -
 +//
  extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
  {
  	return &pluginInfoEx;
 @@ -89,7 +90,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)  // Returns : BOOL
  // Description :
  //=====================================================
 -
 +//
  BOOL WINAPI DllMain(HINSTANCE hinst, DWORD, LPVOID)
  {
  	g_hInst = hinst;
 @@ -102,18 +103,18 @@ int ModulesLoaded(WPARAM, LPARAM)  	return 0;
  }
 +IconItem icoList[] =
 +{
 +	{ LPGEN("Main Icon"), MODNAME, IDI_MAIN },
 +};
 +
  //=====================================================
  // Name : Load
  // Parameters: PLUGINLINK *link
  // Returns : int
  // Description : Called when plugin is loaded into Miranda
  //=====================================================
 -
 -IconItem icoList[] =
 -{
 -	{ LPGEN("Main Icon"), MODNAME, IDI_MAIN },
 -};
 -
 +//
  extern "C" __declspec(dllexport) int Load()
  {
  	mir_getLP(&pluginInfoEx);
 @@ -195,7 +196,7 @@ extern "C" __declspec(dllexport) int Load()  // Returns :
  // Description : Unloads plugin
  //=====================================================
 -
 +//
  extern "C" __declspec(dllexport) int Unload(void)
  {
  	killTimer();
 diff --git a/plugins/Non-IM Contact/src/namereplacing.cpp b/plugins/Non-IM Contact/src/namereplacing.cpp index 32237af843..4077e12eb6 100644 --- a/plugins/Non-IM Contact/src/namereplacing.cpp +++ b/plugins/Non-IM Contact/src/namereplacing.cpp @@ -536,16 +536,15 @@ int stringReplacer(const char *oldString, CMStringA &szNewString, MCONTACT hCont  		else if (!strncmp(&oldString[positionInOldString], "filename(", mir_strlen("filename("))) {
  			positionInOldString += (int)mir_strlen("filename(");
  			tempInt = getNumber(&oldString[positionInOldString]);
 -			if (tempInt == -1) {
 +			if (tempInt == -1) 
  				return ERROR_NO_FILE;
 -			}
 -			else {
 -				mir_snprintf(tempString, "fn%d", tempInt);
 -				if (db_get_static(NULL, MODNAME, tempString, tempString, _countof(tempString)))
 -					szNewString.Append(tempString);
 -				else return ERROR_NO_FILE;
 -				positionInOldString += (int)mir_strlen(_itoa(tempInt, tempString, 10)) + 1;
 -			}
 +
 +			mir_snprintf(tempString, "fn%d", tempInt);
 +			if (db_get_static(NULL, MODNAME, tempString, tempString, _countof(tempString)))
 +				return ERROR_NO_FILE;
 +
 +			szNewString.Append(tempString);
 +			positionInOldString += (int)mir_strlen(_itoa(tempInt, tempString, 10)) + 1;
  		}
  		// lastchecked(file(X))
  		else if (!strncmp(&oldString[positionInOldString], "lastchecked(file(", mir_strlen("lastchecked(file("))) {
 @@ -557,7 +556,7 @@ int stringReplacer(const char *oldString, CMStringA &szNewString, MCONTACT hCont  		}
  	}
  	// free the file strings
 -	for (tempInt = 0; (fileContents[tempInt] != NULL) && (tempInt < MAXLINES); tempInt++)
 +	for (tempInt = 0; (tempInt < MAXLINES) && (fileContents[tempInt] != NULL); tempInt++)
  		free(fileContents[tempInt]);
  	// check for load("A","B")
 @@ -578,7 +577,7 @@ void WriteSetting(MCONTACT hContact, char* module1, char* setting1, char* module  	CMStringA newString;
  	char text[MAX_STRING_LENGTH];
  	int error = 0, status = GetLCStatus(0, 0);
 -	if (db_get_static(hContact, module1, setting1, text, _countof(text))) {
 +	if (!db_get_static(hContact, module1, setting1, text, _countof(text))) {
  		switch (stringReplacer(text, newString, hContact)) {
  		case ERROR_NO_LINE_AFTER_VAR_F:
  			newString.Format(Translate("%s - ERROR: no line specified or line not found (in %s)"), text, setting1);
 @@ -616,18 +615,19 @@ void WriteSetting(MCONTACT hContact, char* module1, char* setting1, char* module  void replaceAllStrings(MCONTACT hContact)
  {
 -	char tmp1[256], tmp2[256], tmp3[256];
  	WriteSetting(hContact, MODNAME, "Name", MODNAME, "Nick");
  	WriteSetting(hContact, MODNAME, "ProgramString", MODNAME, "Program");
  	WriteSetting(hContact, MODNAME, "ProgramParamsString", MODNAME, "ProgramParams");
  	/* tooltips*/
  	WriteSetting(hContact, MODNAME, "ToolTip", "UserInfo", "MyNotes");
 -	if (db_get_static(hContact, MODNAME, "Program", tmp1, _countof(tmp1)) && db_get_static(hContact, MODNAME, "ProgramParams", tmp2, _countof(tmp2))) {
 +
 +	char tmp1[256], tmp2[256], tmp3[256];
 +	if (db_get_static(hContact, MODNAME, "Program", tmp1, _countof(tmp1)))
 +		db_set_s(hContact, "UserInfo", "FirstName", "");
 +	else if (db_get_static(hContact, MODNAME, "ProgramParams", tmp2, _countof(tmp2)))
 +		db_set_s(hContact, "UserInfo", "FirstName", tmp1);
 +	else {
  		mir_snprintf(tmp3, "%s %s", tmp1, tmp2);
  		db_set_s(hContact, "UserInfo", "FirstName", tmp3);
  	}
 -	else if (db_get_static(hContact, MODNAME, "Program", tmp1, _countof(tmp1))) {
 -		db_set_s(hContact, "UserInfo", "FirstName", tmp1);
 -	}
 -	else db_set_s(hContact, "UserInfo", "FirstName", "");
  }
 diff --git a/plugins/Non-IM Contact/src/services.cpp b/plugins/Non-IM Contact/src/services.cpp index e6fcfb3da3..46282ef90a 100644 --- a/plugins/Non-IM Contact/src/services.cpp +++ b/plugins/Non-IM Contact/src/services.cpp @@ -1,23 +1,9 @@  #include "stdafx.h"
  //=======================================================
 -// db_get_static
 -//=======================================================
 -
 -int db_get_static(MCONTACT hContact, const char *szModule, const char *szSetting, char *value, size_t length)
 -{
 -	ptrA str(db_get_sa(hContact, szModule, szSetting));
 -	if (str == NULL)
 -		return 0;
 -
 -	strncpy_s(value, length, str, _TRUNCATE);
 -	return 1;
 -}
 -
 -//=======================================================
  // GetCaps
  //=======================================================
 -
 +//
  INT_PTR GetLCCaps(WPARAM wParam, LPARAM)
  {
  	if (wParam == PFLAGNUM_1)
 @@ -32,6 +18,7 @@ INT_PTR GetLCCaps(WPARAM wParam, LPARAM)  //=======================================================
  // GetName
  //=======================================================
 +//
  INT_PTR GetLCName(WPARAM wParam, LPARAM lParam)
  {
  	mir_strncpy((char*)lParam, MODNAME, wParam);
 @@ -41,6 +28,7 @@ INT_PTR GetLCName(WPARAM wParam, LPARAM lParam)  //=======================================================
  // BPLoadIcon
  //=======================================================
 +//
  INT_PTR LoadLCIcon(WPARAM wParam, LPARAM)
  {
  	if (LOWORD(wParam) == PLI_PROTOCOL) {
 @@ -62,7 +50,7 @@ INT_PTR LoadLCIcon(WPARAM wParam, LPARAM)  //=======================================================
  // SetFStatus			
  //=======================================================
 -
 +//
  int SetLCStatus(WPARAM wParam, LPARAM)
  {
  	int oldStatus = LCStatus;
 @@ -113,7 +101,7 @@ int SetLCStatus(WPARAM wParam, LPARAM)  //=======================================================
  // GetStatus
  //=======================================================
 -
 +//
  INT_PTR GetLCStatus(WPARAM, LPARAM)
  {
  	if ((LCStatus >= ID_STATUS_ONLINE) && (LCStatus <= ID_STATUS_OUTTOLUNCH))
 diff --git a/plugins/Non-IM Contact/src/stdafx.h b/plugins/Non-IM Contact/src/stdafx.h index c6494d2f46..0c5cfc0992 100644 --- a/plugins/Non-IM Contact/src/stdafx.h +++ b/plugins/Non-IM Contact/src/stdafx.h @@ -119,8 +119,6 @@ extern char *szInfo;  extern char *szData;
  extern HANDLE hNetlibUser;
 -int db_get_static(MCONTACT hContact, const char *moduleName, const char *fn, char *buf, size_t cbSize);
 -
  #endif
  #pragma comment(lib,"comctl32.lib")
 diff --git a/plugins/Non-IM Contact/src/timer.cpp b/plugins/Non-IM Contact/src/timer.cpp index b7851eb1d1..f67610cae2 100644 --- a/plugins/Non-IM Contact/src/timer.cpp +++ b/plugins/Non-IM Contact/src/timer.cpp @@ -8,7 +8,7 @@ static UINT_PTR timerId = 0;  // Returns : void
  // Description : called when the timer interval occurs
  //=====================================================
 -
 +//
  void timerFunc(void*)
  {
  	char text[512], fn[16], szFileName[MAX_PATH], temp[MAX_PATH];
 @@ -24,7 +24,7 @@ void timerFunc(void*)  	/* update the web pages*/
  	for (int i = 0;; i++) {
  		mir_snprintf(fn, "fn%d", i);
 -		if (!db_get_static(NULL, MODNAME, fn, text, _countof(text)))
 +		if (db_get_static(NULL, MODNAME, fn, text, _countof(text)))
  			break;
  		if (!strncmp("http://", text, mir_strlen("http://")) || !strncmp("https://", text, mir_strlen("https://"))) {
 @@ -43,7 +43,7 @@ void timerFunc(void*)  	for (MCONTACT hContact = db_find_first(MODNAME); hContact; hContact = db_find_next(hContact, MODNAME)) {
  		int timer = db_get_w(hContact, MODNAME, "Timer", 15);
  		if (timer && !(timerCount % timer))
 -			if (db_get_static(hContact, MODNAME, "Name", text, _countof(text)))
 +			if (!db_get_static(hContact, MODNAME, "Name", text, _countof(text)))
  				replaceAllStrings(hContact);
  	}
  }
 @@ -60,7 +60,7 @@ void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)  // Returns : int
  // Description : starts the timer
  //=====================================================
 -
 +//
  int startTimer(int interval)
  {
  	timerId = SetTimer(NULL, 0, interval, timerProc);
 @@ -73,7 +73,7 @@ int startTimer(int interval)  // Returns : int
  // Description : stops the timer
  //=====================================================
 -
 +//
  int killTimer()
  {
  	if (timerId != 0) {
  | 
