diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-11-07 10:37:53 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-07 10:37:53 +0100 |
commit | f7507aea98b1a428d02fe5c41d25ee69dd5436bb (patch) | |
tree | 49f9349a1d7441874d1cb6d4428e2bcb0d63b422 /win/rfb_win32/Registry.cxx | |
parent | 7508e9887de022e127d8fadb9f6a6bd8e9778864 (diff) | |
parent | 2b7857283b834391266e414adcff8c20f8fe3067 (diff) | |
download | tigervnc-f7507aea98b1a428d02fe5c41d25ee69dd5436bb.tar.gz tigervnc-f7507aea98b1a428d02fe5c41d25ee69dd5436bb.zip |
Merge branch 'stdexcept' of github.com:CendioOssman/tigervnc
Diffstat (limited to 'win/rfb_win32/Registry.cxx')
-rw-r--r-- | win/rfb_win32/Registry.cxx | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx index bbe15f47..47756950 100644 --- a/win/rfb_win32/Registry.cxx +++ b/win/rfb_win32/Registry.cxx @@ -54,7 +54,7 @@ RegKey::RegKey() : key(nullptr), freeKey(false), valueName(nullptr), valueNameBu RegKey::RegKey(const HKEY k) : key(nullptr), freeKey(false), valueName(nullptr), valueNameBufLen(0) { LONG result = RegOpenKeyEx(k, nullptr, 0, KEY_ALL_ACCESS, &key); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegOpenKeyEx(HKEY)", result); + throw rdr::win32_error("RegOpenKeyEx(HKEY)", result); vlog.debug("duplicated %p to %p", k, key); freeKey = true; } @@ -62,7 +62,7 @@ RegKey::RegKey(const HKEY k) : key(nullptr), freeKey(false), valueName(nullptr), RegKey::RegKey(const RegKey& k) : key(nullptr), freeKey(false), valueName(nullptr), valueNameBufLen(0) { LONG result = RegOpenKeyEx(k.key, nullptr, 0, KEY_ALL_ACCESS, &key); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegOpenKeyEx(RegKey&)", result); + throw rdr::win32_error("RegOpenKeyEx(RegKey&)", result); vlog.debug("duplicated %p to %p", k.key, key); freeKey = true; } @@ -86,7 +86,7 @@ bool RegKey::createKey(const RegKey& root, const char* name) { LONG result = RegCreateKey(root.key, name, &key); if (result != ERROR_SUCCESS) { vlog.error("RegCreateKey(%p, %s): %lx", root.key, name, result); - throw rdr::Win32Exception("RegCreateKeyEx", result); + throw rdr::win32_error("RegCreateKeyEx", result); } vlog.debug("createKey(%p,%s) = %p", root.key, name, key); freeKey = true; @@ -97,7 +97,7 @@ void RegKey::openKey(const RegKey& root, const char* name, bool readOnly) { close(); LONG result = RegOpenKeyEx(root.key, name, 0, readOnly ? KEY_READ : KEY_ALL_ACCESS, &key); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegOpenKeyEx (open)", result); + throw rdr::win32_error("RegOpenKeyEx (open)", result); vlog.debug("openKey(%p,%s,%s) = %p", root.key, name, readOnly ? "ro" : "rw", key); freeKey = true; @@ -109,7 +109,7 @@ void RegKey::setDACL(const PACL acl, bool inherit) { DACL_SECURITY_INFORMATION | (inherit ? UNPROTECTED_DACL_SECURITY_INFORMATION : PROTECTED_DACL_SECURITY_INFORMATION), nullptr, nullptr, acl, nullptr)) != ERROR_SUCCESS) - throw rdr::Win32Exception("RegKey::setDACL failed", result); + throw rdr::win32_error("RegKey::setDACL failed", result); } void RegKey::close() { @@ -123,19 +123,19 @@ void RegKey::close() { void RegKey::deleteKey(const char* name) const { LONG result = RegDeleteKey(key, name); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegDeleteKey", result); + throw rdr::win32_error("RegDeleteKey", result); } void RegKey::deleteValue(const char* name) const { LONG result = RegDeleteValue(key, name); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegDeleteValue", result); + throw rdr::win32_error("RegDeleteValue", result); } void RegKey::awaitChange(bool watchSubTree, DWORD filter, HANDLE event) const { LONG result = RegNotifyChangeKeyValue(key, watchSubTree, filter, event, event != nullptr); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegNotifyChangeKeyValue", result); + throw rdr::win32_error("RegNotifyChangeKeyValue", result); } @@ -144,22 +144,22 @@ RegKey::operator HKEY() const {return key;} void RegKey::setExpandString(const char* valname, const char* value) const { LONG result = RegSetValueEx(key, valname, 0, REG_EXPAND_SZ, (const BYTE*)value, (strlen(value)+1)*sizeof(char)); - if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setExpandString", result); + if (result != ERROR_SUCCESS) throw rdr::win32_error("setExpandString", result); } void RegKey::setString(const char* valname, const char* value) const { LONG result = RegSetValueEx(key, valname, 0, REG_SZ, (const BYTE*)value, (strlen(value)+1)*sizeof(char)); - if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setString", result); + if (result != ERROR_SUCCESS) throw rdr::win32_error("setString", result); } void RegKey::setBinary(const char* valname, const void* value, size_t length) const { LONG result = RegSetValueEx(key, valname, 0, REG_BINARY, (const BYTE*)value, length); - if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setBinary", result); + if (result != ERROR_SUCCESS) throw rdr::win32_error("setBinary", result); } void RegKey::setInt(const char* valname, int value) const { LONG result = RegSetValueEx(key, valname, 0, REG_DWORD, (const BYTE*)&value, sizeof(value)); - if (result != ERROR_SUCCESS) throw rdr::Win32Exception("setInt", result); + if (result != ERROR_SUCCESS) throw rdr::win32_error("setInt", result); } void RegKey::setBool(const char* valname, bool value) const { @@ -173,7 +173,7 @@ std::string RegKey::getString(const char* valname) const { std::string RegKey::getString(const char* valname, const char* def) const { try { return getString(valname); - } catch(rdr::Exception&) { + } catch(std::exception&) { return def; } } @@ -185,7 +185,7 @@ std::vector<uint8_t> RegKey::getBinary(const char* valname) const { std::vector<uint8_t> RegKey::getBinary(const char* valname, const uint8_t* def, size_t deflen) const { try { return getBinary(valname); - } catch(rdr::Exception&) { + } catch(std::exception&) { std::vector<uint8_t> out(deflen); memcpy(out.data(), def, deflen); return out; @@ -198,7 +198,7 @@ int RegKey::getInt(const char* valname) const { int RegKey::getInt(const char* valname, int def) const { try { return getInt(valname); - } catch(rdr::Exception&) { + } catch(std::exception&) { return def; } } @@ -214,11 +214,11 @@ std::string RegKey::getRepresentation(const char* valname) const { DWORD type, length; LONG result = RegQueryValueEx(key, valname, nullptr, &type, nullptr, &length); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("get registry value length", result); + throw rdr::win32_error("get registry value length", result); std::vector<uint8_t> data(length); result = RegQueryValueEx(key, valname, nullptr, &type, (BYTE*)data.data(), &length); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("get registry value", result); + throw rdr::win32_error("get registry value", result); switch (type) { case REG_BINARY: @@ -243,18 +243,18 @@ std::string RegKey::getRepresentation(const char* valname) const { std::string str((char*)data.data(), length); DWORD required = ExpandEnvironmentStrings(str.c_str(), nullptr, 0); if (required==0) - throw rdr::Win32Exception("ExpandEnvironmentStrings", GetLastError()); + throw rdr::win32_error("ExpandEnvironmentStrings", GetLastError()); std::vector<char> expanded(required); length = ExpandEnvironmentStrings(str.c_str(), expanded.data(), required); if (required<length) - throw rdr::Exception("unable to expand environment strings"); + throw std::runtime_error("unable to expand environment strings"); return expanded.data(); } else { return ""; } } default: - throw rdr::Exception("unsupported registry type"); + throw std::logic_error("unsupported registry type"); } } @@ -262,7 +262,7 @@ bool RegKey::isValue(const char* valname) const { try { getRepresentation(valname); return true; - } catch(rdr::Exception&) { + } catch(std::exception&) { return false; } } @@ -271,7 +271,7 @@ const char* RegKey::getValueName(int i) { DWORD maxValueNameLen; LONG result = RegQueryInfoKey(key, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &maxValueNameLen, nullptr, nullptr, nullptr); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegQueryInfoKey", result); + throw rdr::win32_error("RegQueryInfoKey", result); if (valueNameBufLen < maxValueNameLen + 1) { valueNameBufLen = maxValueNameLen + 1; delete [] valueName; @@ -281,7 +281,7 @@ const char* RegKey::getValueName(int i) { result = RegEnumValue(key, i, valueName, &length, nullptr, nullptr, nullptr, nullptr); if (result == ERROR_NO_MORE_ITEMS) return nullptr; if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegEnumValue", result); + throw rdr::win32_error("RegEnumValue", result); return valueName; } @@ -289,7 +289,7 @@ const char* RegKey::getKeyName(int i) { DWORD maxValueNameLen; LONG result = RegQueryInfoKey(key, nullptr, nullptr, nullptr, nullptr, &maxValueNameLen, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegQueryInfoKey", result); + throw rdr::win32_error("RegQueryInfoKey", result); if (valueNameBufLen < maxValueNameLen + 1) { valueNameBufLen = maxValueNameLen + 1; delete [] valueName; @@ -299,6 +299,6 @@ const char* RegKey::getKeyName(int i) { result = RegEnumKeyEx(key, i, valueName, &length, nullptr, nullptr, nullptr, nullptr); if (result == ERROR_NO_MORE_ITEMS) return nullptr; if (result != ERROR_SUCCESS) - throw rdr::Win32Exception("RegEnumKey", result); + throw rdr::win32_error("RegEnumKey", result); return valueName; } |