Esempio n. 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)));
}
Esempio n. 2
0
void Registry::setBinary(StringRange valueName, ArrayRange<const unsigned char> value, Registry::ValueKind kind) {
	assert("Empty Registry" && *this);
	assert("Invalid Registry::ValueKind" && ValueKind::_validate(kind));

	checkResult(RegSetValueExW(_handle, valueName.c_str(), 0, kind
		, value.empty() ? nullptr : value.begin(), value.size()));
}
Esempio n. 3
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);
	}
}
Esempio n. 4
0
vector<unsigned char> Registry::getBinary(StringRange valueName) const {
	assert("Empty Registry" && *this);

	DWORD type = REG_NONE;
	DWORD size = 0;
	LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
	vector<unsigned char> buffer;
	if (result == ERROR_SUCCESS && 0 < size) {
		buffer.resize(size);
		result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, buffer.data(), &size);
	}
	if (result == ERROR_FILE_NOT_FOUND) {
		throw ValueNotFoundException();
	}
	checkResult(result);
	return buffer;
}
Esempio n. 5
0
Registry Registry::createKey(StringRange keyName, bool writable) {
	assert("Empty Registry" && *this);
	assert("Empty keyName" && !keyName.empty());

	Registry key;
	checkResult(RegCreateKeyExW(_handle, keyName.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE
		, writable ? KEY_ALL_ACCESS : KEY_READ, nullptr, &key._handle, nullptr));
	return key;
}
Esempio n. 6
0
Registry Registry::openKey(StringRange keyName, bool writable) const {
	assert("Empty Registry" && *this);
	assert("Empty kKeyName" && !keyName.empty());

	Registry key;
	checkResult(RegOpenKeyExW(_handle, keyName.c_str(), 0
		, writable ? KEY_ALL_ACCESS : KEY_READ, &key._handle));
	return key;
}
Esempio n. 7
0
unsigned __int64 Registry::getQword(StringRange valueName) const {
	assert("Empty Registry" && *this);

	DWORD type = REG_NONE;
	DWORD size = 0;
	LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
	unsigned __int64 value = 0;
	if (result == ERROR_SUCCESS) {
		if (type != REG_DWORD && size != sizeof(value)) {
			throw ValueKindMismatchException();
		}
		result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, reinterpret_cast<LPBYTE>(&value), &size);
	}
	if (result == ERROR_FILE_NOT_FOUND) {
		throw ValueNotFoundException();
	}
	checkResult(result);
	return value;
}
Esempio n. 8
0
void Registry::getStringToBuffer(StringBuffer& buffer, StringRange valueName) const {
	assert("Empty Registry" && *this);

	DWORD type = REG_NONE;
	DWORD size = 0;
	LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
	if (result == ERROR_SUCCESS && 0 < size) {
		if (type != REG_SZ
		 && type != REG_EXPAND_SZ
		 && type != REG_MULTI_SZ) {
			throw ValueKindMismatchException();
		}
		int length = size / sizeof(wchar_t);
		buffer.reserveAdditionally(length);
		result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, reinterpret_cast<LPBYTE>(buffer.end()), &size);
		buffer.expandLength(length - 1);
	}
	if (result == ERROR_FILE_NOT_FOUND) {
		throw ValueNotFoundException();
	}
	checkResult(result);
}
Esempio n. 9
0
Registry::ValueKind Registry::getValueKind(StringRange valueName) const {
	assert("Empty Registry" && *this);

	ValueKind kind;
	const LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, reinterpret_cast<LPDWORD>(&kind), nullptr, nullptr);
	if (result == ERROR_FILE_NOT_FOUND) {
		return ValueKind::notFound;
	} else {
		checkResult(result);
		if (!ValueKind::_validate(kind)) {
			return ValueKind::unknown;
		}
	}
	return kind;
}
Esempio n. 10
0
void Registry::removeKey(StringRange keyName, bool recursive) {
	assert("Empty Registry" && *this);
	assert("Empty keyName" && !keyName.empty());

	if (recursive) {
		Registry key = openKey(keyName, true);
		if (key) {
			auto i = NamesIterator(key, true);
			while (i) {
				key.removeKey(*i, true);
				i.refresh();
			}
		}
	}
	checkResult(RegDeleteKeyW(_handle, keyName.c_str()));
}
Esempio n. 11
0
Icon Resource::getIcon(StringRange name, const Size& size) {
	if (locale() != Locale::invariant() && !isId(name)) {
		auto handle = static_cast<HICON>(LoadImageW(_module,  getLocalName(name, _localeName), IMAGE_ICON, size.width, size.height, LR_SHARED));
		if (handle) {
			return Icon(handle);
		}
	}
	auto handle = static_cast<HICON>(LoadImageW(_module, name.c_str(), IMAGE_ICON, size.width, size.height, LR_SHARED));
	if (!handle) {
		const DWORD errorCode = GetLastError();
		switch (errorCode) {
			case ERROR_NOT_ENOUGH_MEMORY       : throw OutOfMemoryException();
			case ERROR_RESOURCE_TYPE_NOT_FOUND :
			case ERROR_RESOURCE_NAME_NOT_FOUND : throw NotFoundException();
			default                            : assert(L"Failed to LoadImageW" && false); break;
		}
	}
	return Icon(handle);
}
Esempio n. 12
0
MemoryStream Resource::getRawData(StringRange name) {
	HRSRC resource = nullptr;
	if (locale() != Locale::invariant() && !isId(name)) {
		resource = FindResourceW(_module, getLocalName(name, _localeName), reinterpret_cast<LPWSTR>(RT_RCDATA));
	}
	if (!resource) {
		resource = FindResourceW(_module, name.c_str(), reinterpret_cast<LPWSTR>(RT_RCDATA));
	}
	if (!resource) {
		throw NotFoundException();
	}
	HGLOBAL const global = LoadResource(_module, resource);
	assert("Failed to LoadResource" && global);
	void* const buffer = LockResource(global);
	assert("Failed to LockResource" && buffer);
	const DWORD size = SizeofResource(_module, resource);
	assert(size <= INT_MAX);
	return MemoryStream(buffer, 0, size, false);
}
Esempio n. 13
0
Cursor Resource::getCursor(StringRange name) {
	if (locale() != Locale::invariant() && !isId(name)) {
		auto handle = static_cast<HCURSOR>(LoadImageW(_module, getLocalName(name, _localeName), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED));
		if (handle) {
			return Cursor(handle);
		}
	}
	auto handle = static_cast<HCURSOR>(LoadImageW(_module, name.c_str(), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED));
	if (!handle) {
		const DWORD errorCode = GetLastError();
		switch (errorCode) {
			case ERROR_NOT_ENOUGH_MEMORY       : throw OutOfMemoryException();
			case ERROR_RESOURCE_TYPE_NOT_FOUND :
			case ERROR_RESOURCE_NAME_NOT_FOUND : throw NotFoundException();
			default                            : assert(L"Failed to LoadImageW" && false); break;
		}
	}
	return Cursor(handle);
}
Esempio n. 14
0
Bitmap Resource::getBitmap(StringRange name) {
	if (locale() != Locale::invariant() && !isId(name)) {
		auto handle = static_cast<HBITMAP>(LoadImageW(_module, getLocalName(name, _localeName), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)); // まずは BITMAP リソースから探す
		if (handle) {
			return Bitmap(handle, true);
		}
	}
	auto handle = static_cast<HBITMAP>(LoadImageW(_module, name.c_str(), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)); // まずは BITMAP リソースから探す
	if (!handle) {
		const DWORD errorCode = GetLastError();
		switch (errorCode) {
			case ERROR_NOT_ENOUGH_MEMORY       : throw OutOfMemoryException();
			case ERROR_RESOURCE_TYPE_NOT_FOUND :
			case ERROR_RESOURCE_NAME_NOT_FOUND : { // 無ければ RCDATA リソースから
				auto stream = getRawData(name);
				return Bitmap(stream);
			} break;
			default                            : assert("Failed to LoadImageW" && false); break;
		}
	}
	return Bitmap(handle, true);
}
Esempio n. 15
0
void Registry::setQword(StringRange valueName, unsigned __int64 value) {
	assert("Empty Registry" && *this);

	checkResult(RegSetValueExW(_handle, valueName.c_str(), 0, ValueKind::qword
		, reinterpret_cast<const BYTE*>(&value), sizeof(value)));
}
Esempio n. 16
0
void Registry::removeValue(StringRange valueName) {
	assert("Empty Registry" && *this);

	checkResult(RegDeleteValueW(_handle, valueName.c_str()));
}
Esempio n. 17
0
RadioButton::RadioButton(Control& parent, int x, int y, int width, int height, StringRange text, bool firstOfGroup) : _checkedChanging(false) {
	attachHandle(CreateWindowExW(0, L"BUTTON", text.c_str()
		, WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | BS_AUTORADIOBUTTON | TextAlign::middleLeft | (firstOfGroup ? WS_GROUP : 0)
		, x, y, width, height, parent, nullptr,nullptr, nullptr));
	size(getPreferredSize(width, height));
}