1998-05-20 10:12:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2005-01-15 19:26:40 -05:00
|
|
|
// Name: wx/msw/registry.h
|
1998-05-20 10:12:05 -04:00
|
|
|
// Purpose: Registry classes and functions
|
|
|
|
// Author: Vadim Zeitlin
|
2000-02-14 19:05:36 -05:00
|
|
|
// Modified by:
|
2005-01-15 19:26:40 -05:00
|
|
|
// Created: 03.04.1998
|
1998-05-20 10:12:05 -04:00
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:12:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-01-15 19:26:40 -05:00
|
|
|
#ifndef _WX_MSW_REGISTRY_H_
|
|
|
|
#define _WX_MSW_REGISTRY_H_
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2007-07-21 09:01:28 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_REGKEY
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxOutputStream;
|
1998-08-02 19:04:55 -04:00
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// class wxRegKey encapsulates window HKEY handle
|
|
|
|
// ----------------------------------------------------------------------------
|
2005-01-15 19:26:40 -05:00
|
|
|
|
2004-09-03 14:32:56 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxRegKey
|
1998-05-20 10:12:05 -04: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-14 19:05:36 -05:00
|
|
|
Type_Dword_little_endian // 32-bit number
|
|
|
|
= Type_Dword, // (same as Type_DWORD)
|
1998-05-20 10:12:05 -04: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-15 19:13:58 -05:00
|
|
|
Type_Resource_requirements_list // ???
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// predefined registry keys
|
|
|
|
enum StdKey
|
|
|
|
{
|
2005-01-15 19:26:40 -05:00
|
|
|
HKCR, // classes root
|
2000-02-14 19:05:36 -05:00
|
|
|
HKCU, // current user
|
|
|
|
HKLM, // local machine
|
2006-10-31 12:29:55 -05:00
|
|
|
HKUSR, // users
|
|
|
|
HKPD, // performance data (WinNT/2K only)
|
|
|
|
HKCC, // current config
|
|
|
|
HKDD, // dynamic data (Win95/98 only)
|
|
|
|
HKMAX
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
2004-03-03 18:01:05 -05:00
|
|
|
// access mode for the key
|
|
|
|
enum AccessMode
|
|
|
|
{
|
|
|
|
Read, // read-only
|
|
|
|
Write // read and write
|
|
|
|
};
|
|
|
|
|
1998-05-20 10:12:05 -04: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 17:46:02 -04:00
|
|
|
static const wxChar *GetStdKeyName(size_t key);
|
1998-05-20 10:12:05 -04:00
|
|
|
// get the short name of a standard key
|
1999-04-21 17:46:02 -04:00
|
|
|
static const wxChar *GetStdKeyShortName(size_t key);
|
1998-05-20 10:12:05 -04:00
|
|
|
// get StdKey from root HKEY
|
1998-08-24 15:13:34 -04:00
|
|
|
static StdKey GetStdKeyFromHkey(WXHKEY hkey);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// extacts the std key prefix from the string (return value) and
|
|
|
|
// 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)
|
|
|
|
wxRegKey();
|
|
|
|
// strKey is the full name of the key (i.e. starting with HKEY_xxx...)
|
|
|
|
wxRegKey(const wxString& strKey);
|
|
|
|
// strKey is the name of key under (standard key) keyParent
|
1998-05-27 19:18:16 -04:00
|
|
|
wxRegKey(StdKey keyParent, const wxString& strKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
// strKey is the name of key under (previously created) keyParent
|
|
|
|
wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
|
2004-03-03 18:01:05 -05:00
|
|
|
// dtor closes the key
|
1998-05-20 10:12:05 -04:00
|
|
|
~wxRegKey();
|
|
|
|
|
|
|
|
// change key (closes the previously opened key if any)
|
1998-05-27 19:18:16 -04:00
|
|
|
// the name is absolute, i.e. should start with HKEY_xxx
|
1998-05-20 10:12:05 -04:00
|
|
|
void SetName(const wxString& strKey);
|
1998-05-27 19:18:16 -04: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 15:13:34 -04:00
|
|
|
void SetHkey(WXHKEY hKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// get infomation about the key
|
|
|
|
// get the (full) key name. Abbreviate std root keys if bShortPrefix.
|
2004-09-03 14:32:56 -04:00
|
|
|
wxString GetName(bool bShortPrefix = true) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if the key exists
|
1998-08-02 19:04:55 -04:00
|
|
|
bool Exists() const;
|
|
|
|
// get the info about key (any number of these pointers may be NULL)
|
1998-08-18 16:15:51 -04:00
|
|
|
bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
|
|
|
|
size_t *pnMaxKeyLen, // max len of subkey name
|
|
|
|
size_t *pnValues, // number of values
|
|
|
|
size_t *pnMaxValueLen) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if the key is opened
|
1998-08-02 19:04:55 -04:00
|
|
|
bool IsOpened() const { return m_hKey != 0; }
|
1998-05-20 10:12:05 -04: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 18:01:05 -05:00
|
|
|
bool Open(AccessMode mode = Write);
|
2000-02-14 19:05:36 -05:00
|
|
|
// create the key: will fail if the key already exists and !bOkIfExists
|
2004-09-03 14:32:56 -04:00
|
|
|
bool Create(bool bOkIfExists = true);
|
2000-02-14 19:05:36 -05:00
|
|
|
// rename a value from old name to new one
|
2007-06-20 03:09:14 -04:00
|
|
|
bool RenameValue(const wxString& szValueOld, const wxString& szValueNew);
|
2000-02-24 18:33:15 -05:00
|
|
|
// rename the key
|
2007-06-20 03:09:14 -04:00
|
|
|
bool Rename(const wxString& szNewName);
|
2000-02-14 19:05:36 -05:00
|
|
|
// copy value to another key possibly changing its name (by default it will
|
|
|
|
// remain the same)
|
2007-06-20 03:09:14 -04:00
|
|
|
bool CopyValue(const wxString& szValue, wxRegKey& keyDst,
|
|
|
|
const wxString& szNewName = wxEmptyString);
|
|
|
|
|
2000-02-14 19:05:36 -05:00
|
|
|
// copy the entire contents of the key recursively to another location
|
2007-06-20 03:09:14 -04:00
|
|
|
bool Copy(const wxString& szNewName);
|
2000-02-14 19:05:36 -05:00
|
|
|
// same as Copy() but using a key and not the name
|
|
|
|
bool Copy(wxRegKey& keyDst);
|
1998-05-20 10:12:05 -04: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 03:09:14 -04: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 10:12:05 -04:00
|
|
|
|
|
|
|
// access to values and subkeys
|
|
|
|
// get value type
|
2007-06-20 03:09:14 -04:00
|
|
|
ValueType GetValueType(const wxString& szValue) const;
|
2004-09-03 14:32:56 -04:00
|
|
|
// returns true if the value contains a number (else it's some string)
|
2007-06-20 03:09:14 -04:00
|
|
|
bool IsNumericValue(const wxString& szValue) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// assignment operators set the default value of the key
|
|
|
|
wxRegKey& operator=(const wxString& strValue)
|
2007-06-20 03:09:14 -04:00
|
|
|
{ SetValue(wxEmptyString, strValue); return *this; }
|
1998-05-20 10:12:05 -04:00
|
|
|
|
2002-01-21 10:52:03 -05:00
|
|
|
// query the default value of the key: implicitly or explicitly
|
|
|
|
wxString QueryDefaultValue() const;
|
|
|
|
operator wxString() const { return QueryDefaultValue(); }
|
|
|
|
|
|
|
|
// named values
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// set the string value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool SetValue(const wxString& szValue, const wxString& strValue);
|
2000-10-12 19:40:26 -04:00
|
|
|
// retrieve the string value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool QueryValue(const wxString& szValue, wxString& strValue) const
|
2004-09-03 14:32:56 -04:00
|
|
|
{ return QueryValue(szValue, strValue, false); }
|
2000-10-12 19:40:26 -04:00
|
|
|
// retrieve raw string value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool QueryRawValue(const wxString& szValue, wxString& strValue) const
|
2004-09-03 14:32:56 -04:00
|
|
|
{ return QueryValue(szValue, strValue, true); }
|
2000-10-12 19:40:26 -04:00
|
|
|
// retrieve either raw or expanded string value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool QueryValue(const wxString& szValue, wxString& strValue, bool raw) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
|
|
|
// set the numeric value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool SetValue(const wxString& szValue, long lValue);
|
1998-05-20 10:12:05 -04:00
|
|
|
// return the numeric value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool QueryValue(const wxString& szValue, long *plValue) const;
|
2004-07-16 09:09:52 -04:00
|
|
|
// set the binary value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool SetValue(const wxString& szValue, const wxMemoryBuffer& buf);
|
2004-07-16 09:09:52 -04:00
|
|
|
// return the binary value
|
2007-06-20 03:09:14 -04:00
|
|
|
bool QueryValue(const wxString& szValue, wxMemoryBuffer& buf) const;
|
1998-05-20 10:12:05 -04:00
|
|
|
|
1998-05-27 19:18:16 -04:00
|
|
|
// query existence of a key/value
|
|
|
|
// return true if value exists
|
2007-06-20 03:09:14 -04:00
|
|
|
bool HasValue(const wxString& szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if given subkey exists
|
2007-06-20 03:09:14 -04:00
|
|
|
bool HasSubKey(const wxString& szKey) const;
|
1998-05-27 19:18:16 -04:00
|
|
|
// return true if any subkeys exist
|
1999-06-26 07:10:50 -04: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 10:12:05 -04: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-15 19:26:40 -05: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-20 21:46:19 -04:00
|
|
|
// for wxRegConfig usage only: preallocate some memory for the name
|
|
|
|
void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
|
|
|
|
|
1998-05-20 10:12:05 -04:00
|
|
|
private:
|
2001-04-20 21:46:19 -04:00
|
|
|
// common part of all ctors
|
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
m_hKey = (WXHKEY) NULL;
|
|
|
|
m_dwLastError = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:26:40 -05: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 10:12:05 -04:00
|
|
|
|
1998-10-14 19:53:24 -04:00
|
|
|
WXHKEY m_hKey, // our handle
|
1998-05-20 10:12:05 -04:00
|
|
|
m_hRootKey; // handle of the top key (i.e. StdKey)
|
|
|
|
wxString m_strKey; // key name (relative to m_hRootKey)
|
|
|
|
|
2005-05-18 19:29:54 -04:00
|
|
|
AccessMode m_mode; // valid only if key is opened
|
2001-04-20 21:46:19 -04:00
|
|
|
long m_dwLastError; // last error (0 if none)
|
2005-01-15 19:26:40 -05:00
|
|
|
|
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxRegKey);
|
1998-05-20 10:12:05 -04:00
|
|
|
};
|
|
|
|
|
2007-07-21 09:01:28 -04:00
|
|
|
#endif // wxUSE_REGKEY
|
|
|
|
|
2005-01-15 19:26:40 -05:00
|
|
|
#endif // _WX_MSW_REGISTRY_H_
|
1998-05-27 19:18:16 -04:00
|
|
|
|