annotate libgaim/win32/win32dep.c @ 14427:1e00e8245720

[gaim-migrate @ 17137] Patch from wabz (Richard Nelson) to show 'Last Seen' for offline buddies. I have also added a fix to show offline buddies in the tooltip for a contact if 'show offline buddies' is turned on. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 03 Sep 2006 08:01:12 +0000
parents 7635195195c0
children 51685370de57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
1 /*
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
2 * gaim
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
3 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
4 * File: win32dep.c
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
5 * Date: June, 2002
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
6 * Description: Windows dependant code for Gaim
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
7 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
8 * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
9 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
13 * (at your option) any later version.
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
14 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
18 * GNU General Public License for more details.
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
19 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
23 *
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
24 */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
25 #define _WIN32_IE 0x500
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
26 #include <windows.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
27 #include <io.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
28 #include <stdlib.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
30 #include <winuser.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
31
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
32 #include <glib.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
33 #include <glib/gstdio.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
34
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
35 #include "gaim.h"
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
36 #include "debug.h"
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
37 #include "notify.h"
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
38
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
39 #include <libintl.h>
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
40
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
41 #include "win32dep.h"
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
42
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
43 /*
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
44 * DEFINES & MACROS
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
45 */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
46 #define _(x) gettext(x)
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
47
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
48 /* For shfolder.dll */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
49 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
50 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
51
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
52 /*
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
53 * LOCALS
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
54 */
14269
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
55 static char *app_data_dir = NULL, *install_dir = NULL,
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
56 *lib_dir = NULL, *locale_dir = NULL;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
57
14269
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
58 static HINSTANCE libgaimdll_hInstance = 0;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
59
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
60
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
61 /*
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
62 * STATIC CODE
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
63 */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
64
14269
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
65 static void wgaim_debug_print(GaimDebugLevel level, const char *category,
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
66 const char *arg_s) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
67 if(category)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
68 printf("%s: %s", category, arg_s);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
69 else
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
70 printf(arg_s);
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
71 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
72
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
73 static GaimDebugUiOps ops = {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
74 wgaim_debug_print
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
75 };
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
76
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
77 /*
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
78 * PUBLIC CODE
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
79 */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
80
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
81 /* Escape windows dir separators. This is needed when paths are saved,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
82 and on being read back have their '\' chars used as an escape char.
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
83 Returns an allocated string which needs to be freed.
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
84 */
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
85 char *wgaim_escape_dirsep(const char *filename) {
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
86 int sepcount = 0;
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
87 const char *tmp = filename;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
88 char *ret;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
89 int cnt = 0;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
90
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
91 g_return_val_if_fail(filename != NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
92
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
93 while(*tmp) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
94 if(*tmp == '\\')
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
95 sepcount++;
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
96 tmp++;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
97 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
98 ret = g_malloc0(strlen(filename) + sepcount + 1);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
99 while(*filename) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
100 ret[cnt] = *filename;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
101 if(*filename == '\\')
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
102 ret[++cnt] = '\\';
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
103 filename++;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
104 cnt++;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
105 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
106 ret[cnt] = '\0';
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
107 return ret;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
108 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
109
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
110 /* Determine whether the specified dll contains the specified procedure.
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
111 If so, load it (if not already loaded). */
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
112 FARPROC wgaim_find_and_loadproc(const char *dllname, const char *procedure) {
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
113 HMODULE hmod;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
114 BOOL did_load = FALSE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
115 FARPROC proc = 0;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
116
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
117 if(!(hmod = GetModuleHandle(dllname))) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
118 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "%s not already loaded; loading it...\n", dllname);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
119 if(!(hmod = LoadLibrary(dllname))) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
120 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Could not load: %s\n", dllname);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
121 return NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
122 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
123 else
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
124 did_load = TRUE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
125 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
126
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
127 if((proc = GetProcAddress(hmod, procedure))) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
128 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "This version of %s contains %s\n",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
129 dllname, procedure);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
130 return proc;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
131 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
132 else {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
133 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Function %s not found in dll %s\n",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
134 procedure, dllname);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
135 if(did_load) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
136 /* unload dll */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
137 FreeLibrary(hmod);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
138 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
139 return NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
140 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
141 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
142
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
143 /* Determine Gaim Paths during Runtime */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
144
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
145 /* Get paths to special Windows folders. */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
146 char *wgaim_get_special_folder(int folder_type) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
147 static LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
148 static LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
149 char *retval = NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
150
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
151 if (!MySHGetFolderPathW) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
152 MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW)
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
153 wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathW");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
154 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
155
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
156 if (MySHGetFolderPathW) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
157 wchar_t utf_16_dir[MAX_PATH + 1];
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
158
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
159 if (SUCCEEDED(MySHGetFolderPathW(NULL, folder_type, NULL,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
160 SHGFP_TYPE_CURRENT, utf_16_dir))) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
161 retval = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
162 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
163 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
164
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
165 if (!retval) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
166 if (!MySHGetFolderPathA) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
167 MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA)
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
168 wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
169 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
170 if (MySHGetFolderPathA) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
171 char locale_dir[MAX_PATH + 1];
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
172
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
173 if (SUCCEEDED(MySHGetFolderPathA(NULL, folder_type, NULL,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
174 SHGFP_TYPE_CURRENT, locale_dir))) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
175 retval = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
176 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
177 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
178 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
179
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
180 return retval;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
181 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
182
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
183 const char *wgaim_install_dir(void) {
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
184 static gboolean initialized = FALSE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
185
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
186 if (!initialized) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
187 char *tmp = NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
188 if (G_WIN32_HAVE_WIDECHAR_API()) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
189 wchar_t winstall_dir[MAXPATHLEN];
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
190 if (GetModuleFileNameW(NULL, winstall_dir,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
191 MAXPATHLEN) > 0) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
192 tmp = g_utf16_to_utf8(winstall_dir, -1,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
193 NULL, NULL, NULL);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
194 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
195 } else {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
196 gchar cpinstall_dir[MAXPATHLEN];
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
197 if (GetModuleFileNameA(NULL, cpinstall_dir,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
198 MAXPATHLEN) > 0) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
199 tmp = g_locale_to_utf8(cpinstall_dir,
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
200 -1, NULL, NULL, NULL);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
201 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
202 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
203
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
204 if (tmp == NULL) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
205 tmp = g_win32_error_message(GetLastError());
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
206 gaim_debug(GAIM_DEBUG_ERROR, "wgaim",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
207 "GetModuleFileName error: %s\n", tmp);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
208 g_free(tmp);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
209 return NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
210 } else {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
211 install_dir = g_path_get_dirname(tmp);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
212 g_free(tmp);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
213 initialized = TRUE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
214 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
215 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
216
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
217 return install_dir;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
218 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
219
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
220 const char *wgaim_lib_dir(void) {
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
221 static gboolean initialized = FALSE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
222
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
223 if (!initialized) {
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
224 const char *inst_dir = wgaim_install_dir();
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
225 if (inst_dir != NULL) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
226 lib_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "plugins", inst_dir);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
227 initialized = TRUE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
228 } else {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
229 return NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
230 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
231 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
232
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
233 return lib_dir;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
234 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
235
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
236 const char *wgaim_locale_dir(void) {
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
237 static gboolean initialized = FALSE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
238
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
239 if (!initialized) {
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
240 const char *inst_dir = wgaim_install_dir();
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
241 if (inst_dir != NULL) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
242 locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", inst_dir);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
243 initialized = TRUE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
244 } else {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
245 return NULL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
246 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
247 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
248
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
249 return locale_dir;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
250 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
251
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
252 const char *wgaim_data_dir(void) {
14269
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
253
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
254 if (!app_data_dir) {
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
255 /* Set app data dir, used by gaim_home_dir */
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
256 const char *newenv = g_getenv("GAIMHOME");
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
257 if (newenv)
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
258 app_data_dir = g_strdup(newenv);
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
259 else {
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
260 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
261 if (!app_data_dir)
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
262 app_data_dir = g_strdup("C:");
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
263 }
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
264 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n",
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
265 app_data_dir);
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
266 }
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
267
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
268 return app_data_dir;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
269 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
270
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
271 /* Miscellaneous */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
272
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
273 gboolean wgaim_write_reg_string(HKEY rootkey, const char *subkey, const char *valname,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
274 const char *value) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
275 HKEY reg_key;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
276 gboolean success = FALSE;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
277
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
278 if(G_WIN32_HAVE_WIDECHAR_API()) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
279 wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
280 NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
281
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
282 if(RegOpenKeyExW(rootkey, wc_subkey, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
283 KEY_SET_VALUE, &reg_key) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
284 wchar_t *wc_valname = NULL;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
285
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
286 if (valname)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
287 wc_valname = g_utf8_to_utf16(valname, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
288 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
289
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
290 if(value) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
291 wchar_t *wc_value = g_utf8_to_utf16(value, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
292 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
293 int len = (wcslen(wc_value) * sizeof(wchar_t)) + 1;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
294 if(RegSetValueExW(reg_key, wc_valname, 0, REG_SZ,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
295 (LPBYTE)wc_value, len
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
296 ) == ERROR_SUCCESS)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
297 success = TRUE;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
298 g_free(wc_value);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
299 } else
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
300 if(RegDeleteValueW(reg_key, wc_valname) == ERROR_SUCCESS)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
301 success = TRUE;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
302
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
303 g_free(wc_valname);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
304 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
305 g_free(wc_subkey);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
306 } else {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
307 char *cp_subkey = g_locale_from_utf8(subkey, -1, NULL,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
308 NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
309 if(RegOpenKeyExA(rootkey, cp_subkey, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
310 KEY_SET_VALUE, &reg_key) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
311 char *cp_valname = NULL;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
312 if(valname)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
313 cp_valname = g_locale_from_utf8(valname, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
314 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
315
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
316 if (value) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
317 char *cp_value = g_locale_from_utf8(value, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
318 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
319 int len = strlen(cp_value) + 1;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
320 if(RegSetValueExA(reg_key, cp_valname, 0, REG_SZ,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
321 cp_value, len
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
322 ) == ERROR_SUCCESS)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
323 success = TRUE;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
324 g_free(cp_value);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
325 } else
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
326 if(RegDeleteValueA(reg_key, cp_valname) == ERROR_SUCCESS)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
327 success = TRUE;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
328
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
329 g_free(cp_valname);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
330 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
331 g_free(cp_subkey);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
332 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
333
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
334 if(reg_key != NULL)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
335 RegCloseKey(reg_key);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
336
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
337 return success;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
338 }
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
339
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
340 char *wgaim_read_reg_string(HKEY rootkey, const char *subkey, const char *valname) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
341
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
342 DWORD type;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
343 DWORD nbytes;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
344 HKEY reg_key;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
345 char *result = NULL;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
346
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
347 if(G_WIN32_HAVE_WIDECHAR_API()) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
348 wchar_t *wc_subkey = g_utf8_to_utf16(subkey, -1, NULL,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
349 NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
350
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
351 if(RegOpenKeyExW(rootkey, wc_subkey, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
352 KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
353 wchar_t *wc_valname = NULL;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
354 if (valname)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
355 wc_valname = g_utf8_to_utf16(valname, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
356 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
357
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
358 if(RegQueryValueExW(reg_key, wc_valname, 0, &type,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
359 NULL, &nbytes) == ERROR_SUCCESS
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
360 && type == REG_SZ) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
361 wchar_t *wc_temp =
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
362 g_new(wchar_t, ((nbytes + 1) / sizeof(wchar_t)) + 1);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
363
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
364 if(RegQueryValueExW(reg_key, wc_valname, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
365 &type, (LPBYTE) wc_temp,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
366 &nbytes) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
367 wc_temp[nbytes / sizeof(wchar_t)] = '\0';
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
368 result = g_utf16_to_utf8(wc_temp, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
369 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
370 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
371 g_free(wc_temp);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
372 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
373 g_free(wc_valname);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
374 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
375 g_free(wc_subkey);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
376 } else {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
377 char *cp_subkey = g_locale_from_utf8(subkey, -1, NULL,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
378 NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
379 if(RegOpenKeyExA(rootkey, cp_subkey, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
380 KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
381 char *cp_valname = NULL;
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
382 if(valname)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
383 cp_valname = g_locale_from_utf8(valname, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
384 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
385
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
386 if(RegQueryValueExA(reg_key, cp_valname, 0, &type,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
387 NULL, &nbytes) == ERROR_SUCCESS
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
388 && type == REG_SZ) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
389 char *cp_temp = g_malloc(nbytes + 1);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
390
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
391 if(RegQueryValueExA(reg_key, cp_valname, 0,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
392 &type, cp_temp,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
393 &nbytes) == ERROR_SUCCESS) {
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
394 cp_temp[nbytes] = '\0';
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
395 result = g_locale_to_utf8(cp_temp, -1,
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
396 NULL, NULL, NULL);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
397 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
398 g_free (cp_temp);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
399 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
400 g_free(cp_valname);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
401 }
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
402 g_free(cp_subkey);
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
403 }
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
404
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
405 if(reg_key != NULL)
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
406 RegCloseKey(reg_key);
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
407
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
408 return result;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
409 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
410
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
411 void wgaim_init(void) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
412 WORD wVersionRequested;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
413 WSADATA wsaData;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
414 const char *perlenv;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
415 char *newenv;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
416
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
417 gaim_debug_set_ui_ops(&ops);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
418 gaim_debug_info("wgaim", "wgaim_init start\n");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
419
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
420 gaim_debug_info("wgaim", "Glib:%u.%u.%u\n",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
421 glib_major_version, glib_minor_version, glib_micro_version);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
422
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
423 /* Winsock init */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
424 wVersionRequested = MAKEWORD(2, 2);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
425 WSAStartup(wVersionRequested, &wsaData);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
426
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
427 /* Confirm that the winsock DLL supports 2.2 */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
428 /* Note that if the DLL supports versions greater than
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
429 2.2 in addition to 2.2, it will still return 2.2 in
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
430 wVersion since that is the version we requested. */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
431 if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
432 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Could not find a usable WinSock DLL. Oh well.\n");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
433 WSACleanup();
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
434 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
435
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
436 /* Set Environmental Variables */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
437 /* Tell perl where to find Gaim's perl modules */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
438 perlenv = g_getenv("PERL5LIB");
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
439 newenv = g_strdup_printf("%s%s%s" G_DIR_SEPARATOR_S "perlmod;",
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
440 perlenv ? perlenv : "",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
441 perlenv ? ";" : "",
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
442 wgaim_install_dir());
14272
7635195195c0 [gaim-migrate @ 16957]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14269
diff changeset
443 if (!g_setenv("PERL5LIB", newenv, TRUE))
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
444 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
445 g_free(newenv);
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
446
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
447 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
448 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
449
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
450 /* Windows Cleanup */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
451
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
452 void wgaim_cleanup(void) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
453 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_cleanup\n");
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
454
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
455 /* winsock cleanup */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
456 WSACleanup();
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
457
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
458 g_free(app_data_dir);
14269
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
459 app_data_dir = NULL;
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
460
d1cb45dec12f [gaim-migrate @ 16951]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14224
diff changeset
461 libgaimdll_hInstance = NULL;
14224
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
462 }
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
463
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
464 /* DLL initializer */
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
465 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) {
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
466 libgaimdll_hInstance = hinstDLL;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
467 return TRUE;
ab8a105eff62 [gaim-migrate @ 16905]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
diff changeset
468 }