X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/655719367ac5e131d9642e5783f3ecf64d1a3385..143318ddbb005602b600216cca621439b771f889:/src/msw/registry.cpp diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 427b33f431..175242651c 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -55,6 +55,7 @@ // some registry functions don't like signed chars typedef unsigned char *RegString; +typedef BYTE* RegBinary; // ---------------------------------------------------------------------------- // constants @@ -491,14 +492,19 @@ bool wxRegKey::CopyValue(const wxChar *szValue, keyDst.SetValue(szValueNew, dwVal); } +#ifdef __WIN32__ + case Type_Binary: + { + wxMemoryBuffer buf; + return QueryValue(szValue,buf) && + keyDst.SetValue(szValueNew,buf); + } // these types are unsupported because I am not sure about how // exactly they should be copied and because they shouldn't // occur among the application keys (supposedly created with // this class) -#ifdef __WIN32__ case Type_None: case Type_Expand_String: - case Type_Binary: case Type_Dword_big_endian: case Type_Link: case Type_Multi_String: @@ -601,6 +607,10 @@ bool wxRegKey::Copy(wxRegKey& keyDst) if ( ok ) bCont = GetNextKey(strKey, lIndex); + else + wxLogError(_("Failed to copy the registry subkey '%s' to '%s'."), + GetFullName(&key), keyName.c_str()); + } // copy all values @@ -620,7 +630,8 @@ bool wxRegKey::Copy(wxRegKey& keyDst) } if ( !ok ) { - wxLogError(_("Failed to copy the contents of registry key '%s' to '%s'."), GetFullName(this), GetFullName(&keyDst)); + wxLogError(_("Failed to copy the contents of registry key '%s' to '%s'."), + GetFullName(this), GetFullName(&keyDst)); } return ok; @@ -645,7 +656,8 @@ bool wxRegKey::DeleteSelf() if ( m_strKey.IsEmpty() || ((m_hRootKey != (WXHKEY) aStdKeys[HKCR].hkey) && (m_strKey.Find(REG_SEPARATOR) == wxNOT_FOUND)) ) { - wxLogError(_("Registry key '%s' is needed for normal system operation,\ndeleting it will leave your system in unusable state:\noperation aborted."), GetFullName(this)); + wxLogError(_("Registry key '%s' is needed for normal system operation,\ndeleting it will leave your system in unusable state:\noperation aborted."), + GetFullName(this)); return FALSE; } @@ -722,7 +734,7 @@ bool wxRegKey::HasValue(const wxChar *szValue) const // this function should be silent, so suppress possible messages from Open() wxLogNull nolog; - if ( !CONST_CAST Open() ) + if ( !CONST_CAST Open(Read) ) return FALSE; LONG dwRet = ::RegQueryValueEx((HKEY) m_hKey, @@ -762,7 +774,7 @@ bool wxRegKey::HasSubKey(const wxChar *szKey) const // this function should be silent, so suppress possible messages from Open() wxLogNull nolog; - if ( !CONST_CAST Open() ) + if ( !CONST_CAST Open(Read) ) return FALSE; return KeyExists(m_hKey, szKey); @@ -770,7 +782,7 @@ bool wxRegKey::HasSubKey(const wxChar *szKey) const wxRegKey::ValueType wxRegKey::GetValueType(const wxChar *szValue) const { - if ( ! CONST_CAST Open() ) + if ( ! CONST_CAST Open(Read) ) return Type_None; DWORD dwType; @@ -802,7 +814,7 @@ bool wxRegKey::SetValue(const wxChar *szValue, long lValue) bool wxRegKey::QueryValue(const wxChar *szValue, long *plValue) const { - if ( CONST_CAST Open() ) { + if ( CONST_CAST Open(Read) ) { DWORD dwType, dwSize = sizeof(DWORD); RegString pBuf = (RegString)plValue; m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, @@ -824,13 +836,68 @@ bool wxRegKey::QueryValue(const wxChar *szValue, long *plValue) const return FALSE; } +bool wxRegKey::SetValue(const wxChar *szValue,const wxMemoryBuffer& buffer) +{ +#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_BINARY, + (RegBinary)buffer.GetData(),buffer.GetDataLen()); + if ( m_dwLastError == ERROR_SUCCESS ) + return TRUE; + } + + wxLogSysError(m_dwLastError, _("Can't set value of '%s'"), + GetFullName(this, szValue)); + return FALSE; +#endif +} + +bool wxRegKey::QueryValue(const wxChar *szValue, wxMemoryBuffer& buffer) const +{ + if ( CONST_CAST Open() ) { + // first get the type and size of the data + DWORD dwType, dwSize; + m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, + &dwType, NULL, &dwSize); + + if ( m_dwLastError == ERROR_SUCCESS ) { + if ( dwSize ) { + const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize); + m_dwLastError = RegQueryValueEx((HKEY) m_hKey, + WXSTRINGCAST szValue, + RESERVED, + &dwType, + pBuf, + &dwSize); + buffer.UngetWriteBuf(dwSize); + } else { + buffer.SetDataLen(0); + } + } + + + if ( m_dwLastError != ERROR_SUCCESS ) { + wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"), + GetName().c_str()); + return FALSE; + } + return TRUE; + } + return FALSE; +} + + + #endif //Win32 bool wxRegKey::QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const { - if ( CONST_CAST Open() ) { + if ( CONST_CAST Open(Read) ) { // first get the type and size of the data DWORD dwType, dwSize; @@ -873,6 +940,8 @@ bool wxRegKey::QueryValue(const wxChar *szValue, wxLogLastError(_T("ExpandEnvironmentStrings")); } } +#else + wxUnusedVar(raw); #endif // __WXWINCE__ } @@ -922,7 +991,7 @@ wxString wxRegKey::QueryDefaultValue() const bool wxRegKey::GetFirstValue(wxString& strValueName, long& lIndex) { - if ( !Open() ) + if ( !Open(Read) ) return FALSE; lIndex = 0; @@ -967,7 +1036,7 @@ bool wxRegKey::GetNextValue(wxString& strValueName, long& lIndex) const bool wxRegKey::GetFirstKey(wxString& strKeyName, long& lIndex) { - if ( !Open() ) + if ( !Open(Read) ) return FALSE; lIndex = 0;