// ---------------------------------------------------------------------------- // delete keys/values // ---------------------------------------------------------------------------- bool wxRegKey::DeleteSelf() { { wxLogNull nolog; if ( !Open() ) { // it already doesn't exist - ok! return true; } } // 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.empty() || ((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)); 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; wxString strKey; long lIndex; bool bCont = GetFirstKey(strKey, lIndex); while ( bCont ) { astrSubkeys.Add(strKey); bCont = GetNextKey(strKey, lIndex); } size_t nKeyCount = astrSubkeys.Count(); for ( size_t nKey = 0; nKey < nKeyCount; nKey++ ) { wxRegKey key(*this, astrSubkeys[nKey]); if ( !key.DeleteSelf() ) return false; } // now delete this key itself Close(); m_dwLastError = RegDeleteKey((HKEY) m_hRootKey, m_strKey.t_str()); // 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; } return true; }
// returns true if this key has any subkeys bool wxRegKey::HasSubkeys() const { // suppress possible messages from GetFirstKey() wxLogNull nolog; // just call GetFirstKey with dummy parameters wxString str; long l; return CONST_CAST GetFirstKey(str, l); }
HRESULT RegistryClassEnum::GetKey (LPTSTR lpName, const DWORD dwNameLen, PFILETIME lpftLastWriteTime, const bool fGetFirst) { if ((NULL == lpName) || (dwNameLen <= 1)) return ERROR_BAD_ARGUMENTS; DWORD cbName=dwNameLen; HRESULT hr=(fGetFirst ? GetFirstKey(lpName, &cbName, lpftLastWriteTime) : GetNextKey(lpName, &cbName, lpftLastWriteTime)); if (hr != S_OK) return hr; if (cbName >= dwNameLen) return ERROR_BUFFER_OVERFLOW; lpName[cbName] = _T('\0'); // just making sure return S_OK; }
bool wxRegKey::Copy(wxRegKey& keyDst) { bool ok = true; // copy all sub keys to the new location wxString strKey; long lIndex; bool bCont = GetFirstKey(strKey, lIndex); while ( ok && bCont ) { wxRegKey key(*this, strKey); wxString keyName; keyName << GetFullName(&keyDst) << REG_SEPARATOR << strKey; ok = key.Copy(keyName); 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 wxString strVal; bCont = GetFirstValue(strVal, lIndex); while ( ok && bCont ) { ok = CopyValue(strVal, keyDst); if ( !ok ) { wxLogSysError(m_dwLastError, _("Failed to copy registry value '%s'"), strVal.c_str()); } else { bCont = GetNextValue(strVal, lIndex); } } if ( !ok ) { wxLogError(_("Failed to copy the contents of registry key '%s' to '%s'."), GetFullName(this), GetFullName(&keyDst)); } return ok; }
char* CNWNXHashSet::OnRequest(char* gameObject, char* Request, char* Parameters) { char* presult = NULL; Log(2, "Request: \"%s\"\n", Request); Log(3, "Params: \"%s\"\n", Parameters); if (strcmp(Request, "LOOKUP") == 0) presult = Lookup(gameObject, Parameters); else if (strcmp(Request, "INSERT") == 0) presult = Insert(gameObject, Parameters); else if (strcmp(Request, "DELETE") == 0) presult = Delete(gameObject, Parameters); else if (strcmp(Request, "STATUS") == 0) presult = (char *)(iLastOperation ? "1" : "0"); else if (strcmp(Request, "VALID") == 0) presult = Valid(gameObject, Parameters); else if (strcmp(Request, "EXISTS") == 0) presult = Exists(gameObject, Parameters); else if (strcmp(Request, "GETFIRSTKEY") == 0) presult = GetFirstKey(gameObject, Parameters); else if (strcmp(Request, "GETNEXTKEY") == 0) presult = GetNextKey(gameObject, Parameters); else if (strcmp(Request, "GETCURRENTKEY") == 0) presult = GetCurrentKey(gameObject, Parameters); else if (strcmp(Request, "GETNTHKEY") == 0) presult = GetNthKey(gameObject, Parameters); else if (strcmp(Request, "HASNEXT") == 0) presult = HasNext(gameObject, Parameters); else if (strcmp(Request, "GETSIZE") == 0) presult = GetSize(gameObject, Parameters); else if (strcmp(Request, "DESTROY") == 0) presult = Destroy(gameObject, Parameters); else if (strcmp(Request, "CREATE") == 0) presult = Create(gameObject, Parameters); Log(4, "hashset returns[%s]\n", presult); // a return value of NULL tells NWNX that it shouldn't copy // any values, a non zero pointer tells NWNX that it should copy // the null terminated string pointed to by that pointer back into NWN. return presult; }
// ---------------------------------------------------------------------------- // delete keys/values // ---------------------------------------------------------------------------- bool wxRegKey::DeleteSelf() { { wxLogNull nolog; if ( !Open() ) { // it already doesn't exist - ok! return true; } } // 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.empty() || ((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)); 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; wxString strKey; long lIndex; bool bCont = GetFirstKey(strKey, lIndex); while ( bCont ) { astrSubkeys.Add(strKey); bCont = GetNextKey(strKey, lIndex); } size_t nKeyCount = astrSubkeys.Count(); for ( size_t nKey = 0; nKey < nKeyCount; nKey++ ) { wxRegKey key(*this, astrSubkeys[nKey]); if ( !key.DeleteSelf() ) return false; } // now delete this key itself Close(); // deleting a key which doesn't exist is not considered an error #if wxUSE_DYNLIB_CLASS wxDynamicLibrary dllAdvapi32(wxT("advapi32")); // Minimum supported OS for RegDeleteKeyEx: Vista, XP Pro x64, Win Server 2008, Win Server 2003 SP1 if(dllAdvapi32.HasSymbol(wxT("RegDeleteKeyEx"))) { typedef LONG (WINAPI *RegDeleteKeyEx_t)(HKEY, LPCTSTR, REGSAM, DWORD); wxDYNLIB_FUNCTION(RegDeleteKeyEx_t, RegDeleteKeyEx, dllAdvapi32); m_dwLastError = (*pfnRegDeleteKeyEx)((HKEY) m_hRootKey, m_strKey.t_str(), GetMSWViewFlags(m_viewMode), 0); // This parameter is reserved and must be zero. } else #endif // wxUSE_DYNLIB_CLASS { m_dwLastError = RegDeleteKey((HKEY) m_hRootKey, m_strKey.t_str()); } if ( m_dwLastError != ERROR_SUCCESS && m_dwLastError != ERROR_FILE_NOT_FOUND ) { wxLogSysError(m_dwLastError, _("Can't delete key '%s'"), GetName().c_str()); return false; } return true; }