From 1bdf42c558d6923380b9f3ea409027816f972f98 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 18 Jul 2021 19:52:05 -0500 Subject: Refactor butil while cleaning up other things. --- .../dutil/CustomizedNativeRecommendedRules.ruleset | 8 - src/libs/dutil/WixToolset.DUtil/butil.cpp | 192 +++++++++++++-------- src/libs/dutil/WixToolset.DUtil/inc/butil.h | 22 ++- src/libs/dutil/WixToolset.DUtil/inc/regutil.h | 161 ++++++++++++++++- src/libs/dutil/WixToolset.DUtil/regutil.cpp | 180 ++++--------------- 5 files changed, 326 insertions(+), 237 deletions(-) delete mode 100644 src/libs/dutil/CustomizedNativeRecommendedRules.ruleset (limited to 'src/libs') diff --git a/src/libs/dutil/CustomizedNativeRecommendedRules.ruleset b/src/libs/dutil/CustomizedNativeRecommendedRules.ruleset deleted file mode 100644 index 142b141c..00000000 --- a/src/libs/dutil/CustomizedNativeRecommendedRules.ruleset +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp index cda2a658..ca73f0c3 100644 --- a/src/libs/dutil/WixToolset.DUtil/butil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp @@ -8,6 +8,7 @@ #define ButilExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__) #define ButilExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__) #define ButilExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__) +#define ButilExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_BUTIL, x, e, s, __VA_ARGS__) #define ButilExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_BUTIL, x, s, __VA_ARGS__) #define ButilExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_BUTIL, p, x, e, s, __VA_ARGS__) #define ButilExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_BUTIL, p, x, s, __VA_ARGS__) @@ -22,7 +23,29 @@ const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = L"BundleUpgrade const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = L"BundleProviderKey"; const LPCWSTR BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY = L"variables"; +enum INTERNAL_BUNDLE_STATUS +{ + INTERNAL_BUNDLE_STATUS_SUCCESS, + INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE, + INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY, +}; + // Forward declarations. +/******************************************************************** +LocateAndQueryBundleValue - Locates the requested key for the bundle, + then queries the registry type for requested value. + +NOTE: caller is responsible for closing key +********************************************************************/ +static HRESULT LocateAndQueryBundleValue( + __in_z LPCWSTR wzBundleId, + __in_opt LPCWSTR wzSubKey, + __in LPCWSTR wzValueName, + __inout HKEY* phKey, + __inout DWORD* pdwType, + __out INTERNAL_BUNDLE_STATUS* pStatus + ); + /******************************************************************** OpenBundleKey - Opens the bundle uninstallation key for a given bundle @@ -31,43 +54,44 @@ NOTE: caller is responsible for closing key static HRESULT OpenBundleKey( __in_z LPCWSTR wzBundleId, __in BUNDLE_INSTALL_CONTEXT context, - __in_opt LPCWSTR szSubKey, - __inout HKEY* key); + __in_opt LPCWSTR wzSubKey, + __inout HKEY* phKey + ); -/******************************************************************** -BundleGetBundleInfo - Read the registration data for a gven bundle -********************************************************************/ -extern "C" HRESULT DAPI BundleGetBundleInfo( - __in_z LPCWSTR wzBundleId, - __in_z LPCWSTR wzAttribute, - __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, - __inout_opt LPDWORD pcchValueBuf - ) +DAPI_(HRESULT) BundleGetBundleInfo( + __in_z LPCWSTR wzBundleId, + __in_z LPCWSTR wzAttribute, + __out_ecount_opt(*pcchValueBuf) LPWSTR lpValueBuf, + __inout_opt LPDWORD pcchValueBuf + ) { Assert(wzBundleId && wzAttribute); HRESULT hr = S_OK; LPWSTR sczValue = NULL; HKEY hkBundle = NULL; + INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS; DWORD cchSource = 0; DWORD dwType = 0; DWORD dwValue = 0; if ((lpValueBuf && !pcchValueBuf) || !wzBundleId || !wzAttribute) { - ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function."); + ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function."); } - if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, NULL, &hkBundle)) && - FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, NULL, &hkBundle))) + hr = LocateAndQueryBundleValue(wzBundleId, NULL, wzAttribute, &hkBundle, &dwType, &status); + ButilExitOnFailure(hr, "Failed to locate and query bundle attribute."); + + switch (status) { - ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) : hr, "Failed to locate bundle uninstall key path."); + case INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE: + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT)); + case INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY: + // If the bundle doesn't have the property defined, return ERROR_UNKNOWN_PROPERTY + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY)); } - // If the bundle doesn't have the property defined, return ERROR_UNKNOWN_PROPERTY - hr = RegGetType(hkBundle, wzAttribute, &dwType); - ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) : hr, "Failed to locate bundle property."); - switch (dwType) { case REG_SZ: @@ -82,12 +106,11 @@ extern "C" HRESULT DAPI BundleGetBundleInfo( ButilExitOnFailure(hr, "Failed to format dword property as string."); break; default: - ButilExitOnFailure(hr = E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType); - + ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle info of type 0x%x not implemented.", dwType); } hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, reinterpret_cast(&cchSource)); - ButilExitOnFailure(hr, "Failed to calculate length of string"); + ButilExitOnRootFailure(hr, "Failed to calculate length of string."); if (lpValueBuf) { @@ -95,11 +118,11 @@ extern "C" HRESULT DAPI BundleGetBundleInfo( if (*pcchValueBuf <= cchSource) { *pcchValueBuf = ++cchSource; - ButilExitOnFailure(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA), "A buffer is too small to hold the requested data."); + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA)); } hr = ::StringCchCatNExW(lpValueBuf, *pcchValueBuf, sczValue, cchSource, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); - ButilExitOnFailure(hr, "Failed to copy the property value to the output buffer."); + ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer."); *pcchValueBuf = cchSource++; } @@ -111,10 +134,8 @@ LExit: return hr; } -/******************************************************************** -********************************************************************/ -extern "C" HRESULT DAPI BundleEnumRelatedBundle( +DAPI_(HRESULT) BundleEnumRelatedBundle( __in_z LPCWSTR wzUpgradeCode, __in BUNDLE_INSTALL_CONTEXT context, __inout PDWORD pdwStartIndex, @@ -170,6 +191,7 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle( case REG_SZ: hr = RegReadString(hkBundle, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE, &sczValue); ButilExitOnFailure(hr, "Failed to read BundleUpgradeCode string property."); + if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, sczValue, -1, wzUpgradeCode, -1)) { *pdwStartIndex = dwIndex; @@ -202,8 +224,7 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle( break; default: - ButilExitOnFailure(hr = E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType); - + ButilExitWithRootFailure(hr, E_NOTIMPL, "BundleUpgradeCode of type 0x%x not implemented.", dwType); } if (fUpgradeCodeFound) @@ -211,10 +232,10 @@ extern "C" HRESULT DAPI BundleEnumRelatedBundle( if (lpBundleIdBuf) { hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, reinterpret_cast(&cchUninstallSubKey)); - ButilExitOnFailure(hr, "Failed to calculate length of string"); + ButilExitOnRootFailure(hr, "Failed to calculate length of string"); hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL); - ButilExitOnFailure(hr, "Failed to copy the property value to the output buffer."); + ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer."); } break; @@ -237,52 +258,37 @@ LExit: return hr; } -/******************************************************************** -BundleGetBundleVariable - Queries the bundle installation metadata for a given variable, -the caller is expected to free the memory returned vis psczValue -RETURNS: -S_OK - Success, if the variable had a value, it's returned in psczValue -E_INVALIDARG - An invalid parameter was passed to the function. -HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) - The bundle is not installed -HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) - The variable is unrecognized -E_NOTIMPL: - Tried to read a bundle variable for a type which has not been implemented - -All other returns are unexpected returns from other dutil methods. -********************************************************************/ -extern "C" HRESULT DAPI BundleGetBundleVariable( +DAPI_(HRESULT) BundleGetBundleVariable( __in_z LPCWSTR wzBundleId, __in_z LPCWSTR wzVariable, - __deref_out_z LPWSTR * psczValue -) + __deref_out_z LPWSTR* psczValue + ) { Assert(wzBundleId && wzVariable); HRESULT hr = S_OK; - BUNDLE_INSTALL_CONTEXT context = BUNDLE_INSTALL_CONTEXT_MACHINE; HKEY hkBundle = NULL; + INTERNAL_BUNDLE_STATUS status = INTERNAL_BUNDLE_STATUS_SUCCESS; DWORD dwType = 0; if (!wzBundleId || !wzVariable || !psczValue) { - ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function."); + ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function."); } - if (FAILED(hr = OpenBundleKey(wzBundleId, context = BUNDLE_INSTALL_CONTEXT_MACHINE, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, &hkBundle)) && - FAILED(hr = OpenBundleKey(wzBundleId, context = BUNDLE_INSTALL_CONTEXT_USER, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, &hkBundle))) + hr = LocateAndQueryBundleValue(wzBundleId, BUNDLE_REGISTRATION_REGISTRY_BUNDLE_VARIABLE_KEY, wzVariable, &hkBundle, &dwType, &status); + ButilExitOnFailure(hr, "Failed to locate and query bundle variable."); + + switch (status) { - ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) : hr, "Failed to locate bundle uninstall key variable path."); + case INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE: + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT)); + case INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY: + // If the bundle doesn't have the shared variable defined, return ERROR_UNKNOWN_PROPERTY + ExitFunction1(hr = HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY)); } - // If the bundle doesn't have the shared variable defined, return ERROR_UNKNOWN_PROPERTY - hr = RegGetType(hkBundle, wzVariable, &dwType); - ButilExitOnFailure(E_FILENOTFOUND == hr ? HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) : hr, "Failed to locate bundle variable."); - switch (dwType) { case REG_SZ: @@ -293,35 +299,74 @@ extern "C" HRESULT DAPI BundleGetBundleVariable( hr = S_OK; break; default: - ButilExitOnFailure(hr = E_NOTIMPL, "Reading bundle variable of type 0x%x not implemented.", dwType); - + ButilExitWithRootFailure(hr, E_NOTIMPL, "Reading bundle variable of type 0x%x not implemented.", dwType); } LExit: ReleaseRegKey(hkBundle); return hr; +} + +static HRESULT LocateAndQueryBundleValue( + __in_z LPCWSTR wzBundleId, + __in_opt LPCWSTR wzSubKey, + __in LPCWSTR wzValueName, + __inout HKEY* phKey, + __inout DWORD* pdwType, + __out INTERNAL_BUNDLE_STATUS* pStatus + ) +{ + HRESULT hr = S_OK; + + *pStatus = INTERNAL_BUNDLE_STATUS_SUCCESS; + if (FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_MACHINE, wzSubKey, phKey)) && + FAILED(hr = OpenBundleKey(wzBundleId, BUNDLE_INSTALL_CONTEXT_USER, wzSubKey, phKey))) + { + if (E_FILENOTFOUND == hr) + { + *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_BUNDLE; + ExitFunction1(hr = S_OK); + } + + ButilExitOnFailure(hr, "Failed to open bundle key."); + } + + // If the bundle doesn't have the value defined, return ERROR_UNKNOWN_PROPERTY + hr = RegGetType(*phKey, wzValueName, pdwType); + if (FAILED(hr)) + { + if (E_FILENOTFOUND == hr) + { + *pStatus = INTERNAL_BUNDLE_STATUS_UNKNOWN_PROPERTY; + ExitFunction1(hr = S_OK); + } + + ButilExitOnFailure(hr, "Failed to read bundle value."); + } + +LExit: + return hr; } -/******************************************************************** -* -********************************************************************/ -HRESULT OpenBundleKey( + +static HRESULT OpenBundleKey( __in_z LPCWSTR wzBundleId, __in BUNDLE_INSTALL_CONTEXT context, - __in_opt LPCWSTR szSubKey, - __inout HKEY* key) + __in_opt LPCWSTR wzSubKey, + __inout HKEY* phKey + ) { - Assert(key && wzBundleId); - AssertSz(NULL == *key, "*key should be null"); + Assert(phKey && wzBundleId); + AssertSz(NULL == *phKey, "*key should be null"); HRESULT hr = S_OK; HKEY hkRoot = BUNDLE_INSTALL_CONTEXT_USER == context ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; LPWSTR sczKeypath = NULL; - if (szSubKey) + if (wzSubKey) { - hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, szSubKey); + hr = StrAllocFormatted(&sczKeypath, L"%ls\\%ls\\%ls", BUNDLE_REGISTRATION_REGISTRY_UNINSTALL_KEY, wzBundleId, wzSubKey); } else { @@ -329,7 +374,7 @@ HRESULT OpenBundleKey( } ButilExitOnFailure(hr, "Failed to allocate bundle uninstall key path."); - hr = RegOpen(hkRoot, sczKeypath, KEY_READ, key); + hr = RegOpen(hkRoot, sczKeypath, KEY_READ, phKey); ButilExitOnFailure(hr, "Failed to open bundle uninstall key path."); LExit: @@ -337,4 +382,3 @@ LExit: return hr; } - diff --git a/src/libs/dutil/WixToolset.DUtil/inc/butil.h b/src/libs/dutil/WixToolset.DUtil/inc/butil.h index d910c113..721d9ad6 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/butil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/butil.h @@ -6,7 +6,7 @@ extern "C" { #endif -typedef enum BUNDLE_INSTALL_CONTEXT +typedef enum _BUNDLE_INSTALL_CONTEXT { BUNDLE_INSTALL_CONTEXT_MACHINE, BUNDLE_INSTALL_CONTEXT_USER, @@ -55,11 +55,29 @@ HRESULT DAPI BundleEnumRelatedBundle( __out_ecount(MAX_GUID_CHARS+1) LPWSTR lpBundleIdBuf ); +/******************************************************************** +BundleGetBundleVariable - Queries the bundle installation metadata for a given variable, + the caller is expected to free the memory returned vis psczValue + +RETURNS: + S_OK + Success, if the variable had a value, it's returned in psczValue + E_INVALIDARG + An invalid parameter was passed to the function. + HRESULT_FROM_WIN32(ERROR_UNKNOWN_PRODUCT) + The bundle is not installed + HRESULT_FROM_WIN32(ERROR_UNKNOWN_PROPERTY) + The variable is unrecognized + E_NOTIMPL: + Tried to read a bundle variable for a type which has not been implemented + + All other returns are unexpected returns from other dutil methods. +********************************************************************/ HRESULT DAPI BundleGetBundleVariable( __in_z LPCWSTR wzBundleId, __in_z LPCWSTR wzVariable, __deref_out_z LPWSTR* psczValue -); + ); #ifdef __cplusplus diff --git a/src/libs/dutil/WixToolset.DUtil/inc/regutil.h b/src/libs/dutil/WixToolset.DUtil/inc/regutil.h index fcf13054..ae47f75e 100644 --- a/src/libs/dutil/WixToolset.DUtil/inc/regutil.h +++ b/src/libs/dutil/WixToolset.DUtil/inc/regutil.h @@ -99,9 +99,23 @@ typedef LSTATUS (APIENTRY *PFN_REGDELETEVALUEW)( __in_opt LPCWSTR lpValueName ); +/******************************************************************** + RegInitialize - initializes regutil + +*********************************************************************/ HRESULT DAPI RegInitialize(); + +/******************************************************************** + RegUninitialize - uninitializes regutil + +*********************************************************************/ void DAPI RegUninitialize(); +/******************************************************************** + RegFunctionOverride - overrides the registry functions. Typically used + for unit testing. + +*********************************************************************/ void DAPI RegFunctionOverride( __in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW, __in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW, @@ -113,12 +127,22 @@ void DAPI RegFunctionOverride( __in_opt PFN_REGSETVALUEEXW pfnRegSetValueExW, __in_opt PFN_REGDELETEVALUEW pfnRegDeleteValueW ); + +/******************************************************************** + RegCreate - creates a registry key. + +*********************************************************************/ HRESULT DAPI RegCreate( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, __out HKEY* phk ); + +/******************************************************************** + RegCreateEx - creates a registry key with extra options. + +*********************************************************************/ HRESULT DAPI RegCreateEx( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, @@ -128,112 +152,229 @@ HRESULT DAPI RegCreateEx( __out HKEY* phk, __out_opt BOOL* pfCreated ); + +/******************************************************************** + RegOpen - opens a registry key. + +*********************************************************************/ HRESULT DAPI RegOpen( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, __out HKEY* phk ); + +/******************************************************************** + RegDelete - deletes a registry key (and optionally it's whole tree). + +*********************************************************************/ HRESULT DAPI RegDelete( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in REG_KEY_BITNESS kbKeyBitness, __in BOOL fDeleteTree ); + +/******************************************************************** + RegKeyEnum - enumerates child registry keys. + +*********************************************************************/ HRESULT DAPI RegKeyEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczKey ); + +/******************************************************************** + RegValueEnum - enumerates registry values. + +*********************************************************************/ HRESULT DAPI RegValueEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczName, __out_opt DWORD *pdwType ); + +/******************************************************************** + RegGetType - reads a registry key value type. + *********************************************************************/ HRESULT DAPI RegGetType( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD *pdwType ); + +/******************************************************************** + RegReadBinary - reads a registry key binary value. + NOTE: caller is responsible for freeing *ppbBuffer +*********************************************************************/ HRESULT DAPI RegReadBinary( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer, __out SIZE_T *pcbBuffer ); + +/******************************************************************** + RegReadString - reads a registry key value as a string. + +*********************************************************************/ HRESULT DAPI RegReadString( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_z LPWSTR* psczValue ); + +/******************************************************************** + RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array. + +*********************************************************************/ HRESULT DAPI RegReadStringArray( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings, __out DWORD *pcStrings ); + +/******************************************************************** + RegReadVersion - reads a registry key value as a version. + +*********************************************************************/ HRESULT DAPI RegReadVersion( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD64* pdw64Version ); + +/******************************************************************** + RegReadNone - reads a NONE registry key value. + +*********************************************************************/ HRESULT DAPI RegReadNone( __in HKEY hk, __in_z_opt LPCWSTR wzName -); + ); + +/******************************************************************** + RegReadNumber - reads a DWORD registry key value as a number. + +*********************************************************************/ HRESULT DAPI RegReadNumber( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD* pdwValue ); + +/******************************************************************** + RegReadQword - reads a QWORD registry key value as a number. + +*********************************************************************/ HRESULT DAPI RegReadQword( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD64* pqwValue ); + +/******************************************************************** + RegWriteBinary - writes a registry key value as a binary. + +*********************************************************************/ HRESULT DAPI RegWriteBinary( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_bcount(cbBuffer) const BYTE *pbBuffer, __in DWORD cbBuffer ); -HRESULT DAPI RegWriteString( + +/******************************************************************** +RegWriteExpandString - writes a registry key value as an expand string. + +Note: if wzValue is NULL the value will be removed. +*********************************************************************/ +HRESULT DAPI RegWriteExpandString( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_z_opt LPCWSTR wzValue ); -HRESULT DAPI RegWriteStringArray( + +/******************************************************************** + RegWriteString - writes a registry key value as a string. + + Note: if wzValue is NULL the value will be removed. +*********************************************************************/ +HRESULT DAPI RegWriteString( __in HKEY hk, __in_z_opt LPCWSTR wzName, - __in_ecount(cStrings) LPWSTR *rgwzStrings, - __in DWORD cStrings + __in_z_opt LPCWSTR wzValue ); -HRESULT DAPI RegWriteStringFormatted( + +/******************************************************************** + RegWriteStringFormatted - writes a registry key value as a formatted string. + +*********************************************************************/ +HRESULT DAPIV RegWriteStringFormatted( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in __format_string LPCWSTR szFormat, ... ); + +/******************************************************************** + RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value + +*********************************************************************/ +HRESULT DAPI RegWriteStringArray( + __in HKEY hk, + __in_z_opt LPCWSTR wzName, + __in_ecount(cStrings) LPWSTR* rgwzStrings, + __in DWORD cStrings + ); + +/******************************************************************** + RegWriteNone - writes a registry key value as none. + +*********************************************************************/ HRESULT DAPI RegWriteNone( __in HKEY hk, __in_z_opt LPCWSTR wzName -); + ); + +/******************************************************************** + RegWriteNumber - writes a registry key value as a number. + +*********************************************************************/ HRESULT DAPI RegWriteNumber( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in DWORD dwValue ); + +/******************************************************************** + RegWriteQword - writes a registry key value as a Qword. + +*********************************************************************/ HRESULT DAPI RegWriteQword( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in DWORD64 qwValue ); + +/******************************************************************** + RegQueryKey - queries the key for the number of subkeys and values. + +*********************************************************************/ HRESULT DAPI RegQueryKey( __in HKEY hk, __out_opt DWORD* pcSubKeys, __out_opt DWORD* pcValues ); + +/******************************************************************** +RegKeyReadNumber - reads a DWORD registry key value as a number from +a specified subkey. + +*********************************************************************/ HRESULT DAPI RegKeyReadNumber( __in HKEY hk, __in_z LPCWSTR wzSubKey, @@ -241,6 +382,12 @@ HRESULT DAPI RegKeyReadNumber( __in BOOL f64Bit, __out DWORD* pdwValue ); + +/******************************************************************** +RegValueExists - determines whether a named value exists in a +specified subkey. + +*********************************************************************/ BOOL DAPI RegValueExists( __in HKEY hk, __in_z LPCWSTR wzSubKey, diff --git a/src/libs/dutil/WixToolset.DUtil/regutil.cpp b/src/libs/dutil/WixToolset.DUtil/regutil.cpp index 458d8586..57093f97 100644 --- a/src/libs/dutil/WixToolset.DUtil/regutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/regutil.cpp @@ -37,14 +37,9 @@ static HRESULT WriteStringToRegistry( __in_z_opt LPCWSTR wzName, __in_z_opt LPCWSTR wzValue, __in DWORD dwType -); + ); -/******************************************************************** - RegInitialize - initializes regutil - -*********************************************************************/ -extern "C" HRESULT DAPI RegInitialize( - ) +DAPI_(HRESULT) RegInitialize() { HRESULT hr = S_OK; @@ -66,12 +61,7 @@ LExit: } -/******************************************************************** - RegUninitialize - uninitializes regutil - -*********************************************************************/ -extern "C" void DAPI RegUninitialize( - ) +DAPI_(void) RegUninitialize() { if (vhAdvApi32Dll) { @@ -85,12 +75,7 @@ extern "C" void DAPI RegUninitialize( } -/******************************************************************** - RegFunctionOverride - overrides the registry functions. Typically used - for unit testing. - -*********************************************************************/ -extern "C" void DAPI RegFunctionOverride( +DAPI_(void) RegFunctionOverride( __in_opt PFN_REGCREATEKEYEXW pfnRegCreateKeyExW, __in_opt PFN_REGOPENKEYEXW pfnRegOpenKeyExW, __in_opt PFN_REGDELETEKEYEXW pfnRegDeleteKeyExW, @@ -114,11 +99,7 @@ extern "C" void DAPI RegFunctionOverride( } -/******************************************************************** - RegCreate - creates a registry key. - -*********************************************************************/ -extern "C" HRESULT DAPI RegCreate( +DAPI_(HRESULT) RegCreate( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, @@ -136,11 +117,7 @@ LExit: } -/******************************************************************** - RegCreate - creates a registry key with extra options. - -*********************************************************************/ -HRESULT DAPI RegCreateEx( +DAPI_(HRESULT) RegCreateEx( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, @@ -167,11 +144,7 @@ LExit: } -/******************************************************************** - RegOpen - opens a registry key. - -*********************************************************************/ -extern "C" HRESULT DAPI RegOpen( +DAPI_(HRESULT) RegOpen( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in DWORD dwAccess, @@ -193,11 +166,7 @@ LExit: } -/******************************************************************** - RegDelete - deletes a registry key (and optionally it's whole tree). - -*********************************************************************/ -extern "C" HRESULT DAPI RegDelete( +DAPI_(HRESULT) RegDelete( __in HKEY hkRoot, __in_z LPCWSTR wzSubKey, __in REG_KEY_BITNESS kbKeyBitness, @@ -282,11 +251,7 @@ LExit: } -/******************************************************************** - RegKeyEnum - enumerates child registry keys. - -*********************************************************************/ -extern "C" HRESULT DAPI RegKeyEnum( +DAPI_(HRESULT) RegKeyEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczKey @@ -342,11 +307,7 @@ LExit: } -/******************************************************************** - RegValueEnum - enumerates registry values. - -*********************************************************************/ -HRESULT DAPI RegValueEnum( +DAPI_(HRESULT) RegValueEnum( __in HKEY hk, __in DWORD dwIndex, __deref_out_z LPWSTR* psczName, @@ -377,10 +338,7 @@ LExit: return hr; } -/******************************************************************** - RegGetType - reads a registry key value type. - *********************************************************************/ -HRESULT DAPI RegGetType( +DAPI_(HRESULT) RegGetType( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD *pdwType @@ -400,11 +358,7 @@ LExit: return hr; } -/******************************************************************** - RegReadBinary - reads a registry key binary value. - NOTE: caller is responsible for freeing *ppbBuffer -*********************************************************************/ -HRESULT DAPI RegReadBinary( +DAPI_(HRESULT) RegReadBinary( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_bcount_opt(*pcbBuffer) BYTE** ppbBuffer, @@ -453,11 +407,7 @@ LExit: } -/******************************************************************** - RegReadString - reads a registry key value as a string. - -*********************************************************************/ -extern "C" HRESULT DAPI RegReadString( +DAPI_(HRESULT) RegReadString( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_z LPWSTR* psczValue @@ -530,11 +480,7 @@ LExit: } -/******************************************************************** - RegReadStringArray - reads a registry key value REG_MULTI_SZ value as a string array. - -*********************************************************************/ -HRESULT DAPI RegReadStringArray( +DAPI_(HRESULT) RegReadStringArray( __in HKEY hk, __in_z_opt LPCWSTR wzName, __deref_out_ecount_opt(*pcStrings) LPWSTR** prgsczStrings, @@ -626,11 +572,7 @@ LExit: } -/******************************************************************** - RegReadVersion - reads a registry key value as a version. - -*********************************************************************/ -extern "C" HRESULT DAPI RegReadVersion( +DAPI_(HRESULT) RegReadVersion( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD64* pdw64Version @@ -672,13 +614,10 @@ LExit: return hr; } -/******************************************************************** - RegReadNone - reads a NONE registry key value. - -*********************************************************************/ -extern "C" HRESULT DAPI RegReadNone( +DAPI_(HRESULT) RegReadNone( __in HKEY hk, - __in_z_opt LPCWSTR wzName) + __in_z_opt LPCWSTR wzName + ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; @@ -694,18 +633,14 @@ extern "C" HRESULT DAPI RegReadNone( if (REG_NONE != dwType) { hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE); - RegExitOnRootFailure(hr, "Error reading version registry value due to unexpected data type: %u", dwType); + RegExitOnRootFailure(hr, "Error reading none registry value due to unexpected data type: %u", dwType); } LExit: return hr; } -/******************************************************************** - RegReadNumber - reads a DWORD registry key value as a number. - -*********************************************************************/ -extern "C" HRESULT DAPI RegReadNumber( +DAPI_(HRESULT) RegReadNumber( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD* pdwValue @@ -734,11 +669,7 @@ LExit: } -/******************************************************************** - RegReadQword - reads a QWORD registry key value as a number. - -*********************************************************************/ -extern "C" HRESULT DAPI RegReadQword( +DAPI_(HRESULT) RegReadQword( __in HKEY hk, __in_z_opt LPCWSTR wzName, __out DWORD64* pqwValue @@ -767,11 +698,7 @@ LExit: } -/******************************************************************** - RegWriteBinary - writes a registry key value as a binary. - -*********************************************************************/ -HRESULT DAPI RegWriteBinary( +DAPI_(HRESULT) RegWriteBinary( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_bcount(cbBuffer) const BYTE *pbBuffer, @@ -789,27 +716,17 @@ LExit: } -/******************************************************************** -RegWriteExpandString - writes a registry key value as an expand string. - -Note: if wzValue is NULL the value will be removed. -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteExpandString( +DAPI_(HRESULT) RegWriteExpandString( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_z_opt LPCWSTR wzValue -) + ) { return WriteStringToRegistry(hk, wzName, wzValue, REG_EXPAND_SZ); } -/******************************************************************** - RegWriteString - writes a registry key value as a string. - - Note: if wzValue is NULL the value will be removed. -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteString( +DAPI_(HRESULT) RegWriteString( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_z_opt LPCWSTR wzValue @@ -819,11 +736,7 @@ extern "C" HRESULT DAPI RegWriteString( } -/******************************************************************** - RegWriteStringFormatted - writes a registry key value as a formatted string. - -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteStringFormatted( +DAPIV_(HRESULT) RegWriteStringFormatted( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in __format_string LPCWSTR szFormat, @@ -848,11 +761,7 @@ LExit: } -/******************************************************************** - RegWriteStringArray - writes an array of strings as a REG_MULTI_SZ value - -*********************************************************************/ -HRESULT DAPI RegWriteStringArray( +DAPI_(HRESULT) RegWriteStringArray( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in_ecount(cValues) LPWSTR *rgwzValues, @@ -913,14 +822,10 @@ LExit: return hr; } -/******************************************************************** - RegWriteNone - writes a registry key value as none. - -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteNone( +DAPI_(HRESULT) RegWriteNone( __in HKEY hk, __in_z_opt LPCWSTR wzName -) + ) { HRESULT hr = S_OK; DWORD er = ERROR_SUCCESS; @@ -932,11 +837,7 @@ LExit: return hr; } -/******************************************************************** - RegWriteNumber - writes a registry key value as a number. - -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteNumber( +DAPI_(HRESULT) RegWriteNumber( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in DWORD dwValue @@ -952,11 +853,7 @@ LExit: return hr; } -/******************************************************************** - RegWriteQword - writes a registry key value as a Qword. - -*********************************************************************/ -extern "C" HRESULT DAPI RegWriteQword( +DAPI_(HRESULT) RegWriteQword( __in HKEY hk, __in_z_opt LPCWSTR wzName, __in DWORD64 qwValue @@ -972,11 +869,7 @@ LExit: return hr; } -/******************************************************************** - RegQueryKey - queries the key for the number of subkeys and values. - -*********************************************************************/ -extern "C" HRESULT DAPI RegQueryKey( +DAPI_(HRESULT) RegQueryKey( __in HKEY hk, __out_opt DWORD* pcSubKeys, __out_opt DWORD* pcValues @@ -992,12 +885,7 @@ LExit: return hr; } -/******************************************************************** -RegKeyReadNumber - reads a DWORD registry key value as a number from -a specified subkey. - -*********************************************************************/ -extern "C" HRESULT DAPI RegKeyReadNumber( +DAPI_(HRESULT) RegKeyReadNumber( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, @@ -1025,7 +913,7 @@ RegValueExists - determines whether a named value exists in a specified subkey. *********************************************************************/ -extern "C" BOOL DAPI RegValueExists( +DAPI_(BOOL) RegValueExists( __in HKEY hk, __in_z LPCWSTR wzSubKey, __in_z_opt LPCWSTR wzName, -- cgit v1.2.3-55-g6feb