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
20 #include <wine/port.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
38 #include <wine/debug.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(appwiz
);
42 #define GECKO_VERSION "1.9"
45 #define ARCH_STRING "x86"
46 #define GECKO_SHA "cadf123dd7c4cedf2b22c066b6259e8649ac2b40"
48 #define ARCH_STRING ""
49 #define GECKO_SHA "???"
54 const char *file_name
;
56 const char *config_key
;
57 const char *dir_config_key
;
58 LPCWSTR dialog_template
;
61 static const addon_info_t addons_info
[] = {
64 "wine_gecko-" GECKO_VERSION
"-" ARCH_STRING
".msi",
68 MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG
)
72 static const addon_info_t
*addon
;
74 static HWND install_dialog
= NULL
;
76 static WCHAR GeckoUrl
[] = L
"http://www.reactos.org/wine-gecko.php";
78 /* SHA definitions are copied from advapi32. They aren't available in headers. */
87 void WINAPI
A_SHAInit(PSHA_CTX
);
88 void WINAPI
A_SHAUpdate(PSHA_CTX
,const unsigned char*,UINT
);
89 void WINAPI
A_SHAFinal(PSHA_CTX
,PULONG
);
91 static BOOL
sha_check(const WCHAR
*file_name
)
93 const unsigned char *file_map
;
96 char buf
[2*sizeof(sha
)+1];
100 file
= CreateFileW(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
101 if(file
== INVALID_HANDLE_VALUE
)
104 size
= GetFileSize(file
, NULL
);
106 map
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
111 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
117 A_SHAUpdate(&ctx
, file_map
, size
);
118 A_SHAFinal(&ctx
, sha
);
120 UnmapViewOfFile(file_map
);
122 for(i
=0; i
< sizeof(sha
); i
++)
123 sprintf(buf
+ i
*2, "%02x", *((unsigned char*)sha
+i
));
125 if(strcmp(buf
, addon
->sha
)) {
126 WARN("Got %s, expected %s\n", buf
, addon
->sha
);
133 static void set_status(DWORD id
)
135 HWND status
= GetDlgItem(install_dialog
, ID_DWL_STATUS
);
138 LoadStringW(hApplet
, id
, buf
, sizeof(buf
)/sizeof(WCHAR
));
139 SendMessageW(status
, WM_SETTEXT
, 0, (LPARAM
)buf
);
148 static enum install_res
install_file(const WCHAR
*file_name
)
152 res
= MsiInstallProductW(file_name
, NULL
);
153 if(res
!= ERROR_SUCCESS
) {
154 ERR("MsiInstallProduct failed: %u\n", res
);
155 return INSTALL_FAILED
;
161 static enum install_res
install_from_unix_file(const char *dir
, const char *subdir
, const char *file_name
)
163 LPWSTR dos_file_name
;
166 enum install_res ret
;
170 file_path
= heap_alloc(len
+strlen(subdir
)+strlen(file_name
)+3);
172 return INSTALL_FAILED
;
174 memcpy(file_path
, dir
, len
);
175 if(len
&& file_path
[len
-1] != '/' && file_path
[len
-1] != '\\')
176 file_path
[len
++] = '/';
178 strcpy(file_path
+len
, subdir
);
179 len
+= strlen(subdir
);
180 file_path
[len
++] = '/';
182 strcpy(file_path
+len
, file_name
);
184 fd
= _open(file_path
, O_RDONLY
);
186 TRACE("%s not found\n", debugstr_a(file_path
));
187 heap_free(file_path
);
193 WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
194 res
= MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, 0, 0);
195 dos_file_name
= heap_alloc (res
*sizeof(WCHAR
));
196 MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, dos_file_name
, res
);
198 heap_free(file_path
);
200 ret
= install_file(dos_file_name
);
202 heap_free(dos_file_name
);
206 static const CHAR mshtml_keyA
[] =
207 {'S','o','f','t','w','a','r','e',
208 '\\','W','i','n','e',
209 '\\','M','S','H','T','M','L',0};
211 static enum install_res
install_from_registered_dir(void)
214 DWORD res
, type
, size
= MAX_PATH
;
215 enum install_res ret
;
217 package_dir
= heap_alloc(size
+ sizeof(addon
->file_name
));
219 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
220 if(res
== ERROR_MORE_DATA
) {
221 package_dir
= heap_realloc(package_dir
, size
+ sizeof(addon
->file_name
));
222 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
225 if(res
!= ERROR_SUCCESS
|| (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)) {
226 heap_free(package_dir
);
227 return INSTALL_FAILED
;
230 TRACE("Trying %s/%s\n", debugstr_a(package_dir
), debugstr_a(addon
->file_name
));
232 ret
= install_from_unix_file(package_dir
, "", addon
->file_name
);
234 heap_free(package_dir
);
238 static HRESULT WINAPI
InstallCallback_QueryInterface(IBindStatusCallback
*iface
,
239 REFIID riid
, void **ppv
)
241 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
249 static ULONG WINAPI
InstallCallback_AddRef(IBindStatusCallback
*iface
)
254 static ULONG WINAPI
InstallCallback_Release(IBindStatusCallback
*iface
)
259 static HRESULT WINAPI
InstallCallback_OnStartBinding(IBindStatusCallback
*iface
,
260 DWORD dwReserved
, IBinding
*pib
)
262 set_status(IDS_DOWNLOADING
);
266 static HRESULT WINAPI
InstallCallback_GetPriority(IBindStatusCallback
*iface
,
272 static HRESULT WINAPI
InstallCallback_OnLowResource(IBindStatusCallback
*iface
,
278 static HRESULT WINAPI
InstallCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
279 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
281 HWND progress
= GetDlgItem(install_dialog
, ID_DWL_PROGRESS
);
284 SendMessageW(progress
, PBM_SETRANGE32
, 0, ulProgressMax
);
286 SendMessageW(progress
, PBM_SETPOS
, ulProgress
, 0);
291 static HRESULT WINAPI
InstallCallback_OnStopBinding(IBindStatusCallback
*iface
,
292 HRESULT hresult
, LPCWSTR szError
)
294 if(FAILED(hresult
)) {
295 ERR("Binding failed %08x\n", hresult
);
299 set_status(IDS_INSTALLING
);
303 static HRESULT WINAPI
InstallCallback_GetBindInfo(IBindStatusCallback
*iface
,
304 DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
311 static HRESULT WINAPI
InstallCallback_OnDataAvailable(IBindStatusCallback
*iface
, DWORD grfBSCF
,
312 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
318 static HRESULT WINAPI
InstallCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
319 REFIID riid
, IUnknown
* punk
)
325 static const IBindStatusCallbackVtbl InstallCallbackVtbl
= {
326 InstallCallback_QueryInterface
,
327 InstallCallback_AddRef
,
328 InstallCallback_Release
,
329 InstallCallback_OnStartBinding
,
330 InstallCallback_GetPriority
,
331 InstallCallback_OnLowResource
,
332 InstallCallback_OnProgress
,
333 InstallCallback_OnStopBinding
,
334 InstallCallback_GetBindInfo
,
335 InstallCallback_OnDataAvailable
,
336 InstallCallback_OnObjectAvailable
339 static IBindStatusCallback InstallCallback
= { &InstallCallbackVtbl
};
341 static DWORD WINAPI
download_proc(PVOID arg
)
343 WCHAR tmp_dir
[MAX_PATH
], tmp_file
[MAX_PATH
];
346 GetTempPathW(sizeof(tmp_dir
)/sizeof(WCHAR
), tmp_dir
);
347 GetTempFileNameW(tmp_dir
, NULL
, 0, tmp_file
);
349 TRACE("using temp file %s\n", debugstr_w(tmp_file
));
351 hres
= URLDownloadToFileW(NULL
, GeckoUrl
, tmp_file
, 0, &InstallCallback
);
353 ERR("URLDownloadToFile failed: %08x\n", hres
);
357 if(sha_check(tmp_file
)) {
358 install_file(tmp_file
);
362 if(LoadStringW(hApplet
, IDS_INVALID_SHA
, message
, sizeof(message
)/sizeof(WCHAR
))) {
363 MessageBoxW(NULL
, message
, NULL
, MB_ICONERROR
);
367 DeleteFileW(tmp_file
);
368 EndDialog(install_dialog
, 0);
372 static INT_PTR CALLBACK
installer_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
376 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_HIDE
);
377 install_dialog
= hwnd
;
390 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_SHOW
);
391 EnableWindow(GetDlgItem(hwnd
, ID_DWL_INSTALL
), 0);
392 EnableWindow(GetDlgItem(hwnd
, IDCANCEL
), 0); /* FIXME */
393 CloseHandle( CreateThread(NULL
, 0, download_proc
, NULL
, 0, NULL
));
401 BOOL
install_addon(addon_t addon_type
)
407 addon
= addons_info
+ addon_type
;
410 * Try to find addon .msi file in following order:
411 * - directory stored in $dir_config_key value of HKCU/Wine/Software/$config_key key
412 * - download the package
414 if (install_from_registered_dir() == INSTALL_NEXT
)
415 DialogBoxW(hApplet
, addon
->dialog_template
, 0, installer_proc
);