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.21"
32 #define ARCH_STRING "x86"
33 #define GECKO_SHA "a514fc4d53783a586c7880a676c415695fe934a3"
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
;
63 static WCHAR GeckoUrl
[] = L
"http://dl.dropboxusercontent.com/u/743491/ReactOS/wine_gecko-2.21-x86.msi";
65 /* SHA definitions are copied from advapi32. They aren't available in headers. */
74 void WINAPI
A_SHAInit(PSHA_CTX
);
75 void WINAPI
A_SHAUpdate(PSHA_CTX
,const unsigned char*,UINT
);
76 void WINAPI
A_SHAFinal(PSHA_CTX
,PULONG
);
78 static BOOL
sha_check(const WCHAR
*file_name
)
80 const unsigned char *file_map
;
83 char buf
[2*sizeof(sha
)+1];
87 file
= CreateFileW(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_READONLY
, NULL
);
88 if(file
== INVALID_HANDLE_VALUE
)
91 size
= GetFileSize(file
, NULL
);
93 map
= CreateFileMappingW(file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
98 file_map
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
104 A_SHAUpdate(&ctx
, file_map
, size
);
105 A_SHAFinal(&ctx
, sha
);
107 UnmapViewOfFile(file_map
);
109 for(i
=0; i
< sizeof(sha
); i
++)
110 sprintf(buf
+ i
*2, "%02x", *((unsigned char*)sha
+i
));
112 if(strcmp(buf
, addon
->sha
)) {
113 WARN("Got %s, expected %s\n", buf
, addon
->sha
);
120 static void set_status(DWORD id
)
122 HWND status
= GetDlgItem(install_dialog
, ID_DWL_STATUS
);
125 LoadStringW(hApplet
, id
, buf
, sizeof(buf
)/sizeof(WCHAR
));
126 SendMessageW(status
, WM_SETTEXT
, 0, (LPARAM
)buf
);
135 static enum install_res
install_file(const WCHAR
*file_name
)
139 res
= MsiInstallProductW(file_name
, NULL
);
140 if(res
!= ERROR_SUCCESS
) {
141 ERR("MsiInstallProduct failed: %u\n", res
);
142 return INSTALL_FAILED
;
148 static enum install_res
install_from_unix_file(const char *dir
, const char *subdir
, const char *file_name
)
150 LPWSTR dos_file_name
;
153 enum install_res ret
;
157 file_path
= heap_alloc(len
+strlen(subdir
)+strlen(file_name
)+3);
159 return INSTALL_FAILED
;
161 memcpy(file_path
, dir
, len
);
162 if(len
&& file_path
[len
-1] != '/' && file_path
[len
-1] != '\\')
163 file_path
[len
++] = '/';
165 strcpy(file_path
+len
, subdir
);
166 len
+= strlen(subdir
);
167 file_path
[len
++] = '/';
169 strcpy(file_path
+len
, file_name
);
171 fd
= _open(file_path
, O_RDONLY
);
173 TRACE("%s not found\n", debugstr_a(file_path
));
174 heap_free(file_path
);
180 WARN("Could not get wine_get_dos_file_name function, calling install_cab directly.\n");
181 res
= MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, 0, 0);
182 dos_file_name
= heap_alloc (res
*sizeof(WCHAR
));
183 MultiByteToWideChar( CP_ACP
, 0, file_path
, -1, dos_file_name
, res
);
185 heap_free(file_path
);
187 ret
= install_file(dos_file_name
);
189 heap_free(dos_file_name
);
193 static const CHAR mshtml_keyA
[] =
194 {'S','o','f','t','w','a','r','e',
195 '\\','W','i','n','e',
196 '\\','M','S','H','T','M','L',0};
198 static enum install_res
install_from_registered_dir(void)
201 DWORD res
, type
, size
= MAX_PATH
;
202 enum install_res ret
;
204 package_dir
= heap_alloc(size
+ sizeof(addon
->file_name
));
206 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
207 if(res
== ERROR_MORE_DATA
) {
208 package_dir
= heap_realloc(package_dir
, size
+ sizeof(addon
->file_name
));
209 res
= RegGetValueA(HKEY_CURRENT_USER
, mshtml_keyA
, "GeckoCabDir", RRF_RT_ANY
, &type
, (PBYTE
)package_dir
, &size
);
212 if(res
!= ERROR_SUCCESS
|| (type
!= REG_SZ
&& type
!= REG_EXPAND_SZ
)) {
213 heap_free(package_dir
);
214 return INSTALL_FAILED
;
217 TRACE("Trying %s/%s\n", debugstr_a(package_dir
), debugstr_a(addon
->file_name
));
219 ret
= install_from_unix_file(package_dir
, "", addon
->file_name
);
221 heap_free(package_dir
);
225 static HRESULT WINAPI
InstallCallback_QueryInterface(IBindStatusCallback
*iface
,
226 REFIID riid
, void **ppv
)
228 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IBindStatusCallback
, riid
)) {
236 static ULONG WINAPI
InstallCallback_AddRef(IBindStatusCallback
*iface
)
241 static ULONG WINAPI
InstallCallback_Release(IBindStatusCallback
*iface
)
246 static HRESULT WINAPI
InstallCallback_OnStartBinding(IBindStatusCallback
*iface
,
247 DWORD dwReserved
, IBinding
*pib
)
249 set_status(IDS_DOWNLOADING
);
253 static HRESULT WINAPI
InstallCallback_GetPriority(IBindStatusCallback
*iface
,
259 static HRESULT WINAPI
InstallCallback_OnLowResource(IBindStatusCallback
*iface
,
265 static HRESULT WINAPI
InstallCallback_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
266 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
268 HWND progress
= GetDlgItem(install_dialog
, ID_DWL_PROGRESS
);
271 SendMessageW(progress
, PBM_SETRANGE32
, 0, ulProgressMax
);
273 SendMessageW(progress
, PBM_SETPOS
, ulProgress
, 0);
278 static HRESULT WINAPI
InstallCallback_OnStopBinding(IBindStatusCallback
*iface
,
279 HRESULT hresult
, LPCWSTR szError
)
281 if(FAILED(hresult
)) {
282 ERR("Binding failed %08x\n", hresult
);
286 set_status(IDS_INSTALLING
);
290 static HRESULT WINAPI
InstallCallback_GetBindInfo(IBindStatusCallback
*iface
,
291 DWORD
* grfBINDF
, BINDINFO
* pbindinfo
)
298 static HRESULT WINAPI
InstallCallback_OnDataAvailable(IBindStatusCallback
*iface
, DWORD grfBSCF
,
299 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
305 static HRESULT WINAPI
InstallCallback_OnObjectAvailable(IBindStatusCallback
*iface
,
306 REFIID riid
, IUnknown
* punk
)
312 static const IBindStatusCallbackVtbl InstallCallbackVtbl
= {
313 InstallCallback_QueryInterface
,
314 InstallCallback_AddRef
,
315 InstallCallback_Release
,
316 InstallCallback_OnStartBinding
,
317 InstallCallback_GetPriority
,
318 InstallCallback_OnLowResource
,
319 InstallCallback_OnProgress
,
320 InstallCallback_OnStopBinding
,
321 InstallCallback_GetBindInfo
,
322 InstallCallback_OnDataAvailable
,
323 InstallCallback_OnObjectAvailable
326 static IBindStatusCallback InstallCallback
= { &InstallCallbackVtbl
};
328 static DWORD WINAPI
download_proc(PVOID arg
)
330 WCHAR tmp_dir
[MAX_PATH
], tmp_file
[MAX_PATH
];
333 GetTempPathW(sizeof(tmp_dir
)/sizeof(WCHAR
), tmp_dir
);
334 GetTempFileNameW(tmp_dir
, NULL
, 0, tmp_file
);
336 TRACE("using temp file %s\n", debugstr_w(tmp_file
));
338 hres
= URLDownloadToFileW(NULL
, GeckoUrl
, tmp_file
, 0, &InstallCallback
);
340 ERR("URLDownloadToFile failed: %08x\n", hres
);
344 if(sha_check(tmp_file
)) {
345 install_file(tmp_file
);
349 if(LoadStringW(hApplet
, IDS_INVALID_SHA
, message
, sizeof(message
)/sizeof(WCHAR
))) {
350 MessageBoxW(NULL
, message
, NULL
, MB_ICONERROR
);
354 DeleteFileW(tmp_file
);
355 EndDialog(install_dialog
, 0);
359 static INT_PTR CALLBACK
installer_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
363 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_HIDE
);
364 install_dialog
= hwnd
;
377 ShowWindow(GetDlgItem(hwnd
, ID_DWL_PROGRESS
), SW_SHOW
);
378 EnableWindow(GetDlgItem(hwnd
, ID_DWL_INSTALL
), 0);
379 EnableWindow(GetDlgItem(hwnd
, IDCANCEL
), 0); /* FIXME */
380 CloseHandle( CreateThread(NULL
, 0, download_proc
, NULL
, 0, NULL
));
388 BOOL
install_addon(addon_t addon_type
)
394 addon
= addons_info
+ addon_type
;
397 * Try to find addon .msi file in following order:
398 * - directory stored in $dir_config_key value of HKCU/Wine/Software/$config_key key
399 * - download the package
401 if (install_from_registered_dir() == INSTALL_NEXT
)
402 DialogBoxW(hApplet
, addon
->dialog_template
, 0, installer_proc
);