X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2432b92dd7a837db13d3938a56c1959decd03203..c16e5a9271ab576a76c8537b67e0f5e25f90bc67:/src/msw/registry.cpp?ds=sidebyside diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index bb51ed0337..099b376cfd 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -27,9 +27,10 @@ #include "wx/string.h" #include "wx/intl.h" #include "wx/log.h" - #include "wx/config.h" // for wxExpandEnvVars +#ifndef __WIN16__ + // Windows headers /* #define STRICT @@ -313,7 +314,7 @@ bool wxRegKey::GetKeyInfo(ulong *pnSubKeys, ulong *pnMaxValueLen) const #endif { -#ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__TWIN32__) m_dwLastError = ::RegQueryInfoKey ( (HKEY) m_hKey, @@ -426,6 +427,18 @@ bool wxRegKey::DeleteSelf() } } + // prevent a buggy program from erasing one of the root registry keys or an + // immediate subkey (i.e. one which doesn't have '\\' inside) of any other + // key except HKCR (HKCR has some "deleteable" subkeys) + if ( m_strKey.IsEmpty() || (m_hRootKey != HKCR && + m_strKey.Find(REG_SEPARATOR) == wxNOT_FOUND) ) { + wxLogError(_("Registry key '%s' is needed for normal system operation,\n" + "deleting it will leave your system in unusable state:\n" + "operation aborted."), GetFullName(this)); + + return FALSE; + } + // we can't delete keys while enumerating because it confuses GetNextKey, so // we first save the key names and then delete them all wxArrayString astrSubkeys; @@ -473,7 +486,7 @@ bool wxRegKey::DeleteValue(const char *szValue) if ( !Open() ) return FALSE; - #ifdef __WIN32__ +#if defined(__WIN32__) && !defined(__TWIN32__) m_dwLastError = RegDeleteValue((HKEY) m_hKey, (char*) (const char*) szValue); if ( m_dwLastError != ERROR_SUCCESS ) { wxLogSysError(m_dwLastError, _("can't delete value '%s' from key '%s'"), @@ -543,10 +556,10 @@ bool wxRegKey::HasSubKey(const char *szKey) const return FALSE; } -wxRegKey::ValueType wxRegKey::GetValueType(const char *szValue) +wxRegKey::ValueType wxRegKey::GetValueType(const char *szValue) const { #ifdef __WIN32__ - if ( !Open() ) + if ( ! CONST_CAST Open() ) return Type_None; DWORD dwType; @@ -567,6 +580,10 @@ wxRegKey::ValueType wxRegKey::GetValueType(const char *szValue) #ifdef __WIN32__ bool wxRegKey::SetValue(const char *szValue, long lValue) { +#ifdef __TWIN32__ + wxFAIL_MSG("RegSetValueEx not implemented by TWIN32"); + return FALSE; +#else if ( CONST_CAST Open() ) { m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_DWORD, (RegString)&lValue, sizeof(lValue)); @@ -577,6 +594,7 @@ bool wxRegKey::SetValue(const char *szValue, long lValue) wxLogSysError(m_dwLastError, _("can't set value of '%s'"), GetFullName(this, szValue)); return FALSE; +#endif } bool wxRegKey::QueryValue(const char *szValue, long *plValue) const @@ -645,7 +663,7 @@ bool wxRegKey::QueryValue(const char *szValue, wxString& strValue) const bool wxRegKey::SetValue(const char *szValue, const wxString& strValue) { if ( CONST_CAST Open() ) { - #ifdef __WIN32__ +#if defined( __WIN32__) && !defined(__TWIN32__) m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ, (RegString)strValue.c_str(), strValue.Len() + 1); @@ -696,7 +714,7 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const if ( lIndex == -1 ) return FALSE; - #ifdef __WIN32__ +#if defined( __WIN32__) && !defined(__TWIN32__) char szValueName[1024]; // @@ use RegQueryInfoKey... DWORD dwValueLen = WXSIZEOF(szValueName); @@ -770,6 +788,21 @@ bool wxRegKey::GetNextKey(wxString& strKeyName, long& lIndex) const return TRUE; } +// returns TRUE if the value contains a number (else it's some string) +bool wxRegKey::IsNumericValue(const char *szValue) const + { + ValueType type = GetValueType(szValue); + switch ( type ) { + case Type_Dword: + case Type_Dword_little_endian: + case Type_Dword_big_endian: + return TRUE; + + default: + return FALSE; + } + } + // ============================================================================ // implementation of global private functions // ============================================================================ @@ -799,3 +832,7 @@ void RemoveTrailingSeparator(wxString& str) if ( !str.IsEmpty() && str.Last() == REG_SEPARATOR ) str.Truncate(str.Len() - 1); } + +#endif + // __WIN16__ +