]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | /////////////////////////////////////////////////////////////////////////////// |
20d8c319 | 2 | // Name: wx/msw/registry.h |
2bda0e17 KB |
3 | // Purpose: Registry classes and functions |
4 | // Author: Vadim Zeitlin | |
23f681ec | 5 | // Modified by: |
20d8c319 | 6 | // Created: 03.04.1998 |
2bda0e17 KB |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
20d8c319 VZ |
12 | #ifndef _WX_MSW_REGISTRY_H_ |
13 | #define _WX_MSW_REGISTRY_H_ | |
2bda0e17 | 14 | |
20d8c319 | 15 | class WXDLLIMPEXP_BASE wxOutputStream; |
8f494e5d | 16 | |
2bda0e17 KB |
17 | // ---------------------------------------------------------------------------- |
18 | // class wxRegKey encapsulates window HKEY handle | |
19 | // ---------------------------------------------------------------------------- | |
20d8c319 | 20 | |
4d08943e | 21 | class WXDLLIMPEXP_BASE wxRegKey |
2bda0e17 KB |
22 | { |
23 | public: | |
24 | // NB: do _not_ change the values of elements in these enumerations! | |
25 | ||
26 | // registry value types (with comments from winnt.h) | |
27 | enum ValueType | |
28 | { | |
29 | Type_None, // No value type | |
30 | Type_String, // Unicode nul terminated string | |
2bda0e17 KB |
31 | Type_Expand_String, // Unicode nul terminated string |
32 | // (with environment variable references) | |
33 | Type_Binary, // Free form binary | |
34 | Type_Dword, // 32-bit number | |
23f681ec VZ |
35 | Type_Dword_little_endian // 32-bit number |
36 | = Type_Dword, // (same as Type_DWORD) | |
2bda0e17 KB |
37 | Type_Dword_big_endian, // 32-bit number |
38 | Type_Link, // Symbolic Link (unicode) | |
39 | Type_Multi_String, // Multiple Unicode strings | |
40 | Type_Resource_list, // Resource list in the resource map | |
41 | Type_Full_resource_descriptor, // Resource list in the hardware description | |
a3ef5bf5 | 42 | Type_Resource_requirements_list // ??? |
2bda0e17 KB |
43 | }; |
44 | ||
45 | // predefined registry keys | |
46 | enum StdKey | |
47 | { | |
20d8c319 | 48 | HKCR, // classes root |
23f681ec VZ |
49 | HKCU, // current user |
50 | HKLM, // local machine | |
0bb22291 VZ |
51 | HKUSR, // users |
52 | HKPD, // performance data (WinNT/2K only) | |
53 | HKCC, // current config | |
54 | HKDD, // dynamic data (Win95/98 only) | |
55 | HKMAX | |
2bda0e17 KB |
56 | }; |
57 | ||
bee96abf VZ |
58 | // access mode for the key |
59 | enum AccessMode | |
60 | { | |
61 | Read, // read-only | |
62 | Write // read and write | |
63 | }; | |
64 | ||
2bda0e17 KB |
65 | // information about standard (predefined) registry keys |
66 | // number of standard keys | |
67 | static const size_t nStdKeys; | |
68 | // get the name of a standard key | |
4de6207a | 69 | static const wxChar *GetStdKeyName(size_t key); |
2bda0e17 | 70 | // get the short name of a standard key |
4de6207a | 71 | static const wxChar *GetStdKeyShortName(size_t key); |
2bda0e17 | 72 | // get StdKey from root HKEY |
0d8d91a9 | 73 | static StdKey GetStdKeyFromHkey(WXHKEY hkey); |
2bda0e17 KB |
74 | |
75 | // extacts the std key prefix from the string (return value) and | |
76 | // leaves only the part after it (i.e. modifies the string passed!) | |
77 | static StdKey ExtractKeyName(wxString& str); | |
78 | ||
79 | // ctors | |
80 | // root key is set to HKCR (the only root key under Win16) | |
81 | wxRegKey(); | |
82 | // strKey is the full name of the key (i.e. starting with HKEY_xxx...) | |
83 | wxRegKey(const wxString& strKey); | |
84 | // strKey is the name of key under (standard key) keyParent | |
2dc77646 | 85 | wxRegKey(StdKey keyParent, const wxString& strKey); |
2bda0e17 KB |
86 | // strKey is the name of key under (previously created) keyParent |
87 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); | |
bee96abf | 88 | // dtor closes the key |
2bda0e17 KB |
89 | ~wxRegKey(); |
90 | ||
91 | // change key (closes the previously opened key if any) | |
2dc77646 | 92 | // the name is absolute, i.e. should start with HKEY_xxx |
2bda0e17 | 93 | void SetName(const wxString& strKey); |
2dc77646 VZ |
94 | // the name is relative to the parent key |
95 | void SetName(StdKey keyParent, const wxString& strKey); | |
96 | // the name is relative to the parent key | |
97 | void SetName(const wxRegKey& keyParent, const wxString& strKey); | |
98 | // hKey should be opened and will be closed in wxRegKey dtor | |
0d8d91a9 | 99 | void SetHkey(WXHKEY hKey); |
2bda0e17 KB |
100 | |
101 | // get infomation about the key | |
102 | // get the (full) key name. Abbreviate std root keys if bShortPrefix. | |
4d08943e | 103 | wxString GetName(bool bShortPrefix = true) const; |
2dc77646 | 104 | // return true if the key exists |
8f494e5d VZ |
105 | bool Exists() const; |
106 | // get the info about key (any number of these pointers may be NULL) | |
3cda6353 VZ |
107 | bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys |
108 | size_t *pnMaxKeyLen, // max len of subkey name | |
109 | size_t *pnValues, // number of values | |
110 | size_t *pnMaxValueLen) const; | |
2dc77646 | 111 | // return true if the key is opened |
8f494e5d | 112 | bool IsOpened() const { return m_hKey != 0; } |
2bda0e17 KB |
113 | // for "if ( !key ) wxLogError(...)" kind of expressions |
114 | operator bool() const { return m_dwLastError == 0; } | |
115 | ||
116 | // operations on the key itself | |
117 | // explicitly open the key (will be automatically done by all functions | |
118 | // which need the key to be opened if the key is not opened yet) | |
bee96abf | 119 | bool Open(AccessMode mode = Write); |
23f681ec | 120 | // create the key: will fail if the key already exists and !bOkIfExists |
4d08943e | 121 | bool Create(bool bOkIfExists = true); |
23f681ec | 122 | // rename a value from old name to new one |
d38f70b2 | 123 | bool RenameValue(const wxString& szValueOld, const wxString& szValueNew); |
225fe9d6 | 124 | // rename the key |
d38f70b2 | 125 | bool Rename(const wxString& szNewName); |
23f681ec VZ |
126 | // copy value to another key possibly changing its name (by default it will |
127 | // remain the same) | |
d38f70b2 VS |
128 | bool CopyValue(const wxString& szValue, wxRegKey& keyDst, |
129 | const wxString& szNewName = wxEmptyString); | |
130 | ||
23f681ec | 131 | // copy the entire contents of the key recursively to another location |
d38f70b2 | 132 | bool Copy(const wxString& szNewName); |
23f681ec VZ |
133 | // same as Copy() but using a key and not the name |
134 | bool Copy(wxRegKey& keyDst); | |
2bda0e17 KB |
135 | // close the key (will be automatically done in dtor) |
136 | bool Close(); | |
137 | ||
138 | // deleting keys/values | |
139 | // deletes this key and all of it's subkeys/values | |
140 | bool DeleteSelf(); | |
141 | // deletes the subkey with all of it's subkeys/values recursively | |
d38f70b2 VS |
142 | bool DeleteKey(const wxString& szKey); |
143 | // deletes the named value (may be empty string to remove the default value) | |
144 | bool DeleteValue(const wxString& szValue); | |
2bda0e17 KB |
145 | |
146 | // access to values and subkeys | |
147 | // get value type | |
d38f70b2 | 148 | ValueType GetValueType(const wxString& szValue) const; |
4d08943e | 149 | // returns true if the value contains a number (else it's some string) |
d38f70b2 | 150 | bool IsNumericValue(const wxString& szValue) const; |
2bda0e17 KB |
151 | |
152 | // assignment operators set the default value of the key | |
153 | wxRegKey& operator=(const wxString& strValue) | |
d38f70b2 | 154 | { SetValue(wxEmptyString, strValue); return *this; } |
2bda0e17 | 155 | |
50e42404 VZ |
156 | // query the default value of the key: implicitly or explicitly |
157 | wxString QueryDefaultValue() const; | |
158 | operator wxString() const { return QueryDefaultValue(); } | |
159 | ||
160 | // named values | |
2bda0e17 KB |
161 | |
162 | // set the string value | |
d38f70b2 | 163 | bool SetValue(const wxString& szValue, const wxString& strValue); |
6dfec4b8 | 164 | // retrieve the string value |
d38f70b2 | 165 | bool QueryValue(const wxString& szValue, wxString& strValue) const |
4d08943e | 166 | { return QueryValue(szValue, strValue, false); } |
6dfec4b8 | 167 | // retrieve raw string value |
d38f70b2 | 168 | bool QueryRawValue(const wxString& szValue, wxString& strValue) const |
4d08943e | 169 | { return QueryValue(szValue, strValue, true); } |
6dfec4b8 | 170 | // retrieve either raw or expanded string value |
d38f70b2 | 171 | bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const; |
2bda0e17 | 172 | |
2bda0e17 | 173 | // set the numeric value |
d38f70b2 | 174 | bool SetValue(const wxString& szValue, long lValue); |
2bda0e17 | 175 | // return the numeric value |
d38f70b2 | 176 | bool QueryValue(const wxString& szValue, long *plValue) const; |
9b386eca | 177 | // set the binary value |
d38f70b2 | 178 | bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf); |
9b386eca | 179 | // return the binary value |
d38f70b2 | 180 | bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const; |
2bda0e17 | 181 | |
2dc77646 VZ |
182 | // query existence of a key/value |
183 | // return true if value exists | |
d38f70b2 | 184 | bool HasValue(const wxString& szKey) const; |
2dc77646 | 185 | // return true if given subkey exists |
d38f70b2 | 186 | bool HasSubKey(const wxString& szKey) const; |
2dc77646 | 187 | // return true if any subkeys exist |
92049cd4 VZ |
188 | bool HasSubkeys() const; |
189 | // return true if any values exist | |
190 | bool HasValues() const; | |
191 | // return true if the key is empty (nothing under this key) | |
192 | bool IsEmpty() const { return !HasSubkeys() && !HasValues(); } | |
2bda0e17 KB |
193 | |
194 | // enumerate values and subkeys | |
2bda0e17 KB |
195 | bool GetFirstValue(wxString& strValueName, long& lIndex); |
196 | bool GetNextValue (wxString& strValueName, long& lIndex) const; | |
2bda0e17 KB |
197 | |
198 | bool GetFirstKey (wxString& strKeyName , long& lIndex); | |
199 | bool GetNextKey (wxString& strKeyName , long& lIndex) const; | |
200 | ||
20d8c319 VZ |
201 | // export the contents of this key and all its subkeys to the given file |
202 | // (which won't be overwritten, it's an error if it already exists) | |
203 | // | |
204 | // note that we export the key in REGEDIT4 format, not RegSaveKey() binary | |
205 | // format nor newer REGEDIT5 one | |
206 | bool Export(const wxString& filename) const; | |
207 | ||
208 | // same as above but write to the given (opened) stream | |
209 | bool Export(wxOutputStream& ostr) const; | |
210 | ||
211 | ||
807a903e VZ |
212 | // for wxRegConfig usage only: preallocate some memory for the name |
213 | void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); } | |
214 | ||
2bda0e17 | 215 | private: |
807a903e VZ |
216 | // common part of all ctors |
217 | void Init() | |
218 | { | |
219 | m_hKey = (WXHKEY) NULL; | |
220 | m_dwLastError = 0; | |
221 | } | |
222 | ||
20d8c319 VZ |
223 | // recursive helper for Export() |
224 | bool DoExport(wxOutputStream& ostr) const; | |
225 | ||
226 | // export a single value | |
227 | bool DoExportValue(wxOutputStream& ostr, const wxString& name) const; | |
228 | ||
229 | // return the text representation (in REGEDIT4 format) of the value with the | |
230 | // given name | |
231 | wxString FormatValue(const wxString& name) const; | |
232 | ||
2bda0e17 | 233 | |
c085e333 | 234 | WXHKEY m_hKey, // our handle |
2bda0e17 KB |
235 | m_hRootKey; // handle of the top key (i.e. StdKey) |
236 | wxString m_strKey; // key name (relative to m_hRootKey) | |
237 | ||
fb5e0dcf | 238 | AccessMode m_mode; // valid only if key is opened |
807a903e | 239 | long m_dwLastError; // last error (0 if none) |
20d8c319 VZ |
240 | |
241 | ||
242 | DECLARE_NO_COPY_CLASS(wxRegKey) | |
2bda0e17 KB |
243 | }; |
244 | ||
20d8c319 | 245 | #endif // _WX_MSW_REGISTRY_H_ |
2dc77646 | 246 |