Commit 39562961 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Implement SetConvertStg().

parent a3a97558
...@@ -44,15 +44,6 @@ HRESULT WINAPI OleCreateLinkToFile(LPCOLESTR lpszFileName, REFIID riid, ...@@ -44,15 +44,6 @@ HRESULT WINAPI OleCreateLinkToFile(LPCOLESTR lpszFileName, REFIID riid,
} }
/****************************************************************************** /******************************************************************************
* SetConvertStg [OLE32.@]
*/
HRESULT WINAPI SetConvertStg(LPSTORAGE pStg, BOOL fConvert)
{
FIXME("(%p,%x), stub!\n", pStg, fConvert);
return E_NOTIMPL;
}
/******************************************************************************
* OleCreateLink [OLE32.@] * OleCreateLink [OLE32.@]
*/ */
HRESULT WINAPI OleCreateLink(LPMONIKER pmkLinkSrc, REFIID riid, DWORD renderopt, LPFORMATETC lpFormatEtc, HRESULT WINAPI OleCreateLink(LPMONIKER pmkLinkSrc, REFIID riid, DWORD renderopt, LPFORMATETC lpFormatEtc,
......
...@@ -9383,7 +9383,7 @@ HRESULT WINAPI OleConvertIStorageToOLESTREAM ( ...@@ -9383,7 +9383,7 @@ HRESULT WINAPI OleConvertIStorageToOLESTREAM (
enum stream_1ole_flags { enum stream_1ole_flags {
OleStream_LinkedObject = 0x00000001, OleStream_LinkedObject = 0x00000001,
OleStream_Convert = 0x00000100 OleStream_Convert = 0x00000004
}; };
/*********************************************************************** /***********************************************************************
...@@ -9396,7 +9396,6 @@ HRESULT WINAPI GetConvertStg(IStorage *stg) ...@@ -9396,7 +9396,6 @@ HRESULT WINAPI GetConvertStg(IStorage *stg)
DWORD header[2]; DWORD header[2];
IStream *stream; IStream *stream;
HRESULT hr; HRESULT hr;
ULONG len;
TRACE("%p\n", stg); TRACE("%p\n", stg);
...@@ -9405,20 +9404,89 @@ HRESULT WINAPI GetConvertStg(IStorage *stg) ...@@ -9405,20 +9404,89 @@ HRESULT WINAPI GetConvertStg(IStorage *stg)
hr = IStorage_OpenStream(stg, stream_1oleW, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream); hr = IStorage_OpenStream(stg, stream_1oleW, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
len = 0; hr = IStream_Read(stream, header, sizeof(header), NULL);
hr = IStream_Read(stream, header, sizeof(header), &len);
IStream_Release(stream); IStream_Release(stream);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
if (header[0] != version_magic) if (header[0] != version_magic)
{ {
ERR("got wrong version magic for \1Ole stream, 0x%08x\n", header[0]); ERR("got wrong version magic for 1Ole stream, 0x%08x\n", header[0]);
return E_FAIL; return E_FAIL;
} }
return header[1] & OleStream_Convert ? S_OK : S_FALSE; return header[1] & OleStream_Convert ? S_OK : S_FALSE;
} }
/***********************************************************************
* SetConvertStg (OLE32.@)
*/
HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
{
static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
static const DWORD version_magic = 0x02000001;
DWORD flags = convert ? OleStream_Convert : 0;
IStream *stream;
HRESULT hr;
TRACE("(%p, %d)\n", storage, convert);
hr = IStorage_CreateStream(storage, stream_1oleW, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
if (hr == S_OK)
{
struct empty_1ole_stream {
DWORD version_magic;
DWORD flags;
BYTE padding[12];
};
struct empty_1ole_stream stream_data;
stream_data.version_magic = version_magic;
stream_data.flags = flags;
memset(stream_data.padding, 0, sizeof(stream_data.padding));
hr = IStream_Write(stream, &stream_data, sizeof(stream_data), NULL);
IStream_Release(stream);
}
else if (hr == STG_E_FILEALREADYEXISTS)
{
DWORD header[2];
hr = IStorage_OpenStream(storage, stream_1oleW, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
if (FAILED(hr)) return hr;
hr = IStream_Read(stream, header, sizeof(header), NULL);
if (FAILED(hr))
{
IStream_Release(stream);
return hr;
}
/* update flag if differs */
if ((header[1] ^ flags) & OleStream_Convert)
{
LARGE_INTEGER pos;
if (header[1] & OleStream_Convert)
flags = header[1] & ~OleStream_Convert;
else
flags = header[1] | OleStream_Convert;
pos.QuadPart = sizeof(DWORD);
hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
if (FAILED(hr))
{
IStream_Release(stream);
return hr;
}
hr = IStream_Write(stream, &flags, sizeof(flags), NULL);
}
IStream_Release(stream);
}
return hr;
}
/****************************************************************************** /******************************************************************************
* StgIsStorageFile [OLE32.@] * StgIsStorageFile [OLE32.@]
* Verify if the file contains a storage object * Verify if the file contains a storage object
......
...@@ -3009,7 +3009,8 @@ static void test_convert(void) ...@@ -3009,7 +3009,8 @@ static void test_convert(void)
hr = GetConvertStg(stg); hr = GetConvertStg(stg);
ok(hr == STG_E_FILENOTFOUND, "got 0x%08x\n", hr); ok(hr == STG_E_FILENOTFOUND, "got 0x%08x\n", hr);
hr = SetConvertStg(stg, TRUE); hr = SetConvertStg(stg, TRUE);
todo_wine { ok(hr == S_OK, "got 0x%08x\n", hr);
hr = SetConvertStg(stg, TRUE);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetConvertStg(stg); hr = GetConvertStg(stg);
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
...@@ -3017,7 +3018,7 @@ todo_wine { ...@@ -3017,7 +3018,7 @@ todo_wine {
ok(hr == S_OK, "got 0x%08x\n", hr); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = GetConvertStg(stg); hr = GetConvertStg(stg);
ok(hr == S_FALSE, "got 0x%08x\n", hr); ok(hr == S_FALSE, "got 0x%08x\n", hr);
}
IStorage_Release(stg); IStorage_Release(stg);
DeleteFileW(filename); DeleteFileW(filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment