include: Add definitions of SERVICES_*_DATABASEW for generic compilers.
[wine.git] / dlls / appwiz.cpl / addons.c
blobaede3d04c026fcdc4f1c45a1e6c504c555e45297
1 /*
2 * Copyright 2006-2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
22 #include <stdarg.h>
23 #include <fcntl.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #define COBJMACROS
31 #define NONAMELESSUNION
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "cpl.h"
37 #include "winreg.h"
38 #include "ole2.h"
39 #include "commctrl.h"
40 #include "advpub.h"
41 #include "wininet.h"
42 #include "shellapi.h"
43 #include "urlmon.h"
44 #include "msi.h"
45 #include "bcrypt.h"
47 #include "appwiz.h"
48 #include "res.h"
50 #include "wine/debug.h"
51 #include "wine/library.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
55 #define GECKO_VERSION "2.47"
57 #ifdef __i386__
58 #define ARCH_STRING "x86"
59 #define GECKO_SHA "3b8a361f5d63952d21caafd74e849a774994822fb96c5922b01d554f1677643a"
60 #elif defined(__x86_64__)
61 #define ARCH_STRING "x86_64"
62 #define GECKO_SHA "c565ea25e50ea953937d4ab01299e4306da4a556946327d253ea9b28357e4a7d"
63 #else
64 #define ARCH_STRING ""
65 #define GECKO_SHA "???"
66 #endif
68 #define MONO_VERSION "4.7.1"
69 #define MONO_SHA "2c8d5db7f833c3413b2519991f5af1f433d59a927564ec6f38a3f1f8b2c629aa"
71 typedef struct {
72 const char *version;
73 const char *file_name;
74 const char *subdir_name;
75 const char *sha;
76 const char *url_default;
77 const char *config_key;
78 const char *url_config_key;
79 const char *dir_config_key;
80 LPCWSTR dialog_template;
81 } addon_info_t;
83 /* Download addon files over HTTP because Wine depends on an external library
84 * for TLS, so we can't be sure that HTTPS will work. The integrity of each file
85 * is checked with a hardcoded cryptographically secure hash. */
86 static const addon_info_t addons_info[] = {
88 GECKO_VERSION,
89 "wine_gecko-" GECKO_VERSION "-" ARCH_STRING ".msi",
90 "gecko",
91 GECKO_SHA,
92 "http://source.winehq.org/winegecko.php",
93 "MSHTML", "GeckoUrl", "GeckoCabDir",
94 MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG)
97 MONO_VERSION,
98 "wine-mono-" MONO_VERSION ".msi",
99 "mono",
100 MONO_SHA,
101 "http://source.winehq.org/winemono.php",
102 "Dotnet", "MonoUrl", "MonoCabDir",
103 MAKEINTRESOURCEW(ID_DWL_MONO_DIALOG)
107 static const addon_info_t *addon;
109 static HWND install_dialog = NULL;
110 static LPWSTR url = NULL;
111 static IBinding *dwl_binding;
112 static WCHAR *msi_file;
114 static WCHAR * (CDECL *p_wine_get_dos_file_name)(const char*);
115 static const WCHAR kernel32_dllW[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
117 static BOOL sha_check(const WCHAR *file_name)
119 const unsigned char *file_map;
120 HANDLE file, map;
121 DWORD size, i;
122 BCRYPT_HASH_HANDLE hash = NULL;
123 BCRYPT_ALG_HANDLE alg = NULL;
124 UCHAR sha[32];
125 char buf[1024];
126 BOOL ret = FALSE;
128 file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
129 if(file == INVALID_HANDLE_VALUE) {
130 WARN("Could not open file: %u\n", GetLastError());
131 return FALSE;
134 size = GetFileSize(file, NULL);
136 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
137 CloseHandle(file);
138 if(!map)
139 return FALSE;
141 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
142 CloseHandle(map);
143 if(!file_map)
144 return FALSE;
146 if(BCryptOpenAlgorithmProvider(&alg, BCRYPT_SHA256_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0))
147 goto end;
148 if(BCryptCreateHash(alg, &hash, NULL, 0, NULL, 0, 0))
149 goto end;
150 if(BCryptHashData(hash, (UCHAR *)file_map, size, 0))
151 goto end;
152 if(BCryptFinishHash(hash, sha, sizeof(sha), 0))
153 goto end;
155 for(i=0; i < sizeof(sha); i++)
156 sprintf(buf + i * 2, "%02x", sha[i]);
158 ret = !strcmp(buf, addon->sha);
159 if(!ret)
160 WARN("Got %s, expected %s\n", buf, addon->sha);
162 end:
163 UnmapViewOfFile(file_map);
164 if(hash) BCryptDestroyHash(hash);
165 if(alg) BCryptCloseAlgorithmProvider(alg, 0);
166 return ret;
169 static void set_status(DWORD id)
171 HWND status = GetDlgItem(install_dialog, ID_DWL_STATUS);
172 WCHAR buf[64];
174 LoadStringW(hInst, id, buf, ARRAY_SIZE(buf));
175 SendMessageW(status, WM_SETTEXT, 0, (LPARAM)buf);
178 enum install_res {
179 INSTALL_OK = 0,
180 INSTALL_FAILED,
181 INSTALL_NEXT,
184 static enum install_res install_file(const WCHAR *file_name)
186 static const WCHAR update_cmd[] = {
187 'R','E','I','N','S','T','A','L','L','=','A','L','L',' ',
188 'R','E','I','N','S','T','A','L','L','M','O','D','E','=','v','o','m','u','s',0};
189 ULONG res;
191 res = MsiInstallProductW(file_name, NULL);
192 if(res == ERROR_PRODUCT_VERSION)
193 res = MsiInstallProductW(file_name, update_cmd);
194 if(res != ERROR_SUCCESS) {
195 ERR("MsiInstallProduct failed: %u\n", res);
196 return INSTALL_FAILED;
199 return INSTALL_OK;
202 static enum install_res install_from_unix_file(const char *dir, const char *subdir, const char *file_name)
204 LPWSTR dos_file_name;
205 char *file_path;
206 int fd, len;
207 enum install_res ret;
209 len = strlen(dir);
210 file_path = heap_alloc(len+strlen(subdir)+strlen(file_name)+3);
211 if(!file_path)
212 return INSTALL_FAILED;
214 memcpy(file_path, dir, len);
215 if(len && file_path[len-1] != '/' && file_path[len-1] != '\\')
216 file_path[len++] = '/';
217 if(*subdir) {
218 strcpy(file_path+len, subdir);
219 len += strlen(subdir);
220 file_path[len++] = '/';
222 strcpy(file_path+len, file_name);
224 fd = open(file_path, O_RDONLY);
225 if(fd == -1) {
226 TRACE("%s not found\n", debugstr_a(file_path));
227 heap_free(file_path);
228 return INSTALL_NEXT;
231 close(fd);
233 if(p_wine_get_dos_file_name) { /* Wine UNIX mode */
234 dos_file_name = p_wine_get_dos_file_name(file_path);
235 if(!dos_file_name) {
236 ERR("Could not get dos file name of %s\n", debugstr_a(file_path));
237 heap_free(file_path);
238 return INSTALL_FAILED;
240 } else { /* Windows mode */
241 UINT res;
242 WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
243 res = MultiByteToWideChar( CP_ACP, 0, file_path, -1, 0, 0);
244 dos_file_name = heap_alloc (res*sizeof(WCHAR));
245 MultiByteToWideChar( CP_ACP, 0, file_path, -1, dos_file_name, res);
248 heap_free(file_path);
250 ret = install_file(dos_file_name);
252 heap_free(dos_file_name);
253 return ret;
256 static HKEY open_config_key(void)
258 HKEY hkey, ret;
259 DWORD res;
261 static const WCHAR wine_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
263 /* @@ Wine registry key: HKCU\Software\Wine\$config_key */
264 res = RegOpenKeyW(HKEY_CURRENT_USER, wine_keyW, &hkey);
265 if(res != ERROR_SUCCESS)
266 return NULL;
268 res = RegOpenKeyA(hkey, addon->config_key, &ret);
269 RegCloseKey(hkey);
270 return res == ERROR_SUCCESS ? ret : NULL;
273 static enum install_res install_from_registered_dir(void)
275 char *package_dir;
276 HKEY hkey;
277 DWORD res, type, size = MAX_PATH;
278 enum install_res ret;
280 hkey = open_config_key();
281 if(!hkey)
282 return INSTALL_NEXT;
284 package_dir = heap_alloc(size);
285 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
286 if(res == ERROR_MORE_DATA) {
287 package_dir = heap_realloc(package_dir, size);
288 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
290 RegCloseKey(hkey);
291 if(res == ERROR_FILE_NOT_FOUND) {
292 heap_free(package_dir);
293 return INSTALL_NEXT;
294 } else if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
295 heap_free(package_dir);
296 return INSTALL_FAILED;
299 TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));
301 ret = install_from_unix_file(package_dir, "", addon->file_name);
303 heap_free(package_dir);
304 return ret;
307 static enum install_res install_from_default_dir(void)
309 const char *data_dir, *package_dir;
310 char *dir_buf = NULL;
311 int len;
312 enum install_res ret;
314 if((data_dir = wine_get_data_dir())) {
315 package_dir = data_dir;
316 }else if((data_dir = wine_get_build_dir())) {
317 len = strlen(data_dir);
318 dir_buf = heap_alloc(len + sizeof("/../"));
319 memcpy(dir_buf, data_dir, len);
320 strcpy(dir_buf+len, "/../");
321 package_dir = dir_buf;
322 }else {
323 return INSTALL_NEXT;
326 ret = install_from_unix_file(package_dir, addon->subdir_name, addon->file_name);
327 heap_free(dir_buf);
329 if (ret == INSTALL_NEXT)
330 ret = install_from_unix_file(INSTALL_DATADIR "/wine/", addon->subdir_name, addon->file_name);
331 if (ret == INSTALL_NEXT && strcmp(INSTALL_DATADIR, "/usr/share"))
332 ret = install_from_unix_file("/usr/share/wine/", addon->subdir_name, addon->file_name);
333 return ret;
336 static WCHAR *get_cache_file_name(BOOL ensure_exists)
338 const char *home_dir = NULL, *xdg_cache_dir;
339 size_t len, size = strlen(addon->file_name) + 7; /* strlen("/wine/"), '\0' */
340 char *cache_file_name;
341 WCHAR *ret;
343 /* non-Wine (eg. Windows) cache is currently not supported */
344 if(!p_wine_get_dos_file_name)
345 return NULL;
347 xdg_cache_dir = getenv("XDG_CACHE_HOME");
348 if(xdg_cache_dir && *xdg_cache_dir) {
349 size += strlen(xdg_cache_dir);
350 }else {
351 home_dir = getenv("HOME");
352 if(!home_dir)
353 return NULL;
355 size += strlen(home_dir) + 8; /* strlen("/.cache/") */
358 cache_file_name = heap_alloc(size);
359 if(!cache_file_name)
360 return NULL;
362 if(xdg_cache_dir && *xdg_cache_dir) {
363 len = strlen(xdg_cache_dir);
364 if(len > 1 && xdg_cache_dir[len-1] == '/')
365 len--;
366 memcpy(cache_file_name, xdg_cache_dir, len);
367 cache_file_name[len] = 0;
368 }else {
369 len = strlen(home_dir);
370 memcpy(cache_file_name, home_dir, len);
371 strcpy(cache_file_name+len, "/.cache");
372 len += 7;
375 if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
376 WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
377 heap_free(cache_file_name);
378 return NULL;
381 strcpy(cache_file_name+len, "/wine");
382 len += 5;
384 if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
385 WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
386 return NULL;
389 cache_file_name[len++] = '/';
390 strcpy(cache_file_name+len, addon->file_name);
391 ret = p_wine_get_dos_file_name(cache_file_name);
393 TRACE("%s -> %s\n", cache_file_name, debugstr_w(ret));
395 heap_free(cache_file_name);
396 return ret;
399 static enum install_res install_from_cache(void)
401 WCHAR *cache_file_name;
402 enum install_res res;
404 cache_file_name = get_cache_file_name(FALSE);
405 if(!cache_file_name)
406 return INSTALL_NEXT;
408 if(!sha_check(cache_file_name)) {
409 WARN("could not validate checksum\n");
410 DeleteFileW(cache_file_name);
411 heap_free(cache_file_name);
412 return INSTALL_NEXT;
415 res = install_file(cache_file_name);
416 heap_free(cache_file_name);
417 return res;
420 static IInternetBindInfo InstallCallbackBindInfo;
422 static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
423 REFIID riid, void **ppv)
425 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IBindStatusCallback, riid)) {
426 *ppv = iface;
427 return S_OK;
430 if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
431 TRACE("IID_IInternetBindInfo\n");
432 *ppv = &InstallCallbackBindInfo;
433 return S_OK;
436 return E_INVALIDARG;
439 static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
441 return 2;
444 static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
446 return 1;
449 static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
450 DWORD dwReserved, IBinding *pib)
452 set_status(IDS_DOWNLOADING);
454 IBinding_AddRef(pib);
455 dwl_binding = pib;
457 return S_OK;
460 static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface,
461 LONG *pnPriority)
463 return E_NOTIMPL;
466 static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface,
467 DWORD dwReserved)
469 return E_NOTIMPL;
472 static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
473 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
475 HWND progress = GetDlgItem(install_dialog, ID_DWL_PROGRESS);
477 if(ulProgressMax)
478 SendMessageW(progress, PBM_SETRANGE32, 0, ulProgressMax);
479 if(ulProgress)
480 SendMessageW(progress, PBM_SETPOS, ulProgress, 0);
482 return S_OK;
485 static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
486 HRESULT hresult, LPCWSTR szError)
488 if(dwl_binding) {
489 IBinding_Release(dwl_binding);
490 dwl_binding = NULL;
493 if(FAILED(hresult)) {
494 if(hresult == E_ABORT)
495 TRACE("Binding aborted\n");
496 else
497 ERR("Binding failed %08x\n", hresult);
498 return S_OK;
501 if(!msi_file) {
502 ERR("No MSI file\n");
503 return E_FAIL;
506 set_status(IDS_INSTALLING);
507 EnableWindow(GetDlgItem(install_dialog, IDCANCEL), 0);
509 if(sha_check(msi_file)) {
510 WCHAR *cache_file_name;
512 install_file(msi_file);
514 cache_file_name = get_cache_file_name(TRUE);
515 if(cache_file_name) {
516 MoveFileW(msi_file, cache_file_name);
517 heap_free(cache_file_name);
519 }else {
520 WCHAR message[256];
522 if(LoadStringW(hInst, IDS_INVALID_SHA, message, ARRAY_SIZE(message)))
523 MessageBoxW(NULL, message, NULL, MB_ICONERROR);
526 DeleteFileW(msi_file);
527 heap_free(msi_file);
528 msi_file = NULL;
530 EndDialog(install_dialog, 0);
531 return S_OK;
534 static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
535 DWORD* grfBINDF, BINDINFO* pbindinfo)
537 TRACE("()\n");
539 *grfBINDF = BINDF_ASYNCHRONOUS;
540 return S_OK;
543 static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
544 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
546 if(!msi_file) {
547 msi_file = heap_strdupW(pstgmed->u.lpszFileName);
548 TRACE("got file name %s\n", debugstr_w(msi_file));
551 return S_OK;
554 static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
555 REFIID riid, IUnknown* punk)
557 ERR("\n");
558 return E_NOTIMPL;
561 static const IBindStatusCallbackVtbl InstallCallbackVtbl = {
562 InstallCallback_QueryInterface,
563 InstallCallback_AddRef,
564 InstallCallback_Release,
565 InstallCallback_OnStartBinding,
566 InstallCallback_GetPriority,
567 InstallCallback_OnLowResource,
568 InstallCallback_OnProgress,
569 InstallCallback_OnStopBinding,
570 InstallCallback_GetBindInfo,
571 InstallCallback_OnDataAvailable,
572 InstallCallback_OnObjectAvailable
575 static IBindStatusCallback InstallCallback = { &InstallCallbackVtbl };
577 static HRESULT WINAPI InstallCallbackBindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
579 return IBindStatusCallback_QueryInterface(&InstallCallback, riid, ppv);
582 static ULONG WINAPI InstallCallbackBindInfo_AddRef(IInternetBindInfo *iface)
584 return 2;
587 static ULONG WINAPI InstallCallbackBindInfo_Release(IInternetBindInfo *iface)
589 return 1;
592 static HRESULT WINAPI InstallCallbackBindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *bindf, BINDINFO *bindinfo)
594 ERR("\n");
595 return E_NOTIMPL;
598 static HRESULT WINAPI InstallCallbackBindInfo_GetBindString(IInternetBindInfo *iface, ULONG string_type,
599 WCHAR **strs, ULONG cnt, ULONG *fetched)
601 static const WCHAR wine_addon_downloaderW[] =
602 {'W','i','n','e',' ','A','d','d','o','n',' ','D','o','w','n','l','o','a','d','e','r',0};
604 switch(string_type) {
605 case BINDSTRING_USER_AGENT:
606 TRACE("BINDSTRING_USER_AGENT\n");
608 *strs = CoTaskMemAlloc(sizeof(wine_addon_downloaderW));
609 if(!*strs)
610 return E_OUTOFMEMORY;
612 memcpy(*strs, wine_addon_downloaderW, sizeof(wine_addon_downloaderW));
613 *fetched = 1;
614 return S_OK;
617 return E_NOTIMPL;
620 static const IInternetBindInfoVtbl InstallCallbackBindInfoVtbl = {
621 InstallCallbackBindInfo_QueryInterface,
622 InstallCallbackBindInfo_AddRef,
623 InstallCallbackBindInfo_Release,
624 InstallCallbackBindInfo_GetBindInfo,
625 InstallCallbackBindInfo_GetBindString
628 static IInternetBindInfo InstallCallbackBindInfo = { &InstallCallbackBindInfoVtbl };
630 static void append_url_params( WCHAR *url )
632 static const WCHAR arch_formatW[] = {'?','a','r','c','h','='};
633 static const WCHAR v_formatW[] = {'&','v','='};
634 static const WCHAR winevW[] = {'&','w','i','n','e','v','='};
635 DWORD size = INTERNET_MAX_URL_LENGTH * sizeof(WCHAR);
636 DWORD len = strlenW(url);
638 memcpy(url+len, arch_formatW, sizeof(arch_formatW));
639 len += sizeof(arch_formatW)/sizeof(WCHAR);
640 len += MultiByteToWideChar(CP_ACP, 0, ARCH_STRING, sizeof(ARCH_STRING),
641 url+len, size/sizeof(WCHAR)-len)-1;
642 memcpy(url+len, v_formatW, sizeof(v_formatW));
643 len += sizeof(v_formatW)/sizeof(WCHAR);
644 len += MultiByteToWideChar(CP_ACP, 0, addon->version, -1, url+len, size/sizeof(WCHAR)-len)-1;
645 memcpy(url+len, winevW, sizeof(winevW));
646 len += sizeof(winevW)/sizeof(WCHAR);
647 MultiByteToWideChar(CP_ACP, 0, PACKAGE_VERSION, -1, url+len, size/sizeof(WCHAR)-len);
650 static LPWSTR get_url(void)
652 DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
653 WCHAR *url, *config_key;
654 HKEY hkey;
655 DWORD res, type;
656 DWORD returned_size;
658 static const WCHAR httpW[] = {'h','t','t','p'};
660 url = heap_alloc(size);
661 returned_size = size;
663 hkey = open_config_key();
664 if (hkey)
666 config_key = heap_strdupAtoW(addon->url_config_key);
667 res = RegQueryValueExW(hkey, config_key, NULL, &type, (LPBYTE)url, &returned_size);
668 heap_free(config_key);
669 RegCloseKey(hkey);
670 if(res == ERROR_SUCCESS && type == REG_SZ) goto found;
673 MultiByteToWideChar( CP_ACP, 0, addon->url_default, -1, url, size / sizeof(WCHAR) );
675 found:
676 if (returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) append_url_params( url );
678 TRACE("Got URL %s\n", debugstr_w(url));
679 return url;
682 static BOOL start_download(void)
684 IBindCtx *bind_ctx;
685 IMoniker *mon;
686 IUnknown *tmp;
687 HRESULT hres;
689 hres = CreateURLMoniker(NULL, url, &mon);
690 if(FAILED(hres))
691 return FALSE;
693 hres = CreateAsyncBindCtx(0, &InstallCallback, NULL, &bind_ctx);
694 if(SUCCEEDED(hres)) {
695 hres = IMoniker_BindToStorage(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&tmp);
696 IBindCtx_Release(bind_ctx);
698 IMoniker_Release(mon);
699 if(FAILED(hres))
700 return FALSE;
702 if(tmp)
703 IUnknown_Release(tmp);
704 return TRUE;
707 static void run_winebrowser(const WCHAR *url)
709 PROCESS_INFORMATION pi;
710 STARTUPINFOW si;
711 WCHAR app[MAX_PATH];
712 LONG len, url_len;
713 WCHAR *args;
714 BOOL ret;
716 static const WCHAR winebrowserW[] = {'\\','w','i','n','e','b','r','o','w','s','e','r','.','e','x','e',0};
718 url_len = strlenW(url);
720 len = GetSystemDirectoryW(app, MAX_PATH-sizeof(winebrowserW)/sizeof(WCHAR));
721 memcpy(app+len, winebrowserW, sizeof(winebrowserW));
722 len += sizeof(winebrowserW)/sizeof(WCHAR) -1;
724 args = heap_alloc((len+1+url_len)*sizeof(WCHAR));
725 if(!args)
726 return;
728 memcpy(args, app, len*sizeof(WCHAR));
729 args[len++] = ' ';
730 memcpy(args+len, url, (url_len+1) * sizeof(WCHAR));
732 TRACE("starting %s\n", debugstr_w(args));
734 memset(&si, 0, sizeof(si));
735 si.cb = sizeof(si);
736 ret = CreateProcessW(app, args, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
737 heap_free(args);
738 if (ret) {
739 CloseHandle(pi.hThread);
740 CloseHandle(pi.hProcess);
744 static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
746 switch(msg) {
747 case WM_INITDIALOG:
748 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_HIDE);
749 install_dialog = hwnd;
750 return TRUE;
752 case WM_NOTIFY:
753 switch (((NMHDR *)lParam)->code)
755 case NM_CLICK:
756 case NM_RETURN:
757 if (wParam == ID_DWL_STATUS)
758 run_winebrowser(((NMLINK*)lParam)->item.szUrl);
759 break;
761 break;
763 case WM_COMMAND:
764 switch(wParam) {
765 case IDCANCEL:
766 if(dwl_binding)
767 IBinding_Abort(dwl_binding);
768 EndDialog(hwnd, 0);
769 return FALSE;
771 case ID_DWL_INSTALL:
772 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_SHOW);
773 EnableWindow(GetDlgItem(hwnd, ID_DWL_INSTALL), 0);
774 if(!start_download())
775 EndDialog(install_dialog, 0);
779 return FALSE;
782 BOOL install_addon(addon_t addon_type)
784 if(!*ARCH_STRING)
785 return FALSE;
787 addon = addons_info+addon_type;
789 p_wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleW(kernel32_dllW), "wine_get_dos_file_name");
792 * Try to find addon .msi file in following order:
793 * - directory stored in $dir_config_key value of HKCU/Software/Wine/$config_key key
794 * - $datadir/$addon_subdir/
795 * - $INSTALL_DATADIR/wine/$addon_subdir/
796 * - /usr/share/wine/$addon_subdir/
797 * - download from URL stored in $url_config_key value of HKCU/Software/Wine/$config_key key
799 if (install_from_registered_dir() == INSTALL_NEXT
800 && install_from_default_dir() == INSTALL_NEXT
801 && install_from_cache() == INSTALL_NEXT
802 && (url = get_url()))
803 DialogBoxW(hInst, addon->dialog_template, 0, installer_proc);
805 heap_free(url);
806 url = NULL;
807 return TRUE;