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
29 #define GECKO_VERSION "2.40"
32 #define ARCH_STRING "x86"
33 #define GECKO_SHA "8a3adedf3707973d1ed4ac3b2e791486abf814bd"
35 #define ARCH_STRING ""
36 #define GECKO_SHA "???"
41 const char *file_name
;
43 const char *config_key
;
44 const char *dir_config_key
;
45 LPCWSTR dialog_template
;
48 static const addon_info_t addons_info
[] = {
51 "wine_gecko-" GECKO_VERSION
"-" ARCH_STRING
".msi",
55 MAKEINTRESOURCEW(ID_DWL_GECKO_DIALOG
)
59 static const addon_info_t
*addon
;
61 static HWND install_dialog
= NULL
;
62 static IBinding
*download_binding
;
64 static WCHAR GeckoUrl
[] = L
"https://svn.reactos.org/amine/wine_gecko-2.40-x86.msi";
66 /* SHA definitions are copied from advapi32. They aren't available in headers. */
75 void WINAPI
A_SHAInit(PSHA_CTX
);
76 void WINAPI
A_SHAUpdate(PSHA_CTX
,const unsigned char*,UINT
);
77 void WINAPI
A_SHAFinal(PSHA_CTX
,PULONG
);
79 static BOOL
sha_check(const WCHAR
*file_name
)
81 const unsigned char *file_map
;
84 char buf
[2*sizeof(sha
)+1];
88 file
= CreateFileW(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
89 if(file
== INVALID_HANDLE_VALUE
)
92 size
= GetFileSize(file
, NULL
);
94 map
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
99 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
105 A_SHAUpdate(&ctx
, file_map
, size
);
106 A_SHAFinal(&ctx
, sha
);
108 UnmapViewOfFile(file_map
);
110 for(i
=0; i
< sizeof(sha
); i
++)
111 sprintf(buf
+ i
*2, "%02x", *((unsigned char*)sha
+i
));
113 if(strcmp(buf
, addon
->sha
)) {
114 WARN("Got %s, expected %s\n", buf
, addon
->sha
);
121 static void set_status(DWORD id
)
123 HWND status
= GetDlgItem(install_dialog
, ID_DWL_STATUS
);
126 LoadStringW(hApplet
, id
, buf
, sizeof(buf
)/sizeof(WCHAR
));
127 SendMessageW(status
, WM_SETTEXT
, 0, (LPARAM
)buf
);
136 static enum install_res
install_file(const WCHAR
*file_name
)
140 res
= MsiInstallProductW(file_name
, NULL
);
141 if(res
!= ERROR_SUCCESS
) {
142 ERR("MsiInstallProduct failed: %u\n", res
);
143 return INSTALL_FAILED
;
149 static enum install_res
install_from_unix_file(const char *dir
, const char *subdir
, const char *file_name
)
151 LPWSTR dos_file_name
;
154 enum install_res ret
;
158 file_path
= heap_alloc(len
+strlen(subdir
)+strlen(file_name
)+3);
160 return INSTALL_FAILED
;
162 memcpy(file_path
, dir
, len
);
163 if(len
&& file_path
[len
-1] != '/' && file_path
[len
-1] != '\\')
164 file_path
[len
++] = '/';
166 strcpy(file_path
+len
, subdir
);
167 len
+= strlen(subdir
);
168 file_path
[len
++] = '/';
170 strcpy(file_path
+len
, file_name
);
172 fd
= _open(file_path
, O_RDONLY
);
174 TRACE("%s not found\n", debugstr_a(file_path
));
175 heap_free(file_path
);
181 WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
182 res
= MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, 0, 0);
183 dos_file_name
= heap_alloc (res
*sizeof(WCHAR
));
184 MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, dos_file_name
, res
);
186 heap_free(file_path
);
188 ret
= install_file(dos_file_name
);
190 heap_free(dos_file_name
);
194 static const CHAR mshtml_keyA
[] =
195 {'S','o','f','t','w','a','r','e',
196 '\\','W','i','n','e',
197 '\\','M','S','H','T','M','L',0};
199 static enum install_res
install_from_registered_dir(void)
202 DWORD res
, type
, size
= MAX_PATH
;
203 enum install_res ret
;
205 package_dir
= heap_alloc(size
+ sizeof(addon
->file_name
));
207 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
208 if(res
== ERROR_MORE_DATA
) {
209 package_dir
= heap_realloc(package_dir
, size
+ sizeof(addon
->file_name
));
210 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
213 if(res
!= ERROR_SUCCESS
|| (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)) {
214 heap_free(package_dir
);
215 return INSTALL_FAILED
;
218 if (type
== REG_EXPAND_SZ
)
220 size
= ExpandEnvironmentStringsA(package_dir
, NULL
, 0);
223 char* buf
= heap_alloc(size
+ sizeof(addon
->file_name
));
224 ExpandEnvironmentStringsA(package_dir
, buf
, size
);
225 heap_free(package_dir
);
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
);
263 IBinding_AddRef(pib
);
264 download_binding
= pib
;
269 static HRESULT WINAPI
InstallCallback_GetPriority(IBindStatusCallback
*iface
,
275 static HRESULT WINAPI
InstallCallback_OnLowResource(IBindStatusCallback
*iface
,
281 static HRESULT WINAPI
InstallCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
282 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
284 HWND progress
= GetDlgItem(install_dialog
, ID_DWL_PROGRESS
);
287 SendMessageW(progress
, PBM_SETRANGE32
, 0, ulProgressMax
);
289 SendMessageW(progress
, PBM_SETPOS
, ulProgress
, 0);
294 static HRESULT WINAPI
InstallCallback_OnStopBinding(IBindStatusCallback
*iface
,
295 HRESULT hresult
, LPCWSTR szError
)
297 if(download_binding
) {
298 IBinding_Release(download_binding
);
299 download_binding
= NULL
;
302 if(FAILED(hresult
)) {
303 if(hresult
== E_ABORT
)
304 TRACE("Binding aborted\n");
306 ERR("Binding failed %08x\n", hresult
);
310 set_status(IDS_INSTALLING
);
314 static HRESULT WINAPI
InstallCallback_GetBindInfo(IBindStatusCallback
*iface
,
315 DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
322 static HRESULT WINAPI
InstallCallback_OnDataAvailable(IBindStatusCallback
*iface
, DWORD grfBSCF
,
323 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
329 static HRESULT WINAPI
InstallCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
330 REFIID riid
, IUnknown
* punk
)
336 static const IBindStatusCallbackVtbl InstallCallbackVtbl
= {
337 InstallCallback_QueryInterface
,
338 InstallCallback_AddRef
,
339 InstallCallback_Release
,
340 InstallCallback_OnStartBinding
,
341 InstallCallback_GetPriority
,
342 InstallCallback_OnLowResource
,
343 InstallCallback_OnProgress
,
344 InstallCallback_OnStopBinding
,
345 InstallCallback_GetBindInfo
,
346 InstallCallback_OnDataAvailable
,
347 InstallCallback_OnObjectAvailable
350 static IBindStatusCallback InstallCallback
= { &InstallCallbackVtbl
};
352 static DWORD WINAPI
download_proc(PVOID arg
)
355 WCHAR tmp_dir
[MAX_PATH
], tmp_file
[MAX_PATH
];
358 GetTempPathW(sizeof(tmp_dir
)/sizeof(WCHAR
), tmp_dir
);
359 GetTempFileNameW(tmp_dir
, NULL
, 0, tmp_file
);
361 TRACE("using temp file %s\n", debugstr_w(tmp_file
));
363 hres
= URLDownloadToFileW(NULL
, GeckoUrl
, tmp_file
, 0, &InstallCallback
);
365 ERR("URLDownloadToFile failed: %08x\n", hres
);
366 if (LoadStringW(hApplet
, IDS_DWL_FAILED
, message
, sizeof(message
) / sizeof(WCHAR
))) {
367 MessageBoxW(NULL
, message
, NULL
, MB_ICONERROR
);
370 if(sha_check(tmp_file
)) {
371 install_file(tmp_file
);
373 if(LoadStringW(hApplet
, IDS_INVALID_SHA
, message
, sizeof(message
)/sizeof(WCHAR
))) {
374 MessageBoxW(NULL
, message
, NULL
, MB_ICONERROR
);
379 DeleteFileW(tmp_file
);
380 EndDialog(install_dialog
, 0);
384 static INT_PTR CALLBACK
installer_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
388 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_HIDE
);
389 install_dialog
= hwnd
;
398 if(download_binding
) {
399 IBinding_Abort(download_binding
);
407 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_SHOW
);
408 EnableWindow(GetDlgItem(hwnd
, ID_DWL_INSTALL
), 0);
409 CloseHandle( CreateThread(NULL
, 0, download_proc
, NULL
, 0, NULL
));
417 BOOL
install_addon(addon_t addon_type
, HWND hwnd_parent
)
423 addon
= addons_info
+ addon_type
;
426 * Try to find addon .msi file in following order:
427 * - directory stored in $dir_config_key value of HKCU/Wine/Software/$config_key key
428 * - download the package
430 if (install_from_registered_dir() == INSTALL_NEXT
)
431 DialogBoxW(hApplet
, addon
->dialog_template
, hwnd_parent
, installer_proc
);