comparison src/win32/win32dep.c @ 13321:c61c0a4ba6de

[gaim-migrate @ 15690] Minor cleanups. Print GLib and GTK+ versions to the wingaim debug log. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 23 Feb 2006 15:19:35 +0000
parents bf01b160ab0d
children e186876efaf3
comparison
equal deleted inserted replaced
13320:ab67558271ff 13321:c61c0a4ba6de
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * 23 *
24 */ 24 */
25 #define _WIN32_IE 0x500
25 #include <windows.h> 26 #include <windows.h>
26 #include <io.h> 27 #include <io.h>
27 #include <stdlib.h> 28 #include <stdlib.h>
28 #include <stdio.h> 29 #include <stdio.h>
29 #include <winuser.h> 30 #include <winuser.h>
54 */ 55 */
55 56
56 /* For shfolder.dll */ 57 /* For shfolder.dll */
57 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR); 58 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHA)(HWND, int, HANDLE, DWORD, LPSTR);
58 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR); 59 typedef HRESULT (CALLBACK* LPFNSHGETFOLDERPATHW)(HWND, int, HANDLE, DWORD, LPWSTR);
59
60 typedef enum {
61 SHGFP_TYPE_CURRENT = 0, /* current value for user, verify it exists */
62 SHGFP_TYPE_DEFAULT = 1, /* default value, may not exist */
63 } SHGFP_TYPE;
64 60
65 /* 61 /*
66 * LOCALS 62 * LOCALS
67 */ 63 */
68 static char *app_data_dir, *install_dir, *lib_dir, *locale_dir; 64 static char *app_data_dir, *install_dir, *lib_dir, *locale_dir;
90 if (args != NULL) { 86 if (args != NULL) {
91 str = g_strdup_vprintf(format, args); 87 str = g_strdup_vprintf(format, args);
92 } else { 88 } else {
93 str = g_strdup(format); 89 str = g_strdup(format);
94 } 90 }
95 printf("%s%s%s", category?category:"", category?": ":"",str); 91 printf("%s%s%s", category ? category : "", category ? ": " : "", str);
96 g_free(str); 92 g_free(str);
97 } 93 }
98 94
99 static GaimDebugUiOps ops = { 95 static GaimDebugUiOps ops = {
100 wgaim_debug_print 96 wgaim_debug_print
101 }; 97 };
102 98
103 /* 99 /*
104 * PUBLIC CODE 100 * PUBLIC CODE
110 106
111 /* Escape windows dir separators. This is needed when paths are saved, 107 /* Escape windows dir separators. This is needed when paths are saved,
112 and on being read back have their '\' chars used as an escape char. 108 and on being read back have their '\' chars used as an escape char.
113 Returns an allocated string which needs to be freed. 109 Returns an allocated string which needs to be freed.
114 */ 110 */
115 char* wgaim_escape_dirsep( char* filename ) { 111 char* wgaim_escape_dirsep(char* filename) {
116 int sepcount=0; 112 int sepcount = 0;
117 char* ret=NULL; 113 char* ret = NULL;
118 int cnt=0; 114 int cnt = 0;
119 115
120 ret = filename; 116 ret = filename;
121 while(*ret) { 117 while(*ret) {
122 if(*ret == '\\') 118 if(*ret == '\\')
123 sepcount++; 119 sepcount++;
135 return ret; 131 return ret;
136 } 132 }
137 133
138 /* Determine whether the specified dll contains the specified procedure. 134 /* Determine whether the specified dll contains the specified procedure.
139 If so, load it (if not already loaded). */ 135 If so, load it (if not already loaded). */
140 FARPROC wgaim_find_and_loadproc( char* dllname, char* procedure ) { 136 FARPROC wgaim_find_and_loadproc(char* dllname, char* procedure) {
141 HMODULE hmod; 137 HMODULE hmod;
142 int did_load=0; 138 BOOL did_load = FALSE;
143 FARPROC proc = 0; 139 FARPROC proc = 0;
144 140
145 if(!(hmod=GetModuleHandle(dllname))) { 141 if(!(hmod = GetModuleHandle(dllname))) {
146 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "%s not found. Loading it..\n", dllname); 142 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "%s not found. Loading it..\n", dllname);
147 if(!(hmod = LoadLibrary(dllname))) { 143 if(!(hmod = LoadLibrary(dllname))) {
148 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Could not load: %s\n", dllname); 144 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Could not load: %s\n", dllname);
149 return NULL; 145 return NULL;
150 } 146 }
151 else 147 else
152 did_load = 1; 148 did_load = TRUE;
153 } 149 }
154 150
155 if((proc=GetProcAddress(hmod, procedure))) { 151 if((proc = GetProcAddress(hmod, procedure))) {
156 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "This version of %s contains %s\n", 152 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "This version of %s contains %s\n",
157 dllname, procedure); 153 dllname, procedure);
158 return proc; 154 return proc;
159 } 155 }
160 else { 156 else {
161 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Function %s not found in dll %s\n", 157 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Function %s not found in dll %s\n",
162 procedure, dllname); 158 procedure, dllname);
163 if(did_load) { 159 if(did_load) {
164 /* unload dll */ 160 /* unload dll */
165 FreeLibrary(hmod); 161 FreeLibrary(hmod);
166 } 162 }
167 return NULL; 163 return NULL;
282 278
283 return locale_dir; 279 return locale_dir;
284 } 280 }
285 281
286 char* wgaim_data_dir(void) { 282 char* wgaim_data_dir(void) {
287 return app_data_dir; 283 return app_data_dir;
288 } 284 }
289 285
290 /* Miscellaneous */ 286 /* Miscellaneous */
291 287
292 gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { 288 gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) {
293 HKEY hkey; 289 HKEY hkey;
294 gboolean ret = FALSE; 290 gboolean ret = FALSE;
295 291
296 if(ERROR_SUCCESS == RegOpenKeyEx(key, 292 if(ERROR_SUCCESS == RegOpenKeyEx(key, sub_key, 0, KEY_QUERY_VALUE,
297 sub_key, 293 &hkey)) {
298 0, KEY_QUERY_VALUE, &hkey)) { 294 if(ERROR_SUCCESS == RegQueryValueEx(hkey, val_name, 0, NULL,
299 if(ERROR_SUCCESS == RegQueryValueEx(hkey, val_name, 0, NULL, data, data_len)) 295 data, data_len))
300 ret = TRUE; 296 ret = TRUE;
301 RegCloseKey(key); 297 RegCloseKey(key);
302 } 298 }
303 return ret; 299 return ret;
304 } 300 }
305 301
306 int wgaim_gz_decompress(const char* in, const char* out) { 302 int wgaim_gz_decompress(const char* in, const char* out) {
307 gzFile fin; 303 gzFile fin;
308 FILE *fout; 304 FILE *fout;
319 else { 315 else {
320 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "gzopen failed to open: %s\n", in); 316 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "gzopen failed to open: %s\n", in);
321 return 0; 317 return 0;
322 } 318 }
323 319
324 while((ret=gzread(fin, buf, 1024))) { 320 while((ret = gzread(fin, buf, 1024))) {
325 if(fwrite(buf, 1, ret, fout) < ret) { 321 if(fwrite(buf, 1, ret, fout) < ret) {
326 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "Error writing %d bytes to file\n", ret); 322 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_decompress", "Error writing %d bytes to file\n", ret);
327 gzclose(fin); 323 gzclose(fin);
328 fclose(fout); 324 fclose(fout);
329 return 0; 325 return 0;
346 342
347 sprintf(tmpfile, "%s%s%s", g_get_tmp_dir(), G_DIR_SEPARATOR_S, _mktemp(template)); 343 sprintf(tmpfile, "%s%s%s", g_get_tmp_dir(), G_DIR_SEPARATOR_S, _mktemp(template));
348 if(wgaim_gz_decompress(filename, tmpfile)) { 344 if(wgaim_gz_decompress(filename, tmpfile)) {
349 int ret; 345 int ret;
350 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET)) 346 if(untar(tmpfile, destdir, UNTAR_FORCE | UNTAR_QUIET))
351 ret=1; 347 ret = 1;
352 else { 348 else {
353 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_untar", "Failure untaring %s\n", tmpfile); 349 gaim_debug(GAIM_DEBUG_ERROR, "wgaim_gz_untar", "Failure untaring %s\n", tmpfile);
354 ret=0; 350 ret = 0;
355 } 351 }
356 g_unlink(tmpfile); 352 g_unlink(tmpfile);
357 return ret; 353 return ret;
358 } 354 }
359 else { 355 else {
364 360
365 void wgaim_notify_uri(const char *uri) { 361 void wgaim_notify_uri(const char *uri) {
366 SHELLEXECUTEINFO sinfo; 362 SHELLEXECUTEINFO sinfo;
367 363
368 memset(&sinfo, 0, sizeof(sinfo)); 364 memset(&sinfo, 0, sizeof(sinfo));
369 sinfo.cbSize = sizeof(sinfo); 365 sinfo.cbSize = sizeof(sinfo);
370 sinfo.fMask = SEE_MASK_CLASSNAME; 366 sinfo.fMask = SEE_MASK_CLASSNAME;
371 sinfo.lpVerb = "open"; 367 sinfo.lpVerb = "open";
372 sinfo.lpFile = uri; 368 sinfo.lpFile = uri;
373 sinfo.nShow = SW_SHOWNORMAL; 369 sinfo.nShow = SW_SHOWNORMAL;
374 sinfo.lpClass = "http"; 370 sinfo.lpClass = "http";
375 371
376 /* We'll allow whatever URI schemes are supported by the 372 /* We'll allow whatever URI schemes are supported by the
377 default http browser. 373 default http browser.
378 */ 374 */
379 if(!ShellExecuteEx(&sinfo)) 375 if(!ShellExecuteEx(&sinfo))
380 gaim_debug_error("wgaim", "Error opening URI: %s error: %d\n", uri, (int)sinfo.hInstApp); 376 gaim_debug_error("wgaim", "Error opening URI: %s error: %d\n",
377 uri, (int) sinfo.hInstApp);
381 } 378 }
382 379
383 void wgaim_init(HINSTANCE hint) { 380 void wgaim_init(HINSTANCE hint) {
384 WORD wVersionRequested; 381 WORD wVersionRequested;
385 WSADATA wsaData; 382 WSADATA wsaData;
386 char *perlenv; 383 const char *perlenv;
387 char *newenv; 384 char *newenv;
388 385
389 gaim_debug_set_ui_ops(&ops); 386 gaim_debug_set_ui_ops(&ops);
390 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init start\n"); 387 gaim_debug_info("wgaim", "wgaim_init start\n");
388
389 gaim_debug_info("wgaim", "Glib:%u.%u.%u\n",
390 glib_major_version, glib_minor_version, glib_micro_version);
391 391
392 gaimexe_hInstance = hint; 392 gaimexe_hInstance = hint;
393 393
394 /* Winsock init */ 394 /* Winsock init */
395 wVersionRequested = MAKEWORD( 2, 2 ); 395 wVersionRequested = MAKEWORD(2, 2);
396 WSAStartup( wVersionRequested, &wsaData ); 396 WSAStartup(wVersionRequested, &wsaData);
397 397
398 /* Confirm that the winsock DLL supports 2.2 */ 398 /* Confirm that the winsock DLL supports 2.2 */
399 /* Note that if the DLL supports versions greater than 399 /* Note that if the DLL supports versions greater than
400 2.2 in addition to 2.2, it will still return 2.2 in 400 2.2 in addition to 2.2, it will still return 2.2 in
401 wVersion since that is the version we requested. */ 401 wVersion since that is the version we requested. */
402 if ( LOBYTE( wsaData.wVersion ) != 2 || 402 if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
403 HIBYTE( wsaData.wVersion ) != 2 ) {
404 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Could not find a usable WinSock DLL. Oh well.\n"); 403 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "Could not find a usable WinSock DLL. Oh well.\n");
405 WSACleanup(); 404 WSACleanup();
406 } 405 }
407 406
408 /* Set Environmental Variables */ 407 /* Set Environmental Variables */
409 /* Tell perl where to find Gaim's perl modules */ 408 /* Tell perl where to find Gaim's perl modules */
410 perlenv = (char*) g_getenv("PERL5LIB"); 409 perlenv = g_getenv("PERL5LIB");
411 newenv = g_strdup_printf("PERL5LIB=%s%s%s%s", 410 newenv = g_strdup_printf("PERL5LIB=%s%s%s%s",
412 perlenv ? perlenv : "", 411 perlenv ? perlenv : "",
413 perlenv ? ";" : "", 412 perlenv ? ";" : "",
414 wgaim_install_dir(), 413 wgaim_install_dir(),
415 "\\perlmod;"); 414 "\\perlmod;");
416 if (putenv(newenv) < 0) 415 if (putenv(newenv) < 0)
417 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n"); 416 gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "putenv failed\n");
418 g_free(newenv); 417 g_free(newenv);
419 418
420 /* Set app data dir, used by gaim_home_dir */ 419 /* Set app data dir, used by gaim_home_dir */
421 newenv = (char*) g_getenv("GAIMHOME"); 420 newenv = (char*) g_getenv("GAIMHOME");
422 if (newenv) { 421 if (newenv) {
423 app_data_dir = g_strdup(newenv); 422 app_data_dir = g_strdup(newenv);
424 } else { 423 } else {
425 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA); 424 app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA);
426 if (!app_data_dir) { 425 if (!app_data_dir) {
427 app_data_dir = g_strdup("C:"); 426 app_data_dir = g_strdup("C:");
428 } 427 }
429 } 428 }
430 429
431 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir); 430 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir);
432 431
433 /* IdleTracker Initialization */ 432 /* IdleTracker Initialization */
434 if(!wgaim_set_idlehooks()) 433 if(!wgaim_set_idlehooks())
435 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n"); 434 gaim_debug(GAIM_DEBUG_ERROR, "wgaim", "Failed to initialize idle tracker\n");
436 435
437 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n"); 436 gaim_debug(GAIM_DEBUG_INFO, "wgaim", "wgaim_init end\n");
438 } 437 }
439 438
440 /* Windows Cleanup */ 439 /* Windows Cleanup */