3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Fridrich Strba <fridrich.strba@bluewin.ch>
19 * Copyright (C) 2010 Fridrich Strba
29 #include "e-win32-defaults.h"
30 #include "e-util-private.h"
32 #define MAX_VALUE_NAME 4096
33 #define EVOBINARY "evolution.exe"
34 #define EUTILDLL "libeutil-0.dll"
35 #define CANONICALNAME "Evolution"
38 _e_win32_sanitize_path (gchar
*path
)
42 if (G_IS_DIR_SEPARATOR (*p
))
44 p
= g_utf8_find_next_char (p
, NULL
);
50 * Addressbook Client registration
54 _e_register_vcard_structure (HKEY hKey
)
59 gchar
*defaultIcon
= NULL
;
60 gchar
*evolutionBinary
= NULL
;
61 gchar
*vcardCommand
= NULL
;
62 BYTE editFlags
[4] = { 0x02, 0x00, 0x00, 0x00 };
64 static HKEY tmp_subkey
= (HKEY
) INVALID_HANDLE_VALUE
;
66 if ((returnValue
= RegCreateKeyExA (hKey
, ".vcf", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
69 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"vcard_evo_auto_file", strlen ("vcard_evo_auto_file") + 1)))
71 if ((returnValue
= RegSetValueExA (tmp_subkey
, "Content Type", 0, REG_SZ
, (const BYTE
*)"text/x-vcard", strlen ("text/x-vcard") + 1)))
74 RegFlushKey (tmp_subkey
);
76 RegCloseKey (tmp_subkey
);
78 if ((returnValue
= RegCreateKeyExA (hKey
, "MIME\\Database\\Content Type\\text/x-vcard", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
81 if ((returnValue
= RegSetValueExA (tmp_subkey
, "Extension", 0, REG_SZ
, (const BYTE
*)".vcf", strlen (".vcf") + 1)))
84 RegFlushKey (tmp_subkey
);
86 RegCloseKey (tmp_subkey
);
88 if ((returnValue
= RegCreateKeyExA (hKey
, "vcard_evo_auto_file", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
91 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"vCard File", strlen ("vCard File") + 1)))
93 if ((returnValue
= RegSetValueExA (tmp_subkey
, "EditFlags", 0, REG_BINARY
, editFlags
, G_N_ELEMENTS (editFlags
))))
96 RegFlushKey (tmp_subkey
);
98 RegCloseKey (tmp_subkey
);
100 if ((returnValue
= RegCreateKeyExA (hKey
, "vcard_evo_auto_file\\DefaultIcon", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
103 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
104 defaultIcon
= g_strconcat (evolutionBinary
, ",0", NULL
);
106 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defaultIcon
, strlen (defaultIcon
) + 1)))
110 RegFlushKey (tmp_subkey
);
112 RegCloseKey (tmp_subkey
);
114 if ((returnValue
= RegCreateKeyExA (hKey
, "vcard_evo_auto_file\\shell\\open\\command", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
117 vcardCommand
= g_strconcat("\"", evolutionBinary
, "\" --component=addressbook \%1", NULL
);
119 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)vcardCommand
, strlen (vcardCommand
) + 1)))
122 RegFlushKey (tmp_subkey
);
124 RegCloseKey (tmp_subkey
);
127 g_free (defaultIcon
);
128 g_free (evolutionBinary
);
129 g_free (vcardCommand
);
133 _e_register_ldif_structure (HKEY hKey
)
138 gchar
*defaultIcon
= NULL
;
139 gchar
*evolutionBinary
= NULL
;
140 gchar
*vcardCommand
= NULL
;
141 BYTE editFlags
[4] = { 0x02, 0x00, 0x00, 0x00 };
143 static HKEY tmp_subkey
= (HKEY
) INVALID_HANDLE_VALUE
;
145 if ((returnValue
= RegCreateKeyExA (hKey
, ".ldi", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
148 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"ldif_evo_auto_file", strlen ("ldif_evo_auto_file") + 1)))
150 if ((returnValue
= RegSetValueExA (tmp_subkey
, "Content Type", 0, REG_SZ
, (const BYTE
*)"text/x-ldif", strlen ("text/x-ldif") + 1)))
153 RegFlushKey (tmp_subkey
);
155 RegCloseKey (tmp_subkey
);
157 if ((returnValue
= RegCreateKeyExA (hKey
, ".ldif", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
160 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"ldif_evo_auto_file", strlen ("ldif_evo_auto_file") + 1)))
162 if ((returnValue
= RegSetValueExA (tmp_subkey
, "Content Type", 0, REG_SZ
, (const BYTE
*)"text/x-ldif", strlen ("text/x-ldif") + 1)))
165 RegFlushKey (tmp_subkey
);
167 RegCloseKey (tmp_subkey
);
169 if ((returnValue
= RegCreateKeyExA (hKey
, "MIME\\Database\\Content Type\\text/x-ldif", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
172 if ((returnValue
= RegSetValueExA (tmp_subkey
, "Extension", 0, REG_SZ
, (const BYTE
*)".ldi", strlen (".ldi") + 1)))
175 RegFlushKey (tmp_subkey
);
177 RegCloseKey (tmp_subkey
);
179 if ((returnValue
= RegCreateKeyExA (hKey
, "ldif_evo_auto_file", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
182 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)"LDIF File", strlen ("LDIF File") + 1)))
184 if ((returnValue
= RegSetValueExA (tmp_subkey
, "EditFlags", 0, REG_BINARY
, editFlags
, G_N_ELEMENTS (editFlags
))))
187 RegFlushKey (tmp_subkey
);
189 RegCloseKey (tmp_subkey
);
191 if ((returnValue
= RegCreateKeyExA (hKey
, "ldif_evo_auto_file\\DefaultIcon", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
194 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
195 defaultIcon
= g_strconcat (evolutionBinary
, ",0", NULL
);
197 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defaultIcon
, strlen (defaultIcon
) + 1)))
201 RegFlushKey (tmp_subkey
);
203 RegCloseKey (tmp_subkey
);
205 if ((returnValue
= RegCreateKeyExA (hKey
, "ldif_evo_auto_file\\shell\\open\\command", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
208 vcardCommand
= g_strconcat("\"", evolutionBinary
, "\" --component=addressbook \%1", NULL
);
210 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)vcardCommand
, strlen (vcardCommand
) + 1)))
213 RegFlushKey (tmp_subkey
);
215 RegCloseKey (tmp_subkey
);
218 g_free (defaultIcon
);
219 g_free (evolutionBinary
);
220 g_free (vcardCommand
);
224 _e_win32_register_addressbook_impl (gboolean system
)
228 gchar
*evolutionBinary
= NULL
;
229 gchar
*openCommand
= NULL
;
231 static HKEY reg_key
= (HKEY
) INVALID_HANDLE_VALUE
;
232 static HKEY reg_subkey
= (HKEY
) INVALID_HANDLE_VALUE
;
235 if ((returnValue
= RegCreateKeyExA (system
? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
236 "Software\\Clients\\Contacts\\" CANONICALNAME
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_key
, &dwDisposition
)))
239 if ((returnValue
= RegSetValueExA (reg_key
, NULL
, 0, REG_SZ
, (const BYTE
*)CANONICALNAME
, strlen (CANONICALNAME
) + 1)))
242 RegFlushKey (reg_key
);
244 if ((returnValue
= RegCreateKeyExA (reg_key
, "shell\\open\\command", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
247 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
248 openCommand
= g_strconcat("\"", evolutionBinary
, "\" --component=addressbook", NULL
);
249 if ((returnValue
= RegSetValueExA (reg_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)openCommand
, strlen (openCommand
) + 1)))
252 RegFlushKey (reg_subkey
);
254 RegCloseKey (reg_subkey
);
257 if ((returnValue
= RegCreateKeyExA (reg_key
, "Protocols", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
260 _e_register_vcard_structure (reg_subkey
);
261 _e_register_ldif_structure (reg_subkey
);
263 RegCloseKey (reg_subkey
);
265 RegCloseKey (reg_key
);
267 if ((returnValue
= RegCreateKeyExA (system
? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
268 "Software\\Classes", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_key
, &dwDisposition
)))
271 _e_register_ldif_structure (reg_key
);
273 RegFlushKey (reg_key
);
275 RegCloseKey (reg_key
);
278 g_free (evolutionBinary
);
279 g_free (openCommand
);
283 _e_win32_register_addressbook (void)
285 _e_win32_register_addressbook_impl (TRUE
);
286 _e_win32_register_addressbook_impl (FALSE
);
290 _e_win32_unregister_addressbook (void)
295 * Mail Client registration
299 _e_register_mailto_structure (HKEY hKey
)
303 gchar
*defaultIcon
= NULL
;
304 gchar
*evolutionBinary
= NULL
;
305 gchar
*mailtoCommand
= NULL
;
306 BYTE editFlags
[4] = { 0x02, 0x00, 0x00, 0x00 };
308 static HKEY tmp_subkey
= (HKEY
) INVALID_HANDLE_VALUE
;
310 if ((returnValue
= RegSetValueExA (hKey
, NULL
, 0, REG_SZ
, (const BYTE
*)"URL:MailTo Protocol", strlen ("URL:MailTo Protocol") + 1)))
312 if ((returnValue
= RegSetValueExA (hKey
, "EditFlags", 0, REG_BINARY
, editFlags
, G_N_ELEMENTS (editFlags
))))
314 if ((returnValue
= RegSetValueExA (hKey
, "URL Protocol", 0, REG_SZ
, (const BYTE
*)"", strlen ("") + 1)))
319 if ((returnValue
= RegCreateKeyExA (hKey
, "DefaultIcon", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
322 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
323 defaultIcon
= g_strconcat (evolutionBinary
, ",1", NULL
);
325 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defaultIcon
, strlen (defaultIcon
) + 1)))
329 RegFlushKey (tmp_subkey
);
331 RegCloseKey (tmp_subkey
);
333 if ((returnValue
= RegCreateKeyExA (hKey
, "shell\\open\\command", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &tmp_subkey
, &dwDisposition
)))
336 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
337 mailtoCommand
= g_strconcat("\"", evolutionBinary
, "\" --component=mail mailto:\%1", NULL
);
339 if ((returnValue
= RegSetValueExA (tmp_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)mailtoCommand
, strlen (mailtoCommand
) + 1)))
343 RegFlushKey (tmp_subkey
);
345 RegCloseKey (tmp_subkey
);
348 g_free (defaultIcon
);
349 g_free (evolutionBinary
);
350 g_free (mailtoCommand
);
354 _e_win32_register_mailer_impl (gboolean system
)
357 DWORD i
, dwDisposition
;
358 gchar
*defaultIcon
= NULL
;
359 gchar
*dllPath
= NULL
;
360 gchar
*evolutionBinary
= NULL
;
361 gchar
*openCommand
= NULL
;
362 gchar
*reinstallCommand
= NULL
;
363 gchar
*showIconsCommand
= NULL
;
364 gchar
*hideIconsCommand
= NULL
;
366 static HKEY reg_key
= (HKEY
) INVALID_HANDLE_VALUE
;
367 static HKEY reg_subkey
= (HKEY
) INVALID_HANDLE_VALUE
;
370 if ((returnValue
= RegCreateKeyExA (system
? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
371 "Software\\Clients\\Mail\\" CANONICALNAME
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_key
, &dwDisposition
)))
374 if ((returnValue
= RegSetValueExA (reg_key
, NULL
, 0, REG_SZ
, (const BYTE
*)CANONICALNAME
, strlen (CANONICALNAME
) + 1)))
377 dllPath
= _e_win32_sanitize_path (g_build_path(G_DIR_SEPARATOR_S
, _e_get_bindir (), EUTILDLL
, NULL
));
379 if ((returnValue
= RegSetValueExA (reg_key
, "DLLPath", 0, REG_SZ
, (const BYTE
*)dllPath
, strlen (dllPath
) + 1)))
382 RegFlushKey (reg_key
);
384 if ((returnValue
= RegCreateKeyExA (reg_key
, "DefaultIcon", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
387 evolutionBinary
= _e_win32_sanitize_path (g_build_path (G_DIR_SEPARATOR_S
, _e_get_bindir (), EVOBINARY
, NULL
));
388 defaultIcon
= g_strconcat(evolutionBinary
, ",0", NULL
);
390 if ((returnValue
= RegSetValueExA (reg_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)defaultIcon
, strlen (defaultIcon
) + 1)))
394 RegFlushKey (reg_subkey
);
396 RegCloseKey (reg_subkey
);
398 if ((returnValue
= RegCreateKeyExA (reg_key
, "shell\\open\\command", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
401 openCommand
= g_strconcat("\"", evolutionBinary
, "\" --component=mail", NULL
);
402 if ((returnValue
= RegSetValueExA (reg_subkey
, NULL
, 0, REG_SZ
, (const BYTE
*)openCommand
, strlen (openCommand
) + 1)))
405 RegFlushKey (reg_subkey
);
407 RegCloseKey (reg_subkey
);
409 if ((returnValue
= RegCreateKeyExA (reg_key
, "InstallInfo", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
412 reinstallCommand
= g_strconcat ("\"", evolutionBinary
, "\" --reinstall", NULL
);
414 if ((returnValue
= RegSetValueExA (reg_subkey
, "ReinstallCommand", 0, REG_EXPAND_SZ
, (const BYTE
*)reinstallCommand
, strlen (reinstallCommand
) + 1)))
418 showIconsCommand
= g_strconcat ("\"", evolutionBinary
, "\" --show-icons", NULL
);
420 if ((returnValue
= RegSetValueExA (reg_subkey
, "ShowIconsCommand", 0, REG_EXPAND_SZ
, (const BYTE
*)showIconsCommand
, strlen (showIconsCommand
) + 1)))
424 hideIconsCommand
= g_strconcat ("\"", evolutionBinary
, "\" --hide-icons", NULL
);
426 if ((returnValue
= RegSetValueExA (reg_subkey
, "HideIconsCommand", 0, REG_EXPAND_SZ
, (const BYTE
*)hideIconsCommand
, strlen (hideIconsCommand
) + 1)))
431 if ((returnValue
= RegSetValueExA (reg_subkey
, "IconsVisible", 0, REG_DWORD
, (BYTE
*)&i
, sizeof (i
))))
434 RegFlushKey (reg_subkey
);
436 RegCloseKey (reg_subkey
);
438 if ((returnValue
= RegCreateKeyExA (reg_key
, "Protocols\\mailto", 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_subkey
, &dwDisposition
)))
441 if ((returnValue
= RegSetValueExA (reg_key
, NULL
, 0, REG_SZ
, (const BYTE
*)CANONICALNAME
, strlen (CANONICALNAME
) + 1)))
444 _e_register_mailto_structure (reg_subkey
);
446 RegCloseKey (reg_subkey
);
448 RegCloseKey (reg_key
);
451 g_free (defaultIcon
);
453 g_free (evolutionBinary
);
454 g_free (openCommand
);
455 g_free (reinstallCommand
);
456 g_free (showIconsCommand
);
457 g_free (hideIconsCommand
);
461 _e_win32_register_mailer (void)
463 _e_win32_register_mailer_impl (TRUE
);
464 _e_win32_register_mailer_impl (FALSE
);
468 _e_win32_unregister_mailer (void)
473 _e_win32_set_default_mailer_impl (gboolean system
)
478 const char client_message
[] = "Software\\Clients\\Mail";
479 const char mailto_message
[] = "Software\\Classes\\mailto";
481 static HKEY reg_key
= (HKEY
) INVALID_HANDLE_VALUE
;
483 _e_win32_register_mailer_impl (system
);
485 if ((returnValue
= RegCreateKeyExA (system
? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
486 client_message
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_key
, &dwDisposition
)))
489 if ((returnValue
= RegSetValueExA (reg_key
, NULL
, 0, REG_SZ
, (const BYTE
*)CANONICALNAME
, strlen (CANONICALNAME
) + 1)))
492 RegFlushKey (reg_key
);
494 RegCloseKey (reg_key
);
496 if ((returnValue
= RegCreateKeyExA (system
? HKEY_LOCAL_MACHINE
: HKEY_CURRENT_USER
,
497 mailto_message
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, ®_key
, &dwDisposition
)))
500 _e_register_mailto_structure (reg_key
);
502 RegFlushKey (reg_key
);
504 RegCloseKey (reg_key
);
506 SendMessageA (HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, (LPARAM
)&client_message
);
507 SendMessageA (HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, (LPARAM
)&mailto_message
);
511 _e_win32_set_default_mailer (void)
513 _e_win32_set_default_mailer_impl (TRUE
);
514 _e_win32_set_default_mailer_impl (FALSE
);
518 _e_win32_unset_default_mailer (void)
520 /* TODO: implement */