Mercurial > pidgin.yaz
comparison src/win32/win32dep.c @ 10673:179b0245a2f7
[gaim-migrate @ 12213]
This is patches 1115963 and 1115968 from rlaager, implementation of wgaim_get_special_folder() and using it to specify a sane default for the file chooser.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 08 Mar 2005 03:15:37 +0000 |
parents | 0f7452b1f777 |
children | 2b772e7094ef |
comparison
equal
deleted
inserted
replaced
10672:0925c898b73c | 10673:179b0245a2f7 |
---|---|
25 #include <windows.h> | 25 #include <windows.h> |
26 #include <io.h> | 26 #include <io.h> |
27 #include <stdlib.h> | 27 #include <stdlib.h> |
28 #include <stdio.h> | 28 #include <stdio.h> |
29 #include <winuser.h> | 29 #include <winuser.h> |
30 #include <shlobj.h> | |
31 | 30 |
32 #include <gtk/gtk.h> | 31 #include <gtk/gtk.h> |
33 #include <glib.h> | 32 #include <glib.h> |
34 #if GLIB_CHECK_VERSION(2,6,0) | 33 #if GLIB_CHECK_VERSION(2,6,0) |
35 # include <glib/gstdio.h> | 34 # include <glib/gstdio.h> |
51 #include "zlib.h" | 50 #include "zlib.h" |
52 #include "untar.h" | 51 #include "untar.h" |
53 | 52 |
54 #include <libintl.h> | 53 #include <libintl.h> |
55 | 54 |
55 #include "win32dep.h" | |
56 | |
56 /* | 57 /* |
57 * DEFINES & MACROS | 58 * DEFINES & MACROS |
58 */ | 59 */ |
59 #define _(x) gettext(x) | 60 #define _(x) gettext(x) |
60 | 61 |
81 typedef struct _WGAIM_FLASH_INFO WGAIM_FLASH_INFO; | 82 typedef struct _WGAIM_FLASH_INFO WGAIM_FLASH_INFO; |
82 | 83 |
83 /* | 84 /* |
84 * LOCALS | 85 * LOCALS |
85 */ | 86 */ |
86 static char app_data_dir[MAX_PATH + 1] = "C:"; | 87 static char *app_data_dir; |
87 static char install_dir[MAXPATHLEN]; | 88 static char install_dir[MAXPATHLEN]; |
88 static char lib_dir[MAXPATHLEN]; | 89 static char lib_dir[MAXPATHLEN]; |
89 static char locale_dir[MAXPATHLEN]; | 90 static char locale_dir[MAXPATHLEN]; |
90 static gboolean blink_turned_on = TRUE; | 91 static gboolean blink_turned_on = TRUE; |
91 | 92 |
97 | 98 |
98 /* | 99 /* |
99 * PROTOS | 100 * PROTOS |
100 */ | 101 */ |
101 LPFNFLASHWINDOWEX MyFlashWindowEx = NULL; | 102 LPFNFLASHWINDOWEX MyFlashWindowEx = NULL; |
102 LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL; | |
103 LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL; | |
104 | 103 |
105 FARPROC wgaim_find_and_loadproc(char*, char*); | 104 FARPROC wgaim_find_and_loadproc(char*, char*); |
106 extern void wgaim_gtkspell_init(); | 105 extern void wgaim_gtkspell_init(); |
107 char* wgaim_data_dir(void); | 106 char* wgaim_data_dir(void); |
108 | 107 |
231 } | 230 } |
232 } | 231 } |
233 | 232 |
234 /* Determine Gaim Paths during Runtime */ | 233 /* Determine Gaim Paths during Runtime */ |
235 | 234 |
235 /* Get paths to special Windows folders. */ | |
236 char *wgaim_get_special_folder(int folder_type) { | |
237 static LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL; | |
238 char *retval = NULL; | |
239 #if GLIB_CHECK_VERSION(2,6,0) | |
240 static LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL; | |
241 | |
242 if (!MySHGetFolderPathW) { | |
243 MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW) | |
244 wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathW"); | |
245 } | |
246 | |
247 if (MySHGetFolderPathW) { | |
248 wchar_t utf_16_dir[MAX_PATH + 1]; | |
249 | |
250 if (SUCCEEDED(MySHGetFolderPathW(NULL, folder_type, NULL, | |
251 SHGFP_TYPE_CURRENT, utf_16_dir))) { | |
252 retval = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL); | |
253 } | |
254 } | |
255 #endif | |
256 | |
257 if (!retval) { | |
258 if (!MySHGetFolderPathA) { | |
259 MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) | |
260 wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"); | |
261 } | |
262 if (MySHGetFolderPathA) { | |
263 char locale_dir[MAX_PATH + 1]; | |
264 | |
265 if (SUCCEEDED(MySHGetFolderPathA(NULL, folder_type, NULL, | |
266 SHGFP_TYPE_CURRENT, locale_dir))) { | |
267 #if GLIB_CHECK_VERSION(2,6,0) | |
268 retval = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL); | |
269 #else | |
270 retval = g_strdup(locale_dir); | |
271 #endif | |
272 } | |
273 } | |
274 } | |
275 | |
276 return retval; | |
277 } | |
278 | |
236 char* wgaim_install_dir(void) { | 279 char* wgaim_install_dir(void) { |
237 HMODULE hmod; | 280 HMODULE hmod; |
238 char* buf; | 281 char* buf; |
239 | 282 |
240 hmod = GetModuleHandle(NULL); | 283 hmod = GetModuleHandle(NULL); |
268 g_strlcat(locale_dir, G_DIR_SEPARATOR_S "locale", sizeof(locale_dir)); | 311 g_strlcat(locale_dir, G_DIR_SEPARATOR_S "locale", sizeof(locale_dir)); |
269 return (char*)&locale_dir; | 312 return (char*)&locale_dir; |
270 } | 313 } |
271 | 314 |
272 char* wgaim_data_dir(void) { | 315 char* wgaim_data_dir(void) { |
273 return (char*)&app_data_dir; | 316 return app_data_dir; |
274 } | 317 } |
275 | 318 |
276 /* Miscellaneous */ | 319 /* Miscellaneous */ |
277 | 320 |
278 gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { | 321 gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { |
450 if(putenv(newenv)<0) | 493 if(putenv(newenv)<0) |
451 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); | 494 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); |
452 g_free(newenv); | 495 g_free(newenv); |
453 | 496 |
454 /* Set app data dir, used by gaim_home_dir */ | 497 /* Set app data dir, used by gaim_home_dir */ |
455 newenv = (char*)g_getenv("GAIMHOME"); | 498 newenv = (char*) g_getenv("GAIMHOME"); |
456 if(!newenv) { | 499 if (newenv) { |
457 #if GLIB_CHECK_VERSION(2,6,0) | 500 app_data_dir = g_strdup(newenv); |
458 if ((MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathW"))) { | 501 } else { |
459 wchar_t utf_16_dir[MAX_PATH +1]; | 502 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA); |
460 char *temp; | 503 if (!app_data_dir) { |
461 MySHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, | 504 app_data_dir = g_strdup("C:"); |
462 SHGFP_TYPE_CURRENT, utf_16_dir); | |
463 temp = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL); | |
464 g_strlcpy(app_data_dir, temp, sizeof(app_data_dir)); | |
465 g_free(temp); | |
466 } else if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"))) { | |
467 char locale_dir[MAX_PATH + 1]; | |
468 char *temp; | |
469 MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, | |
470 SHGFP_TYPE_CURRENT, locale_dir); | |
471 temp = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL); | |
472 g_strlcpy(app_data_dir, temp, sizeof(app_data_dir)); | |
473 g_free(temp); | |
474 } | |
475 #else | |
476 if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"))) { | |
477 MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, | |
478 SHGFP_TYPE_CURRENT, app_data_dir); | |
479 } | |
480 #endif | |
481 else { | |
482 strcpy(app_data_dir, "C:"); | |
483 } | 505 } |
484 } | 506 } |
485 else { | 507 |
486 g_strlcpy(app_data_dir, newenv, sizeof(app_data_dir)); | 508 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir); |
487 } | |
488 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir); | |
489 | 509 |
490 /* IdleTracker Initialization */ | 510 /* IdleTracker Initialization */ |
491 if(!wgaim_set_idlehooks()) | 511 if(!wgaim_set_idlehooks()) |
492 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n"); | 512 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n"); |
493 | 513 |
503 /* winsock cleanup */ | 523 /* winsock cleanup */ |
504 WSACleanup(); | 524 WSACleanup(); |
505 | 525 |
506 /* Idle tracker cleanup */ | 526 /* Idle tracker cleanup */ |
507 wgaim_remove_idlehooks(); | 527 wgaim_remove_idlehooks(); |
528 | |
529 g_free(app_data_dir); | |
508 } | 530 } |
509 | 531 |
510 /* DLL initializer */ | 532 /* DLL initializer */ |
511 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { | 533 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { |
512 gaimdll_hInstance = hinstDLL; | 534 gaimdll_hInstance = hinstDLL; |