riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / appwiz.cpl / addons.c
blobb4fcc25167ffc12151c87bdd8f772786dd477033
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"
46 #include "appwiz.h"
47 #include "res.h"
49 #include "wine/debug.h"
50 #include "wine/library.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
54 #define GECKO_VERSION "2.36"
56 #ifdef __i386__
57 #define ARCH_STRING "x86"
58 #define GECKO_SHA "08b02bf0e3ff3a315135afa1132ddb3a25a63e15"
59 #elif defined(__x86_64__)
60 #define ARCH_STRING "x86_64"
61 #define GECKO_SHA "a7624eb685d04c4ef1f4f093095a5a324808d57c"
62 #else
63 #define ARCH_STRING ""
64 #define GECKO_SHA "???"
65 #endif
67 #define MONO_VERSION "4.5.6"
68 #define MONO_SHA "12ec9a4fa5958426292effd40d9230c7acbba1e8"
70 typedef struct {
71 const char *version;
72 const char *file_name;
73 const char *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 static const addon_info_t addons_info[] = {
84 GECKO_VERSION,
85 "wine_gecko-" GECKO_VERSION "-" ARCH_STRING ".msi",
86 "gecko",
87 GECKO_SHA,
88 "http://source.winehq.org/winegecko.php",
89 "MSHTML", "GeckoUrl", "GeckoCabDir",
90 MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG)
93 MONO_VERSION,
94 "wine-mono-" MONO_VERSION ".msi",
95 "mono",
96 MONO_SHA,
97 "http://source.winehq.org/winemono.php",
98 "Dotnet", "MonoUrl", "MonoCabDir",
99 MAKEINTRESOURCEW(ID_DWL_MONO_DIALOG)
103 static const addon_info_t *addon;
105 static HWND install_dialog = NULL;
106 static LPWSTR url = NULL;
107 static IBinding *dwl_binding;
108 static WCHAR *msi_file;
110 static WCHAR * (CDECL *p_wine_get_dos_file_name)(const char*);
111 static const WCHAR kernel32_dllW[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
114 /* SHA definitions are copied from advapi32. They aren't available in headers. */
116 typedef struct {
117 ULONG Unknown[6];
118 ULONG State[5];
119 ULONG Count[2];
120 UCHAR Buffer[64];
121 } SHA_CTX, *PSHA_CTX;
123 void WINAPI A_SHAInit(PSHA_CTX);
124 void WINAPI A_SHAUpdate(PSHA_CTX,const unsigned char*,UINT);
125 void WINAPI A_SHAFinal(PSHA_CTX,PULONG);
127 static BOOL sha_check(const WCHAR *file_name)
129 const unsigned char *file_map;
130 HANDLE file, map;
131 ULONG sha[5];
132 char buf[2*sizeof(sha)+1];
133 SHA_CTX ctx;
134 DWORD size, i;
136 file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
137 if(file == INVALID_HANDLE_VALUE) {
138 WARN("Could not open file: %u\n", GetLastError());
139 return FALSE;
142 size = GetFileSize(file, NULL);
144 map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
145 CloseHandle(file);
146 if(!map)
147 return FALSE;
149 file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
150 CloseHandle(map);
151 if(!file_map)
152 return FALSE;
154 A_SHAInit(&ctx);
155 A_SHAUpdate(&ctx, file_map, size);
156 A_SHAFinal(&ctx, sha);
158 UnmapViewOfFile(file_map);
160 for(i=0; i < sizeof(sha); i++)
161 sprintf(buf + i*2, "%02x", *((unsigned char*)sha+i));
163 if(strcmp(buf, addon->sha)) {
164 WARN("Got %s, expected %s\n", buf, addon->sha);
165 return FALSE;
168 return TRUE;
171 static void set_status(DWORD id)
173 HWND status = GetDlgItem(install_dialog, ID_DWL_STATUS);
174 WCHAR buf[64];
176 LoadStringW(hInst, id, buf, sizeof(buf)/sizeof(WCHAR));
177 SendMessageW(status, WM_SETTEXT, 0, (LPARAM)buf);
180 enum install_res {
181 INSTALL_OK = 0,
182 INSTALL_FAILED,
183 INSTALL_NEXT,
186 static enum install_res install_file(const WCHAR *file_name)
188 ULONG res;
190 res = MsiInstallProductW(file_name, NULL);
191 if(res != ERROR_SUCCESS) {
192 ERR("MsiInstallProduct failed: %u\n", res);
193 return INSTALL_FAILED;
196 return INSTALL_OK;
199 static enum install_res install_from_unix_file(const char *dir, const char *subdir, const char *file_name)
201 LPWSTR dos_file_name;
202 char *file_path;
203 int fd, len;
204 enum install_res ret;
206 len = strlen(dir);
207 file_path = heap_alloc(len+strlen(subdir)+strlen(file_name)+3);
208 if(!file_path)
209 return INSTALL_FAILED;
211 memcpy(file_path, dir, len);
212 if(len && file_path[len-1] != '/' && file_path[len-1] != '\\')
213 file_path[len++] = '/';
214 if(*subdir) {
215 strcpy(file_path+len, subdir);
216 len += strlen(subdir);
217 file_path[len++] = '/';
219 strcpy(file_path+len, file_name);
221 fd = open(file_path, O_RDONLY);
222 if(fd == -1) {
223 TRACE("%s not found\n", debugstr_a(file_path));
224 heap_free(file_path);
225 return INSTALL_NEXT;
228 close(fd);
230 if(p_wine_get_dos_file_name) { /* Wine UNIX mode */
231 dos_file_name = p_wine_get_dos_file_name(file_path);
232 if(!dos_file_name) {
233 ERR("Could not get dos file name of %s\n", debugstr_a(file_path));
234 heap_free(file_path);
235 return INSTALL_FAILED;
237 } else { /* Windows mode */
238 UINT res;
239 WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
240 res = MultiByteToWideChar( CP_ACP, 0, file_path, -1, 0, 0);
241 dos_file_name = heap_alloc (res*sizeof(WCHAR));
242 MultiByteToWideChar( CP_ACP, 0, file_path, -1, dos_file_name, res);
245 heap_free(file_path);
247 ret = install_file(dos_file_name);
249 heap_free(dos_file_name);
250 return ret;
253 static HKEY open_config_key(void)
255 HKEY hkey, ret;
256 DWORD res;
258 static const WCHAR wine_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
260 /* @@ Wine registry key: HKCU\Software\Wine\$config_key */
261 res = RegOpenKeyW(HKEY_CURRENT_USER, wine_keyW, &hkey);
262 if(res != ERROR_SUCCESS)
263 return NULL;
265 res = RegOpenKeyA(hkey, addon->config_key, &ret);
266 RegCloseKey(hkey);
267 return res == ERROR_SUCCESS ? ret : NULL;
270 static enum install_res install_from_registered_dir(void)
272 char *package_dir;
273 HKEY hkey;
274 DWORD res, type, size = MAX_PATH;
275 enum install_res ret;
277 hkey = open_config_key();
278 if(!hkey)
279 return INSTALL_NEXT;
281 package_dir = heap_alloc(size);
282 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
283 if(res == ERROR_MORE_DATA) {
284 package_dir = heap_realloc(package_dir, size);
285 res = RegGetValueA(hkey, NULL, addon->dir_config_key, RRF_RT_ANY, &type, (PBYTE)package_dir, &size);
287 RegCloseKey(hkey);
288 if(res == ERROR_FILE_NOT_FOUND) {
289 heap_free(package_dir);
290 return INSTALL_NEXT;
291 } else if(res != ERROR_SUCCESS || (type != REG_SZ && type != REG_EXPAND_SZ)) {
292 heap_free(package_dir);
293 return INSTALL_FAILED;
296 TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));
298 ret = install_from_unix_file(package_dir, "", addon->file_name);
300 heap_free(package_dir);
301 return ret;
304 static enum install_res install_from_default_dir(void)
306 const char *data_dir, *package_dir;
307 char *dir_buf = NULL;
308 int len;
309 enum install_res ret;
311 if((data_dir = wine_get_data_dir())) {
312 package_dir = data_dir;
313 }else if((data_dir = wine_get_build_dir())) {
314 len = strlen(data_dir);
315 dir_buf = heap_alloc(len + sizeof("/../"));
316 memcpy(dir_buf, data_dir, len);
317 strcpy(dir_buf+len, "/../");
318 package_dir = dir_buf;
319 }else {
320 return INSTALL_NEXT;
323 ret = install_from_unix_file(package_dir, addon->subdir_name, addon->file_name);
324 heap_free(dir_buf);
326 if (ret == INSTALL_NEXT)
327 ret = install_from_unix_file(INSTALL_DATADIR "/wine/", addon->subdir_name, addon->file_name);
328 if (ret == INSTALL_NEXT && strcmp(INSTALL_DATADIR, "/usr/share"))
329 ret = install_from_unix_file("/usr/share/wine/", addon->subdir_name, addon->file_name);
330 return ret;
333 static WCHAR *get_cache_file_name(BOOL ensure_exists)
335 const char *home_dir = NULL, *xdg_cache_dir;
336 size_t len, size = strlen(addon->file_name) + 7; /* strlen("/wine/"), '\0' */
337 char *cache_file_name;
338 WCHAR *ret;
340 /* non-Wine (eg. Windows) cache is currently not supported */
341 if(!p_wine_get_dos_file_name)
342 return NULL;
344 xdg_cache_dir = getenv("XDG_CACHE_HOME");
345 if(xdg_cache_dir && *xdg_cache_dir) {
346 size += strlen(xdg_cache_dir);
347 }else {
348 home_dir = getenv("HOME");
349 if(!home_dir)
350 return NULL;
352 size += strlen(home_dir) + 8; /* strlen("/.cache/") */
355 cache_file_name = heap_alloc(size);
356 if(!cache_file_name)
357 return NULL;
359 if(xdg_cache_dir && *xdg_cache_dir) {
360 len = strlen(xdg_cache_dir);
361 if(len > 1 && xdg_cache_dir[len-1] == '/')
362 len--;
363 memcpy(cache_file_name, xdg_cache_dir, len);
364 cache_file_name[len] = 0;
365 }else {
366 len = strlen(home_dir);
367 memcpy(cache_file_name, home_dir, len);
368 strcpy(cache_file_name+len, "/.cache");
369 len += 7;
372 if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
373 WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
374 heap_free(cache_file_name);
375 return NULL;
378 strcpy(cache_file_name+len, "/wine");
379 len += 5;
381 if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
382 WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
383 return NULL;
386 cache_file_name[len++] = '/';
387 strcpy(cache_file_name+len, addon->file_name);
388 ret = p_wine_get_dos_file_name(cache_file_name);
390 TRACE("%s -> %s\n", cache_file_name, debugstr_w(ret));
392 heap_free(cache_file_name);
393 return ret;
396 static enum install_res install_from_cache(void)
398 WCHAR *cache_file_name;
399 enum install_res res;
401 cache_file_name = get_cache_file_name(FALSE);
402 if(!cache_file_name)
403 return INSTALL_NEXT;
405 if(!sha_check(cache_file_name)) {
406 WARN("could not validate check sum\n");
407 DeleteFileW(cache_file_name);
408 heap_free(cache_file_name);
409 return INSTALL_NEXT;
412 res = install_file(cache_file_name);
413 heap_free(cache_file_name);
414 return res;
417 static IInternetBindInfo InstallCallbackBindInfo;
419 static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
420 REFIID riid, void **ppv)
422 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IBindStatusCallback, riid)) {
423 *ppv = iface;
424 return S_OK;
427 if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
428 TRACE("IID_IInternetBindInfo\n");
429 *ppv = &InstallCallbackBindInfo;
430 return S_OK;
433 return E_INVALIDARG;
436 static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
438 return 2;
441 static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
443 return 1;
446 static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
447 DWORD dwReserved, IBinding *pib)
449 set_status(IDS_DOWNLOADING);
451 IBinding_AddRef(pib);
452 dwl_binding = pib;
454 return S_OK;
457 static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface,
458 LONG *pnPriority)
460 return E_NOTIMPL;
463 static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface,
464 DWORD dwReserved)
466 return E_NOTIMPL;
469 static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
470 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
472 HWND progress = GetDlgItem(install_dialog, ID_DWL_PROGRESS);
474 if(ulProgressMax)
475 SendMessageW(progress, PBM_SETRANGE32, 0, ulProgressMax);
476 if(ulProgress)
477 SendMessageW(progress, PBM_SETPOS, ulProgress, 0);
479 return S_OK;
482 static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
483 HRESULT hresult, LPCWSTR szError)
485 if(dwl_binding) {
486 IBinding_Release(dwl_binding);
487 dwl_binding = NULL;
490 if(FAILED(hresult)) {
491 if(hresult == E_ABORT)
492 TRACE("Binding aborted\n");
493 else
494 ERR("Binding failed %08x\n", hresult);
495 return S_OK;
498 if(!msi_file) {
499 ERR("No MSI file\n");
500 return E_FAIL;
503 set_status(IDS_INSTALLING);
504 EnableWindow(GetDlgItem(install_dialog, IDCANCEL), 0);
506 if(sha_check(msi_file)) {
507 WCHAR *cache_file_name;
509 install_file(msi_file);
511 cache_file_name = get_cache_file_name(TRUE);
512 if(cache_file_name) {
513 MoveFileW(msi_file, cache_file_name);
514 heap_free(cache_file_name);
516 }else {
517 WCHAR message[256];
519 if(LoadStringW(hInst, IDS_INVALID_SHA, message, sizeof(message)/sizeof(WCHAR)))
520 MessageBoxW(NULL, message, NULL, MB_ICONERROR);
523 DeleteFileW(msi_file);
524 heap_free(msi_file);
525 msi_file = NULL;
527 EndDialog(install_dialog, 0);
528 return S_OK;
531 static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
532 DWORD* grfBINDF, BINDINFO* pbindinfo)
534 TRACE("()\n");
536 *grfBINDF = BINDF_ASYNCHRONOUS;
537 return S_OK;
540 static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
541 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
543 if(!msi_file) {
544 msi_file = heap_strdupW(pstgmed->u.lpszFileName);
545 TRACE("got file name %s\n", debugstr_w(msi_file));
548 return S_OK;
551 static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
552 REFIID riid, IUnknown* punk)
554 ERR("\n");
555 return E_NOTIMPL;
558 static const IBindStatusCallbackVtbl InstallCallbackVtbl = {
559 InstallCallback_QueryInterface,
560 InstallCallback_AddRef,
561 InstallCallback_Release,
562 InstallCallback_OnStartBinding,
563 InstallCallback_GetPriority,
564 InstallCallback_OnLowResource,
565 InstallCallback_OnProgress,
566 InstallCallback_OnStopBinding,
567 InstallCallback_GetBindInfo,
568 InstallCallback_OnDataAvailable,
569 InstallCallback_OnObjectAvailable
572 static IBindStatusCallback InstallCallback = { &InstallCallbackVtbl };
574 static HRESULT WINAPI InstallCallbackBindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
576 return IBindStatusCallback_QueryInterface(&InstallCallback, riid, ppv);
579 static ULONG WINAPI InstallCallbackBindInfo_AddRef(IInternetBindInfo *iface)
581 return 2;
584 static ULONG WINAPI InstallCallbackBindInfo_Release(IInternetBindInfo *iface)
586 return 1;
589 static HRESULT WINAPI InstallCallbackBindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *bindf, BINDINFO *bindinfo)
591 ERR("\n");
592 return E_NOTIMPL;
595 static HRESULT WINAPI InstallCallbackBindInfo_GetBindString(IInternetBindInfo *iface, ULONG string_type,
596 WCHAR **strs, ULONG cnt, ULONG *fetched)
598 static const WCHAR wine_addon_downloaderW[] =
599 {'W','i','n','e',' ','A','d','d','o','n',' ','D','o','w','n','l','o','a','d','e','r',0};
601 switch(string_type) {
602 case BINDSTRING_USER_AGENT:
603 TRACE("BINDSTRING_USER_AGENT\n");
605 *strs = CoTaskMemAlloc(sizeof(wine_addon_downloaderW));
606 if(!*strs)
607 return E_OUTOFMEMORY;
609 memcpy(*strs, wine_addon_downloaderW, sizeof(wine_addon_downloaderW));
610 *fetched = 1;
611 return S_OK;
614 return E_NOTIMPL;
617 static const IInternetBindInfoVtbl InstallCallbackBindInfoVtbl = {
618 InstallCallbackBindInfo_QueryInterface,
619 InstallCallbackBindInfo_AddRef,
620 InstallCallbackBindInfo_Release,
621 InstallCallbackBindInfo_GetBindInfo,
622 InstallCallbackBindInfo_GetBindString
625 static IInternetBindInfo InstallCallbackBindInfo = { &InstallCallbackBindInfoVtbl };
627 static void append_url_params( WCHAR *url )
629 static const WCHAR arch_formatW[] = {'?','a','r','c','h','='};
630 static const WCHAR v_formatW[] = {'&','v','='};
631 static const WCHAR winevW[] = {'&','w','i','n','e','v','='};
632 DWORD size = INTERNET_MAX_URL_LENGTH * sizeof(WCHAR);
633 DWORD len = strlenW(url);
635 memcpy(url+len, arch_formatW, sizeof(arch_formatW));
636 len += sizeof(arch_formatW)/sizeof(WCHAR);
637 len += MultiByteToWideChar(CP_ACP, 0, ARCH_STRING, sizeof(ARCH_STRING),
638 url+len, size/sizeof(WCHAR)-len)-1;
639 memcpy(url+len, v_formatW, sizeof(v_formatW));
640 len += sizeof(v_formatW)/sizeof(WCHAR);
641 len += MultiByteToWideChar(CP_ACP, 0, addon->version, -1, url+len, size/sizeof(WCHAR)-len)-1;
642 memcpy(url+len, winevW, sizeof(winevW));
643 len += sizeof(winevW)/sizeof(WCHAR);
644 MultiByteToWideChar(CP_ACP, 0, PACKAGE_VERSION, -1, url+len, size/sizeof(WCHAR)-len);
647 static LPWSTR get_url(void)
649 DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
650 WCHAR *url, *config_key;
651 HKEY hkey;
652 DWORD res, type;
653 DWORD returned_size;
655 static const WCHAR httpW[] = {'h','t','t','p'};
657 url = heap_alloc(size);
658 returned_size = size;
660 hkey = open_config_key();
661 if (hkey)
663 config_key = heap_strdupAtoW(addon->url_config_key);
664 res = RegQueryValueExW(hkey, config_key, NULL, &type, (LPBYTE)url, &returned_size);
665 heap_free(config_key);
666 RegCloseKey(hkey);
667 if(res == ERROR_SUCCESS && type == REG_SZ) goto found;
670 MultiByteToWideChar( CP_ACP, 0, addon->url_default, -1, url, size / sizeof(WCHAR) );
672 found:
673 if (returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) append_url_params( url );
675 TRACE("Got URL %s\n", debugstr_w(url));
676 return url;
679 static BOOL start_download(void)
681 IBindCtx *bind_ctx;
682 IMoniker *mon;
683 IUnknown *tmp;
684 HRESULT hres;
686 hres = CreateURLMoniker(NULL, url, &mon);
687 if(FAILED(hres))
688 return FALSE;
690 hres = CreateAsyncBindCtx(0, &InstallCallback, NULL, &bind_ctx);
691 if(SUCCEEDED(hres)) {
692 hres = IMoniker_BindToStorage(mon, bind_ctx, NULL, &IID_IUnknown, (void**)&tmp);
693 IBindCtx_Release(bind_ctx);
695 IMoniker_Release(mon);
696 if(FAILED(hres))
697 return FALSE;
699 if(tmp)
700 IUnknown_Release(tmp);
701 return TRUE;
704 static void run_winebrowser(const WCHAR *url)
706 PROCESS_INFORMATION pi;
707 STARTUPINFOW si;
708 WCHAR app[MAX_PATH];
709 LONG len, url_len;
710 WCHAR *args;
711 BOOL ret;
713 static const WCHAR winebrowserW[] = {'\\','w','i','n','e','b','r','o','w','s','e','r','.','e','x','e',0};
715 url_len = strlenW(url);
717 len = GetSystemDirectoryW(app, MAX_PATH-sizeof(winebrowserW)/sizeof(WCHAR));
718 memcpy(app+len, winebrowserW, sizeof(winebrowserW));
719 len += sizeof(winebrowserW)/sizeof(WCHAR) -1;
721 args = heap_alloc((len+1+url_len)*sizeof(WCHAR));
722 if(!args)
723 return;
725 memcpy(args, app, len*sizeof(WCHAR));
726 args[len++] = ' ';
727 memcpy(args+len, url, (url_len+1) * sizeof(WCHAR));
729 TRACE("starting %s\n", debugstr_w(args));
731 memset(&si, 0, sizeof(si));
732 si.cb = sizeof(si);
733 ret = CreateProcessW(app, args, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi);
734 heap_free(args);
735 if (ret) {
736 CloseHandle(pi.hThread);
737 CloseHandle(pi.hProcess);
741 static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
743 switch(msg) {
744 case WM_INITDIALOG:
745 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_HIDE);
746 install_dialog = hwnd;
747 return TRUE;
749 case WM_NOTIFY:
750 switch (((NMHDR *)lParam)->code)
752 case NM_CLICK:
753 case NM_RETURN:
754 if (wParam == ID_DWL_STATUS)
755 run_winebrowser(((NMLINK*)lParam)->item.szUrl);
756 break;
758 break;
760 case WM_COMMAND:
761 switch(wParam) {
762 case IDCANCEL:
763 if(dwl_binding)
764 IBinding_Abort(dwl_binding);
765 EndDialog(hwnd, 0);
766 return FALSE;
768 case ID_DWL_INSTALL:
769 ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_SHOW);
770 EnableWindow(GetDlgItem(hwnd, ID_DWL_INSTALL), 0);
771 if(!start_download())
772 EndDialog(install_dialog, 0);
776 return FALSE;
779 BOOL install_addon(addon_t addon_type)
781 if(!*ARCH_STRING)
782 return FALSE;
784 addon = addons_info+addon_type;
786 p_wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleW(kernel32_dllW), "wine_get_dos_file_name");
789 * Try to find addon .msi file in following order:
790 * - directory stored in $dir_config_key value of HKCU/Software/Wine/$config_key key
791 * - $datadir/$addon_subdir/
792 * - $INSTALL_DATADIR/wine/$addon_subdir/
793 * - /usr/share/wine/$addon_subdir/
794 * - download from URL stored in $url_config_key value of HKCU/Software/Wine/$config_key key
796 if (install_from_registered_dir() == INSTALL_NEXT
797 && install_from_default_dir() == INSTALL_NEXT
798 && install_from_cache() == INSTALL_NEXT
799 && (url = get_url()))
800 DialogBoxW(hInst, addon->dialog_template, 0, installer_proc);
802 heap_free(url);
803 url = NULL;
804 return TRUE;