ole32: Try to open 1Ole stream before trying to create it in SetConvertStg function.

This commit is contained in:
Piotr Caban 2014-04-07 18:55:41 +02:00 committed by Alexandre Julliard
parent f83d24d4f7
commit 046d7c6d42
1 changed files with 30 additions and 29 deletions

View File

@ -9510,20 +9510,22 @@ HRESULT WINAPI GetConvertStg(IStorage *stg)
*/ */
HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert) HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
{ {
static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
DWORD flags = convert ? OleStream_Convert : 0; DWORD flags = convert ? OleStream_Convert : 0;
IStream *stream;
DWORD header[2];
HRESULT hr; HRESULT hr;
TRACE("(%p, %d)\n", storage, convert); TRACE("(%p, %d)\n", storage, convert);
hr = STORAGE_CreateOleStream(storage, flags);
if (hr == STG_E_FILEALREADYEXISTS)
{
static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
IStream *stream;
DWORD header[2];
hr = IStorage_OpenStream(storage, stream_1oleW, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream); hr = IStorage_OpenStream(storage, stream_1oleW, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
if (FAILED(hr)) return hr; if (FAILED(hr))
{
if (hr != STG_E_FILENOTFOUND)
return hr;
return STORAGE_CreateOleStream(storage, flags);
}
hr = IStream_Read(stream, header, sizeof(header), NULL); hr = IStream_Read(stream, header, sizeof(header), NULL);
if (FAILED(hr)) if (FAILED(hr))
@ -9535,7 +9537,7 @@ HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
/* update flag if differs */ /* update flag if differs */
if ((header[1] ^ flags) & OleStream_Convert) if ((header[1] ^ flags) & OleStream_Convert)
{ {
LARGE_INTEGER pos; LARGE_INTEGER pos = {{0}};
if (header[1] & OleStream_Convert) if (header[1] & OleStream_Convert)
flags = header[1] & ~OleStream_Convert; flags = header[1] & ~OleStream_Convert;
@ -9552,9 +9554,8 @@ HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
hr = IStream_Write(stream, &flags, sizeof(flags), NULL); hr = IStream_Write(stream, &flags, sizeof(flags), NULL);
} }
IStream_Release(stream);
}
IStream_Release(stream);
return hr; return hr;
} }