comparison libgaim/win32/win32dep.c @ 14269:d1cb45dec12f

[gaim-migrate @ 16951] Use lazy initialization for wgaim_data_dir() to allow it to be used before the core is initialized. Make win32 debug printing not allocate memory when it doesn't need to. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 21 Aug 2006 15:17:22 +0000
parents ab8a105eff62
children 7635195195c0
comparison
equal deleted inserted replaced
14268:e6892c0050ad 14269:d1cb45dec12f
43 /* 43 /*
44 * DEFINES & MACROS 44 * DEFINES & MACROS
45 */ 45 */
46 #define _(x) gettext(x) 46 #define _(x) gettext(x)
47 47
48 /*
49 * DATA STRUCTS
50 */
51
52 /* For shfolder.dll */ 48 /* For shfolder.dll */
53 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR); 49 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
54 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR); 50 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
55 51
56 /* 52 /*
57 * LOCALS 53 * LOCALS
58 */ 54 */
59 static char *app_data_dir, *install_dir, *lib_dir, *locale_dir; 55 static char *app_data_dir = NULL, *install_dir = NULL,
60 56 *lib_dir = NULL, *locale_dir = NULL;
61 /* 57
62 * GLOBALS 58 static HINSTANCE libgaimdll_hInstance = 0;
63 */ 59
64 HINSTANCE libgaimdll_hInstance = 0;
65
66 /*
67 * PROTOS
68 */
69
70 FARPROC wgaim_find_and_loadproc(char*, char*);
71 char* wgaim_data_dir(void);
72 60
73 /* 61 /*
74 * STATIC CODE 62 * STATIC CODE
75 */ 63 */
76 64
77 static void wgaim_debug_print(GaimDebugLevel level, const char *category, const char *format, va_list args) { 65 static void wgaim_debug_print(GaimDebugLevel level, const char *category,
66 const char *format, va_list args) {
78 char *str = NULL; 67 char *str = NULL;
79 if (args != NULL) { 68 if (args != NULL)
80 str = g_strdup_vprintf(format, args); 69 str = g_strdup_vprintf(format, args);
81 } else { 70 printf("%s%s%s",
82 str = g_strdup(format); 71 category ? category : "",
83 } 72 category ? ": " : "",
84 printf("%s%s%s", category ? category : "", category ? ": " : "", str); 73 str ? str : format);
85 g_free(str); 74 g_free(str);
86 } 75 }
87 76
88 static GaimDebugUiOps ops = { 77 static GaimDebugUiOps ops = {
89 wgaim_debug_print 78 wgaim_debug_print
261 250
262 return locale_dir; 251 return locale_dir;
263 } 252 }
264 253
265 char* wgaim_data_dir(void) { 254 char* wgaim_data_dir(void) {
255
256 if (!app_data_dir) {
257 /* Set app data dir, used by gaim_home_dir */
258 const char *newenv = g_getenv("GAIMHOME");
259 if (newenv)
260 app_data_dir = g_strdup(newenv);
261 else {
262 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
263 if (!app_data_dir)
264 app_data_dir = g_strdup("C:");
265 }
266 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n",
267 app_data_dir);
268 }
269
266 return app_data_dir; 270 return app_data_dir;
267 } 271 }
268 272
269 /* Miscellaneous */ 273 /* Miscellaneous */
270 274
316 wgaim_install_dir()); 320 wgaim_install_dir());
317 if (putenv(newenv) < 0) 321 if (putenv(newenv) < 0)
318 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); 322 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n");
319 g_free(newenv); 323 g_free(newenv);
320 324
321 /* Set app data dir, used by gaim_home_dir */
322 newenv = (char*) g_getenv("GAIMHOME");
323 if (newenv) {
324 app_data_dir = g_strdup(newenv);
325 } else {
326 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
327 if (!app_data_dir) {
328 app_data_dir = g_strdup("C:");
329 }
330 }
331
332 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir);
333
334 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n"); 325 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n");
335 } 326 }
336 327
337 /* Windows Cleanup */ 328 /* Windows Cleanup */
338 329
341 332
342 /* winsock cleanup */ 333 /* winsock cleanup */
343 WSACleanup(); 334 WSACleanup();
344 335
345 g_free(app_data_dir); 336 g_free(app_data_dir);
337 app_data_dir = NULL;
338
339 libgaimdll_hInstance = NULL;
346 } 340 }
347 341
348 /* DLL initializer */ 342 /* DLL initializer */
349 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { 343 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) {
350 libgaimdll_hInstance = hinstDLL; 344 libgaimdll_hInstance = hinstDLL;