include: Assorted spelling fixes.
[wine] / dlls / appwiz.cpl / addons.c
1 /*
2  * Copyright 2006-2010 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include "config.h"
20 #include "wine/port.h"
21
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
29
30 #define COBJMACROS
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winuser.h"
37 #include "cpl.h"
38 #include "winreg.h"
39 #include "ole2.h"
40 #include "commctrl.h"
41 #include "advpub.h"
42 #include "wininet.h"
43 #include "shellapi.h"
44 #include "urlmon.h"
45 #include "msi.h"
46
47 #include "appwiz.h"
48 #include "res.h"
49
50 #include "wine/debug.h"
51 #include "wine/unicode.h"
52 #include "wine/library.h"
53
54 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
55
56 #define GECKO_VERSION "1.8"
57
58 #ifdef __i386__
59 #define ARCH_STRING "x86"
60 #define GECKO_SHA "a8622ff749cc2a2cb311f902b7e99664ecc2f8d6"
61 #elif defined(__x86_64__)
62 #define ARCH_STRING "x86_64"
63 #define GECKO_SHA "ea8bb450c6b41f71cc0ef23c490dfebdaccf789d"
64 #else
65 #define ARCH_STRING ""
66 #define GECKO_SHA "???"
67 #endif
68
69 #define MONO_VERSION "0.0.8"
70 #define MONO_SHA "dd349e72249ce5ff981be0e9dae33ac4a46a9f60"
71
72 typedef struct {
73     const char *version;
74     const char *file_name;
75     const char *subdir_name;
76     const char *sha;
77     const char *url_default;
78     const char *config_key;
79     const char *url_config_key;
80     const char *dir_config_key;
81     LPCWSTR dialog_template;
82 } addon_info_t;
83
84 static const addon_info_t addons_info[] = {
85     {
86         GECKO_VERSION,
87         "wine_gecko-" GECKO_VERSION "-" ARCH_STRING ".msi",
88         "gecko",
89         GECKO_SHA,
90         "http://source.winehq.org/winegecko.php",
91         "MSHTML", "GeckoUrl", "GeckoCabDir",
92         MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG)
93     },
94     {
95         MONO_VERSION,
96         "wine-mono-" MONO_VERSION ".msi",
97         "mono",
98         MONO_SHA,
99         "http://source.winehq.org/winemono.php",
100         "Dotnet", "MonoUrl", "MonoCabDir",
101         MAKEINTRESOURCEW(ID_DWL_MONO_DIALOG)
102     }
103 };
104
105 static const addon_info_t *addon;
106
107 static HWND install_dialog = NULL;
108 static LPWSTR url = NULL;
109
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};
112
113
114 /* SHA definitions are copied from advapi32. They aren't available in headers. */
115
116 typedef struct {
117    ULONG Unknown[6];
118    ULONG State[5];
119    ULONG Count[2];
120    UCHAR Buffer[64];
121 } SHA_CTX, *PSHA_CTX;
122
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);
126
127 static BOOL sha_check(const WCHAR *file_name)
128 {
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;
135
136     file = CreateFileW(file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
137     if(file == INVALID_HANDLE_VALUE)
138         return FALSE;
139
140     size = GetFileSize(file, NULL);
141
142     map = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
143     CloseHandle(file);
144     if(!map)
145         return FALSE;
146
147     file_map = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
148     CloseHandle(map);
149     if(!file_map)
150         return FALSE;
151
152     A_SHAInit(&ctx);
153     A_SHAUpdate(&ctx, file_map, size);
154     A_SHAFinal(&ctx, sha);
155
156     UnmapViewOfFile(file_map);
157
158     for(i=0; i < sizeof(sha); i++)
159         sprintf(buf + i*2, "%02x", *((unsigned char*)sha+i));
160
161     if(strcmp(buf, addon->sha)) {
162         WARN("Got %s, expected %s\n", buf, addon->sha);
163         return FALSE;
164     }
165
166     return TRUE;
167 }
168
169 static void set_status(DWORD id)
170 {
171     HWND status = GetDlgItem(install_dialog, ID_DWL_STATUS);
172     WCHAR buf[64];
173
174     LoadStringW(hInst, id, buf, sizeof(buf)/sizeof(WCHAR));
175     SendMessageW(status, WM_SETTEXT, 0, (LPARAM)buf);
176 }
177
178 enum install_res {
179     INSTALL_OK = 0,
180     INSTALL_FAILED,
181     INSTALL_NEXT,
182 };
183
184 static enum install_res install_file(const WCHAR *file_name)
185 {
186     ULONG res;
187
188     res = MsiInstallProductW(file_name, NULL);
189     if(res != ERROR_SUCCESS) {
190         ERR("MsiInstallProduct failed: %u\n", res);
191         return INSTALL_FAILED;
192     }
193
194     return INSTALL_OK;
195 }
196
197 static enum install_res install_from_unix_file(const char *dir, const char *subdir, const char *file_name)
198 {
199     LPWSTR dos_file_name;
200     char *file_path;
201     int fd, len;
202     enum install_res ret;
203
204     len = strlen(dir);
205     file_path = heap_alloc(len+strlen(subdir)+strlen(file_name)+3);
206     if(!file_path)
207         return INSTALL_FAILED;
208
209     memcpy(file_path, dir, len);
210     if(len && file_path[len-1] != '/' && file_path[len-1] != '\\')
211         file_path[len++] = '/';
212     if(*subdir) {
213         strcpy(file_path+len, subdir);
214         len += strlen(subdir);
215         file_path[len++] = '/';
216     }
217     strcpy(file_path+len, file_name);
218
219     fd = open(file_path, O_RDONLY);
220     if(fd == -1) {
221         TRACE("%s not found\n", debugstr_a(file_path));
222         heap_free(file_path);
223         return INSTALL_NEXT;
224     }
225
226     close(fd);
227
228     if(p_wine_get_dos_file_name) { /* Wine UNIX mode */
229         dos_file_name = p_wine_get_dos_file_name(file_path);
230         if(!dos_file_name) {
231             ERR("Could not get dos file name of %s\n", debugstr_a(file_path));
232             heap_free(file_path);
233             return INSTALL_FAILED;
234         }
235     } else { /* Windows mode */
236         UINT res;
237         WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
238         res = MultiByteToWideChar( CP_ACP, 0, file_path, -1, 0, 0);
239         dos_file_name = heap_alloc (res*sizeof(WCHAR));
240         MultiByteToWideChar( CP_ACP, 0, file_path, -1, dos_file_name, res);
241     }
242
243     heap_free(file_path);
244
245     ret = install_file(dos_file_name);
246
247     heap_free(dos_file_name);
248     return ret;
249 }
250
251 static HKEY open_config_key(void)
252 {
253     HKEY hkey, ret;
254     DWORD res;
255
256     static const WCHAR wine_keyW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
257
258     /* @@ Wine registry key: HKCU\Software\Wine\$config_key */
259     res = RegOpenKeyW(HKEY_CURRENT_USER, wine_keyW, &hkey);
260     if(res != ERROR_SUCCESS)
261         return NULL;
262
263     res = RegOpenKeyA(hkey, addon->config_key, &ret);
264     RegCloseKey(hkey);
265     return res == ERROR_SUCCESS ? ret : NULL;
266 }
267
268 static enum install_res install_from_registered_dir(void)
269 {
270     char *package_dir;
271     HKEY hkey;
272     DWORD res, type, size = MAX_PATH;
273     enum install_res ret;
274
275     hkey = open_config_key();
276     if(!hkey)
277         return INSTALL_NEXT;
278
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);
284     }
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;
292     }
293
294     TRACE("Trying %s/%s\n", debugstr_a(package_dir), debugstr_a(addon->file_name));
295
296     ret = install_from_unix_file(package_dir, "", addon->file_name);
297
298     heap_free(package_dir);
299     return ret;
300 }
301
302 static enum install_res install_from_default_dir(void)
303 {
304     const char *data_dir, *package_dir;
305     char *dir_buf = NULL;
306     int len;
307     BOOL ret;
308
309     if((data_dir = wine_get_data_dir())) {
310         package_dir = data_dir;
311     }else if((data_dir = wine_get_build_dir())) {
312         len = strlen(data_dir);
313         dir_buf = heap_alloc(len + sizeof("/../"));
314         memcpy(dir_buf, data_dir, len);
315         strcpy(dir_buf+len, "/../");
316         package_dir = dir_buf;
317     }else {
318         return INSTALL_NEXT;
319     }
320
321     ret = install_from_unix_file(package_dir, addon->subdir_name, addon->file_name);
322     heap_free(dir_buf);
323
324     if (ret == INSTALL_NEXT)
325         ret = install_from_unix_file(INSTALL_DATADIR "/wine/", addon->subdir_name, addon->file_name);
326     if (ret == INSTALL_NEXT && strcmp(INSTALL_DATADIR, "/usr/share"))
327         ret = install_from_unix_file("/usr/share/wine/", addon->subdir_name, addon->file_name);
328     return ret;
329 }
330
331 static WCHAR *get_cache_file_name(BOOL ensure_exists)
332 {
333     const char *home_dir = NULL, *xdg_cache_dir;
334     size_t len, size = strlen(addon->file_name) + 7; /* strlen("/wine/"), '\0' */
335     char *cache_file_name;
336     WCHAR *ret;
337
338     /* non-Wine (eg. Windows) cache is currently not supported */
339     if(!p_wine_get_dos_file_name)
340         return NULL;
341
342     xdg_cache_dir = getenv("XDG_CACHE_HOME");
343     if(xdg_cache_dir && *xdg_cache_dir) {
344         size += strlen(xdg_cache_dir);
345     }else {
346         home_dir = getenv("HOME");
347         if(!home_dir)
348             return NULL;
349
350         size += strlen(home_dir) + 8; /* strlen("/.cache/") */
351     }
352
353     cache_file_name = heap_alloc(size);
354     if(!cache_file_name)
355         return NULL;
356
357     if(xdg_cache_dir && *xdg_cache_dir) {
358         len = strlen(xdg_cache_dir);
359         if(len > 1 && xdg_cache_dir[len-1] == '/')
360             len--;
361         memcpy(cache_file_name, xdg_cache_dir, len);
362         cache_file_name[len] = 0;
363     }else {
364         len = strlen(home_dir);
365         memcpy(cache_file_name, home_dir, len);
366         strcpy(cache_file_name+len, "/.cache");
367         len += 7;
368     }
369
370     if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
371         WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
372         heap_free(cache_file_name);
373         return NULL;
374     }
375
376     strcpy(cache_file_name+len, "/wine");
377     len += 5;
378
379     if(ensure_exists && mkdir(cache_file_name, 0777) && errno != EEXIST) {
380         WARN("%s does not exist and could not be created: %s\n", cache_file_name, strerror(errno));
381         return NULL;
382     }
383
384     cache_file_name[len++] = '/';
385     strcpy(cache_file_name+len, addon->file_name);
386     ret = p_wine_get_dos_file_name(cache_file_name);
387
388     TRACE("%s -> %s\n", cache_file_name, debugstr_w(ret));
389
390     heap_free(cache_file_name);
391     return ret;
392 }
393
394 static enum install_res install_from_cache(void)
395 {
396     WCHAR *cache_file_name;
397     enum install_res res;
398
399     cache_file_name = get_cache_file_name(FALSE);
400     if(!cache_file_name)
401         return INSTALL_NEXT;
402
403     if(!sha_check(cache_file_name)) {
404         WARN("could not validate check sum\n");
405         DeleteFileW(cache_file_name);
406         heap_free(cache_file_name);
407         return INSTALL_NEXT;
408     }
409
410     res = install_file(cache_file_name);
411     heap_free(cache_file_name);
412     return res;
413 }
414
415 static HRESULT WINAPI InstallCallback_QueryInterface(IBindStatusCallback *iface,
416         REFIID riid, void **ppv)
417 {
418     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IBindStatusCallback, riid)) {
419         *ppv = iface;
420         return S_OK;
421     }
422
423     return E_INVALIDARG;
424 }
425
426 static ULONG WINAPI InstallCallback_AddRef(IBindStatusCallback *iface)
427 {
428     return 2;
429 }
430
431 static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
432 {
433     return 1;
434 }
435
436 static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
437         DWORD dwReserved, IBinding *pib)
438 {
439     set_status(IDS_DOWNLOADING);
440     return S_OK;
441 }
442
443 static HRESULT WINAPI InstallCallback_GetPriority(IBindStatusCallback *iface,
444         LONG *pnPriority)
445 {
446     return E_NOTIMPL;
447 }
448
449 static HRESULT WINAPI InstallCallback_OnLowResource(IBindStatusCallback *iface,
450        DWORD dwReserved)
451 {
452     return E_NOTIMPL;
453 }
454
455 static HRESULT WINAPI InstallCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
456         ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
457 {
458     HWND progress = GetDlgItem(install_dialog, ID_DWL_PROGRESS);
459
460     if(ulProgressMax)
461         SendMessageW(progress, PBM_SETRANGE32, 0, ulProgressMax);
462     if(ulProgress)
463         SendMessageW(progress, PBM_SETPOS, ulProgress, 0);
464
465     return S_OK;
466 }
467
468 static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
469         HRESULT hresult, LPCWSTR szError)
470 {
471     if(FAILED(hresult)) {
472         ERR("Binding failed %08x\n", hresult);
473         return S_OK;
474     }
475
476     set_status(IDS_INSTALLING);
477     return S_OK;
478 }
479
480 static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
481         DWORD* grfBINDF, BINDINFO* pbindinfo)
482 {
483     /* FIXME */
484     *grfBINDF = 0;
485     return S_OK;
486 }
487
488 static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
489         DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
490 {
491     ERR("\n");
492     return E_NOTIMPL;
493 }
494
495 static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
496         REFIID riid, IUnknown* punk)
497 {
498     ERR("\n");
499     return E_NOTIMPL;
500 }
501
502 static const IBindStatusCallbackVtbl InstallCallbackVtbl = {
503     InstallCallback_QueryInterface,
504     InstallCallback_AddRef,
505     InstallCallback_Release,
506     InstallCallback_OnStartBinding,
507     InstallCallback_GetPriority,
508     InstallCallback_OnLowResource,
509     InstallCallback_OnProgress,
510     InstallCallback_OnStopBinding,
511     InstallCallback_GetBindInfo,
512     InstallCallback_OnDataAvailable,
513     InstallCallback_OnObjectAvailable
514 };
515
516 static IBindStatusCallback InstallCallback = { &InstallCallbackVtbl };
517
518 static void append_url_params( WCHAR *url )
519 {
520     static const WCHAR arch_formatW[] = {'?','a','r','c','h','='};
521     static const WCHAR v_formatW[] = {'&','v','='};
522     DWORD size = INTERNET_MAX_URL_LENGTH * sizeof(WCHAR);
523     DWORD len = strlenW(url);
524
525     memcpy(url+len, arch_formatW, sizeof(arch_formatW));
526     len += sizeof(arch_formatW)/sizeof(WCHAR);
527     len += MultiByteToWideChar(CP_ACP, 0, ARCH_STRING, sizeof(ARCH_STRING),
528                                url+len, size/sizeof(WCHAR)-len)-1;
529     memcpy(url+len, v_formatW, sizeof(v_formatW));
530     len += sizeof(v_formatW)/sizeof(WCHAR);
531     MultiByteToWideChar(CP_ACP, 0, addon->version, -1, url+len, size/sizeof(WCHAR)-len);
532 }
533
534 static LPWSTR get_url(void)
535 {
536     DWORD size = INTERNET_MAX_URL_LENGTH*sizeof(WCHAR);
537     WCHAR *url, *config_key;
538     HKEY hkey;
539     DWORD res, type;
540     DWORD returned_size;
541
542     static const WCHAR httpW[] = {'h','t','t','p'};
543
544     url = heap_alloc(size);
545     returned_size = size;
546
547     hkey = open_config_key();
548     if (hkey)
549     {
550         config_key = heap_strdupAtoW(addon->url_config_key);
551         res = RegQueryValueExW(hkey, config_key, NULL, &type, (LPBYTE)url, &returned_size);
552         heap_free(config_key);
553         RegCloseKey(hkey);
554         if(res == ERROR_SUCCESS && type == REG_SZ) goto found;
555     }
556
557     MultiByteToWideChar( CP_ACP, 0, addon->url_default, -1, url, size / sizeof(WCHAR) );
558
559 found:
560     if (returned_size > sizeof(httpW) && !memcmp(url, httpW, sizeof(httpW))) append_url_params( url );
561
562     TRACE("Got URL %s\n", debugstr_w(url));
563     return url;
564 }
565
566 static DWORD WINAPI download_proc(PVOID arg)
567 {
568     WCHAR tmp_dir[MAX_PATH], tmp_file[MAX_PATH];
569     HRESULT hres;
570
571     GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
572     GetTempFileNameW(tmp_dir, NULL, 0, tmp_file);
573
574     TRACE("using temp file %s\n", debugstr_w(tmp_file));
575
576     hres = URLDownloadToFileW(NULL, url, tmp_file, 0, &InstallCallback);
577     if(FAILED(hres)) {
578         ERR("URLDownloadToFile failed: %08x\n", hres);
579         return 0;
580     }
581
582     if(sha_check(tmp_file)) {
583         WCHAR *cache_file_name;
584
585         install_file(tmp_file);
586
587         cache_file_name = get_cache_file_name(TRUE);
588         if(cache_file_name) {
589             MoveFileW(tmp_file, cache_file_name);
590             heap_free(cache_file_name);
591         }
592     }else {
593         WCHAR message[256];
594
595         if(LoadStringW(hInst, IDS_INVALID_SHA, message, sizeof(message)/sizeof(WCHAR)))
596             MessageBoxW(NULL, message, NULL, MB_ICONERROR);
597     }
598
599     DeleteFileW(tmp_file);
600     EndDialog(install_dialog, 0);
601     return 0;
602 }
603
604 static void run_winebrowser(const WCHAR *url)
605 {
606     PROCESS_INFORMATION pi;
607     STARTUPINFOW si;
608     WCHAR app[MAX_PATH];
609     LONG len, url_len;
610     WCHAR *args;
611     BOOL ret;
612
613     static const WCHAR winebrowserW[] = {'\\','w','i','n','e','b','r','o','w','s','e','r','.','e','x','e',0};
614
615     url_len = strlenW(url);
616
617     len = GetSystemDirectoryW(app, MAX_PATH-sizeof(winebrowserW)/sizeof(WCHAR));
618     memcpy(app+len, winebrowserW, sizeof(winebrowserW));
619     len += sizeof(winebrowserW)/sizeof(WCHAR) -1;
620
621     args = heap_alloc((len+1+url_len)*sizeof(WCHAR));
622     if(!args)
623         return;
624
625     memcpy(args, app, len*sizeof(WCHAR));
626     args[len++] = ' ';
627     memcpy(args+len, url, (url_len+1) * sizeof(WCHAR));
628
629     TRACE("starting %s\n", debugstr_w(args));
630
631     memset(&si, 0, sizeof(si));
632     si.cb = sizeof(si);
633     ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
634     heap_free(args);
635     if (ret) {
636         CloseHandle(pi.hThread);
637         CloseHandle(pi.hProcess);
638     }
639 }
640
641 static INT_PTR CALLBACK installer_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
642 {
643     switch(msg) {
644     case WM_INITDIALOG:
645         ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_HIDE);
646         install_dialog = hwnd;
647         return TRUE;
648
649     case WM_NOTIFY:
650         switch (((NMHDR *)lParam)->code)
651         {
652         case NM_CLICK:
653         case NM_RETURN:
654             if (wParam == ID_DWL_STATUS)
655                 run_winebrowser(((NMLINK*)lParam)->item.szUrl);
656             break;
657         }
658         break;
659
660     case WM_COMMAND:
661         switch(wParam) {
662         case IDCANCEL:
663             EndDialog(hwnd, 0);
664             return FALSE;
665
666         case ID_DWL_INSTALL:
667             ShowWindow(GetDlgItem(hwnd, ID_DWL_PROGRESS), SW_SHOW);
668             EnableWindow(GetDlgItem(hwnd, ID_DWL_INSTALL), 0);
669             EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0); /* FIXME */
670             CloseHandle( CreateThread(NULL, 0, download_proc, NULL, 0, NULL));
671             return FALSE;
672         }
673     }
674
675     return FALSE;
676 }
677
678 BOOL install_addon(addon_t addon_type)
679 {
680     if(!*ARCH_STRING)
681         return FALSE;
682
683     addon = addons_info+addon_type;
684
685     p_wine_get_dos_file_name = (void*)GetProcAddress(GetModuleHandleW(kernel32_dllW), "wine_get_dos_file_name");
686
687     /*
688      * Try to find addon .msi file in following order:
689      * - directory stored in $dir_config_key value of HKCU/Wine/Software/$config_key key
690      * - $datadir/$addon_subdir/
691      * - $INSTALL_DATADIR/wine/$addon_subdir/
692      * - /usr/share/wine/$addon_subdir/
693      * - download from URL stored in $url_config_key value of HKCU/Wine/Software/$config_key key
694      */
695     if (install_from_registered_dir() == INSTALL_NEXT
696         && install_from_default_dir() == INSTALL_NEXT
697         && install_from_cache() == INSTALL_NEXT
698         && (url = get_url()))
699         DialogBoxW(hInst, addon->dialog_template, 0, installer_proc);
700
701     heap_free(url);
702     url = NULL;
703     return TRUE;
704 }