mshtml: Use URLDownloadToFile to download Gecko package file.

This commit is contained in:
Jacek Caban 2010-10-01 15:31:05 +02:00 committed by Alexandre Julliard
parent 1f716bcbf4
commit a9b4f82c7c
1 changed files with 13 additions and 79 deletions

View File

@ -63,30 +63,8 @@ static const WCHAR mshtml_keyW[] =
'\\','M','S','H','T','M','L',0};
static HWND install_dialog = NULL;
static LPWSTR tmp_file_name = NULL;
static HANDLE tmp_file = INVALID_HANDLE_VALUE;
static LPWSTR url = NULL;
static void clean_up(void)
{
if(tmp_file != INVALID_HANDLE_VALUE)
CloseHandle(tmp_file);
if(tmp_file_name) {
DeleteFileW(tmp_file_name);
heap_free(tmp_file_name);
tmp_file_name = NULL;
}
if(tmp_file != INVALID_HANDLE_VALUE) {
CloseHandle(tmp_file);
tmp_file = INVALID_HANDLE_VALUE;
}
if(install_dialog)
EndDialog(install_dialog, 0);
}
static void set_status(DWORD id)
{
HWND status = GetDlgItem(install_dialog, ID_DWL_STATUS);
@ -174,13 +152,10 @@ static BOOL install_cab(LPCWSTR file_name)
heap_free(file_name_a);
if(FAILED(hres)) {
ERR("Could not extract package: %08x\n", hres);
clean_up();
return FALSE;
}
set_registry(install_dir);
clean_up();
return TRUE;
}
@ -313,26 +288,7 @@ static ULONG WINAPI InstallCallback_Release(IBindStatusCallback *iface)
static HRESULT WINAPI InstallCallback_OnStartBinding(IBindStatusCallback *iface,
DWORD dwReserved, IBinding *pib)
{
WCHAR tmp_dir[MAX_PATH];
set_status(IDS_DOWNLOADING);
GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
tmp_file_name = heap_alloc(MAX_PATH*sizeof(WCHAR));
GetTempFileNameW(tmp_dir, NULL, 0, tmp_file_name);
TRACE("creating temp file %s\n", debugstr_w(tmp_file_name));
tmp_file = CreateFileW(tmp_file_name, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(tmp_file == INVALID_HANDLE_VALUE) {
ERR("Could not create file: %d\n", GetLastError());
clean_up();
return E_FAIL;
}
return S_OK;
}
@ -366,17 +322,10 @@ static HRESULT WINAPI InstallCallback_OnStopBinding(IBindStatusCallback *iface,
{
if(FAILED(hresult)) {
ERR("Binding failed %08x\n", hresult);
clean_up();
return S_OK;
}
CloseHandle(tmp_file);
tmp_file = INVALID_HANDLE_VALUE;
set_status(IDS_INSTALLING);
install_cab(tmp_file_name);
return S_OK;
}
@ -391,21 +340,8 @@ static HRESULT WINAPI InstallCallback_GetBindInfo(IBindStatusCallback *iface,
static HRESULT WINAPI InstallCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
{
IStream *str = pstgmed->u.pstm;
BYTE buf[1024];
DWORD size;
HRESULT hres;
do {
DWORD written;
size = 0;
hres = IStream_Read(str, buf, sizeof(buf), &size);
if(size)
WriteFile(tmp_file, buf, size, &written, NULL);
}while(hres == S_OK);
return S_OK;
ERR("\n");
return E_NOTIMPL;
}
static HRESULT WINAPI InstallCallback_OnObjectAvailable(IBindStatusCallback *iface,
@ -477,27 +413,23 @@ static LPWSTR get_url(void)
static DWORD WINAPI download_proc(PVOID arg)
{
IMoniker *mon;
IBindCtx *bctx;
IStream *str = NULL;
WCHAR tmp_dir[MAX_PATH], tmp_file[MAX_PATH];
HRESULT hres;
CreateURLMoniker(NULL, url, &mon);
heap_free(url);
url = NULL;
GetTempPathW(sizeof(tmp_dir)/sizeof(WCHAR), tmp_dir);
GetTempFileNameW(tmp_dir, NULL, 0, tmp_file);
CreateAsyncBindCtx(0, &InstallCallback, 0, &bctx);
TRACE("using temp file %s\n", debugstr_w(tmp_file));
hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&str);
IBindCtx_Release(bctx);
hres = URLDownloadToFileW(NULL, url, tmp_file, 0, &InstallCallback);
if(FAILED(hres)) {
ERR("BindToStorage failed: %08x\n", hres);
ERR("URLDownloadToFile failed: %08x\n", hres);
return 0;
}
if(str)
IStream_Release(str);
install_cab(tmp_file);
DeleteFileW(tmp_file);
EndDialog(install_dialog, 0);
return 0;
}
@ -552,6 +484,8 @@ BOOL install_wine_gecko(BOOL silent)
DialogBoxW(hInst, MAKEINTRESOURCEW(ID_DWL_DIALOG), 0, installer_proc);
}
heap_free(url);
url = NULL;
ReleaseSemaphore(hsem, 1, NULL);
CloseHandle(hsem);