comparison src/win32/win32dep.c @ 11323:caec745e390e

[gaim-migrate @ 13528] This fixes issues that were happening when wingaim was installed in a non-ASCII path. I can't believe that I didn't notice this before. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 21 Aug 2005 20:13:22 +0000
parents bb0d7b719af2
children 9f6df41df587
comparison
equal deleted inserted replaced
11322:162dd2f8ad92 11323:caec745e390e
28 #include <stdio.h> 28 #include <stdio.h>
29 #include <winuser.h> 29 #include <winuser.h>
30 30
31 #include <gtk/gtk.h> 31 #include <gtk/gtk.h>
32 #include <glib.h> 32 #include <glib.h>
33 #if GLIB_CHECK_VERSION(2,6,0) 33 #include <glib/gstdio.h>
34 # include <glib/gstdio.h>
35 #else
36 # define g_fopen fopen
37 # define g_unlink unlink
38 #endif
39 #include <gdk/gdkwin32.h> 34 #include <gdk/gdkwin32.h>
40 35
41 #include "gaim.h" 36 #include "gaim.h"
42 #include "debug.h" 37 #include "debug.h"
43 #include "notify.h" 38 #include "notify.h"
73 } SHGFP_TYPE; 68 } SHGFP_TYPE;
74 69
75 /* 70 /*
76 * LOCALS 71 * LOCALS
77 */ 72 */
78 static char *app_data_dir; 73 static char *app_data_dir, *install_dir, *lib_dir, *locale_dir;
79 static char install_dir[MAXPATHLEN];
80 static char lib_dir[MAXPATHLEN];
81 static char locale_dir[MAXPATHLEN];
82 74
83 /* 75 /*
84 * GLOBALS 76 * GLOBALS
85 */ 77 */
86 HINSTANCE gaimexe_hInstance = 0; 78 HINSTANCE gaimexe_hInstance = 0;
226 218
227 return retval; 219 return retval;
228 } 220 }
229 221
230 char* wgaim_install_dir(void) { 222 char* wgaim_install_dir(void) {
231 HMODULE hmod; 223 static gboolean initialized = FALSE;
232 char* buf; 224
233 225 if (!initialized) {
234 hmod = GetModuleHandle(NULL); 226 char *tmp = NULL;
235 if( hmod == 0 ) { 227 if (G_WIN32_HAVE_WIDECHAR_API()) {
236 buf = g_win32_error_message( GetLastError() ); 228 wchar_t winstall_dir[MAXPATHLEN];
237 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "GetModuleHandle error: %s\n", buf); 229 if (GetModuleFileNameW(NULL, winstall_dir,
238 g_free(buf); 230 MAXPATHLEN) > 0) {
239 return NULL; 231 tmp = g_utf16_to_utf8(winstall_dir, -1,
240 } 232 NULL, NULL, NULL);
241 if(GetModuleFileName( hmod, (char*)&install_dir, MAXPATHLEN ) == 0) { 233 }
242 buf = g_win32_error_message( GetLastError() ); 234 } else {
243 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "GetModuleFileName error: %s\n", buf); 235 gchar cpinstall_dir[MAXPATHLEN];
244 g_free(buf); 236 if (GetModuleFileNameA(NULL, cpinstall_dir,
245 return NULL; 237 MAXPATHLEN) > 0) {
246 } 238 tmp = g_locale_to_utf8(cpinstall_dir,
247 buf = g_path_get_dirname( install_dir ); 239 -1, NULL, NULL, NULL);
248 strcpy( (char*)&install_dir, buf ); 240 }
249 g_free( buf ); 241 }
250 242
251 return (char*)&install_dir; 243 if (tmp == NULL) {
244 tmp = g_win32_error_message(GetLastError());
245 gaim_debug(GAIM_DEBUG_ERROR, "wgaim",
246 "GetModuleFileName error: %s\n", tmp);
247 g_free(tmp);
248 return NULL;
249 } else {
250 install_dir = g_path_get_dirname(tmp);
251 g_free(tmp);
252 initialized = TRUE;
253 }
254 }
255
256 return install_dir;
252 } 257 }
253 258
254 char* wgaim_lib_dir(void) { 259 char* wgaim_lib_dir(void) {
255 strcpy(lib_dir, wgaim_install_dir()); 260 static gboolean initialized = FALSE;
256 g_strlcat(lib_dir, G_DIR_SEPARATOR_S "plugins", sizeof(lib_dir)); 261
257 return (char*)&lib_dir; 262 if (!initialized) {
263 char *inst_dir = wgaim_install_dir();
264 if (inst_dir != NULL) {
265 lib_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "plugins", inst_dir);
266 initialized = TRUE;
267 } else {
268 return NULL;
269 }
270 }
271
272 return lib_dir;
258 } 273 }
259 274
260 char* wgaim_locale_dir(void) { 275 char* wgaim_locale_dir(void) {
261 strcpy(locale_dir, wgaim_install_dir()); 276 static gboolean initialized = FALSE;
262 g_strlcat(locale_dir, G_DIR_SEPARATOR_S "locale", sizeof(locale_dir)); 277
263 return (char*)&locale_dir; 278 if (!initialized) {
279 char *inst_dir = wgaim_install_dir();
280 if (inst_dir != NULL) {
281 locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", inst_dir);
282 initialized = TRUE;
283 } else {
284 return NULL;
285 }
286 }
287
288 return locale_dir;
264 } 289 }
265 290
266 char* wgaim_data_dir(void) { 291 char* wgaim_data_dir(void) {
267 return app_data_dir; 292 return app_data_dir;
268 } 293 }
371 396
372 void wgaim_init(HINSTANCE hint) { 397 void wgaim_init(HINSTANCE hint) {
373 WORD wVersionRequested; 398 WORD wVersionRequested;
374 WSADATA wsaData; 399 WSADATA wsaData;
375 char *perlenv; 400 char *perlenv;
376 char *newenv; 401 char *newenv;
377 402
378 gaim_debug_set_ui_ops(&ops); 403 gaim_debug_set_ui_ops(&ops);
379 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init start\n"); 404 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init start\n");
380 405
381 gaimexe_hInstance = hint; 406 gaimexe_hInstance = hint;
382 407
383 /* Winsock init */ 408 /* Winsock init */
392 HIBYTE( wsaData.wVersion ) != 2 ) { 417 HIBYTE( wsaData.wVersion ) != 2 ) {
393 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Could not find a usable WinSock DLL. Oh well.\n"); 418 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Could not find a usable WinSock DLL. Oh well.\n");
394 WSACleanup(); 419 WSACleanup();
395 } 420 }
396 421
397 /* Set Environmental Variables */ 422 /* Set Environmental Variables */
398 /* Tell perl where to find Gaim's perl modules */ 423 /* Tell perl where to find Gaim's perl modules */
399 perlenv = (char*)g_getenv("PERL5LIB"); 424 perlenv = (char*) g_getenv("PERL5LIB");
400 newenv = g_strdup_printf("PERL5LIB=%s%s%s%s", 425 newenv = g_strdup_printf("PERL5LIB=%s%s%s%s",
401 perlenv ? perlenv : "", 426 perlenv ? perlenv : "",
402 perlenv ? ";" : "", 427 perlenv ? ";" : "",
403 wgaim_install_dir(), 428 wgaim_install_dir(),
404 "\\perlmod;"); 429 "\\perlmod;");
405 if(putenv(newenv)<0) 430 if (putenv(newenv) < 0)
406 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); 431 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n");
407 g_free(newenv); 432 g_free(newenv);
408 433
409 /* Set app data dir, used by gaim_home_dir */ 434 /* Set app data dir, used by gaim_home_dir */
410 newenv = (char*) g_getenv("GAIMHOME"); 435 newenv = (char*) g_getenv("GAIMHOME");
411 if (newenv) { 436 if (newenv) {
412 app_data_dir = g_strdup(newenv); 437 app_data_dir = g_strdup(newenv);
422 /* IdleTracker Initialization */ 447 /* IdleTracker Initialization */
423 if(!wgaim_set_idlehooks()) 448 if(!wgaim_set_idlehooks())
424 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n"); 449 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n");
425 450
426 wgaim_gtkspell_init(); 451 wgaim_gtkspell_init();
427 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n"); 452 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n");
428 } 453 }
429 454
430 /* Windows Cleanup */ 455 /* Windows Cleanup */
431 456
432 void wgaim_cleanup(void) { 457 void wgaim_cleanup(void) {