X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1311c7a9bbaefda6b68eee5c32c3309f163a8861..564b260950a9a370bf9231f7432caced5156ba1b:/src/msw/registry.cpp diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 713ca417c3..4717b97ebb 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -33,8 +33,11 @@ #include "wx/log.h" // Windows headers +/* #define STRICT #define WIN32_LEAN_AND_MEAN +*/ + #include // other std headers @@ -100,7 +103,7 @@ aStdKeys[] = // removes the trailing backslash from the string if it has one static inline void RemoveTrailingSeparator(wxString& str); -// returns true if given registry key exists +// returns TRUE if given registry key exists static bool KeyExists(HKEY hRootKey, const char *szKey); // combines value and key name (uses static buffer!) @@ -253,9 +256,10 @@ void wxRegKey::SetName(const wxRegKey& keyParent, const wxString& strKey) Close(); // combine our name with parent's to get the full name - m_strKey = strKey; + m_strKey = keyParent.m_strKey; if ( !strKey.IsEmpty() && strKey[0] != REG_SEPARATOR ) m_strKey += REG_SEPARATOR; + m_strKey += strKey; RemoveTrailingSeparator(m_strKey); @@ -274,11 +278,11 @@ void wxRegKey::SetHkey(HKEY hKey) // info about the key // ---------------------------------------------------------------------------- -// returns true if the key exists +// returns TRUE if the key exists bool wxRegKey::Exists() const { // opened key has to exist, try to open it if not done yet - return IsOpened() ? true : KeyExists(m_hRootKey, m_strKey); + return IsOpened() ? TRUE : KeyExists(m_hRootKey, m_strKey); } // returns the full name of the key (prefix is abbreviated if bShortPrefix) @@ -293,6 +297,42 @@ wxString wxRegKey::GetName(bool bShortPrefix) const return str; } +bool wxRegKey::GetKeyInfo(ulong *pnSubKeys, + ulong *pnMaxKeyLen, + ulong *pnValues, + ulong *pnMaxValueLen) const +{ +#ifdef __WIN32__ + m_dwLastError = ::RegQueryInfoKey + ( + m_hKey, + NULL, // class name + NULL, // (ptr to) size of class name buffer + RESERVED, + pnSubKeys, // [out] number of subkeys + pnMaxKeyLen, // [out] max length of a subkey name + NULL, // longest subkey class name + pnValues, // [out] number of values + pnMaxValueLen, // [out] max length of a value name + NULL, // longest value data + NULL, // security descriptor + NULL // time of last modification + ); + + if ( m_dwLastError != ERROR_SUCCESS ) { + wxLogSysError(m_dwLastError, _("can't get info about registry key '%s'"), + GetName().c_str()); + return FALSE; + } + else + return TRUE; +#else // Win16 + wxFAIL_MSG("GetKeyInfo() not implemented"); + + return FALSE; +#endif +} + // ---------------------------------------------------------------------------- // operations // ---------------------------------------------------------------------------- @@ -301,16 +341,16 @@ wxString wxRegKey::GetName(bool bShortPrefix) const bool wxRegKey::Open() { if ( IsOpened() ) - return true; + return TRUE; m_dwLastError = RegOpenKey(m_hRootKey, m_strKey, &m_hKey); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't open registry key '%s'", + wxLogSysError(m_dwLastError, _("can't open registry key '%s'"), GetName().c_str()); - return false; + return FALSE; } else - return true; + return TRUE; } // creates key, failing if it exists and !bOkIfExists @@ -318,20 +358,20 @@ bool wxRegKey::Create(bool bOkIfExists) { // check for existence only if asked (i.e. order is important!) if ( !bOkIfExists && Exists() ) { - return false; + return FALSE; } if ( IsOpened() ) - return true; + return TRUE; m_dwLastError = RegCreateKey(m_hRootKey, m_strKey, &m_hKey); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't create registry key '%s'", + wxLogSysError(m_dwLastError, _("can't create registry key '%s'"), GetName().c_str()); - return false; + return FALSE; } else - return true; + return TRUE; } // close the key, it's not an error to call it when not opened @@ -340,18 +380,18 @@ bool wxRegKey::Close() if ( IsOpened() ) { m_dwLastError = RegCloseKey(m_hKey); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't close registry key '%s'", + wxLogSysError(m_dwLastError, _("can't close registry key '%s'"), GetName().c_str()); m_hKey = 0; - return false; + return FALSE; } else { m_hKey = 0; } } - return true; + return TRUE; } // ---------------------------------------------------------------------------- @@ -392,7 +432,8 @@ bool wxRegKey::DeleteSelf() m_dwLastError = RegDeleteKey(m_hRootKey, m_strKey); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't delete key '%s'", GetName().c_str()); + wxLogSysError(m_dwLastError, _("can't delete key '%s'"), + GetName().c_str()); return FALSE; } @@ -402,7 +443,7 @@ bool wxRegKey::DeleteSelf() bool wxRegKey::DeleteKey(const char *szKey) { if ( !Open() ) - return false; + return FALSE; wxRegKey key(*this, szKey); return key.DeleteSelf(); @@ -411,14 +452,14 @@ bool wxRegKey::DeleteKey(const char *szKey) bool wxRegKey::DeleteValue(const char *szValue) { if ( !Open() ) - return false; + return FALSE; #ifdef __WIN32__ m_dwLastError = RegDeleteValue(m_hKey, szValue); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't delete value '%s' from key '%s'", + wxLogSysError(m_dwLastError, _("can't delete value '%s' from key '%s'"), szValue, GetName().c_str()); - return false; + return FALSE; } #else //WIN16 // named registry values don't exist in Win16 world @@ -427,20 +468,20 @@ bool wxRegKey::DeleteValue(const char *szValue) // just set the (default and unique) value of the key to "" m_dwLastError = RegSetValue(m_hKey, NULL, REG_SZ, "", RESERVED); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't delete value of key '%s'", + wxLogSysError(m_dwLastError, _("can't delete value of key '%s'"), GetName().c_str()); - return false; + return FALSE; } #endif //WIN16/32 - return true; + return TRUE; } // ---------------------------------------------------------------------------- // access to values and subkeys // ---------------------------------------------------------------------------- -// return true if value exists +// return TRUE if value exists bool wxRegKey::HasValue(const char *szValue) const { #ifdef __WIN32__ @@ -449,14 +490,14 @@ bool wxRegKey::HasValue(const char *szValue) const NULL, NULL, NULL) == ERROR_SUCCESS; } else - return false; + return FALSE; #else // WIN16 // only unnamed value exists return IsEmpty(szValue); #endif // WIN16/32 } -// returns true if this key has any subkeys +// returns TRUE if this key has any subkeys bool wxRegKey::HasSubkeys() const { // just call GetFirstKey with dummy parameters @@ -465,13 +506,13 @@ bool wxRegKey::HasSubkeys() const return CONST_CAST GetFirstKey(str, l); } -// returns true if given subkey exists +// returns TRUE if given subkey exists bool wxRegKey::HasSubKey(const char *szKey) const { if ( CONST_CAST Open() ) return KeyExists(m_hKey, szKey); else - return false; + return FALSE; } wxRegKey::ValueType wxRegKey::GetValueType(const char *szValue) @@ -484,7 +525,7 @@ wxRegKey::ValueType wxRegKey::GetValueType(const char *szValue) m_dwLastError = RegQueryValueEx(m_hKey, szValue, RESERVED, &dwType, NULL, NULL); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't read value of key '%s'", + wxLogSysError(m_dwLastError, _("can't read value of key '%s'"), GetName().c_str()); return Type_None; } @@ -502,12 +543,12 @@ bool wxRegKey::SetValue(const char *szValue, long lValue) m_dwLastError = RegSetValueEx(m_hKey, szValue, RESERVED, REG_DWORD, (RegString)&lValue, sizeof(lValue)); if ( m_dwLastError == ERROR_SUCCESS ) - return true; + return TRUE; } - wxLogSysError(m_dwLastError, "can't set value of '%s'", + wxLogSysError(m_dwLastError, _("can't set value of '%s'"), GetFullName(this, szValue)); - return false; + return FALSE; } bool wxRegKey::QueryValue(const char *szValue, long *plValue) const @@ -518,20 +559,20 @@ bool wxRegKey::QueryValue(const char *szValue, long *plValue) const m_dwLastError = RegQueryValueEx(m_hKey, szValue, RESERVED, &dwType, pBuf, &dwSize); if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, "can't read value of key '%s'", + wxLogSysError(m_dwLastError, _("can't read value of key '%s'"), GetName().c_str()); - return false; + return FALSE; } else { // check that we read the value of right type wxASSERT_MSG( dwType == REG_DWORD, "Type mismatch in wxRegKey::QueryValue()." ); - return true; + return TRUE; } } else - return false; + return FALSE; } #endif //Win32 @@ -548,12 +589,13 @@ bool wxRegKey::QueryValue(const char *szValue, wxString& strValue) const RegString pBuf = (RegString)strValue.GetWriteBuf(dwSize); m_dwLastError = RegQueryValueEx(m_hKey, szValue, RESERVED, &dwType, pBuf, &dwSize); + strValue.UngetWriteBuf(); if ( m_dwLastError == ERROR_SUCCESS ) { // check that it was the right type wxASSERT_MSG( dwType == REG_SZ, "Type mismatch in wxRegKey::QueryValue()." ); - return true; + return TRUE; } } #else //WIN16 @@ -561,14 +603,15 @@ bool wxRegKey::QueryValue(const char *szValue, wxString& strValue) const wxASSERT( IsEmpty(szValue) ); m_dwLastError = RegQueryValue(m_hKey, 0, strValue.GetWriteBuf(256), &l); + strValue.UngetWriteBuf(); if ( m_dwLastError == ERROR_SUCCESS ) - return true; + return TRUE; #endif //WIN16/32 } - wxLogSysError(m_dwLastError, "can't read value of '%s'", + wxLogSysError(m_dwLastError, _("can't read value of '%s'"), GetFullName(this, szValue)); - return false; + return FALSE; } bool wxRegKey::SetValue(const char *szValue, const wxString& strValue) @@ -579,20 +622,20 @@ bool wxRegKey::SetValue(const char *szValue, const wxString& strValue) (RegString)strValue.c_str(), strValue.Len() + 1); if ( m_dwLastError == ERROR_SUCCESS ) - return true; + return TRUE; #else //WIN16 // named registry values don't exist in Win16 wxASSERT( IsEmpty(szValue) ); m_dwLastError = RegSetValue(m_hKey, NULL, REG_SZ, strValue, NULL); if ( m_dwLastError == ERROR_SUCCESS ) - return true; + return TRUE; #endif //WIN16/32 } - wxLogSysError(m_dwLastError, "can't set value of '%s'", + wxLogSysError(m_dwLastError, _("can't set value of '%s'"), GetFullName(this, szValue)); - return false; + return FALSE; } wxRegKey::operator wxString() const @@ -611,7 +654,7 @@ wxRegKey::operator wxString() const bool wxRegKey::GetFirstValue(wxString& strValueName, long& lIndex) { if ( !Open() ) - return false; + return FALSE; lIndex = 0; return GetNextValue(strValueName, lIndex); @@ -623,7 +666,7 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const // are we already at the end of enumeration? if ( lIndex == -1 ) - return false; + return FALSE; #ifdef __WIN32__ char szValueName[1024]; // @@ use RegQueryInfoKey... @@ -643,11 +686,11 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const lIndex = -1; } else { - wxLogSysError(m_dwLastError, "can't enumerate values of key '%s'", + wxLogSysError(m_dwLastError, _("can't enumerate values of key '%s'"), GetName().c_str()); } - return false; + return FALSE; } strValueName = szValueName; @@ -659,13 +702,13 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const strValueName.Empty(); #endif - return true; + return TRUE; } bool wxRegKey::GetFirstKey(wxString& strKeyName, long& lIndex) { if ( !Open() ) - return false; + return FALSE; lIndex = 0; return GetNextKey(strKeyName, lIndex); @@ -677,7 +720,7 @@ bool wxRegKey::GetNextKey(wxString& strKeyName, long& lIndex) const // are we already at the end of enumeration? if ( lIndex == -1 ) - return false; + return FALSE; char szKeyName[_MAX_PATH + 1]; m_dwLastError = RegEnumKey(m_hKey, lIndex++, szKeyName, WXSIZEOF(szKeyName)); @@ -688,15 +731,15 @@ bool wxRegKey::GetNextKey(wxString& strKeyName, long& lIndex) const lIndex = -1; } else { - wxLogSysError(m_dwLastError, "can't enumerate subkeys of key '%s'", + wxLogSysError(m_dwLastError, _("can't enumerate subkeys of key '%s'"), GetName().c_str()); } - return false; + return FALSE; } strKeyName = szKeyName; - return true; + return TRUE; } // ============================================================================ @@ -707,10 +750,10 @@ bool KeyExists(HKEY hRootKey, const char *szKey) HKEY hkeyDummy; if ( RegOpenKey(hRootKey, szKey, &hkeyDummy) == ERROR_SUCCESS ) { RegCloseKey(hkeyDummy); - return true; + return TRUE; } else - return false; + return FALSE; } const char *GetFullName(const wxRegKey *pKey, const char *szValue)