1998-05-20 14:12:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2005-01-16 00:26:40 +00:00
|
|
|
// Name: wx/msw/registry.h
|
1998-05-20 14:12:05 +00:00
|
|
|
// Purpose: Registry classes and functions
|
|
|
|
// Author: Vadim Zeitlin
|
2000-02-15 00:05:36 +00:00
|
|
|
// Modified by:
|
2005-01-16 00:26:40 +00:00
|
|
|
// Created: 03.04.1998
|
1998-05-20 14:12:05 +00:00
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:12:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-01-16 00:26:40 +00:00
|
|
|
#ifndef _WX_MSW_REGISTRY_H_
|
|
|
|
#define _WX_MSW_REGISTRY_H_
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2007-07-21 13:01:28 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_REGKEY
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxOutputStream;
|
1998-08-02 23:04:55 +00:00
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// class wxRegKey encapsulates window HKEY handle
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-01-16 00:26:40 +00:00
|
|
|
|
2004-09-03 18:32:56 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxRegKey
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// NB: do _not_ change the values of elements in these enumerations!
|
|
|
|
|
|
|
|
// registry value types (with comments from winnt.h)
|
|
|
|
enum ValueType
|
|
|
|
{
|
|
|
|
Type_None, // No value type
|
|
|
|
Type_String, // Unicode nul terminated string
|
|
|
|
Type_Expand_String, // Unicode nul terminated string
|
|
|
|
// (with environment variable references)
|
|
|
|
Type_Binary, // Free form binary
|
|
|
|
Type_Dword, // 32-bit number
|
2000-02-15 00:05:36 +00:00
|
|
|
Type_Dword_little_endian // 32-bit number
|
|
|
|
= Type_Dword, // (same as Type_DWORD)
|
1998-05-20 14:12:05 +00:00
|
|
|
Type_Dword_big_endian, // 32-bit number
|
|
|
|
Type_Link, // Symbolic Link (unicode)
|
|
|
|
Type_Multi_String, // Multiple Unicode strings
|
|
|
|
Type_Resource_list, // Resource list in the resource map
|
|
|
|
Type_Full_resource_descriptor, // Resource list in the hardware description
|
1999-01-16 00:13:58 +00:00
|
|
|
Type_Resource_requirements_list // ???
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// predefined registry keys
|
|
|
|
enum StdKey
|
|
|
|
{
|
2005-01-16 00:26:40 +00:00
|
|
|
HKCR, // classes root
|
2000-02-15 00:05:36 +00:00
|
|
|
HKCU, // current user
|
|
|
|
HKLM, // local machine
|
2006-10-31 17:29:55 +00:00
|
|
|
HKUSR, // users
|
2016-02-21 10:12:47 +00:00
|
|
|
HKPD, // (obsolete under XP and later)
|
2006-10-31 17:29:55 +00:00
|
|
|
HKCC, // current config
|
2016-02-21 10:12:47 +00:00
|
|
|
HKDD, // (obsolete under XP and later)
|
2006-10-31 17:29:55 +00:00
|
|
|
HKMAX
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
2004-03-03 23:01:05 +00:00
|
|
|
// access mode for the key
|
|
|
|
enum AccessMode
|
|
|
|
{
|
|
|
|
Read, // read-only
|
|
|
|
Write // read and write
|
|
|
|
};
|
|
|
|
|
2011-02-06 01:01:01 +00:00
|
|
|
// Different registry views supported under WOW64.
|
|
|
|
enum WOW64ViewMode
|
|
|
|
{
|
|
|
|
// 32 bit registry for 32 bit applications, 64 bit registry
|
|
|
|
// for 64 bit ones.
|
|
|
|
WOW64ViewMode_Default,
|
|
|
|
|
|
|
|
// Can be used in 64 bit apps to access 32 bit registry,
|
|
|
|
// has no effect (i.e. treated as default) in 32 bit apps.
|
|
|
|
WOW64ViewMode_32,
|
|
|
|
|
|
|
|
// Can be used in 32 bit apps to access 64 bit registry,
|
|
|
|
// has no effect (i.e. treated as default) in 64 bit apps.
|
|
|
|
WOW64ViewMode_64
|
|
|
|
};
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// information about standard (predefined) registry keys
|
|
|
|
// number of standard keys
|
|
|
|
static const size_t nStdKeys;
|
|
|
|
// get the name of a standard key
|
1999-04-21 21:46:02 +00:00
|
|
|
static const wxChar *GetStdKeyName(size_t key);
|
1998-05-20 14:12:05 +00:00
|
|
|
// get the short name of a standard key
|
1999-04-21 21:46:02 +00:00
|
|
|
static const wxChar *GetStdKeyShortName(size_t key);
|
1998-05-20 14:12:05 +00:00
|
|
|
// get StdKey from root HKEY
|
1998-08-24 19:13:34 +00:00
|
|
|
static StdKey GetStdKeyFromHkey(WXHKEY hkey);
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2011-03-22 14:17:38 +00:00
|
|
|
// extracts the std key prefix from the string (return value) and
|
1998-05-20 14:12:05 +00:00
|
|
|
// leaves only the part after it (i.e. modifies the string passed!)
|
|
|
|
static StdKey ExtractKeyName(wxString& str);
|
|
|
|
|
|
|
|
// ctors
|
|
|
|
// root key is set to HKCR (the only root key under Win16)
|
2011-02-06 01:01:01 +00:00
|
|
|
wxRegKey(WOW64ViewMode viewMode = WOW64ViewMode_Default);
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// strKey is the full name of the key (i.e. starting with HKEY_xxx...)
|
2011-02-06 01:01:01 +00:00
|
|
|
wxRegKey(const wxString& strKey,
|
|
|
|
WOW64ViewMode viewMode = WOW64ViewMode_Default);
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// strKey is the name of key under (standard key) keyParent
|
2011-02-06 01:01:01 +00:00
|
|
|
wxRegKey(StdKey keyParent,
|
|
|
|
const wxString& strKey,
|
|
|
|
WOW64ViewMode viewMode = WOW64ViewMode_Default);
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// strKey is the name of key under (previously created) keyParent
|
|
|
|
wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
|
2004-03-03 23:01:05 +00:00
|
|
|
// dtor closes the key
|
1998-05-20 14:12:05 +00:00
|
|
|
~wxRegKey();
|
|
|
|
|
|
|
|
// change key (closes the previously opened key if any)
|
1998-05-27 23:18:16 +00:00
|
|
|
// the name is absolute, i.e. should start with HKEY_xxx
|
1998-05-20 14:12:05 +00:00
|
|
|
void SetName(const wxString& strKey);
|
1998-05-27 23:18:16 +00:00
|
|
|
// the name is relative to the parent key
|
|
|
|
void SetName(StdKey keyParent, const wxString& strKey);
|
|
|
|
// the name is relative to the parent key
|
|
|
|
void SetName(const wxRegKey& keyParent, const wxString& strKey);
|
|
|
|
// hKey should be opened and will be closed in wxRegKey dtor
|
1998-08-24 19:13:34 +00:00
|
|
|
void SetHkey(WXHKEY hKey);
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2014-12-14 11:12:31 +00:00
|
|
|
// get information about the key
|
1998-05-20 14:12:05 +00:00
|
|
|
// get the (full) key name. Abbreviate std root keys if bShortPrefix.
|
2004-09-03 18:32:56 +00:00
|
|
|
wxString GetName(bool bShortPrefix = true) const;
|
2011-02-06 01:01:01 +00:00
|
|
|
// Retrieves the registry view used by this key.
|
|
|
|
WOW64ViewMode GetView() const { return m_viewMode; }
|
1998-05-27 23:18:16 +00:00
|
|
|
// return true if the key exists
|
1998-08-02 23:04:55 +00:00
|
|
|
bool Exists() const;
|
|
|
|
// get the info about key (any number of these pointers may be NULL)
|
1998-08-18 20:15:51 +00:00
|
|
|
bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
|
2014-12-14 11:12:31 +00:00
|
|
|
size_t *pnMaxKeyLen, // max length of subkey name
|
1998-08-18 20:15:51 +00:00
|
|
|
size_t *pnValues, // number of values
|
|
|
|
size_t *pnMaxValueLen) const;
|
1998-05-27 23:18:16 +00:00
|
|
|
// return true if the key is opened
|
1998-08-02 23:04:55 +00:00
|
|
|
bool IsOpened() const { return m_hKey != 0; }
|
1998-05-20 14:12:05 +00:00
|
|
|
// for "if ( !key ) wxLogError(...)" kind of expressions
|
|
|
|
operator bool() const { return m_dwLastError == 0; }
|
|
|
|
|
|
|
|
// operations on the key itself
|
|
|
|
// explicitly open the key (will be automatically done by all functions
|
|
|
|
// which need the key to be opened if the key is not opened yet)
|
2004-03-03 23:01:05 +00:00
|
|
|
bool Open(AccessMode mode = Write);
|
2000-02-15 00:05:36 +00:00
|
|
|
// create the key: will fail if the key already exists and !bOkIfExists
|
2004-09-03 18:32:56 +00:00
|
|
|
bool Create(bool bOkIfExists = true);
|
2000-02-15 00:05:36 +00:00
|
|
|
// rename a value from old name to new one
|
2007-06-20 07:09:14 +00:00
|
|
|
bool RenameValue(const wxString& szValueOld, const wxString& szValueNew);
|
2000-02-24 23:33:15 +00:00
|
|
|
// rename the key
|
2007-06-20 07:09:14 +00:00
|
|
|
bool Rename(const wxString& szNewName);
|
2000-02-15 00:05:36 +00:00
|
|
|
// copy value to another key possibly changing its name (by default it will
|
|
|
|
// remain the same)
|
2007-06-20 07:09:14 +00:00
|
|
|
bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
|
|
|
|
const wxString& szNewName = wxEmptyString);
|
|
|
|
|
2000-02-15 00:05:36 +00:00
|
|
|
// copy the entire contents of the key recursively to another location
|
2007-06-20 07:09:14 +00:00
|
|
|
bool Copy(const wxString& szNewName);
|
2000-02-15 00:05:36 +00:00
|
|
|
// same as Copy() but using a key and not the name
|
|
|
|
bool Copy(wxRegKey& keyDst);
|
1998-05-20 14:12:05 +00:00
|
|
|
// close the key (will be automatically done in dtor)
|
|
|
|
bool Close();
|
|
|
|
|
|
|
|
// deleting keys/values
|
|
|
|
// deletes this key and all of it's subkeys/values
|
|
|
|
bool DeleteSelf();
|
|
|
|
// deletes the subkey with all of it's subkeys/values recursively
|
2007-06-20 07:09:14 +00:00
|
|
|
bool DeleteKey(const wxString& szKey);
|
|
|
|
// deletes the named value (may be empty string to remove the default value)
|
|
|
|
bool DeleteValue(const wxString& szValue);
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// access to values and subkeys
|
|
|
|
// get value type
|
2007-06-20 07:09:14 +00:00
|
|
|
ValueType GetValueType(const wxString& szValue) const;
|
2004-09-03 18:32:56 +00:00
|
|
|
// returns true if the value contains a number (else it's some string)
|
2007-06-20 07:09:14 +00:00
|
|
|
bool IsNumericValue(const wxString& szValue) const;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// assignment operators set the default value of the key
|
|
|
|
wxRegKey& operator=(const wxString& strValue)
|
2007-06-20 07:09:14 +00:00
|
|
|
{ SetValue(wxEmptyString, strValue); return *this; }
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2002-01-21 15:52:03 +00:00
|
|
|
// query the default value of the key: implicitly or explicitly
|
|
|
|
wxString QueryDefaultValue() const;
|
|
|
|
operator wxString() const { return QueryDefaultValue(); }
|
|
|
|
|
|
|
|
// named values
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// set the string value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool SetValue(const wxString& szValue, const wxString& strValue);
|
2000-10-12 23:40:26 +00:00
|
|
|
// retrieve the string value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool QueryValue(const wxString& szValue, wxString& strValue) const
|
2004-09-03 18:32:56 +00:00
|
|
|
{ return QueryValue(szValue, strValue, false); }
|
2000-10-12 23:40:26 +00:00
|
|
|
// retrieve raw string value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool QueryRawValue(const wxString& szValue, wxString& strValue) const
|
2004-09-03 18:32:56 +00:00
|
|
|
{ return QueryValue(szValue, strValue, true); }
|
2000-10-12 23:40:26 +00:00
|
|
|
// retrieve either raw or expanded string value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// set the numeric value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool SetValue(const wxString& szValue, long lValue);
|
1998-05-20 14:12:05 +00:00
|
|
|
// return the numeric value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool QueryValue(const wxString& szValue, long *plValue) const;
|
2004-07-16 13:09:52 +00:00
|
|
|
// set the binary value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
|
2004-07-16 13:09:52 +00:00
|
|
|
// return the binary value
|
2007-06-20 07:09:14 +00:00
|
|
|
bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
1998-05-27 23:18:16 +00:00
|
|
|
// query existence of a key/value
|
|
|
|
// return true if value exists
|
2007-06-20 07:09:14 +00:00
|
|
|
bool HasValue(const wxString& szKey) const;
|
1998-05-27 23:18:16 +00:00
|
|
|
// return true if given subkey exists
|
2007-06-20 07:09:14 +00:00
|
|
|
bool HasSubKey(const wxString& szKey) const;
|
1998-05-27 23:18:16 +00:00
|
|
|
// return true if any subkeys exist
|
1999-06-26 11:10:50 +00:00
|
|
|
bool HasSubkeys() const;
|
|
|
|
// return true if any values exist
|
|
|
|
bool HasValues() const;
|
|
|
|
// return true if the key is empty (nothing under this key)
|
|
|
|
bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// enumerate values and subkeys
|
|
|
|
bool GetFirstValue(wxString& strValueName, long& lIndex);
|
|
|
|
bool GetNextValue (wxString& strValueName, long& lIndex) const;
|
|
|
|
|
|
|
|
bool GetFirstKey (wxString& strKeyName , long& lIndex);
|
|
|
|
bool GetNextKey (wxString& strKeyName , long& lIndex) const;
|
|
|
|
|
2005-01-16 00:26:40 +00:00
|
|
|
// export the contents of this key and all its subkeys to the given file
|
|
|
|
// (which won't be overwritten, it's an error if it already exists)
|
|
|
|
//
|
|
|
|
// note that we export the key in REGEDIT4 format, not RegSaveKey() binary
|
|
|
|
// format nor newer REGEDIT5 one
|
|
|
|
bool Export(const wxString& filename) const;
|
|
|
|
|
|
|
|
// same as above but write to the given (opened) stream
|
|
|
|
bool Export(wxOutputStream& ostr) const;
|
|
|
|
|
|
|
|
|
2001-04-21 01:46:19 +00:00
|
|
|
// for wxRegConfig usage only: preallocate some memory for the name
|
|
|
|
void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
private:
|
2001-04-21 01:46:19 +00:00
|
|
|
// common part of all ctors
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_hKey = (WXHKEY) NULL;
|
|
|
|
m_dwLastError = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-16 00:26:40 +00:00
|
|
|
// recursive helper for Export()
|
|
|
|
bool DoExport(wxOutputStream& ostr) const;
|
|
|
|
|
|
|
|
// export a single value
|
|
|
|
bool DoExportValue(wxOutputStream& ostr, const wxString& name) const;
|
|
|
|
|
|
|
|
// return the text representation (in REGEDIT4 format) of the value with the
|
|
|
|
// given name
|
|
|
|
wxString FormatValue(const wxString& name) const;
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2011-02-06 01:01:01 +00:00
|
|
|
WXHKEY m_hKey, // our handle
|
|
|
|
m_hRootKey; // handle of the top key (i.e. StdKey)
|
|
|
|
wxString m_strKey; // key name (relative to m_hRootKey)
|
|
|
|
WOW64ViewMode m_viewMode; // which view to select under WOW64
|
|
|
|
AccessMode m_mode; // valid only if key is opened
|
|
|
|
long m_dwLastError; // last error (0 if none)
|
2005-01-16 00:26:40 +00:00
|
|
|
|
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxRegKey);
|
1998-05-20 14:12:05 +00:00
|
|
|
};
|
|
|
|
|
2007-07-21 13:01:28 +00:00
|
|
|
#endif // wxUSE_REGKEY
|
|
|
|
|
2005-01-16 00:26:40 +00:00
|
|
|
#endif // _WX_MSW_REGISTRY_H_
|
1998-05-27 23:18:16 +00:00
|
|
|
|