예제 #1
0
void Registry::setString(StringRange valueName, StringRange value, Registry::ValueKind kind) {
	assert("Empty Registry" && *this);
	assert("Invalid Registry::ValueKind" && (kind == ValueKind::string || kind == ValueKind::expandString || kind == ValueKind::multiString));

	checkResult(RegSetValueExW(_handle, valueName.c_str(), 0, kind
		, reinterpret_cast<const BYTE*>(value.c_str()), value.length() * sizeof(wchar_t)));
}
예제 #2
0
Registry::Registry(StringRange path, bool writable) : _handle(nullptr) {
	assert("Empty path" && !path.empty());
	int rootKeyNameEnd = String::refer(path).indexOf(L'\\');
	StringRange subKeyName = L"";
	if (rootKeyNameEnd == -1) {
		rootKeyNameEnd = path.length();
	} else {
		subKeyName  = StringRange(path.c_str() + rootKeyNameEnd + 1);
	}
	if (!rootKeyNameEnd) {
		assert("Invalid Registry root key name" && false);
	} else if (!String::compare(path, 0, L"HKEY_CLASSES_ROOT", 0, rootKeyNameEnd)) {
		*this = Registry::classesRoot();
	} else if (!String::compare(path, 0, L"HKEY_CURRENT_CONFIG", 0, rootKeyNameEnd)) {
		*this = Registry::currentConfig();
	} else if (!String::compare(path, 0, L"HKEY_CURRENT_USER", 0, rootKeyNameEnd)) {
		*this = Registry::currentUser();
	} else if (!String::compare(path, 0, L"HKEY_LOCAL_MACHINE", 0, rootKeyNameEnd)) {
		*this = Registry::localMachine();
	} else if (!String::compare(path, 0, L"HKEY_USERS", 0, rootKeyNameEnd)) {
		*this = Registry::users();
	} else {
		assert("Invalid Registry root key name" && false);
	}
	if (!subKeyName.empty()) {
		*this = openKey(subKeyName, writable);
	}
}