+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool
+wxRegKey::RenameValue(const wxString& szValueOld, const wxString& szValueNew)
+{
+ bool ok = true;
+ if ( HasValue(szValueNew) ) {
+ wxLogError(_("Registry value '%s' already exists."), szValueNew);
+
+ ok = false;
+ }
+
+ if ( !ok ||
+ !CopyValue(szValueOld, *this, szValueNew) ||
+ !DeleteValue(szValueOld) ) {
+ wxLogError(_("Failed to rename registry value '%s' to '%s'."),
+ szValueOld, szValueNew);
+
+ return false;
+ }
+
+ return true;
+}
+
+bool wxRegKey::CopyValue(const wxString& szValue,
+ wxRegKey& keyDst,
+ const wxString& szValueNew)
+{
+ wxString valueNew(szValueNew);
+ if ( valueNew.empty() ) {
+ // by default, use the same name
+ valueNew = szValue;
+ }
+
+ switch ( GetValueType(szValue) ) {
+ case Type_String:
+ {
+ wxString strVal;
+ return QueryValue(szValue, strVal) &&
+ keyDst.SetValue(valueNew, strVal);
+ }
+
+ case Type_Dword:
+ /* case Type_Dword_little_endian: == Type_Dword */
+ {
+ long dwVal;
+ return QueryValue(szValue, &dwVal) &&
+ keyDst.SetValue(valueNew, dwVal);
+ }
+
+ case Type_Binary:
+ {
+ wxMemoryBuffer buf;
+ return QueryValue(szValue,buf) &&
+ keyDst.SetValue(valueNew,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)
+ case Type_None:
+ case Type_Expand_String:
+ case Type_Dword_big_endian:
+ case Type_Link:
+ case Type_Multi_String:
+ case Type_Resource_list:
+ case Type_Full_resource_descriptor:
+ case Type_Resource_requirements_list:
+ default:
+ wxLogError(_("Can't copy values of unsupported type %d."),
+ GetValueType(szValue));
+ return false;
+ }
+}
+
+bool wxRegKey::Rename(const wxString& szNewName)
+{
+ wxCHECK_MSG( !m_strKey.empty(), false, _T("registry hives can't be renamed") );
+
+ if ( !Exists() ) {
+ wxLogError(_("Registry key '%s' does not exist, cannot rename it."),
+ GetFullName(this));
+
+ return false;
+ }
+
+ // do we stay in the same hive?
+ bool inSameHive = !wxStrchr(szNewName, REG_SEPARATOR);
+
+ // construct the full new name of the key
+ wxRegKey keyDst;
+
+ if ( inSameHive ) {
+ // rename the key to the new name under the same parent
+ wxString strKey = m_strKey.BeforeLast(REG_SEPARATOR);
+ if ( !strKey.empty() ) {
+ // don't add '\\' in the start if strFullNewName is empty
+ strKey += REG_SEPARATOR;
+ }
+
+ strKey += szNewName;
+
+ keyDst.SetName(GetStdKeyFromHkey(m_hRootKey), strKey);