annotate src/win_gaim.c @ 11484:4539174a88bd

[gaim-migrate @ 13726] Fix a warning. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Fri, 09 Sep 2005 20:06:13 +0000
parents d83e1fe99d69
children 4da9e0d4e8d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
2 * win_gaim.c
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Date: June, 2002
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 * Description: Entry point for win32 gaim, and various win32 dependant
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * routines.
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
7 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7802
diff changeset
8 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7802
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7802
diff changeset
10 * source distribution.
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
11 *
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
12 * This program is free software; you can redistribute it and/or modify
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
13 * it under the terms of the GNU General Public License as published by
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
15 * (at your option) any later version.
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
16 *
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
17 * This program is distributed in the hope that it will be useful,
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
20 * GNU General Public License for more details.
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
21 *
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
22 * You should have received a copy of the GNU General Public License
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
23 * along with this program; if not, write to the Free Software
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
25 *
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 */
11060
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
27
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 #include <windows.h>
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
29 #include <fcntl.h>
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 #include <stdlib.h>
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
31 #include <string.h>
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
32 #include <stdio.h>
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33
11193
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
34 #define WIN32_PROXY_REGKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
35
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
36 typedef int (CALLBACK* LPFNGAIMMAIN)(HINSTANCE, int, char**);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
37 typedef void (CALLBACK* LPFNSETDLLDIRECTORY)(LPCTSTR);
11060
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
38 typedef BOOL (CALLBACK* LPFNATTACHCONSOLE)(DWORD);
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
39
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 /*
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 * PROTOTYPES
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 */
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
43 static LPFNGAIMMAIN gaim_main = NULL;
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
44 static LPFNSETDLLDIRECTORY MySetDllDirectory = NULL;
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
45
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
46
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
47 static BOOL read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) {
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
48 HKEY hkey;
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
49 BOOL ret = FALSE;
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
50 LONG retv;
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
51
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
52 if (ERROR_SUCCESS == (retv = RegOpenKeyEx(key, sub_key, 0,
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
53 KEY_QUERY_VALUE, &hkey))) {
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
54 if (ERROR_SUCCESS == (retv = RegQueryValueEx(hkey, val_name,
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
55 NULL, NULL, data, data_len)))
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
56 ret = TRUE;
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
57 else {
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
58 TCHAR szBuf[80];
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
59
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
60 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
61 NULL, retv, 0,
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
62 (LPTSTR) &szBuf, sizeof(szBuf), NULL);
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
63
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
64 printf("Could not read reg key '%s' subkey '%s' value: '%s'\nError: (%ld) %s\n",
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
65 ((key == HKEY_LOCAL_MACHINE) ? "HKLM" :
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
66 (key == HKEY_CURRENT_USER) ? "HKCU" :
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
67 "???"),
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
68 sub_key, val_name, retv, szBuf);
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
69 }
11193
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
70 RegCloseKey(hkey);
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
71 }
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
72 else {
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
73 TCHAR szBuf[80];
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
74
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
75 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, retv, 0,
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
76 (LPTSTR) &szBuf, sizeof(szBuf), NULL);
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
77 printf("Could not open reg subkey: %s\nError: (%ld) %s\n",
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
78 sub_key, retv, szBuf);
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
79 }
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
80
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
81 return ret;
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
82 }
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
83
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
84 static void dll_prep() {
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
85 char gtkpath[MAX_PATH + 1];
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
86 char path[MAX_PATH + 1];
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
87 DWORD plen;
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
88 BOOL gotreg = FALSE;
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
89 HKEY hkey;
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
90 HMODULE hmod;
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
91
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
92 plen = sizeof(gtkpath);
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
93 if(!(gotreg = read_reg_string((hkey=HKEY_LOCAL_MACHINE), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen)))
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
94 gotreg = read_reg_string((hkey=HKEY_CURRENT_USER), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen);
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
95
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
96 if(!gotreg)
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
97 return;
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
98
10688
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
99 /* this value is replaced during a successful RegQueryValueEx() */
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
100 plen = sizeof(path);
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
101 /* Determine GTK+ dll path .. */
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
102 if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "DllPath",
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
103 (LPBYTE) &path, &plen)) {
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
104 strcpy(path, gtkpath);
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
105 strcat(path, "\\bin");
7818a5e9e3a2 [gaim-migrate @ 12237]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10521
diff changeset
106 }
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
107
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
108 printf("GTK+ path found: %s\n", path);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
109
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
110 if((hmod=GetModuleHandle("kernel32.dll"))) {
10898
cfacc0de0d94 [gaim-migrate @ 12614]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10688
diff changeset
111 MySetDllDirectory = (LPFNSETDLLDIRECTORY)GetProcAddress(hmod, "SetDllDirectoryA");
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
112 if(!MySetDllDirectory)
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
113 printf("SetDllDirectory not supported\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
114 }
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
115 else
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
116 printf("Error getting kernel32.dll module handle\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
117
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
118 /* For Windows XP SP1+ / Server 2003 we use SetDllDirectory to avoid dll hell */
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
119 if(MySetDllDirectory) {
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
120 printf("Using SetDllDirectory\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
121 MySetDllDirectory(path);
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
122 }
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
123
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
124 /* For the rest, we set the current directory and make sure SafeDllSearch is set
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
125 to 0 where needed. */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
126 else {
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
127 OSVERSIONINFO osinfo;
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
128
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
129 printf("Setting current directory to GTK+ dll directory\n");
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
130 SetCurrentDirectory(path);
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
131 /* For Windows 2000 (SP3+) / WinXP (No SP):
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
132 * If SafeDllSearchMode is set to 1, Windows system directories are
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
133 * searched for dlls before the current directory. Therefore we set it
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
134 * to 0.
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
135 */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
136 osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
137 GetVersionEx(&osinfo);
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
138 if((osinfo.dwMajorVersion == 5 &&
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
139 osinfo.dwMinorVersion == 0 &&
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
140 strcmp(osinfo.szCSDVersion, "Service Pack 3") >= 0) ||
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
141 (osinfo.dwMajorVersion == 5 &&
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
142 osinfo.dwMinorVersion == 1 &&
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
143 strcmp(osinfo.szCSDVersion, "") >= 0)
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
144 ) {
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
145 DWORD regval = 1;
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
146 DWORD reglen = sizeof(DWORD);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
147
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
148 printf("Using Win2k (SP3+) / WinXP (No SP).. Checking SafeDllSearch\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
149 read_reg_string(HKEY_LOCAL_MACHINE,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
150 "System\\CurrentControlSet\\Control\\Session Manager",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
151 "SafeDllSearchMode",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
152 (LPBYTE)&regval,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
153 &reglen);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
154
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
155 if(regval != 0) {
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
156 printf("Trying to set SafeDllSearchMode to 0\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
157 regval = 0;
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
158 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
159 "System\\CurrentControlSet\\Control\\Session Manager",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
160 0, KEY_SET_VALUE, &hkey) == ERROR_SUCCESS) {
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
161 if(RegSetValueEx(hkey,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
162 "SafeDllSearchMode",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
163 0,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
164 REG_DWORD,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
165 (LPBYTE) &regval,
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
166 sizeof(DWORD)) != ERROR_SUCCESS)
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
167 printf("Error writing SafeDllSearchMode. Error: %u\n",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
168 (UINT)GetLastError());
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
169 RegCloseKey(hkey);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
170 }
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
171 else
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
172 printf("Error opening Session Manager key for writing. Error: %u\n",
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
173 (UINT)GetLastError());
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
174 }
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
175 else
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
176 printf("SafeDllSearchMode is set to 0\n");
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
177 }/*end else*/
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
178 }
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
179 }
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
181 static char* wgaim_lcid_to_posix(LCID lcid) {
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
182 switch(lcid) {
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
183 case 1026: return "bg"; /* bulgarian */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
184 case 2125: return "my_MM"; /* burmese (Myanmar) */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
185 case 1027: return "ca"; /* catalan */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
186 case 1050: return "hr"; /* croatian */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
187 case 1029: return "cs"; /* czech */
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
188 case 1030: return "da"; /* danish */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
189 case 1043: return "nl"; /* dutch - netherlands */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
190 case 1033: return "en"; /* english - us */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
191 case 3081: return "en_AU"; /* english - australia */
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
192 case 4105: return "en_CA"; /* english - canada */
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
193 case 2057: return "en_GB"; /* english - great britain */
8735
92cbf9713795 [gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents: 8046
diff changeset
194 case 1035: return "fi"; /* finnish */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
195 case 1036: return "fr"; /* french - france */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
196 case 1031: return "de"; /* german - germany */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
197 case 1032: return "el"; /* greek */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
198 case 1037: return "he"; /* hebrew */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
199 case 1081: return "hi"; /* hindi */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
200 case 1038: return "hu"; /* hungarian */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
201 case 1040: return "it"; /* italian - italy */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
202 case 1041: return "ja"; /* japanese */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
203 case 1042: return "ko"; /* korean */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
204 case 1063: return "lt"; /* lithuanian */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
205 case 1071: return "mk"; /* macedonian */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
206 case 1044: return "no"; /* norwegian */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
207 case 1045: return "pl"; /* polish */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
208 case 2070: return "pt"; /* portuguese - portugal */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
209 case 1046: return "pt_BR"; /* portuguese - brazil */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
210 case 1048: return "ro"; /* romanian - romania */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
211 case 1049: return "ru"; /* russian - russia */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
212 case 2074: return "sr@Latn"; /* serbian - latin */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
213 case 3098: return "sr"; /* serbian - cyrillic */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
214 case 2052: return "zh_CN"; /* chinese - china (simple) */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
215 case 1051: return "sk"; /* slovak */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
216 case 1060: return "sl"; /* slovenian */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
217 case 1034: return "es"; /* spanish */
10095
b28f9be379b3 [gaim-migrate @ 11114]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 8735
diff changeset
218 case 1052: return "sq"; /* albanian */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
219 case 1053: return "sv"; /* swedish */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
220 case 1054: return "th"; /* thai */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
221 case 1028: return "zh_TW"; /* chinese - taiwan (traditional) */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
222 case 1055: return "tr"; /* turkish */
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
223 case 1058: return "uk"; /* ukrainian */
10521
db44efdf6565 [gaim-migrate @ 11836]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10330
diff changeset
224 case 1066: return "vi"; /* vietnamese */
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
225 default:
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
226 return NULL;
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
227 }
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
228 }
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
229
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
230 /* Determine and set Gaim locale as follows (in order of priority):
10210
4d3c2749deec [gaim-migrate @ 11332]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10095
diff changeset
231 - Check GAIMLANG env var
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
232 - Check NSIS Installer Language reg value
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
233 - Use default user locale
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
234 */
10330
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
235 static const char* wgaim_get_locale() {
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
236 const char* locale=NULL;
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
237 char data[10];
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
238 DWORD datalen = 10;
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
239 LCID lcid;
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
240
10210
4d3c2749deec [gaim-migrate @ 11332]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10095
diff changeset
241 /* Check if user set GAIMLANG env var */
10330
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
242 if((locale = getenv("GAIMLANG")))
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
243 return locale;
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
244
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
245 if(read_reg_string(HKEY_CURRENT_USER, "SOFTWARE\\gaim", "Installer Language", (LPBYTE)&data, &datalen)) {
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
246 if((locale = wgaim_lcid_to_posix(atoi(data))))
10330
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
247 return locale;
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
248 }
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
249
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
250 lcid = GetUserDefaultLCID();
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
251 if((locale = wgaim_lcid_to_posix(lcid)))
10330
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
252 return locale;
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
253
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
254 return "en";
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
255 }
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
256
10330
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
257 static void wgaim_set_locale() {
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
258 const char* locale=NULL;
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
259 char envstr[25];
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
260
4f5a7ddd3161 [gaim-migrate @ 11537]
Mark Doliner <mark@kingant.net>
parents: 10227
diff changeset
261 locale = wgaim_get_locale();
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
262
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
263 snprintf(envstr, 25, "LANG=%s", locale);
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
264 printf("Setting locale: %s\n", envstr);
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
265 putenv(envstr);
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
266 }
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
267
10212
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
268 static BOOL wgaim_set_running() {
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
269 HANDLE h;
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
270
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
271 if((h=CreateMutex(NULL, FALSE, "gaim_is_running"))) {
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
272 if(GetLastError() == ERROR_ALREADY_EXISTS) {
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
273 MessageBox(NULL, "An instance of Gaim is already running", NULL, MB_OK | MB_TOPMOST);
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
274 return FALSE;
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
275 }
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
276 }
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
277 return TRUE;
08251403c871 [gaim-migrate @ 11336]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10210
diff changeset
278 }
7350
e28728795a45 [gaim-migrate @ 7941]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6890
diff changeset
279
11193
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
280 static void wgaim_set_proxy() {
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
281 DWORD regval = 1;
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
282 DWORD reglen = sizeof(DWORD);
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
283
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
284 /* If the proxy server environment variables are already set,
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
285 * we shouldn't override them */
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
286 if (getenv("HTTP_PROXY") || getenv("http_proxy") || getenv("HTTPPROXY"))
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
287 return;
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
288
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
289 if (read_reg_string(HKEY_CURRENT_USER, WIN32_PROXY_REGKEY, "ProxyEnable",
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
290 (LPBYTE) &regval, &reglen) && (regval & 1)) {
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
291 char proxy_server[2048];
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
292 char *c = NULL;
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
293 reglen = sizeof(proxy_server);
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
294
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
295 if (!read_reg_string(HKEY_CURRENT_USER, WIN32_PROXY_REGKEY , "ProxyServer",
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
296 (LPBYTE) &proxy_server, &reglen))
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
297 return;
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
298
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
299 if ((reglen > strlen("http=")) && (c = strstr(proxy_server, "http="))) {
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
300 char *d;
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
301 c += strlen("http=");
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
302 d = strchr(c, ';');
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
303 if (d) {
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
304 *d = '\0';
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
305 }
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
306 /* c now points the proxy server (and port) */
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
307 }
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
308
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
309 if (c) {
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
310 const char envstr_prefix[] = "HTTP_PROXY=http://";
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
311 char envstr[sizeof(envstr_prefix) + strlen(c) + 1];
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
312 snprintf(envstr, sizeof(envstr), "%s%s", envstr_prefix, c);
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
313 printf("Setting HTTP Proxy: %s\n", envstr);
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
314 putenv(envstr);
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
315 }
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
316 }
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
317
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
318 }
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
319
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
320 #ifdef __GNUC__
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
321 # ifndef _stdcall
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
322 # define _stdcall __attribute__((stdcall))
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
323 # endif
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 #endif
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
325
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
326 int _stdcall
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
327 WinMain (struct HINSTANCE__ *hInstance,
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
328 struct HINSTANCE__ *hPrevInstance,
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
329 char *lpszCmdLine,
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
330 int nCmdShow)
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
331 {
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
332 char errbuf[512];
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
333 char gaimdir[MAX_PATH];
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
334 HMODULE hmod;
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
335
11469
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
336 /* If debug or help or version flag used, create console for output */
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
337 if (strstr(lpszCmdLine, "-d") || strstr(lpszCmdLine, "-h") || strstr(lpszCmdLine, "-v")) {
11060
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
338 LPFNATTACHCONSOLE MyAttachConsole = NULL;
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
339 if ((hmod = GetModuleHandle("kernel32.dll"))) {
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
340 MyAttachConsole =
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
341 (LPFNATTACHCONSOLE)
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
342 GetProcAddress(hmod, "AttachConsole");
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
343 }
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
344 if ((MyAttachConsole && MyAttachConsole(ATTACH_PARENT_PROCESS))
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
345 || AllocConsole())
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
346 freopen("CONOUT$", "w", stdout);
52d6b10025ca [gaim-migrate @ 13014]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10898
diff changeset
347 }
7802
f1d2907db5be [gaim-migrate @ 8448]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7522
diff changeset
348
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
349 /* Load exception handler if we have it */
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
350 if(GetModuleFileName(NULL, gaimdir, MAX_PATH) != 0) {
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
351 char *tmp = gaimdir;
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
352 char *prev = NULL;
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
353
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
354 while((tmp=strchr(tmp, '\\'))) {
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
355 prev = tmp;
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
356 tmp+=1;
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
357 }
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
358 if(prev) {
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
359 prev[0] = '\0';
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
360 strcat(gaimdir, "\\exchndl.dll");
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
361 if(LoadLibrary(gaimdir))
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
362 printf("Loaded exchndl.dll\n");
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
363 }
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
364 }
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
365 else {
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
366 snprintf(errbuf, 512, "Error getting module filename. Error: %u", (UINT)GetLastError());
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
367 MessageBox(NULL, errbuf, NULL, MB_OK | MB_TOPMOST);
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
368 }
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
369
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
370 if(!getenv("GAIM_NO_DLL_CHECK"))
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
371 dll_prep();
6816
5aeba37b303c [gaim-migrate @ 7356]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 4490
diff changeset
372
11193
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
373 wgaim_set_locale();
11469
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
374 /* If help or version flag used, do not check Mutex */
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
375 if(!strstr(lpszCmdLine, "-h") && !strstr(lpszCmdLine, "-v"))
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
376 if(!getenv("GAIM_MULTI_INST") && !wgaim_set_running())
d83e1fe99d69 [gaim-migrate @ 13709]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11441
diff changeset
377 return 0;
11193
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
378
e865bdbbf91d [gaim-migrate @ 13316]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11060
diff changeset
379 wgaim_set_proxy();
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
380
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
381 /* Now we are ready for Gaim .. */
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
382 if((hmod=LoadLibrary("gaim.dll"))) {
7522
07156f873116 [gaim-migrate @ 8135]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7477
diff changeset
383 gaim_main = (LPFNGAIMMAIN)GetProcAddress(hmod, "gaim_main");
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
384 }
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
385
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
386 if(!gaim_main) {
7477
29d69daa1ede [gaim-migrate @ 8090]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7363
diff changeset
387 snprintf(errbuf, 512, "Error loading gaim.dll. Error: %u", (UINT)GetLastError());
7356
be11a6f2fe00 [gaim-migrate @ 7949]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7350
diff changeset
388 MessageBox(NULL, errbuf, NULL, MB_OK | MB_TOPMOST);
6890
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
389 return 0;
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
390 }
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
391 else
4eee806af511 [gaim-migrate @ 7436]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 6816
diff changeset
392 return gaim_main (hInstance, __argc, __argv);
4490
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
393 }
70b892694e0b [gaim-migrate @ 4765]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
394