diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/regutil.cpp')
| -rw-r--r-- | src/libs/dutil/WixToolset.DUtil/regutil.cpp | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp index 9a1b9ced..744e7a3f 100644 --- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) | 17 | #define RegExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_REGUTIL, p, x, s, __VA_ARGS__) |
| 18 | #define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__) | 18 | #define RegExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_REGUTIL, e, x, s, __VA_ARGS__) |
| 19 | #define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__) | 19 | #define RegExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_REGUTIL, g, x, s, __VA_ARGS__) |
| 20 | #define RegExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_REGUTIL, x, b, s, __VA_ARGS__) | ||
| 20 | 21 | ||
| 21 | static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; | 22 | static PFN_REGCREATEKEYEXW vpfnRegCreateKeyExW = ::RegCreateKeyExW; |
| 22 | static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; | 23 | static PFN_REGOPENKEYEXW vpfnRegOpenKeyExW = ::RegOpenKeyExW; |
| @@ -179,7 +180,7 @@ DAPI_(HRESULT) RegOpen( | |||
| 179 | __in_z LPCWSTR wzSubKey, | 180 | __in_z LPCWSTR wzSubKey, |
| 180 | __in DWORD dwAccess, | 181 | __in DWORD dwAccess, |
| 181 | __out HKEY* phk | 182 | __out HKEY* phk |
| 182 | ) | 183 | ) |
| 183 | { | 184 | { |
| 184 | return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk); | 185 | return RegOpenEx(hkRoot, wzSubKey, dwAccess, REG_KEY_DEFAULT, phk); |
| 185 | } | 186 | } |
| @@ -191,18 +192,18 @@ DAPI_(HRESULT) RegOpenEx( | |||
| 191 | __in DWORD dwAccess, | 192 | __in DWORD dwAccess, |
| 192 | __in REG_KEY_BITNESS kbKeyBitness, | 193 | __in REG_KEY_BITNESS kbKeyBitness, |
| 193 | __out HKEY* phk | 194 | __out HKEY* phk |
| 194 | ) | 195 | ) |
| 195 | { | 196 | { |
| 196 | HRESULT hr = S_OK; | 197 | HRESULT hr = S_OK; |
| 197 | DWORD er = ERROR_SUCCESS; | 198 | DWORD er = ERROR_SUCCESS; |
| 198 | 199 | ||
| 199 | REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); | 200 | REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); |
| 200 | er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk); | 201 | er = vpfnRegOpenKeyExW(hkRoot, wzSubKey, 0, dwAccess | samDesired, phk); |
| 201 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 202 | if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) |
| 202 | { | 203 | { |
| 203 | ExitFunction1(hr = E_FILENOTFOUND); | 204 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
| 204 | } | 205 | } |
| 205 | RegExitOnWin32Error(er, hr, "Failed to open registry key."); | 206 | RegExitOnWin32Error(er, hr, "Failed to open registry key, root: %x, subkey: %ls.", hkRoot, wzSubKey); |
| 206 | 207 | ||
| 207 | LExit: | 208 | LExit: |
| 208 | return hr; | 209 | return hr; |
| @@ -221,6 +222,7 @@ DAPI_(HRESULT) RegDelete( | |||
| 221 | LPWSTR pszEnumeratedSubKey = NULL; | 222 | LPWSTR pszEnumeratedSubKey = NULL; |
| 222 | LPWSTR pszRecursiveSubKey = NULL; | 223 | LPWSTR pszRecursiveSubKey = NULL; |
| 223 | HKEY hkKey = NULL; | 224 | HKEY hkKey = NULL; |
| 225 | BOOL fExists = FALSE; | ||
| 224 | 226 | ||
| 225 | if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) | 227 | if (!vfRegInitialized && REG_KEY_DEFAULT != kbKeyBitness) |
| 226 | { | 228 | { |
| @@ -231,9 +233,9 @@ DAPI_(HRESULT) RegDelete( | |||
| 231 | if (fDeleteTree) | 233 | if (fDeleteTree) |
| 232 | { | 234 | { |
| 233 | hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); | 235 | hr = RegOpenEx(hkRoot, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); |
| 234 | if (E_FILENOTFOUND == hr) | 236 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) |
| 235 | { | 237 | { |
| 236 | ExitFunction1(hr = S_OK); | 238 | ExitFunction(); |
| 237 | } | 239 | } |
| 238 | RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey); | 240 | RegExitOnFailure(hr, "Failed to open this key for enumerating subkeys: %ls", wzSubKey); |
| 239 | 241 | ||
| @@ -246,28 +248,31 @@ DAPI_(HRESULT) RegDelete( | |||
| 246 | RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); | 248 | RegExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); |
| 247 | 249 | ||
| 248 | hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); | 250 | hr = RegDelete(hkRoot, pszRecursiveSubKey, kbKeyBitness, fDeleteTree); |
| 249 | RegExitOnFailure(hr, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); | 251 | RegExitOnPathFailure(hr, fExists, "Failed to recursively delete subkey: %ls", pszRecursiveSubKey); |
| 250 | } | 252 | } |
| 251 | 253 | ||
| 252 | hr = S_OK; | 254 | hr = S_OK; |
| 255 | |||
| 256 | // Release the handle to make sure it's deleted immediately. | ||
| 257 | ReleaseRegKey(hkKey); | ||
| 253 | } | 258 | } |
| 254 | 259 | ||
| 255 | if (NULL != vpfnRegDeleteKeyExW) | 260 | if (NULL != vpfnRegDeleteKeyExW) |
| 256 | { | 261 | { |
| 257 | REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); | 262 | REGSAM samDesired = RegTranslateKeyBitness(kbKeyBitness); |
| 258 | er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); | 263 | er = vpfnRegDeleteKeyExW(hkRoot, wzSubKey, samDesired, 0); |
| 259 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 264 | if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) |
| 260 | { | 265 | { |
| 261 | ExitFunction1(hr = E_FILENOTFOUND); | 266 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
| 262 | } | 267 | } |
| 263 | RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); | 268 | RegExitOnWin32Error(er, hr, "Failed to delete registry key (ex)."); |
| 264 | } | 269 | } |
| 265 | else | 270 | else |
| 266 | { | 271 | { |
| 267 | er = vpfnRegDeleteKeyW(hkRoot, wzSubKey); | 272 | er = vpfnRegDeleteKeyW(hkRoot, wzSubKey); |
| 268 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 273 | if (ERROR_PATH_NOT_FOUND == er || ERROR_FILE_NOT_FOUND == er) |
| 269 | { | 274 | { |
| 270 | ExitFunction1(hr = E_FILENOTFOUND); | 275 | ExitFunction1(hr = HRESULT_FROM_WIN32(er)); |
| 271 | } | 276 | } |
| 272 | RegExitOnWin32Error(er, hr, "Failed to delete registry key."); | 277 | RegExitOnWin32Error(er, hr, "Failed to delete registry key."); |
| 273 | } | 278 | } |
| @@ -772,7 +777,7 @@ DAPI_(HRESULT) RegReadNumber( | |||
| 772 | DWORD cb = sizeof(DWORD); | 777 | DWORD cb = sizeof(DWORD); |
| 773 | 778 | ||
| 774 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pdwValue), &cb); | 779 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pdwValue), &cb); |
| 775 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 780 | if (ERROR_FILE_NOT_FOUND == er) |
| 776 | { | 781 | { |
| 777 | ExitFunction1(hr = E_FILENOTFOUND); | 782 | ExitFunction1(hr = E_FILENOTFOUND); |
| 778 | } | 783 | } |
| @@ -801,7 +806,7 @@ DAPI_(HRESULT) RegReadQword( | |||
| 801 | DWORD cb = sizeof(DWORD64); | 806 | DWORD cb = sizeof(DWORD64); |
| 802 | 807 | ||
| 803 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pqwValue), &cb); | 808 | er = vpfnRegQueryValueExW(hk, wzName, NULL, &dwType, reinterpret_cast<LPBYTE>(pqwValue), &cb); |
| 804 | if (E_FILENOTFOUND == HRESULT_FROM_WIN32(er)) | 809 | if (ERROR_FILE_NOT_FOUND == er) |
| 805 | { | 810 | { |
| 806 | ExitFunction1(hr = E_FILENOTFOUND); | 811 | ExitFunction1(hr = E_FILENOTFOUND); |
| 807 | } | 812 | } |
| @@ -1015,9 +1020,17 @@ DAPI_(HRESULT) RegKeyReadNumber( | |||
| 1015 | HKEY hkKey = NULL; | 1020 | HKEY hkKey = NULL; |
| 1016 | 1021 | ||
| 1017 | hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); | 1022 | hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); |
| 1023 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) | ||
| 1024 | { | ||
| 1025 | ExitFunction(); | ||
| 1026 | } | ||
| 1018 | RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); | 1027 | RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); |
| 1019 | 1028 | ||
| 1020 | hr = RegReadNumber(hkKey, wzName, pdwValue); | 1029 | hr = RegReadNumber(hkKey, wzName, pdwValue); |
| 1030 | if (E_FILENOTFOUND == hr) | ||
| 1031 | { | ||
| 1032 | ExitFunction(); | ||
| 1033 | } | ||
| 1021 | RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName); | 1034 | RegExitOnFailure(hr, "Failed to read value: %ls/@%ls", wzSubKey, wzName); |
| 1022 | 1035 | ||
| 1023 | LExit: | 1036 | LExit: |
| @@ -1038,9 +1051,17 @@ DAPI_(BOOL) RegValueExists( | |||
| 1038 | DWORD dwType = 0; | 1051 | DWORD dwType = 0; |
| 1039 | 1052 | ||
| 1040 | hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); | 1053 | hr = RegOpenEx(hk, wzSubKey, KEY_READ, kbKeyBitness, &hkKey); |
| 1054 | if (E_PATHNOTFOUND == hr || E_FILENOTFOUND == hr) | ||
| 1055 | { | ||
| 1056 | ExitFunction(); | ||
| 1057 | } | ||
| 1041 | RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); | 1058 | RegExitOnFailure(hr, "Failed to open key: %ls", wzSubKey); |
| 1042 | 1059 | ||
| 1043 | hr = RegGetType(hkKey, wzName, &dwType); | 1060 | hr = RegGetType(hkKey, wzName, &dwType); |
| 1061 | if (E_FILENOTFOUND == hr) | ||
| 1062 | { | ||
| 1063 | ExitFunction(); | ||
| 1064 | } | ||
| 1044 | RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName); | 1065 | RegExitOnFailure(hr, "Failed to read value type: %ls/@%ls", wzSubKey, wzName); |
| 1045 | 1066 | ||
| 1046 | LExit: | 1067 | LExit: |
