diff options
author | Rob Mensching <rob@firegiant.com> | 2021-04-11 12:23:19 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-04-12 19:28:07 -0700 |
commit | ae7e9817bb10d635e031e51496f2e529595a9cfe (patch) | |
tree | c70942b721dc860dd8ea7d14e90ed0f880030983 /src/ca | |
parent | 13c4becf524dbd12b92f099320726aa0b59f3bbc (diff) | |
download | wix-ae7e9817bb10d635e031e51496f2e529595a9cfe.tar.gz wix-ae7e9817bb10d635e031e51496f2e529595a9cfe.tar.bz2 wix-ae7e9817bb10d635e031e51496f2e529595a9cfe.zip |
Add RemoveRegistryKey
Diffstat (limited to 'src/ca')
-rw-r--r-- | src/ca/RemoveRegistryKeysEx.cpp | 114 | ||||
-rw-r--r-- | src/ca/utilca.def | 2 | ||||
-rw-r--r-- | src/ca/utilca.vcxproj | 1 |
3 files changed, 117 insertions, 0 deletions
diff --git a/src/ca/RemoveRegistryKeysEx.cpp b/src/ca/RemoveRegistryKeysEx.cpp new file mode 100644 index 00000000..478c0779 --- /dev/null +++ b/src/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 | } | ||
diff --git a/src/ca/utilca.def b/src/ca/utilca.def index 97d5776f..337c3a68 100644 --- a/src/ca/utilca.def +++ b/src/ca/utilca.def | |||
@@ -35,6 +35,8 @@ EXPORTS | |||
35 | WixSilentExec64 | 35 | WixSilentExec64 |
36 | ; RemoveFoldersEx.cpp | 36 | ; RemoveFoldersEx.cpp |
37 | WixRemoveFoldersEx | 37 | WixRemoveFoldersEx |
38 | ; RemoveRegistryKeysEx.cpp | ||
39 | WixRemoveRegistryKeysEx | ||
38 | ;scaexec.cpp | 40 | ;scaexec.cpp |
39 | RegisterPerfCounterData | 41 | RegisterPerfCounterData |
40 | UnregisterPerfCounterData | 42 | UnregisterPerfCounterData |
diff --git a/src/ca/utilca.vcxproj b/src/ca/utilca.vcxproj index 4fafba68..6a076f2f 100644 --- a/src/ca/utilca.vcxproj +++ b/src/ca/utilca.vcxproj | |||
@@ -59,6 +59,7 @@ | |||
59 | <ClCompile Include="OsInfo.cpp" /> | 59 | <ClCompile Include="OsInfo.cpp" /> |
60 | <ClCompile Include="qtexecca.cpp" /> | 60 | <ClCompile Include="qtexecca.cpp" /> |
61 | <ClCompile Include="RemoveFoldersEx.cpp" /> | 61 | <ClCompile Include="RemoveFoldersEx.cpp" /> |
62 | <ClCompile Include="RemoveRegistryKeysEx.cpp" /> | ||
62 | <ClCompile Include="RestartManager.cpp" /> | 63 | <ClCompile Include="RestartManager.cpp" /> |
63 | <ClCompile Include="scaexec.cpp" /> | 64 | <ClCompile Include="scaexec.cpp" /> |
64 | <ClCompile Include="scamanifest.cpp" /> | 65 | <ClCompile Include="scamanifest.cpp" /> |