Commit 73faa990 authored by captainwong's avatar captainwong

update for unicode; re-format

parent e91a1a4a
......@@ -60,11 +60,11 @@ class RegKey;
// Wrappers for getting registry values
//
DWORD RegGetDword (HKEY hKey, const std::wstring& subKey, const std::wstring& value);
ULONGLONG RegGetQword (HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::wstring RegGetString (HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::vector<std::wstring> RegGetMultiString (HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::vector<BYTE> RegGetBinary (HKEY hKey, const std::wstring& subKey, const std::wstring& value);
DWORD RegGetDword(HKEY hKey, const std::wstring& subKey, const std::wstring& value);
ULONGLONG RegGetQword(HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::vector<std::wstring> RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& value);
std::vector<BYTE> RegGetBinary(HKEY hKey, const std::wstring& subKey, const std::wstring& value);
//
......@@ -162,8 +162,7 @@ public:
//
// Prevent self-move-assign
//
if ((this != &other) && (m_hKey != other.m_hKey))
{
if ((this != &other) && (m_hKey != other.m_hKey)) {
Close();
//
......@@ -203,8 +202,7 @@ public:
//
void Close() noexcept
{
if (IsValid())
{
if (IsValid()) {
::RegCloseKey(m_hKey);
m_hKey = nullptr;
}
......@@ -255,8 +253,7 @@ public:
//
// Prevent self-attach
//
if (m_hKey != hKey)
{
if (m_hKey != hKey) {
Close();
//
......@@ -358,7 +355,7 @@ inline DWORD RegGetDword(HKEY hKey, const std::wstring& subKey, const std::wstri
//
DWORD data{};
DWORD dataSize = sizeof(data);
LONG retCode = ::RegGetValue(
LONG retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -366,8 +363,7 @@ inline DWORD RegGetDword(HKEY hKey, const std::wstring& subKey, const std::wstri
nullptr,
&data,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read DWORD from registry.", retCode };
}
......@@ -382,7 +378,7 @@ inline ULONGLONG RegGetQword(HKEY hKey, const std::wstring& subKey, const std::w
//
ULONGLONG data{};
DWORD dataSize = sizeof(data);
LONG retCode = ::RegGetValue(
LONG retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -390,8 +386,7 @@ inline ULONGLONG RegGetQword(HKEY hKey, const std::wstring& subKey, const std::w
nullptr,
&data,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read QWORD from registry.", retCode };
}
......@@ -405,7 +400,7 @@ inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const st
// Request the size of the string, in bytes
//
DWORD dataSize{};
LONG retCode = ::RegGetValue(
LONG retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -413,8 +408,7 @@ inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const st
nullptr,
nullptr,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read string from registry", retCode };
}
......@@ -430,7 +424,7 @@ inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const st
//
// Read the string from the registry into local wstring object
//
retCode = ::RegGetValue(
retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -438,8 +432,7 @@ inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const st
nullptr,
&data[0],
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read string from registry", retCode };
}
......@@ -464,7 +457,7 @@ RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& val
// Request the size of the multi-string, in bytes
//
DWORD dataSize{};
LONG retCode = ::RegGetValue(
LONG retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -472,8 +465,7 @@ RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& val
nullptr,
nullptr,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read multi-string from registry", retCode };
}
......@@ -488,7 +480,7 @@ RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& val
//
// Read the multi-string from the registry into the vector object
//
retCode = ::RegGetValue(
retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -496,8 +488,7 @@ RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& val
nullptr,
&data[0],
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read multi-string from registry", retCode };
}
......@@ -506,15 +497,14 @@ RegGetMultiString(HKEY hKey, const std::wstring& subKey, const std::wstring& val
// Note that the vector is a vector of wchar_ts, instead the size returned by GetRegValue()
// is in bytes, so we have to scale from bytes to wchar_t count.
//
data.resize( dataSize / sizeof(wchar_t) );
data.resize(dataSize / sizeof(wchar_t));
//
// Parse the double-NUL-terminated string into a vector<wstring>
//
std::vector<std::wstring> result;
const wchar_t* currStringPtr = &data[0];
while (*currStringPtr != L'\0')
{
while (*currStringPtr != L'\0') {
// Current string is NUL-terminated, so get its length with wcslen()
const size_t currStringLength = wcslen(currStringPtr);
......@@ -535,7 +525,7 @@ inline std::vector<BYTE> RegGetBinary(HKEY hKey, const std::wstring& subKey, con
// Request the size of the binary data, in bytes
//
DWORD dataSize{};
LONG retCode = ::RegGetValue(
LONG retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -543,8 +533,7 @@ inline std::vector<BYTE> RegGetBinary(HKEY hKey, const std::wstring& subKey, con
nullptr,
nullptr,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read binary data from registry", retCode };
}
......@@ -557,7 +546,7 @@ inline std::vector<BYTE> RegGetBinary(HKEY hKey, const std::wstring& subKey, con
//
// Read the binary data from the registry into the vector object
//
retCode = ::RegGetValue(
retCode = ::RegGetValueW(
hKey,
subKey.c_str(),
value.c_str(),
......@@ -565,8 +554,7 @@ inline std::vector<BYTE> RegGetBinary(HKEY hKey, const std::wstring& subKey, con
nullptr,
&data[0],
&dataSize);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot read binary data from registry", retCode };
}
......@@ -602,8 +590,7 @@ inline std::vector<std::pair<std::wstring, DWORD>> RegEnumValues(HKEY hKey)
nullptr, // no security descriptor
nullptr // no last write time
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "RegQueryInfoKey failed while preparing for value enumeration.", retCode };
}
......@@ -627,14 +614,13 @@ inline std::vector<std::pair<std::wstring, DWORD>> RegEnumValues(HKEY hKey)
//
// Enumerate all the values
//
for (DWORD index = 0; index < valueCount; index++)
{
for (DWORD index = 0; index < valueCount; index++) {
//
// Get the name and the type of the current value
//
DWORD valueNameLen = maxValueNameLen;
DWORD valueType{};
retCode = ::RegEnumValue(
retCode = ::RegEnumValueW(
hKey,
index,
nameBuffer.get(),
......@@ -644,8 +630,7 @@ inline std::vector<std::pair<std::wstring, DWORD>> RegEnumValues(HKEY hKey)
nullptr, // no data
nullptr // no data size
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot enumerate values: RegEnumValue failed.", retCode };
}
......@@ -689,8 +674,7 @@ inline std::vector<std::wstring> RegEnumSubKeys(HKEY hKey)
nullptr, // no security descriptor
nullptr // no last write time
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "RegQueryInfoKey failed while preparing for subkey enumeration.", retCode };
}
......@@ -714,13 +698,12 @@ inline std::vector<std::wstring> RegEnumSubKeys(HKEY hKey)
//
// Enumerate all the subkeys
//
for (DWORD index = 0; index < subKeyCount; index++)
{
for (DWORD index = 0; index < subKeyCount; index++) {
//
// Get the name of the current subkey
//
DWORD subKeyNameLen = maxSubKeyNameLen;
retCode = ::RegEnumKeyEx(
retCode = ::RegEnumKeyExW(
hKey,
index,
nameBuffer.get(),
......@@ -730,8 +713,7 @@ inline std::vector<std::wstring> RegEnumSubKeys(HKEY hKey)
nullptr, // no class
nullptr // no last write time
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot enumerate subkeys: RegEnumKeyEx failed.", retCode };
}
......@@ -751,7 +733,7 @@ inline std::vector<std::wstring> RegEnumSubKeys(HKEY hKey)
inline RegKey RegCreateKey(
HKEY hKeyParent,
const std::wstring& keyName,
LPTSTR keyClass,
LPWSTR keyClass,
DWORD options,
REGSAM access,
SECURITY_ATTRIBUTES* securityAttributes,
......@@ -762,7 +744,7 @@ inline RegKey RegCreateKey(
// Create the key invoking the native RegCreateKeyEx Win32 API
//
HKEY hKey = nullptr;
LONG retCode = ::RegCreateKeyEx(
LONG retCode = ::RegCreateKeyExW(
hKeyParent,
keyName.c_str(),
0, // reserved
......@@ -773,8 +755,7 @@ inline RegKey RegCreateKey(
&hKey,
disposition
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot create registry key: RegCreateKeyEx failed.", retCode };
}
......@@ -795,15 +776,14 @@ inline RegKey RegOpenKey(
// Open the key invoking the native RegOpenKeyEx Win32 API
//
HKEY hKey = nullptr;
LONG retCode = ::RegOpenKeyEx(
LONG retCode = ::RegOpenKeyExW(
hKeyParent,
keyName.c_str(),
0, // default options
access,
&hKey
);
if (retCode != ERROR_SUCCESS)
{
if (retCode != ERROR_SUCCESS) {
throw RegistryError{ "Cannot open registry key: RegOpenKeyEx failed.", retCode };
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment