X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14f355c2b5c71fc7c3d680aea366582d2ac60f7b..7848088476db284a94f19eeb24411b45d676ac46:/src/msw/registry.cpp diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 8305c63eb8..b2a25f4391 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -28,8 +28,6 @@ #include "wx/intl.h" #include "wx/log.h" -#ifndef __WIN16__ - // Windows headers /* #define STRICT @@ -321,8 +319,6 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, size_t *pnValues, size_t *pnMaxValueLen) const { -#if defined(__WIN32__) - // old gcc headers incorrectly prototype RegQueryInfoKey() #if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__) #define REG_PARAM (size_t *) @@ -362,11 +358,6 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, } return TRUE; -#else // Win16 - wxFAIL_MSG("GetKeyInfo() not implemented"); - - return FALSE; -#endif } // ---------------------------------------------------------------------------- @@ -374,7 +365,7 @@ bool wxRegKey::GetKeyInfo(size_t *pnSubKeys, // ---------------------------------------------------------------------------- // opens key (it's not an error to call Open() on an already opened key) -bool wxRegKey::Open() +bool wxRegKey::Open(AccessMode mode) { if ( IsOpened() ) return TRUE; @@ -385,7 +376,7 @@ bool wxRegKey::Open() (HKEY) m_hRootKey, m_strKey, RESERVED, - KEY_ALL_ACCESS, + mode == Read ? KEY_READ : KEY_ALL_ACCESS, &tmpKey ); @@ -683,7 +674,9 @@ bool wxRegKey::DeleteSelf() Close(); m_dwLastError = RegDeleteKey((HKEY) m_hRootKey, m_strKey); - if ( m_dwLastError != ERROR_SUCCESS ) { + // deleting a key which doesn't exist is not considered an error + if ( m_dwLastError != ERROR_SUCCESS && + m_dwLastError != ERROR_FILE_NOT_FOUND ) { wxLogSysError(m_dwLastError, _("Can't delete key '%s'"), GetName().c_str()); return FALSE; @@ -706,7 +699,6 @@ bool wxRegKey::DeleteValue(const wxChar *szValue) if ( !Open() ) return FALSE; -#if defined(__WIN32__) m_dwLastError = RegDeleteValue((HKEY) m_hKey, WXSTRINGCAST szValue); // deleting a value which doesn't exist is not considered an error @@ -716,18 +708,6 @@ bool wxRegKey::DeleteValue(const wxChar *szValue) szValue, GetName().c_str()); return FALSE; } -#else //WIN16 - // named registry values don't exist in Win16 world - wxASSERT( IsEmpty(szValue) ); - - // just set the (default and unique) value of the key to "" - m_dwLastError = RegSetValue((HKEY) m_hKey, NULL, REG_SZ, "", RESERVED); - if ( m_dwLastError != ERROR_SUCCESS ) { - wxLogSysError(m_dwLastError, _("Can't delete value of key '%s'"), - GetName().c_str()); - return FALSE; - } -#endif //WIN16/32 return TRUE; } @@ -742,7 +722,6 @@ bool wxRegKey::HasValue(const wxChar *szValue) const // this function should be silent, so suppress possible messages from Open() wxLogNull nolog; - #ifdef __WIN32__ if ( !CONST_CAST Open() ) return FALSE; @@ -751,10 +730,6 @@ bool wxRegKey::HasValue(const wxChar *szValue) const RESERVED, NULL, NULL, NULL); return dwRet == ERROR_SUCCESS; - #else // WIN16 - // only unnamed value exists - return IsEmpty(szValue); - #endif // WIN16/32 } // returns TRUE if this key has any values @@ -795,7 +770,6 @@ bool wxRegKey::HasSubKey(const wxChar *szKey) const wxRegKey::ValueType wxRegKey::GetValueType(const wxChar *szValue) const { - #ifdef __WIN32__ if ( ! CONST_CAST Open() ) return Type_None; @@ -809,9 +783,6 @@ wxRegKey::ValueType wxRegKey::GetValueType(const wxChar *szValue) const } return (ValueType)dwType; - #else //WIN16 - return IsEmpty(szValue) ? Type_String : Type_None; - #endif //WIN16/32 } #ifdef __WIN32__ @@ -860,7 +831,7 @@ bool wxRegKey::QueryValue(const wxChar *szValue, bool raw) const { if ( CONST_CAST Open() ) { - #ifdef __WIN32__ + // first get the type and size of the data DWORD dwType, dwSize; m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, @@ -914,15 +885,6 @@ bool wxRegKey::QueryValue(const wxChar *szValue, return TRUE; } } - #else //WIN16 - // named registry values don't exist in Win16 - wxASSERT( IsEmpty(szValue) ); - - m_dwLastError = RegQueryValue((HKEY) m_hKey, 0, strValue.GetWriteBuf(256), &l); - strValue.UngetWriteBuf(); - if ( m_dwLastError == ERROR_SUCCESS ) - return TRUE; - #endif //WIN16/32 } wxLogSysError(m_dwLastError, _("Can't read value of '%s'"), @@ -933,20 +895,11 @@ bool wxRegKey::QueryValue(const wxChar *szValue, bool wxRegKey::SetValue(const wxChar *szValue, const wxString& strValue) { if ( CONST_CAST Open() ) { -#if defined( __WIN32__) m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ, (RegString)strValue.c_str(), (strValue.Len() + 1)*sizeof(wxChar)); if ( m_dwLastError == ERROR_SUCCESS ) return TRUE; -#else //WIN16 - // named registry values don't exist in Win16 - wxASSERT( IsEmpty(szValue) ); - - m_dwLastError = RegSetValue((HKEY) m_hKey, NULL, REG_SZ, strValue, NULL); - if ( m_dwLastError == ERROR_SUCCESS ) - return TRUE; -#endif //WIN16/32 } wxLogSysError(m_dwLastError, _("Can't set value of '%s'"), @@ -984,7 +937,6 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const if ( lIndex == -1 ) return FALSE; -#if defined( __WIN32__) wxChar szValueName[1024]; // @@ use RegQueryInfoKey... DWORD dwValueLen = WXSIZEOF(szValueName); @@ -1009,13 +961,6 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const } strValueName = szValueName; -#else //WIN16 - // only one unnamed value - wxASSERT( lIndex == 0 ); - - lIndex = -1; - strValueName.Empty(); -#endif return TRUE; } @@ -1095,7 +1040,7 @@ bool KeyExists(WXHKEY hRootKey, const wxChar *szKey) (HKEY)hRootKey, szKey, RESERVED, - KEY_ALL_ACCESS, + KEY_READ, // we might not have enough rights for rw access &hkeyDummy ) == ERROR_SUCCESS ) { @@ -1123,6 +1068,3 @@ void RemoveTrailingSeparator(wxString& str) str.Truncate(str.Len() - 1); } -#endif - // __WIN16__ -