aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/deputil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/deputil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/deputil.cpp145
1 files changed, 73 insertions, 72 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/deputil.cpp b/src/libs/dutil/WixToolset.DUtil/deputil.cpp
index 4de85199..f92c7d18 100644
--- a/src/libs/dutil/WixToolset.DUtil/deputil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/deputil.cpp
@@ -16,6 +16,7 @@
16#define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__) 16#define DepExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DEPUTIL, p, x, s, __VA_ARGS__)
17#define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__) 17#define DepExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DEPUTIL, e, x, s, __VA_ARGS__)
18#define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__) 18#define DepExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_DEPUTIL, g, x, s, __VA_ARGS__)
19#define DepExitOnPathFailure(x, b, s, ...) ExitOnPathFailureSource(DUTIL_SOURCE_DEPUTIL, x, b, s, __VA_ARGS__)
19 20
20#define ARRAY_GROWTH_SIZE 5 21#define ARRAY_GROWTH_SIZE 5
21 22
@@ -54,6 +55,7 @@ DAPI_(HRESULT) DepGetProviderInformation(
54 HRESULT hr = S_OK; 55 HRESULT hr = S_OK;
55 LPWSTR sczKey = NULL; 56 LPWSTR sczKey = NULL;
56 HKEY hkKey = NULL; 57 HKEY hkKey = NULL;
58 BOOL fExists = FALSE;
57 59
58 // Format the provider dependency registry key. 60 // Format the provider dependency registry key.
59 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 61 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -61,43 +63,32 @@ DAPI_(HRESULT) DepGetProviderInformation(
61 63
62 // Try to open the dependency key. 64 // Try to open the dependency key.
63 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 65 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
64 if (E_FILENOTFOUND == hr) 66 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
67
68 if (!fExists)
65 { 69 {
66 ExitFunction1(hr = E_NOTFOUND); 70 ExitFunction1(hr = E_NOTFOUND);
67 } 71 }
68 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
69 72
70 // Get the Id if requested and available. 73 // Get the Id if requested and available.
71 if (psczId) 74 if (psczId)
72 { 75 {
73 hr = RegReadString(hkKey, NULL, psczId); 76 hr = RegReadString(hkKey, NULL, psczId);
74 if (E_FILENOTFOUND == hr) 77 DepExitOnPathFailure(hr, fExists, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
75 {
76 hr = S_OK;
77 }
78 DepExitOnFailure(hr, "Failed to get the id for the dependency \"%ls\".", wzProviderKey);
79 } 78 }
80 79
81 // Get the DisplayName if requested and available. 80 // Get the DisplayName if requested and available.
82 if (psczName) 81 if (psczName)
83 { 82 {
84 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); 83 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
85 if (E_FILENOTFOUND == hr) 84 DepExitOnPathFailure(hr, fExists, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
86 {
87 hr = S_OK;
88 }
89 DepExitOnFailure(hr, "Failed to get the name for the dependency \"%ls\".", wzProviderKey);
90 } 85 }
91 86
92 // Get the Version if requested and available. 87 // Get the Version if requested and available.
93 if (psczVersion) 88 if (psczVersion)
94 { 89 {
95 hr = RegReadString(hkKey, vcszVersionValue, psczVersion); 90 hr = RegReadString(hkKey, vcszVersionValue, psczVersion);
96 if (E_FILENOTFOUND == hr) 91 DepExitOnPathFailure(hr, fExists, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
97 {
98 hr = S_OK;
99 }
100 DepExitOnFailure(hr, "Failed to get the version for the dependency \"%ls\".", wzProviderKey);
101 } 92 }
102 93
103LExit: 94LExit:
@@ -121,6 +112,7 @@ DAPI_(HRESULT) DepCheckDependency(
121 HRESULT hr = S_OK; 112 HRESULT hr = S_OK;
122 LPWSTR sczKey = NULL; 113 LPWSTR sczKey = NULL;
123 HKEY hkKey = NULL; 114 HKEY hkKey = NULL;
115 BOOL fExists = FALSE;
124 VERUTIL_VERSION* pVersion = NULL; 116 VERUTIL_VERSION* pVersion = NULL;
125 VERUTIL_VERSION* pMinVersion = NULL; 117 VERUTIL_VERSION* pMinVersion = NULL;
126 VERUTIL_VERSION* pMaxVersion = NULL; 118 VERUTIL_VERSION* pMaxVersion = NULL;
@@ -134,20 +126,17 @@ DAPI_(HRESULT) DepCheckDependency(
134 126
135 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist. 127 // Try to open the key. If that fails, add the missing dependency key to the dependency array if it doesn't already exist.
136 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 128 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
137 if (E_FILENOTFOUND != hr) 129 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
138 {
139 DepExitOnFailure(hr, "Failed to open the registry key for dependency \"%ls\".", wzProviderKey);
140 130
131 if (fExists)
132 {
141 // If there are no registry values, consider the key orphaned and treat it as missing. 133 // If there are no registry values, consider the key orphaned and treat it as missing.
142 hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion); 134 hr = RegReadWixVersion(hkKey, vcszVersionValue, &pVersion);
143 if (E_FILENOTFOUND != hr) 135 DepExitOnPathFailure(hr, fExists, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
144 {
145 DepExitOnFailure(hr, "Failed to read the %ls registry value for dependency \"%ls\".", vcszVersionValue, wzProviderKey);
146 }
147 } 136 }
148 137
149 // If the key was not found or the Version value was not found, add the missing dependency key to the dependency array. 138 // If the key was not found or the Version value was not found, add the missing dependency key to the dependency array.
150 if (E_FILENOTFOUND == hr) 139 if (!fExists)
151 { 140 {
152 hr = DictKeyExists(sdDependencies, wzProviderKey); 141 hr = DictKeyExists(sdDependencies, wzProviderKey);
153 if (E_NOTFOUND != hr) 142 if (E_NOTFOUND != hr)
@@ -190,7 +179,7 @@ DAPI_(HRESULT) DepCheckDependency(
190 else 179 else
191 { 180 {
192 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 181 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
193 DepExitOnFailure(hr, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey); 182 DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the older dependency \"%ls\".", wzProviderKey);
194 183
195 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 184 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
196 DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey); 185 DepExitOnFailure(hr, "Failed to add the older dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -228,7 +217,7 @@ DAPI_(HRESULT) DepCheckDependency(
228 else 217 else
229 { 218 {
230 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName); 219 hr = RegReadString(hkKey, vcszDisplayNameValue, &sczName);
231 DepExitOnFailure(hr, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey); 220 DepExitOnPathFailure(hr, fExists, "Failed to get the display name of the newer dependency \"%ls\".", wzProviderKey);
232 221
233 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName); 222 hr = DepDependencyArrayAlloc(prgDependencies, pcDependencies, wzProviderKey, sczName);
234 DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey); 223 DepExitOnFailure(hr, "Failed to add the newer dependency \"%ls\" to the dependencies array.", wzProviderKey);
@@ -267,6 +256,7 @@ DAPI_(HRESULT) DepCheckDependents(
267 LPWSTR sczKey = NULL; 256 LPWSTR sczKey = NULL;
268 HKEY hkProviderKey = NULL; 257 HKEY hkProviderKey = NULL;
269 HKEY hkDependentsKey = NULL; 258 HKEY hkDependentsKey = NULL;
259 BOOL fExists = FALSE;
270 LPWSTR sczDependentKey = NULL; 260 LPWSTR sczDependentKey = NULL;
271 LPWSTR sczDependentName = NULL; 261 LPWSTR sczDependentName = NULL;
272 BOOL fIgnore = FALSE; 262 BOOL fIgnore = FALSE;
@@ -277,15 +267,18 @@ DAPI_(HRESULT) DepCheckDependents(
277 267
278 // Try to open the key. If that fails, the dependency information is corrupt. 268 // Try to open the key. If that fails, the dependency information is corrupt.
279 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey); 269 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkProviderKey);
280 DepExitOnFailure(hr, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey); 270 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key \"%ls\". The dependency store is corrupt.", sczKey);
281 271
282 // Try to open the dependencies key. If that does not exist, there are no dependents. 272 if (!fExists)
283 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
284 if (E_FILENOTFOUND != hr)
285 { 273 {
286 DepExitOnFailure(hr, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey); 274 ExitFunction1(hr = S_OK);
287 } 275 }
288 else 276
277 // Try to open the dependencies key. If that does not exist, there are no dependents.
278 hr = RegOpen(hkProviderKey, vsczRegistryDependents, KEY_READ, &hkDependentsKey);
279 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for dependents of \"%ls\".", wzProviderKey);
280
281 if (!fExists)
289 { 282 {
290 ExitFunction1(hr = S_OK); 283 ExitFunction1(hr = S_OK);
291 } 284 }
@@ -399,15 +392,18 @@ DAPI_(HRESULT) DepDependentExists(
399 HRESULT hr = S_OK; 392 HRESULT hr = S_OK;
400 LPWSTR sczDependentKey = NULL; 393 LPWSTR sczDependentKey = NULL;
401 HKEY hkDependentKey = NULL; 394 HKEY hkDependentKey = NULL;
395 BOOL fExists = FALSE;
402 396
403 // Format the provider dependents registry key. 397 // Format the provider dependents registry key.
404 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey); 398 hr = StrAllocFormatted(&sczDependentKey, L"%ls%ls\\%ls\\%ls", vsczRegistryRoot, wzDependencyProviderKey, vsczRegistryDependents, wzProviderKey);
405 DepExitOnFailure(hr, "Failed to format registry key to dependent."); 399 DepExitOnFailure(hr, "Failed to format registry key to dependent.");
406 400
407 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey); 401 hr = RegOpen(hkHive, sczDependentKey, KEY_READ, &hkDependentKey);
408 if (E_FILENOTFOUND != hr) 402 DepExitOnPathFailure(hr, fExists, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey);
403
404 if (!fExists)
409 { 405 {
410 DepExitOnFailure(hr, "Failed to open the dependent registry key at: \"%ls\".", sczDependentKey); 406 hr = E_FILENOTFOUND;
411 } 407 }
412 408
413LExit: 409LExit:
@@ -480,6 +476,7 @@ DAPI_(HRESULT) DepUnregisterDependency(
480 HRESULT hr = S_OK; 476 HRESULT hr = S_OK;
481 LPWSTR sczKey = NULL; 477 LPWSTR sczKey = NULL;
482 HKEY hkKey = NULL; 478 HKEY hkKey = NULL;
479 BOOL fExists = FALSE;
483 480
484 // Format the provider dependency registry key. 481 // Format the provider dependency registry key.
485 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 482 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -487,9 +484,11 @@ DAPI_(HRESULT) DepUnregisterDependency(
487 484
488 // Delete the entire key including all sub-keys. 485 // Delete the entire key including all sub-keys.
489 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE); 486 hr = RegDelete(hkHive, sczKey, REG_KEY_DEFAULT, TRUE);
490 if (E_FILENOTFOUND != hr) 487 DepExitOnPathFailure(hr, fExists, "Failed to delete the key \"%ls\".", sczKey);
488
489 if (!fExists)
491 { 490 {
492 DepExitOnFailure(hr, "Failed to delete the key \"%ls\".", sczKey); 491 hr = E_FILENOTFOUND;
493 } 492 }
494 493
495LExit: 494LExit:
@@ -506,6 +505,7 @@ DAPI_(HRESULT) DepUnregisterDependent(
506 ) 505 )
507{ 506{
508 HRESULT hr = S_OK; 507 HRESULT hr = S_OK;
508 BOOL fExists = FALSE;
509 HKEY hkRegistryRoot = NULL; 509 HKEY hkRegistryRoot = NULL;
510 HKEY hkDependencyProviderKey = NULL; 510 HKEY hkDependencyProviderKey = NULL;
511 HKEY hkRegistryDependents = NULL; 511 HKEY hkRegistryDependents = NULL;
@@ -514,40 +514,39 @@ DAPI_(HRESULT) DepUnregisterDependent(
514 514
515 // Open the root key. We may delete the wzDependencyProviderKey during clean up. 515 // Open the root key. We may delete the wzDependencyProviderKey during clean up.
516 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot); 516 hr = RegOpen(hkHive, vsczRegistryRoot, KEY_READ, &hkRegistryRoot);
517 if (E_FILENOTFOUND != hr) 517 DepExitOnPathFailure(hr, fExists, "Failed to open root registry key \"%ls\".", vsczRegistryRoot);
518 { 518
519 DepExitOnFailure(hr, "Failed to open root registry key \"%ls\".", vsczRegistryRoot); 519 if (!fExists)
520 }
521 else
522 { 520 {
523 ExitFunction(); 521 ExitFunction1(hr = E_FILENOTFOUND);
524 } 522 }
525 523
526 // Try to open the dependency key. If that does not exist, simply return. 524 // Try to open the dependency key. If that does not exist, simply return.
527 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey); 525 hr = RegOpen(hkRegistryRoot, wzDependencyProviderKey, KEY_READ, &hkDependencyProviderKey);
528 if (E_FILENOTFOUND != hr) 526 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey);
529 { 527
530 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzDependencyProviderKey); 528 if (!fExists)
531 }
532 else
533 { 529 {
534 ExitFunction(); 530 ExitFunction1(hr = E_FILENOTFOUND);
535 } 531 }
536 532
537 // Try to open the dependents subkey to enumerate. 533 // Try to open the dependents subkey to enumerate.
538 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents); 534 hr = RegOpen(hkDependencyProviderKey, vsczRegistryDependents, KEY_READ, &hkRegistryDependents);
539 if (E_FILENOTFOUND != hr) 535 DepExitOnPathFailure(hr, fExists, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
540 { 536
541 DepExitOnFailure(hr, "Failed to open the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); 537 if (!fExists)
542 }
543 else
544 { 538 {
545 ExitFunction(); 539 ExitFunction1(hr = E_FILENOTFOUND);
546 } 540 }
547 541
548 // Delete the wzProviderKey dependent sub-key. 542 // Delete the wzProviderKey dependent sub-key.
549 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE); 543 hr = RegDelete(hkRegistryDependents, wzProviderKey, REG_KEY_DEFAULT, TRUE);
550 DepExitOnFailure(hr, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey); 544 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependent \"%ls\" under the dependency \"%ls\".", wzProviderKey, wzDependencyProviderKey);
545
546 if (!fExists)
547 {
548 ExitFunction1(hr = E_FILENOTFOUND);
549 }
551 550
552 // If there are no remaining dependents, delete the Dependents subkey. 551 // If there are no remaining dependents, delete the Dependents subkey.
553 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL); 552 hr = RegQueryKey(hkRegistryDependents, &cSubKeys, NULL);
@@ -563,7 +562,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
563 562
564 // Fail if there are any subkeys since we just checked. 563 // Fail if there are any subkeys since we just checked.
565 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE); 564 hr = RegDelete(hkDependencyProviderKey, vsczRegistryDependents, REG_KEY_DEFAULT, FALSE);
566 DepExitOnFailure(hr, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey); 565 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependents subkey under the dependency \"%ls\".", wzDependencyProviderKey);
566
567 if (!fExists)
568 {
569 ExitFunction1(hr = E_FILENOTFOUND);
570 }
567 571
568 // If there are no values, delete the provider dependency key. 572 // If there are no values, delete the provider dependency key.
569 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues); 573 hr = RegQueryKey(hkDependencyProviderKey, NULL, &cValues);
@@ -576,7 +580,12 @@ DAPI_(HRESULT) DepUnregisterDependent(
576 580
577 // Fail if there are any subkeys since we just checked. 581 // Fail if there are any subkeys since we just checked.
578 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE); 582 hr = RegDelete(hkRegistryRoot, wzDependencyProviderKey, REG_KEY_DEFAULT, FALSE);
579 DepExitOnFailure(hr, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey); 583 DepExitOnPathFailure(hr, fExists, "Failed to delete the dependency \"%ls\".", wzDependencyProviderKey);
584
585 if (!fExists)
586 {
587 ExitFunction1(hr = E_FILENOTFOUND);
588 }
580 } 589 }
581 590
582LExit: 591LExit:
@@ -685,6 +694,7 @@ static HRESULT GetDependencyNameFromKey(
685 HRESULT hr = S_OK; 694 HRESULT hr = S_OK;
686 LPWSTR sczKey = NULL; 695 LPWSTR sczKey = NULL;
687 HKEY hkKey = NULL; 696 HKEY hkKey = NULL;
697 BOOL fExists = FALSE;
688 698
689 // Format the provider dependency registry key. 699 // Format the provider dependency registry key.
690 hr = AllocDependencyKeyName(wzProviderKey, &sczKey); 700 hr = AllocDependencyKeyName(wzProviderKey, &sczKey);
@@ -692,25 +702,16 @@ static HRESULT GetDependencyNameFromKey(
692 702
693 // Try to open the dependency key. 703 // Try to open the dependency key.
694 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey); 704 hr = RegOpen(hkHive, sczKey, KEY_READ, &hkKey);
695 if (E_FILENOTFOUND != hr) 705 DepExitOnPathFailure(hr, fExists, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey);
696 { 706
697 DepExitOnFailure(hr, "Failed to open the registry key for the dependency \"%ls\".", wzProviderKey); 707 if (!fExists)
698 }
699 else
700 { 708 {
701 ExitFunction1(hr = S_OK); 709 ExitFunction();
702 } 710 }
703 711
704 // Get the DisplayName if available. 712 // Get the DisplayName if available.
705 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName); 713 hr = RegReadString(hkKey, vcszDisplayNameValue, psczName);
706 if (E_FILENOTFOUND != hr) 714 DepExitOnPathFailure(hr, fExists, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
707 {
708 DepExitOnFailure(hr, "Failed to get the dependency name for the dependency \"%ls\".", wzProviderKey);
709 }
710 else
711 {
712 ExitFunction1(hr = S_OK);
713 }
714 715
715LExit: 716LExit:
716 ReleaseRegKey(hkKey); 717 ReleaseRegKey(hkKey);