* Description: Windows dependant code for Purple * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA static char *app_data_dir = NULL, *install_dir = NULL, *lib_dir = NULL, *locale_dir = NULL; static HINSTANCE libpurpledll_hInstance = NULL; /* Escape windows dir separators. This is needed when paths are saved, and on being read back have their '\' chars used as an escape char. Returns an allocated string which needs to be freed. char *wpurple_escape_dirsep(const char *filename) { const char *tmp = filename; g_return_val_if_fail(filename != NULL, NULL); ret = g_malloc0(strlen(filename) + sepcount + 1); /* Determine whether the specified dll contains the specified procedure. If so, load it (if not already loaded). */ FARPROC wpurple_find_and_loadproc(const char *dllname, const char *procedure) { wchar_t *wc_dllname = g_utf8_to_utf16(dllname, -1, NULL, NULL, NULL); if(!(hmod = GetModuleHandleW(wc_dllname))) { purple_debug_warning("wpurple", "%s not already loaded; loading it...\n", dllname); if(!(hmod = LoadLibraryW(wc_dllname))) { purple_debug_error("wpurple", "Could not load: %s (%s)\n", dllname, g_win32_error_message(GetLastError())); if((proc = GetProcAddress(hmod, procedure))) { purple_debug_info("wpurple", "This version of %s contains %s\n", purple_debug_warning("wpurple", "Function %s not found in dll %s\n", /* Determine Purple Paths during Runtime */ /* Get paths to special Windows folders. */ gchar *wpurple_get_special_folder(int folder_type) { wchar_t utf_16_dir[MAX_PATH + 1]; if (SUCCEEDED(SHGetFolderPathW(NULL, folder_type, NULL, SHGFP_TYPE_CURRENT, utf_16_dir))) { retval = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL); const char *wpurple_install_dir(void) { static gboolean initialized = FALSE; wchar_t winstall_dir[MAXPATHLEN]; if (GetModuleFileNameW(libpurpledll_hInstance, winstall_dir, tmp = g_utf16_to_utf8(winstall_dir, -1, tmp = g_win32_error_message(GetLastError()); purple_debug_error("wpurple", "GetModuleFileName error: %s\n", tmp); install_dir = g_path_get_dirname(tmp); const char *wpurple_lib_dir(void) { static gboolean initialized = FALSE; const char *inst_dir = wpurple_install_dir(); lib_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "plugins", inst_dir); const char *wpurple_locale_dir(void) { static gboolean initialized = FALSE; const char *inst_dir = wpurple_install_dir(); locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", inst_dir); const char *wpurple_data_dir(void) { /* Set app data dir, used by purple_home_dir */ const char *newenv = g_getenv("PURPLEHOME"); app_data_dir = g_strdup(newenv); app_data_dir = wpurple_get_special_folder(CSIDL_APPDATA); app_data_dir = g_strdup("C:"); purple_debug_info("wpurple", "Purple settings dir: %s\n", gboolean wpurple_write_reg_string(HKEY rootkey, const char *subkey, const char *valname, gboolean success = FALSE; wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL, if(RegOpenKeyExW(rootkey, wc_subkey, 0, KEY_SET_VALUE, ®_key) == ERROR_SUCCESS) { wchar_t *wc_valname = NULL; wc_valname = g_utf8_to_utf16(valname, -1, wchar_t *wc_value = g_utf8_to_utf16(value, -1, int len = (wcslen(wc_value) * sizeof(wchar_t)) + 1; if(RegSetValueExW(reg_key, wc_valname, 0, REG_SZ, if(RegDeleteValueW(reg_key, wc_valname) == ERROR_SUCCESS) static HKEY _reg_open_key(HKEY rootkey, const char *subkey, REGSAM access) { wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL, rv = RegOpenKeyExW(rootkey, wc_subkey, 0, access, ®_key); if (rv != ERROR_SUCCESS) { char *errmsg = g_win32_error_message(rv); purple_debug_error("wpurple", "Could not open reg key '%s' subkey '%s'.\nMessage: (%ld) %s\n", ((rootkey == HKEY_LOCAL_MACHINE) ? "HKLM" : (rootkey == HKEY_CURRENT_USER) ? "HKCU" : (rootkey == HKEY_CLASSES_ROOT) ? "HKCR" : "???"), static gboolean _reg_read(HKEY reg_key, const char *valname, LPDWORD type, LPBYTE data, LPDWORD data_len) { wchar_t *wc_valname = NULL; wc_valname = g_utf8_to_utf16(valname, -1, NULL, NULL, NULL); rv = RegQueryValueExW(reg_key, wc_valname, 0, type, data, data_len); if (rv != ERROR_SUCCESS) { char *errmsg = g_win32_error_message(rv); purple_debug_error("wpurple", "Could not read from reg key value '%s'.\nMessage: (%ld) %s\n", return (rv == ERROR_SUCCESS); gboolean wpurple_read_reg_dword(HKEY rootkey, const char *subkey, const char *valname, LPDWORD result) { HKEY reg_key = _reg_open_key(rootkey, subkey, KEY_QUERY_VALUE); gboolean success = FALSE; if(_reg_read(reg_key, valname, &type, (LPBYTE)result, &nbytes)) char *wpurple_read_reg_string(HKEY rootkey, const char *subkey, const char *valname) { HKEY reg_key = _reg_open_key(rootkey, subkey, KEY_QUERY_VALUE); if(_reg_read(reg_key, valname, &type, NULL, &nbytes) && type == REG_SZ) { LPBYTE data = (LPBYTE) g_new(wchar_t, ((nbytes + 1) / sizeof(wchar_t)) + 1); if(_reg_read(reg_key, valname, &type, data, &nbytes)) { wchar_t *wc_temp = (wchar_t*) data; wc_temp[nbytes / sizeof(wchar_t)] = '\0'; result = g_utf16_to_utf8(wc_temp, -1, void wpurple_init(void) { if (!g_thread_supported()) purple_debug_info("wpurple", "wpurple_init start\n"); purple_debug_info("wpurple", "libpurple version: " DISPLAY_VERSION "\n"); purple_debug_info("wpurple", "Glib:%u.%u.%u\n", glib_major_version, glib_minor_version, glib_micro_version); wVersionRequested = MAKEWORD(2, 2); WSAStartup(wVersionRequested, &wsaData); /* Confirm that the winsock DLL supports 2.2 */ /* Note that if the DLL supports versions greater than 2.2 in addition to 2.2, it will still return 2.2 in wVersion since that is the version we requested. */ if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) { purple_debug_error("wpurple", "Could not find a usable WinSock DLL. Oh well.\n"); purple_debug_info("wpurple", "wpurple_init end\n"); void wpurple_cleanup(void) { purple_debug_info("wpurple", "wpurple_cleanup\n"); libpurpledll_hInstance = NULL; wpurple_get_tz_offset() { TIME_ZONE_INFORMATION tzi; if ((ret = GetTimeZoneInformation(&tzi)) != TIME_ZONE_ID_INVALID) if (ret == TIME_ZONE_ID_DAYLIGHT) off -= tzi.DaylightBias * 60; /* suppress gcc "no previous prototype" warning */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { libpurpledll_hInstance = hinstDLL;