diff options
Diffstat (limited to 'src/ext/Util/ca/RemoveRegistryKeysEx.cpp')
-rw-r--r-- | src/ext/Util/ca/RemoveRegistryKeysEx.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/ext/Util/ca/RemoveRegistryKeysEx.cpp b/src/ext/Util/ca/RemoveRegistryKeysEx.cpp new file mode 100644 index 00000000..478c0779 --- /dev/null +++ b/src/ext/Util/ca/RemoveRegistryKeysEx.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | LPCWSTR vcsRemoveRegistryKeyExQuery = | ||
6 | L"SELECT `Wix4RemoveRegistryKeyEx`, `Component_`, `Root`, `Key`, `InstallMode`, `Condition` FROM `Wix4RemoveRegistryKeyEx`"; | ||
7 | enum eRemoveRegistryKeyExQuery { rrxqId = 1, rrxqComponent, rrxqRoot, rrxqKey, rrxqMode, rrxqCondition }; | ||
8 | |||
9 | extern "C" UINT WINAPI WixRemoveRegistryKeysEx( | ||
10 | __in MSIHANDLE hInstall | ||
11 | ) | ||
12 | { | ||
13 | //AssertSz(FALSE, "debug WixRemoveRegistryKeyEx"); | ||
14 | |||
15 | HRESULT hr = S_OK; | ||
16 | PMSIHANDLE hView; | ||
17 | PMSIHANDLE hRec; | ||
18 | LPWSTR sczId = NULL; | ||
19 | LPWSTR sczComponent = NULL; | ||
20 | LPWSTR sczCondition = NULL; | ||
21 | LPWSTR sczKey = NULL; | ||
22 | int iRoot = 0; | ||
23 | int iMode = 0; | ||
24 | MSIHANDLE hTable = NULL; | ||
25 | MSIHANDLE hColumns = NULL; | ||
26 | |||
27 | hr = WcaInitialize(hInstall, __FUNCTION__); | ||
28 | ExitOnFailure(hr, "Failed to initialize " __FUNCTION__); | ||
29 | |||
30 | // anything to do? | ||
31 | if (S_OK != WcaTableExists(L"Wix4RemoveRegistryKeyEx")) | ||
32 | { | ||
33 | WcaLog(LOGMSG_STANDARD, "Wix4RemoveRegistryKeyEx table doesn't exist, so there are no registry keys to remove."); | ||
34 | ExitFunction(); | ||
35 | } | ||
36 | |||
37 | hr = WcaOpenExecuteView(vcsRemoveRegistryKeyExQuery, &hView); | ||
38 | ExitOnFailure(hr, "Failed to open view on Wix4RemoveRegistryKeyEx table"); | ||
39 | |||
40 | while (S_OK == (hr = WcaFetchRecord(hView, &hRec))) | ||
41 | { | ||
42 | hr = WcaGetRecordString(hRec, rrxqId, &sczId); | ||
43 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx identity."); | ||
44 | |||
45 | hr = WcaGetRecordString(hRec, rrxqCondition, &sczCondition); | ||
46 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx condition."); | ||
47 | |||
48 | if (sczCondition && *sczCondition) | ||
49 | { | ||
50 | MSICONDITION condition = ::MsiEvaluateConditionW(hInstall, sczCondition); | ||
51 | if (MSICONDITION_TRUE == condition) | ||
52 | { | ||
53 | WcaLog(LOGMSG_STANDARD, "True condition for row %S: %S; processing.", sczId, sczCondition); | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | WcaLog(LOGMSG_STANDARD, "False or invalid condition for row %S: %S; skipping.", sczId, sczCondition); | ||
58 | continue; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | hr = WcaGetRecordString(hRec, rrxqComponent, &sczComponent); | ||
63 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx component."); | ||
64 | |||
65 | hr = WcaGetRecordInteger(hRec, rrxqRoot, &iRoot); | ||
66 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx root."); | ||
67 | |||
68 | hr = WcaGetRecordString(hRec, rrxqKey, &sczKey); | ||
69 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx key."); | ||
70 | |||
71 | hr = WcaGetRecordInteger(hRec, rrxqMode, &iMode); | ||
72 | ExitOnFailure(hr, "Failed to get Wix4RemoveRegistryKeyEx mode."); | ||
73 | |||
74 | switch (iMode) | ||
75 | { | ||
76 | case 1: // remove on install | ||
77 | WcaLog(LOGMSG_STANDARD, "Adding RemoveRegistry row: %ls/%d/%ls/-/%ls", sczId, iRoot, sczKey, sczComponent); | ||
78 | hr = WcaAddTempRecord(&hTable, &hColumns, L"RemoveRegistry", NULL, 0, 5, sczId, iRoot, sczKey, L"-", sczComponent); | ||
79 | ExitOnFailure(hr, "Failed to add RemoveRegistry row for remove-on-install Wix4RemoveRegistryKeyEx row: %ls:", sczId); | ||
80 | break; | ||
81 | case 2: // remove on uninstall | ||
82 | WcaLog(LOGMSG_STANDARD, "Adding Registry row: %ls/%d/%ls/-/null/%ls", sczId, iRoot, sczKey, sczComponent); | ||
83 | hr = WcaAddTempRecord(&hTable, &hColumns, L"Registry", NULL, 0, 6, sczId, iRoot, sczKey, L"-", NULL, sczComponent); | ||
84 | ExitOnFailure(hr, "Failed to add Registry row for remove-on-uninstall Wix4RemoveRegistryKeyEx row: %ls:", sczId); | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // reaching the end of the list is actually a good thing, not an error | ||
90 | if (E_NOMOREITEMS == hr) | ||
91 | { | ||
92 | hr = S_OK; | ||
93 | } | ||
94 | ExitOnFailure(hr, "Failure occured while processing Wix4RemoveRegistryKeyEx table."); | ||
95 | |||
96 | LExit: | ||
97 | if (hColumns) | ||
98 | { | ||
99 | ::MsiCloseHandle(hColumns); | ||
100 | } | ||
101 | |||
102 | if (hTable) | ||
103 | { | ||
104 | ::MsiCloseHandle(hTable); | ||
105 | } | ||
106 | |||
107 | ReleaseStr(sczKey); | ||
108 | ReleaseStr(sczComponent); | ||
109 | ReleaseStr(sczCondition); | ||
110 | ReleaseStr(sczId); | ||
111 | |||
112 | DWORD er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; | ||
113 | return WcaFinalize(er); | ||
114 | } | ||