2. badly famous wxRegConfig::DeleteAll() bug corrected
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1456
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// access to values and subkeys
// get value type
// 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)
// assignment operators set the default value of the key
wxRegKey& operator=(const wxString& strValue)
void MyFrame::OnDelete(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() ) {
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.");
+ }
{
m_keyLocal.Close();
m_keyGlobal.Close();
{
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();
bool bOk = m_keyLocalRoot.DeleteSelf();
+
+ // 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;
bOk = m_keyGlobalRoot.DeleteSelf();
return bOk;
+ // 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;
// 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;