⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winpidgin.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		case LANG_NORWEGIAN:			switch (sub_id) {				case SUBLANG_NORWEGIAN_BOKMAL:					posix = "nb"; break;				case SUBLANG_NORWEGIAN_NYNORSK:					posix = "nn"; break;			}			break;		case LANG_PUNJABI: posix = "pa"; break;		case LANG_POLISH: posix = "pl"; break;		case LANG_PORTUGUESE:			switch (sub_id) {				case SUBLANG_PORTUGUESE_BRAZILIAN:					posix = "pt_BR"; break;				default:				posix = "pt"; break;			}			break;		case LANG_ROMANIAN: posix = "ro"; break;		case LANG_RUSSIAN: posix = "ru"; break;		/* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN */		case LANG_SERBIAN:			switch (sub_id) {				case SUBLANG_SERBIAN_LATIN:					posix = "sr@Latn"; break;				case SUBLANG_SERBIAN_CYRILLIC:					posix = "sr"; break;				case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC:				case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN:					posix = "bs"; break;				case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN:					posix = "hr"; break;			}			break;		case LANG_SLOVAK: posix = "sk"; break;		case LANG_SLOVENIAN: posix = "sl"; break;		case LANG_ALBANIAN: posix = "sq"; break;		case LANG_SWEDISH: posix = "sv"; break;		case LANG_TAMIL: posix = "ta"; break;		case LANG_TELUGU: posix = "te"; break;		case LANG_THAI: posix = "th"; break;		case LANG_TURKISH: posix = "tr"; break;		case LANG_UKRAINIAN: posix = "uk"; break;		case LANG_VIETNAMESE: posix = "vi"; break;		case LANG_XHOSA: posix = "xh"; break;		case LANG_URDU: break;		case LANG_INDONESIAN: break;		case LANG_BELARUSIAN: break;		case LANG_LATVIAN: break;		case LANG_ARMENIAN: break;		case LANG_AFRIKAANS: break;		case LANG_FAEROESE: break;		case LANG_MALAY: break;		case LANG_KAZAK: break;		case LANG_KYRGYZ: break;		case LANG_SWAHILI: break;		case LANG_UZBEK: break;		case LANG_TATAR: break;		case LANG_ORIYA: break;		case LANG_KANNADA: break;		case LANG_MALAYALAM: break;		case LANG_ASSAMESE: break;		case LANG_MARATHI: break;		case LANG_SANSKRIT: break;		case LANG_MONGOLIAN: break;		case LANG_KONKANI: break;		case LANG_MANIPURI: break;		case LANG_SINDHI: break;		case LANG_SYRIAC: break;		case LANG_KASHMIRI: break;		case LANG_DIVEHI: break;	}	/* Deal with exceptions */	if (posix == NULL) {		switch (lcid) {			case 0x0455: posix = "my_MM"; break; /* Myanmar (Burmese) */			case 9999: posix = "ku"; break; /* Kurdish (from NSIS) */		}	}	return posix;}/* Determine and set Pidgin locale as follows (in order of priority):   - Check PIDGINLANG env var   - Check NSIS Installer Language reg value   - Use default user locale*/static const char *winpidgin_get_locale() {	const char *locale = NULL;	LCID lcid;#ifndef PORTABLE	char data[10];	DWORD datalen = 10;#endif	/* Check if user set PIDGINLANG env var */	if ((locale = getenv("PIDGINLANG")))		return locale;#ifndef PORTABLE	if (read_reg_string(HKEY_CURRENT_USER, "SOFTWARE\\pidgin",			"Installer Language", (LPBYTE) &data, &datalen)) {		if ((locale = winpidgin_lcid_to_posix(atoi(data))))			return locale;	}#endif	lcid = GetUserDefaultLCID();	if ((locale = winpidgin_lcid_to_posix(lcid)))		return locale;	return "en";}static void winpidgin_set_locale() {	const char *locale = NULL;	char envstr[25];	locale = winpidgin_get_locale();	snprintf(envstr, 25, "LANG=%s", locale);	printf("Setting locale: %s\n", envstr);	putenv(envstr);}#define PIDGIN_WM_FOCUS_REQUEST (WM_APP + 13)#define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14)static BOOL winpidgin_set_running() {	HANDLE h;	if ((h = CreateMutex(NULL, FALSE, "pidgin_is_running"))) {		if (GetLastError() == ERROR_ALREADY_EXISTS) {			HWND msg_win;			if((msg_win = FindWindow(TEXT("WinpidginMsgWinCls"), NULL)))				if(SendMessage(msg_win, PIDGIN_WM_FOCUS_REQUEST, (WPARAM) NULL, (LPARAM) NULL))					return FALSE;			/* If we get here, the focus request wasn't successful */			MessageBox(NULL,				"An instance of Pidgin is already running",				NULL, MB_OK | MB_TOPMOST);			return FALSE;		}	}	return TRUE;}#define PROTO_HANDLER_SWITCH "--protocolhandler="static void handle_protocol(char *cmd) {	char *remote_msg, *tmp1, *tmp2;	int len;	SIZE_T len_written;	HWND msg_win;	DWORD pid;	HANDLE process;	/* The start of the message */	tmp1 = cmd + strlen(PROTO_HANDLER_SWITCH);	/* The end of the message */	if ((tmp2 = strchr(tmp1, ' ')))		len = (tmp2 - tmp1);	else		len = strlen(tmp1);	if (len == 0) {		printf("No protocol message specified.\n");		return;	}	if (!(msg_win = FindWindow(TEXT("WinpidginMsgWinCls"), NULL))) {		printf("Unable to find an instance of Pidgin to handle protocol message.\n");		return;	}	GetWindowThreadProcessId(msg_win, &pid);	if (!(process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, pid))) {		DWORD dw = GetLastError();		const char *err_msg = get_win32_error_message(dw);		printf("Unable to open Pidgin process. (%u) %s\n", (UINT) dw, err_msg);		return;	}	printf("Trying to handle protocol message:\n'%*s'\n", len, tmp1);	/* MEM_COMMIT initializes the memory to zero,	 * so we don't need to worry that our section of tmp1 isn't nul-terminated */	if ((remote_msg = (char*) VirtualAllocEx(process, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE))) {		if (WriteProcessMemory(process, remote_msg, tmp1, len, &len_written)) {			if (!SendMessage(msg_win, PIDGIN_WM_PROTOCOL_HANDLE, len_written, (LPARAM) remote_msg))				printf("Unable to send protocol message to Pidgin instance.\n");		} else {			DWORD dw = GetLastError();			const char *err_msg = get_win32_error_message(dw);			printf("Unable to write to remote memory. (%u) %s\n", (UINT) dw, err_msg);		}		VirtualFreeEx(process, remote_msg, 0, MEM_RELEASE);	} else {		DWORD dw = GetLastError();		const char *err_msg = get_win32_error_message(dw);		printf("Unable to allocate remote memory. (%u) %s\n", (UINT) dw, err_msg);	}	CloseHandle(process);}int _stdcallWinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,		char *lpszCmdLine, int nCmdShow) {	char errbuf[512];	char pidgindir[MAX_PATH];	HMODULE hmod;	char *tmp;	/* If debug or help or version flag used, create console for output */	if (strstr(lpszCmdLine, "-d") || strstr(lpszCmdLine, "-h") || strstr(lpszCmdLine, "-v")) {		/* If stdout hasn't been redirected to a file, alloc a console		 *  (_istty() doesn't work for stuff using the GUI subsystem) */		if (_fileno(stdout) == -1) {			LPFNATTACHCONSOLE MyAttachConsole = NULL;			if ((hmod = GetModuleHandle("kernel32.dll"))) {				MyAttachConsole =					(LPFNATTACHCONSOLE)					GetProcAddress(hmod, "AttachConsole");			}			if ((MyAttachConsole && MyAttachConsole(ATTACH_PARENT_PROCESS))					|| AllocConsole()) {				freopen("CONOUT$", "w", stdout);				freopen("CONOUT$", "w", stderr);			}		}	}	/* If this is a protocol handler invocation, deal with it accordingly */	if ((tmp = strstr(lpszCmdLine, PROTO_HANDLER_SWITCH)) != NULL) {		handle_protocol(tmp);		return 0;	}	/* Load exception handler if we have it */	if (GetModuleFileName(NULL, pidgindir, MAX_PATH) != 0) {		char *prev = NULL;		tmp = pidgindir;		while ((tmp = strchr(tmp, '\\'))) {			prev = tmp;			tmp++;		}		if (prev) {			prev[0] = '\0';			strcat(pidgindir, "\\exchndl.dll");			if (LoadLibrary(pidgindir))				printf("Loaded exchndl.dll\n");		}	} else {		DWORD dw = GetLastError();		const char *err_msg = get_win32_error_message(dw);		snprintf(errbuf, 512,			"Error getting module filename.\nError: (%u) %s",			(UINT) dw, err_msg);		printf("%s", errbuf);		MessageBox(NULL, errbuf, NULL, MB_OK | MB_TOPMOST);	}#ifndef PORTABLE	if (!getenv("PIDGIN_NO_DLL_CHECK"))#endif		dll_prep();	winpidgin_set_locale();	/* If help or version flag used, do not check Mutex */	if (!strstr(lpszCmdLine, "-h") && !strstr(lpszCmdLine, "-v"))		if (!getenv("PIDGIN_MULTI_INST") && !winpidgin_set_running())			return 0;	/* Now we are ready for Pidgin .. */	if ((hmod = LoadLibrary("pidgin.dll"))) {		pidgin_main = (LPFNPIDGINMAIN) GetProcAddress(hmod, "pidgin_main");	}	if (!pidgin_main) {		DWORD dw = GetLastError();		BOOL mod_not_found = (dw == ERROR_MOD_NOT_FOUND || dw == ERROR_DLL_NOT_FOUND);		const char *err_msg = get_win32_error_message(dw);		snprintf(errbuf, 512, "Error loading pidgin.dll.\nError: (%u) %s%s%s",			(UINT) dw, err_msg,			mod_not_found ? "\n" : "",			mod_not_found ? "This probably means that GTK+ can't be found." : "");		printf("%s", errbuf);		MessageBox(NULL, errbuf, TEXT("Error"), MB_OK | MB_TOPMOST);		return 0;	}	return pidgin_main(hInstance, __argc, __argv);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -