/*********************************************************************** * URLDownloadToCacheFileW (URLMON.@) */ HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName, DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC) { WCHAR cache_path[MAX_PATH + 1]; FILETIME expire, modified; HRESULT hr; LPWSTR ext; static WCHAR header[] = { 'H','T','T','P','/','1','.','0',' ','2','0','0',' ', 'O','K','\\','r','\\','n','\\','r','\\','n',0 }; TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL), szFileName, dwBufLength, dwReserved, pBSC); if (!szURL || !szFileName) return E_INVALIDARG; ext = PathFindExtensionW(szURL); if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0)) return E_FAIL; hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC); if (FAILED(hr)) return hr; expire.dwHighDateTime = 0; expire.dwLowDateTime = 0; modified.dwHighDateTime = 0; modified.dwLowDateTime = 0; if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY, header, sizeof(header), NULL, NULL)) return E_FAIL; if (strlenW(cache_path) > dwBufLength) return E_OUTOFMEMORY; lstrcpyW(szFileName, cache_path); return S_OK; }
HRESULT UMCreateStreamOnCacheFile(LPCWSTR pszURL, DWORD dwSize, LPWSTR pszFileName, HANDLE *phfile, IUMCacheStream **ppstr) { IUMCacheStream* ucstr; HANDLE handle; DWORD size; LPWSTR url, c, ext = NULL; HRESULT hr; size = (strlenW(pszURL)+1)*sizeof(WCHAR); url = heap_alloc(size); memcpy(url, pszURL, size); for (c = url; *c && *c != '#' && *c != '?'; ++c) { if (*c == '.') ext = c+1; else if(*c == '/') ext = NULL; } *c = 0; if(!CreateUrlCacheEntryW(url, dwSize, ext, pszFileName, 0)) hr = HRESULT_FROM_WIN32(GetLastError()); else hr = S_OK; heap_free(url); if (hr != S_OK) return hr; TRACE("Opening %s\n", debugstr_w(pszFileName) ); handle = CreateFileW( pszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, (HANDLE)NULL ); if( handle == INVALID_HANDLE_VALUE ) return HRESULT_FROM_WIN32(GetLastError()); if (phfile) { /* Call CreateFileW again because we need a handle with its own file pointer, and DuplicateHandle will return * a handle that shares its file pointer with the original. */ *phfile = CreateFileW( pszFileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, (HANDLE)NULL ); if (*phfile == (HANDLE) HFILE_ERROR) { DWORD dwError = GetLastError(); CloseHandle(handle); return HRESULT_FROM_WIN32(dwError); } } ucstr = heap_alloc_zero(sizeof(IUMCacheStream)); if(ucstr) { ucstr->pszURL = heap_alloc_zero(sizeof(WCHAR) * (lstrlenW(pszURL) + 1)); if (ucstr->pszURL) { ucstr->pszFileName = heap_alloc_zero(sizeof(WCHAR) * (lstrlenW(pszFileName) + 1)); if (ucstr->pszFileName) { ucstr->lpVtbl=&stvt; ucstr->ref = 1; ucstr->handle = handle; ucstr->closed = 0; lstrcpyW(ucstr->pszURL, pszURL); lstrcpyW(ucstr->pszFileName, pszFileName); *ppstr = ucstr; return S_OK; } heap_free(ucstr->pszURL); } heap_free(ucstr); } CloseHandle(handle); if (phfile) CloseHandle(*phfile); return E_OUTOFMEMORY; }