Mercurial > pidgin.yaz
comparison src/win32/wspell.c @ 10878:da36acb8442c
[gaim-migrate @ 12571]
Don't blow up when $PATH is not defined. Deal with the situation where aspell is installed in a non-ascii path.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 27 Apr 2005 01:21:01 +0000 |
parents | 26b739bc9f1a |
children | 50224ac8184d |
comparison
equal
deleted
inserted
replaced
10877:99c1fb67b7bb | 10878:da36acb8442c |
---|---|
63 wgaim_gtkspell_detach = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_detach"); | 63 wgaim_gtkspell_detach = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_detach"); |
64 wgaim_gtkspell_set_language = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_set_language"); | 64 wgaim_gtkspell_set_language = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_set_language"); |
65 wgaim_gtkspell_recheck_all = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_recheck_all"); | 65 wgaim_gtkspell_recheck_all = (void*)wgaim_find_and_loadproc("libgtkspell.dll", "gtkspell_recheck_all"); |
66 } | 66 } |
67 | 67 |
68 static char* lookup_aspell_path() { | |
69 char *path = NULL; | |
70 HKEY reg_key; | |
71 DWORD type; | |
72 DWORD nbytes; | |
73 gboolean found_reg_key; | |
74 LPCTSTR subkey = NULL; | |
75 if (G_WIN32_HAVE_WIDECHAR_API ()) { | |
76 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Aspell", 0, | |
77 KEY_QUERY_VALUE, | |
78 ®_key) == ERROR_SUCCESS) { | |
79 subkey = (LPCTSTR) L"Path"; | |
80 if (!(found_reg_key = RegQueryValueExW(reg_key, | |
81 (WCHAR*) subkey, NULL, | |
82 &type, NULL, &nbytes | |
83 ) == ERROR_SUCCESS)) { | |
84 subkey = NULL; | |
85 found_reg_key = (RegQueryValueExW(reg_key, | |
86 (WCHAR*) subkey, NULL, | |
87 &type, NULL, &nbytes | |
88 ) == ERROR_SUCCESS); | |
89 } | |
90 if (found_reg_key) { | |
91 wchar_t *wc_temp = g_new (wchar_t, (nbytes + 1) / 2 + 1); | |
92 RegQueryValueExW(reg_key, (WCHAR*) subkey, | |
93 NULL, &type, (LPBYTE) wc_temp, | |
94 &nbytes); | |
95 wc_temp[nbytes / 2] = '\0'; | |
96 path = g_utf16_to_utf8( | |
97 wc_temp, -1, NULL, NULL, NULL); | |
98 g_free (wc_temp); | |
99 } | |
100 } | |
101 } else { | |
102 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Aspell", 0, | |
103 KEY_QUERY_VALUE, ®_key | |
104 ) == ERROR_SUCCESS) { | |
105 subkey = "Path"; | |
106 if (!(found_reg_key = RegQueryValueExA(reg_key, subkey, | |
107 NULL, &type, NULL, | |
108 &nbytes | |
109 ) == ERROR_SUCCESS)) { | |
110 subkey = NULL; | |
111 found_reg_key = (RegQueryValueExA(reg_key, | |
112 subkey, NULL, &type, | |
113 NULL, &nbytes | |
114 ) == ERROR_SUCCESS); | |
115 } | |
116 if (found_reg_key) { | |
117 char *cp_temp = g_malloc (nbytes + 1); | |
118 RegQueryValueExA(reg_key, subkey, NULL, &type, | |
119 cp_temp, &nbytes); | |
120 cp_temp[nbytes] = '\0'; | |
121 path = g_locale_to_utf8( | |
122 cp_temp, -1, NULL, NULL, NULL); | |
123 g_free (cp_temp); | |
124 } | |
125 } | |
126 } | |
127 | |
128 if (reg_key != NULL) { | |
129 RegCloseKey(reg_key); | |
130 } | |
131 | |
132 return path; | |
133 } | |
134 | |
68 void wgaim_gtkspell_init() { | 135 void wgaim_gtkspell_init() { |
69 HKEY hKey; | 136 char *aspell_path = lookup_aspell_path(); |
70 char buffer[1024] = ""; | |
71 DWORD size = sizeof(buffer); | |
72 DWORD type; | |
73 | 137 |
74 if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, | 138 if (aspell_path != NULL) { |
75 "Software\\Aspell", | 139 char *tmp = g_strconcat(aspell_path, "\\aspell-15.dll", NULL); |
76 0, | 140 if (g_file_test(tmp, G_FILE_TEST_EXISTS)) { |
77 KEY_QUERY_VALUE, | 141 const char *path = g_getenv("PATH"); |
78 &hKey)) { | 142 gaim_debug_info("wspell", "Found Aspell in %s\n", aspell_path); |
79 /* Official aspell.net win32 installation or Gaim's aspell installation */ | 143 |
80 if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Path", NULL, &type, (LPBYTE)buffer, &size) || | 144 g_free(tmp); |
81 ERROR_SUCCESS == RegQueryValueEx(hKey, "", NULL, &type, (LPBYTE)buffer, &size)) { | 145 |
82 int mark = strlen(buffer); | 146 tmp = g_strdup_printf("%s%s%s", (path ? path : ""), |
83 strcat(buffer, "\\aspell-15.dll"); | 147 (path ? G_SEARCHPATH_SEPARATOR_S : ""), |
84 if(_access( buffer, 0 ) < 0) | 148 aspell_path); |
85 gaim_debug(GAIM_DEBUG_WARNING, "wspell", "Couldn't find aspell-15.dll\n"); | 149 |
86 else { | 150 g_setenv("PATH", tmp, TRUE); |
87 char* tmp=NULL; | 151 |
88 buffer[mark] = '\0'; | 152 load_gtkspell(); |
89 gaim_debug(GAIM_DEBUG_INFO, "wspell", "Found Aspell in %s\n", buffer); | 153 } else { |
90 /* Add path to Aspell dlls to PATH */ | 154 gaim_debug_warning("wspell", "Couldn't find aspell-15.dll\n"); |
91 tmp = g_malloc0(strlen(getenv("PATH")) + strlen(buffer) + 7); | 155 } |
92 sprintf(tmp, "PATH=%s;%s", getenv("PATH"), buffer); | 156 |
93 putenv(tmp); | 157 g_free(tmp); |
94 g_free(tmp); | 158 g_free(aspell_path); |
95 load_gtkspell(); | 159 } else { |
96 } | 160 gaim_debug_warning("wspell", "Couldn't find path for Aspell\n"); |
97 } | 161 } |
98 else { | |
99 gaim_debug(GAIM_DEBUG_WARNING, "wspell", "Couldn't find path for Aspell\n"); | |
100 } | |
101 RegCloseKey(hKey); | |
102 } | |
103 } | 162 } |