aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/butil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/butil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/butil.cpp140
1 files changed, 128 insertions, 12 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/butil.cpp b/src/libs/dutil/WixToolset.DUtil/butil.cpp
index 5e980699..4c96dfc1 100644
--- a/src/libs/dutil/WixToolset.DUtil/butil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/butil.cpp
@@ -57,6 +57,11 @@ static HRESULT OpenBundleKey(
57 __in_opt LPCWSTR wzSubKey, 57 __in_opt LPCWSTR wzSubKey,
58 __inout HKEY* phKey 58 __inout HKEY* phKey
59 ); 59 );
60static HRESULT CopyStringToBuffer(
61 __in_z LPWSTR wzValue,
62 __in_z_opt LPWSTR wzBuffer,
63 __inout SIZE_T* pcchBuffer
64 );
60 65
61DAPI_(HRESULT) BundleGetBundleInfo( 66DAPI_(HRESULT) BundleGetBundleInfo(
62 __in_z LPCWSTR wzBundleId, 67 __in_z LPCWSTR wzBundleId,
@@ -111,11 +116,39 @@ LExit:
111} 116}
112 117
113 118
119DAPI_(HRESULT) BundleGetBundleInfoFixed(
120 __in_z LPCWSTR wzBundleId,
121 __in_z LPCWSTR wzAttribute,
122 __out_ecount_opt(*pcchValue) LPWSTR wzValue,
123 __inout SIZE_T* pcchValue
124 )
125{
126 HRESULT hr = S_OK;
127 LPWSTR sczValue = NULL;
128
129 if (!pcchValue)
130 {
131 ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
132 }
133
134 hr = BundleGetBundleInfo(wzBundleId, wzAttribute, &sczValue);
135 if (SUCCEEDED(hr))
136 {
137 hr = CopyStringToBuffer(sczValue, wzValue, pcchValue);
138 }
139
140LExit:
141 ReleaseStr(sczValue);
142
143 return hr;
144}
145
146
114DAPI_(HRESULT) BundleEnumRelatedBundle( 147DAPI_(HRESULT) BundleEnumRelatedBundle(
115 __in_z LPCWSTR wzUpgradeCode, 148 __in_z LPCWSTR wzUpgradeCode,
116 __in BUNDLE_INSTALL_CONTEXT context, 149 __in BUNDLE_INSTALL_CONTEXT context,
117 __inout PDWORD pdwStartIndex, 150 __inout PDWORD pdwStartIndex,
118 __out_ecount(MAX_GUID_CHARS+1) LPWSTR lpBundleIdBuf 151 __deref_out_z LPWSTR* psczBundleId
119 ) 152 )
120{ 153{
121 HRESULT hr = S_OK; 154 HRESULT hr = S_OK;
@@ -123,7 +156,6 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
123 HKEY hkUninstall = NULL; 156 HKEY hkUninstall = NULL;
124 HKEY hkBundle = NULL; 157 HKEY hkBundle = NULL;
125 LPWSTR sczUninstallSubKey = NULL; 158 LPWSTR sczUninstallSubKey = NULL;
126 size_t cchUninstallSubKey = 0;
127 LPWSTR sczUninstallSubKeyPath = NULL; 159 LPWSTR sczUninstallSubKeyPath = NULL;
128 LPWSTR sczValue = NULL; 160 LPWSTR sczValue = NULL;
129 DWORD dwType = 0; 161 DWORD dwType = 0;
@@ -132,7 +164,7 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
132 DWORD cBundleUpgradeCodes = 0; 164 DWORD cBundleUpgradeCodes = 0;
133 BOOL fUpgradeCodeFound = FALSE; 165 BOOL fUpgradeCodeFound = FALSE;
134 166
135 if (!wzUpgradeCode || !lpBundleIdBuf || !pdwStartIndex) 167 if (!wzUpgradeCode || !pdwStartIndex)
136 { 168 {
137 ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function."); 169 ButilExitOnFailure(hr = E_INVALIDARG, "An invalid parameter was passed to the function.");
138 } 170 }
@@ -205,13 +237,10 @@ DAPI_(HRESULT) BundleEnumRelatedBundle(
205 237
206 if (fUpgradeCodeFound) 238 if (fUpgradeCodeFound)
207 { 239 {
208 if (lpBundleIdBuf) 240 if (psczBundleId)
209 { 241 {
210 hr = ::StringCchLengthW(sczUninstallSubKey, STRSAFE_MAX_CCH, &cchUninstallSubKey); 242 *psczBundleId = sczUninstallSubKey;
211 ButilExitOnRootFailure(hr, "Failed to calculate length of string."); 243 sczUninstallSubKey = NULL;
212
213 hr = ::StringCchCopyNExW(lpBundleIdBuf, MAX_GUID_CHARS + 1, sczUninstallSubKey, cchUninstallSubKey, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
214 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
215 } 244 }
216 245
217 break; 246 break;
@@ -235,6 +264,34 @@ LExit:
235} 264}
236 265
237 266
267DAPI_(HRESULT) BundleEnumRelatedBundleFixed(
268 __in_z LPCWSTR wzUpgradeCode,
269 __in BUNDLE_INSTALL_CONTEXT context,
270 __inout PDWORD pdwStartIndex,
271 __out_ecount(MAX_GUID_CHARS+1) LPWSTR wzBundleId
272 )
273{
274 HRESULT hr = S_OK;
275 LPWSTR sczValue = NULL;
276 size_t cchValue = 0;
277
278 hr = BundleEnumRelatedBundle(wzUpgradeCode, context, pdwStartIndex, &sczValue);
279 if (SUCCEEDED(hr) && wzBundleId)
280 {
281 hr = ::StringCchLengthW(sczValue, STRSAFE_MAX_CCH, &cchValue);
282 ButilExitOnRootFailure(hr, "Failed to calculate length of string.");
283
284 hr = ::StringCchCopyNExW(wzBundleId, MAX_GUID_CHARS + 1, sczValue, cchValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
285 ButilExitOnRootFailure(hr, "Failed to copy the property value to the output buffer.");
286 }
287
288LExit:
289 ReleaseStr(sczValue);
290
291 return hr;
292}
293
294
238DAPI_(HRESULT) BundleGetBundleVariable( 295DAPI_(HRESULT) BundleGetBundleVariable(
239 __in_z LPCWSTR wzBundleId, 296 __in_z LPCWSTR wzBundleId,
240 __in_z LPCWSTR wzVariable, 297 __in_z LPCWSTR wzVariable,
@@ -282,6 +339,34 @@ LExit:
282 return hr; 339 return hr;
283} 340}
284 341
342
343DAPI_(HRESULT) BundleGetBundleVariableFixed(
344 __in_z LPCWSTR wzBundleId,
345 __in_z LPCWSTR wzVariable,
346 __out_ecount_opt(*pcchValue) LPWSTR wzValue,
347 __inout SIZE_T* pcchValue
348 )
349{
350 HRESULT hr = S_OK;
351 LPWSTR sczValue = NULL;
352
353 if (!pcchValue)
354 {
355 ButilExitWithRootFailure(hr, E_INVALIDARG, "An invalid parameter was passed to the function.");
356 }
357
358 hr = BundleGetBundleVariable(wzBundleId, wzVariable, &sczValue);
359 if (SUCCEEDED(hr))
360 {
361 hr = CopyStringToBuffer(sczValue, wzValue, pcchValue);
362 }
363
364LExit:
365 ReleaseStr(sczValue);
366
367 return hr;
368}
369
285static HRESULT LocateAndQueryBundleValue( 370static HRESULT LocateAndQueryBundleValue(
286 __in_z LPCWSTR wzBundleId, 371 __in_z LPCWSTR wzBundleId,
287 __in_opt LPCWSTR wzSubKey, 372 __in_opt LPCWSTR wzSubKey,
@@ -356,3 +441,34 @@ LExit:
356 441
357 return hr; 442 return hr;
358} 443}
444
445static HRESULT CopyStringToBuffer(
446 __in_z LPWSTR wzValue,
447 __in_z_opt LPWSTR wzBuffer,
448 __inout SIZE_T* pcchBuffer
449 )
450{
451 HRESULT hr = S_OK;
452 BOOL fTooSmall = !wzBuffer;
453
454 if (!fTooSmall)
455 {
456 hr = ::StringCchCopyExW(wzBuffer, *pcchBuffer, wzValue, NULL, NULL, STRSAFE_FILL_BEHIND_NULL);
457 if (STRSAFE_E_INSUFFICIENT_BUFFER == hr)
458 {
459 fTooSmall = TRUE;
460 }
461 }
462
463 if (fTooSmall)
464 {
465 hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_LENGTH, reinterpret_cast<size_t*>(pcchBuffer));
466 if (SUCCEEDED(hr))
467 {
468 hr = E_MOREDATA;
469 *pcchBuffer += 1; // null terminator.
470 }
471 }
472
473 return hr;
474}