2005-02-21 21:58:09 +01:00
|
|
|
/*
|
|
|
|
* Compound Storage (32 bit version)
|
|
|
|
* Storage implementation
|
|
|
|
*
|
|
|
|
* This file contains the compound file implementation
|
|
|
|
* of the storage interface.
|
|
|
|
*
|
|
|
|
* Copyright 1999 Francis Beaudet
|
|
|
|
* Copyright 1999 Sylvain St-Germain
|
|
|
|
* Copyright 1999 Thuy Nguyen
|
|
|
|
* Copyright 2005 Mike McCormack
|
2005-03-17 21:50:35 +01:00
|
|
|
* Copyright 2005 Juan Lang
|
2019-11-11 08:39:23 +01:00
|
|
|
* Copyright 2006 Mike McCormack
|
2005-02-21 21:58:09 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-17 21:50:35 +01:00
|
|
|
*
|
2005-05-14 13:06:44 +02:00
|
|
|
* TODO:
|
2005-05-16 19:52:36 +02:00
|
|
|
* - I don't honor the maximum property set size.
|
2005-03-17 21:50:35 +01:00
|
|
|
* - Certain bogus files could result in reading past the end of a buffer.
|
|
|
|
* - Mac-generated files won't be read correctly, even if they're little
|
|
|
|
* endian, because I disregard whether the generator was a Mac. This means
|
|
|
|
* strings will probably be munged (as I don't understand Mac scripts.)
|
|
|
|
* - Not all PROPVARIANT types are supported.
|
2005-05-16 23:37:54 +02:00
|
|
|
* - User defined properties are not supported, see comment in
|
|
|
|
* PropertyStorage_ReadFromStream
|
2005-02-21 21:58:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "winuser.h"
|
2019-05-14 12:30:46 +02:00
|
|
|
#include "wine/asm.h"
|
2005-02-21 21:58:09 +01:00
|
|
|
#include "wine/debug.h"
|
2019-11-08 14:33:52 +01:00
|
|
|
#include "wine/heap.h"
|
2005-03-17 21:50:35 +01:00
|
|
|
#include "dictionary.h"
|
2005-02-21 21:58:09 +01:00
|
|
|
#include "storage32.h"
|
2012-08-28 00:28:23 +02:00
|
|
|
#include "oleauto.h"
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(storage);
|
|
|
|
|
2005-07-27 13:10:52 +02:00
|
|
|
static inline StorageImpl *impl_from_IPropertySetStorage( IPropertySetStorage *iface )
|
|
|
|
{
|
2012-07-14 18:42:48 +02:00
|
|
|
return CONTAINING_RECORD(iface, StorageImpl, base.IPropertySetStorage_iface);
|
2005-07-27 13:10:52 +02:00
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2008-03-01 05:36:46 +01:00
|
|
|
/* These are documented in MSDN,
|
2005-03-17 21:50:35 +01:00
|
|
|
* but they don't seem to be in any header file.
|
|
|
|
*/
|
|
|
|
#define PROPSETHDR_BYTEORDER_MAGIC 0xfffe
|
|
|
|
#define PROPSETHDR_OSVER_KIND_WIN16 0
|
|
|
|
#define PROPSETHDR_OSVER_KIND_MAC 1
|
|
|
|
#define PROPSETHDR_OSVER_KIND_WIN32 2
|
|
|
|
|
2005-04-11 16:30:24 +02:00
|
|
|
#define CP_UNICODE 1200
|
|
|
|
|
2005-05-16 19:52:36 +02:00
|
|
|
#define MAX_VERSION_0_PROP_NAME_LENGTH 256
|
|
|
|
|
2006-06-19 20:31:01 +02:00
|
|
|
#define CFTAG_WINDOWS (-1L)
|
|
|
|
#define CFTAG_MACINTOSH (-2L)
|
|
|
|
#define CFTAG_FMTID (-3L)
|
|
|
|
#define CFTAG_NODATA 0L
|
|
|
|
|
2020-01-27 07:24:19 +01:00
|
|
|
#define ALIGNED_LENGTH(_Len, _Align) (((_Len)+(_Align))&~(_Align))
|
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
typedef struct tagPROPERTYSETHEADER
|
|
|
|
{
|
|
|
|
WORD wByteOrder; /* always 0xfffe */
|
|
|
|
WORD wFormat; /* can be zero or one */
|
|
|
|
DWORD dwOSVer; /* OS version of originating system */
|
|
|
|
CLSID clsid; /* application CLSID */
|
|
|
|
DWORD reserved; /* always 1 */
|
|
|
|
} PROPERTYSETHEADER;
|
|
|
|
|
|
|
|
typedef struct tagFORMATIDOFFSET
|
|
|
|
{
|
|
|
|
FMTID fmtid;
|
|
|
|
DWORD dwOffset; /* from beginning of stream */
|
|
|
|
} FORMATIDOFFSET;
|
|
|
|
|
|
|
|
typedef struct tagPROPERTYSECTIONHEADER
|
|
|
|
{
|
|
|
|
DWORD cbSection;
|
|
|
|
DWORD cProperties;
|
|
|
|
} PROPERTYSECTIONHEADER;
|
|
|
|
|
|
|
|
typedef struct tagPROPERTYIDOFFSET
|
|
|
|
{
|
|
|
|
DWORD propid;
|
2005-04-11 16:30:24 +02:00
|
|
|
DWORD dwOffset; /* from beginning of section */
|
2005-03-17 21:50:35 +01:00
|
|
|
} PROPERTYIDOFFSET;
|
|
|
|
|
2006-07-11 11:38:01 +02:00
|
|
|
typedef struct tagPropertyStorage_impl PropertyStorage_impl;
|
2005-04-11 20:50:45 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
/* Initializes the property storage from the stream (and undoes any uncommitted
|
|
|
|
* changes in the process.) Returns an error if there is an error reading or
|
|
|
|
* if the stream format doesn't match what's expected.
|
|
|
|
*/
|
2006-07-11 11:38:01 +02:00
|
|
|
static HRESULT PropertyStorage_ReadFromStream(PropertyStorage_impl *);
|
2005-04-11 20:50:45 +02:00
|
|
|
|
2006-07-11 11:38:01 +02:00
|
|
|
static HRESULT PropertyStorage_WriteToStream(PropertyStorage_impl *);
|
2005-04-11 20:50:45 +02:00
|
|
|
|
|
|
|
/* Creates the dictionaries used by the property storage. If successful, all
|
|
|
|
* the dictionaries have been created. If failed, none has been. (This makes
|
|
|
|
* it a bit easier to deal with destroying them.)
|
|
|
|
*/
|
2006-07-11 11:38:01 +02:00
|
|
|
static HRESULT PropertyStorage_CreateDictionaries(PropertyStorage_impl *);
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2006-07-11 11:38:01 +02:00
|
|
|
static void PropertyStorage_DestroyDictionaries(PropertyStorage_impl *);
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2005-04-23 21:04:49 +02:00
|
|
|
/* Copies from propvar to prop. If propvar's type is VT_LPSTR, copies the
|
|
|
|
* string using PropertyStorage_StringCopy.
|
|
|
|
*/
|
|
|
|
static HRESULT PropertyStorage_PropVariantCopy(PROPVARIANT *prop,
|
2019-12-13 11:06:53 +01:00
|
|
|
const PROPVARIANT *propvar, UINT targetCP, UINT srcCP);
|
2005-04-23 21:04:49 +02:00
|
|
|
|
|
|
|
/* Copies the string src, which is encoded using code page srcCP, and returns
|
|
|
|
* it in *dst, in the code page specified by targetCP. The returned string is
|
|
|
|
* allocated using CoTaskMemAlloc.
|
|
|
|
* If srcCP is CP_UNICODE, src is in fact an LPCWSTR. Similarly, if targetCP
|
|
|
|
* is CP_UNICODE, the returned string is in fact an LPWSTR.
|
|
|
|
* Returns S_OK on success, something else on failure.
|
|
|
|
*/
|
2019-12-13 11:06:53 +01:00
|
|
|
static HRESULT PropertyStorage_StringCopy(LPCSTR src, UINT srcCP, LPSTR *dst,
|
|
|
|
UINT targetCP);
|
2005-04-23 21:04:49 +02:00
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPropertyStorageVtbl IPropertyStorage_Vtbl;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Implementation of IPropertyStorage
|
|
|
|
*/
|
2006-07-11 11:38:01 +02:00
|
|
|
struct tagPropertyStorage_impl
|
2005-02-21 21:58:09 +01:00
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
IPropertyStorage IPropertyStorage_iface;
|
2005-07-05 13:02:54 +02:00
|
|
|
LONG ref;
|
2005-03-17 21:50:35 +01:00
|
|
|
CRITICAL_SECTION cs;
|
2005-02-21 21:58:09 +01:00
|
|
|
IStream *stm;
|
2005-03-17 21:50:35 +01:00
|
|
|
BOOL dirty;
|
|
|
|
FMTID fmtid;
|
|
|
|
CLSID clsid;
|
2005-05-16 19:52:36 +02:00
|
|
|
WORD format;
|
2005-03-17 21:50:35 +01:00
|
|
|
DWORD originatorOS;
|
|
|
|
DWORD grfFlags;
|
|
|
|
DWORD grfMode;
|
|
|
|
UINT codePage;
|
|
|
|
LCID locale;
|
|
|
|
PROPID highestProp;
|
|
|
|
struct dictionary *name_to_propid;
|
|
|
|
struct dictionary *propid_to_name;
|
|
|
|
struct dictionary *propid_to_prop;
|
2006-07-11 11:38:01 +02:00
|
|
|
};
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2010-12-08 13:15:12 +01:00
|
|
|
static inline PropertyStorage_impl *impl_from_IPropertyStorage(IPropertyStorage *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, PropertyStorage_impl, IPropertyStorage_iface);
|
|
|
|
}
|
|
|
|
|
2019-11-11 08:39:23 +01:00
|
|
|
struct enum_stat_prop_stg
|
|
|
|
{
|
|
|
|
IEnumSTATPROPSTG IEnumSTATPROPSTG_iface;
|
|
|
|
LONG refcount;
|
2019-11-12 10:00:11 +01:00
|
|
|
PropertyStorage_impl *storage;
|
2019-11-11 08:39:23 +01:00
|
|
|
STATPROPSTG *stats;
|
|
|
|
size_t current;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct enum_stat_prop_stg *impl_from_IEnumSTATPROPSTG(IEnumSTATPROPSTG *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct enum_stat_prop_stg, IEnumSTATPROPSTG_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_prop_stg_QueryInterface(IEnumSTATPROPSTG *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IEnumSTATPROPSTG) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IEnumSTATPROPSTG_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_stat_prop_stg_AddRef(IEnumSTATPROPSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *penum = impl_from_IEnumSTATPROPSTG(iface);
|
|
|
|
LONG refcount = InterlockedIncrement(&penum->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_stat_prop_stg_Release(IEnumSTATPROPSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *penum = impl_from_IEnumSTATPROPSTG(iface);
|
|
|
|
LONG refcount = InterlockedDecrement(&penum->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2019-11-12 10:00:11 +01:00
|
|
|
IPropertyStorage_Release(&penum->storage->IPropertyStorage_iface);
|
2019-11-11 08:39:23 +01:00
|
|
|
heap_free(penum->stats);
|
|
|
|
heap_free(penum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_prop_stg_Next(IEnumSTATPROPSTG *iface, ULONG celt, STATPROPSTG *ret, ULONG *fetched)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *penum = impl_from_IEnumSTATPROPSTG(iface);
|
|
|
|
ULONG count = 0;
|
2019-11-12 10:00:11 +01:00
|
|
|
WCHAR *name;
|
2019-11-11 08:39:23 +01:00
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %p.\n", iface, celt, ret, fetched);
|
|
|
|
|
|
|
|
if (penum->current == ~0u)
|
|
|
|
penum->current = 0;
|
|
|
|
|
|
|
|
while (count < celt && penum->current < penum->count)
|
2019-11-12 10:00:11 +01:00
|
|
|
{
|
|
|
|
*ret = penum->stats[penum->current++];
|
|
|
|
|
|
|
|
if (dictionary_find(penum->storage->propid_to_name, UlongToPtr(ret->propid), (void **)&name))
|
|
|
|
{
|
|
|
|
SIZE_T size = (lstrlenW(name) + 1) * sizeof(WCHAR);
|
|
|
|
ret->lpwstrName = CoTaskMemAlloc(size);
|
|
|
|
if (ret->lpwstrName)
|
|
|
|
memcpy(ret->lpwstrName, name, size);
|
|
|
|
}
|
|
|
|
ret++;
|
|
|
|
count++;
|
|
|
|
}
|
2019-11-11 08:39:23 +01:00
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
*fetched = count;
|
|
|
|
|
|
|
|
return count < celt ? S_FALSE : S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_prop_stg_Skip(IEnumSTATPROPSTG *iface, ULONG celt)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, celt);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_prop_stg_Reset(IEnumSTATPROPSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *penum = impl_from_IEnumSTATPROPSTG(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
penum->current = ~0u;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_prop_stg_Clone(IEnumSTATPROPSTG *iface, IEnumSTATPROPSTG **ppenum)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, ppenum);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumSTATPROPSTGVtbl enum_stat_prop_stg_vtbl =
|
|
|
|
{
|
|
|
|
enum_stat_prop_stg_QueryInterface,
|
|
|
|
enum_stat_prop_stg_AddRef,
|
|
|
|
enum_stat_prop_stg_Release,
|
|
|
|
enum_stat_prop_stg_Next,
|
|
|
|
enum_stat_prop_stg_Skip,
|
|
|
|
enum_stat_prop_stg_Reset,
|
|
|
|
enum_stat_prop_stg_Clone,
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL prop_enum_stat(const void *k, const void *v, void *extra, void *arg)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *stg = arg;
|
|
|
|
PROPID propid = PtrToUlong(k);
|
|
|
|
const PROPVARIANT *prop = v;
|
|
|
|
STATPROPSTG *dest;
|
|
|
|
|
|
|
|
dest = &stg->stats[stg->count];
|
|
|
|
|
|
|
|
dest->lpwstrName = NULL;
|
|
|
|
dest->propid = propid;
|
|
|
|
dest->vt = prop->vt;
|
|
|
|
stg->count++;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL prop_enum_stat_count(const void *k, const void *v, void *extra, void *arg)
|
|
|
|
{
|
|
|
|
DWORD *count = arg;
|
|
|
|
|
|
|
|
*count += 1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT create_enum_stat_prop_stg(PropertyStorage_impl *storage, IEnumSTATPROPSTG **ret)
|
|
|
|
{
|
|
|
|
struct enum_stat_prop_stg *enum_obj;
|
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
enum_obj = heap_alloc_zero(sizeof(*enum_obj));
|
|
|
|
if (!enum_obj)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
enum_obj->IEnumSTATPROPSTG_iface.lpVtbl = &enum_stat_prop_stg_vtbl;
|
|
|
|
enum_obj->refcount = 1;
|
2019-11-12 10:00:11 +01:00
|
|
|
enum_obj->storage = storage;
|
|
|
|
IPropertyStorage_AddRef(&storage->IPropertyStorage_iface);
|
2019-11-11 08:39:23 +01:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
dictionary_enumerate(storage->propid_to_prop, prop_enum_stat_count, &count);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
if (!(enum_obj->stats = heap_alloc(sizeof(*enum_obj->stats) * count)))
|
|
|
|
{
|
|
|
|
IEnumSTATPROPSTG_Release(&enum_obj->IEnumSTATPROPSTG_iface);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
dictionary_enumerate(storage->propid_to_prop, prop_enum_stat, enum_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = &enum_obj->IEnumSTATPROPSTG_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:58:09 +01:00
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnQueryInterface (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnQueryInterface(
|
|
|
|
IPropertyStorage *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2010-03-17 16:21:52 +01:00
|
|
|
TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppvObject);
|
|
|
|
|
|
|
|
if (!ppvObject)
|
2005-02-21 21:58:09 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppvObject = 0;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&IID_IUnknown, riid) ||
|
|
|
|
IsEqualGUID(&IID_IPropertyStorage, riid))
|
|
|
|
{
|
|
|
|
IPropertyStorage_AddRef(iface);
|
2008-01-14 23:02:11 +01:00
|
|
|
*ppvObject = iface;
|
2005-02-21 21:58:09 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnAddRef (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IPropertyStorage_fnAddRef(
|
|
|
|
IPropertyStorage *iface)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-02-21 21:58:09 +01:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnRelease (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IPropertyStorage_fnRelease(
|
|
|
|
IPropertyStorage *iface)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-02-21 21:58:09 +01:00
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
TRACE("Destroying %p\n", This);
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->dirty)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-02-21 21:58:09 +01:00
|
|
|
IStream_Release(This->stm);
|
2007-03-11 00:21:23 +01:00
|
|
|
This->cs.DebugInfo->Spare[0] = 0;
|
2005-03-17 21:50:35 +01:00
|
|
|
DeleteCriticalSection(&This->cs);
|
2005-04-11 20:50:45 +02:00
|
|
|
PropertyStorage_DestroyDictionaries(This);
|
2005-02-21 21:58:09 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
static PROPVARIANT *PropertyStorage_FindProperty(PropertyStorage_impl *This,
|
|
|
|
DWORD propid)
|
|
|
|
{
|
|
|
|
PROPVARIANT *ret = NULL;
|
|
|
|
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_find(This->propid_to_prop, UlongToPtr(propid), (void **)&ret);
|
2005-04-11 16:30:24 +02:00
|
|
|
TRACE("returning %p\n", ret);
|
2005-03-17 21:50:35 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
/* Returns NULL if name is NULL. */
|
2005-03-17 21:50:35 +01:00
|
|
|
static PROPVARIANT *PropertyStorage_FindPropertyByName(
|
|
|
|
PropertyStorage_impl *This, LPCWSTR name)
|
|
|
|
{
|
|
|
|
PROPVARIANT *ret = NULL;
|
2009-12-30 21:24:43 +01:00
|
|
|
void *propid;
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
if (!name)
|
2005-03-17 21:50:35 +01:00
|
|
|
return NULL;
|
2005-05-16 10:43:35 +02:00
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
{
|
2009-12-30 21:24:43 +01:00
|
|
|
if (dictionary_find(This->name_to_propid, name, &propid))
|
|
|
|
ret = PropertyStorage_FindProperty(This, PtrToUlong(propid));
|
2005-05-16 10:43:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPSTR ansiName;
|
2005-05-16 23:37:54 +02:00
|
|
|
HRESULT hr = PropertyStorage_StringCopy((LPCSTR)name, CP_UNICODE,
|
|
|
|
&ansiName, This->codePage);
|
2005-05-16 10:43:35 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2009-12-30 21:24:43 +01:00
|
|
|
if (dictionary_find(This->name_to_propid, ansiName, &propid))
|
|
|
|
ret = PropertyStorage_FindProperty(This, PtrToUlong(propid));
|
2005-05-16 10:43:35 +02:00
|
|
|
CoTaskMemFree(ansiName);
|
|
|
|
}
|
|
|
|
}
|
2005-04-11 16:30:24 +02:00
|
|
|
TRACE("returning %p\n", ret);
|
2005-03-17 21:50:35 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR PropertyStorage_FindPropertyNameById(PropertyStorage_impl *This,
|
|
|
|
DWORD propid)
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_find(This->propid_to_name, UlongToPtr(propid), (void **)&ret);
|
2005-04-11 16:30:24 +02:00
|
|
|
TRACE("returning %p\n", ret);
|
2005-03-17 21:50:35 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:58:09 +01:00
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnReadMultiple (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnReadMultiple(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpspec,
|
|
|
|
const PROPSPEC rgpspec[],
|
|
|
|
PROPVARIANT rgpropvar[])
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2006-07-11 18:39:30 +02:00
|
|
|
HRESULT hr = S_OK;
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %p)\n", iface, cpspec, rgpspec, rgpropvar);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2006-07-12 11:24:10 +02:00
|
|
|
if (!cpspec)
|
|
|
|
return S_FALSE;
|
|
|
|
if (!rgpspec || !rgpropvar)
|
2005-03-17 21:50:35 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
for (i = 0; i < cpspec; i++)
|
|
|
|
{
|
|
|
|
PropVariantInit(&rgpropvar[i]);
|
|
|
|
if (rgpspec[i].ulKind == PRSPEC_LPWSTR)
|
|
|
|
{
|
|
|
|
PROPVARIANT *prop = PropertyStorage_FindPropertyByName(This,
|
|
|
|
rgpspec[i].u.lpwstr);
|
|
|
|
|
|
|
|
if (prop)
|
2005-04-23 21:04:49 +02:00
|
|
|
PropertyStorage_PropVariantCopy(&rgpropvar[i], prop, GetACP(),
|
|
|
|
This->codePage);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-23 21:04:49 +02:00
|
|
|
switch (rgpspec[i].u.propid)
|
|
|
|
{
|
|
|
|
case PID_CODEPAGE:
|
|
|
|
rgpropvar[i].vt = VT_I2;
|
2021-03-23 00:30:54 +01:00
|
|
|
rgpropvar[i].iVal = This->codePage;
|
2005-04-23 21:04:49 +02:00
|
|
|
break;
|
|
|
|
case PID_LOCALE:
|
|
|
|
rgpropvar[i].vt = VT_I4;
|
2021-03-23 00:30:54 +01:00
|
|
|
rgpropvar[i].lVal = This->locale;
|
2005-04-23 21:04:49 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
PROPVARIANT *prop = PropertyStorage_FindProperty(This,
|
|
|
|
rgpspec[i].u.propid);
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2005-04-23 21:04:49 +02:00
|
|
|
if (prop)
|
|
|
|
PropertyStorage_PropVariantCopy(&rgpropvar[i], prop,
|
|
|
|
GetACP(), This->codePage);
|
2006-07-11 18:39:30 +02:00
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
2005-04-23 21:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-13 11:06:53 +01:00
|
|
|
static HRESULT PropertyStorage_StringCopy(LPCSTR src, UINT srcCP, LPSTR *dst, UINT dstCP)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
int len;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%s, %p, %d, %d\n",
|
2005-04-23 21:04:49 +02:00
|
|
|
srcCP == CP_UNICODE ? debugstr_w((LPCWSTR)src) : debugstr_a(src), dst,
|
2005-05-16 23:37:54 +02:00
|
|
|
dstCP, srcCP);
|
2005-04-23 21:04:49 +02:00
|
|
|
assert(src);
|
|
|
|
assert(dst);
|
|
|
|
*dst = NULL;
|
2005-05-16 23:37:54 +02:00
|
|
|
if (dstCP == srcCP)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
2005-05-16 23:37:54 +02:00
|
|
|
if (dstCP == CP_UNICODE)
|
2019-06-17 09:36:46 +02:00
|
|
|
len = (lstrlenW((LPCWSTR)src) + 1) * sizeof(WCHAR);
|
2005-04-23 21:04:49 +02:00
|
|
|
else
|
|
|
|
len = strlen(src) + 1;
|
2020-01-27 07:24:20 +01:00
|
|
|
*dst = CoTaskMemAlloc(len);
|
2005-04-23 21:04:49 +02:00
|
|
|
if (!*dst)
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
else
|
|
|
|
memcpy(*dst, src, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-16 23:37:54 +02:00
|
|
|
if (dstCP == CP_UNICODE)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(srcCP, 0, src, -1, NULL, 0);
|
|
|
|
*dst = CoTaskMemAlloc(len * sizeof(WCHAR));
|
|
|
|
if (!*dst)
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
else
|
|
|
|
MultiByteToWideChar(srcCP, 0, src, -1, (LPWSTR)*dst, len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-07 00:26:38 +01:00
|
|
|
LPCWSTR wideStr = NULL;
|
|
|
|
LPWSTR wideStr_tmp = NULL;
|
2005-04-23 21:04:49 +02:00
|
|
|
|
|
|
|
if (srcCP == CP_UNICODE)
|
2006-11-07 00:26:38 +01:00
|
|
|
wideStr = (LPCWSTR)src;
|
2005-04-23 21:04:49 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(srcCP, 0, src, -1, NULL, 0);
|
2006-11-07 00:26:38 +01:00
|
|
|
wideStr_tmp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
if (wideStr_tmp)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(srcCP, 0, src, -1, wideStr_tmp, len);
|
|
|
|
wideStr = wideStr_tmp;
|
|
|
|
}
|
2005-04-23 21:04:49 +02:00
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2005-05-16 23:37:54 +02:00
|
|
|
len = WideCharToMultiByte(dstCP, 0, wideStr, -1, NULL, 0,
|
2005-04-23 21:04:49 +02:00
|
|
|
NULL, NULL);
|
|
|
|
*dst = CoTaskMemAlloc(len);
|
|
|
|
if (!*dst)
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOL defCharUsed = FALSE;
|
|
|
|
|
2005-05-16 23:37:54 +02:00
|
|
|
if (WideCharToMultiByte(dstCP, 0, wideStr, -1, *dst, len,
|
|
|
|
NULL, &defCharUsed) == 0 || defCharUsed)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
|
|
|
CoTaskMemFree(*dst);
|
|
|
|
*dst = NULL;
|
|
|
|
hr = HRESULT_FROM_WIN32(ERROR_NO_UNICODE_TRANSLATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-07 00:26:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, wideStr_tmp);
|
2005-04-23 21:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x (%s)\n", hr,
|
2005-05-16 23:37:54 +02:00
|
|
|
dstCP == CP_UNICODE ? debugstr_w((LPCWSTR)*dst) : debugstr_a(*dst));
|
2005-04-23 21:04:49 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-13 11:06:53 +01:00
|
|
|
static HRESULT PropertyStorage_PropVariantCopy(PROPVARIANT *prop, const PROPVARIANT *propvar,
|
|
|
|
UINT targetCP, UINT srcCP)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
assert(prop);
|
|
|
|
assert(propvar);
|
2020-01-27 07:24:16 +01:00
|
|
|
|
|
|
|
switch (propvar->vt)
|
2005-04-23 21:04:49 +02:00
|
|
|
{
|
2020-01-27 07:24:16 +01:00
|
|
|
case VT_LPSTR:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = PropertyStorage_StringCopy(propvar->pszVal, srcCP, &prop->pszVal, targetCP);
|
2005-04-23 21:04:49 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
prop->vt = VT_LPSTR;
|
2020-01-27 07:24:16 +01:00
|
|
|
break;
|
|
|
|
case VT_BSTR:
|
2021-03-23 00:30:54 +01:00
|
|
|
if ((prop->bstrVal = SysAllocStringLen(propvar->bstrVal, SysStringLen(propvar->bstrVal))))
|
2020-01-27 07:24:16 +01:00
|
|
|
prop->vt = VT_BSTR;
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hr = PropVariantCopy(prop, propvar);
|
2005-04-23 21:04:49 +02:00
|
|
|
}
|
2020-01-27 07:24:16 +01:00
|
|
|
|
2005-04-23 21:04:49 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stores the property with id propid and value propvar into this property
|
|
|
|
* storage. lcid is ignored if propvar's type is not VT_LPSTR. If propvar's
|
|
|
|
* type is VT_LPSTR, converts the string using lcid as the source code page
|
|
|
|
* and This->codePage as the target code page before storing.
|
2005-05-16 19:52:36 +02:00
|
|
|
* As a side effect, may change This->format to 1 if the type of propvar is
|
|
|
|
* a version 1-only property.
|
2005-04-23 21:04:49 +02:00
|
|
|
*/
|
2005-03-17 21:50:35 +01:00
|
|
|
static HRESULT PropertyStorage_StorePropWithId(PropertyStorage_impl *This,
|
2019-12-13 11:06:53 +01:00
|
|
|
PROPID propid, const PROPVARIANT *propvar, UINT cp)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
PROPVARIANT *prop = PropertyStorage_FindProperty(This, propid);
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
assert(propvar);
|
2005-05-16 19:52:36 +02:00
|
|
|
if (propvar->vt & VT_BYREF || propvar->vt & VT_ARRAY)
|
|
|
|
This->format = 1;
|
|
|
|
switch (propvar->vt)
|
|
|
|
{
|
|
|
|
case VT_DECIMAL:
|
|
|
|
case VT_I1:
|
|
|
|
case VT_INT:
|
|
|
|
case VT_UINT:
|
|
|
|
case VT_VECTOR|VT_I1:
|
|
|
|
This->format = 1;
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Setting 0x%08x to type %d\n", propid, propvar->vt);
|
2005-03-17 21:50:35 +01:00
|
|
|
if (prop)
|
|
|
|
{
|
|
|
|
PropVariantClear(prop);
|
2019-12-13 11:06:53 +01:00
|
|
|
hr = PropertyStorage_PropVariantCopy(prop, propvar, This->codePage, cp);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(PROPVARIANT));
|
|
|
|
if (prop)
|
|
|
|
{
|
2019-12-13 11:06:53 +01:00
|
|
|
hr = PropertyStorage_PropVariantCopy(prop, propvar, This->codePage, cp);
|
2005-04-23 21:04:49 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_insert(This->propid_to_prop, UlongToPtr(propid), prop);
|
2005-04-23 21:04:49 +02:00
|
|
|
if (propid > This->highestProp)
|
|
|
|
This->highestProp = propid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
HeapFree(GetProcessHeap(), 0, prop);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
2005-05-14 13:06:44 +02:00
|
|
|
/* Adds the name srcName to the name dictionaries, mapped to property ID id.
|
2005-05-16 19:52:36 +02:00
|
|
|
* srcName is encoded in code page cp, and is converted to This->codePage.
|
|
|
|
* If cp is CP_UNICODE, srcName is actually a unicode string.
|
|
|
|
* As a side effect, may change This->format to 1 if srcName is too long for
|
|
|
|
* a version 0 property storage.
|
2005-05-14 13:06:44 +02:00
|
|
|
* Doesn't validate id.
|
|
|
|
*/
|
2005-05-16 19:52:36 +02:00
|
|
|
static HRESULT PropertyStorage_StoreNameWithId(PropertyStorage_impl *This,
|
2019-12-13 11:06:53 +01:00
|
|
|
LPCSTR srcName, UINT cp, PROPID id)
|
2005-05-14 13:06:44 +02:00
|
|
|
{
|
2005-05-16 10:43:35 +02:00
|
|
|
LPSTR name;
|
2005-05-14 13:06:44 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(srcName);
|
|
|
|
|
2008-01-14 23:02:11 +01:00
|
|
|
hr = PropertyStorage_StringCopy(srcName, cp, &name, This->codePage);
|
2005-05-16 10:43:35 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2005-05-14 13:06:44 +02:00
|
|
|
{
|
2005-05-16 19:52:36 +02:00
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
{
|
|
|
|
if (lstrlenW((LPWSTR)name) >= MAX_VERSION_0_PROP_NAME_LENGTH)
|
|
|
|
This->format = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strlen(name) >= MAX_VERSION_0_PROP_NAME_LENGTH)
|
|
|
|
This->format = 1;
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Adding prop name %s, propid %d\n",
|
2005-05-16 10:43:35 +02:00
|
|
|
This->codePage == CP_UNICODE ? debugstr_w((LPCWSTR)name) :
|
|
|
|
debugstr_a(name), id);
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_insert(This->name_to_propid, name, UlongToPtr(id));
|
|
|
|
dictionary_insert(This->propid_to_name, UlongToPtr(id), name);
|
2005-05-14 13:06:44 +02:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:58:09 +01:00
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnWriteMultiple (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnWriteMultiple(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpspec,
|
|
|
|
const PROPSPEC rgpspec[],
|
|
|
|
const PROPVARIANT rgpropvar[],
|
|
|
|
PROPID propidNameFirst)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
ULONG i;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %p)\n", iface, cpspec, rgpspec, rgpropvar);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
if (cpspec && (!rgpspec || !rgpropvar))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
This->dirty = TRUE;
|
|
|
|
This->originatorOS = (DWORD)MAKELONG(LOWORD(GetVersion()),
|
|
|
|
PROPSETHDR_OSVER_KIND_WIN32) ;
|
|
|
|
for (i = 0; i < cpspec; i++)
|
|
|
|
{
|
|
|
|
if (rgpspec[i].ulKind == PRSPEC_LPWSTR)
|
|
|
|
{
|
|
|
|
PROPVARIANT *prop = PropertyStorage_FindPropertyByName(This,
|
|
|
|
rgpspec[i].u.lpwstr);
|
|
|
|
|
|
|
|
if (prop)
|
|
|
|
PropVariantCopy(prop, &rgpropvar[i]);
|
|
|
|
else
|
|
|
|
{
|
2005-04-11 16:30:24 +02:00
|
|
|
/* Note that I don't do the special cases here that I do below,
|
|
|
|
* because naming the special PIDs isn't supported.
|
|
|
|
*/
|
2005-03-17 21:50:35 +01:00
|
|
|
if (propidNameFirst < PID_FIRST_USABLE ||
|
|
|
|
propidNameFirst >= PID_MIN_READONLY)
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PROPID nextId = max(propidNameFirst, This->highestProp + 1);
|
|
|
|
|
2005-05-16 19:52:36 +02:00
|
|
|
hr = PropertyStorage_StoreNameWithId(This,
|
|
|
|
(LPCSTR)rgpspec[i].u.lpwstr, CP_UNICODE, nextId);
|
2005-05-14 13:06:44 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2005-05-09 11:26:43 +02:00
|
|
|
hr = PropertyStorage_StorePropWithId(This, nextId,
|
|
|
|
&rgpropvar[i], GetACP());
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-11 16:30:24 +02:00
|
|
|
switch (rgpspec[i].u.propid)
|
|
|
|
{
|
|
|
|
case PID_DICTIONARY:
|
|
|
|
/* Can't set the dictionary */
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
break;
|
|
|
|
case PID_CODEPAGE:
|
|
|
|
/* Can only set the code page if nothing else has been set */
|
|
|
|
if (dictionary_num_entries(This->propid_to_prop) == 0 &&
|
|
|
|
rgpropvar[i].vt == VT_I2)
|
2005-05-14 13:06:44 +02:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
This->codePage = rgpropvar[i].iVal;
|
2005-05-14 13:06:44 +02:00
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
This->grfFlags &= ~PROPSETFLAG_ANSI;
|
|
|
|
else
|
|
|
|
This->grfFlags |= PROPSETFLAG_ANSI;
|
|
|
|
}
|
2005-04-11 16:30:24 +02:00
|
|
|
else
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
break;
|
|
|
|
case PID_LOCALE:
|
|
|
|
/* Can only set the locale if nothing else has been set */
|
|
|
|
if (dictionary_num_entries(This->propid_to_prop) == 0 &&
|
|
|
|
rgpropvar[i].vt == VT_I4)
|
2021-03-23 00:30:54 +01:00
|
|
|
This->locale = rgpropvar[i].lVal;
|
2005-04-11 16:30:24 +02:00
|
|
|
else
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
break;
|
|
|
|
case PID_ILLEGAL:
|
|
|
|
/* silently ignore like MSDN says */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (rgpspec[i].u.propid >= PID_MIN_READONLY)
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
else
|
|
|
|
hr = PropertyStorage_StorePropWithId(This,
|
2005-04-23 21:04:49 +02:00
|
|
|
rgpspec[i].u.propid, &rgpropvar[i], GetACP());
|
2005-04-11 16:30:24 +02:00
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->grfFlags & PROPSETFLAG_UNBUFFERED)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-03-17 21:50:35 +01:00
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnDeleteMultiple (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnDeleteMultiple(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpspec,
|
|
|
|
const PROPSPEC rgpspec[])
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p)\n", iface, cpspec, rgpspec);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-04-11 16:30:24 +02:00
|
|
|
if (cpspec && !rgpspec)
|
2005-03-17 21:50:35 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
hr = S_OK;
|
|
|
|
EnterCriticalSection(&This->cs);
|
2005-04-11 20:50:45 +02:00
|
|
|
This->dirty = TRUE;
|
2005-03-17 21:50:35 +01:00
|
|
|
for (i = 0; i < cpspec; i++)
|
|
|
|
{
|
|
|
|
if (rgpspec[i].ulKind == PRSPEC_LPWSTR)
|
|
|
|
{
|
2009-12-30 21:24:43 +01:00
|
|
|
void *propid;
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2009-12-30 21:24:43 +01:00
|
|
|
if (dictionary_find(This->name_to_propid, rgpspec[i].u.lpwstr, &propid))
|
|
|
|
dictionary_remove(This->propid_to_prop, propid);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-11 16:30:24 +02:00
|
|
|
if (rgpspec[i].u.propid >= PID_FIRST_USABLE &&
|
|
|
|
rgpspec[i].u.propid < PID_MIN_READONLY)
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_remove(This->propid_to_prop, UlongToPtr(rgpspec[i].u.propid));
|
2005-04-11 16:30:24 +02:00
|
|
|
else
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->grfFlags & PROPSETFLAG_UNBUFFERED)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-03-17 21:50:35 +01:00
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnReadPropertyNames (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnReadPropertyNames(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpropid,
|
|
|
|
const PROPID rgpropid[],
|
|
|
|
LPOLESTR rglpwstrName[])
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
2005-04-11 16:30:24 +02:00
|
|
|
HRESULT hr = S_FALSE;
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %p)\n", iface, cpropid, rgpropid, rglpwstrName);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
if (cpropid && (!rgpropid || !rglpwstrName))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
for (i = 0; i < cpropid && SUCCEEDED(hr); i++)
|
|
|
|
{
|
|
|
|
LPWSTR name = PropertyStorage_FindPropertyNameById(This, rgpropid[i]);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
size_t len = lstrlenW(name);
|
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
rglpwstrName[i] = CoTaskMemAlloc((len + 1) * sizeof(WCHAR));
|
2011-06-26 16:43:02 +02:00
|
|
|
if (rglpwstrName[i])
|
|
|
|
memcpy(rglpwstrName[i], name, (len + 1) * sizeof(WCHAR));
|
2005-03-17 21:50:35 +01:00
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rglpwstrName[i] = NULL;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnWritePropertyNames (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnWritePropertyNames(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpropid,
|
|
|
|
const PROPID rgpropid[],
|
|
|
|
const LPOLESTR rglpwstrName[])
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p, %p)\n", iface, cpropid, rgpropid, rglpwstrName);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
if (cpropid && (!rgpropid || !rglpwstrName))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
hr = S_OK;
|
|
|
|
EnterCriticalSection(&This->cs);
|
2005-04-11 20:50:45 +02:00
|
|
|
This->dirty = TRUE;
|
2005-04-23 21:04:49 +02:00
|
|
|
for (i = 0; SUCCEEDED(hr) && i < cpropid; i++)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
if (rgpropid[i] != PID_ILLEGAL)
|
2005-05-16 19:52:36 +02:00
|
|
|
hr = PropertyStorage_StoreNameWithId(This, (LPCSTR)rglpwstrName[i],
|
|
|
|
CP_UNICODE, rgpropid[i]);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->grfFlags & PROPSETFLAG_UNBUFFERED)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-03-17 21:50:35 +01:00
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnDeletePropertyNames (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnDeletePropertyNames(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
ULONG cpropid,
|
|
|
|
const PROPID rgpropid[])
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, %d, %p)\n", iface, cpropid, rgpropid);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
if (cpropid && !rgpropid)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
hr = S_OK;
|
|
|
|
EnterCriticalSection(&This->cs);
|
2005-04-11 20:50:45 +02:00
|
|
|
This->dirty = TRUE;
|
2005-03-17 21:50:35 +01:00
|
|
|
for (i = 0; i < cpropid; i++)
|
|
|
|
{
|
|
|
|
LPWSTR name = NULL;
|
|
|
|
|
2009-12-30 21:24:43 +01:00
|
|
|
if (dictionary_find(This->propid_to_name, UlongToPtr(rgpropid[i]), (void **)&name))
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2009-12-30 21:24:43 +01:00
|
|
|
dictionary_remove(This->propid_to_name, UlongToPtr(rgpropid[i]));
|
2005-03-17 21:50:35 +01:00
|
|
|
dictionary_remove(This->name_to_propid, name);
|
|
|
|
}
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->grfFlags & PROPSETFLAG_UNBUFFERED)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-03-17 21:50:35 +01:00
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnCommit (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnCommit(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
DWORD grfCommitFlags)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("(%p, 0x%08x)\n", iface, grfCommitFlags);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
if (This->dirty)
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = PropertyStorage_WriteToStream(This);
|
2005-03-17 21:50:35 +01:00
|
|
|
else
|
|
|
|
hr = S_OK;
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnRevert (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnRevert(
|
|
|
|
IPropertyStorage* iface)
|
|
|
|
{
|
2005-03-17 21:50:35 +01:00
|
|
|
HRESULT hr;
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->cs);
|
|
|
|
if (This->dirty)
|
2005-04-11 20:50:45 +02:00
|
|
|
{
|
|
|
|
PropertyStorage_DestroyDictionaries(This);
|
|
|
|
hr = PropertyStorage_CreateDictionaries(This);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = PropertyStorage_ReadFromStream(This);
|
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
else
|
|
|
|
hr = S_OK;
|
|
|
|
LeaveCriticalSection(&This->cs);
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnEnum (IPropertyStorage)
|
|
|
|
*/
|
2019-11-11 08:39:23 +01:00
|
|
|
static HRESULT WINAPI IPropertyStorage_fnEnum(IPropertyStorage *iface, IEnumSTATPROPSTG **ppenum)
|
2005-02-21 21:58:09 +01:00
|
|
|
{
|
2019-11-11 08:39:23 +01:00
|
|
|
PropertyStorage_impl *storage = impl_from_IPropertyStorage(iface);
|
|
|
|
|
|
|
|
TRACE("%p, %p.\n", iface, ppenum);
|
|
|
|
|
|
|
|
return create_enum_stat_prop_stg(storage, ppenum);
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnSetTimes (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnSetTimes(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
const FILETIME* pctime,
|
|
|
|
const FILETIME* patime,
|
|
|
|
const FILETIME* pmtime)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnSetClass (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnSetClass(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
REFCLSID clsid)
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
|
|
|
|
TRACE("%p, %s\n", iface, debugstr_guid(clsid));
|
2006-07-12 06:03:22 +02:00
|
|
|
|
|
|
|
if (!clsid)
|
2005-03-17 21:50:35 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
if (!(This->grfMode & STGM_READWRITE))
|
|
|
|
return STG_E_ACCESSDENIED;
|
2008-03-13 21:52:00 +01:00
|
|
|
This->clsid = *clsid;
|
2005-03-17 21:50:35 +01:00
|
|
|
This->dirty = TRUE;
|
2005-04-11 20:50:45 +02:00
|
|
|
if (This->grfFlags & PROPSETFLAG_UNBUFFERED)
|
|
|
|
IPropertyStorage_Commit(iface, STGC_DEFAULT);
|
2005-03-17 21:50:35 +01:00
|
|
|
return S_OK;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertyStorage_fnStat (IPropertyStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertyStorage_fnStat(
|
|
|
|
IPropertyStorage* iface,
|
|
|
|
STATPROPSETSTG* statpsstg)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
PropertyStorage_impl *This = impl_from_IPropertyStorage(iface);
|
2005-03-17 21:50:35 +01:00
|
|
|
STATSTG stat;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p, %p\n", iface, statpsstg);
|
2006-07-12 06:03:22 +02:00
|
|
|
|
|
|
|
if (!statpsstg)
|
2005-03-17 21:50:35 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = IStream_Stat(This->stm, &stat, STATFLAG_NONAME);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2008-03-10 22:58:43 +01:00
|
|
|
statpsstg->fmtid = This->fmtid;
|
|
|
|
statpsstg->clsid = This->clsid;
|
2005-03-17 21:50:35 +01:00
|
|
|
statpsstg->grfFlags = This->grfFlags;
|
2008-03-10 22:58:43 +01:00
|
|
|
statpsstg->mtime = stat.mtime;
|
|
|
|
statpsstg->ctime = stat.ctime;
|
|
|
|
statpsstg->atime = stat.atime;
|
2005-03-17 21:50:35 +01:00
|
|
|
statpsstg->dwOSVersion = This->originatorOS;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int PropertyStorage_PropNameCompare(const void *a, const void *b,
|
|
|
|
void *extra)
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
PropertyStorage_impl *This = extra;
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2005-05-16 10:43:35 +02:00
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
{
|
|
|
|
TRACE("(%s, %s)\n", debugstr_w(a), debugstr_w(b));
|
|
|
|
if (This->grfFlags & PROPSETFLAG_CASE_SENSITIVE)
|
2019-06-17 09:36:46 +02:00
|
|
|
return wcscmp(a, b);
|
2005-05-16 10:43:35 +02:00
|
|
|
else
|
2009-02-11 10:48:38 +01:00
|
|
|
return lstrcmpiW(a, b);
|
2005-05-16 10:43:35 +02:00
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
else
|
2005-05-16 10:43:35 +02:00
|
|
|
{
|
|
|
|
TRACE("(%s, %s)\n", debugstr_a(a), debugstr_a(b));
|
|
|
|
if (This->grfFlags & PROPSETFLAG_CASE_SENSITIVE)
|
2009-02-11 10:48:38 +01:00
|
|
|
return lstrcmpA(a, b);
|
2005-05-16 10:43:35 +02:00
|
|
|
else
|
2009-02-11 10:48:38 +01:00
|
|
|
return lstrcmpiA(a, b);
|
2005-05-16 10:43:35 +02:00
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyStorage_PropNameDestroy(void *k, void *d, void *extra)
|
|
|
|
{
|
2005-05-14 13:06:44 +02:00
|
|
|
CoTaskMemFree(k);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int PropertyStorage_PropCompare(const void *a, const void *b,
|
|
|
|
void *extra)
|
|
|
|
{
|
2019-11-19 10:26:13 +01:00
|
|
|
TRACE("(%u, %u)\n", PtrToUlong(a), PtrToUlong(b));
|
2009-12-30 21:24:43 +01:00
|
|
|
return PtrToUlong(a) - PtrToUlong(b);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyStorage_PropertyDestroy(void *k, void *d, void *extra)
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
PropVariantClear(d);
|
2005-03-17 21:50:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, d);
|
|
|
|
}
|
|
|
|
|
2005-05-14 13:06:44 +02:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
/* Swaps each character in str to or from little endian; assumes the conversion
|
2009-04-23 18:17:49 +02:00
|
|
|
* is symmetric, that is, that lendian16toh is equivalent to htole16.
|
2005-05-14 13:06:44 +02:00
|
|
|
*/
|
|
|
|
static void PropertyStorage_ByteSwapString(LPWSTR str, size_t len)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
/* Swap characters to host order.
|
|
|
|
* FIXME: alignment?
|
|
|
|
*/
|
|
|
|
for (i = 0; i < len; i++)
|
2009-09-01 05:22:13 +02:00
|
|
|
str[i] = lendian16toh(str[i]);
|
2005-05-14 13:06:44 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define PropertyStorage_ByteSwapString(s, l)
|
|
|
|
#endif
|
|
|
|
|
2015-03-12 06:20:14 +01:00
|
|
|
static void* WINAPI Allocate_CoTaskMemAlloc(void *this, ULONG size)
|
2012-08-28 00:01:24 +02:00
|
|
|
{
|
|
|
|
return CoTaskMemAlloc(size);
|
|
|
|
}
|
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
struct read_buffer
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2020-01-27 07:24:17 +01:00
|
|
|
BYTE *data;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT buffer_test_offset(const struct read_buffer *buffer, size_t offset, size_t len)
|
|
|
|
{
|
|
|
|
return len > buffer->size || offset > buffer->size - len ? STG_E_READFAULT : S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT buffer_read_uint64(const struct read_buffer *buffer, size_t offset, ULARGE_INTEGER *data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, sizeof(*data))))
|
|
|
|
StorageUtl_ReadULargeInteger(buffer->data, offset, data);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT buffer_read_dword(const struct read_buffer *buffer, size_t offset, DWORD *data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, sizeof(*data))))
|
|
|
|
StorageUtl_ReadDWord(buffer->data, offset, data);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT buffer_read_word(const struct read_buffer *buffer, size_t offset, WORD *data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, sizeof(*data))))
|
|
|
|
StorageUtl_ReadWord(buffer->data, offset, data);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT buffer_read_byte(const struct read_buffer *buffer, size_t offset, BYTE *data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, sizeof(*data))))
|
|
|
|
*data = *(buffer->data + offset);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT buffer_read_len(const struct read_buffer *buffer, size_t offset, void *dest, size_t len)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, len)))
|
|
|
|
memcpy(dest, buffer->data + offset, len);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-01-27 07:24:18 +01:00
|
|
|
static HRESULT propertystorage_read_scalar(PROPVARIANT *prop, const struct read_buffer *buffer, size_t offset,
|
|
|
|
UINT codepage, void* (WINAPI *allocate)(void *this, ULONG size), void *allocate_data)
|
2020-01-27 07:24:17 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2020-01-27 07:24:18 +01:00
|
|
|
assert(!(prop->vt & (VT_ARRAY | VT_VECTOR)));
|
2020-01-27 07:24:17 +01:00
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
switch (prop->vt)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2005-04-11 20:50:45 +02:00
|
|
|
case VT_EMPTY:
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_NULL:
|
2020-01-27 07:24:18 +01:00
|
|
|
hr = S_OK;
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
case VT_I1:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_byte(buffer, offset, (BYTE *)&prop->cVal);
|
|
|
|
TRACE("Read char 0x%x ('%c')\n", prop->cVal, prop->cVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
case VT_UI1:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_byte(buffer, offset, &prop->bVal);
|
|
|
|
TRACE("Read byte 0x%x\n", prop->bVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
2018-07-17 04:18:15 +02:00
|
|
|
case VT_BOOL:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_word(buffer, offset, (WORD *)&prop->boolVal);
|
|
|
|
TRACE("Read bool %d\n", prop->boolVal);
|
2018-07-17 04:18:15 +02:00
|
|
|
break;
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_I2:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_word(buffer, offset, (WORD *)&prop->iVal);
|
|
|
|
TRACE("Read short %d\n", prop->iVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
case VT_UI2:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_word(buffer, offset, &prop->uiVal);
|
|
|
|
TRACE("Read ushort %d\n", prop->uiVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
2005-05-16 19:52:36 +02:00
|
|
|
case VT_INT:
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_I4:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_dword(buffer, offset, (DWORD *)&prop->lVal);
|
|
|
|
TRACE("Read long %d\n", prop->lVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
2005-05-16 19:52:36 +02:00
|
|
|
case VT_UINT:
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_UI4:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_dword(buffer, offset, &prop->ulVal);
|
|
|
|
TRACE("Read ulong %d\n", prop->ulVal);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
2018-07-17 04:18:15 +02:00
|
|
|
case VT_I8:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_uint64(buffer, offset, (ULARGE_INTEGER *)&prop->hVal);
|
|
|
|
TRACE("Read long long %s\n", wine_dbgstr_longlong(prop->hVal.QuadPart));
|
2018-07-17 04:18:15 +02:00
|
|
|
break;
|
|
|
|
case VT_UI8:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_uint64(buffer, offset, &prop->uhVal);
|
|
|
|
TRACE("Read ulong long %s\n", wine_dbgstr_longlong(prop->uhVal.QuadPart));
|
2018-07-17 04:18:15 +02:00
|
|
|
break;
|
|
|
|
case VT_R8:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_len(buffer, offset, &prop->dblVal, sizeof(prop->dblVal));
|
|
|
|
TRACE("Read double %f\n", prop->dblVal);
|
2018-07-17 04:18:15 +02:00
|
|
|
break;
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_LPSTR:
|
|
|
|
{
|
2005-04-11 20:50:45 +02:00
|
|
|
DWORD count;
|
2020-01-27 07:24:17 +01:00
|
|
|
|
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &count)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
|
|
|
if (codepage == CP_UNICODE && count % sizeof(WCHAR))
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2005-05-16 19:52:36 +02:00
|
|
|
WARN("Unicode string has odd number of bytes\n");
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
2005-05-16 19:52:36 +02:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pszVal = allocate(allocate_data, count);
|
|
|
|
if (prop->pszVal)
|
2005-05-16 19:52:36 +02:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
if (FAILED(hr = buffer_read_len(buffer, offset, prop->pszVal, count)))
|
2020-01-27 07:24:17 +01:00
|
|
|
break;
|
|
|
|
|
2012-08-28 00:01:24 +02:00
|
|
|
/* This is stored in the code page specified in codepage.
|
2005-05-16 19:52:36 +02:00
|
|
|
* Don't convert it, the caller will just store it as-is.
|
|
|
|
*/
|
2012-08-28 00:01:24 +02:00
|
|
|
if (codepage == CP_UNICODE)
|
2005-05-16 19:52:36 +02:00
|
|
|
{
|
|
|
|
/* Make sure it's NULL-terminated */
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pszVal[count / sizeof(WCHAR) - 1] = '\0';
|
2005-05-16 19:52:36 +02:00
|
|
|
TRACE("Read string value %s\n",
|
2021-03-23 00:30:54 +01:00
|
|
|
debugstr_w(prop->pwszVal));
|
2005-05-16 19:52:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make sure it's NULL-terminated */
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pszVal[count - 1] = '\0';
|
|
|
|
TRACE("Read string value %s\n", debugstr_a(prop->pszVal));
|
2005-05-16 19:52:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-08-28 00:28:23 +02:00
|
|
|
case VT_BSTR:
|
|
|
|
{
|
|
|
|
DWORD count, wcount;
|
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &count)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
|
|
|
if (codepage == CP_UNICODE && count % sizeof(WCHAR))
|
2012-08-28 00:28:23 +02:00
|
|
|
{
|
|
|
|
WARN("Unicode string has odd number of bytes\n");
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (codepage == CP_UNICODE)
|
2020-01-27 07:24:17 +01:00
|
|
|
wcount = count / sizeof(WCHAR);
|
2012-08-28 00:28:23 +02:00
|
|
|
else
|
2020-01-27 07:24:17 +01:00
|
|
|
{
|
|
|
|
if (FAILED(hr = buffer_test_offset(buffer, offset, count)))
|
|
|
|
break;
|
|
|
|
wcount = MultiByteToWideChar(codepage, 0, (LPCSTR)(buffer->data + offset), count, NULL, 0);
|
|
|
|
}
|
2012-08-28 00:28:23 +02:00
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->bstrVal = SysAllocStringLen(NULL, wcount); /* FIXME: use allocator? */
|
2012-08-28 00:28:23 +02:00
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
if (prop->bstrVal)
|
2012-08-28 00:28:23 +02:00
|
|
|
{
|
|
|
|
if (codepage == CP_UNICODE)
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_len(buffer, offset, prop->bstrVal, count);
|
2012-08-28 00:28:23 +02:00
|
|
|
else
|
2021-03-23 00:30:54 +01:00
|
|
|
MultiByteToWideChar(codepage, 0, (LPCSTR)(buffer->data + offset), count, prop->bstrVal, wcount);
|
2012-08-28 00:28:23 +02:00
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->bstrVal[wcount - 1] = '\0';
|
|
|
|
TRACE("Read string value %s\n", debugstr_w(prop->bstrVal));
|
2012-08-28 00:28:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-12-04 23:52:44 +01:00
|
|
|
case VT_BLOB:
|
|
|
|
{
|
|
|
|
DWORD count;
|
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &count)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->blob.cbSize = count;
|
|
|
|
prop->blob.pBlobData = allocate(allocate_data, count);
|
|
|
|
if (prop->blob.pBlobData)
|
2011-12-04 23:52:44 +01:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_len(buffer, offset, prop->blob.pBlobData, count);
|
2011-12-04 23:52:44 +01:00
|
|
|
TRACE("Read blob value of size %d\n", count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
case VT_LPWSTR:
|
|
|
|
{
|
2005-04-11 20:50:45 +02:00
|
|
|
DWORD count;
|
2005-03-17 21:50:35 +01:00
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &count)))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pwszVal = allocate(allocate_data, count * sizeof(WCHAR));
|
|
|
|
if (prop->pwszVal)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
if (SUCCEEDED(hr = buffer_read_len(buffer, offset, prop->pwszVal, count * sizeof(WCHAR))))
|
2020-01-27 07:24:17 +01:00
|
|
|
{
|
|
|
|
/* make sure string is NULL-terminated */
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pwszVal[count - 1] = '\0';
|
|
|
|
PropertyStorage_ByteSwapString(prop->pwszVal, count);
|
|
|
|
TRACE("Read string value %s\n", debugstr_w(prop->pwszVal));
|
2020-01-27 07:24:17 +01:00
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VT_FILETIME:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = buffer_read_uint64(buffer, offset, (ULARGE_INTEGER *)&prop->filetime);
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
2006-06-19 20:31:01 +02:00
|
|
|
case VT_CF:
|
|
|
|
{
|
2006-07-12 11:23:30 +02:00
|
|
|
DWORD len = 0, tag = 0;
|
2006-06-19 20:31:01 +02:00
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
if (SUCCEEDED(hr = buffer_read_dword(buffer, offset, &len)))
|
|
|
|
hr = buffer_read_dword(buffer, offset + sizeof(DWORD), &tag);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += 2 * sizeof(DWORD);
|
|
|
|
|
2006-07-12 11:23:30 +02:00
|
|
|
if (len > 8)
|
2006-06-19 20:31:01 +02:00
|
|
|
{
|
2006-07-12 11:23:30 +02:00
|
|
|
len -= 8;
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->pclipdata = allocate(allocate_data, sizeof (CLIPDATA));
|
|
|
|
prop->pclipdata->cbSize = len;
|
|
|
|
prop->pclipdata->ulClipFmt = tag;
|
|
|
|
prop->pclipdata->pClipData = allocate(allocate_data, len - sizeof(prop->pclipdata->ulClipFmt));
|
|
|
|
hr = buffer_read_len(buffer, offset, prop->pclipdata->pClipData, len - sizeof(prop->pclipdata->ulClipFmt));
|
2006-06-19 20:31:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
2020-03-23 07:24:11 +01:00
|
|
|
break;
|
|
|
|
case VT_CLSID:
|
2021-03-23 00:30:54 +01:00
|
|
|
if (!(prop->puuid = allocate(allocate_data, sizeof (*prop->puuid))))
|
2020-03-23 07:24:11 +01:00
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
if (SUCCEEDED(hr = buffer_test_offset(buffer, offset, sizeof(*prop->puuid))))
|
|
|
|
StorageUtl_ReadGUID(buffer->data, offset, prop->puuid);
|
2020-03-23 07:24:11 +01:00
|
|
|
|
2006-06-19 20:31:01 +02:00
|
|
|
break;
|
2005-03-17 21:50:35 +01:00
|
|
|
default:
|
2005-04-11 20:50:45 +02:00
|
|
|
FIXME("unsupported type %d\n", prop->vt);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
2020-01-27 07:24:18 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t propertystorage_get_elemsize(const PROPVARIANT *prop)
|
|
|
|
{
|
|
|
|
if (!(prop->vt & VT_VECTOR))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (prop->vt & ~VT_VECTOR)
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
case VT_I1: return sizeof(*prop->cac.pElems);
|
|
|
|
case VT_UI1: return sizeof(*prop->caub.pElems);
|
|
|
|
case VT_I2: return sizeof(*prop->cai.pElems);
|
|
|
|
case VT_UI2: return sizeof(*prop->caui.pElems);
|
|
|
|
case VT_BOOL: return sizeof(*prop->cabool.pElems);
|
|
|
|
case VT_I4: return sizeof(*prop->cal.pElems);
|
|
|
|
case VT_UI4: return sizeof(*prop->caul.pElems);
|
|
|
|
case VT_R4: return sizeof(*prop->caflt.pElems);
|
|
|
|
case VT_ERROR: return sizeof(*prop->cascode.pElems);
|
|
|
|
case VT_I8: return sizeof(*prop->cah.pElems);
|
|
|
|
case VT_UI8: return sizeof(*prop->cauh.pElems);
|
|
|
|
case VT_R8: return sizeof(*prop->cadbl.pElems);
|
|
|
|
case VT_CY: return sizeof(*prop->cacy.pElems);
|
|
|
|
case VT_DATE: return sizeof(*prop->cadate.pElems);
|
|
|
|
case VT_FILETIME: return sizeof(*prop->cafiletime.pElems);
|
|
|
|
case VT_CLSID: return sizeof(*prop->cauuid.pElems);
|
|
|
|
case VT_VARIANT: return sizeof(*prop->capropvar.pElems);
|
2020-01-27 07:24:18 +01:00
|
|
|
default:
|
|
|
|
FIXME("Unhandled type %#x.\n", prop->vt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_ReadProperty(PROPVARIANT *prop, const struct read_buffer *buffer,
|
|
|
|
size_t offset, UINT codepage, void* (WINAPI *allocate)(void *this, ULONG size), void *allocate_data)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD vt;
|
|
|
|
|
|
|
|
assert(prop);
|
|
|
|
assert(buffer->data);
|
|
|
|
|
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &vt)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
prop->vt = vt;
|
|
|
|
|
|
|
|
if (prop->vt & VT_VECTOR)
|
|
|
|
{
|
|
|
|
DWORD count, i;
|
|
|
|
|
|
|
|
switch (prop->vt & VT_VECTOR)
|
|
|
|
{
|
|
|
|
case VT_BSTR:
|
|
|
|
case VT_VARIANT:
|
|
|
|
case VT_LPSTR:
|
|
|
|
case VT_LPWSTR:
|
|
|
|
case VT_CF:
|
|
|
|
FIXME("Vector with variable length elements are not supported.\n");
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_read_dword(buffer, offset, &count)))
|
|
|
|
{
|
|
|
|
size_t elemsize = propertystorage_get_elemsize(prop);
|
|
|
|
PROPVARIANT elem;
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
if ((prop->capropvar.pElems = allocate(allocate_data, elemsize * count)))
|
2020-01-27 07:24:18 +01:00
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
prop->capropvar.cElems = count;
|
2020-01-27 07:24:18 +01:00
|
|
|
elem.vt = prop->vt & ~VT_VECTOR;
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr = propertystorage_read_scalar(&elem, buffer, offset + i * elemsize, codepage,
|
|
|
|
allocate, allocate_data)))
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
memcpy(&prop->capropvar.pElems[i], &elem.lVal, elemsize);
|
2020-01-27 07:24:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (prop->vt & VT_ARRAY)
|
|
|
|
{
|
|
|
|
FIXME("VT_ARRAY properties are not supported.\n");
|
|
|
|
hr = STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = propertystorage_read_scalar(prop, buffer, offset, codepage, allocate, allocate_data);
|
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_ReadHeaderFromStream(IStream *stm,
|
|
|
|
PROPERTYSETHEADER *hdr)
|
|
|
|
{
|
|
|
|
BYTE buf[sizeof(PROPERTYSETHEADER)];
|
|
|
|
ULONG count = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2005-04-11 16:30:24 +02:00
|
|
|
assert(stm);
|
|
|
|
assert(hdr);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = IStream_Read(stm, buf, sizeof(buf), &count);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (count != sizeof(buf))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("read only %d\n", count);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StorageUtl_ReadWord(buf, offsetof(PROPERTYSETHEADER, wByteOrder),
|
|
|
|
&hdr->wByteOrder);
|
|
|
|
StorageUtl_ReadWord(buf, offsetof(PROPERTYSETHEADER, wFormat),
|
|
|
|
&hdr->wFormat);
|
|
|
|
StorageUtl_ReadDWord(buf, offsetof(PROPERTYSETHEADER, dwOSVer),
|
|
|
|
&hdr->dwOSVer);
|
|
|
|
StorageUtl_ReadGUID(buf, offsetof(PROPERTYSETHEADER, clsid),
|
|
|
|
&hdr->clsid);
|
|
|
|
StorageUtl_ReadDWord(buf, offsetof(PROPERTYSETHEADER, reserved),
|
|
|
|
&hdr->reserved);
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x\n", hr);
|
2005-03-17 21:50:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_ReadFmtIdOffsetFromStream(IStream *stm,
|
|
|
|
FORMATIDOFFSET *fmt)
|
|
|
|
{
|
|
|
|
BYTE buf[sizeof(FORMATIDOFFSET)];
|
|
|
|
ULONG count = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2005-04-11 16:30:24 +02:00
|
|
|
assert(stm);
|
|
|
|
assert(fmt);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = IStream_Read(stm, buf, sizeof(buf), &count);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (count != sizeof(buf))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("read only %d\n", count);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StorageUtl_ReadGUID(buf, offsetof(FORMATIDOFFSET, fmtid),
|
|
|
|
&fmt->fmtid);
|
|
|
|
StorageUtl_ReadDWord(buf, offsetof(FORMATIDOFFSET, dwOffset),
|
|
|
|
&fmt->dwOffset);
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x\n", hr);
|
2005-03-17 21:50:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_ReadSectionHeaderFromStream(IStream *stm,
|
|
|
|
PROPERTYSECTIONHEADER *hdr)
|
|
|
|
{
|
|
|
|
BYTE buf[sizeof(PROPERTYSECTIONHEADER)];
|
|
|
|
ULONG count = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2005-04-11 16:30:24 +02:00
|
|
|
assert(stm);
|
|
|
|
assert(hdr);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = IStream_Read(stm, buf, sizeof(buf), &count);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (count != sizeof(buf))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("read only %d\n", count);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StorageUtl_ReadDWord(buf, offsetof(PROPERTYSECTIONHEADER,
|
|
|
|
cbSection), &hdr->cbSection);
|
|
|
|
StorageUtl_ReadDWord(buf, offsetof(PROPERTYSECTIONHEADER,
|
|
|
|
cProperties), &hdr->cProperties);
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x\n", hr);
|
2005-03-17 21:50:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-01-27 07:24:19 +01:00
|
|
|
/* Reads the dictionary from the memory buffer beginning at ptr. Interprets
|
|
|
|
* the entries according to the values of This->codePage and This->locale.
|
|
|
|
*/
|
|
|
|
static HRESULT PropertyStorage_ReadDictionary(PropertyStorage_impl *This, const struct read_buffer *buffer,
|
|
|
|
size_t offset)
|
|
|
|
{
|
|
|
|
DWORD numEntries, i;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(This->name_to_propid);
|
|
|
|
assert(This->propid_to_name);
|
|
|
|
|
|
|
|
if (FAILED(hr = buffer_read_dword(buffer, offset, &numEntries)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
TRACE("Reading %d entries:\n", numEntries);
|
|
|
|
|
|
|
|
offset += sizeof(DWORD);
|
|
|
|
|
|
|
|
for (i = 0; SUCCEEDED(hr) && i < numEntries; i++)
|
|
|
|
{
|
|
|
|
PROPID propid;
|
|
|
|
DWORD cbEntry;
|
|
|
|
WCHAR ch = 0;
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = buffer_read_dword(buffer, offset, &propid)))
|
|
|
|
hr = buffer_read_dword(buffer, offset + sizeof(PROPID), &cbEntry);
|
|
|
|
if (FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
offset += sizeof(PROPID) + sizeof(DWORD);
|
|
|
|
|
|
|
|
if (FAILED(hr = buffer_test_offset(buffer, offset, This->codePage == CP_UNICODE ?
|
|
|
|
ALIGNED_LENGTH(cbEntry * sizeof(WCHAR), 3) : cbEntry)))
|
|
|
|
{
|
|
|
|
WARN("Broken name length for entry %d.\n", i);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the source string is NULL-terminated */
|
|
|
|
if (This->codePage != CP_UNICODE)
|
|
|
|
buffer_read_byte(buffer, offset + cbEntry - 1, (BYTE *)&ch);
|
|
|
|
else
|
|
|
|
buffer_read_word(buffer, offset + (cbEntry - 1) * sizeof(WCHAR), &ch);
|
|
|
|
|
|
|
|
if (ch)
|
|
|
|
{
|
|
|
|
WARN("Dictionary entry name %d is not null-terminated.\n", i);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Reading entry with ID %#x, %d chars, name %s.\n", propid, cbEntry, This->codePage == CP_UNICODE ?
|
|
|
|
debugstr_wn((WCHAR *)buffer->data, cbEntry) : debugstr_an((char *)buffer->data, cbEntry));
|
|
|
|
|
|
|
|
hr = PropertyStorage_StoreNameWithId(This, (char *)buffer->data + offset, This->codePage, propid);
|
|
|
|
/* Unicode entries are padded to DWORD boundaries */
|
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
cbEntry = ALIGNED_LENGTH(cbEntry * sizeof(WCHAR), 3);
|
|
|
|
|
|
|
|
offset += cbEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
static HRESULT PropertyStorage_ReadFromStream(PropertyStorage_impl *This)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2020-01-27 07:24:17 +01:00
|
|
|
struct read_buffer read_buffer;
|
2005-03-17 21:50:35 +01:00
|
|
|
PROPERTYSETHEADER hdr;
|
|
|
|
FORMATIDOFFSET fmtOffset;
|
|
|
|
PROPERTYSECTIONHEADER sectionHdr;
|
2005-04-11 20:50:45 +02:00
|
|
|
LARGE_INTEGER seek;
|
2005-03-17 21:50:35 +01:00
|
|
|
ULONG i;
|
|
|
|
STATSTG stat;
|
|
|
|
HRESULT hr;
|
|
|
|
BYTE *buf = NULL;
|
|
|
|
ULONG count = 0;
|
|
|
|
DWORD dictOffset = 0;
|
|
|
|
|
|
|
|
This->dirty = FALSE;
|
|
|
|
This->highestProp = 0;
|
|
|
|
hr = IStream_Stat(This->stm, &stat, STATFLAG_NONAME);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
if (stat.cbSize.u.HighPart)
|
|
|
|
{
|
|
|
|
WARN("stream too big\n");
|
|
|
|
/* maximum size varies, but it can't be this big */
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (stat.cbSize.u.LowPart == 0)
|
|
|
|
{
|
2005-04-11 20:50:45 +02:00
|
|
|
/* empty stream is okay */
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = S_OK;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
else if (stat.cbSize.u.LowPart < sizeof(PROPERTYSETHEADER) +
|
|
|
|
sizeof(FORMATIDOFFSET))
|
|
|
|
{
|
|
|
|
WARN("stream too small\n");
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
seek.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = PropertyStorage_ReadHeaderFromStream(This->stm, &hdr);
|
|
|
|
/* I've only seen reserved == 1, but the article says I shouldn't disallow
|
|
|
|
* higher values.
|
|
|
|
*/
|
|
|
|
if (hdr.wByteOrder != PROPSETHDR_BYTEORDER_MAGIC || hdr.reserved < 1)
|
|
|
|
{
|
|
|
|
WARN("bad magic in prop set header\n");
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (hdr.wFormat != 0 && hdr.wFormat != 1)
|
|
|
|
{
|
|
|
|
WARN("bad format version %d\n", hdr.wFormat);
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-05-16 19:52:36 +02:00
|
|
|
This->format = hdr.wFormat;
|
2008-03-10 22:58:43 +01:00
|
|
|
This->clsid = hdr.clsid;
|
2005-03-17 21:50:35 +01:00
|
|
|
This->originatorOS = hdr.dwOSVer;
|
|
|
|
if (PROPSETHDR_OSVER_KIND(hdr.dwOSVer) == PROPSETHDR_OSVER_KIND_MAC)
|
|
|
|
WARN("File comes from a Mac, strings will probably be screwed up\n");
|
|
|
|
hr = PropertyStorage_ReadFmtIdOffsetFromStream(This->stm, &fmtOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
if (fmtOffset.dwOffset > stat.cbSize.u.LowPart)
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("invalid offset %d (stream length is %d)\n", fmtOffset.dwOffset,
|
2005-03-17 21:50:35 +01:00
|
|
|
stat.cbSize.u.LowPart);
|
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
/* wackiness alert: if the format ID is FMTID_DocSummaryInformation, there
|
2013-11-20 23:39:28 +01:00
|
|
|
* follows not one, but two sections. The first contains the standard properties
|
|
|
|
* for the document summary information, and the second consists of user-defined
|
2005-03-17 21:50:35 +01:00
|
|
|
* properties. This is the only case in which multiple sections are
|
|
|
|
* allowed.
|
|
|
|
* Reading the second stream isn't implemented yet.
|
|
|
|
*/
|
|
|
|
hr = PropertyStorage_ReadSectionHeaderFromStream(This->stm, §ionHdr);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
/* The section size includes the section header, so check it */
|
|
|
|
if (sectionHdr.cbSection < sizeof(PROPERTYSECTIONHEADER))
|
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
WARN("section header too small, got %d\n", sectionHdr.cbSection);
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDHEADER;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, sectionHdr.cbSection -
|
|
|
|
sizeof(PROPERTYSECTIONHEADER));
|
|
|
|
if (!buf)
|
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
2020-01-27 07:24:17 +01:00
|
|
|
read_buffer.data = buf;
|
|
|
|
read_buffer.size = sectionHdr.cbSection - sizeof(sectionHdr);
|
|
|
|
|
|
|
|
hr = IStream_Read(This->stm, read_buffer.data, read_buffer.size, &count);
|
2005-03-17 21:50:35 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Reading %d properties:\n", sectionHdr.cProperties);
|
2005-03-17 21:50:35 +01:00
|
|
|
for (i = 0; SUCCEEDED(hr) && i < sectionHdr.cProperties; i++)
|
|
|
|
{
|
2020-01-27 07:24:17 +01:00
|
|
|
PROPERTYIDOFFSET *idOffset = (PROPERTYIDOFFSET *)(read_buffer.data +
|
2005-03-17 21:50:35 +01:00
|
|
|
i * sizeof(PROPERTYIDOFFSET));
|
|
|
|
|
|
|
|
if (idOffset->dwOffset < sizeof(PROPERTYSECTIONHEADER) ||
|
2010-11-20 20:43:01 +01:00
|
|
|
idOffset->dwOffset > sectionHdr.cbSection - sizeof(DWORD))
|
2005-03-17 21:50:35 +01:00
|
|
|
hr = STG_E_INVALIDPOINTER;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (idOffset->propid >= PID_FIRST_USABLE &&
|
|
|
|
idOffset->propid < PID_MIN_READONLY && idOffset->propid >
|
|
|
|
This->highestProp)
|
|
|
|
This->highestProp = idOffset->propid;
|
2005-04-11 16:30:24 +02:00
|
|
|
if (idOffset->propid == PID_DICTIONARY)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
/* Don't read the dictionary yet, its entries depend on the
|
|
|
|
* code page. Just store the offset so we know to read it
|
|
|
|
* later.
|
|
|
|
*/
|
|
|
|
dictOffset = idOffset->dwOffset;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Dictionary offset is %d\n", dictOffset);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PROPVARIANT prop;
|
|
|
|
|
2006-08-14 14:02:09 +02:00
|
|
|
PropVariantInit(&prop);
|
2020-01-27 07:24:17 +01:00
|
|
|
if (SUCCEEDED(PropertyStorage_ReadProperty(&prop, &read_buffer,
|
|
|
|
idOffset->dwOffset - sizeof(PROPERTYSECTIONHEADER), This->codePage,
|
|
|
|
Allocate_CoTaskMemAlloc, NULL)))
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Read property with ID 0x%08x, type %d\n",
|
2005-04-11 20:50:45 +02:00
|
|
|
idOffset->propid, prop.vt);
|
2005-03-17 21:50:35 +01:00
|
|
|
switch(idOffset->propid)
|
|
|
|
{
|
|
|
|
case PID_CODEPAGE:
|
|
|
|
if (prop.vt == VT_I2)
|
2021-03-23 00:30:54 +01:00
|
|
|
This->codePage = (UINT)prop.iVal;
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
case PID_LOCALE:
|
|
|
|
if (prop.vt == VT_I4)
|
2021-03-23 00:30:54 +01:00
|
|
|
This->locale = (LCID)prop.lVal;
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
case PID_BEHAVIOR:
|
2021-03-23 00:30:54 +01:00
|
|
|
if (prop.vt == VT_I4 && prop.lVal)
|
2005-03-17 21:50:35 +01:00
|
|
|
This->grfFlags |= PROPSETFLAG_CASE_SENSITIVE;
|
2005-05-16 19:52:36 +02:00
|
|
|
/* The format should already be 1, but just in case */
|
|
|
|
This->format = 1;
|
2005-03-17 21:50:35 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hr = PropertyStorage_StorePropWithId(This,
|
2005-04-23 21:04:49 +02:00
|
|
|
idOffset->propid, &prop, This->codePage);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 19:46:41 +01:00
|
|
|
PropVariantClear(&prop);
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!This->codePage)
|
|
|
|
{
|
2008-03-01 05:36:46 +01:00
|
|
|
/* default to Unicode unless told not to, as specified on msdn */
|
2005-03-17 21:50:35 +01:00
|
|
|
if (This->grfFlags & PROPSETFLAG_ANSI)
|
|
|
|
This->codePage = GetACP();
|
|
|
|
else
|
2005-04-11 16:30:24 +02:00
|
|
|
This->codePage = CP_UNICODE;
|
2005-03-17 21:50:35 +01:00
|
|
|
}
|
|
|
|
if (!This->locale)
|
|
|
|
This->locale = LOCALE_SYSTEM_DEFAULT;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Code page is %d, locale is %d\n", This->codePage, This->locale);
|
2005-03-17 21:50:35 +01:00
|
|
|
if (dictOffset)
|
2020-01-27 07:24:19 +01:00
|
|
|
hr = PropertyStorage_ReadDictionary(This, &read_buffer, dictOffset - sizeof(PROPERTYSECTIONHEADER));
|
2005-03-17 21:50:35 +01:00
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
2005-04-11 16:30:24 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
dictionary_destroy(This->name_to_propid);
|
|
|
|
This->name_to_propid = NULL;
|
|
|
|
dictionary_destroy(This->propid_to_name);
|
|
|
|
This->propid_to_name = NULL;
|
|
|
|
dictionary_destroy(This->propid_to_prop);
|
|
|
|
This->propid_to_prop = NULL;
|
|
|
|
}
|
2005-03-17 21:50:35 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
static void PropertyStorage_MakeHeader(PropertyStorage_impl *This,
|
|
|
|
PROPERTYSETHEADER *hdr)
|
2005-02-21 21:58:09 +01:00
|
|
|
{
|
2005-04-11 20:50:45 +02:00
|
|
|
assert(hdr);
|
2019-12-12 11:43:21 +01:00
|
|
|
StorageUtl_WriteWord(&hdr->wByteOrder, 0, PROPSETHDR_BYTEORDER_MAGIC);
|
|
|
|
StorageUtl_WriteWord(&hdr->wFormat, 0, This->format);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&hdr->dwOSVer, 0, This->originatorOS);
|
2019-12-12 11:43:22 +01:00
|
|
|
StorageUtl_WriteGUID(&hdr->clsid, 0, &This->clsid);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&hdr->reserved, 0, 1);
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyStorage_MakeFmtIdOffset(PropertyStorage_impl *This,
|
|
|
|
FORMATIDOFFSET *fmtOffset)
|
|
|
|
{
|
|
|
|
assert(fmtOffset);
|
2019-12-12 11:43:22 +01:00
|
|
|
StorageUtl_WriteGUID(fmtOffset, 0, &This->fmtid);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(fmtOffset, offsetof(FORMATIDOFFSET, dwOffset),
|
2005-04-11 20:50:45 +02:00
|
|
|
sizeof(PROPERTYSETHEADER) + sizeof(FORMATIDOFFSET));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyStorage_MakeSectionHdr(DWORD cbSection, DWORD numProps,
|
|
|
|
PROPERTYSECTIONHEADER *hdr)
|
|
|
|
{
|
|
|
|
assert(hdr);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(hdr, 0, cbSection);
|
|
|
|
StorageUtl_WriteDWord(hdr, offsetof(PROPERTYSECTIONHEADER, cProperties), numProps);
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyStorage_MakePropertyIdOffset(DWORD propid, DWORD dwOffset,
|
|
|
|
PROPERTYIDOFFSET *propIdOffset)
|
|
|
|
{
|
|
|
|
assert(propIdOffset);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(propIdOffset, 0, propid);
|
|
|
|
StorageUtl_WriteDWord(propIdOffset, offsetof(PROPERTYIDOFFSET, dwOffset), dwOffset);
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
|
2019-11-28 13:29:19 +01:00
|
|
|
static inline HRESULT PropertyStorage_WriteWStringToStream(IStream *stm,
|
2009-08-20 04:18:26 +02:00
|
|
|
LPCWSTR str, DWORD len, DWORD *written)
|
|
|
|
{
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
WCHAR *leStr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!leStr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(leStr, str, len * sizeof(WCHAR));
|
|
|
|
PropertyStorage_ByteSwapString(leStr, len);
|
|
|
|
hr = IStream_Write(stm, leStr, len, written);
|
|
|
|
HeapFree(GetProcessHeap(), 0, leStr);
|
|
|
|
return hr;
|
|
|
|
#else
|
2019-12-12 11:43:19 +01:00
|
|
|
return IStream_Write(stm, str, len * sizeof(WCHAR), written);
|
2009-08-20 04:18:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
struct DictionaryClosure
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD bytesWritten;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL PropertyStorage_DictionaryWriter(const void *key,
|
|
|
|
const void *value, void *extra, void *closure)
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
PropertyStorage_impl *This = extra;
|
|
|
|
struct DictionaryClosure *c = closure;
|
2019-12-12 11:43:19 +01:00
|
|
|
DWORD propid, keyLen;
|
2005-04-11 20:50:45 +02:00
|
|
|
ULONG count;
|
|
|
|
|
|
|
|
assert(key);
|
|
|
|
assert(closure);
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&propid, 0, PtrToUlong(value));
|
2005-04-11 20:50:45 +02:00
|
|
|
c->hr = IStream_Write(This->stm, &propid, sizeof(propid), &count);
|
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
|
|
|
c->bytesWritten += sizeof(DWORD);
|
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
{
|
2019-12-12 11:43:19 +01:00
|
|
|
DWORD pad = 0, pad_len;
|
2005-04-11 20:50:45 +02:00
|
|
|
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&keyLen, 0, lstrlenW((LPCWSTR)key) + 1);
|
2005-04-11 20:50:45 +02:00
|
|
|
c->hr = IStream_Write(This->stm, &keyLen, sizeof(keyLen), &count);
|
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
|
|
|
c->bytesWritten += sizeof(DWORD);
|
2019-11-28 13:29:19 +01:00
|
|
|
c->hr = PropertyStorage_WriteWStringToStream(This->stm, key, keyLen,
|
2009-08-20 04:18:26 +02:00
|
|
|
&count);
|
2005-04-11 20:50:45 +02:00
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
2019-12-12 11:43:19 +01:00
|
|
|
keyLen *= sizeof(WCHAR);
|
|
|
|
c->bytesWritten += keyLen;
|
|
|
|
|
|
|
|
/* Align to 4 bytes. */
|
|
|
|
pad_len = sizeof(DWORD) - keyLen % sizeof(DWORD);
|
|
|
|
if (pad_len)
|
2005-04-11 20:50:45 +02:00
|
|
|
{
|
2019-12-12 11:43:19 +01:00
|
|
|
c->hr = IStream_Write(This->stm, &pad, pad_len, &count);
|
2005-04-11 20:50:45 +02:00
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
2019-12-12 11:43:19 +01:00
|
|
|
c->bytesWritten += pad_len;
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&keyLen, 0, strlen((LPCSTR)key) + 1);
|
2005-05-16 10:43:35 +02:00
|
|
|
c->hr = IStream_Write(This->stm, &keyLen, sizeof(keyLen), &count);
|
2005-04-11 20:50:45 +02:00
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
|
|
|
c->bytesWritten += sizeof(DWORD);
|
2005-05-16 10:43:35 +02:00
|
|
|
c->hr = IStream_Write(This->stm, key, keyLen, &count);
|
2005-04-11 20:50:45 +02:00
|
|
|
if (FAILED(c->hr))
|
|
|
|
goto end;
|
2005-05-16 10:43:35 +02:00
|
|
|
c->bytesWritten += keyLen;
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
end:
|
|
|
|
return SUCCEEDED(c->hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SECTIONHEADER_OFFSET sizeof(PROPERTYSETHEADER) + sizeof(FORMATIDOFFSET)
|
|
|
|
|
|
|
|
/* Writes the dictionary to the stream. Assumes without checking that the
|
|
|
|
* dictionary isn't empty.
|
|
|
|
*/
|
|
|
|
static HRESULT PropertyStorage_WriteDictionaryToStream(
|
|
|
|
PropertyStorage_impl *This, DWORD *sectionOffset)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
PROPERTYIDOFFSET propIdOffset;
|
|
|
|
ULONG count;
|
|
|
|
DWORD dwTemp;
|
|
|
|
struct DictionaryClosure closure;
|
|
|
|
|
|
|
|
assert(sectionOffset);
|
|
|
|
|
|
|
|
/* The dictionary's always the first property written, so seek to its
|
|
|
|
* spot.
|
|
|
|
*/
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET + sizeof(PROPERTYSECTIONHEADER);
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
PropertyStorage_MakePropertyIdOffset(PID_DICTIONARY, *sectionOffset,
|
|
|
|
&propIdOffset);
|
|
|
|
hr = IStream_Write(This->stm, &propIdOffset, sizeof(propIdOffset), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET + *sectionOffset;
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, dictionary_num_entries(This->name_to_propid));
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
*sectionOffset += sizeof(dwTemp);
|
|
|
|
|
|
|
|
closure.hr = S_OK;
|
|
|
|
closure.bytesWritten = 0;
|
|
|
|
dictionary_enumerate(This->name_to_propid, PropertyStorage_DictionaryWriter,
|
|
|
|
&closure);
|
|
|
|
hr = closure.hr;
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
*sectionOffset += closure.bytesWritten;
|
|
|
|
if (closure.bytesWritten % sizeof(DWORD))
|
|
|
|
{
|
2006-10-20 12:16:45 +02:00
|
|
|
DWORD padding = sizeof(DWORD) - closure.bytesWritten % sizeof(DWORD);
|
|
|
|
TRACE("adding %d bytes of padding\n", padding);
|
|
|
|
*sectionOffset += padding;
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_WritePropertyToStream(PropertyStorage_impl *This,
|
2007-07-04 21:12:48 +02:00
|
|
|
DWORD propNum, DWORD propid, const PROPVARIANT *var, DWORD *sectionOffset)
|
2005-04-11 20:50:45 +02:00
|
|
|
{
|
2020-01-27 07:24:16 +01:00
|
|
|
DWORD len, dwType, dwTemp, bytesWritten;
|
2005-04-11 20:50:45 +02:00
|
|
|
HRESULT hr;
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
PROPERTYIDOFFSET propIdOffset;
|
2020-11-12 22:07:05 +01:00
|
|
|
ULARGE_INTEGER ularge;
|
2005-04-11 20:50:45 +02:00
|
|
|
ULONG count;
|
|
|
|
|
|
|
|
assert(var);
|
|
|
|
assert(sectionOffset);
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%p, %d, 0x%08x, (%d), (%d)\n", This, propNum, propid, var->vt,
|
2005-04-11 20:50:45 +02:00
|
|
|
*sectionOffset);
|
|
|
|
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET + sizeof(PROPERTYSECTIONHEADER) +
|
|
|
|
propNum * sizeof(PROPERTYIDOFFSET);
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
PropertyStorage_MakePropertyIdOffset(propid, *sectionOffset, &propIdOffset);
|
|
|
|
hr = IStream_Write(This->stm, &propIdOffset, sizeof(propIdOffset), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET + *sectionOffset;
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&dwType, 0, var->vt);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwType, sizeof(dwType), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
*sectionOffset += sizeof(dwType);
|
|
|
|
|
|
|
|
switch (var->vt)
|
|
|
|
{
|
|
|
|
case VT_EMPTY:
|
|
|
|
case VT_NULL:
|
|
|
|
bytesWritten = 0;
|
|
|
|
break;
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1:
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = IStream_Write(This->stm, &var->cVal, sizeof(var->cVal),
|
2005-04-11 20:50:45 +02:00
|
|
|
&count);
|
|
|
|
bytesWritten = count;
|
|
|
|
break;
|
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2:
|
|
|
|
{
|
|
|
|
WORD wTemp;
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteWord(&wTemp, 0, var->iVal);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &wTemp, sizeof(wTemp), &count);
|
|
|
|
bytesWritten = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VT_I4:
|
|
|
|
case VT_UI4:
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, var->lVal);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
bytesWritten = count;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-12 22:07:05 +01:00
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteULargeInteger(&ularge, 0, &var->uhVal);
|
2020-11-12 22:07:05 +01:00
|
|
|
hr = IStream_Write(This->stm, &ularge, sizeof(ularge), &bytesWritten);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
case VT_LPSTR:
|
|
|
|
{
|
|
|
|
if (This->codePage == CP_UNICODE)
|
2021-03-23 00:30:54 +01:00
|
|
|
len = (lstrlenW(var->pwszVal) + 1) * sizeof(WCHAR);
|
2005-04-11 20:50:45 +02:00
|
|
|
else
|
2021-03-23 00:30:54 +01:00
|
|
|
len = lstrlenA(var->pszVal) + 1;
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, len);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = IStream_Write(This->stm, var->pszVal, len, &count);
|
2005-04-11 20:50:45 +02:00
|
|
|
bytesWritten = count + sizeof(DWORD);
|
|
|
|
break;
|
|
|
|
}
|
2020-01-27 07:24:16 +01:00
|
|
|
case VT_BSTR:
|
|
|
|
{
|
|
|
|
if (This->codePage == CP_UNICODE)
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
len = SysStringByteLen(var->bstrVal) + sizeof(WCHAR);
|
2020-01-27 07:24:16 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, len);
|
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (SUCCEEDED(hr))
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = IStream_Write(This->stm, var->bstrVal, len, &count);
|
2020-01-27 07:24:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
len = WideCharToMultiByte(This->codePage, 0, var->bstrVal, SysStringLen(var->bstrVal) + 1,
|
2020-01-27 07:24:16 +01:00
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
str = heap_alloc(len);
|
|
|
|
if (!str)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
WideCharToMultiByte(This->codePage, 0, var->bstrVal, SysStringLen(var->bstrVal),
|
2020-01-27 07:24:16 +01:00
|
|
|
str, len, NULL, NULL);
|
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, len);
|
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IStream_Write(This->stm, str, len, &count);
|
|
|
|
heap_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
bytesWritten = count + sizeof(DWORD);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
case VT_LPWSTR:
|
|
|
|
{
|
2021-03-23 00:30:54 +01:00
|
|
|
len = lstrlenW(var->pwszVal) + 1;
|
2005-04-11 20:50:45 +02:00
|
|
|
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, len);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = IStream_Write(This->stm, var->pwszVal, len * sizeof(WCHAR),
|
2005-04-11 20:50:45 +02:00
|
|
|
&count);
|
|
|
|
bytesWritten = count + sizeof(DWORD);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-14 13:06:44 +02:00
|
|
|
case VT_FILETIME:
|
|
|
|
{
|
|
|
|
FILETIME temp;
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteULargeInteger(&temp, 0, (const ULARGE_INTEGER *)&var->filetime);
|
2019-12-12 11:43:23 +01:00
|
|
|
hr = IStream_Write(This->stm, &temp, sizeof(temp), &count);
|
2005-05-14 13:06:44 +02:00
|
|
|
bytesWritten = count;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-12 11:23:30 +02:00
|
|
|
case VT_CF:
|
|
|
|
{
|
2020-01-27 07:24:16 +01:00
|
|
|
DWORD cf_hdr[2];
|
2006-07-12 11:23:30 +02:00
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
len = var->pclipdata->cbSize;
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&cf_hdr[0], 0, len + 8);
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteDWord(&cf_hdr[1], 0, var->pclipdata->ulClipFmt);
|
2008-07-11 11:41:44 +02:00
|
|
|
hr = IStream_Write(This->stm, cf_hdr, sizeof(cf_hdr), &count);
|
2006-07-12 11:23:30 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2021-03-23 00:30:54 +01:00
|
|
|
hr = IStream_Write(This->stm, var->pclipdata->pClipData,
|
|
|
|
len - sizeof(var->pclipdata->ulClipFmt), &count);
|
2006-07-12 11:23:30 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
bytesWritten = count + sizeof cf_hdr;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-13 18:02:15 +01:00
|
|
|
case VT_CLSID:
|
|
|
|
{
|
|
|
|
CLSID temp;
|
|
|
|
|
2021-03-23 00:30:54 +01:00
|
|
|
StorageUtl_WriteGUID(&temp, 0, var->puuid);
|
2011-11-13 18:02:15 +01:00
|
|
|
hr = IStream_Write(This->stm, &temp, sizeof(temp), &count);
|
|
|
|
bytesWritten = count;
|
|
|
|
break;
|
|
|
|
}
|
2021-04-05 08:06:00 +02:00
|
|
|
case VT_BLOB:
|
|
|
|
{
|
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, var->blob.cbSize);
|
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
hr = IStream_Write(This->stm, var->blob.pBlobData, var->blob.cbSize, &count);
|
|
|
|
bytesWritten = count + sizeof(DWORD);
|
|
|
|
break;
|
|
|
|
}
|
2005-04-11 20:50:45 +02:00
|
|
|
default:
|
|
|
|
FIXME("unsupported type: %d\n", var->vt);
|
|
|
|
return STG_E_INVALIDPARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*sectionOffset += bytesWritten;
|
|
|
|
if (bytesWritten % sizeof(DWORD))
|
|
|
|
{
|
2006-10-20 12:16:45 +02:00
|
|
|
DWORD padding = sizeof(DWORD) - bytesWritten % sizeof(DWORD);
|
|
|
|
TRACE("adding %d bytes of padding\n", padding);
|
|
|
|
*sectionOffset += padding;
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PropertyClosure
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD propNum;
|
|
|
|
DWORD *sectionOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
static BOOL PropertyStorage_PropertiesWriter(const void *key, const void *value,
|
|
|
|
void *extra, void *closure)
|
|
|
|
{
|
2009-02-11 10:48:38 +01:00
|
|
|
PropertyStorage_impl *This = extra;
|
|
|
|
struct PropertyClosure *c = closure;
|
2005-04-11 20:50:45 +02:00
|
|
|
|
|
|
|
assert(key);
|
|
|
|
assert(value);
|
|
|
|
assert(extra);
|
|
|
|
assert(closure);
|
2007-07-06 00:27:24 +02:00
|
|
|
c->hr = PropertyStorage_WritePropertyToStream(This, c->propNum++,
|
2009-12-30 21:24:43 +01:00
|
|
|
PtrToUlong(key), value, c->sectionOffset);
|
2005-04-11 20:50:45 +02:00
|
|
|
return SUCCEEDED(c->hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_WritePropertiesToStream(
|
|
|
|
PropertyStorage_impl *This, DWORD startingPropNum, DWORD *sectionOffset)
|
|
|
|
{
|
|
|
|
struct PropertyClosure closure;
|
|
|
|
|
|
|
|
assert(sectionOffset);
|
|
|
|
closure.hr = S_OK;
|
|
|
|
closure.propNum = startingPropNum;
|
|
|
|
closure.sectionOffset = sectionOffset;
|
|
|
|
dictionary_enumerate(This->propid_to_prop, PropertyStorage_PropertiesWriter,
|
|
|
|
&closure);
|
|
|
|
return closure.hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_WriteHeadersToStream(PropertyStorage_impl *This)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG count = 0;
|
|
|
|
LARGE_INTEGER seek = { {0} };
|
|
|
|
PROPERTYSETHEADER hdr;
|
|
|
|
FORMATIDOFFSET fmtOffset;
|
|
|
|
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
PropertyStorage_MakeHeader(This, &hdr);
|
|
|
|
hr = IStream_Write(This->stm, &hdr, sizeof(hdr), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
if (count != sizeof(hdr))
|
|
|
|
{
|
|
|
|
hr = STG_E_WRITEFAULT;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyStorage_MakeFmtIdOffset(This, &fmtOffset);
|
|
|
|
hr = IStream_Write(This->stm, &fmtOffset, sizeof(fmtOffset), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
if (count != sizeof(fmtOffset))
|
|
|
|
{
|
|
|
|
hr = STG_E_WRITEFAULT;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
end:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_WriteToStream(PropertyStorage_impl *This)
|
|
|
|
{
|
|
|
|
PROPERTYSECTIONHEADER sectionHdr;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG count;
|
|
|
|
LARGE_INTEGER seek;
|
|
|
|
DWORD numProps, prop, sectionOffset, dwTemp;
|
|
|
|
PROPVARIANT var;
|
|
|
|
|
|
|
|
PropertyStorage_WriteHeadersToStream(This);
|
|
|
|
|
|
|
|
/* Count properties. Always at least one property, the code page */
|
|
|
|
numProps = 1;
|
|
|
|
if (dictionary_num_entries(This->name_to_propid))
|
|
|
|
numProps++;
|
|
|
|
if (This->locale != LOCALE_SYSTEM_DEFAULT)
|
|
|
|
numProps++;
|
|
|
|
if (This->grfFlags & PROPSETFLAG_CASE_SENSITIVE)
|
|
|
|
numProps++;
|
|
|
|
numProps += dictionary_num_entries(This->propid_to_prop);
|
|
|
|
|
|
|
|
/* Write section header with 0 bytes right now, I'll adjust it after
|
|
|
|
* writing properties.
|
|
|
|
*/
|
|
|
|
PropertyStorage_MakeSectionHdr(0, numProps, §ionHdr);
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET;
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
hr = IStream_Write(This->stm, §ionHdr, sizeof(sectionHdr), &count);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
prop = 0;
|
|
|
|
sectionOffset = sizeof(PROPERTYSECTIONHEADER) +
|
|
|
|
numProps * sizeof(PROPERTYIDOFFSET);
|
|
|
|
|
|
|
|
if (dictionary_num_entries(This->name_to_propid))
|
|
|
|
{
|
|
|
|
prop++;
|
|
|
|
hr = PropertyStorage_WriteDictionaryToStream(This, §ionOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropVariantInit(&var);
|
|
|
|
|
|
|
|
var.vt = VT_I2;
|
2021-03-23 00:30:54 +01:00
|
|
|
var.iVal = This->codePage;
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = PropertyStorage_WritePropertyToStream(This, prop++, PID_CODEPAGE,
|
|
|
|
&var, §ionOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (This->locale != LOCALE_SYSTEM_DEFAULT)
|
|
|
|
{
|
|
|
|
var.vt = VT_I4;
|
2021-03-23 00:30:54 +01:00
|
|
|
var.lVal = This->locale;
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = PropertyStorage_WritePropertyToStream(This, prop++, PID_LOCALE,
|
|
|
|
&var, §ionOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->grfFlags & PROPSETFLAG_CASE_SENSITIVE)
|
|
|
|
{
|
|
|
|
var.vt = VT_I4;
|
2021-03-23 00:30:54 +01:00
|
|
|
var.lVal = 1;
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = PropertyStorage_WritePropertyToStream(This, prop++, PID_BEHAVIOR,
|
|
|
|
&var, §ionOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = PropertyStorage_WritePropertiesToStream(This, prop, §ionOffset);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Now write the byte count of the section */
|
|
|
|
seek.QuadPart = SECTIONHEADER_OFFSET;
|
|
|
|
hr = IStream_Seek(This->stm, seek, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto end;
|
2019-12-12 11:43:20 +01:00
|
|
|
StorageUtl_WriteDWord(&dwTemp, 0, sectionOffset);
|
2005-04-11 20:50:45 +02:00
|
|
|
hr = IStream_Write(This->stm, &dwTemp, sizeof(dwTemp), &count);
|
|
|
|
|
|
|
|
end:
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2005-03-17 21:50:35 +01:00
|
|
|
* PropertyStorage_Construct
|
2005-02-21 21:58:09 +01:00
|
|
|
*/
|
2005-04-11 20:50:45 +02:00
|
|
|
static void PropertyStorage_DestroyDictionaries(PropertyStorage_impl *This)
|
|
|
|
{
|
|
|
|
dictionary_destroy(This->name_to_propid);
|
|
|
|
This->name_to_propid = NULL;
|
|
|
|
dictionary_destroy(This->propid_to_name);
|
|
|
|
This->propid_to_name = NULL;
|
|
|
|
dictionary_destroy(This->propid_to_prop);
|
|
|
|
This->propid_to_prop = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_CreateDictionaries(PropertyStorage_impl *This)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
This->name_to_propid = dictionary_create(
|
|
|
|
PropertyStorage_PropNameCompare, PropertyStorage_PropNameDestroy,
|
|
|
|
This);
|
|
|
|
if (!This->name_to_propid)
|
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
This->propid_to_name = dictionary_create(PropertyStorage_PropCompare,
|
|
|
|
NULL, This);
|
|
|
|
if (!This->propid_to_name)
|
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
This->propid_to_prop = dictionary_create(PropertyStorage_PropCompare,
|
|
|
|
PropertyStorage_PropertyDestroy, This);
|
|
|
|
if (!This->propid_to_prop)
|
|
|
|
{
|
|
|
|
hr = STG_E_INSUFFICIENTMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
if (FAILED(hr))
|
|
|
|
PropertyStorage_DestroyDictionaries(This);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_BaseConstruct(IStream *stm,
|
|
|
|
REFFMTID rfmtid, DWORD grfMode, PropertyStorage_impl **pps)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
assert(pps);
|
|
|
|
assert(rfmtid);
|
|
|
|
*pps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof **pps);
|
2005-05-09 11:26:43 +02:00
|
|
|
if (!*pps)
|
2005-04-11 20:50:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-08 13:15:12 +01:00
|
|
|
(*pps)->IPropertyStorage_iface.lpVtbl = &IPropertyStorage_Vtbl;
|
2005-04-11 20:50:45 +02:00
|
|
|
(*pps)->ref = 1;
|
|
|
|
InitializeCriticalSection(&(*pps)->cs);
|
2007-03-11 00:21:23 +01:00
|
|
|
(*pps)->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PropertyStorage_impl.cs");
|
2005-04-11 20:50:45 +02:00
|
|
|
(*pps)->stm = stm;
|
2008-03-10 22:58:43 +01:00
|
|
|
(*pps)->fmtid = *rfmtid;
|
2005-04-11 20:50:45 +02:00
|
|
|
(*pps)->grfMode = grfMode;
|
|
|
|
|
|
|
|
hr = PropertyStorage_CreateDictionaries(*pps);
|
2005-05-09 11:26:43 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2007-03-11 00:21:23 +01:00
|
|
|
(*pps)->cs.DebugInfo->Spare[0] = 0;
|
2005-05-09 11:26:43 +02:00
|
|
|
DeleteCriticalSection(&(*pps)->cs);
|
|
|
|
HeapFree(GetProcessHeap(), 0, *pps);
|
|
|
|
*pps = NULL;
|
|
|
|
}
|
2016-04-21 10:00:24 +02:00
|
|
|
else IStream_AddRef( stm );
|
2005-04-11 20:50:45 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT PropertyStorage_ConstructFromStream(IStream *stm,
|
|
|
|
REFFMTID rfmtid, DWORD grfMode, IPropertyStorage** pps)
|
2005-02-21 21:58:09 +01:00
|
|
|
{
|
|
|
|
PropertyStorage_impl *ps;
|
2005-03-17 21:50:35 +01:00
|
|
|
HRESULT hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
assert(pps);
|
|
|
|
hr = PropertyStorage_BaseConstruct(stm, rfmtid, grfMode, &ps);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = PropertyStorage_ReadFromStream(ps);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2010-12-08 13:15:12 +01:00
|
|
|
*pps = &ps->IPropertyStorage_iface;
|
2005-04-11 20:50:45 +02:00
|
|
|
TRACE("PropertyStorage %p constructed\n", ps);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
2016-04-21 10:00:24 +02:00
|
|
|
else IPropertyStorage_Release( &ps->IPropertyStorage_iface );
|
2005-04-11 20:50:45 +02:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
static HRESULT PropertyStorage_ConstructEmpty(IStream *stm,
|
|
|
|
REFFMTID rfmtid, DWORD grfFlags, DWORD grfMode, IPropertyStorage** pps)
|
|
|
|
{
|
|
|
|
PropertyStorage_impl *ps;
|
|
|
|
HRESULT hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
assert(pps);
|
|
|
|
hr = PropertyStorage_BaseConstruct(stm, rfmtid, grfMode, &ps);
|
2005-03-17 21:50:35 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2005-05-16 19:52:36 +02:00
|
|
|
ps->format = 0;
|
2005-04-11 20:50:45 +02:00
|
|
|
ps->grfFlags = grfFlags;
|
2005-05-16 19:52:36 +02:00
|
|
|
if (ps->grfFlags & PROPSETFLAG_CASE_SENSITIVE)
|
|
|
|
ps->format = 1;
|
2008-04-09 21:33:37 +02:00
|
|
|
/* default to Unicode unless told not to, as specified on msdn */
|
2005-04-11 20:50:45 +02:00
|
|
|
if (ps->grfFlags & PROPSETFLAG_ANSI)
|
|
|
|
ps->codePage = GetACP();
|
|
|
|
else
|
|
|
|
ps->codePage = CP_UNICODE;
|
|
|
|
ps->locale = LOCALE_SYSTEM_DEFAULT;
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("Code page is %d, locale is %d\n", ps->codePage, ps->locale);
|
2010-12-08 13:15:12 +01:00
|
|
|
*pps = &ps->IPropertyStorage_iface;
|
2005-03-17 21:50:35 +01:00
|
|
|
TRACE("PropertyStorage %p constructed\n", ps);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
return hr;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Implementation of IPropertySetStorage
|
|
|
|
*/
|
|
|
|
|
2019-11-08 14:33:52 +01:00
|
|
|
struct enum_stat_propset_stg
|
|
|
|
{
|
|
|
|
IEnumSTATPROPSETSTG IEnumSTATPROPSETSTG_iface;
|
|
|
|
LONG refcount;
|
|
|
|
STATPROPSETSTG *stats;
|
|
|
|
size_t current;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct enum_stat_propset_stg *impl_from_IEnumSTATPROPSETSTG(IEnumSTATPROPSETSTG *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct enum_stat_propset_stg, IEnumSTATPROPSETSTG_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_propset_stg_QueryInterface(IEnumSTATPROPSETSTG *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
TRACE("%p, %s, %p.\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IEnumSTATPROPSETSTG) ||
|
|
|
|
IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
*obj = iface;
|
|
|
|
IEnumSTATPROPSETSTG_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s.\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_stat_propset_stg_AddRef(IEnumSTATPROPSETSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_propset_stg *psenum = impl_from_IEnumSTATPROPSETSTG(iface);
|
|
|
|
LONG refcount = InterlockedIncrement(&psenum->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_stat_propset_stg_Release(IEnumSTATPROPSETSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_propset_stg *psenum = impl_from_IEnumSTATPROPSETSTG(iface);
|
|
|
|
LONG refcount = InterlockedDecrement(&psenum->refcount);
|
|
|
|
|
|
|
|
TRACE("%p, refcount %u.\n", iface, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
heap_free(psenum->stats);
|
|
|
|
heap_free(psenum);
|
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_propset_stg_Next(IEnumSTATPROPSETSTG *iface, ULONG celt,
|
|
|
|
STATPROPSETSTG *ret, ULONG *fetched)
|
|
|
|
{
|
|
|
|
struct enum_stat_propset_stg *psenum = impl_from_IEnumSTATPROPSETSTG(iface);
|
|
|
|
ULONG count = 0;
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %p.\n", iface, celt, ret, fetched);
|
|
|
|
|
|
|
|
if (psenum->current == ~0u)
|
|
|
|
psenum->current = 0;
|
|
|
|
|
|
|
|
while (count < celt && psenum->current < psenum->count)
|
|
|
|
ret[count++] = psenum->stats[psenum->current++];
|
|
|
|
|
|
|
|
if (fetched)
|
|
|
|
*fetched = count;
|
|
|
|
|
|
|
|
return count < celt ? S_FALSE : S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_propset_stg_Skip(IEnumSTATPROPSETSTG *iface, ULONG celt)
|
|
|
|
{
|
|
|
|
FIXME("%p, %u.\n", iface, celt);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_propset_stg_Reset(IEnumSTATPROPSETSTG *iface)
|
|
|
|
{
|
|
|
|
struct enum_stat_propset_stg *psenum = impl_from_IEnumSTATPROPSETSTG(iface);
|
|
|
|
|
|
|
|
TRACE("%p.\n", iface);
|
|
|
|
|
|
|
|
psenum->current = ~0u;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_stat_propset_stg_Clone(IEnumSTATPROPSETSTG *iface, IEnumSTATPROPSETSTG **ppenum)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p.\n", iface, ppenum);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumSTATPROPSETSTGVtbl enum_stat_propset_stg_vtbl =
|
|
|
|
{
|
|
|
|
enum_stat_propset_stg_QueryInterface,
|
|
|
|
enum_stat_propset_stg_AddRef,
|
|
|
|
enum_stat_propset_stg_Release,
|
|
|
|
enum_stat_propset_stg_Next,
|
|
|
|
enum_stat_propset_stg_Skip,
|
|
|
|
enum_stat_propset_stg_Reset,
|
|
|
|
enum_stat_propset_stg_Clone,
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT create_enum_stat_propset_stg(StorageImpl *storage, IEnumSTATPROPSETSTG **ret)
|
|
|
|
{
|
|
|
|
IStorage *stg = &storage->base.IStorage_iface;
|
|
|
|
IEnumSTATSTG *penum = NULL;
|
|
|
|
STATSTG stat;
|
|
|
|
ULONG count;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
struct enum_stat_propset_stg *enum_obj;
|
|
|
|
|
|
|
|
enum_obj = heap_alloc_zero(sizeof(*enum_obj));
|
|
|
|
if (!enum_obj)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
enum_obj->IEnumSTATPROPSETSTG_iface.lpVtbl = &enum_stat_propset_stg_vtbl;
|
|
|
|
enum_obj->refcount = 1;
|
|
|
|
|
|
|
|
/* add all the property set elements into a list */
|
|
|
|
hr = IStorage_EnumElements(stg, 0, NULL, 0, &penum);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Allocate stats array and fill it. */
|
|
|
|
while ((hr = IEnumSTATSTG_Next(penum, 1, &stat, &count)) == S_OK)
|
|
|
|
{
|
|
|
|
enum_obj->count++;
|
|
|
|
CoTaskMemFree(stat.pwcsName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
enum_obj->stats = heap_alloc(enum_obj->count * sizeof(*enum_obj->stats));
|
|
|
|
if (!enum_obj->stats)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
enum_obj->count = 0;
|
|
|
|
|
|
|
|
if (FAILED(hr = IEnumSTATSTG_Reset(penum)))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while (IEnumSTATSTG_Next(penum, 1, &stat, &count) == S_OK)
|
|
|
|
{
|
|
|
|
if (!stat.pwcsName)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (stat.pwcsName[0] == 5 && stat.type == STGTY_STREAM)
|
|
|
|
{
|
|
|
|
STATPROPSETSTG *ptr = &enum_obj->stats[enum_obj->count++];
|
|
|
|
|
|
|
|
PropStgNameToFmtId(stat.pwcsName, &ptr->fmtid);
|
|
|
|
|
|
|
|
TRACE("adding %s - %s.\n", debugstr_w(stat.pwcsName), debugstr_guid(&ptr->fmtid));
|
|
|
|
|
|
|
|
ptr->mtime = stat.mtime;
|
|
|
|
ptr->atime = stat.atime;
|
|
|
|
ptr->ctime = stat.ctime;
|
|
|
|
ptr->grfFlags = stat.grfMode;
|
|
|
|
ptr->clsid = stat.clsid;
|
|
|
|
}
|
|
|
|
CoTaskMemFree(stat.pwcsName);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
if (penum)
|
|
|
|
IEnumSTATSTG_Release(penum);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*ret = &enum_obj->IEnumSTATPROPSETSTG_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ret = NULL;
|
|
|
|
IEnumSTATPROPSETSTG_Release(&enum_obj->IEnumSTATPROPSETSTG_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:58:09 +01:00
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnQueryInterface (IUnknown)
|
|
|
|
*
|
|
|
|
* This method forwards to the common QueryInterface implementation
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertySetStorage_fnQueryInterface(
|
|
|
|
IPropertySetStorage *ppstg,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2012-07-14 18:42:48 +02:00
|
|
|
return IStorage_QueryInterface( &This->base.IStorage_iface, riid, ppvObject );
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnAddRef (IUnknown)
|
|
|
|
*
|
|
|
|
* This method forwards to the common AddRef implementation
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IPropertySetStorage_fnAddRef(
|
|
|
|
IPropertySetStorage *ppstg)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2012-07-14 18:42:48 +02:00
|
|
|
return IStorage_AddRef( &This->base.IStorage_iface );
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnRelease (IUnknown)
|
|
|
|
*
|
|
|
|
* This method forwards to the common Release implementation
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IPropertySetStorage_fnRelease(
|
|
|
|
IPropertySetStorage *ppstg)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2012-07-14 18:42:48 +02:00
|
|
|
return IStorage_Release( &This->base.IStorage_iface );
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnCreate (IPropertySetStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertySetStorage_fnCreate(
|
|
|
|
IPropertySetStorage *ppstg,
|
|
|
|
REFFMTID rfmtid,
|
|
|
|
const CLSID* pclsid,
|
|
|
|
DWORD grfFlags,
|
|
|
|
DWORD grfMode,
|
|
|
|
IPropertyStorage** ppprstg)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2016-06-18 09:58:09 +02:00
|
|
|
WCHAR name[CCH_MAX_PROPSTG_NAME + 1];
|
2005-02-21 21:58:09 +01:00
|
|
|
IStream *stm = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%p %s %08x %08x %p\n", This, debugstr_guid(rfmtid), grfFlags,
|
2005-03-17 21:50:35 +01:00
|
|
|
grfMode, ppprstg);
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
/* be picky */
|
|
|
|
if (grfMode != (STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE))
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
r = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
if (!rfmtid)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
r = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
/* FIXME: if (grfFlags & PROPSETFLAG_NONSIMPLE), we need to create a
|
|
|
|
* storage, not a stream. For now, disallow it.
|
|
|
|
*/
|
|
|
|
if (grfFlags & PROPSETFLAG_NONSIMPLE)
|
|
|
|
{
|
|
|
|
FIXME("PROPSETFLAG_NONSIMPLE not supported\n");
|
|
|
|
r = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2005-04-15 16:09:18 +02:00
|
|
|
r = FmtIdToPropStgName(rfmtid, name);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2012-07-14 18:42:48 +02:00
|
|
|
r = IStorage_CreateStream( &This->base.IStorage_iface, name, grfMode, 0, 0, &stm );
|
2005-02-21 21:58:09 +01:00
|
|
|
if (FAILED(r))
|
2005-03-17 21:50:35 +01:00
|
|
|
goto end;
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
r = PropertyStorage_ConstructEmpty(stm, rfmtid, grfFlags, grfMode, ppprstg);
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2016-04-21 10:00:24 +02:00
|
|
|
IStream_Release( stm );
|
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
end:
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x\n", r);
|
2005-03-17 21:50:35 +01:00
|
|
|
return r;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnOpen (IPropertySetStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertySetStorage_fnOpen(
|
|
|
|
IPropertySetStorage *ppstg,
|
|
|
|
REFFMTID rfmtid,
|
|
|
|
DWORD grfMode,
|
|
|
|
IPropertyStorage** ppprstg)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2005-02-21 21:58:09 +01:00
|
|
|
IStream *stm = NULL;
|
2016-06-18 09:58:09 +02:00
|
|
|
WCHAR name[CCH_MAX_PROPSTG_NAME + 1];
|
2005-02-21 21:58:09 +01:00
|
|
|
HRESULT r;
|
|
|
|
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("%p %s %08x %p\n", This, debugstr_guid(rfmtid), grfMode, ppprstg);
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
/* be picky */
|
|
|
|
if (grfMode != (STGM_READWRITE|STGM_SHARE_EXCLUSIVE) &&
|
|
|
|
grfMode != (STGM_READ|STGM_SHARE_EXCLUSIVE))
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
r = STG_E_INVALIDFLAG;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
if (!rfmtid)
|
2005-03-17 21:50:35 +01:00
|
|
|
{
|
|
|
|
r = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2005-04-15 16:09:18 +02:00
|
|
|
r = FmtIdToPropStgName(rfmtid, name);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2012-07-14 18:42:48 +02:00
|
|
|
r = IStorage_OpenStream( &This->base.IStorage_iface, name, 0, grfMode, 0, &stm );
|
2005-02-21 21:58:09 +01:00
|
|
|
if (FAILED(r))
|
2005-03-17 21:50:35 +01:00
|
|
|
goto end;
|
|
|
|
|
2005-04-11 20:50:45 +02:00
|
|
|
r = PropertyStorage_ConstructFromStream(stm, rfmtid, grfMode, ppprstg);
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2016-04-21 10:00:24 +02:00
|
|
|
IStream_Release( stm );
|
|
|
|
|
2005-03-17 21:50:35 +01:00
|
|
|
end:
|
2006-10-15 12:28:08 +02:00
|
|
|
TRACE("returning 0x%08x\n", r);
|
2005-03-17 21:50:35 +01:00
|
|
|
return r;
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IPropertySetStorage_fnDelete (IPropertySetStorage)
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IPropertySetStorage_fnDelete(
|
|
|
|
IPropertySetStorage *ppstg,
|
|
|
|
REFFMTID rfmtid)
|
|
|
|
{
|
2005-07-27 13:10:52 +02:00
|
|
|
StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
|
2016-06-18 09:58:09 +02:00
|
|
|
WCHAR name[CCH_MAX_PROPSTG_NAME + 1];
|
2005-04-15 16:09:18 +02:00
|
|
|
HRESULT r;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
|
|
|
TRACE("%p %s\n", This, debugstr_guid(rfmtid));
|
|
|
|
|
|
|
|
if (!rfmtid)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-04-15 16:09:18 +02:00
|
|
|
r = FmtIdToPropStgName(rfmtid, name);
|
|
|
|
if (FAILED(r))
|
|
|
|
return r;
|
2005-02-21 21:58:09 +01:00
|
|
|
|
2012-07-14 18:42:48 +02:00
|
|
|
return IStorage_DestroyElement(&This->base.IStorage_iface, name);
|
2005-02-21 21:58:09 +01:00
|
|
|
}
|
|
|
|
|
2019-11-08 14:33:52 +01:00
|
|
|
static HRESULT WINAPI IPropertySetStorage_fnEnum(IPropertySetStorage *iface, IEnumSTATPROPSETSTG **enum_obj)
|
2006-07-11 09:13:29 +02:00
|
|
|
{
|
2019-11-08 14:33:52 +01:00
|
|
|
StorageImpl *storage = impl_from_IPropertySetStorage(iface);
|
2006-07-11 09:13:29 +02:00
|
|
|
|
2019-11-08 14:33:52 +01:00
|
|
|
TRACE("%p, %p.\n", iface, enum_obj);
|
2006-07-11 09:13:29 +02:00
|
|
|
|
2019-11-08 14:33:52 +01:00
|
|
|
if (!enum_obj)
|
|
|
|
return E_INVALIDARG;
|
2006-07-11 09:13:29 +02:00
|
|
|
|
2019-11-08 14:33:52 +01:00
|
|
|
return create_enum_stat_propset_stg(storage, enum_obj);
|
2006-07-11 09:13:29 +02:00
|
|
|
}
|
2005-03-01 11:41:25 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* vtables
|
|
|
|
*/
|
2005-06-06 21:50:35 +02:00
|
|
|
const IPropertySetStorageVtbl IPropertySetStorage_Vtbl =
|
2005-03-01 11:41:25 +01:00
|
|
|
{
|
|
|
|
IPropertySetStorage_fnQueryInterface,
|
|
|
|
IPropertySetStorage_fnAddRef,
|
|
|
|
IPropertySetStorage_fnRelease,
|
|
|
|
IPropertySetStorage_fnCreate,
|
|
|
|
IPropertySetStorage_fnOpen,
|
|
|
|
IPropertySetStorage_fnDelete,
|
|
|
|
IPropertySetStorage_fnEnum
|
|
|
|
};
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPropertyStorageVtbl IPropertyStorage_Vtbl =
|
2005-03-01 11:41:25 +01:00
|
|
|
{
|
|
|
|
IPropertyStorage_fnQueryInterface,
|
|
|
|
IPropertyStorage_fnAddRef,
|
|
|
|
IPropertyStorage_fnRelease,
|
|
|
|
IPropertyStorage_fnReadMultiple,
|
|
|
|
IPropertyStorage_fnWriteMultiple,
|
|
|
|
IPropertyStorage_fnDeleteMultiple,
|
|
|
|
IPropertyStorage_fnReadPropertyNames,
|
|
|
|
IPropertyStorage_fnWritePropertyNames,
|
|
|
|
IPropertyStorage_fnDeletePropertyNames,
|
|
|
|
IPropertyStorage_fnCommit,
|
|
|
|
IPropertyStorage_fnRevert,
|
|
|
|
IPropertyStorage_fnEnum,
|
|
|
|
IPropertyStorage_fnSetTimes,
|
|
|
|
IPropertyStorage_fnSetClass,
|
|
|
|
IPropertyStorage_fnStat,
|
|
|
|
};
|
2005-04-15 16:09:18 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Format ID <-> name conversion
|
|
|
|
*/
|
2020-11-26 22:20:04 +01:00
|
|
|
static const WCHAR szSummaryInfo[] = L"\5SummaryInformation";
|
|
|
|
static const WCHAR szDocSummaryInfo[] = L"\5DocumentSummaryInformation";
|
2005-04-15 16:09:18 +02:00
|
|
|
|
|
|
|
#define BITS_PER_BYTE 8
|
|
|
|
#define CHARMASK 0x1f
|
|
|
|
#define BITS_IN_CHARMASK 5
|
|
|
|
#define NUM_ALPHA_CHARS 26
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FmtIdToPropStgName [ole32.@]
|
|
|
|
* Returns the storage name of the format ID rfmtid.
|
|
|
|
* PARAMS
|
|
|
|
* rfmtid [I] Format ID for which to return a storage name
|
|
|
|
* str [O] Storage name associated with rfmtid.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* E_INVALIDARG if rfmtid or str i NULL, S_OK otherwise.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* str must be at least CCH_MAX_PROPSTG_NAME characters in length.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI FmtIdToPropStgName(const FMTID *rfmtid, LPOLESTR str)
|
|
|
|
{
|
|
|
|
static const char fmtMap[] = "abcdefghijklmnopqrstuvwxyz012345";
|
|
|
|
|
|
|
|
TRACE("%s, %p\n", debugstr_guid(rfmtid), str);
|
|
|
|
|
|
|
|
if (!rfmtid) return E_INVALIDARG;
|
|
|
|
if (!str) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (IsEqualGUID(&FMTID_SummaryInformation, rfmtid))
|
|
|
|
lstrcpyW(str, szSummaryInfo);
|
|
|
|
else if (IsEqualGUID(&FMTID_DocSummaryInformation, rfmtid))
|
|
|
|
lstrcpyW(str, szDocSummaryInfo);
|
|
|
|
else if (IsEqualGUID(&FMTID_UserDefinedProperties, rfmtid))
|
|
|
|
lstrcpyW(str, szDocSummaryInfo);
|
|
|
|
else
|
|
|
|
{
|
2006-09-20 23:03:08 +02:00
|
|
|
const BYTE *fmtptr;
|
2005-04-15 16:09:18 +02:00
|
|
|
WCHAR *pstr = str;
|
|
|
|
ULONG bitsRemaining = BITS_PER_BYTE;
|
|
|
|
|
|
|
|
*pstr++ = 5;
|
2006-09-20 23:03:08 +02:00
|
|
|
for (fmtptr = (const BYTE *)rfmtid; fmtptr < (const BYTE *)rfmtid + sizeof(FMTID); )
|
2005-04-15 16:09:18 +02:00
|
|
|
{
|
|
|
|
ULONG i = *fmtptr >> (BITS_PER_BYTE - bitsRemaining);
|
|
|
|
|
|
|
|
if (bitsRemaining >= BITS_IN_CHARMASK)
|
|
|
|
{
|
|
|
|
*pstr = (WCHAR)(fmtMap[i & CHARMASK]);
|
|
|
|
if (bitsRemaining == BITS_PER_BYTE && *pstr >= 'a' &&
|
|
|
|
*pstr <= 'z')
|
|
|
|
*pstr += 'A' - 'a';
|
|
|
|
pstr++;
|
|
|
|
bitsRemaining -= BITS_IN_CHARMASK;
|
|
|
|
if (bitsRemaining == 0)
|
|
|
|
{
|
|
|
|
fmtptr++;
|
|
|
|
bitsRemaining = BITS_PER_BYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-27 11:53:46 +02:00
|
|
|
if (++fmtptr < (const BYTE *)rfmtid + sizeof(FMTID))
|
2005-04-15 16:09:18 +02:00
|
|
|
i |= *fmtptr << bitsRemaining;
|
|
|
|
*pstr++ = (WCHAR)(fmtMap[i & CHARMASK]);
|
|
|
|
bitsRemaining += BITS_PER_BYTE - BITS_IN_CHARMASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pstr = 0;
|
|
|
|
}
|
|
|
|
TRACE("returning %s\n", debugstr_w(str));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* PropStgNameToFmtId [ole32.@]
|
|
|
|
* Returns the format ID corresponding to the given name.
|
|
|
|
* PARAMS
|
|
|
|
* str [I] Storage name to convert to a format ID.
|
|
|
|
* rfmtid [O] Format ID corresponding to str.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* E_INVALIDARG if rfmtid or str is NULL or if str can't be converted to
|
|
|
|
* a format ID, S_OK otherwise.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI PropStgNameToFmtId(const LPOLESTR str, FMTID *rfmtid)
|
|
|
|
{
|
2005-04-23 21:04:49 +02:00
|
|
|
HRESULT hr = STG_E_INVALIDNAME;
|
2005-04-15 16:09:18 +02:00
|
|
|
|
|
|
|
TRACE("%s, %p\n", debugstr_w(str), rfmtid);
|
|
|
|
|
|
|
|
if (!rfmtid) return E_INVALIDARG;
|
2005-04-23 21:04:49 +02:00
|
|
|
if (!str) return STG_E_INVALIDNAME;
|
2005-04-15 16:09:18 +02:00
|
|
|
|
|
|
|
if (!lstrcmpiW(str, szDocSummaryInfo))
|
|
|
|
{
|
2008-03-10 22:58:43 +01:00
|
|
|
*rfmtid = FMTID_DocSummaryInformation;
|
2005-04-15 16:09:18 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else if (!lstrcmpiW(str, szSummaryInfo))
|
|
|
|
{
|
2008-03-10 22:58:43 +01:00
|
|
|
*rfmtid = FMTID_SummaryInformation;
|
2005-04-15 16:09:18 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULONG bits;
|
|
|
|
BYTE *fmtptr = (BYTE *)rfmtid - 1;
|
|
|
|
const WCHAR *pstr = str;
|
|
|
|
|
|
|
|
memset(rfmtid, 0, sizeof(*rfmtid));
|
|
|
|
for (bits = 0; bits < sizeof(FMTID) * BITS_PER_BYTE;
|
|
|
|
bits += BITS_IN_CHARMASK)
|
|
|
|
{
|
|
|
|
ULONG bitsUsed = bits % BITS_PER_BYTE, bitsStored;
|
|
|
|
WCHAR wc;
|
|
|
|
|
|
|
|
if (bitsUsed == 0)
|
|
|
|
fmtptr++;
|
|
|
|
wc = *++pstr - 'A';
|
|
|
|
if (wc > NUM_ALPHA_CHARS)
|
|
|
|
{
|
|
|
|
wc += 'A' - 'a';
|
|
|
|
if (wc > NUM_ALPHA_CHARS)
|
|
|
|
{
|
|
|
|
wc += 'a' - '0' + NUM_ALPHA_CHARS;
|
|
|
|
if (wc > CHARMASK)
|
|
|
|
{
|
|
|
|
WARN("invalid character (%d)\n", *pstr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*fmtptr |= wc << bitsUsed;
|
|
|
|
bitsStored = min(BITS_PER_BYTE - bitsUsed, BITS_IN_CHARMASK);
|
|
|
|
if (bitsStored < BITS_IN_CHARMASK)
|
|
|
|
{
|
|
|
|
wc >>= BITS_PER_BYTE - bitsUsed;
|
|
|
|
if (bits + bitsStored == sizeof(FMTID) * BITS_PER_BYTE)
|
|
|
|
{
|
|
|
|
if (wc != 0)
|
|
|
|
{
|
|
|
|
WARN("extra bits\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fmtptr++;
|
|
|
|
*fmtptr |= (BYTE)wc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
return hr;
|
|
|
|
}
|
2012-08-28 00:01:24 +02:00
|
|
|
|
|
|
|
#ifdef __i386__ /* thiscall functions are i386-specific */
|
|
|
|
|
|
|
|
#define DEFINE_STDCALL_WRAPPER(num,func,args) \
|
|
|
|
__ASM_STDCALL_FUNC(func, args, \
|
|
|
|
"popl %eax\n\t" \
|
|
|
|
"popl %ecx\n\t" \
|
|
|
|
"pushl %eax\n\t" \
|
|
|
|
"movl (%ecx), %eax\n\t" \
|
|
|
|
"jmp *(4*(" #num "))(%eax)" )
|
|
|
|
|
|
|
|
DEFINE_STDCALL_WRAPPER(0,Allocate_PMemoryAllocator,8)
|
2015-03-12 06:20:14 +01:00
|
|
|
extern void* WINAPI Allocate_PMemoryAllocator(void *this, ULONG cbSize);
|
2012-08-28 00:01:24 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2015-03-12 06:20:14 +01:00
|
|
|
static void* WINAPI Allocate_PMemoryAllocator(void *this, ULONG cbSize)
|
2012-08-28 00:01:24 +02:00
|
|
|
{
|
2015-03-12 06:20:14 +01:00
|
|
|
void* (WINAPI *fn)(void*,ULONG) = **(void***)this;
|
2012-08-28 00:01:24 +02:00
|
|
|
return fn(this, cbSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BOOLEAN WINAPI StgConvertPropertyToVariant(const SERIALIZEDPROPERTYVALUE* prop,
|
|
|
|
USHORT CodePage, PROPVARIANT* pvar, void* pma)
|
|
|
|
{
|
2020-01-27 07:24:17 +01:00
|
|
|
struct read_buffer read_buffer;
|
2012-08-28 00:01:24 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-01-27 07:24:17 +01:00
|
|
|
read_buffer.data = (BYTE *)prop;
|
|
|
|
read_buffer.size = ~(size_t)0;
|
|
|
|
hr = PropertyStorage_ReadProperty(pvar, &read_buffer, 0, CodePage, Allocate_PMemoryAllocator, pma);
|
2012-08-28 00:01:24 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
FIXME("should raise C++ exception on failure\n");
|
|
|
|
PropVariantInit(pvar);
|
|
|
|
}
|
|
|
|
|
2014-01-27 22:26:43 +01:00
|
|
|
return FALSE;
|
2012-08-28 00:01:24 +02:00
|
|
|
}
|
2012-10-04 22:30:20 +02:00
|
|
|
|
|
|
|
SERIALIZEDPROPERTYVALUE* WINAPI StgConvertVariantToProperty(const PROPVARIANT *pvar,
|
|
|
|
USHORT CodePage, SERIALIZEDPROPERTYVALUE *pprop, ULONG *pcb, PROPID pid,
|
|
|
|
BOOLEAN fReserved, ULONG *pcIndirect)
|
|
|
|
{
|
|
|
|
FIXME("%p,%d,%p,%p,%d,%d,%p\n", pvar, CodePage, pprop, pcb, pid, fReserved, pcIndirect);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-04-11 00:22:25 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI StgCreatePropStg(IUnknown *unk, REFFMTID fmt, const CLSID *clsid,
|
|
|
|
DWORD flags, DWORD reserved, IPropertyStorage **prop_stg)
|
|
|
|
{
|
|
|
|
IStorage *stg;
|
|
|
|
IStream *stm;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("%p %s %s %08x %d %p\n", unk, debugstr_guid(fmt), debugstr_guid(clsid), flags, reserved, prop_stg);
|
|
|
|
|
|
|
|
if (!fmt || reserved)
|
|
|
|
{
|
|
|
|
r = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & PROPSETFLAG_NONSIMPLE)
|
|
|
|
{
|
|
|
|
r = IUnknown_QueryInterface(unk, &IID_IStorage, (void **)&stg);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* FIXME: if (flags & PROPSETFLAG_NONSIMPLE), we need to create a
|
|
|
|
* storage, not a stream. For now, disallow it.
|
|
|
|
*/
|
|
|
|
FIXME("PROPSETFLAG_NONSIMPLE not supported\n");
|
|
|
|
IStorage_Release(stg);
|
|
|
|
r = STG_E_INVALIDFLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = IUnknown_QueryInterface(unk, &IID_IStream, (void **)&stm);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = PropertyStorage_ConstructEmpty(stm, fmt, flags,
|
|
|
|
STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, prop_stg);
|
2016-04-21 10:00:24 +02:00
|
|
|
|
|
|
|
IStream_Release( stm );
|
2016-04-11 00:22:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
TRACE("returning 0x%08x\n", r);
|
|
|
|
return r;
|
|
|
|
}
|
2016-04-11 00:22:26 +02:00
|
|
|
|
|
|
|
HRESULT WINAPI StgOpenPropStg(IUnknown *unk, REFFMTID fmt, DWORD flags,
|
|
|
|
DWORD reserved, IPropertyStorage **prop_stg)
|
|
|
|
{
|
|
|
|
IStorage *stg;
|
|
|
|
IStream *stm;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("%p %s %08x %d %p\n", unk, debugstr_guid(fmt), flags, reserved, prop_stg);
|
|
|
|
|
|
|
|
if (!fmt || reserved)
|
|
|
|
{
|
|
|
|
r = E_INVALIDARG;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & PROPSETFLAG_NONSIMPLE)
|
|
|
|
{
|
|
|
|
r = IUnknown_QueryInterface(unk, &IID_IStorage, (void **)&stg);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* FIXME: if (flags & PROPSETFLAG_NONSIMPLE), we need to open a
|
|
|
|
* storage, not a stream. For now, disallow it.
|
|
|
|
*/
|
|
|
|
FIXME("PROPSETFLAG_NONSIMPLE not supported\n");
|
|
|
|
IStorage_Release(stg);
|
|
|
|
r = STG_E_INVALIDFLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = IUnknown_QueryInterface(unk, &IID_IStream, (void **)&stm);
|
|
|
|
if (FAILED(r))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = PropertyStorage_ConstructFromStream(stm, fmt,
|
|
|
|
STGM_READWRITE|STGM_SHARE_EXCLUSIVE, prop_stg);
|
2016-04-21 10:00:24 +02:00
|
|
|
|
|
|
|
IStream_Release( stm );
|
2016-04-11 00:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
TRACE("returning 0x%08x\n", r);
|
|
|
|
return r;
|
|
|
|
}
|