wrc: Store version and characteristics as simple integers.
[wine.git] / dlls / appwiz.cpl / addons.c
blob1d87eac5b1a307ac6ca1c8d5337dcb657fb66045
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 <stdarg.h>
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <errno.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "cpl.h"
31 #include "winreg.h"
32 #include "ole2.h"
33 #include "commctrl.h"
34 #include "advpub.h"
35 #include "wininet.h"
36 #include "pathcch.h"
37 #include "shellapi.h"
38 #include "urlmon.h"
39 #include "msi.h"
40 #include "bcrypt.h"
42 #include "appwiz.h"
43 #include "res.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
49 #define GECKO_VERSION "2.47.2"
50 #ifdef __i386__
51 #define GECKO_ARCH "x86"
52 #define GECKO_SHA "e520ce7336cd420cd09c91337d87e74bb420300fd5cbc6f724c1802766b6a61d"
53 #elif defined(__x86_64__)
54 #define GECKO_ARCH "x86_64"
55 #define GECKO_SHA "0596761024823ff3c21f13e1cd5cd3e89dccc698294d62974d8930aeda86ce45"
56 #else
57 #define GECKO_ARCH ""
58 #define GECKO_SHA "???"
59 #endif
61 #define MONO_VERSION "7.1.1"
62 #if defined(__i386__) || defined(__x86_64__)
63 #define MONO_ARCH "x86"
64 #define MONO_SHA "9dc8e5603b7bc64354eb94ae4ea0f6821424767a3ff44ff0d19e346a490c11ea"
65 #else
66 #define MONO_ARCH ""
67 #define MONO_SHA "???"
68 #endif
70 typedef struct {
71 const char *version;
72 const WCHAR *file_name;
73 const WCHAR *subdir_name;
74 const char *sha;
75 const char *url_default;
76 const char *config_key;
77 const char *url_config_key;
78 const char *dir_config_key;
79 LPCWSTR dialog_template;
80 } addon_info_t;
82 /* Download addon files over HTTP because Wine depends on an external library
83 * for TLS, so we can't be sure that HTTPS will work. The integrity of each file
84 * is checked with a hardcoded cryptographically secure hash. */
85 static const addon_info_t addons_info[] = {
87 GECKO_VERSION,
88 L"wine-gecko-" GECKO_VERSION "-" GECKO_ARCH ".msi",
89 L"gecko",
90 GECKO_SHA,
91 "http://source.winehq.org/winegecko.php",
92 "MSHTML", "GeckoUrl", "GeckoCabDir",
93 MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG)
96 MONO_VERSION,
97 L"wine-mono-" MONO_VERSION "-" MONO_ARCH ".msi",
98 L"mono",
99 MONO_SHA,
100 "http://source.winehq.org/winemono.php",
101 "Dotnet", "MonoUrl", "MonoCabDir",
102 MAKEINTRESOURCEW(ID_DWL_MONO_DIALOG)
106 static const addon_info_t *addon;
108 static HWND install_dialog = NULL;
109 static LPWSTR url = NULL;
110 static IBinding *dwl_binding;
111 static WCHAR *msi_file;
113 extern const char * CDECL wine_get_version(void);
115 static WCHAR * (CDECL *p_wine_get_dos_file_name)(const char*);
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: %lu\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 ULONG res;
188 res = MsiInstallProductW(file_name, NULL);
189 if(res == ERROR_PRODUCT_VERSION)
190 res = MsiInstallProductW(file_name, L"REINSTALL=ALL REINSTALLMODE=vomus");
191 if(res != ERROR_SUCCESS) {
192 ERR("MsiInstallProduct failed: %lu\n", res);
193 return INSTALL_FAILED;
196 return INSTALL_OK;
199 static enum install_res install_from_dos_file(const WCHAR *dir, const WCHAR *subdir, const WCHAR *file_name)
201 WCHAR *path, *canonical_path;
202 enum install_res ret;
203 int len = lstrlenW( dir );
204 int size = len + 1;
205 HRESULT hr;
207 size += lstrlenW( subdir ) + lstrlenW( file_name ) + 2;
208 if (!(path = heap_alloc( size * sizeof(WCHAR) ))) return INSTALL_FAILED;
210 lstrcpyW( path, dir );
211 if (!wcsncmp( path, L"\\??\\", 4 )) path[1] = '\\'; /* change \??\ into \\?\ */
212 if (len && path[len-1] != '/' && path[len-1] != '\\') path[len++] = '\\';
214 lstrcpyW( path + len, subdir );
215 lstrcatW( path, L"\\" );
216 lstrcatW( path, file_name );
218 hr = PathAllocCanonicalize( path, PATHCCH_ALLOW_LONG_PATHS, &canonical_path );
219 if (FAILED( hr ))
221 ERR( "Failed to canonicalize %s, hr %#lx\n", debugstr_w(path), hr );
222 heap_free( path );
223 return INSTALL_NEXT;
225 heap_free( path );
227 if (GetFileAttributesW( canonical_path ) == INVALID_FILE_ATTRIBUTES)
229 TRACE( "%s not found\n", debugstr_w(canonical_path) );
230 LocalFree( canonical_path );
231 return INSTALL_NEXT;
234 ret = install_file( canonical_path );
236 LocalFree( canonical_path );
237 return ret;
240 static enum install_res install_from_unix_file(const char *dir, const WCHAR *subdir, const WCHAR *file_name)
242 WCHAR *dos_dir;
243 enum install_res ret = INSTALL_NEXT;
245 if (p_wine_get_dos_file_name && (dos_dir = p_wine_get_dos_file_name( dir )))
247 ret = install_from_dos_file( dos_dir, subdir, file_name );
248 heap_free( dos_dir );
250 return ret;
253 static HKEY open_config_key(void)
255 HKEY hkey, ret;
256 DWORD res;
258 /* @@ Wine registry key: HKCU\Software\Wine\$config_key */
259 res = RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Wine", &hkey);
260 if(res != ERROR_SUCCESS)
261 return NULL;
263 res = RegOpenKeyA(hkey, addon->config_key, &ret);
264 RegCloseKey(hkey);
265 return res == ERROR_SUCCESS ? ret : NULL;
268 static enum install_res install_from_registered_dir(void)
270 char *package_dir;
271 HKEY hkey;
272 DWORD res, type, size = MAX_PATH;
273 enum install_res ret;
275 hkey = open_config_key();
276 if(!hkey)
277 return INSTALL_NEXT;
279 package_dir = heap_alloc(size);
280 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
281 if(res == ERROR_MORE_DATA) {
282 package_dir = heap_realloc(package_dir, size);
283 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
285 RegCloseKey(hkey);
286 if(res == ERROR_FILE_NOT_FOUND) {
287 heap_free(package_dir);
288 return INSTALL_NEXT;
289 } else if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
290 heap_free(package_dir);
291 return INSTALL_FAILED;
294 ret = install_from_unix_file(package_dir, L"", addon->file_name);
296 heap_free(package_dir);
297 return ret;
300 static enum install_res install_from_default_dir(void)
302 const WCHAR *package_dir;
303 WCHAR *dir_buf = NULL;
304 enum install_res ret = INSTALL_NEXT;
306 if ((package_dir = _wgetenv( L"WINEBUILDDIR" )))
308 dir_buf = heap_alloc( lstrlenW(package_dir) * sizeof(WCHAR) + sizeof(L"\\..\\") );
309 lstrcpyW( dir_buf, package_dir );
310 lstrcatW( dir_buf, L"\\..\\" );
311 package_dir = dir_buf;
313 else package_dir = _wgetenv( L"WINEDATADIR" );
315 if (package_dir)
317 ret = install_from_dos_file(package_dir, addon->subdir_name, addon->file_name);
318 heap_free(dir_buf);
321 if (ret == INSTALL_NEXT)
322 ret = install_from_unix_file(INSTALL_DATADIR "/wine/", addon->subdir_name, addon->file_name);
323 if (ret == INSTALL_NEXT && strcmp(INSTALL_DATADIR, "/usr/share") != 0)
324 ret = install_from_unix_file("/usr/share/wine/", addon->subdir_name, addon->file_name);
325 if (ret == INSTALL_NEXT)
326 ret = install_from_unix_file("/opt/wine/", addon->subdir_name, addon->file_name);
327 return ret;
330 static WCHAR *get_cache_file_name(BOOL ensure_exists)
332 const char *xdg_dir;
333 const WCHAR *home_dir;
334 WCHAR *cache_dir, *ret;
335 size_t len, size;
337 xdg_dir = getenv( "XDG_CACHE_HOME" );
338 if (xdg_dir && *xdg_dir && p_wine_get_dos_file_name)
340 if (!(cache_dir = p_wine_get_dos_file_name( xdg_dir ))) return NULL;
342 else if ((home_dir = _wgetenv( L"WINEHOMEDIR" )))
344 if (!(cache_dir = heap_alloc( lstrlenW(home_dir) * sizeof(WCHAR) + sizeof(L"\\.cache") ))) return NULL;
345 lstrcpyW( cache_dir, home_dir );
346 lstrcatW( cache_dir, L"\\.cache" );
347 cache_dir[1] = '\\'; /* change \??\ into \\?\ */
349 else return NULL;
351 if (ensure_exists && !CreateDirectoryW( cache_dir, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS)
353 WARN( "%s does not exist and could not be created (%lu)\n", debugstr_w(cache_dir), GetLastError() );
354 heap_free( cache_dir );
355 return NULL;
358 size = lstrlenW( cache_dir ) + ARRAY_SIZE(L"\\wine") + lstrlenW( addon->file_name ) + 1;
359 if (!(ret = heap_alloc( size * sizeof(WCHAR) )))
361 heap_free( cache_dir );
362 return NULL;
364 lstrcpyW( ret, cache_dir );
365 lstrcatW( ret, L"\\wine" );
366 heap_free( cache_dir );
368 if (ensure_exists && !CreateDirectoryW( ret, NULL ) && GetLastError() != ERROR_ALREADY_EXISTS)
370 WARN( "%s does not exist and could not be created (%lu)\n", debugstr_w(ret), GetLastError() );
371 heap_free( ret );
372 return NULL;
374 len = lstrlenW( ret );
375 ret[len++] = '\\';
376 lstrcpyW( ret + len, addon->file_name );
378 TRACE( "got %s\n", debugstr_w(ret) );
379 return ret;
382 static enum install_res install_from_cache(void)
384 WCHAR *cache_file_name;
385 enum install_res res;
387 cache_file_name = get_cache_file_name(FALSE);
388 if(!cache_file_name)
389 return INSTALL_NEXT;
391 if(!sha_check(cache_file_name)) {
392 WARN("could not validate checksum\n");
393 DeleteFileW(cache_file_name);
394 heap_free(cache_file_name);
395 return INSTALL_NEXT;
398 res = install_file(cache_file_name);
399 heap_free(cache_file_name);
400 return res;
403 static IInternetBindInfo InstallCallbackBindInfo;
405 static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
406 REFIID riid, void **ppv)
408 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IBindStatusCallback, riid)) {
409 *ppv = iface;
410 return S_OK;
413 if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
414 TRACE("IID_IInternetBindInfo\n");
415 *ppv = &InstallCallbackBindInfo;
416 return S_OK;
419 return E_INVALIDARG;
422 static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
424 return 2;
427 static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
429 return 1;
432 static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
433 DWORD dwReserved, IBinding *pib)
435 set_status(IDS_DOWNLOADING);
437 IBinding_AddRef(pib);
438 dwl_binding = pib;
440 return S_OK;
443 static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface,
444 LONG *pnPriority)
446 return E_NOTIMPL;
449 static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface,
450 DWORD dwReserved)
452 return E_NOTIMPL;
455 static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
456 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
458 HWND progress = GetDlgItem(install_dialog, ID_DWL_PROGRESS);
460 if(ulProgressMax)
461 SendMessageW(progress, PBM_SETRANGE32, 0, ulProgressMax);
462 if(ulProgress)
463 SendMessageW(progress, PBM_SETPOS, ulProgress, 0);
465 return S_OK;
468 static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
469 HRESULT hresult, LPCWSTR szError)
471 if(dwl_binding) {
472 IBinding_Release(dwl_binding);
473 dwl_binding = NULL;
476 if(FAILED(hresult)) {
477 if(hresult == E_ABORT)
478 TRACE("Binding aborted\n");
479 else
480 ERR("Binding failed %08lx\n", hresult);
481 return S_OK;
484 if(!msi_file) {
485 ERR("No MSI file\n");
486 return E_FAIL;
489 set_status(IDS_INSTALLING);
490 EnableWindow(GetDlgItem(install_dialog, IDCANCEL), 0);
492 if(sha_check(msi_file)) {
493 WCHAR *cache_file_name;
495 install_file(msi_file);
497 cache_file_name = get_cache_file_name(TRUE);
498 if(cache_file_name) {
499 CopyFileW(msi_file, cache_file_name, FALSE);
500 heap_free(cache_file_name);
502 }else {
503 WCHAR message[256];
505 if(LoadStringW(hInst, IDS_INVALID_SHA, message, ARRAY_SIZE(message)))
506 MessageBoxW(NULL, message, NULL, MB_ICONERROR);
509 DeleteFileW(msi_file);
510 heap_free(msi_file);
511 msi_file = NULL;
513 EndDialog(install_dialog, 0);
514 return S_OK;
517 static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
518 DWORD* grfBINDF, BINDINFO* pbindinfo)
520 TRACE("()\n");
522 *grfBINDF = BINDF_ASYNCHRONOUS;
523 return S_OK;
526 static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
527 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
529 if(!msi_file) {
530 msi_file = heap_strdupW(pstgmed->u.lpszFileName);
531 TRACE("got file name %s\n", debugstr_w(msi_file));
534 return S_OK;
537 static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
538 REFIID riid, IUnknown* punk)
540 ERR("\n");
541 return E_NOTIMPL;
544 static const IBindStatusCallbackVtbl InstallCallbackVtbl = {
545 InstallCallback_QueryInterface,
546 InstallCallback_AddRef,
547 InstallCallback_Release,
548 InstallCallback_OnStartBinding,
549 InstallCallback_GetPriority,
550 InstallCallback_OnLowResource,
551 InstallCallback_OnProgress,
552 InstallCallback_OnStopBinding,
553 InstallCallback_GetBindInfo,
554 InstallCallback_OnDataAvailable,
555 InstallCallback_OnObjectAvailable
558 static IBindStatusCallback InstallCallback = { &InstallCallbackVtbl };
560 static HRESULT WINAPI InstallCallbackBindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
562 return IBindStatusCallback_QueryInterface(&InstallCallback, riid, ppv);
565 static ULONG WINAPI InstallCallbackBindInfo_AddRef(IInternetBindInfo *iface)
567 return 2;
570 static ULONG WINAPI InstallCallbackBindInfo_Release(IInternetBindInfo *iface)
572 return 1;
575 static HRESULT WINAPI InstallCallbackBindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *bindf, BINDINFO *bindinfo)
577 ERR("\n");
578 return E_NOTIMPL;
581 static HRESULT WINAPI InstallCallbackBindInfo_GetBindString(IInternetBindInfo *iface, ULONG string_type,
582 WCHAR **strs, ULONG cnt, ULONG *fetched)
584 switch(string_type) {
585 case BINDSTRING_USER_AGENT:
586 TRACE("BINDSTRING_USER_AGENT\n");
588 *strs = CoTaskMemAlloc(sizeof(L"Wine Addon Downloader"));
589 if(!*strs)
590 return E_OUTOFMEMORY;
592 lstrcpyW(*strs, L"Wine Addon Downloader");
593 *fetched = 1;
594 return S_OK;
597 return E_NOTIMPL;
600 static const IInternetBindInfoVtbl InstallCallbackBindInfoVtbl = {
601 InstallCallbackBindInfo_QueryInterface,
602 InstallCallbackBindInfo_AddRef,
603 InstallCallbackBindInfo_Release,
604 InstallCallbackBindInfo_GetBindInfo,
605 InstallCallbackBindInfo_GetBindString
608 static IInternetBindInfo InstallCallbackBindInfo = { &InstallCallbackBindInfoVtbl };
610 static void append_url_params( WCHAR *url )
612 DWORD size = INTERNET_MAX_URL_LENGTH * sizeof(WCHAR);
613 DWORD len = lstrlenW(url);
615 lstrcpyW(url+len, L"?arch=");
616 len += lstrlenW(L"?arch=");
617 len += MultiByteToWideChar(CP_ACP, 0, GECKO_ARCH, sizeof(GECKO_ARCH),
618 url+len, size/sizeof(WCHAR)-len)-1;
619 lstrcpyW(url+len, L"&v=");
620 len += lstrlenW(L"&v=");
621 len += MultiByteToWideChar(CP_ACP, 0, addon->version, -1, url+len, size/sizeof(WCHAR)-len)-1;
622 lstrcpyW(url+len, L"&winev=");
623 len += lstrlenW(L"&winev=");
624 MultiByteToWideChar(CP_ACP, 0, wine_get_version(), -1, url+len, size/sizeof(WCHAR)-len);
627 static LPWSTR get_url(void)
629 DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
630 WCHAR *url, *config_key;
631 HKEY hkey;
632 DWORD res, type;
633 DWORD returned_size;
635 static const WCHAR httpW[] = {'h','t','t','p'};
637 url = heap_alloc(size);
638 returned_size = size;
640 hkey = open_config_key();
641 if (hkey)
643 config_key = heap_strdupAtoW(addon->url_config_key);
644 res = RegQueryValueExW(hkey, config_key, NULL, &type, (LPBYTE)url, &returned_size);
645 heap_free(config_key);
646 RegCloseKey(hkey);
647 if(res == ERROR_SUCCESS && type == REG_SZ) goto found;
650 MultiByteToWideChar( CP_ACP, 0, addon->url_default, -1, url, size / sizeof(WCHAR) );
652 found:
653 if (returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) append_url_params( url );
655 TRACE("Got URL %s\n", debugstr_w(url));
656 return url;
659 static BOOL start_download(void)
661 IBindCtx *bind_ctx;
662 IMoniker *mon;
663 IUnknown *tmp;
664 HRESULT hres;
666 hres = CreateURLMoniker(NULL, url, &mon);
667 if(FAILED(hres))
668 return FALSE;
670 hres = CreateAsyncBindCtx(0, &InstallCallback, NULL, &bind_ctx);
671 if(SUCCEEDED(hres)) {
672 hres = IMoniker_BindToStorage(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&tmp);
673 IBindCtx_Release(bind_ctx);
675 IMoniker_Release(mon);
676 if(FAILED(hres))
677 return FALSE;
679 if(tmp)
680 IUnknown_Release(tmp);
681 return TRUE;
684 static void run_winebrowser(const WCHAR *url)
686 PROCESS_INFORMATION pi;
687 STARTUPINFOW si;
688 WCHAR app[MAX_PATH];
689 LONG len, url_len;
690 WCHAR *args;
691 BOOL ret;
693 url_len = lstrlenW(url);
695 len = GetSystemDirectoryW(app, MAX_PATH - ARRAY_SIZE(L"\\winebrowser.exe"));
696 lstrcpyW(app+len, L"\\winebrowser.exe");
697 len += ARRAY_SIZE(L"\\winebrowser.exe") - 1;
699 args = heap_alloc((len+1+url_len)*sizeof(WCHAR));
700 if(!args)
701 return;
703 memcpy(args, app, len*sizeof(WCHAR));
704 args[len++] = ' ';
705 memcpy(args+len, url, (url_len+1) * sizeof(WCHAR));
707 TRACE("starting %s\n", debugstr_w(args));
709 memset(&si, 0, sizeof(si));
710 si.cb = sizeof(si);
711 ret = CreateProcessW(app, args, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
712 heap_free(args);
713 if (ret) {
714 CloseHandle(pi.hThread);
715 CloseHandle(pi.hProcess);
719 static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
721 switch(msg) {
722 case WM_INITDIALOG:
723 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_HIDE);
724 install_dialog = hwnd;
725 return TRUE;
727 case WM_NOTIFY:
728 switch (((NMHDR *)lParam)->code)
730 case NM_CLICK:
731 case NM_RETURN:
732 if (wParam == ID_DWL_STATUS)
733 run_winebrowser(((NMLINK*)lParam)->item.szUrl);
734 break;
736 break;
738 case WM_COMMAND:
739 switch(wParam) {
740 case IDCANCEL:
741 if(dwl_binding)
742 IBinding_Abort(dwl_binding);
743 EndDialog(hwnd, 0);
744 return FALSE;
746 case ID_DWL_INSTALL:
747 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_SHOW);
748 EnableWindow(GetDlgItem(hwnd, ID_DWL_INSTALL), 0);
749 if(!start_download())
750 EndDialog(install_dialog, 0);
754 return FALSE;
757 BOOL install_addon(addon_t addon_type)
759 if(!*GECKO_ARCH)
760 return FALSE;
762 addon = addons_info+addon_type;
764 p_wine_get_dos_file_name = (void *)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "wine_get_dos_file_name");
767 * Try to find addon .msi file in following order:
768 * - directory stored in $dir_config_key value of HKCU/Software/Wine/$config_key key
769 * - $datadir/$addon_subdir/
770 * - $INSTALL_DATADIR/wine/$addon_subdir/
771 * - /usr/share/wine/$addon_subdir/
772 * - /opt/wine/$addon_subdir/
773 * - download from URL stored in $url_config_key value of HKCU/Software/Wine/$config_key key
775 if (install_from_registered_dir() == INSTALL_NEXT
776 && install_from_default_dir() == INSTALL_NEXT
777 && install_from_cache() == INSTALL_NEXT
778 && (url = get_url()))
779 DialogBoxW(hInst, addon->dialog_template, 0, installer_proc);
781 heap_free(url);
782 url = NULL;
783 return TRUE;