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