From: Vadim Zeitlin Date: Sat, 23 Jan 1999 23:50:24 +0000 (+0000) Subject: 1. registry files corresponding to the recent registry.h changes X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/90186e524e347a3a779c928a44fb7d744b3efcf7 1. registry files corresponding to the recent registry.h changes 2. badly famous wxRegConfig::DeleteAll() bug corrected git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1456 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/registry.h b/include/wx/msw/registry.h index f2386f6594..f4694aff5c 100644 --- a/include/wx/msw/registry.h +++ b/include/wx/msw/registry.h @@ -160,7 +160,21 @@ public: // access to values and subkeys // get value type - ValueType GetValueType(const char *szValue); + ValueType GetValueType(const char *szValue) const; + // returns TRUE if the value contains a number (else it's some string) + bool 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; + } + } // assignment operators set the default value of the key wxRegKey& operator=(const wxString& strValue) diff --git a/samples/config/conftest.cpp b/samples/config/conftest.cpp index 4d485ac269..6c47dc4bd6 100644 --- a/samples/config/conftest.cpp +++ b/samples/config/conftest.cpp @@ -202,18 +202,16 @@ void MyFrame::OnAbout(wxCommandEvent&) void MyFrame::OnDelete(wxCommandEvent&) { - // VZ: it seems that DeleteAll() wreaks havoc on NT. Disabled until I - // investigate it further, do _not_ compile this code in meanwhile! - // JACS: wxRegConfig::DeleteAll is disabled, so it's safe to call DeleteAll, - // it just won't do anything useful on Win95/NT. if ( wxConfigBase::Get()->DeleteAll() ) { - wxLogMessage("Config file/registry key successfully deleted."); - - delete wxConfigBase::Set((wxConfigBase *) NULL); - wxConfigBase::DontCreateOnDemand(); - } - else - wxLogError("Deleting config file/registry key failed."); + wxLogMessage("Config file/registry key successfully deleted."); + + delete wxConfigBase::Set((wxConfigBase *) NULL); + wxConfigBase::DontCreateOnDemand(); + } + else + { + wxLogError("Deleting config file/registry key failed."); + } } MyFrame::~MyFrame() diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 4bc56da8b6..8943720d8f 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -528,16 +528,15 @@ bool wxRegConfig::DeleteAll() { m_keyLocal.Close(); m_keyGlobal.Close(); -#if 1 - wxFAIL_MSG("wxRegConfig::DeleteAll will wipe out your entire registry, so please do not use until it's fixed!"); - return FALSE; -#else + bool bOk = m_keyLocalRoot.DeleteSelf(); - if ( bOk ) + + // make sure that we opened m_keyGlobalRoot and so it has a reasonable name: + // otherwise we will delete HKEY_CLASSES_ROOT recursively + if ( bOk && m_keyGlobalRoot.IsOpened() ) bOk = m_keyGlobalRoot.DeleteSelf(); return bOk; -#endif } #endif diff --git a/src/msw/registry.cpp b/src/msw/registry.cpp index 9ab127dd67..5d59c9ee38 100644 --- a/src/msw/registry.cpp +++ b/src/msw/registry.cpp @@ -427,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;