@joebigelow / wix / commits / d291d27f

Share code to map stream name to payload when extracting containers.

Sean Hall committed Apr 25, 2021 at 21:50 UTC d291d27f94d0702bcd4ffd6fb72125c8996b3aef
4 files changed +20 -52
src/engine/apply.cpp
+12 -9
@@ -1113,7 +1113,8 @@ static HRESULT ExtractContainer(
1113 HRESULT hr = S_OK;
1114 BURN_CONTAINER_CONTEXT context = { };
1115 HANDLE hContainerHandle = INVALID_HANDLE_VALUE;
1116 - LPWSTR sczExtractPayloadId = NULL;
1116 + LPWSTR sczStreamName = NULL;
1117 + BURN_PAYLOAD* pExtract = NULL;
1118 BURN_CACHE_PROGRESS_CONTEXT progress = { };
1119
1120 progress.pCacheContext = pContext;
@@ -1129,14 +1130,17 @@ static HRESULT ExtractContainer(
1130 hr = ContainerOpen(&context, pContainer, hContainerHandle, pContainer->sczUnverifiedPath);
1131 ExitOnFailure(hr, "Failed to open container: %ls.", pContainer->sczId);
1132
1132 - while (S_OK == (hr = ContainerNextStream(&context, &sczExtractPayloadId)))
1133 + while (S_OK == (hr = ContainerNextStream(&context, &sczStreamName)))
1134 {
1135 BOOL fExtracted = FALSE;
1136
1136 - for (DWORD iExtract = 0; iExtract < pContext->pPayloads->cPayloads; ++iExtract)
1137 + hr = PayloadFindEmbeddedBySourcePath(pContext->pPayloads, sczStreamName, &pExtract);
1138 + if (E_NOTFOUND != hr)
1139 {
1138 - BURN_PAYLOAD* pExtract = pContext->pPayloads->rgPayloads + iExtract;
1139 - if (pExtract->sczUnverifiedPath && pExtract->cRemainingInstances && CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczExtractPayloadId, -1, pExtract->sczSourcePath, -1))
1140 + ExitOnFailure(hr, "Failed to find embedded payload by source path: %ls container: %ls", sczStreamName, pContainer->sczId);
1141 +
1142 + // Skip payloads that weren't planned or have already been cached.
1143 + if (pExtract->sczUnverifiedPath && pExtract->cRemainingInstances)
1144 {
1145 progress.pPayload = pExtract;
1146
@@ -1161,17 +1165,16 @@ static HRESULT ExtractContainer(
1165 }
1166
1167 UserExperienceOnCachePayloadExtractComplete(pContext->pUX, pContainer->sczId, pExtract->sczKey, hr);
1164 - ExitOnFailure(hr, "Failed to extract payload: %ls from container: %ls", sczExtractPayloadId, pContainer->sczId);
1168 + ExitOnFailure(hr, "Failed to extract payload: %ls from container: %ls", sczStreamName, pContainer->sczId);
1169
1170 fExtracted = TRUE;
1167 - break;
1171 }
1172 }
1173
1174 if (!fExtracted)
1175 {
1176 hr = ContainerSkipStream(&context);
1174 - ExitOnFailure(hr, "Failed to skip the extraction of payload: %ls from container: %ls", sczExtractPayloadId, pContainer->sczId);
1177 + ExitOnFailure(hr, "Failed to skip the extraction of payload: %ls from container: %ls", sczStreamName, pContainer->sczId);
1178 }
1179 }
1180
@@ -1182,7 +1185,7 @@ static HRESULT ExtractContainer(
1185 ExitOnFailure(hr, "Failed to extract all payloads from container: %ls", pContainer->sczId);
1186
1187 LExit:
1185 - ReleaseStr(sczExtractPayloadId);
1188 + ReleaseStr(sczStreamName);
1189 ContainerClose(&context);
1190
1191 return hr;
src/engine/core.cpp
+1 -1
@@ -155,7 +155,7 @@ extern "C" HRESULT CoreInitialize(
155 hr = UserExperienceEnsureWorkingFolder(pEngineState->registration.sczId, &pEngineState->userExperience.sczTempDirectory);
156 ExitOnFailure(hr, "Failed to get unique temporary folder for bootstrapper application.");
157
158 - hr = PayloadExtractFromContainer(&pEngineState->userExperience.payloads, NULL, &containerContext, pEngineState->userExperience.sczTempDirectory);
158 + hr = PayloadExtractUXContainer(&pEngineState->userExperience.payloads, &containerContext, pEngineState->userExperience.sczTempDirectory);
159 ExitOnFailure(hr, "Failed to extract bootstrapper application payloads.");
160
161 hr = PathConcat(pEngineState->userExperience.sczTempDirectory, L"BootstrapperApplicationData.xml", &pEngineState->command.wzBootstrapperApplicationDataPath);
src/engine/payload.cpp
+6 -40
@@ -190,9 +190,8 @@ extern "C" void PayloadsUninitialize(
190 memset(pPayloads, 0, sizeof(BURN_PAYLOADS));
191 }
192
193 -extern "C" HRESULT PayloadExtractFromContainer(
193 +extern "C" HRESULT PayloadExtractUXContainer(
194 __in BURN_PAYLOADS* pPayloads,
195 - __in_opt BURN_CONTAINER* pContainer,
195 __in BURN_CONTAINER_CONTEXT* pContainerContext,
196 __in_z LPCWSTR wzTargetDir
197 )
@@ -215,7 +214,7 @@ extern "C" HRESULT PayloadExtractFromContainer(
214 ExitOnFailure(hr, "Failed to get next stream.");
215
216 // find payload by stream name
218 - hr = FindEmbeddedBySourcePath(pPayloads, pContainer, sczStreamName, &pPayload);
217 + hr = PayloadFindEmbeddedBySourcePath(pPayloads, sczStreamName, &pPayload);
218 ExitOnFailure(hr, "Failed to find embedded payload: %ls", sczStreamName);
219
220 // make file path
@@ -241,15 +240,11 @@ extern "C" HRESULT PayloadExtractFromContainer(
240 {
241 pPayload = &pPayloads->rgPayloads[i];
242
244 - // if the payload is part of the container
245 - if (!pContainer || pPayload->pContainer == pContainer)
243 + // if the payload has not been acquired
244 + if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state)
245 {
247 - // if the payload has not been acquired
248 - if (BURN_PAYLOAD_STATE_ACQUIRED > pPayload->state)
249 - {
250 - hr = E_INVALIDDATA;
251 - ExitOnRootFailure(hr, "Payload was not found in container: %ls", pPayload->sczKey);
252 - }
246 + hr = E_INVALIDDATA;
247 + ExitOnRootFailure(hr, "Payload was not found in container: %ls", pPayload->sczKey);
248 }
249 }
250
@@ -317,32 +312,3 @@ LExit:
312
313
314 // internal function definitions
320 -
321 -static HRESULT FindEmbeddedBySourcePath(
322 - __in BURN_PAYLOADS* pPayloads,
323 - __in_opt BURN_CONTAINER* pContainer,
324 - __in_z LPCWSTR wzStreamName,
325 - __out BURN_PAYLOAD** ppPayload
326 - )
327 -{
328 - HRESULT hr = S_OK;
329 -
330 - for (DWORD i = 0; i < pPayloads->cPayloads; ++i)
331 - {
332 - BURN_PAYLOAD* pPayload = &pPayloads->rgPayloads[i];
333 -
334 - if (BURN_PAYLOAD_PACKAGING_EMBEDDED == pPayload->packaging && (!pContainer || pPayload->pContainer == pContainer))
335 - {
336 - if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pPayload->sczSourcePath, -1, wzStreamName, -1))
337 - {
338 - *ppPayload = pPayload;
339 - ExitFunction1(hr = S_OK);
340 - }
341 - }
342 - }
343 -
344 - hr = E_NOTFOUND;
345 -
346 -LExit:
347 - return hr;
348 -}
src/engine/payload.h
+1 -2
@@ -85,9 +85,8 @@ void PayloadUninitialize(
85 void PayloadsUninitialize(
86 __in BURN_PAYLOADS* pPayloads
87 );
88 -HRESULT PayloadExtractFromContainer(
88 +HRESULT PayloadExtractUXContainer(
89 __in BURN_PAYLOADS* pPayloads,
90 - __in_opt BURN_CONTAINER* pContainer,
90 __in BURN_CONTAINER_CONTEXT* pContainerContext,
91 __in_z LPCWSTR wzTargetDir
92 );