aboutsummaryrefslogtreecommitdiff
path: root/src/ca/scaperf.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2018-12-15 21:46:30 -0600
committerGitHub <noreply@github.com>2018-12-15 21:46:30 -0600
commitf7020c0d16baf2b960e7123e233e20c519f6a340 (patch)
treed2cd464ee15b2b3f304ff780c531b39bb292d331 /src/ca/scaperf.cpp
parent6ed8d107e6edf16956c778bda3573f8d7a7690fc (diff)
downloadwix-f7020c0d16baf2b960e7123e233e20c519f6a340.tar.gz
wix-f7020c0d16baf2b960e7123e233e20c519f6a340.tar.bz2
wix-f7020c0d16baf2b960e7123e233e20c519f6a340.zip
Import implementation of UtilCA from old repo's WixCA/scasched/scaexec. (#3)
Diffstat (limited to 'src/ca/scaperf.cpp')
-rw-r--r--src/ca/scaperf.cpp310
1 files changed, 310 insertions, 0 deletions
diff --git a/src/ca/scaperf.cpp b/src/ca/scaperf.cpp
new file mode 100644
index 00000000..82f458af
--- /dev/null
+++ b/src/ca/scaperf.cpp
@@ -0,0 +1,310 @@
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
5LPCWSTR vcsPerfCounterDataQuery = L"SELECT `PerformanceCategory`, `Component_`, `Name`, `IniData`, `ConstantData` FROM `PerformanceCategory`";
6enum ePerfCounterDataQuery { pcdqId = 1, pcdqComponent, pcdqName, pcdqIniData, pcdqConstantData };
7
8LPCWSTR vcsPerfMonQuery = L"SELECT `Component_`, `File`, `Name` FROM `Perfmon`";
9enum ePerfMonQuery { pmqComponent = 1, pmqFile, pmqName };
10
11
12static HRESULT ProcessPerformanceCategory(
13 __in MSIHANDLE hInstall,
14 __in BOOL fInstall
15 );
16
17
18/********************************************************************
19 InstallPerfCounterData - CUSTOM ACTION ENTRY POINT for installing
20 Performance Counters.
21
22********************************************************************/
23extern "C" UINT __stdcall InstallPerfCounterData(
24 __in MSIHANDLE hInstall
25 )
26{
27 // AssertSz(FALSE, "debug InstallPerfCounterData{}");
28 HRESULT hr;
29 UINT er = ERROR_SUCCESS;
30
31 hr = WcaInitialize(hInstall, "InstallPerfCounterData");
32 ExitOnFailure(hr, "Failed to initialize InstallPerfCounterData.");
33
34 hr = ProcessPerformanceCategory(hInstall, TRUE);
35 MessageExitOnFailure(hr, msierrInstallPerfCounterData, "Failed to process PerformanceCategory table.");
36
37LExit:
38 er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
39 return WcaFinalize(er);
40}
41
42
43/********************************************************************
44 UninstallPerfCounterData - CUSTOM ACTION ENTRY POINT for installing
45 Performance Counters.
46
47********************************************************************/
48extern "C" UINT __stdcall UninstallPerfCounterData(
49 __in MSIHANDLE hInstall
50 )
51{
52 // AssertSz(FALSE, "debug UninstallPerfCounterData{}");
53 HRESULT hr;
54 UINT er = ERROR_SUCCESS;
55
56 hr = WcaInitialize(hInstall, "UninstallPerfCounterData");
57 ExitOnFailure(hr, "Failed to initialize UninstallPerfCounterData.");
58
59 hr = ProcessPerformanceCategory(hInstall, FALSE);
60 MessageExitOnFailure(hr, msierrUninstallPerfCounterData, "Failed to process PerformanceCategory table.");
61
62LExit:
63 er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
64 return WcaFinalize(er);
65}
66
67
68/********************************************************************
69 RegisterPerfmon - CUSTOM ACTION ENTRY POINT for installing Perfmon counters
70
71********************************************************************/
72extern "C" UINT __stdcall ConfigurePerfmonInstall(
73 __in MSIHANDLE hInstall
74 )
75{
76// Assert(FALSE);
77 HRESULT hr;
78 UINT er = ERROR_SUCCESS;
79
80 PMSIHANDLE hView, hRec;
81 LPWSTR pwzData = NULL, pwzName = NULL, pwzFile = NULL;
82 INSTALLSTATE isInstalled, isAction;
83
84 hr = WcaInitialize(hInstall, "ConfigurePerfmonInstall");
85 ExitOnFailure(hr, "Failed to initialize");
86
87 // check to see if necessary tables are specified
88 if (S_OK != WcaTableExists(L"Perfmon"))
89 {
90 WcaLog(LOGMSG_VERBOSE, "Skipping RegisterPerfmon() because Perfmon table not present");
91 ExitFunction1(hr = S_FALSE);
92 }
93
94 hr = WcaOpenExecuteView(vcsPerfMonQuery, &hView);
95 ExitOnFailure(hr, "failed to open view on PerfMon table");
96 while ((hr = WcaFetchRecord(hView, &hRec)) == S_OK)
97 {
98 // get component install state
99 hr = WcaGetRecordString(hRec, pmqComponent, &pwzData);
100 ExitOnFailure(hr, "failed to get Component for PerfMon");
101 er = ::MsiGetComponentStateW(hInstall, pwzData, &isInstalled, &isAction);
102 hr = HRESULT_FROM_WIN32(er);
103 ExitOnFailure(hr, "failed to get Component state for PerfMon");
104 if (!WcaIsInstalling(isInstalled, isAction))
105 {
106 continue;
107 }
108
109 hr = WcaGetRecordString(hRec, pmqName, &pwzName);
110 ExitOnFailure(hr, "failed to get Name for PerfMon");
111
112 hr = WcaGetRecordFormattedString(hRec, pmqFile, &pwzFile);
113 ExitOnFailure(hr, "failed to get File for PerfMon");
114
115 WcaLog(LOGMSG_VERBOSE, "ConfigurePerfmonInstall's CustomActionData: '%ls', '%ls'", pwzName, pwzFile);
116 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RegisterPerfmon"), pwzFile, COST_PERFMON_REGISTER);
117 ExitOnFailure(hr, "failed to schedule RegisterPerfmon action");
118 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackRegisterPerfmon"), pwzName, COST_PERFMON_UNREGISTER);
119 ExitOnFailure(hr, "failed to schedule RollbackRegisterPerfmon action");
120 }
121
122 if (hr == E_NOMOREITEMS)
123 {
124 hr = S_OK;
125 }
126 ExitOnFailure(hr, "Failure while processing PerfMon");
127
128 hr = S_OK;
129
130LExit:
131 ReleaseStr(pwzData);
132 ReleaseStr(pwzName);
133 ReleaseStr(pwzFile);
134
135 er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
136 return WcaFinalize(er);
137}
138
139
140/********************************************************************
141 ConfigurePerfmonUninstall - CUSTOM ACTION ENTRY POINT for uninstalling
142 Perfmon counters
143
144********************************************************************/
145extern "C" UINT __stdcall ConfigurePerfmonUninstall(
146 __in MSIHANDLE hInstall
147 )
148{
149// Assert(FALSE);
150 HRESULT hr;
151 UINT er = ERROR_SUCCESS;
152
153 PMSIHANDLE hView, hRec;
154 LPWSTR pwzData = NULL, pwzName = NULL, pwzFile = NULL;
155 INSTALLSTATE isInstalled, isAction;
156
157 hr = WcaInitialize(hInstall, "ConfigurePerfmonUninstall");
158 ExitOnFailure(hr, "Failed to initialize");
159
160 // check to see if necessary tables are specified
161 if (WcaTableExists(L"Perfmon") != S_OK)
162 {
163 WcaLog(LOGMSG_VERBOSE, "Skipping UnregisterPerfmon() because Perfmon table not present");
164 ExitFunction1(hr = S_FALSE);
165 }
166
167 hr = WcaOpenExecuteView(vcsPerfMonQuery, &hView);
168 ExitOnFailure(hr, "failed to open view on PerfMon table");
169 while ((hr = WcaFetchRecord(hView, &hRec)) == S_OK)
170 {
171 // get component install state
172 hr = WcaGetRecordString(hRec, pmqComponent, &pwzData);
173 ExitOnFailure(hr, "failed to get Component for PerfMon");
174 er = ::MsiGetComponentStateW(hInstall, pwzData, &isInstalled, &isAction);
175 hr = HRESULT_FROM_WIN32(er);
176 ExitOnFailure(hr, "failed to get Component state for PerfMon");
177 if (!WcaIsUninstalling(isInstalled, isAction))
178 {
179 continue;
180 }
181
182 hr = WcaGetRecordString(hRec, pmqName, &pwzName);
183 ExitOnFailure(hr, "failed to get Name for PerfMon");
184
185 hr = WcaGetRecordFormattedString(hRec, pmqFile, &pwzFile);
186 ExitOnFailure(hr, "failed to get File for PerfMon");
187
188 WcaLog(LOGMSG_VERBOSE, "ConfigurePerfmonUninstall's CustomActionData: '%ls', '%ls'", pwzName, pwzFile);
189 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"UnregisterPerfmon"), pwzName, COST_PERFMON_UNREGISTER);
190 ExitOnFailure(hr, "failed to schedule UnregisterPerfmon action");
191 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackUnregisterPerfmon"), pwzFile, COST_PERFMON_REGISTER);
192 ExitOnFailure(hr, "failed to schedule RollbackUnregisterPerfmon action");
193 }
194
195 if (hr == E_NOMOREITEMS)
196 {
197 hr = S_OK;
198 }
199 ExitOnFailure(hr, "Failure while processing PerfMon");
200
201 hr = S_OK;
202
203LExit:
204 ReleaseStr(pwzData);
205 ReleaseStr(pwzName);
206 ReleaseStr(pwzFile);
207
208 er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
209 return WcaFinalize(er);
210}
211
212
213
214static HRESULT ProcessPerformanceCategory(
215 __in MSIHANDLE hInstall,
216 __in BOOL fInstall
217 )
218{
219 HRESULT hr = S_OK;
220 DWORD er = ERROR_SUCCESS;
221
222 PMSIHANDLE hView, hRec;
223 LPWSTR pwzId = NULL;
224 LPWSTR pwzComponent = NULL;
225 LPWSTR pwzName = NULL;
226 LPWSTR pwzData = NULL;
227 INSTALLSTATE isInstalled, isAction;
228
229 LPWSTR pwzCustomActionData = NULL;
230
231 // check to see if necessary tables are specified
232 if (S_OK != WcaTableExists(L"PerformanceCategory"))
233 {
234 ExitFunction1(hr = S_FALSE);
235 }
236
237 hr = WcaOpenExecuteView(vcsPerfCounterDataQuery, &hView);
238 ExitOnFailure(hr, "failed to open view on PerformanceCategory table");
239 while (S_OK == (hr = WcaFetchRecord(hView, &hRec)))
240 {
241 hr = WcaGetRecordString(hRec, pcdqId, &pwzId);
242 ExitOnFailure(hr, "Failed to get id for PerformanceCategory.");
243
244 // Check to see if the Component is being installed or uninstalled
245 // when we are processing the same.
246 hr = WcaGetRecordString(hRec, pcdqComponent, &pwzComponent);
247 ExitOnFailure(hr, "Failed to get Component for PerformanceCategory: %ls", pwzId);
248
249 er = ::MsiGetComponentStateW(hInstall, pwzComponent, &isInstalled, &isAction);
250 hr = HRESULT_FROM_WIN32(er);
251 ExitOnFailure(hr, "Failed to get Component state for PerformanceCategory: %ls", pwzId);
252
253 if ((fInstall && !WcaIsInstalling(isInstalled, isAction)) ||
254 (!fInstall && !WcaIsUninstalling(isInstalled, isAction)))
255 {
256 continue;
257 }
258
259 hr = WcaGetRecordString(hRec, pcdqName, &pwzName);
260 ExitOnFailure(hr, "Failed to get Name for PerformanceCategory: %ls", pwzId);
261 hr = WcaWriteStringToCaData(pwzName, &pwzCustomActionData);
262 ExitOnFailure(hr, "Failed to add Name to CustomActionData for PerformanceCategory: %ls", pwzId);
263
264 hr = WcaGetRecordString(hRec, pcdqIniData, &pwzData);
265 ExitOnFailure(hr, "Failed to get IniData for PerformanceCategory: %ls", pwzId);
266 hr = WcaWriteStringToCaData(pwzData, &pwzCustomActionData);
267 ExitOnFailure(hr, "Failed to add IniData to CustomActionData for PerformanceCategory: %ls", pwzId);
268
269 hr = WcaGetRecordString(hRec, pcdqConstantData, &pwzData);
270 ExitOnFailure(hr, "Failed to get ConstantData for PerformanceCategory: %ls", pwzId);
271 hr = WcaWriteStringToCaData(pwzData, &pwzCustomActionData);
272 ExitOnFailure(hr, "Failed to add ConstantData to CustomActionData for PerformanceCategory: %ls", pwzId);
273 }
274
275 if (hr == E_NOMOREITEMS)
276 {
277 hr = S_OK;
278 }
279 ExitOnFailure(hr, "Failure while processing PerformanceCategory table.");
280
281 // If there was any data built up, schedule it for execution.
282 if (pwzCustomActionData)
283 {
284 if (fInstall)
285 {
286 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackRegisterPerfCounterData"), pwzCustomActionData, COST_PERFMON_UNREGISTER);
287 ExitOnFailure(hr, "Failed to schedule RollbackRegisterPerfCounterData action for PerformanceCategory: %ls", pwzId);
288
289 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RegisterPerfCounterData"), pwzCustomActionData, COST_PERFMON_REGISTER);
290 ExitOnFailure(hr, "Failed to schedule RegisterPerfCounterData action for PerformanceCategory: %ls", pwzId);
291 }
292 else
293 {
294 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"RollbackUnregisterPerfCounterData"), pwzCustomActionData, COST_PERFMON_REGISTER);
295 ExitOnFailure(hr, "Failed to schedule RollbackUnregisterPerfCounterData action for PerformanceCategory: %ls", pwzId);
296
297 hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"UnregisterPerfCounterData"), pwzCustomActionData, COST_PERFMON_UNREGISTER);
298 ExitOnFailure(hr, "Failed to schedule UnregisterPerfCounterData action for PerformanceCategory: %ls", pwzId);
299 }
300 }
301
302LExit:
303 ReleaseStr(pwzCustomActionData);
304 ReleaseStr(pwzData);
305 ReleaseStr(pwzName);
306 ReleaseStr(pwzComponent);
307 ReleaseStr(pwzId);
308
309 return hr;
310}