7#include "unipstoregen.h"
9#include "wvlinkerhack.h"
15static const int MAX = 1024;
17using namespace PSTORECLib;
19typedef HRESULT (WINAPI *PStoreCreateInstancePtr)(IPStore **, DWORD, DWORD, DWORD);
25 _PST_TYPEINFO myTypeInfo;
26 myTypeInfo.cbSize = strlen(type_name.
cstr()) + 1;
27 myTypeInfo.szDisplayName =
new wchar_t[myTypeInfo.cbSize];
28 mbstowcs(myTypeInfo.szDisplayName, type_name.
cstr(), myTypeInfo.cbSize);
30 _PST_TYPEINFO mySubTypeInfo;
31 mySubTypeInfo.cbSize = strlen(subtype_name.
cstr()) + 1;
32 mySubTypeInfo.szDisplayName =
new wchar_t[mySubTypeInfo.cbSize];
33 mbstowcs(mySubTypeInfo.szDisplayName, subtype_name.
cstr(), mySubTypeInfo.cbSize);
35 _PST_ACCESSRULESET myRuleSet;
36 myRuleSet.cbSize =
sizeof(myRuleSet);
38 myRuleSet.rgRules = 0;
40 hRes = m_spPStore->CreateType( m_key, &m_type, &myTypeInfo, 0);
42 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS))
44 m_log(
"CreateSubtype() returned: %s\n", hRes);
48 hRes = m_spPStore->CreateSubtype( m_key, &m_type, &m_subtype, &mySubTypeInfo, &myRuleSet, 0);
49 if ((hRes != PST_E_OK) && (hRes != PST_E_TYPE_EXISTS))
51 m_log(
"CreateSubtype() returned: %s\n", hRes);
56 delete[] myTypeInfo.szDisplayName;
57 delete[] mySubTypeInfo.szDisplayName;
63UniPStoreGen::UniPStoreGen(
WvString _moniker) :
64 m_log(_moniker), m_key(-1)
67 m_hPstoreDLL = LoadLibrary(
"pstorec.dll");
70 PStoreCreateInstancePtr pPStoreCreateInstance =
71 (PStoreCreateInstancePtr) GetProcAddress(m_hPstoreDLL,
"PStoreCreateInstance");
72 assert(pPStoreCreateInstance);
74 HRESULT hr = pPStoreCreateInstance(&m_spPStore, 0, 0, 0);
75 assert(SUCCEEDED(hr));
78 char *moniker = _moniker.
edit();
79 const char *seps =
":";
80 WvString _key = strtok(moniker, seps);
81 WvString type_name = strtok(NULL, seps);
82 WvString _type_guid = strtok(NULL, seps);
83 WvString subtype_name = strtok(NULL, seps);
84 WvString _subtype_guid = strtok(NULL, seps);
86 if (!!_key && strcmp(_key,
"PST_KEY_CURRENT_USER") == 0)
88 m_key = PST_KEY_CURRENT_USER;
90 else if (!!_key && strcmp(_key,
"PST_KEY_LOCAL_MACHINE") == 0)
92 m_key = PST_KEY_LOCAL_MACHINE;
95 if ((m_key >= 0) && !!type_name && !!_type_guid && !!subtype_name && !!_subtype_guid)
98 hr = UuidFromString((
unsigned char*)_type_guid.
edit(), &m_type);
99 hr = UuidFromString((
unsigned char*)_subtype_guid.
edit(), &m_subtype);
100 int result = create_types(type_name, subtype_name);
101 assert(SUCCEEDED( result ) || (result == PST_E_TYPE_EXISTS));
105UniPStoreGen::~UniPStoreGen()
110 FreeLibrary(m_hPstoreDLL);
127 unsigned long cbdata;
131 mbstowcs(name, _name.
cstr(), MAX);
133 hRes = m_spPStore->ReadItem(
144 if (hRes == PST_E_OK)
147 wcstombs(value.
edit(), (
wchar_t*)data, MAX);
156 WCHAR name[MAX], data[MAX];
158 mbstowcs(data, value.
cstr(), MAX);
160 DWORD cbdata = DWORD((wcslen(data) + 1) *
sizeof(WCHAR));
162 HRESULT hRes = m_spPStore->WriteItem(
168 (
unsigned char *)data,
174 if (hRes == PST_E_OK)
207#pragma warning(disable : 4073)
The basic interface which is included by all other XPLC interfaces and objects.
An abstract data container that backs a UniConf tree.
An abstract iterator over keys and values in a generator.
An iterator that's always empty.
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
WvString printable() const
Returns the canonical string representation of the path.
UniConfKey last(int n=1) const
Returns the path formed by the n last segments of this path.
A generator that exposes Windows protected storage.
virtual bool isok()
Determines if the generator is usable and working properly.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
virtual bool exists(const UniConfKey &key)
Without fetching its value, returns true if a key exists.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
const char * cstr() const
return a (const char *) for this string.
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
WvString is an implementation of a simple and efficient printable-string class.
char * edit()
make the string editable, and return a non-const (char*)