45 auto result = RegOpenCurrentUser(KEY_ALL_ACCESS, &
mKeyHandle);
47 if (result != ERROR_SUCCESS)
50 "Failed to create registry key: %s", wxSysErrorMsgStr(result));
51 throw std::exception(
"Failed to create registry key");
58 RegOpenKeyExW(parent,
name.c_str(), 0, KEY_ALL_ACCESS, &
mKeyHandle);
60 if (result == ERROR_FILE_NOT_FOUND)
63 if (result != ERROR_SUCCESS)
65 wxLogDebug(
"Failed to open registry key: %s", wxSysErrorMsgStr(result));
66 throw std::exception(
"Failed to open registry key");
83 void SetValue(
const wchar_t* subKey,
const std::wstring& value)
85 auto result = RegSetValueExW(
87 reinterpret_cast<const BYTE*
>(value.c_str()),
88 (value.size() + 1) *
sizeof(
wchar_t));
90 if (result != ERROR_SUCCESS)
93 "Failed to set value to a registry key: %s", wxSysErrorMsgStr(result));
94 throw std::exception(
"Failed to set value to a registry key");
106 constexpr size_t fileNameBufferSize = MAX_PATH + 1;
107 wchar_t filenameBuffer[fileNameBufferSize] = { 0 };
109 const size_t fileNameLength =
110 GetModuleFileNameW(
nullptr, filenameBuffer, fileNameBufferSize);
113 if (fileNameLength == fileNameBufferSize)
124 schemaKey.
SetValue(L
"", L
"URL:" + schema + L
" Protocol");
125 schemaKey.
SetValue(L
"URL Protocol", L
"");
127 const std::wstring filename(filenameBuffer);
130 iconKey.
SetValue(L
"", filename + std::wstring(L
",1"));
136 commandKey.
SetValue(L
"", L
"\"" + filename + L
"\" -u \"%1\"");
Declare functions to perform UTF-8 to std::wstring conversions.
void SetValue(const wchar_t *subKey, const std::wstring &value)
RegistryKey(HKEY parent, const std::wstring &name)
RegistryKey(const RegistryKey &)=delete
RegistryKey & operator=(const RegistryKey &)=delete
RegistryKey(const RegistryKey &parent, const std::wstring &name)
std::wstring ToWString(const std::string &str)
void SetSchemaRegistrar(std::function< bool(std::string_view)> registrar)