// 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)
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()
{
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
}
}
+ // 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;