Exemplo n.º 1
0
/*
 * CopyKey() -- worker function implementing RegDupKeyAlt().
 *
 *     Note: - assumes target does not exist (i.e., deleted by RegDupKeyAlt())
 *           - no cleanup on failure (i.e., assumes done by RegDupKeyAlt())
 */
static long
CopyKey(const char *sourceKey, const char *targetKey)
{
    long status;
    HKEY srcKey, dupKey;

    /* open source key */
    status = RegOpenKeyAlt(AFSREG_NULL_KEY, sourceKey,
			   KEY_READ, 0, &srcKey, NULL);
    if (status == ERROR_SUCCESS) {
	/* create target key */
	status = RegOpenKeyAlt(AFSREG_NULL_KEY, targetKey,
			       KEY_ALL_ACCESS, 1 /* create */, &dupKey, NULL);
	if (status == ERROR_SUCCESS) {
	    /* copy values and their data from source to target */
	    status = CopyValues(srcKey, dupKey);

	    if (status == ERROR_SUCCESS) {
		/* copy subkeys from source to target */
		status = CopySubkeys(sourceKey, srcKey, targetKey, dupKey);
	    }
	    (void) RegCloseKey(dupKey);
	}
	(void) RegCloseKey(srcKey);
    }
    return status;
}
Exemplo n.º 2
0
KeyValues *KeyValues::MakeCopy(void) const
{
	KeyValues *newKeyValue = new KeyValues(GetName());
	newKeyValue->m_iDataType = m_iDataType;

	switch (m_iDataType)
	{
		case TYPE_STRING:
		{
			if (m_sValue)
			{
				int len = Q_strlen(m_sValue);
				assert(!newKeyValue->m_sValue);
				newKeyValue->m_sValue = new char[len + 1];
				Q_memcpy(newKeyValue->m_sValue, m_sValue, len + 1);
			}

			break;
		}

		case TYPE_WSTRING:
		{
			if (m_wsValue)
			{
				int len = wcslen(m_wsValue);
				newKeyValue->m_wsValue = new wchar_t[len + 1];
				Q_memcpy(newKeyValue->m_wsValue, m_wsValue, (len + 1) * sizeof(wchar_t));
			}

			break;
		}

		case TYPE_INT:
		{
			newKeyValue->m_iValue = m_iValue;
			break;
		}

		case TYPE_FLOAT:
		{
			newKeyValue->m_flValue = m_flValue;
			break;
		}

		case TYPE_PTR:
		{
			newKeyValue->m_pValue = m_pValue;
			break;
		}

		case TYPE_COLOR:
		{
			newKeyValue->m_Color[0] = m_Color[0];
			newKeyValue->m_Color[1] = m_Color[1];
			newKeyValue->m_Color[2] = m_Color[2];
			newKeyValue->m_Color[3] = m_Color[3];
			break;
		}

		case TYPE_UINT64:
		{
			newKeyValue->m_sValue = new char[sizeof(uint64)];
			Q_memcpy(newKeyValue->m_sValue, m_sValue, sizeof(uint64));
			break;
		}
	}

	CopySubkeys(newKeyValue);
	return newKeyValue;
}