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