| 6 * Description: Entry point for win32 gaim, and various win32 dependant |
6 * Description: Entry point for win32 gaim, and various win32 dependant |
| 7 * routines. |
7 * routines. |
| 8 */ |
8 */ |
| 9 #include <windows.h> |
9 #include <windows.h> |
| 10 #include <stdlib.h> |
10 #include <stdlib.h> |
| 11 #include <glib.h> |
11 #include <string.h> |
| |
12 #include <stdio.h> |
| 12 |
13 |
| 13 /* |
14 /* |
| 14 * GLOBALS |
15 * GLOBALS |
| 15 */ |
16 */ |
| 16 __declspec(dllimport) HINSTANCE gaimexe_hInstance; |
17 __declspec(dllimport) HINSTANCE gaimexe_hInstance; |
| 17 |
18 |
| 18 /* |
19 /* |
| 19 * LOCALS |
20 * LOCALS |
| 20 */ |
21 */ |
| |
22 static char msg1[] = "The following duplicate of "; |
| |
23 static char msg2[] = " has been found in your dll search path and will likely\x0d\x0a" |
| |
24 "cause Gaim to malfunction:\x0d\x0a\x0d\x0a"; |
| |
25 |
| |
26 static char msg3[] = "\x0d\x0a\x0d\x0aWould you like to rename this dll to "; |
| |
27 static char msg4[] = ".prob in order to avoid any possible conflicts?\x0d\x0a" |
| |
28 "\x0d\x0a" |
| |
29 "Note: Doing so will likely cause the application that installed this dll to stop functioning.\x0d\x0a" |
| |
30 "You may wish to inform the author of the responsible application so that future versions\x0d\x0a" |
| |
31 "do not cause 'Dll Hell'."; |
| 21 |
32 |
| 22 /* |
33 /* |
| 23 * PROTOTYPES |
34 * PROTOTYPES |
| 24 */ |
35 */ |
| 25 extern int gaim_main( int, char** ); |
36 int (*gaim_main)( HINSTANCE, int, char** ) = NULL; |
| 26 extern char* wgaim_install_dir(); |
37 |
| |
38 static void check_dll(char* dll, char* orig) { |
| |
39 char tmp[MAX_PATH]; |
| |
40 char *last; |
| |
41 |
| |
42 if(SearchPath(NULL, dll, NULL, MAX_PATH, tmp, &last)) { |
| |
43 char* patha = (char*)malloc(strlen(orig) + strlen(dll) + 4); |
| |
44 strcpy(patha, orig); |
| |
45 strcat(patha, "\\"); |
| |
46 strcat(patha, dll); |
| |
47 /* Make sure that 2 paths are not the same */ |
| |
48 if(strcasecmp(patha, tmp) != 0) { |
| |
49 char *warning = (char*)malloc(strlen(msg1)+ |
| |
50 strlen(msg2)+ |
| |
51 strlen(msg3)+ |
| |
52 strlen(msg4)+ |
| |
53 strlen(tmp)+ |
| |
54 (strlen(dll)*2)+4); |
| |
55 sprintf(warning, "%s%s%s%s%s%s%s", msg1, dll, msg2, tmp, msg3, dll, msg4); |
| |
56 if(MessageBox(NULL, warning, "Gaim Warning", MB_YESNO | MB_TOPMOST)==IDYES) { |
| |
57 char *newname = (char*)malloc(strlen(tmp)+6); |
| |
58 /* Rename offending dll */ |
| |
59 sprintf(newname, "%s%s", tmp, ".prob"); |
| |
60 if(rename(tmp, newname) != 0) { |
| |
61 MessageBox(NULL, "Error renaming file.", NULL, MB_OK | MB_TOPMOST); |
| |
62 } |
| |
63 else |
| |
64 check_dll(dll, orig); |
| |
65 free(newname); |
| |
66 } |
| |
67 free(warning); |
| |
68 } |
| |
69 free(patha); |
| |
70 } |
| |
71 } |
| |
72 |
| |
73 static void dll_hell_check(char* gtkpath) { |
| |
74 HANDLE myHandle; |
| |
75 WIN32_FIND_DATA fd; |
| |
76 char* srchstr = (char*)malloc(strlen(gtkpath) + 8); |
| |
77 |
| |
78 sprintf(srchstr, "%s%s", gtkpath, "\\*.dll"); |
| |
79 myHandle = FindFirstFile(srchstr, &fd ); |
| |
80 if(myHandle != INVALID_HANDLE_VALUE) { |
| |
81 check_dll(fd.cFileName, gtkpath); |
| |
82 while(FindNextFile(myHandle, &fd)) { |
| |
83 check_dll(fd.cFileName, gtkpath); |
| |
84 } |
| |
85 } |
| |
86 free(srchstr); |
| |
87 } |
| |
88 |
| |
89 BOOL read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { |
| |
90 HKEY hkey; |
| |
91 BOOL ret = FALSE; |
| |
92 int retv; |
| |
93 |
| |
94 if(ERROR_SUCCESS == RegOpenKeyEx(key, |
| |
95 sub_key, |
| |
96 0, KEY_QUERY_VALUE, &hkey)) { |
| |
97 if(ERROR_SUCCESS == (retv=RegQueryValueEx(hkey, val_name, 0, NULL, data, data_len))) |
| |
98 ret = TRUE; |
| |
99 else { |
| |
100 printf("Error reading registry string value: %d\n", retv); |
| |
101 } |
| |
102 RegCloseKey(key); |
| |
103 } |
| |
104 return ret; |
| |
105 } |
| |
106 |
| |
107 void run_dll_check() { |
| |
108 char path[MAX_PATH]; |
| |
109 DWORD plen = MAX_PATH; |
| |
110 int gotreg=FALSE; |
| |
111 |
| |
112 /* Dll Hell Check.. Only run check if we are the same gaim as found in the |
| |
113 gaim registry key */ |
| |
114 if(!(gotreg = read_reg_string(HKEY_LOCAL_MACHINE, "SOFTWARE\\gaim", "", (LPBYTE)&path, &plen))) |
| |
115 gotreg = read_reg_string(HKEY_CURRENT_USER, "SOFTWARE\\gaim", "", (LPBYTE)&path, &plen); |
| |
116 |
| |
117 if(gotreg) { |
| |
118 char modpath[MAX_PATH]; |
| |
119 |
| |
120 strcat(path, "\\gaim.exe"); |
| |
121 GetModuleFileName(NULL, modpath, MAX_PATH); |
| |
122 if(strcasecmp(path, modpath) == 0) { |
| |
123 plen = MAX_PATH; |
| |
124 if(!(gotreg = read_reg_string(HKEY_LOCAL_MACHINE, "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&path, &plen))) |
| |
125 gotreg = read_reg_string(HKEY_CURRENT_USER, "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&path, &plen); |
| |
126 if(gotreg) { |
| |
127 strcat(path, "\\bin"); |
| |
128 dll_hell_check(path); |
| |
129 } |
| |
130 } |
| |
131 } |
| |
132 } |
| 27 |
133 |
| 28 #ifdef __GNUC__ |
134 #ifdef __GNUC__ |
| 29 # ifndef _stdcall |
135 # ifndef _stdcall |
| 30 # define _stdcall __attribute__((stdcall)) |
136 # define _stdcall __attribute__((stdcall)) |
| 31 # endif |
137 # endif |
| 35 WinMain (struct HINSTANCE__ *hInstance, |
141 WinMain (struct HINSTANCE__ *hInstance, |
| 36 struct HINSTANCE__ *hPrevInstance, |
142 struct HINSTANCE__ *hPrevInstance, |
| 37 char *lpszCmdLine, |
143 char *lpszCmdLine, |
| 38 int nCmdShow) |
144 int nCmdShow) |
| 39 { |
145 { |
| 40 char* drmingw; |
146 char gaimdir[MAX_PATH]; |
| 41 gaimexe_hInstance = hInstance; |
147 char *point; |
| |
148 HMODULE hmod; |
| 42 |
149 |
| 43 /* Load exception handler if we have it */ |
150 /* If GAIM_NO_DLL_CHECK is set, don't run the dll check */ |
| 44 drmingw = g_build_filename(wgaim_install_dir(), "exchndl.dll", NULL); |
151 if(!getenv("GAIM_NO_DLL_CHECK")) |
| 45 LoadLibrary(drmingw); |
152 run_dll_check(); |
| 46 g_free(drmingw); |
|
| 47 |
153 |
| 48 return gaim_main (__argc, __argv); |
154 /* Load exception handler if we have it */ |
| |
155 GetModuleFileName(NULL, gaimdir, MAX_PATH); |
| |
156 if((point=strstr(gaimdir, "gaim.exe"))) { |
| |
157 point[0] = '\0'; |
| |
158 strcat(gaimdir, "exchndl.dll"); |
| |
159 LoadLibrary(gaimdir); |
| |
160 } |
| |
161 |
| |
162 /* Now we are ready for Gaim .. */ |
| |
163 if((hmod=LoadLibrary("gaim.dll"))) { |
| |
164 gaim_main = (void*)GetProcAddress(hmod, "gaim_main"); |
| |
165 } |
| |
166 |
| |
167 if(!gaim_main) { |
| |
168 MessageBox(NULL, "Error loading gaim.dll entry point.", NULL, MB_OK | MB_TOPMOST); |
| |
169 return 0; |
| |
170 } |
| |
171 else |
| |
172 return gaim_main (hInstance, __argc, __argv); |
| 49 } |
173 } |
| 50 |
174 |