@joebigelow / wix-1 / commits / 6d7a275e

Replace static cache internals with a struct.

Initialize them explicitly to make it clearer when that happens.

Sean Hall committed Aug 3, 2021 at 15:41 UTC 6d7a275edafb3ae0f3cff94d66503a82dafb71f7
32 files changed +526 -372
src/burn/engine/apply.cpp
+20 -14
@@ -26,6 +26,7 @@ enum BURN_CACHE_PROGRESS_TYPE
26
27 typedef struct _BURN_CACHE_CONTEXT
28 {
29 + BURN_CACHE* pCache;
30 BURN_USER_EXPERIENCE* pUX;
31 BURN_VARIABLES* pVariables;
32 BURN_PAYLOADS* pPayloads;
@@ -55,6 +56,7 @@ typedef struct _BURN_CACHE_PROGRESS_CONTEXT
56
57 typedef struct _BURN_EXECUTE_CONTEXT
58 {
59 + BURN_CACHE* pCache;
60 BURN_USER_EXPERIENCE* pUX;
61 BURN_APPLY_CONTEXT* pApplyContext;
62 BOOL fRollback;
@@ -269,6 +271,7 @@ static void ResetTransactionRegistrationState(
271 __in BOOL fCommit
272 );
273 static HRESULT CleanPackage(
274 + __in BURN_CACHE* pCache,
275 __in HANDLE hElevatedPipe,
276 __in BURN_PACKAGE* pPackage
277 );
@@ -401,7 +404,7 @@ extern "C" HRESULT ApplyRegister(
404 }
405 else // need to complete registration on the machine.
406 {
404 - hr = CacheCalculateBundleWorkingPath(pEngineState->registration.sczId, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath);
407 + hr = CacheCalculateBundleWorkingPath(pEngineState->plan.pCache, pEngineState->registration.sczExecutableName, &sczEngineWorkingPath);
408 ExitOnFailure(hr, "Failed to calculate working path for engine.");
409
410 // begin new session
@@ -412,7 +415,7 @@ extern "C" HRESULT ApplyRegister(
415 }
416 else
417 {
415 - hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->plan.dependencyRegistrationAction, pEngineState->plan.qwEstimatedSize, registrationType);
418 + hr = RegistrationSessionBegin(sczEngineWorkingPath, &pEngineState->registration, &pEngineState->cache, &pEngineState->variables, pEngineState->plan.dwRegistrationOperations, pEngineState->plan.dependencyRegistrationAction, pEngineState->plan.qwEstimatedSize, registrationType);
419 ExitOnFailure(hr, "Failed to begin registration session.");
420 }
421 }
@@ -501,7 +504,7 @@ extern "C" HRESULT ApplyUnregister(
504 }
505 else
506 {
504 - hr = RegistrationSessionEnd(&pEngineState->registration, &pEngineState->variables, &pEngineState->packages, resumeMode, restart, pEngineState->plan.dependencyRegistrationAction, registrationType);
507 + hr = RegistrationSessionEnd(&pEngineState->registration, &pEngineState->cache, &pEngineState->variables, &pEngineState->packages, resumeMode, restart, pEngineState->plan.dependencyRegistrationAction, registrationType);
508 ExitOnFailure(hr, "Failed to end session in per-user process.");
509 }
510
@@ -531,6 +534,7 @@ extern "C" HRESULT ApplyCache(
534 ExitOnRootFailure(hr, "BA aborted cache.");
535
536 cacheContext.hSourceEngineFile = hSourceEngineFile;
537 + cacheContext.pCache = pPlan->pCache;
538 cacheContext.pPayloads = pPlan->pPayloads;
539 cacheContext.pUX = pUX;
540 cacheContext.pVariables = pVariables;
@@ -568,7 +572,7 @@ extern "C" HRESULT ApplyCache(
572 {
573 if (!pPackage->fPerMachine || INVALID_HANDLE_VALUE == cacheContext.hPipe)
574 {
571 - hr = CachePreparePackage(pPackage);
575 + hr = CachePreparePackage(pPlan->pCache, pPackage);
576
577 cacheContext.hPipe = INVALID_HANDLE_VALUE;
578 }
@@ -616,7 +620,7 @@ LExit:
620 ElevationCacheCleanup(hPipe);
621 }
622
619 - CacheCleanup(FALSE, pPlan->wzBundleId);
623 + CacheCleanup(FALSE, pPlan->pCache);
624
625 for (DWORD i = 0; i < cacheContext.cSearchPathsMax; ++i)
626 {
@@ -653,6 +657,7 @@ extern "C" HRESULT ApplyExecute(
657 BURN_ROLLBACK_BOUNDARY* pRollbackBoundary = NULL;
658 BOOL fSeekNextRollbackBoundary = FALSE;
659
660 + context.pCache = pEngineState->plan.pCache;
661 context.pUX = &pEngineState->userExperience;
662 context.pApplyContext = pApplyContext;
663 context.cExecutePackagesTotal = pEngineState->plan.cExecutePackagesTotal;
@@ -762,7 +767,7 @@ extern "C" void ApplyClean(
767 BURN_CLEAN_ACTION* pCleanAction = pPlan->rgCleanActions + i;
768 BURN_PACKAGE* pPackage = pCleanAction->pPackage;
769
765 - hr = CleanPackage(hPipe, pPackage);
770 + hr = CleanPackage(pPlan->pCache, hPipe, pPackage);
771 }
772 }
773
@@ -1479,7 +1484,7 @@ static HRESULT AcquireContainerOrPayload(
1484 dwChosenSearchPath = 0;
1485 dwDestinationSearchPath = 0;
1486
1482 - hr = CacheGetLocalSourcePaths(wzRelativePath, *pwzSourcePath, wzDestinationPath, pContext->wzLayoutDirectory, pContext->pVariables, &pContext->rgSearchPaths, &pContext->cSearchPaths, &dwChosenSearchPath, &dwDestinationSearchPath);
1487 + hr = CacheGetLocalSourcePaths(wzRelativePath, *pwzSourcePath, wzDestinationPath, pContext->wzLayoutDirectory, pContext->pCache, pContext->pVariables, &pContext->rgSearchPaths, &pContext->cSearchPaths, &dwChosenSearchPath, &dwDestinationSearchPath);
1488 ExitOnFailure(hr, "Failed to search local source.");
1489
1490 if (wzPayloadContainerId)
@@ -1710,7 +1715,7 @@ static HRESULT LayoutOrCacheContainerOrPayload(
1715 }
1716 else // complete the payload.
1717 {
1713 - hr = CacheCompletePayload(pPackage->fPerMachine, pPayload, pPackage->sczCacheId, wzUnverifiedPath, fMove, CacheMessageHandler, CacheProgressRoutine, &progress);
1718 + hr = CacheCompletePayload(pContext->pCache, pPackage->fPerMachine, pPayload, pPackage->sczCacheId, wzUnverifiedPath, fMove, CacheMessageHandler, CacheProgressRoutine, &progress);
1719 }
1720 }
1721
@@ -2174,7 +2179,7 @@ static void DoRollbackCache(
2179 {
2180 if (dwLastCheckpoint <= dwCheckpoint) // only rollback when it was attempted to be cached.
2181 {
2177 - hr = CleanPackage(hPipe, pPackage);
2182 + hr = CleanPackage(pPlan->pCache, hPipe, pPackage);
2183 }
2184 }
2185 else if (pPackage->fCanAffectRegistration)
@@ -2401,7 +2406,7 @@ static HRESULT DoRollbackActions(
2406 case BURN_EXECUTE_ACTION_TYPE_UNCACHE_PACKAGE:
2407 if (!pRollbackAction->uncachePackage.pPackage->fCached) // only rollback when it wasn't already cached.
2408 {
2404 - hr = CleanPackage(pEngineState->companionConnection.hPipe, pRollbackAction->uncachePackage.pPackage);
2409 + hr = CleanPackage(pEngineState->plan.pCache, pEngineState->companionConnection.hPipe, pRollbackAction->uncachePackage.pPackage);
2410 IgnoreRollbackError(hr, "Failed to uncache package for rollback.");
2411 }
2412 else if (pRollbackAction->uncachePackage.pPackage->fCanAffectRegistration)
@@ -2477,7 +2482,7 @@ static HRESULT ExecuteExePackage(
2482 }
2483 else
2484 {
2480 - hrExecute = ExeEngineExecutePackage(pExecuteAction, &pEngineState->variables, fRollback, GenericExecuteMessageHandler, pContext, pRestart);
2485 + hrExecute = ExeEngineExecutePackage(pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, GenericExecuteMessageHandler, pContext, pRestart);
2486 ExitOnFailure(hrExecute, "Failed to configure per-user EXE package.");
2487 }
2488
@@ -2548,7 +2553,7 @@ static HRESULT ExecuteMsiPackage(
2553 }
2554 else
2555 {
2551 - hrExecute = MsiEngineExecutePackage(pEngineState->userExperience.hwndApply, pExecuteAction, &pEngineState->variables, fRollback, MsiExecuteMessageHandler, pContext, pRestart);
2556 + hrExecute = MsiEngineExecutePackage(pEngineState->userExperience.hwndApply, pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, MsiExecuteMessageHandler, pContext, pRestart);
2557 ExitOnFailure(hrExecute, "Failed to configure per-user MSI package.");
2558 }
2559
@@ -2621,7 +2626,7 @@ static HRESULT ExecuteMspPackage(
2626 }
2627 else
2628 {
2624 - hrExecute = MspEngineExecutePackage(pEngineState->userExperience.hwndApply, pExecuteAction, &pEngineState->variables, fRollback, MsiExecuteMessageHandler, pContext, pRestart);
2629 + hrExecute = MspEngineExecutePackage(pEngineState->userExperience.hwndApply, pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, MsiExecuteMessageHandler, pContext, pRestart);
2630 ExitOnFailure(hrExecute, "Failed to configure per-user MSP package.");
2631 }
2632
@@ -2983,6 +2988,7 @@ static void ResetTransactionRegistrationState(
2988 }
2989
2990 static HRESULT CleanPackage(
2991 + __in BURN_CACHE* pCache,
2992 __in HANDLE hElevatedPipe,
2993 __in BURN_PACKAGE* pPackage
2994 )
@@ -2995,7 +3001,7 @@ static HRESULT CleanPackage(
3001 }
3002 else
3003 {
2998 - hr = CacheRemovePackage(FALSE, pPackage->sczId, pPackage->sczCacheId);
3004 + hr = CacheRemovePackage(pCache, FALSE, pPackage->sczId, pPackage->sczCacheId);
3005 }
3006
3007 if (pPackage->fCanAffectRegistration)
src/burn/engine/approvedexe.cpp
+2 -1
@@ -211,6 +211,7 @@ LExit:
211 }
212
213 extern "C" HRESULT ApprovedExesVerifySecureLocation(
214 + __in BURN_CACHE* pCache,
215 __in BURN_VARIABLES* pVariables,
216 __in BURN_LAUNCH_APPROVED_EXE* pLaunchApprovedExe
217 )
@@ -245,7 +246,7 @@ extern "C" HRESULT ApprovedExesVerifySecureLocation(
246
247 // The problem with using a Variable for the root package cache folder is that it might not have been secured yet.
248 // Getting it through CacheGetPerMachineRootCompletedPath makes sure it has been secured.
248 - hr = CacheGetPerMachineRootCompletedPath(&scz, &sczSecondary);
249 + hr = CacheGetPerMachineRootCompletedPath(pCache, &scz, &sczSecondary);
250 ExitOnFailure(hr, "Failed to get the root package cache folder.");
251
252 // If the package cache is redirected, hr is S_FALSE.
src/burn/engine/approvedexe.h
+6
@@ -6,6 +6,11 @@
6 extern "C" {
7 #endif
8
9 +// forward declare
10 +
11 +typedef struct _BOOTSTRAPPER_ENGINE_CONTEXT BOOTSTRAPPER_ENGINE_CONTEXT;
12 +typedef struct _BURN_CACHE BURN_CACHE;
13 +typedef struct _BURN_ENGINE_COMMAND BURN_ENGINE_COMMAND;
14
15 // structs
16
@@ -57,6 +62,7 @@ HRESULT ApprovedExesLaunch(
62 __out DWORD* pdwProcessId
63 );
64 HRESULT ApprovedExesVerifySecureLocation(
65 + __in BURN_CACHE* pCache,
66 __in BURN_VARIABLES* pVariables,
67 __in BURN_LAUNCH_APPROVED_EXE* pLaunchApprovedExe
68 );
src/burn/engine/cache.cpp
+259 -246
@@ -9,40 +9,37 @@ static const LPCWSTR PACKAGE_CACHE_FOLDER_NAME = L"Package Cache";
9 static const DWORD FILE_OPERATION_RETRY_COUNT = 3;
10 static const DWORD FILE_OPERATION_RETRY_WAIT = 2000;
11
12 -static BOOL vfInitializedCache = FALSE;
13 -static BOOL vfRunningFromCache = FALSE;
14 -static LPWSTR vsczSourceProcessFolder = NULL;
15 -static LPWSTR vsczWorkingFolder = NULL;
16 -static LPWSTR vsczDefaultUserPackageCache = NULL;
17 -static LPWSTR vsczDefaultMachinePackageCache = NULL;
18 -static LPWSTR vsczCurrentMachinePackageCache = NULL;
19 -
12 static HRESULT CacheVerifyPayloadSignature(
13 __in BURN_PAYLOAD* pPayload,
14 __in_z LPCWSTR wzUnverifiedPayloadPath,
15 __in HANDLE hFile
16 );
17 static HRESULT CalculateWorkingFolder(
26 - __in_z LPCWSTR wzBundleId,
27 - __deref_out_z LPWSTR* psczWorkingFolder
18 + __in BURN_CACHE* pCache,
19 + __in BURN_ENGINE_COMMAND* pInternalCommand
20 );
21 static HRESULT GetLastUsedSourceFolder(
22 __in BURN_VARIABLES* pVariables,
23 __out_z LPWSTR* psczLastSource
24 );
33 -static HRESULT SecurePerMachineCacheRoot();
25 +static HRESULT SecurePerMachineCacheRoot(
26 + __in BURN_CACHE* pCache
27 + );
28 static HRESULT CreateCompletedPath(
29 + __in BURN_CACHE* pCache,
30 __in BOOL fPerMachine,
31 __in LPCWSTR wzCacheId,
32 __in LPCWSTR wzFilePath,
33 __out_z LPWSTR* psczCachePath
34 );
35 static HRESULT CreateUnverifiedPath(
36 + __in BURN_CACHE* pCache,
37 __in BOOL fPerMachine,
38 __in_z LPCWSTR wzPayloadId,
39 __out_z LPWSTR* psczUnverifiedPayloadPath
40 );
41 static HRESULT GetRootPath(
42 + __in BURN_CACHE* pCache,
43 __in BOOL fPerMachine,
44 __in BOOL fAllowRedirect,
45 __deref_out_z LPWSTR* psczRootPath
@@ -101,6 +98,7 @@ static HRESULT SecurePath(
98 __in LPCWSTR wzPath
99 );
100 static HRESULT CopyEngineToWorkingFolder(
101 + __in BURN_CACHE* pCache,
102 __in_z LPCWSTR wzSourcePath,
103 __in_z LPCWSTR wzWorkingFolderName,
104 __in_z LPCWSTR wzExecutableName,
@@ -114,6 +112,7 @@ static HRESULT CopyEngineWithSignatureFixup(
112 __in BURN_SECTION* pSection
113 );
114 static HRESULT RemoveBundleOrPackage(
115 + __in BURN_CACHE* pCache,
116 __in BOOL fBundle,
117 __in BOOL fPerMachine,
118 __in_z LPCWSTR wzBundleOrPackageId,
@@ -158,11 +157,79 @@ static HRESULT SendCacheCompleteMessage(
157
158
159 extern "C" HRESULT CacheInitialize(
160 + __in BURN_CACHE* pCache,
161 + __in BURN_ENGINE_COMMAND* pInternalCommand
162 + )
163 +{
164 + Assert(!pCache->fInitializedCache);
165 +
166 + HRESULT hr = S_OK;
167 + LPWSTR sczAppData = NULL;
168 + int nCompare = 0;
169 +
170 + // Cache paths are initialized once so they cannot be changed while the engine is caching payloads.
171 + // Always construct the default machine package cache path so we can determine if we're redirected.
172 + hr = PathGetKnownFolder(CSIDL_COMMON_APPDATA, &sczAppData);
173 + ExitOnFailure(hr, "Failed to find local %hs appdata directory.", "per-machine");
174 +
175 + hr = PathConcat(sczAppData, PACKAGE_CACHE_FOLDER_NAME, &pCache->sczDefaultMachinePackageCache);
176 + ExitOnFailure(hr, "Failed to construct %hs package cache directory name.", "per-machine");
177 +
178 + hr = PathBackslashTerminate(&pCache->sczDefaultMachinePackageCache);
179 + ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-machine");
180 +
181 +
182 + // The machine package cache can be redirected through policy.
183 + hr = PolcReadString(POLICY_BURN_REGISTRY_PATH, L"PackageCache", NULL, &pCache->sczCurrentMachinePackageCache);
184 + ExitOnFailure(hr, "Failed to read PackageCache policy directory.");
185 +
186 + if (pCache->sczCurrentMachinePackageCache)
187 + {
188 + hr = PathBackslashTerminate(&pCache->sczCurrentMachinePackageCache);
189 + ExitOnFailure(hr, "Failed to backslash terminate redirected per-machine package cache directory name.");
190 + }
191 + else
192 + {
193 + hr = StrAllocString(&pCache->sczCurrentMachinePackageCache, pCache->sczDefaultMachinePackageCache, 0);
194 + ExitOnFailure(hr, "Failed to copy default package cache directory to current package cache directory.");
195 + }
196 +
197 + hr = PathCompare(pCache->sczDefaultMachinePackageCache, pCache->sczCurrentMachinePackageCache, &nCompare);
198 + ExitOnFailure(hr, "Failed to compare default and current package cache directories.");
199 +
200 + pCache->fCustomMachinePackageCache = CSTR_EQUAL != nCompare;
201 +
202 +
203 + hr = PathGetKnownFolder(CSIDL_LOCAL_APPDATA, &sczAppData);
204 + ExitOnFailure(hr, "Failed to find local %hs appdata directory.", "per-user");
205 +
206 + hr = PathConcat(sczAppData, PACKAGE_CACHE_FOLDER_NAME, &pCache->sczDefaultUserPackageCache);
207 + ExitOnFailure(hr, "Failed to construct %hs package cache directory name.", "per-user");
208 +
209 + hr = PathBackslashTerminate(&pCache->sczDefaultUserPackageCache);
210 + ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-user");
211 +
212 +
213 + hr = CalculateWorkingFolder(pCache, pInternalCommand);
214 +
215 + pCache->fInitializedCache = TRUE;
216 +
217 +LExit:
218 + ReleaseStr(sczAppData);
219 +
220 + return hr;
221 +}
222 +
223 +
224 +extern "C" HRESULT CacheInitializeSources(
225 + __in BURN_CACHE* pCache,
226 __in BURN_REGISTRATION* pRegistration,
227 __in BURN_VARIABLES* pVariables,
163 - __in_z_opt LPCWSTR wzSourceProcessPath
228 + __in BURN_ENGINE_COMMAND* pInternalCommand
229 )
230 {
231 + Assert(!pCache->fInitializedCacheSources);
232 +
233 HRESULT hr = S_OK;
234 LPWSTR sczCurrentPath = NULL;
235 LPWSTR sczCompletedFolder = NULL;
@@ -170,66 +237,64 @@ extern "C" HRESULT CacheInitialize(
237 LPWSTR sczOriginalSource = NULL;
238 LPWSTR sczOriginalSourceFolder = NULL;
239 int nCompare = 0;
240 + LPCWSTR wzSourceProcessPath = pInternalCommand->sczSourceProcessPath;
241
174 - if (!vfInitializedCache)
175 - {
176 - hr = PathForCurrentProcess(&sczCurrentPath, NULL);
177 - ExitOnFailure(hr, "Failed to get current process path.");
242 + hr = PathForCurrentProcess(&sczCurrentPath, NULL);
243 + ExitOnFailure(hr, "Failed to get current process path.");
244
179 - // Determine if we are running from the package cache or not.
180 - hr = CacheGetCompletedPath(pRegistration->fPerMachine, pRegistration->sczId, &sczCompletedFolder);
181 - ExitOnFailure(hr, "Failed to get completed path for bundle.");
245 + // Determine if we are running from the package cache or not.
246 + hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczId, &sczCompletedFolder);
247 + ExitOnFailure(hr, "Failed to get completed path for bundle.");
248
183 - hr = PathConcat(sczCompletedFolder, pRegistration->sczExecutableName, &sczCompletedPath);
184 - ExitOnFailure(hr, "Failed to combine working path with engine file name.");
249 + hr = PathConcat(sczCompletedFolder, pRegistration->sczExecutableName, &sczCompletedPath);
250 + ExitOnFailure(hr, "Failed to combine working path with engine file name.");
251
186 - hr = PathCompare(sczCurrentPath, sczCompletedPath, &nCompare);
187 - ExitOnFailure(hr, "Failed to compare current path for bundle: %ls", sczCurrentPath);
252 + hr = PathCompare(sczCurrentPath, sczCompletedPath, &nCompare);
253 + ExitOnFailure(hr, "Failed to compare current path for bundle: %ls", sczCurrentPath);
254
189 - vfRunningFromCache = (CSTR_EQUAL == nCompare);
255 + pCache->fRunningFromCache = (CSTR_EQUAL == nCompare);
256
191 - // If a source process path was not provided (e.g. we are not being
192 - // run in a clean room) then use the current process path as the
193 - // source process path.
194 - if (!wzSourceProcessPath)
195 - {
196 - wzSourceProcessPath = sczCurrentPath;
197 - }
257 + // If a source process path was not provided (e.g. we are not being
258 + // run in a clean room) then use the current process path as the
259 + // source process path.
260 + if (!wzSourceProcessPath)
261 + {
262 + wzSourceProcessPath = sczCurrentPath;
263 + }
264
199 - hr = PathGetDirectory(wzSourceProcessPath, &vsczSourceProcessFolder);
200 - ExitOnFailure(hr, "Failed to initialize cache source folder.");
265 + hr = PathGetDirectory(wzSourceProcessPath, &pCache->sczSourceProcessFolder);
266 + ExitOnFailure(hr, "Failed to initialize cache source folder.");
267
202 - // If we're not running from the cache, ensure the original source is set.
203 - if (!vfRunningFromCache)
268 + // If we're not running from the cache, ensure the original source is set.
269 + if (!pCache->fRunningFromCache)
270 + {
271 + // If the original source has not been set already then set it where the bundle is
272 + // running from right now. This value will be persisted and we'll use it when launched
273 + // from the clean room or package cache since none of our packages will be relative to
274 + // those locations.
275 + hr = VariableGetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE, &sczOriginalSource);
276 + if (E_NOTFOUND == hr)
277 {
205 - // If the original source has not been set already then set it where the bundle is
206 - // running from right now. This value will be persisted and we'll use it when launched
207 - // from the clean room or package cache since none of our packages will be relative to
208 - // those locations.
209 - hr = VariableGetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE, &sczOriginalSource);
210 - if (E_NOTFOUND == hr)
211 - {
212 - hr = VariableSetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE, wzSourceProcessPath, FALSE, FALSE);
213 - ExitOnFailure(hr, "Failed to set original source variable.");
278 + hr = VariableSetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE, wzSourceProcessPath, FALSE, FALSE);
279 + ExitOnFailure(hr, "Failed to set original source variable.");
280
215 - hr = StrAllocString(&sczOriginalSource, wzSourceProcessPath, 0);
216 - ExitOnFailure(hr, "Failed to copy current path to original source.");
217 - }
281 + hr = StrAllocString(&sczOriginalSource, wzSourceProcessPath, 0);
282 + ExitOnFailure(hr, "Failed to copy current path to original source.");
283 + }
284
219 - hr = VariableGetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE_FOLDER, &sczOriginalSourceFolder);
220 - if (E_NOTFOUND == hr)
221 - {
222 - hr = PathGetDirectory(sczOriginalSource, &sczOriginalSourceFolder);
223 - ExitOnFailure(hr, "Failed to get directory from original source path.");
285 + hr = VariableGetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE_FOLDER, &sczOriginalSourceFolder);
286 + if (E_NOTFOUND == hr)
287 + {
288 + hr = PathGetDirectory(sczOriginalSource, &sczOriginalSourceFolder);
289 + ExitOnFailure(hr, "Failed to get directory from original source path.");
290
225 - hr = VariableSetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE_FOLDER, sczOriginalSourceFolder, FALSE, FALSE);
226 - ExitOnFailure(hr, "Failed to set original source directory variable.");
227 - }
291 + hr = VariableSetString(pVariables, BURN_BUNDLE_ORIGINAL_SOURCE_FOLDER, sczOriginalSourceFolder, FALSE, FALSE);
292 + ExitOnFailure(hr, "Failed to set original source directory variable.");
293 }
229 -
230 - vfInitializedCache = TRUE;
294 }
295
296 + pCache->fInitializedCacheSources = TRUE;
297 +
298 LExit:
299 ReleaseStr(sczCurrentPath);
300 ReleaseStr(sczCompletedFolder);
@@ -241,99 +306,85 @@ LExit:
306 }
307
308 extern "C" HRESULT CacheEnsureWorkingFolder(
244 - __in_z_opt LPCWSTR wzBundleId,
309 + __in BURN_CACHE* pCache,
310 __deref_out_z_opt LPWSTR* psczWorkingFolder
311 )
312 {
248 - HRESULT hr = S_OK;
249 - LPWSTR sczWorkingFolder = NULL;
313 + Assert(pCache->fInitializedCache);
314
251 - hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
252 - ExitOnFailure(hr, "Failed to calculate working folder to ensure it exists.");
315 + HRESULT hr = S_OK;
316
254 - hr = DirEnsureExists(sczWorkingFolder, NULL);
317 + hr = DirEnsureExists(pCache->sczWorkingFolder, NULL);
318 ExitOnFailure(hr, "Failed create working folder.");
319
320 // Best effort to ensure our working folder is not encrypted.
258 - ::DecryptFileW(sczWorkingFolder, 0);
321 + ::DecryptFileW(pCache->sczWorkingFolder, 0);
322
323 if (psczWorkingFolder)
324 {
262 - hr = StrAllocString(psczWorkingFolder, sczWorkingFolder, 0);
325 + hr = StrAllocString(psczWorkingFolder, pCache->sczWorkingFolder, 0);
326 ExitOnFailure(hr, "Failed to copy working folder.");
327 }
328
329 LExit:
267 - ReleaseStr(sczWorkingFolder);
268 -
330 return hr;
331 }
332
333 extern "C" HRESULT CacheCalculateBundleWorkingPath(
273 - __in_z LPCWSTR wzBundleId,
334 + __in BURN_CACHE* pCache,
335 __in LPCWSTR wzExecutableName,
336 __deref_out_z LPWSTR* psczWorkingPath
337 )
338 {
278 - Assert(vfInitializedCache);
339 + Assert(pCache->fInitializedCache);
340
341 HRESULT hr = S_OK;
281 - LPWSTR sczWorkingFolder = NULL;
342
343 // If the bundle is running out of the package cache then we use that as the
344 // working folder since we feel safe in the package cache.
285 - if (vfRunningFromCache)
345 + if (CacheBundleRunningFromCache(pCache))
346 {
347 hr = PathForCurrentProcess(psczWorkingPath, NULL);
348 ExitOnFailure(hr, "Failed to get current process path.");
349 }
350 else // Otherwise, use the real working folder.
351 {
292 - hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
293 - ExitOnFailure(hr, "Failed to get working folder for bundle.");
294 -
295 - hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", sczWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName);
352 + hr = StrAllocFormatted(psczWorkingPath, L"%ls%ls\\%ls", pCache->sczWorkingFolder, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName);
353 ExitOnFailure(hr, "Failed to calculate the bundle working path.");
354 }
355
356 LExit:
300 - ReleaseStr(sczWorkingFolder);
301 -
357 return hr;
358 }
359
360 extern "C" HRESULT CacheCalculateBundleLayoutWorkingPath(
361 + __in BURN_CACHE* pCache,
362 __in_z LPCWSTR wzBundleId,
363 __deref_out_z LPWSTR* psczWorkingPath
364 )
365 {
310 - HRESULT hr = S_OK;
311 - LPWSTR sczWorkingFolder = NULL;
366 + Assert(pCache->fInitializedCache);
367
313 - hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
314 - ExitOnFailure(hr, "Failed to get working folder for bundle layout.");
368 + HRESULT hr = S_OK;
369
316 - hr = StrAllocConcat(psczWorkingPath, wzBundleId, 0);
370 + hr = PathConcat(pCache->sczWorkingFolder, wzBundleId, psczWorkingPath);
371 ExitOnFailure(hr, "Failed to append bundle id for bundle layout working path.");
372
373 LExit:
320 - ReleaseStr(sczWorkingFolder);
321 -
374 return hr;
375 }
376
377 extern "C" HRESULT CacheCalculatePayloadWorkingPath(
326 - __in_z LPCWSTR wzBundleId,
378 + __in BURN_CACHE* pCache,
379 __in BURN_PAYLOAD* pPayload,
380 __deref_out_z LPWSTR* psczWorkingPath
381 )
382 {
331 - HRESULT hr = S_OK;
383 + Assert(pCache->fInitializedCache);
384
333 - hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
334 - ExitOnFailure(hr, "Failed to get working folder for payload.");
385 + HRESULT hr = S_OK;
386
336 - hr = StrAllocConcat(psczWorkingPath, pPayload->sczKey, 0);
387 + hr = PathConcat(pCache->sczWorkingFolder, pPayload->sczKey, psczWorkingPath);
388 ExitOnFailure(hr, "Failed to append Id as payload unverified path.");
389
390 LExit:
@@ -341,17 +392,16 @@ LExit:
392 }
393
394 extern "C" HRESULT CacheCalculateContainerWorkingPath(
344 - __in_z LPCWSTR wzBundleId,
395 + __in BURN_CACHE* pCache,
396 __in BURN_CONTAINER* pContainer,
397 __deref_out_z LPWSTR* psczWorkingPath
398 )
399 {
349 - HRESULT hr = S_OK;
400 + Assert(pCache->fInitializedCache);
401
351 - hr = CalculateWorkingFolder(wzBundleId, psczWorkingPath);
352 - ExitOnFailure(hr, "Failed to get working folder for container.");
402 + HRESULT hr = S_OK;
403
354 - hr = StrAllocConcat(psczWorkingPath, pContainer->sczHash, 0);
404 + hr = PathConcat(pCache->sczWorkingFolder, pContainer->sczHash, psczWorkingPath);
405 ExitOnFailure(hr, "Failed to append hash as container unverified path.");
406
407 LExit:
@@ -359,6 +409,7 @@ LExit:
409 }
410
411 extern "C" HRESULT CacheGetPerMachineRootCompletedPath(
412 + __in BURN_CACHE* pCache,
413 __out_z LPWSTR* psczCurrentRootCompletedPath,
414 __out_z LPWSTR* psczDefaultRootCompletedPath
415 )
@@ -368,15 +419,15 @@ extern "C" HRESULT CacheGetPerMachineRootCompletedPath(
419 *psczCurrentRootCompletedPath = NULL;
420 *psczDefaultRootCompletedPath = NULL;
421
371 - hr = SecurePerMachineCacheRoot();
422 + hr = SecurePerMachineCacheRoot(pCache);
423 ExitOnFailure(hr, "Failed to secure per-machine cache root.");
424
374 - hr = GetRootPath(TRUE, TRUE, psczCurrentRootCompletedPath);
425 + hr = GetRootPath(pCache, TRUE, TRUE, psczCurrentRootCompletedPath);
426 ExitOnFailure(hr, "Failed to get per-machine cache root.");
427
428 if (S_FALSE == hr)
429 {
379 - hr = GetRootPath(TRUE, FALSE, psczDefaultRootCompletedPath);
430 + hr = GetRootPath(pCache, TRUE, FALSE, psczDefaultRootCompletedPath);
431 ExitOnFailure(hr, "Failed to get default per-machine cache root.");
432
433 hr = S_FALSE;
@@ -387,6 +438,7 @@ LExit:
438 }
439
440 extern "C" HRESULT CacheGetCompletedPath(
441 + __in BURN_CACHE* pCache,
442 __in BOOL fPerMachine,
443 __in_z LPCWSTR wzCacheId,
444 __deref_out_z LPWSTR* psczCompletedPath
@@ -398,7 +450,7 @@ extern "C" HRESULT CacheGetCompletedPath(
450 LPWSTR sczCurrentCompletedPath = NULL;
451 LPWSTR sczDefaultCompletedPath = NULL;
452
401 - hr = GetRootPath(fPerMachine, TRUE, &sczRootPath);
453 + hr = GetRootPath(pCache, fPerMachine, TRUE, &sczRootPath);
454 ExitOnFailure(hr, "Failed to get %hs package cache root directory.", fPerMachine ? "per-machine" : "per-user");
455
456 // GetRootPath returns S_FALSE if the package cache is redirected elsewhere.
@@ -414,7 +466,7 @@ extern "C" HRESULT CacheGetCompletedPath(
466 // If neither package cache directory exists return the (possibly) redirected package cache directory.
467 if (fRedirected && !DirExists(sczCurrentCompletedPath, NULL))
468 {
417 - hr = GetRootPath(fPerMachine, FALSE, &sczRootPath);
469 + hr = GetRootPath(pCache, fPerMachine, FALSE, &sczRootPath);
470 ExitOnFailure(hr, "Failed to get old %hs package cache root directory.", fPerMachine ? "per-machine" : "per-user");
471
472 hr = PathConcat(sczRootPath, wzCacheId, &sczDefaultCompletedPath);
@@ -462,6 +514,7 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
514 __in_z LPCWSTR wzSourcePath,
515 __in_z LPCWSTR wzDestinationPath,
516 __in_z_opt LPCWSTR wzLayoutDirectory,
517 + __in BURN_CACHE* pCache,
518 __in BURN_VARIABLES* pVariables,
519 __inout LPWSTR** prgSearchPaths,
520 __out DWORD* pcSearchPaths,
@@ -469,6 +522,8 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
522 __out DWORD* pdwDestinationSearchPath
523 )
524 {
525 + AssertSz(pCache->fInitializedCacheSources, "Cache sources weren't initialized");
526 +
527 HRESULT hr = S_OK;
528 LPWSTR sczCurrentPath = NULL;
529 LPWSTR sczLastSourceFolder = NULL;
@@ -481,11 +536,9 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
536 DWORD dwLikelySearchPath = 0;
537 DWORD dwDestinationSearchPath = 0;
538
484 - AssertSz(vfInitializedCache, "Cache wasn't initialized");
485 -
539 hr = GetLastUsedSourceFolder(pVariables, &sczLastSourceFolder);
487 - fPreferSourcePathLocation = !vfRunningFromCache || FAILED(hr);
488 - fTryLastFolder = SUCCEEDED(hr) && sczLastSourceFolder && *sczLastSourceFolder && CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, vsczSourceProcessFolder, -1, sczLastSourceFolder, -1);
540 + fPreferSourcePathLocation = !pCache->fRunningFromCache || FAILED(hr);
541 + fTryLastFolder = SUCCEEDED(hr) && sczLastSourceFolder && *sczLastSourceFolder && CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, pCache->sczSourceProcessFolder, -1, sczLastSourceFolder, -1);
542 fTryRelativePath = CSTR_EQUAL != ::CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, wzSourcePath, -1, wzRelativePath, -1);
543 fSourceIsAbsolute = PathIsAbsolute(wzSourcePath);
544
@@ -528,7 +581,7 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
581 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgSearchPaths), cSearchPaths + 1, sizeof(LPWSTR), BURN_CACHE_MAX_SEARCH_PATHS);
582 ExitOnFailure(hr, "Failed to ensure size for search paths array.");
583
531 - hr = PathConcat(vsczSourceProcessFolder, wzSourcePath, &sczCurrentPath);
584 + hr = PathConcat(pCache->sczSourceProcessFolder, wzSourcePath, &sczCurrentPath);
585 ExitOnFailure(hr, "Failed to combine source process folder with source.");
586
587 // If we're not running from cache or we couldn't get the last source,
@@ -580,7 +633,7 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
633 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgSearchPaths), cSearchPaths + 1, sizeof(LPWSTR), BURN_CACHE_MAX_SEARCH_PATHS);
634 ExitOnFailure(hr, "Failed to ensure size for search paths array.");
635
583 - hr = PathConcat(vsczSourceProcessFolder, wzRelativePath, &sczCurrentPath);
636 + hr = PathConcat(pCache->sczSourceProcessFolder, wzRelativePath, &sczCurrentPath);
637 ExitOnFailure(hr, "Failed to combine source process folder with relative.");
638
639 if (fPreferSourcePathLocation)
@@ -761,12 +814,17 @@ extern "C" void CacheSendErrorCallback(
814 }
815 }
816
764 -extern "C" BOOL CacheBundleRunningFromCache()
817 +extern "C" BOOL CacheBundleRunningFromCache(
818 + __in BURN_CACHE* pCache
819 + )
820 {
766 - return vfRunningFromCache;
821 + AssertSz(pCache->fInitializedCacheSources, "Cache sources weren't initialized");
822 +
823 + return pCache->fRunningFromCache;
824 }
825
769 -HRESULT CachePreparePackage(
826 +extern "C" HRESULT CachePreparePackage(
827 + __in BURN_CACHE* pCache,
828 __in BURN_PACKAGE* pPackage
829 )
830 {
@@ -774,13 +832,14 @@ HRESULT CachePreparePackage(
832
833 if (!pPackage->sczCacheFolder)
834 {
777 - hr = CreateCompletedPath(pPackage->fPerMachine, pPackage->sczCacheId, NULL, &pPackage->sczCacheFolder);
835 + hr = CreateCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, NULL, &pPackage->sczCacheFolder);
836 }
837
838 return hr;
839 }
840
841 extern "C" HRESULT CacheBundleToCleanRoom(
842 + __in BURN_CACHE* pCache,
843 __in BURN_SECTION* pSection,
844 __deref_out_z_opt LPWSTR* psczCleanRoomBundlePath
845 )
@@ -794,7 +853,7 @@ extern "C" HRESULT CacheBundleToCleanRoom(
853
854 wzExecutableName = PathFile(sczSourcePath);
855
797 - hr = CopyEngineToWorkingFolder(sczSourcePath, BUNDLE_CLEAN_ROOM_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczCleanRoomBundlePath);
856 + hr = CopyEngineToWorkingFolder(pCache, sczSourcePath, BUNDLE_CLEAN_ROOM_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczCleanRoomBundlePath);
857 ExitOnFailure(hr, "Failed to cache bundle to clean room.");
858
859 LExit:
@@ -804,13 +863,13 @@ LExit:
863 }
864
865 extern "C" HRESULT CacheBundleToWorkingDirectory(
807 - __in_z LPCWSTR /*wzBundleId*/,
866 + __in BURN_CACHE* pCache,
867 __in_z LPCWSTR wzExecutableName,
868 __in BURN_SECTION* pSection,
869 __deref_out_z_opt LPWSTR* psczEngineWorkingPath
870 )
871 {
813 - Assert(vfInitializedCache);
872 + Assert(pCache->fInitializedCache);
873
874 HRESULT hr = S_OK;
875 LPWSTR sczSourcePath = NULL;
@@ -821,14 +880,14 @@ extern "C" HRESULT CacheBundleToWorkingDirectory(
880
881 // If the bundle is running out of the package cache then we don't need to copy it to
882 // the working folder since we feel safe in the package cache and will run from there.
824 - if (vfRunningFromCache)
883 + if (CacheBundleRunningFromCache(pCache))
884 {
885 hr = StrAllocString(psczEngineWorkingPath, sczSourcePath, 0);
886 ExitOnFailure(hr, "Failed to use current process path as target path.");
887 }
888 else // otherwise, carry on putting the bundle in the working folder.
889 {
831 - hr = CopyEngineToWorkingFolder(sczSourcePath, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczEngineWorkingPath);
890 + hr = CopyEngineToWorkingFolder(pCache, sczSourcePath, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczEngineWorkingPath);
891 ExitOnFailure(hr, "Failed to copy engine to working folder.");
892 }
893
@@ -866,6 +925,7 @@ LExit:
925 }
926
927 extern "C" HRESULT CacheCompleteBundle(
928 + __in BURN_CACHE* pCache,
929 __in BOOL fPerMachine,
930 __in_z LPCWSTR wzExecutableName,
931 __in_z LPCWSTR wzBundleId,
@@ -882,7 +942,7 @@ extern "C" HRESULT CacheCompleteBundle(
942 LPWSTR sczSourceDirectory = NULL;
943 LPWSTR sczPayloadSourcePath = NULL;
944
885 - hr = CreateCompletedPath(fPerMachine, wzBundleId, NULL, &sczTargetDirectory);
945 + hr = CreateCompletedPath(pCache, fPerMachine, wzBundleId, NULL, &sczTargetDirectory);
946 ExitOnFailure(hr, "Failed to create completed cache path for bundle.");
947
948 hr = PathConcat(sczTargetDirectory, wzExecutableName, &sczTargetPath);
@@ -976,6 +1036,7 @@ LExit:
1036 }
1037
1038 extern "C" HRESULT CacheCompletePayload(
1039 + __in BURN_CACHE* pCache,
1040 __in BOOL fPerMachine,
1041 __in BURN_PAYLOAD* pPayload,
1042 __in_z LPCWSTR wzCacheId,
@@ -990,7 +1051,7 @@ extern "C" HRESULT CacheCompletePayload(
1051 LPWSTR sczCachedPath = NULL;
1052 LPWSTR sczUnverifiedPayloadPath = NULL;
1053
993 - hr = CreateCompletedPath(fPerMachine, wzCacheId, pPayload->sczFilePath, &sczCachedPath);
1054 + hr = CreateCompletedPath(pCache, fPerMachine, wzCacheId, pPayload->sczFilePath, &sczCachedPath);
1055 ExitOnFailure(hr, "Failed to get cached path for package with cache id: %ls", wzCacheId);
1056
1057 // If the cached file matches what we expected, we're good.
@@ -1000,7 +1061,7 @@ extern "C" HRESULT CacheCompletePayload(
1061 ExitFunction();
1062 }
1063
1003 - hr = CreateUnverifiedPath(fPerMachine, pPayload->sczKey, &sczUnverifiedPayloadPath);
1064 + hr = CreateUnverifiedPath(pCache, fPerMachine, pPayload->sczKey, &sczUnverifiedPayloadPath);
1065 ExitOnFailure(hr, "Failed to create unverified path.");
1066
1067 // If the working path exists, let's get it into the unverified path so we can reset the ACLs and verify the file.
@@ -1091,36 +1152,30 @@ LExit:
1152 }
1153
1154 extern "C" HRESULT CacheRemoveWorkingFolder(
1094 - __in_z_opt LPCWSTR wzBundleId
1155 + __in BURN_CACHE* pCache
1156 )
1157 {
1158 HRESULT hr = S_OK;
1098 - LPWSTR sczWorkingFolder = NULL;
1159
1100 - if (vfInitializedCache)
1160 + if (pCache->fInitializedCacheSources)
1161 {
1102 - hr = CalculateWorkingFolder(wzBundleId, &sczWorkingFolder);
1103 - ExitOnFailure(hr, "Failed to calculate the working folder to remove it.");
1104 -
1162 // Try to clean out everything in the working folder.
1106 - hr = DirEnsureDeleteEx(sczWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE);
1163 + hr = DirEnsureDeleteEx(pCache->sczWorkingFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE);
1164 TraceError(hr, "Could not delete bundle engine working folder.");
1165 }
1166
1110 -LExit:
1111 - ReleaseStr(sczWorkingFolder);
1112 -
1167 return hr;
1168 }
1169
1170 extern "C" HRESULT CacheRemoveBundle(
1171 + __in BURN_CACHE* pCache,
1172 __in BOOL fPerMachine,
1173 __in_z LPCWSTR wzBundleId
1174 )
1175 {
1176 HRESULT hr = S_OK;
1177
1123 - hr = RemoveBundleOrPackage(TRUE, fPerMachine, wzBundleId, wzBundleId);
1178 + hr = RemoveBundleOrPackage(pCache, TRUE, fPerMachine, wzBundleId, wzBundleId);
1179 ExitOnFailure(hr, "Failed to remove bundle id: %ls.", wzBundleId);
1180
1181 LExit:
@@ -1128,6 +1183,7 @@ LExit:
1183 }
1184
1185 extern "C" HRESULT CacheRemovePackage(
1186 + __in BURN_CACHE* pCache,
1187 __in BOOL fPerMachine,
1188 __in_z LPCWSTR wzPackageId,
1189 __in_z LPCWSTR wzCacheId
@@ -1135,7 +1191,7 @@ extern "C" HRESULT CacheRemovePackage(
1191 {
1192 HRESULT hr = S_OK;
1193
1138 - hr = RemoveBundleOrPackage(FALSE, fPerMachine, wzPackageId, wzCacheId);
1194 + hr = RemoveBundleOrPackage(pCache, FALSE, fPerMachine, wzPackageId, wzCacheId);
1195 ExitOnFailure(hr, "Failed to remove package id: %ls.", wzPackageId);
1196
1197 LExit:
@@ -1194,9 +1250,11 @@ LExit:
1250
1251 extern "C" void CacheCleanup(
1252 __in BOOL fPerMachine,
1197 - __in_z LPCWSTR wzBundleId
1253 + __in BURN_CACHE* pCache
1254 )
1255 {
1256 + Assert(pCache->fInitializedCache);
1257 +
1258 HRESULT hr = S_OK;
1259 LPWSTR sczFolder = NULL;
1260 LPWSTR sczFiles = NULL;
@@ -1205,7 +1263,7 @@ extern "C" void CacheCleanup(
1263 WIN32_FIND_DATAW wfd = { };
1264 size_t cchFileName = 0;
1265
1208 - hr = CacheGetCompletedPath(fPerMachine, UNVERIFIED_CACHE_FOLDER_NAME, &sczFolder);
1266 + hr = CacheGetCompletedPath(pCache, fPerMachine, UNVERIFIED_CACHE_FOLDER_NAME, &sczFolder);
1267 if (SUCCEEDED(hr))
1268 {
1269 hr = DirEnsureDeleteEx(sczFolder, DIR_DELETE_FILES | DIR_DELETE_RECURSE | DIR_DELETE_SCHEDULE);
@@ -1213,10 +1271,9 @@ extern "C" void CacheCleanup(
1271
1272 if (!fPerMachine)
1273 {
1216 - hr = CalculateWorkingFolder(wzBundleId, &sczFolder);
1217 - if (SUCCEEDED(hr))
1274 + if (pCache->sczWorkingFolder)
1275 {
1219 - hr = PathConcat(sczFolder, L"*.*", &sczFiles);
1276 + hr = PathConcat(pCache->sczWorkingFolder, L"*.*", &sczFiles);
1277 if (SUCCEEDED(hr))
1278 {
1279 hFind = ::FindFirstFileW(sczFiles, &wfd);
@@ -1238,7 +1295,7 @@ extern "C" void CacheCleanup(
1295 continue;
1296 }
1297
1241 - hr = PathConcatCch(sczFolder, 0, wfd.cFileName, cchFileName, &sczDelete);
1298 + hr = PathConcatCch(pCache->sczWorkingFolder, 0, wfd.cFileName, cchFileName, &sczDelete);
1299 if (SUCCEEDED(hr))
1300 {
1301 hr = FileEnsureDelete(sczDelete);
@@ -1259,63 +1316,61 @@ extern "C" void CacheCleanup(
1316 ReleaseStr(sczFolder);
1317 }
1318
1262 -extern "C" void CacheUninitialize()
1319 +extern "C" void CacheUninitialize(
1320 + __in BURN_CACHE* pCache
1321 + )
1322 {
1264 - ReleaseNullStr(vsczCurrentMachinePackageCache);
1265 - ReleaseNullStr(vsczDefaultMachinePackageCache);
1266 - ReleaseNullStr(vsczDefaultUserPackageCache);
1267 - ReleaseNullStr(vsczWorkingFolder);
1268 - ReleaseNullStr(vsczSourceProcessFolder);
1269 -
1270 - vfRunningFromCache = FALSE;
1271 - vfInitializedCache = FALSE;
1323 + ReleaseNullStr(pCache->sczCurrentMachinePackageCache);
1324 + ReleaseNullStr(pCache->sczDefaultMachinePackageCache);
1325 + ReleaseNullStr(pCache->sczDefaultUserPackageCache);
1326 + ReleaseNullStr(pCache->sczWorkingFolder);
1327 + ReleaseNullStr(pCache->sczSourceProcessFolder);
1328 +
1329 + pCache->fRunningFromCache = FALSE;
1330 + pCache->fInitializedCache = FALSE;
1331 + pCache->fInitializedCacheSources = FALSE;
1332 + pCache->fPerMachineCacheRootVerified = FALSE;
1333 + pCache->fOriginalPerMachineCacheRootVerified = FALSE;
1334 + pCache->fUnverifiedCacheFolderCreated = FALSE;
1335 + pCache->fCustomMachinePackageCache = FALSE;
1336 }
1337
1338 // Internal functions.
1339
1340 static HRESULT CalculateWorkingFolder(
1277 - __in_z_opt LPCWSTR /*wzBundleId*/,
1278 - __deref_out_z LPWSTR* psczWorkingFolder
1341 + __in BURN_CACHE* pCache,
1342 + __in BURN_ENGINE_COMMAND* pInternalCommand
1343 )
1344 {
1345 HRESULT hr = S_OK;
1346 RPC_STATUS rs = RPC_S_OK;
1283 - BOOL fElevated = FALSE;
1347 LPWSTR sczTempPath = NULL;
1348 UUID guid = {};
1349 WCHAR wzGuid[39];
1350
1288 - if (!vsczWorkingFolder)
1351 + if (pInternalCommand->fInitiallyElevated)
1352 {
1290 - ProcElevated(::GetCurrentProcess(), &fElevated);
1291 -
1292 - if (fElevated)
1293 - {
1294 - hr = PathGetSystemTempPath(&sczTempPath);
1295 - ExitOnFailure(hr, "Failed to get system temp folder path for working folder.");
1296 - }
1297 - else
1298 - {
1299 - hr = PathGetTempPath(&sczTempPath);
1300 - ExitOnFailure(hr, "Failed to get temp folder path for working folder.");
1301 - }
1302 -
1303 - rs = ::UuidCreate(&guid);
1304 - hr = HRESULT_FROM_RPC(rs);
1305 - ExitOnFailure(hr, "Failed to create working folder guid.");
1353 + hr = PathGetSystemTempPath(&sczTempPath);
1354 + ExitOnFailure(hr, "Failed to get system temp folder path for working folder.");
1355 + }
1356 + else
1357 + {
1358 + hr = PathGetTempPath(&sczTempPath);
1359 + ExitOnFailure(hr, "Failed to get temp folder path for working folder.");
1360 + }
1361
1307 - if (!::StringFromGUID2(guid, wzGuid, countof(wzGuid)))
1308 - {
1309 - hr = E_OUTOFMEMORY;
1310 - ExitOnRootFailure(hr, "Failed to convert working folder guid into string.");
1311 - }
1362 + rs = ::UuidCreate(&guid);
1363 + hr = HRESULT_FROM_RPC(rs);
1364 + ExitOnFailure(hr, "Failed to create working folder guid.");
1365
1313 - hr = StrAllocFormatted(&vsczWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid);
1314 - ExitOnFailure(hr, "Failed to append bundle id on to temp path for working folder.");
1366 + if (!::StringFromGUID2(guid, wzGuid, countof(wzGuid)))
1367 + {
1368 + hr = E_OUTOFMEMORY;
1369 + ExitOnRootFailure(hr, "Failed to convert working folder guid into string.");
1370 }
1371
1317 - hr = StrAllocString(psczWorkingFolder, vsczWorkingFolder, 0);
1318 - ExitOnFailure(hr, "Failed to copy working folder path.");
1372 + hr = StrAllocFormatted(&pCache->sczWorkingFolder, L"%ls%ls\\", sczTempPath, wzGuid);
1373 + ExitOnFailure(hr, "Failed to append random guid on to temp path for working folder.");
1374
1375 LExit:
1376 ReleaseStr(sczTempPath);
@@ -1324,78 +1379,33 @@ LExit:
1379 }
1380
1381 static HRESULT GetRootPath(
1382 + __in BURN_CACHE* pCache,
1383 __in BOOL fPerMachine,
1384 __in BOOL fAllowRedirect,
1385 __deref_out_z LPWSTR* psczRootPath
1386 )
1387 {
1388 + Assert(pCache->fInitializedCache);
1389 +
1390 HRESULT hr = S_OK;
1333 - LPWSTR sczAppData = NULL;
1334 - int nCompare = 0;
1391
1336 - // Cache paths are initialized once so they cannot be changed while the engine is caching payloads.
1392 if (fPerMachine)
1393 {
1339 - // Always construct the default machine package cache path so we can determine if we're redirected.
1340 - if (!vsczDefaultMachinePackageCache)
1341 - {
1342 - hr = PathGetKnownFolder(CSIDL_COMMON_APPDATA, &sczAppData);
1343 - ExitOnFailure(hr, "Failed to find local %hs appdata directory.", "per-machine");
1344 -
1345 - hr = PathConcat(sczAppData, PACKAGE_CACHE_FOLDER_NAME, &vsczDefaultMachinePackageCache);
1346 - ExitOnFailure(hr, "Failed to construct %hs package cache directory name.", "per-machine");
1347 -
1348 - hr = PathBackslashTerminate(&vsczDefaultMachinePackageCache);
1349 - ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-machine");
1350 - }
1394 + BOOL fRedirect = fAllowRedirect && pCache->fCustomMachinePackageCache;
1395
1352 - if (!vsczCurrentMachinePackageCache)
1353 - {
1354 - hr = PolcReadString(POLICY_BURN_REGISTRY_PATH, L"PackageCache", NULL, &vsczCurrentMachinePackageCache);
1355 - ExitOnFailure(hr, "Failed to read PackageCache policy directory.");
1356 -
1357 - if (vsczCurrentMachinePackageCache)
1358 - {
1359 - hr = PathBackslashTerminate(&vsczCurrentMachinePackageCache);
1360 - ExitOnFailure(hr, "Failed to backslash terminate redirected per-machine package cache directory name.");
1361 - }
1362 - else
1363 - {
1364 - hr = StrAllocString(&vsczCurrentMachinePackageCache, vsczDefaultMachinePackageCache, 0);
1365 - ExitOnFailure(hr, "Failed to copy default package cache directory to current package cache directory.");
1366 - }
1367 - }
1368 -
1369 - hr = StrAllocString(psczRootPath, fAllowRedirect ? vsczCurrentMachinePackageCache : vsczDefaultMachinePackageCache, 0);
1396 + hr = StrAllocString(psczRootPath, fRedirect ? pCache->sczCurrentMachinePackageCache : pCache->sczDefaultMachinePackageCache, 0);
1397 ExitOnFailure(hr, "Failed to copy %hs package cache root directory.", "per-machine");
1398
1372 - hr = PathCompare(vsczDefaultMachinePackageCache, *psczRootPath, &nCompare);
1373 - ExitOnFailure(hr, "Failed to compare default and current package cache directories.");
1374 -
1399 // Return S_FALSE if the current location is not the default location (redirected).
1376 - hr = CSTR_EQUAL == nCompare ? S_OK : S_FALSE;
1400 + hr = fRedirect ? S_FALSE : S_OK;
1401 }
1402 else
1403 {
1380 - if (!vsczDefaultUserPackageCache)
1381 - {
1382 - hr = PathGetKnownFolder(CSIDL_LOCAL_APPDATA, &sczAppData);
1383 - ExitOnFailure(hr, "Failed to find local %hs appdata directory.", "per-user");
1384 -
1385 - hr = PathConcat(sczAppData, PACKAGE_CACHE_FOLDER_NAME, &vsczDefaultUserPackageCache);
1386 - ExitOnFailure(hr, "Failed to construct %hs package cache directory name.", "per-user");
1387 -
1388 - hr = PathBackslashTerminate(&vsczDefaultUserPackageCache);
1389 - ExitOnFailure(hr, "Failed to backslash terminate default %hs package cache directory name.", "per-user");
1390 - }
1391 -
1392 - hr = StrAllocString(psczRootPath, vsczDefaultUserPackageCache, 0);
1404 + hr = StrAllocString(psczRootPath, pCache->sczDefaultUserPackageCache, 0);
1405 ExitOnFailure(hr, "Failed to copy %hs package cache root directory.", "per-user");
1406 }
1407
1408 LExit:
1397 - ReleaseStr(sczAppData);
1398 -
1409 return hr;
1410 }
1411
@@ -1416,20 +1426,19 @@ static HRESULT GetLastUsedSourceFolder(
1426 return hr;
1427 }
1428
1419 -static HRESULT SecurePerMachineCacheRoot()
1429 +static HRESULT SecurePerMachineCacheRoot(
1430 + __in BURN_CACHE* pCache
1431 + )
1432 {
1421 - static BOOL fPerMachineCacheRootVerified = FALSE;
1422 - static BOOL fOriginalPerMachineCacheRootVerified = FALSE;
1423 -
1433 HRESULT hr = S_OK;
1434 BOOL fRedirected = FALSE;
1435 LPWSTR sczCacheDirectory = NULL;
1436
1428 - if (!fPerMachineCacheRootVerified)
1437 + if (!pCache->fPerMachineCacheRootVerified)
1438 {
1439 // If we are doing a permachine install but have not yet verified that the root cache folder
1440 // was created with the correct ACLs yet, do that now.
1432 - hr = GetRootPath(TRUE, TRUE, &sczCacheDirectory);
1441 + hr = GetRootPath(pCache, TRUE, TRUE, &sczCacheDirectory);
1442 ExitOnFailure(hr, "Failed to get cache directory.");
1443
1444 fRedirected = S_FALSE == hr;
@@ -1440,19 +1449,19 @@ static HRESULT SecurePerMachineCacheRoot()
1449 hr = SecurePath(sczCacheDirectory);
1450 ExitOnFailure(hr, "Failed to secure cache directory: %ls", sczCacheDirectory);
1451
1443 - fPerMachineCacheRootVerified = TRUE;
1452 + pCache->fPerMachineCacheRootVerified = TRUE;
1453
1454 if (!fRedirected)
1455 {
1447 - fOriginalPerMachineCacheRootVerified = TRUE;
1456 + pCache->fOriginalPerMachineCacheRootVerified = TRUE;
1457 }
1458 }
1459
1451 - if (!fOriginalPerMachineCacheRootVerified)
1460 + if (!pCache->fOriginalPerMachineCacheRootVerified)
1461 {
1462 // If we are doing a permachine install but have not yet verified that the original root cache folder
1463 // was created with the correct ACLs yet, do that now.
1455 - hr = GetRootPath(TRUE, FALSE, &sczCacheDirectory);
1464 + hr = GetRootPath(pCache, TRUE, FALSE, &sczCacheDirectory);
1465 ExitOnFailure(hr, "Failed to get original cache directory.");
1466
1467 hr = DirEnsureExists(sczCacheDirectory, NULL);
@@ -1461,7 +1470,7 @@ static HRESULT SecurePerMachineCacheRoot()
1470 hr = SecurePath(sczCacheDirectory);
1471 ExitOnFailure(hr, "Failed to secure original cache directory: %ls", sczCacheDirectory);
1472
1464 - fOriginalPerMachineCacheRootVerified = TRUE;
1473 + pCache->fOriginalPerMachineCacheRootVerified = TRUE;
1474 }
1475
1476 LExit:
@@ -1471,6 +1480,7 @@ LExit:
1480 }
1481
1482 static HRESULT CreateCompletedPath(
1483 + __in BURN_CACHE* pCache,
1484 __in BOOL fPerMachine,
1485 __in LPCWSTR wzId,
1486 __in LPCWSTR wzFilePath,
@@ -1483,12 +1493,12 @@ static HRESULT CreateCompletedPath(
1493
1494 if (fPerMachine)
1495 {
1486 - hr = SecurePerMachineCacheRoot();
1496 + hr = SecurePerMachineCacheRoot(pCache);
1497 ExitOnFailure(hr, "Failed to secure per-machine cache root.");
1498 }
1499
1500 // Get the cache completed path.
1491 - hr = CacheGetCompletedPath(fPerMachine, wzId, &sczCacheDirectory);
1501 + hr = CacheGetCompletedPath(pCache, fPerMachine, wzId, &sczCacheDirectory);
1502 ExitOnFailure(hr, "Failed to get cache directory.");
1503
1504 // Ensure it exists.
@@ -1523,25 +1533,26 @@ LExit:
1533 }
1534
1535 static HRESULT CreateUnverifiedPath(
1536 + __in BURN_CACHE* pCache,
1537 __in BOOL fPerMachine,
1538 __in_z LPCWSTR wzPayloadId,
1539 __out_z LPWSTR* psczUnverifiedPayloadPath
1540 )
1541 {
1531 - static BOOL fUnverifiedCacheFolderCreated = FALSE;
1532 -
1542 HRESULT hr = S_OK;
1543 LPWSTR sczUnverifiedCacheFolder = NULL;
1544
1536 - hr = CacheGetCompletedPath(fPerMachine, UNVERIFIED_CACHE_FOLDER_NAME, &sczUnverifiedCacheFolder);
1545 + hr = CacheGetCompletedPath(pCache, fPerMachine, UNVERIFIED_CACHE_FOLDER_NAME, &sczUnverifiedCacheFolder);
1546 ExitOnFailure(hr, "Failed to get cache directory.");
1547
1539 - if (!fUnverifiedCacheFolderCreated)
1548 + if (!pCache->fUnverifiedCacheFolderCreated)
1549 {
1550 hr = DirEnsureExists(sczUnverifiedCacheFolder, NULL);
1551 ExitOnFailure(hr, "Failed to create unverified cache directory: %ls", sczUnverifiedCacheFolder);
1552
1553 ResetPathPermissions(fPerMachine, sczUnverifiedCacheFolder);
1554 +
1555 + pCache->fUnverifiedCacheFolderCreated = TRUE;
1556 }
1557
1558 hr = PathConcat(sczUnverifiedCacheFolder, wzPayloadId, psczUnverifiedPayloadPath);
@@ -1946,6 +1957,7 @@ LExit:
1957
1958
1959 static HRESULT CopyEngineToWorkingFolder(
1960 + __in BURN_CACHE* pCache,
1961 __in_z LPCWSTR wzSourcePath,
1962 __in_z LPCWSTR wzWorkingFolderName,
1963 __in_z LPCWSTR wzExecutableName,
@@ -1961,7 +1973,7 @@ static HRESULT CopyEngineToWorkingFolder(
1973 LPWSTR sczPayloadSourcePath = NULL;
1974 LPWSTR sczPayloadTargetPath = NULL;
1975
1964 - hr = CacheEnsureWorkingFolder(NULL, &sczWorkingFolder);
1976 + hr = CacheEnsureWorkingFolder(pCache, &sczWorkingFolder);
1977 ExitOnFailure(hr, "Failed to create working path to copy engine.");
1978
1979 hr = PathConcat(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory);
@@ -2064,6 +2076,7 @@ LExit:
2076
2077
2078 static HRESULT RemoveBundleOrPackage(
2079 + __in BURN_CACHE* pCache,
2080 __in BOOL fBundle,
2081 __in BOOL fPerMachine,
2082 __in_z LPCWSTR wzBundleOrPackageId,
@@ -2074,7 +2087,7 @@ static HRESULT RemoveBundleOrPackage(
2087 LPWSTR sczRootCacheDirectory = NULL;
2088 LPWSTR sczDirectory = NULL;
2089
2077 - hr = CacheGetCompletedPath(fPerMachine, wzCacheId, &sczDirectory);
2090 + hr = CacheGetCompletedPath(pCache, fPerMachine, wzCacheId, &sczDirectory);
2091 ExitOnFailure(hr, "Failed to calculate cache path.");
2092
2093 LogId(REPORT_STANDARD, fBundle ? MSG_UNCACHE_BUNDLE : MSG_UNCACHE_PACKAGE, wzBundleOrPackageId, sczDirectory);
@@ -2103,14 +2116,14 @@ static HRESULT RemoveBundleOrPackage(
2116 else
2117 {
2118 // Try to remove root package cache in the off chance it is now empty.
2106 - hr = GetRootPath(fPerMachine, TRUE, &sczRootCacheDirectory);
2119 + hr = GetRootPath(pCache, fPerMachine, TRUE, &sczRootCacheDirectory);
2120 ExitOnFailure(hr, "Failed to get %hs package cache root directory.", fPerMachine ? "per-machine" : "per-user");
2121 DirEnsureDeleteEx(sczRootCacheDirectory, DIR_DELETE_SCHEDULE);
2122
2123 // GetRootPath returns S_FALSE if the package cache is redirected elsewhere.
2124 if (S_FALSE == hr)
2125 {
2113 - hr = GetRootPath(fPerMachine, FALSE, &sczRootCacheDirectory);
2126 + hr = GetRootPath(pCache, fPerMachine, FALSE, &sczRootCacheDirectory);
2127 ExitOnFailure(hr, "Failed to get old %hs package cache root directory.", fPerMachine ? "per-machine" : "per-user");
2128 DirEnsureDeleteEx(sczRootCacheDirectory, DIR_DELETE_SCHEDULE);
2129 }
src/burn/engine/cache.h
+47 -10
@@ -24,6 +24,24 @@ enum BURN_CACHE_STEP
24 BURN_CACHE_STEP_FINALIZE,
25 };
26
27 +typedef struct _BURN_CACHE
28 +{
29 + BOOL fInitializedCache;
30 + BOOL fPerMachineCacheRootVerified;
31 + BOOL fOriginalPerMachineCacheRootVerified;
32 + BOOL fUnverifiedCacheFolderCreated;
33 + BOOL fCustomMachinePackageCache;
34 + LPWSTR sczDefaultUserPackageCache;
35 + LPWSTR sczDefaultMachinePackageCache;
36 + LPWSTR sczCurrentMachinePackageCache;
37 +
38 + // Only valid after CacheInitializeSources
39 + BOOL fInitializedCacheSources;
40 + BOOL fRunningFromCache;
41 + LPWSTR sczSourceProcessFolder;
42 + LPWSTR sczWorkingFolder;
43 +} BURN_CACHE;
44 +
45 typedef struct _BURN_CACHE_MESSAGE
46 {
47 BURN_CACHE_MESSAGE_TYPE type;
@@ -53,38 +71,46 @@ typedef HRESULT(CALLBACK* PFN_BURNCACHEMESSAGEHANDLER)(
71 // functions
72
73 HRESULT CacheInitialize(
74 + __in BURN_CACHE* pCache,
75 + __in BURN_ENGINE_COMMAND* pInternalCommand
76 + );
77 +HRESULT CacheInitializeSources(
78 + __in BURN_CACHE* pCache,
79 __in BURN_REGISTRATION* pRegistration,
80 __in BURN_VARIABLES* pVariables,
58 - __in_z_opt LPCWSTR wzSourceProcessPath
81 + __in BURN_ENGINE_COMMAND* pInternalCommand
82 );
83 HRESULT CacheEnsureWorkingFolder(
61 - __in_z_opt LPCWSTR wzBundleId,
84 + __in BURN_CACHE* pCache,
85 __deref_out_z_opt LPWSTR* psczWorkingFolder
86 );
87 HRESULT CacheCalculateBundleWorkingPath(
65 - __in_z LPCWSTR wzBundleId,
88 + __in BURN_CACHE* pCache,
89 __in LPCWSTR wzExecutableName,
90 __deref_out_z LPWSTR* psczWorkingPath
91 );
92 HRESULT CacheCalculateBundleLayoutWorkingPath(
93 + __in BURN_CACHE* pCache,
94 __in_z LPCWSTR wzBundleId,
95 __deref_out_z LPWSTR* psczWorkingPath
96 );
97 HRESULT CacheCalculatePayloadWorkingPath(
74 - __in_z LPCWSTR wzBundleId,
98 + __in BURN_CACHE* pCache,
99 __in BURN_PAYLOAD* pPayload,
100 __deref_out_z LPWSTR* psczWorkingPath
101 );
102 HRESULT CacheCalculateContainerWorkingPath(
79 - __in_z LPCWSTR wzBundleId,
103 + __in BURN_CACHE* pCache,
104 __in BURN_CONTAINER* pContainer,
105 __deref_out_z LPWSTR* psczWorkingPath
106 );
107 HRESULT CacheGetPerMachineRootCompletedPath(
108 + __in BURN_CACHE* pCache,
109 __out_z LPWSTR* psczCurrentRootCompletedPath,
110 __out_z LPWSTR* psczDefaultRootCompletedPath
111 );
112 HRESULT CacheGetCompletedPath(
113 + __in BURN_CACHE* pCache,
114 __in BOOL fPerMachine,
115 __in_z LPCWSTR wzCacheId,
116 __deref_out_z LPWSTR* psczCompletedPath
@@ -98,6 +124,7 @@ HRESULT CacheGetLocalSourcePaths(
124 __in_z LPCWSTR wzSourcePath,
125 __in_z LPCWSTR wzDestinationPath,
126 __in_z_opt LPCWSTR wzLayoutDirectory,
127 + __in BURN_CACHE* pCache,
128 __in BURN_VARIABLES* pVariables,
129 __inout LPWSTR** prgSearchPaths,
130 __out DWORD* pcSearchPaths,
@@ -121,16 +148,20 @@ void CacheSendErrorCallback(
148 __in_z_opt LPCWSTR wzError,
149 __out_opt BOOL* pfRetry
150 );
124 -BOOL CacheBundleRunningFromCache();
151 +BOOL CacheBundleRunningFromCache(
152 + __in BURN_CACHE* pCache
153 + );
154 HRESULT CachePreparePackage(
155 + __in BURN_CACHE* pCache,
156 __in BURN_PACKAGE* pPackage
157 );
158 HRESULT CacheBundleToCleanRoom(
159 + __in BURN_CACHE* pCache,
160 __in BURN_SECTION* pSection,
161 __deref_out_z_opt LPWSTR* psczCleanRoomBundlePath
162 );
163 HRESULT CacheBundleToWorkingDirectory(
133 - __in_z LPCWSTR wzBundleId,
164 + __in BURN_CACHE* pCache,
165 __in_z LPCWSTR wzExecutableName,
166 __in BURN_SECTION* pSection,
167 __deref_out_z_opt LPWSTR* psczEngineWorkingPath
@@ -145,6 +176,7 @@ HRESULT CacheLayoutBundle(
176 __in LPVOID pContext
177 );
178 HRESULT CacheCompleteBundle(
179 + __in BURN_CACHE* pCache,
180 __in BOOL fPerMachine,
181 __in_z LPCWSTR wzExecutableName,
182 __in_z LPCWSTR wzBundleId,
@@ -172,6 +204,7 @@ HRESULT CacheLayoutPayload(
204 __in LPVOID pContext
205 );
206 HRESULT CacheCompletePayload(
207 + __in BURN_CACHE* pCache,
208 __in BOOL fPerMachine,
209 __in BURN_PAYLOAD* pPayload,
210 __in_z LPCWSTR wzCacheId,
@@ -196,22 +229,26 @@ HRESULT CacheVerifyPayload(
229 __in LPVOID pContext
230 );
231 HRESULT CacheRemoveWorkingFolder(
199 - __in_z_opt LPCWSTR wzBundleId
232 + __in BURN_CACHE* pCache
233 );
234 HRESULT CacheRemoveBundle(
235 + __in BURN_CACHE* pCache,
236 __in BOOL fPerMachine,
237 __in_z LPCWSTR wzPackageId
238 );
239 HRESULT CacheRemovePackage(
240 + __in BURN_CACHE* pCache,
241 __in BOOL fPerMachine,
242 __in_z LPCWSTR wzPackageId,
243 __in_z LPCWSTR wzCacheId
244 );
245 void CacheCleanup(
246 __in BOOL fPerMachine,
212 - __in_z LPCWSTR wzBundleId
247 + __in BURN_CACHE* pCache
248 + );
249 +void CacheUninitialize(
250 + __in BURN_CACHE* pCache
251 );
214 -void CacheUninitialize();
252
253 #ifdef __cplusplus
254 }
src/burn/engine/core.cpp
+11 -12
@@ -32,6 +32,7 @@ static HRESULT DetectPackage(
32 __in BURN_PACKAGE* pPackage
33 );
34 static HRESULT DetectPackagePayloadsCached(
35 + __in BURN_CACHE* pCache,
36 __in BURN_PACKAGE* pPackage
37 );
38 static DWORD WINAPI CacheThreadProc(
@@ -65,7 +66,6 @@ extern "C" HRESULT CoreInitialize(
66 BYTE* pbBuffer = NULL;
67 SIZE_T cbBuffer = 0;
68 BURN_CONTAINER_CONTEXT containerContext = { };
68 - BOOL fElevated = FALSE;
69 LPWSTR sczSourceProcessFolder = NULL;
70
71 // Initialize variables.
@@ -105,10 +105,7 @@ extern "C" HRESULT CoreInitialize(
105 hr = CoreInitializeConstants(pEngineState);
106 ExitOnFailure(hr, "Failed to initialize contants.");
107
108 - // Retain whether bundle was initially run elevated.
109 - ProcElevated(::GetCurrentProcess(), &fElevated);
110 -
111 - hr = VariableSetNumeric(&pEngineState->variables, BURN_BUNDLE_ELEVATED, fElevated, TRUE);
108 + hr = VariableSetNumeric(&pEngineState->variables, BURN_BUNDLE_ELEVATED, pEngineState->internalCommand.fInitiallyElevated, TRUE);
109 ExitOnFailure(hr, "Failed to overwrite the %ls built-in variable.", BURN_BUNDLE_ELEVATED);
110
111 hr = VariableSetNumeric(&pEngineState->variables, BURN_BUNDLE_UILEVEL, pEngineState->command.display, TRUE);
@@ -136,8 +133,8 @@ extern "C" HRESULT CoreInitialize(
133
134 if (BURN_MODE_UNTRUSTED == pEngineState->mode || BURN_MODE_NORMAL == pEngineState->mode || BURN_MODE_EMBEDDED == pEngineState->mode)
135 {
139 - hr = CacheInitialize(&pEngineState->registration, &pEngineState->variables, pEngineState->internalCommand.sczSourceProcessPath);
140 - ExitOnFailure(hr, "Failed to initialize internal cache functionality.");
136 + hr = CacheInitializeSources(&pEngineState->cache, &pEngineState->registration, &pEngineState->variables, &pEngineState->internalCommand);
137 + ExitOnFailure(hr, "Failed to initialize internal cache source functionality.");
138 }
139
140 // If we're not elevated then we'll be loading the bootstrapper application, so extract
@@ -145,7 +142,7 @@ extern "C" HRESULT CoreInitialize(
142 if (BURN_MODE_NORMAL == pEngineState->mode || BURN_MODE_EMBEDDED == pEngineState->mode)
143 {
144 // Extract all UX payloads to working folder.
148 - hr = UserExperienceEnsureWorkingFolder(pEngineState->registration.sczId, &pEngineState->userExperience.sczTempDirectory);
145 + hr = UserExperienceEnsureWorkingFolder(&pEngineState->cache, &pEngineState->userExperience.sczTempDirectory);
146 ExitOnFailure(hr, "Failed to get unique temporary folder for bootstrapper application.");
147
148 hr = PayloadExtractUXContainer(&pEngineState->userExperience.payloads, &containerContext, pEngineState->userExperience.sczTempDirectory);
@@ -455,6 +452,7 @@ extern "C" HRESULT CorePlan(
452 // Remember the overall action state in the plan since it shapes the changes
453 // we make everywhere.
454 pEngineState->plan.action = action;
455 + pEngineState->plan.pCache = &pEngineState->cache;
456 pEngineState->plan.pPayloads = &pEngineState->payloads;
457 pEngineState->plan.wzBundleId = pEngineState->registration.sczId;
458 pEngineState->plan.wzBundleProviderKey = pEngineState->registration.sczId;
@@ -571,7 +569,7 @@ extern "C" HRESULT CoreElevate(
569 // If the elevated companion pipe isn't created yet, let's make that happen.
570 if (!pEngineState->sczBundleEngineWorkingPath)
571 {
574 - hr = CacheBundleToWorkingDirectory(pEngineState->registration.sczId, pEngineState->registration.sczExecutableName, &pEngineState->section, &pEngineState->sczBundleEngineWorkingPath);
572 + hr = CacheBundleToWorkingDirectory(&pEngineState->cache, pEngineState->registration.sczExecutableName, &pEngineState->section, &pEngineState->sczBundleEngineWorkingPath);
573 ExitOnFailure(hr, "Failed to cache engine to working directory.");
574 }
575
@@ -673,7 +671,7 @@ extern "C" HRESULT CoreApply(
671 // Ensure the engine is cached to the working path.
672 if (!pEngineState->sczBundleEngineWorkingPath)
673 {
676 - hr = CacheBundleToWorkingDirectory(pEngineState->registration.sczId, pEngineState->registration.sczExecutableName, &pEngineState->section, &pEngineState->sczBundleEngineWorkingPath);
674 + hr = CacheBundleToWorkingDirectory(&pEngineState->cache, pEngineState->registration.sczExecutableName, &pEngineState->section, &pEngineState->sczBundleEngineWorkingPath);
675 ExitOnFailure(hr, "Failed to cache engine to working directory.");
676 }
677
@@ -1740,7 +1738,7 @@ static HRESULT DetectPackage(
1738 ExitOnRootFailure(hr, "BA aborted detect package begin.");
1739
1740 // Detect the cache state of the package.
1743 - hr = DetectPackagePayloadsCached(pPackage);
1741 + hr = DetectPackagePayloadsCached(&pEngineState->cache, pPackage);
1742 ExitOnFailure(hr, "Failed to detect if payloads are all cached for package: %ls", pPackage->sczId);
1743
1744 // Use the correct engine to detect the package.
@@ -1782,6 +1780,7 @@ LExit:
1780 }
1781
1782 static HRESULT DetectPackagePayloadsCached(
1783 + __in BURN_CACHE* pCache,
1784 __in BURN_PACKAGE* pPackage
1785 )
1786 {
@@ -1792,7 +1791,7 @@ static HRESULT DetectPackagePayloadsCached(
1791
1792 if (pPackage->sczCacheId && *pPackage->sczCacheId)
1793 {
1795 - hr = CacheGetCompletedPath(pPackage->fPerMachine, pPackage->sczCacheId, &sczCachePath);
1794 + hr = CacheGetCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, &sczCachePath);
1795 ExitOnFailure(hr, "Failed to get completed cache path.");
1796
1797 // If the cached directory exists, we have something.
src/burn/engine/core.h
+2
@@ -80,6 +80,7 @@ enum BURN_AU_PAUSE_ACTION
80
81 typedef struct _BURN_ENGINE_COMMAND
82 {
83 + BOOL fInitiallyElevated;
84 LPWSTR sczSourceProcessPath;
85 LPWSTR sczOriginalSource;
86 } BURN_ENGINE_COMMAND;
@@ -109,6 +110,7 @@ typedef struct _BURN_ENGINE_STATE
110 BURN_PACKAGES packages;
111 BURN_UPDATE update;
112 BURN_APPROVED_EXES approvedExes;
113 + BURN_CACHE cache;
114 BURN_EXTENSIONS extensions;
115
116 HWND hMessageWindow;
src/burn/engine/elevation.cpp
+49 -25
@@ -88,6 +88,7 @@ typedef struct _BURN_ELEVATION_CHILD_MESSAGE_CONTEXT
88 HANDLE* phLock;
89 BOOL* pfDisabledAutomaticUpdates;
90 BURN_APPROVED_EXES* pApprovedExes;
91 + BURN_CACHE* pCache;
92 BURN_CONTAINERS* pContainers;
93 BURN_PACKAGES* pPackages;
94 BURN_PAYLOADS* pPayloads;
@@ -164,6 +165,7 @@ static HRESULT OnApplyUninitialize(
165 __in HANDLE* phLock
166 );
167 static HRESULT OnSessionBegin(
168 + __in BURN_CACHE* pCache,
169 __in BURN_REGISTRATION* pRegistration,
170 __in BURN_VARIABLES* pVariables,
171 __in BYTE* pbData,
@@ -176,6 +178,7 @@ static HRESULT OnSessionResume(
178 __in SIZE_T cbData
179 );
180 static HRESULT OnSessionEnd(
181 + __in BURN_CACHE* pCache,
182 __in BURN_PACKAGES* pPackages,
183 __in BURN_REGISTRATION* pRegistration,
184 __in BURN_VARIABLES* pVariables,
@@ -188,12 +191,14 @@ static HRESULT OnSaveState(
191 __in SIZE_T cbData
192 );
193 static HRESULT OnCachePreparePackage(
194 + __in BURN_CACHE* pCache,
195 __in BURN_PACKAGES* pPackages,
196 __in BYTE* pbData,
197 __in SIZE_T cbData
198 );
199 static HRESULT OnCacheCompletePayload(
200 __in HANDLE hPipe,
201 + __in BURN_CACHE* pCache,
202 __in BURN_PACKAGES* pPackages,
203 __in BURN_PAYLOADS* pPayloads,
204 __in BYTE* pbData,
@@ -207,7 +212,7 @@ static HRESULT OnCacheVerifyPayload(
212 __in SIZE_T cbData
213 );
214 static void OnCacheCleanup(
210 - __in_z LPCWSTR wzBundleId
215 + __in BURN_CACHE* pCache
216 );
217 static HRESULT OnProcessDependentRegistration(
218 __in const BURN_REGISTRATION* pRegistration,
@@ -216,6 +221,7 @@ static HRESULT OnProcessDependentRegistration(
221 );
222 static HRESULT OnExecuteExePackage(
223 __in HANDLE hPipe,
224 + __in BURN_CACHE* pCache,
225 __in BURN_PACKAGES* pPackages,
226 __in BURN_RELATED_BUNDLES* pRelatedBundles,
227 __in BURN_VARIABLES* pVariables,
@@ -224,6 +230,7 @@ static HRESULT OnExecuteExePackage(
230 );
231 static HRESULT OnExecuteMsiPackage(
232 __in HANDLE hPipe,
233 + __in BURN_CACHE* pCache,
234 __in BURN_PACKAGES* pPackages,
235 __in BURN_VARIABLES* pVariables,
236 __in BYTE* pbData,
@@ -231,6 +238,7 @@ static HRESULT OnExecuteMsiPackage(
238 );
239 static HRESULT OnExecuteMspPackage(
240 __in HANDLE hPipe,
241 + __in BURN_CACHE* pCache,
242 __in BURN_PACKAGES* pPackages,
243 __in BURN_VARIABLES* pVariables,
244 __in BYTE* pbData,
@@ -238,6 +246,7 @@ static HRESULT OnExecuteMspPackage(
246 );
247 static HRESULT OnExecuteMsuPackage(
248 __in HANDLE hPipe,
249 + __in BURN_CACHE* pCache,
250 __in BURN_PACKAGES* pPackages,
251 __in BURN_VARIABLES* pVariables,
252 __in BYTE* pbData,
@@ -279,6 +288,7 @@ static int MsiExecuteMessageHandler(
288 __in_opt LPVOID pvContext
289 );
290 static HRESULT OnCleanPackage(
291 + __in BURN_CACHE* pCache,
292 __in BURN_PACKAGES* pPackages,
293 __in BYTE* pbData,
294 __in SIZE_T cbData
@@ -286,6 +296,7 @@ static HRESULT OnCleanPackage(
296 static HRESULT OnLaunchApprovedExe(
297 __in HANDLE hPipe,
298 __in BURN_APPROVED_EXES* pApprovedExes,
299 + __in BURN_CACHE* pCache,
300 __in BURN_VARIABLES* pVariables,
301 __in BYTE* pbData,
302 __in SIZE_T cbData
@@ -1284,6 +1295,7 @@ extern "C" HRESULT ElevationChildPumpMessages(
1295 __in HANDLE hPipe,
1296 __in HANDLE hCachePipe,
1297 __in BURN_APPROVED_EXES* pApprovedExes,
1298 + __in BURN_CACHE* pCache,
1299 __in BURN_CONTAINERS* pContainers,
1300 __in BURN_PACKAGES* pPackages,
1301 __in BURN_PAYLOADS* pPayloads,
@@ -1304,6 +1316,7 @@ extern "C" HRESULT ElevationChildPumpMessages(
1316
1317 cacheContext.dwLoggingTlsId = dwLoggingTlsId;
1318 cacheContext.hPipe = hCachePipe;
1319 + cacheContext.pCache = pCache;
1320 cacheContext.pContainers = pContainers;
1321 cacheContext.pPackages = pPackages;
1322 cacheContext.pPayloads = pPayloads;
@@ -1316,6 +1329,7 @@ extern "C" HRESULT ElevationChildPumpMessages(
1329 context.phLock = phLock;
1330 context.pfDisabledAutomaticUpdates = pfDisabledAutomaticUpdates;
1331 context.pApprovedExes = pApprovedExes;
1332 + context.pCache = pCache;
1333 context.pContainers = pContainers;
1334 context.pPackages = pPackages;
1335 context.pPayloads = pPayloads;
@@ -1826,7 +1840,7 @@ static HRESULT ProcessElevatedChildMessage(
1840 break;
1841
1842 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_BEGIN:
1829 - hrResult = OnSessionBegin(pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1843 + hrResult = OnSessionBegin(pContext->pCache, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1844 break;
1845
1846 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_RESUME:
@@ -1834,7 +1848,7 @@ static HRESULT ProcessElevatedChildMessage(
1848 break;
1849
1850 case BURN_ELEVATION_MESSAGE_TYPE_SESSION_END:
1837 - hrResult = OnSessionEnd(pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1851 + hrResult = OnSessionEnd(pContext->pCache, pContext->pPackages, pContext->pRegistration, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1852 break;
1853
1854 case BURN_ELEVATION_MESSAGE_TYPE_SAVE_STATE:
@@ -1846,19 +1860,19 @@ static HRESULT ProcessElevatedChildMessage(
1860 break;
1861
1862 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_EXE_PACKAGE:
1849 - hrResult = OnExecuteExePackage(pContext->hPipe, pContext->pPackages, &pContext->pRegistration->relatedBundles, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1863 + hrResult = OnExecuteExePackage(pContext->hPipe, pContext->pCache, pContext->pPackages, &pContext->pRegistration->relatedBundles, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1864 break;
1865
1866 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_MSI_PACKAGE:
1853 - hrResult = OnExecuteMsiPackage(pContext->hPipe, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1867 + hrResult = OnExecuteMsiPackage(pContext->hPipe, pContext->pCache, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1868 break;
1869
1870 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_MSP_PACKAGE:
1857 - hrResult = OnExecuteMspPackage(pContext->hPipe, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1871 + hrResult = OnExecuteMspPackage(pContext->hPipe, pContext->pCache, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1872 break;
1873
1874 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_MSU_PACKAGE:
1861 - hrResult = OnExecuteMsuPackage(pContext->hPipe, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1875 + hrResult = OnExecuteMsuPackage(pContext->hPipe, pContext->pCache, pContext->pPackages, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1876 break;
1877
1878 case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_PACKAGE_PROVIDER:
@@ -1870,11 +1884,11 @@ static HRESULT ProcessElevatedChildMessage(
1884 break;
1885
1886 case BURN_ELEVATION_MESSAGE_TYPE_CLEAN_PACKAGE:
1873 - hrResult = OnCleanPackage(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1887 + hrResult = OnCleanPackage(pContext->pCache, pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1888 break;
1889
1890 case BURN_ELEVATION_MESSAGE_TYPE_LAUNCH_APPROVED_EXE:
1877 - hrResult = OnLaunchApprovedExe(pContext->hPipe, pContext->pApprovedExes, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1891 + hrResult = OnLaunchApprovedExe(pContext->hPipe, pContext->pApprovedExes, pContext->pCache, pContext->pVariables, (BYTE*)pMsg->pvData, pMsg->cbData);
1892 break;
1893
1894 default:
@@ -1901,11 +1915,11 @@ static HRESULT ProcessElevatedChildCacheMessage(
1915 switch (pMsg->dwMessage)
1916 {
1917 case BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE:
1904 - hrResult = OnCachePreparePackage(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1918 + hrResult = OnCachePreparePackage(pContext->pCache, pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1919 break;
1920
1921 case BURN_ELEVATION_MESSAGE_TYPE_CACHE_COMPLETE_PAYLOAD:
1908 - hrResult = OnCacheCompletePayload(pContext->hPipe, pContext->pPackages, pContext->pPayloads, (BYTE*)pMsg->pvData, pMsg->cbData);
1922 + hrResult = OnCacheCompletePayload(pContext->hPipe, pContext->pCache, pContext->pPackages, pContext->pPayloads, (BYTE*)pMsg->pvData, pMsg->cbData);
1923 break;
1924
1925 case BURN_ELEVATION_MESSAGE_TYPE_CACHE_VERIFY_PAYLOAD:
@@ -1913,12 +1927,12 @@ static HRESULT ProcessElevatedChildCacheMessage(
1927 break;
1928
1929 case BURN_ELEVATION_MESSAGE_TYPE_CACHE_CLEANUP:
1916 - OnCacheCleanup(pContext->pRegistration->sczId);
1930 + OnCacheCleanup(pContext->pCache);
1931 hrResult = S_OK;
1932 break;
1933
1934 case BURN_ELEVATION_MESSAGE_TYPE_CLEAN_PACKAGE:
1921 - hrResult = OnCleanPackage(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1935 + hrResult = OnCleanPackage(pContext->pCache, pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData);
1936 break;
1937
1938 default:
@@ -2080,6 +2094,7 @@ static HRESULT OnApplyUninitialize(
2094 }
2095
2096 static HRESULT OnSessionBegin(
2097 + __in BURN_CACHE* pCache,
2098 __in BURN_REGISTRATION* pRegistration,
2099 __in BURN_VARIABLES* pVariables,
2100 __in BYTE* pbData,
@@ -2120,7 +2135,7 @@ static HRESULT OnSessionBegin(
2135 ExitOnFailure(hr, "Failed to read variables.");
2136
2137 // Begin session in per-machine process.
2123 - hr = RegistrationSessionBegin(sczEngineWorkingPath, pRegistration, pVariables, dwRegistrationOperations, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction, qwEstimatedSize, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType);
2138 + hr = RegistrationSessionBegin(sczEngineWorkingPath, pRegistration, pCache, pVariables, dwRegistrationOperations, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction, qwEstimatedSize, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType);
2139 ExitOnFailure(hr, "Failed to begin registration session.");
2140
2141 LExit:
@@ -2162,6 +2177,7 @@ LExit:
2177 }
2178
2179 static HRESULT OnSessionEnd(
2180 + __in BURN_CACHE* pCache,
2181 __in BURN_PACKAGES* pPackages,
2182 __in BURN_REGISTRATION* pRegistration,
2183 __in BURN_VARIABLES* pVariables,
@@ -2190,7 +2206,7 @@ static HRESULT OnSessionEnd(
2206 ExitOnFailure(hr, "Failed to read dependency registration action.");
2207
2208 // suspend session in per-machine process
2193 - hr = RegistrationSessionEnd(pRegistration, pVariables, pPackages, (BURN_RESUME_MODE)dwResumeMode, (BOOTSTRAPPER_APPLY_RESTART)dwRestart, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType);
2209 + hr = RegistrationSessionEnd(pRegistration, pCache, pVariables, pPackages, (BURN_RESUME_MODE)dwResumeMode, (BOOTSTRAPPER_APPLY_RESTART)dwRestart, (BURN_DEPENDENCY_REGISTRATION_ACTION)dwDependencyRegistrationAction, (BOOTSTRAPPER_REGISTRATION_TYPE)dwRegistrationType);
2210 ExitOnFailure(hr, "Failed to suspend registration session.");
2211
2212 LExit:
@@ -2214,6 +2230,7 @@ LExit:
2230 }
2231
2232 static HRESULT OnCachePreparePackage(
2233 + __in BURN_CACHE* pCache,
2234 __in BURN_PACKAGES* pPackages,
2235 __in BYTE* pbData,
2236 __in SIZE_T cbData
@@ -2239,7 +2256,7 @@ static HRESULT OnCachePreparePackage(
2256 ExitOnRootFailure(hr, "Invalid data passed to cache prepare package.");
2257 }
2258
2242 - hr = CachePreparePackage(pPackage);
2259 + hr = CachePreparePackage(pCache, pPackage);
2260 ExitOnFailure(hr, "Failed to prepare cache package.");
2261
2262 LExit:
@@ -2250,6 +2267,7 @@ LExit:
2267
2268 static HRESULT OnCacheCompletePayload(
2269 __in HANDLE hPipe,
2270 + __in BURN_CACHE* pCache,
2271 __in BURN_PACKAGES* pPackages,
2272 __in BURN_PAYLOADS* pPayloads,
2273 __in BYTE* pbData,
@@ -2291,7 +2309,7 @@ static HRESULT OnCacheCompletePayload(
2309
2310 if (pPackage && pPayload) // complete payload.
2311 {
2294 - hr = CacheCompletePayload(pPackage->fPerMachine, pPayload, pPackage->sczCacheId, sczUnverifiedPath, fMove, BurnCacheMessageHandler, ElevatedProgressRoutine, hPipe);
2312 + hr = CacheCompletePayload(pCache, pPackage->fPerMachine, pPayload, pPackage->sczCacheId, sczUnverifiedPath, fMove, BurnCacheMessageHandler, ElevatedProgressRoutine, hPipe);
2313 ExitOnFailure(hr, "Failed to cache payload: %ls", pPayload->sczKey);
2314 }
2315 else
@@ -2364,10 +2382,10 @@ LExit:
2382 }
2383
2384 static void OnCacheCleanup(
2367 - __in_z LPCWSTR wzBundleId
2385 + __in BURN_CACHE* pCache
2386 )
2387 {
2370 - CacheCleanup(TRUE, wzBundleId);
2388 + CacheCleanup(TRUE, pCache);
2389 }
2390
2391 static HRESULT OnProcessDependentRegistration(
@@ -2405,6 +2423,7 @@ LExit:
2423
2424 static HRESULT OnExecuteExePackage(
2425 __in HANDLE hPipe,
2426 + __in BURN_CACHE* pCache,
2427 __in BURN_PACKAGES* pPackages,
2428 __in BURN_RELATED_BUNDLES* pRelatedBundles,
2429 __in BURN_VARIABLES* pVariables,
@@ -2464,7 +2483,7 @@ static HRESULT OnExecuteExePackage(
2483 }
2484
2485 // Execute EXE package.
2467 - hr = ExeEngineExecutePackage(&executeAction, pVariables, static_cast<BOOL>(dwRollback), GenericExecuteMessageHandler, hPipe, &exeRestart);
2486 + hr = ExeEngineExecutePackage(&executeAction, pCache, pVariables, static_cast<BOOL>(dwRollback), GenericExecuteMessageHandler, hPipe, &exeRestart);
2487 ExitOnFailure(hr, "Failed to execute EXE package.");
2488
2489 LExit:
@@ -2490,6 +2509,7 @@ LExit:
2509
2510 static HRESULT OnExecuteMsiPackage(
2511 __in HANDLE hPipe,
2512 + __in BURN_CACHE* pCache,
2513 __in BURN_PACKAGES* pPackages,
2514 __in BURN_VARIABLES* pVariables,
2515 __in BYTE* pbData,
@@ -2563,7 +2583,7 @@ static HRESULT OnExecuteMsiPackage(
2583 ExitOnFailure(hr, "Failed to read variables.");
2584
2585 // Execute MSI package.
2566 - hr = MsiEngineExecutePackage(hwndParent, &executeAction, pVariables, fRollback, MsiExecuteMessageHandler, hPipe, &msiRestart);
2586 + hr = MsiEngineExecutePackage(hwndParent, &executeAction, pCache, pVariables, fRollback, MsiExecuteMessageHandler, hPipe, &msiRestart);
2587 ExitOnFailure(hr, "Failed to execute MSI package.");
2588
2589 LExit:
@@ -2587,6 +2607,7 @@ LExit:
2607
2608 static HRESULT OnExecuteMspPackage(
2609 __in HANDLE hPipe,
2610 + __in BURN_CACHE* pCache,
2611 __in BURN_PACKAGES* pPackages,
2612 __in BURN_VARIABLES* pVariables,
2613 __in BYTE* pbData,
@@ -2658,7 +2679,7 @@ static HRESULT OnExecuteMspPackage(
2679 ExitOnFailure(hr, "Failed to read rollback flag.");
2680
2681 // Execute MSP package.
2661 - hr = MspEngineExecutePackage(hwndParent, &executeAction, pVariables, fRollback, MsiExecuteMessageHandler, hPipe, &restart);
2682 + hr = MspEngineExecutePackage(hwndParent, &executeAction, pCache, pVariables, fRollback, MsiExecuteMessageHandler, hPipe, &restart);
2683 ExitOnFailure(hr, "Failed to execute MSP package.");
2684
2685 LExit:
@@ -2682,6 +2703,7 @@ LExit:
2703
2704 static HRESULT OnExecuteMsuPackage(
2705 __in HANDLE hPipe,
2706 + __in BURN_CACHE* pCache,
2707 __in BURN_PACKAGES* pPackages,
2708 __in BURN_VARIABLES* pVariables,
2709 __in BYTE* pbData,
@@ -2718,7 +2740,7 @@ static HRESULT OnExecuteMsuPackage(
2740 ExitOnFailure(hr, "Failed to find package: %ls", sczPackage);
2741
2742 // execute MSU package
2721 - hr = MsuEngineExecutePackage(&executeAction, pVariables, static_cast<BOOL>(dwRollback), static_cast<BOOL>(dwStopWusaService), GenericExecuteMessageHandler, hPipe, &restart);
2743 + hr = MsuEngineExecutePackage(&executeAction, pCache, pVariables, static_cast<BOOL>(dwRollback), static_cast<BOOL>(dwStopWusaService), GenericExecuteMessageHandler, hPipe, &restart);
2744 ExitOnFailure(hr, "Failed to execute MSU package.");
2745
2746 LExit:
@@ -3051,6 +3073,7 @@ LExit:
3073 }
3074
3075 static HRESULT OnCleanPackage(
3076 + __in BURN_CACHE* pCache,
3077 __in BURN_PACKAGES* pPackages,
3078 __in BYTE* pbData,
3079 __in SIZE_T cbData
@@ -3069,7 +3092,7 @@ static HRESULT OnCleanPackage(
3092 ExitOnFailure(hr, "Failed to find package: %ls", sczPackage);
3093
3094 // Remove the package from the cache.
3072 - hr = CacheRemovePackage(TRUE, pPackage->sczId, pPackage->sczCacheId);
3095 + hr = CacheRemovePackage(pCache, TRUE, pPackage->sczId, pPackage->sczCacheId);
3096 ExitOnFailure(hr, "Failed to remove from cache package: %ls", pPackage->sczId);
3097
3098 LExit:
@@ -3080,6 +3103,7 @@ LExit:
3103 static HRESULT OnLaunchApprovedExe(
3104 __in HANDLE hPipe,
3105 __in BURN_APPROVED_EXES* pApprovedExes,
3106 + __in BURN_CACHE* pCache,
3107 __in BURN_VARIABLES* pVariables,
3108 __in BYTE* pbData,
3109 __in SIZE_T cbData
@@ -3124,7 +3148,7 @@ static HRESULT OnLaunchApprovedExe(
3148 hr = RegReadString(hKey, pApprovedExe->sczValueName, &pLaunchApprovedExe->sczExecutablePath);
3149 ExitOnFailure(hr, "Failed to read the value for the approved exe path.");
3150
3127 - hr = ApprovedExesVerifySecureLocation(pVariables, pLaunchApprovedExe);
3151 + hr = ApprovedExesVerifySecureLocation(pCache, pVariables, pLaunchApprovedExe);
3152 ExitOnFailure(hr, "Failed to verify the executable path is in a secure location: %ls", pLaunchApprovedExe->sczExecutablePath);
3153 if (S_FALSE == hr)
3154 {
src/burn/engine/elevation.h
+1
@@ -151,6 +151,7 @@ HRESULT ElevationChildPumpMessages(
151 __in HANDLE hPipe,
152 __in HANDLE hCachePipe,
153 __in BURN_APPROVED_EXES* pApprovedExes,
154 + __in BURN_CACHE* pCache,
155 __in BURN_CONTAINERS* pContainers,
156 __in BURN_PACKAGES* pPackages,
157 __in BURN_PAYLOADS* pPayloads,
src/burn/engine/engine.cpp
+11 -7
@@ -244,8 +244,8 @@ LExit:
244
245 UserExperienceRemove(&engineState.userExperience);
246
247 - CacheRemoveWorkingFolder(engineState.registration.sczId);
248 - CacheUninitialize();
247 + CacheRemoveWorkingFolder(&engineState.cache);
248 + CacheUninitialize(&engineState.cache);
249
250 // If this is a related bundle (but not an update) suppress restart and return the standard restart error code.
251 if (fRestart && BOOTSTRAPPER_RELATION_NONE != engineState.command.relationType && BOOTSTRAPPER_RELATION_UPDATE != engineState.command.relationType)
@@ -334,6 +334,9 @@ static HRESULT InitializeEngineState(
334 PipeConnectionInitialize(&pEngineState->companionConnection);
335 PipeConnectionInitialize(&pEngineState->embeddedConnection);
336
337 + // Retain whether bundle was initially run elevated.
338 + ProcElevated(::GetCurrentProcess(), &pEngineState->internalCommand.fInitiallyElevated);
339 +
340 // Parse command line.
341 hr = CoreParseCommandLine(pEngineState->argc, pEngineState->argv, &pEngineState->command, &pEngineState->companionConnection, &pEngineState->embeddedConnection, &pEngineState->mode, &pEngineState->automaticUpdates, &pEngineState->fDisableSystemRestore, &pEngineState->internalCommand.sczSourceProcessPath, &pEngineState->internalCommand.sczOriginalSource, &hSectionFile, &hSourceEngineFile, &pEngineState->fDisableUnelevate, &pEngineState->log.dwAttributes, &pEngineState->log.sczPath, &pEngineState->registration.sczActiveParent, &pEngineState->sczIgnoreDependencies, &pEngineState->registration.sczAncestors, &pEngineState->fInvalidCommandLine, &pEngineState->cUnknownArgs, &pEngineState->rgUnknownArgs);
342 ExitOnFailure(hr, "Fatal error while parsing command line.");
@@ -341,6 +344,9 @@ static HRESULT InitializeEngineState(
344 hr = SectionInitialize(&pEngineState->section, hSectionFile, hSourceEngineFile);
345 ExitOnFailure(hr, "Failed to initialize engine section.");
346
347 + hr = CacheInitialize(&pEngineState->cache, &pEngineState->internalCommand);
348 + ExitOnFailure(hr, "Failed to initialize internal cache functionality.");
349 +
350 LExit:
351 return hr;
352 }
@@ -421,8 +427,6 @@ static HRESULT RunUntrusted(
427 hr = PathForCurrentProcess(&sczCurrentProcessPath, NULL);
428 ExitOnFailure(hr, "Failed to get path for current process.");
429
424 - BOOL fRunningFromCache = CacheBundleRunningFromCache();
425 -
430 // If we're running from the package cache, we're in a secure
431 // folder (DLLs cannot be inserted here for hijacking purposes)
432 // so just launch the current process's path as the clean room
@@ -431,13 +435,13 @@ static HRESULT RunUntrusted(
435 // a secure folder) but it makes the code that only wants to run
436 // in clean room more complicated if we don't launch an explicit
437 // clean room process.
434 - if (fRunningFromCache)
438 + if (CacheBundleRunningFromCache(&pEngineState->cache))
439 {
440 wzCleanRoomBundlePath = sczCurrentProcessPath;
441 }
442 else
443 {
440 - hr = CacheBundleToCleanRoom(&pEngineState->section, &sczCachedCleanRoomBundlePath);
444 + hr = CacheBundleToCleanRoom(&pEngineState->cache, &pEngineState->section, &sczCachedCleanRoomBundlePath);
445 ExitOnFailure(hr, "Failed to cache to clean room.");
446
447 wzCleanRoomBundlePath = sczCachedCleanRoomBundlePath;
@@ -658,7 +662,7 @@ static HRESULT RunElevated(
662 SrpInitialize(TRUE);
663
664 // Pump messages from parent process.
661 - hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart);
665 + hr = ElevationChildPumpMessages(pEngineState->dwElevatedLoggingTlsId, pEngineState->companionConnection.hPipe, pEngineState->companionConnection.hCachePipe, &pEngineState->approvedExes, &pEngineState->cache, &pEngineState->containers, &pEngineState->packages, &pEngineState->payloads, &pEngineState->variables, &pEngineState->registration, &pEngineState->userExperience, &hLock, &fDisabledAutomaticUpdates, &pEngineState->userExperience.dwExitCode, &pEngineState->fRestart);
666 LogRedirect(NULL, NULL); // reset logging so the next failure gets written to "log buffer" for the failure log.
667 ExitOnFailure(hr, "Failed to pump messages from parent process.");
668
src/burn/engine/exeengine.cpp
+2 -1
@@ -342,6 +342,7 @@ LExit:
342
343 extern "C" HRESULT ExeEngineExecutePackage(
344 __in BURN_EXECUTE_ACTION* pExecuteAction,
345 + __in BURN_CACHE* pCache,
346 __in BURN_VARIABLES* pVariables,
347 __in BOOL fRollback,
348 __in PFN_GENERICMESSAGEHANDLER pfnGenericMessageHandler,
@@ -368,7 +369,7 @@ extern "C" HRESULT ExeEngineExecutePackage(
369 BURN_PAYLOAD* pPackagePayload = pPackage->payloads.rgItems[0].pPayload;
370
371 // get cached executable path
371 - hr = CacheGetCompletedPath(pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory);
372 + hr = CacheGetCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory);
373 ExitOnFailure(hr, "Failed to get cached path for package: %ls", pPackage->sczId);
374
375 // Best effort to set the execute package cache folder and action variables.
src/burn/engine/exeengine.h
+1
@@ -32,6 +32,7 @@ HRESULT ExeEnginePlanAddPackage(
32 );
33 HRESULT ExeEngineExecutePackage(
34 __in BURN_EXECUTE_ACTION* pExecuteAction,
35 + __in BURN_CACHE* pCache,
36 __in BURN_VARIABLES* pVariables,
37 __in BOOL fRollback,
38 __in PFN_GENERICMESSAGEHANDLER pfnGenericExecuteProgress,
src/burn/engine/manifest.cpp
+1 -1
@@ -133,7 +133,7 @@ static HRESULT ParseFromXml(
133 ExitOnFailure(hr, "Failed to parse searches.");
134
135 // parse registration
136 - hr = RegistrationParseFromXml(&pEngineState->registration, pixeBundle);
136 + hr = RegistrationParseFromXml(&pEngineState->registration, &pEngineState->cache, pixeBundle);
137 ExitOnFailure(hr, "Failed to parse registration.");
138
139 // parse update
src/burn/engine/msiengine.cpp
+7 -4
@@ -41,6 +41,7 @@ static HRESULT ConcatFeatureActionProperties(
41 __inout_z LPWSTR* psczArguments
42 );
43 static HRESULT ConcatPatchProperty(
44 + __in BURN_CACHE* pCache,
45 __in BURN_PACKAGE* pPackage,
46 __in BOOL fRollback,
47 __inout_z LPWSTR* psczArguments
@@ -1059,6 +1060,7 @@ LExit:
1060 extern "C" HRESULT MsiEngineExecutePackage(
1061 __in_opt HWND hwndParent,
1062 __in BURN_EXECUTE_ACTION* pExecuteAction,
1063 + __in BURN_CACHE* pCache,
1064 __in BURN_VARIABLES* pVariables,
1065 __in BOOL fRollback,
1066 __in PFN_MSIEXECUTEMESSAGEHANDLER pfnMessageHandler,
@@ -1119,7 +1121,7 @@ extern "C" HRESULT MsiEngineExecutePackage(
1121 if (BOOTSTRAPPER_ACTION_STATE_UNINSTALL != pExecuteAction->msiPackage.action)
1122 {
1123 // get cached MSI path
1122 - hr = CacheGetCompletedPath(pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory);
1124 + hr = CacheGetCompletedPath(pCache, pPackage->fPerMachine, pPackage->sczCacheId, &sczCachedDirectory);
1125 ExitOnFailure(hr, "Failed to get cached path for package: %ls", pPackage->sczId);
1126
1127 // Best effort to set the execute package cache folder variable.
@@ -1165,10 +1167,10 @@ extern "C" HRESULT MsiEngineExecutePackage(
1167 ExitOnFailure(hr, "Failed to add feature action properties to obfuscated argument string.");
1168
1169 // add slipstream patch properties
1168 - hr = ConcatPatchProperty(pPackage, fRollback, &sczProperties);
1170 + hr = ConcatPatchProperty(pCache, pPackage, fRollback, &sczProperties);
1171 ExitOnFailure(hr, "Failed to add patch properties to argument string.");
1172
1171 - hr = ConcatPatchProperty(pPackage, fRollback, &sczObfuscatedProperties);
1173 + hr = ConcatPatchProperty(pCache, pPackage, fRollback, &sczObfuscatedProperties);
1174 ExitOnFailure(hr, "Failed to add patch properties to obfuscated argument string.");
1175
1176 hr = MsiEngineConcatActionProperty(pExecuteAction->msiPackage.actionMsiProperty, &sczProperties);
@@ -1940,6 +1942,7 @@ LExit:
1942 }
1943
1944 static HRESULT ConcatPatchProperty(
1945 + __in BURN_CACHE* pCache,
1946 __in BURN_PACKAGE* pPackage,
1947 __in BOOL fRollback,
1948 __inout_z LPWSTR* psczArguments
@@ -1962,7 +1965,7 @@ static HRESULT ConcatPatchProperty(
1965
1966 if (BOOTSTRAPPER_ACTION_STATE_UNINSTALL < patchExecuteAction)
1967 {
1965 - hr = CacheGetCompletedPath(pMspPackage->fPerMachine, pMspPackage->sczCacheId, &sczCachedDirectory);
1968 + hr = CacheGetCompletedPath(pCache, pMspPackage->fPerMachine, pMspPackage->sczCacheId, &sczCachedDirectory);
1969 ExitOnFailure(hr, "Failed to get cached path for MSP package: %ls", pMspPackage->sczId);
1970
1971 hr = PathConcat(sczCachedDirectory, pMspPackagePayload->sczFilePath, &sczMspPath);
src/burn/engine/msiengine.h
+1
@@ -63,6 +63,7 @@ HRESULT MsiEngineRollbackTransaction(
63 HRESULT MsiEngineExecutePackage(
64 __in_opt HWND hwndParent,
65 __in BURN_EXECUTE_ACTION* pExecuteAction,
66 + __in BURN_CACHE* pCache,
67 __in BURN_VARIABLES* pVariables,
68 __in BOOL fRollback,
69 __in PFN_MSIEXECUTEMESSAGEHANDLER pfnMessageHandler,
src/burn/engine/mspengine.cpp
+2 -1
@@ -544,6 +544,7 @@ LExit:
544 extern "C" HRESULT MspEngineExecutePackage(
545 __in_opt HWND hwndParent,
546 __in BURN_EXECUTE_ACTION* pExecuteAction,
547 + __in BURN_CACHE* pCache,
548 __in BURN_VARIABLES* pVariables,
549 __in BOOL fRollback,
550 __in PFN_MSIEXECUTEMESSAGEHANDLER pfnMessageHandler,
@@ -574,7 +575,7 @@ extern "C" HRESULT MspEngineExecutePackage(
575
576 if (BOOTSTRAPPER_ACTION_STATE_INSTALL == pExecuteAction->mspTarget.action)
577 {
577 - hr = CacheGetCompletedPath(pMspPackage->fPerMachine, pMspPackage->sczCacheId, &sczCachedDirectory);
578 + hr = CacheGetCompletedPath(pCache, pMspPackage->fPerMachine, pMspPackage->sczCacheId, &sczCachedDirectory);
579 ExitOnFailure(hr, "Failed to get cached path for MSP package: %ls", pMspPackage->sczId);
580
581 // TODO: Figure out if this makes sense -- the variable is set to the last patch's path only
src/burn/engine/mspengine.h
+1
@@ -62,6 +62,7 @@ HRESULT MspEnginePlanAddPackage(
62 HRESULT MspEngineExecutePackage(
63 __in_opt HWND hwndParent,
64 __in BURN_EXECUTE_ACTION* pExecuteAction,
65 + __in BURN_CACHE* pCache,
66 __in BURN_VARIABLES* pVariables,
67 __in BOOL fRollback,
68 __in PFN_MSIEXECUTEMESSAGEHANDLER pfnMessageHandler,
src/burn/engine/msuengine.cpp
+2 -1
@@ -233,6 +233,7 @@ LExit:
233
234 extern "C" HRESULT MsuEngineExecutePackage(
235 __in BURN_EXECUTE_ACTION* pExecuteAction,
236 + __in BURN_CACHE* pCache,
237 __in BURN_VARIABLES* pVariables,
238 __in BOOL fRollback,
239 __in BOOL fStopWusaService,
@@ -289,7 +290,7 @@ extern "C" HRESULT MsuEngineExecutePackage(
290 {
291 case BOOTSTRAPPER_ACTION_STATE_INSTALL:
292 // get cached MSU path
292 - hr = CacheGetCompletedPath(TRUE, pPackage->sczCacheId, &sczCachedDirectory);
293 + hr = CacheGetCompletedPath(pCache, TRUE, pPackage->sczCacheId, &sczCachedDirectory);
294 ExitOnFailure(hr, "Failed to get cached path for package: %ls", pPackage->sczId);
295
296 // Best effort to set the execute package cache folder variable.
src/burn/engine/msuengine.h
+1
@@ -31,6 +31,7 @@ HRESULT MsuEnginePlanAddPackage(
31 );
32 HRESULT MsuEngineExecutePackage(
33 __in BURN_EXECUTE_ACTION* pExecuteAction,
34 + __in BURN_CACHE* pCache,
35 __in BURN_VARIABLES* pVariables,
36 __in BOOL fRollback,
37 __in BOOL fStopWusaService,
src/burn/engine/plan.cpp
+4 -4
@@ -409,7 +409,7 @@ extern "C" HRESULT PlanLayoutBundle(
409 hr = StrAllocString(&pCacheAction->bundleLayout.sczExecutableName, wzExecutableName, 0);
410 ExitOnFailure(hr, "Failed to to copy executable name for bundle.");
411
412 - hr = CacheCalculateBundleLayoutWorkingPath(pPlan->wzBundleId, &pCacheAction->bundleLayout.sczUnverifiedPath);
412 + hr = CacheCalculateBundleLayoutWorkingPath(pPlan->pCache, pPlan->wzBundleId, &pCacheAction->bundleLayout.sczUnverifiedPath);
413 ExitOnFailure(hr, "Failed to calculate bundle layout working path.");
414
415 pCacheAction->bundleLayout.qwBundleSize = qwBundleSize;
@@ -526,7 +526,7 @@ extern "C" HRESULT PlanRegistration(
526 pPlan->fIgnoreAllDependents = pRegistration->fIgnoreAllDependents;
527
528 // Ensure the bundle is cached if not running from the cache.
529 - if (!CacheBundleRunningFromCache())
529 + if (!CacheBundleRunningFromCache(pPlan->pCache))
530 {
531 pPlan->dwRegistrationOperations |= BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE;
532 }
@@ -1021,7 +1021,7 @@ extern "C" HRESULT PlanLayoutContainer(
1021 }
1022 else
1023 {
1024 - hr = CacheCalculateContainerWorkingPath(pPlan->wzBundleId, pContainer, &pContainer->sczUnverifiedPath);
1024 + hr = CacheCalculateContainerWorkingPath(pPlan->pCache, pContainer, &pContainer->sczUnverifiedPath);
1025 ExitOnFailure(hr, "Failed to calculate unverified path for container.");
1026 }
1027 }
@@ -2235,7 +2235,7 @@ static HRESULT ProcessPayloadGroup(
2235
2236 if (!pPayload->sczUnverifiedPath)
2237 {
2238 - hr = CacheCalculatePayloadWorkingPath(pPlan->wzBundleId, pPayload, &pPayload->sczUnverifiedPath);
2238 + hr = CacheCalculatePayloadWorkingPath(pPlan->pCache, pPayload, &pPayload->sczUnverifiedPath);
2239 ExitOnFailure(hr, "Failed to calculate unverified path for payload.");
2240 }
2241 }
src/burn/engine/plan.h
+2 -1
@@ -229,7 +229,8 @@ typedef struct _BURN_CLEAN_ACTION
229 typedef struct _BURN_PLAN
230 {
231 BOOTSTRAPPER_ACTION action;
232 - BURN_PAYLOADS* pPayloads; // points directly into parent the ENGINE_STATE.
232 + BURN_CACHE* pCache;
233 + BURN_PAYLOADS* pPayloads;
234 LPWSTR wzBundleId; // points directly into parent the ENGINE_STATE.
235 LPWSTR wzBundleProviderKey; // points directly into parent the ENGINE_STATE.
236 BOOL fPerMachine;
src/burn/engine/precomp.h
+1 -1
@@ -82,8 +82,8 @@
82 #include "plan.h"
83 #include "logging.h"
84 #include "pipe.h"
85 -#include "core.h"
85 #include "cache.h"
86 +#include "core.h"
87 #include "apply.h"
88 #include "exeengine.h"
89 #include "msiengine.h"
src/burn/engine/registration.cpp
+11 -6
@@ -42,7 +42,8 @@ static HRESULT ParseSoftwareTagsFromXml(
42 __out DWORD* pcSoftwareTags
43 );
44 static HRESULT SetPaths(
45 - __in BURN_REGISTRATION* pRegistration
45 + __in BURN_REGISTRATION* pRegistration,
46 + __in BURN_CACHE* pCache
47 );
48 static HRESULT GetBundleManufacturer(
49 __in BURN_REGISTRATION* pRegistration,
@@ -120,6 +121,7 @@ static BOOL IsRegistryRebootPending();
121 *******************************************************************/
122 extern "C" HRESULT RegistrationParseFromXml(
123 __in BURN_REGISTRATION* pRegistration,
124 + __in BURN_CACHE* pCache,
125 __in IXMLDOMNode* pixnBundle
126 )
127 {
@@ -335,7 +337,7 @@ extern "C" HRESULT RegistrationParseFromXml(
337 ExitOnFailure(hr, "Failed to get @Classification.");
338 }
339
338 - hr = SetPaths(pRegistration);
340 + hr = SetPaths(pRegistration, pCache);
341 ExitOnFailure(hr, "Failed to set registration paths.");
342
343 LExit:
@@ -614,6 +616,7 @@ LExit:
616 extern "C" HRESULT RegistrationSessionBegin(
617 __in_z LPCWSTR wzEngineWorkingPath,
618 __in BURN_REGISTRATION* pRegistration,
619 + __in BURN_CACHE* pCache,
620 __in BURN_VARIABLES* pVariables,
621 __in DWORD dwRegistrationOptions,
622 __in BURN_DEPENDENCY_REGISTRATION_ACTION dependencyRegistrationAction,
@@ -633,7 +636,7 @@ extern "C" HRESULT RegistrationSessionBegin(
636 // Cache bundle executable.
637 if (dwRegistrationOptions & BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE)
638 {
636 - hr = CacheCompleteBundle(pRegistration->fPerMachine, pRegistration->sczExecutableName, pRegistration->sczId, wzEngineWorkingPath
639 + hr = CacheCompleteBundle(pCache, pRegistration->fPerMachine, pRegistration->sczExecutableName, pRegistration->sczId, wzEngineWorkingPath
640 #ifdef DEBUG
641 , pRegistration->sczCacheExecutablePath
642 #endif
@@ -900,6 +903,7 @@ LExit:
903 *******************************************************************/
904 extern "C" HRESULT RegistrationSessionEnd(
905 __in BURN_REGISTRATION* pRegistration,
906 + __in BURN_CACHE* pCache,
907 __in BURN_VARIABLES* pVariables,
908 __in BURN_PACKAGES* pPackages,
909 __in BURN_RESUME_MODE resumeMode,
@@ -964,7 +968,7 @@ extern "C" HRESULT RegistrationSessionEnd(
968 ExitOnFailure(hr, "Failed to delete registration key: %ls", pRegistration->sczRegistrationKey);
969 }
970
967 - CacheRemoveBundle(pRegistration->fPerMachine, pRegistration->sczId);
971 + CacheRemoveBundle(pCache, pRegistration->fPerMachine, pRegistration->sczId);
972 }
973 else // the mode needs to be updated so open the registration key.
974 {
@@ -1213,7 +1217,8 @@ LExit:
1217 }
1218
1219 static HRESULT SetPaths(
1216 - __in BURN_REGISTRATION* pRegistration
1220 + __in BURN_REGISTRATION* pRegistration,
1221 + __in BURN_CACHE* pCache
1222 )
1223 {
1224 HRESULT hr = S_OK;
@@ -1227,7 +1232,7 @@ static HRESULT SetPaths(
1232 ExitOnFailure(hr, "Failed to build uninstall registry key path.");
1233
1234 // build cache directory
1230 - hr = CacheGetCompletedPath(pRegistration->fPerMachine, pRegistration->sczId, &sczCacheDirectory);
1235 + hr = CacheGetCompletedPath(pCache, pRegistration->fPerMachine, pRegistration->sczId, &sczCacheDirectory);
1236 ExitOnFailure(hr, "Failed to build cache directory.");
1237
1238 // build cached executable path
src/burn/engine/registration.h
+3
@@ -166,6 +166,7 @@ typedef struct _BURN_REGISTRATION
166
167 HRESULT RegistrationParseFromXml(
168 __in BURN_REGISTRATION* pRegistration,
169 + __in BURN_CACHE* pCache,
170 __in IXMLDOMNode* pixnBundle
171 );
172 void RegistrationUninitialize(
@@ -188,6 +189,7 @@ HRESULT RegistrationDetectRelatedBundles(
189 HRESULT RegistrationSessionBegin(
190 __in_z LPCWSTR wzEngineWorkingPath,
191 __in BURN_REGISTRATION* pRegistration,
192 + __in BURN_CACHE* pCache,
193 __in BURN_VARIABLES* pVariables,
194 __in DWORD dwRegistrationOptions,
195 __in BURN_DEPENDENCY_REGISTRATION_ACTION dependencyRegistrationAction,
@@ -201,6 +203,7 @@ HRESULT RegistrationSessionResume(
203 );
204 HRESULT RegistrationSessionEnd(
205 __in BURN_REGISTRATION* pRegistration,
206 + __in BURN_CACHE* pCache,
207 __in BURN_VARIABLES* pVariables,
208 __in BURN_PACKAGES* pPackages,
209 __in BURN_RESUME_MODE resumeMode,
src/burn/engine/uithread.cpp
+6 -6
@@ -16,7 +16,7 @@ struct UITHREAD_CONTEXT
16
17 struct UITHREAD_INFO
18 {
19 - BOOL fElevated;
19 + BOOL fElevatedEngine;
20 BURN_USER_EXPERIENCE* pUserExperience;
21 };
22
@@ -105,10 +105,10 @@ static DWORD WINAPI ThreadProc(
105 MSG msg = { };
106
107 BURN_ENGINE_STATE* pEngineState = pContext->pEngineState;
108 - BOOL fElevated = BURN_MODE_ELEVATED == pContext->pEngineState->mode;
108 + BOOL fElevatedEngine = BURN_MODE_ELEVATED == pContext->pEngineState->mode;
109
110 // If elevated, set up the thread local storage to store the correct pipe to communicate logging.
111 - if (fElevated)
111 + if (fElevatedEngine)
112 {
113 Assert(TLS_OUT_OF_INDEXES != pEngineState->dwElevatedLoggingTlsId);
114
@@ -130,7 +130,7 @@ static DWORD WINAPI ThreadProc(
130
131 fRegistered = TRUE;
132
133 - info.fElevated = fElevated;
133 + info.fElevatedEngine = fElevatedEngine;
134 info.pUserExperience = &pEngineState->userExperience;
135
136 // Create the window to handle reboots without activating it.
@@ -199,7 +199,7 @@ static LRESULT CALLBACK WndProc(
199
200 // Always block shutdown in the elevated process, but ask the BA in the non-elevated.
201 UITHREAD_INFO* pInfo = reinterpret_cast<UITHREAD_INFO*>(::GetWindowLongPtrW(hWnd, GWLP_USERDATA));
202 - if (!pInfo->fElevated)
202 + if (!pInfo->fElevatedEngine)
203 {
204 // TODO: instead of recommending canceling all non-critical shutdowns, maybe we should only recommend cancel
205 // when the engine is doing work?
@@ -209,7 +209,7 @@ static LRESULT CALLBACK WndProc(
209 }
210
211 fRet = !fCancel;
212 - LogId(REPORT_STANDARD, MSG_SYSTEM_SHUTDOWN, LoggingBoolToString(fCritical), LoggingBoolToString(pInfo->fElevated), LoggingBoolToString(fRet));
212 + LogId(REPORT_STANDARD, MSG_SYSTEM_SHUTDOWN, LoggingBoolToString(fCritical), LoggingBoolToString(pInfo->fElevatedEngine), LoggingBoolToString(fRet));
213 return fRet;
214 }
215
src/burn/engine/userexperience.cpp
+2 -2
@@ -161,14 +161,14 @@ extern "C" HRESULT UserExperienceUnload(
161 }
162
163 extern "C" HRESULT UserExperienceEnsureWorkingFolder(
164 - __in LPCWSTR wzBundleId,
164 + __in BURN_CACHE* pCache,
165 __deref_out_z LPWSTR* psczUserExperienceWorkingFolder
166 )
167 {
168 HRESULT hr = S_OK;
169 LPWSTR sczWorkingFolder = NULL;
170
171 - hr = CacheEnsureWorkingFolder(wzBundleId, &sczWorkingFolder);
171 + hr = CacheEnsureWorkingFolder(pCache, &sczWorkingFolder);
172 ExitOnFailure(hr, "Failed to create working folder.");
173
174 hr = StrAllocFormatted(psczUserExperienceWorkingFolder, L"%ls%ls\\", sczWorkingFolder, L".ba");
src/burn/engine/userexperience.h
+1 -3
@@ -15,8 +15,6 @@ const DWORD MB_RETRYTRYAGAIN = 0xF;
15
16 // structs
17
18 -typedef struct _BOOTSTRAPPER_ENGINE_CONTEXT BOOTSTRAPPER_ENGINE_CONTEXT; // forward declare
19 -
18 typedef struct _BURN_USER_EXPERIENCE
19 {
20 BURN_PAYLOADS payloads;
@@ -66,7 +64,7 @@ HRESULT UserExperienceUnload(
64 __in BURN_USER_EXPERIENCE* pUserExperience
65 );
66 HRESULT UserExperienceEnsureWorkingFolder(
69 - __in LPCWSTR wzBundleId,
67 + __in BURN_CACHE* pCache,
68 __deref_out_z LPWSTR* psczUserExperienceWorkingFolder
69 );
70 HRESULT UserExperienceRemove(
src/burn/test/BurnUnitTest/CacheTest.cpp
+6 -1
@@ -48,6 +48,8 @@ namespace Bootstrapper
48 void CacheSignatureTest()
49 {
50 HRESULT hr = S_OK;
51 + BURN_CACHE cache = { };
52 + BURN_ENGINE_COMMAND internalCommand = { };
53 BURN_PACKAGE package = { };
54 BURN_PAYLOAD payload = { };
55 LPWSTR sczPayloadPath = NULL;
@@ -74,7 +76,10 @@ namespace Bootstrapper
76 payload.qwFileSize = 27;
77 payload.verification = BURN_PAYLOAD_VERIFICATION_HASH;
78
77 - hr = CacheCompletePayload(package.fPerMachine, &payload, package.sczCacheId, sczPayloadPath, FALSE, CacheTestEventRoutine, CacheTestProgressRoutine, &context);
79 + hr = CacheInitialize(&cache, &internalCommand);
80 + TestThrowOnFailure(hr, L"Failed initialize cache.");
81 +
82 + hr = CacheCompletePayload(&cache, package.fPerMachine, &payload, package.sczCacheId, sczPayloadPath, FALSE, CacheTestEventRoutine, CacheTestProgressRoutine, &context);
83 Assert::Equal(S_OK, hr);
84 }
85 finally
src/burn/test/BurnUnitTest/ManifestTest.cpp
+3
@@ -40,6 +40,9 @@ namespace Bootstrapper
40 " <CommandLine Variables='upperCase' />"
41 "</Bundle>";
42
43 + hr = CacheInitialize(&engineState.cache, &engineState.internalCommand);
44 + TestThrowOnFailure(hr, L"Failed initialize cache.");
45 +
46 hr = VariableInitialize(&engineState.variables);
47 TestThrowOnFailure(hr, L"Failed to initialize variables.");
48
src/burn/test/BurnUnitTest/PlanTest.cpp
+6
@@ -925,6 +925,9 @@ namespace Bootstrapper
925
926 ::InitializeCriticalSection(&pEngineState->userExperience.csEngineActive);
927
928 + hr = CacheInitialize(&pEngineState->cache, &pEngineState->internalCommand);
929 + NativeAssert::Succeeded(hr, "Failed to initialize cache.");
930 +
931 hr = VariableInitialize(&pEngineState->variables);
932 NativeAssert::Succeeded(hr, "Failed to initialize variables.");
933
@@ -948,6 +951,9 @@ namespace Bootstrapper
951 hr = CoreInitializeConstants(pEngineState);
952 NativeAssert::Succeeded(hr, "Failed to initialize core constants");
953
954 + hr = CacheInitializeSources(&pEngineState->cache, &pEngineState->registration, &pEngineState->variables, &pEngineState->internalCommand);
955 + NativeAssert::Succeeded(hr, "Failed to initialize cache sources.");
956 +
957 pEngineState->userExperience.pfnBAProc = PlanTestBAProc;
958 }
959
src/burn/test/BurnUnitTest/RegistrationTest.cpp
+54 -24
@@ -75,6 +75,8 @@ namespace Bootstrapper
75 BURN_REGISTRATION registration = { };
76 BURN_LOGGING logging = { };
77 BURN_PACKAGES packages = { };
78 + BURN_CACHE cache = { };
79 + BURN_ENGINE_COMMAND internalCommand = { };
80 String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
81
82 try
@@ -99,13 +101,16 @@ namespace Bootstrapper
101 // load XML document
102 LoadBundleXmlHelper(wzDocument, &pixeBundle);
103
104 + hr = CacheInitialize(&cache, &internalCommand);
105 + TestThrowOnFailure(hr, L"Failed initialize cache.");
106 +
107 hr = VariableInitialize(&variables);
108 TestThrowOnFailure(hr, L"Failed to initialize variables.");
109
110 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
111 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
112
108 - hr = RegistrationParseFromXml(&registration, pixeBundle);
113 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
114 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
115
116 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -115,7 +120,7 @@ namespace Bootstrapper
120 TestThrowOnFailure(hr, L"Failed to get current process path.");
121
122 // write registration
118 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE | BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
123 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_CACHE_BUNDLE | BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
124 TestThrowOnFailure(hr, L"Failed to register bundle.");
125
126 // verify that registration was created
@@ -126,7 +131,7 @@ namespace Bootstrapper
131 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)(Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr)));
132
133 // end session
129 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
134 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
135 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
136
137 // verify that registration was removed
@@ -165,6 +170,8 @@ namespace Bootstrapper
170 BURN_REGISTRATION registration = { };
171 BURN_LOGGING logging = { };
172 BURN_PACKAGES packages = { };
173 + BURN_CACHE cache = { };
174 + BURN_ENGINE_COMMAND internalCommand = { };
175 String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
176 try
177 {
@@ -188,13 +195,16 @@ namespace Bootstrapper
195 // load XML document
196 LoadBundleXmlHelper(wzDocument, &pixeBundle);
197
198 + hr = CacheInitialize(&cache, &internalCommand);
199 + TestThrowOnFailure(hr, L"Failed initialize cache.");
200 +
201 hr = VariableInitialize(&variables);
202 TestThrowOnFailure(hr, L"Failed to initialize variables.");
203
204 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
205 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
206
197 - hr = RegistrationParseFromXml(&registration, pixeBundle);
207 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
208 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
209
210 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -208,7 +218,7 @@ namespace Bootstrapper
218 //
219
220 // write registration
211 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
221 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
222 TestThrowOnFailure(hr, L"Failed to register bundle.");
223
224 // verify that registration was created
@@ -217,7 +227,7 @@ namespace Bootstrapper
227 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
228
229 // complete registration
220 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
230 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
231 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
232
233 // verify that registration was updated
@@ -230,7 +240,7 @@ namespace Bootstrapper
240 //
241
242 // write registration
233 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
243 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
244 TestThrowOnFailure(hr, L"Failed to register bundle.");
245
246 // verify that registration was updated
@@ -239,7 +249,7 @@ namespace Bootstrapper
249 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
250
251 // delete registration
242 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
252 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
253 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
254
255 // verify that registration was removed
@@ -277,6 +287,8 @@ namespace Bootstrapper
287 BURN_REGISTRATION registration = { };
288 BURN_LOGGING logging = { };
289 BURN_PACKAGES packages = { };
290 + BURN_CACHE cache = { };
291 + BURN_ENGINE_COMMAND internalCommand = { };
292 String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
293 try
294 {
@@ -300,13 +312,16 @@ namespace Bootstrapper
312 // load XML document
313 LoadBundleXmlHelper(wzDocument, &pixeBundle);
314
315 + hr = CacheInitialize(&cache, &internalCommand);
316 + TestThrowOnFailure(hr, L"Failed initialize cache.");
317 +
318 hr = VariableInitialize(&variables);
319 TestThrowOnFailure(hr, L"Failed to initialize variables.");
320
321 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
322 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
323
309 - hr = RegistrationParseFromXml(&registration, pixeBundle);
324 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
325 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
326
327 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -320,7 +335,7 @@ namespace Bootstrapper
335 //
336
337 // write registration
323 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
338 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
339 TestThrowOnFailure(hr, L"Failed to register bundle.");
340
341 // verify that registration was created
@@ -328,7 +343,7 @@ namespace Bootstrapper
343 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
344
345 // complete registration
331 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_REQUIRED, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
346 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_REQUIRED, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
347 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
348
349 // verify that registration variables were updated
@@ -349,7 +364,7 @@ namespace Bootstrapper
364 //
365
366 // delete registration
352 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
367 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
368 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
369
370 // verify that registration was removed
@@ -387,6 +402,8 @@ namespace Bootstrapper
402 BURN_REGISTRATION registration = { };
403 BURN_LOGGING logging = { };
404 BURN_PACKAGES packages = { };
405 + BURN_CACHE cache = { };
406 + BURN_ENGINE_COMMAND internalCommand = { };
407 String^ cacheDirectory = Path::Combine(Path::Combine(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), gcnew String(L"Package Cache")), gcnew String(TEST_BUNDLE_ID));
408 try
409 {
@@ -412,13 +429,16 @@ namespace Bootstrapper
429 // load XML document
430 LoadBundleXmlHelper(wzDocument, &pixeBundle);
431
432 + hr = CacheInitialize(&cache, &internalCommand);
433 + TestThrowOnFailure(hr, L"Failed initialize cache.");
434 +
435 hr = VariableInitialize(&variables);
436 TestThrowOnFailure(hr, L"Failed to initialize variables.");
437
438 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
439 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
440
421 - hr = RegistrationParseFromXml(&registration, pixeBundle);
441 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
442 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
443
444 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -432,7 +452,7 @@ namespace Bootstrapper
452 //
453
454 // write registration
435 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
455 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
456 TestThrowOnFailure(hr, L"Failed to register bundle.");
457
458 // verify that registration was created
@@ -440,7 +460,7 @@ namespace Bootstrapper
460 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
461
462 // finish registration
443 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
463 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_ARP, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_FULL);
464 TestThrowOnFailure(hr, L"Failed to register bundle.");
465
466 // verify that registration was updated
@@ -465,7 +485,7 @@ namespace Bootstrapper
485 //
486
487 // write registration
468 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
488 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
489 TestThrowOnFailure(hr, L"Failed to register bundle.");
490
491 // verify that registration was updated
@@ -473,7 +493,7 @@ namespace Bootstrapper
493 Assert::Equal<String^>(String::Concat(L"\"", Path::Combine(cacheDirectory, gcnew String(L"setup.exe")), L"\" /burn.runonce"), (String^)Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
494
495 // delete registration
476 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
496 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
497 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
498
499 // verify that registration was removed
@@ -514,6 +534,8 @@ namespace Bootstrapper
534 BURN_REGISTRATION registration = { };
535 BURN_LOGGING logging = { };
536 BURN_PACKAGES packages = { };
537 + BURN_CACHE cache = { };
538 + BURN_ENGINE_COMMAND internalCommand = { };
539 BYTE* pbBuffer = NULL;
540 SIZE_T cbBuffer = 0;
541
@@ -546,6 +568,9 @@ namespace Bootstrapper
568 // load XML document
569 LoadBundleXmlHelper(wzDocument, &pixeBundle);
570
571 + hr = CacheInitialize(&cache, &internalCommand);
572 + TestThrowOnFailure(hr, L"Failed initialize cache.");
573 +
574 hr = VariableInitialize(&variables);
575 TestThrowOnFailure(hr, L"Failed to initialize variables.");
576
@@ -555,7 +580,7 @@ namespace Bootstrapper
580 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
581 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
582
558 - hr = RegistrationParseFromXml(&registration, pixeBundle);
583 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
584 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
585
586 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -565,7 +590,7 @@ namespace Bootstrapper
590 TestThrowOnFailure(hr, L"Failed to get current process path.");
591
592 // begin session
568 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
593 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
594 TestThrowOnFailure(hr, L"Failed to register bundle.");
595
596 VariableSetNumericHelper(&variables, L"MyBurnVariable1", 42);
@@ -608,7 +633,7 @@ namespace Bootstrapper
633 NativeAssert::StringEqual(L"42", sczValue);
634
635 // end session
611 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
636 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
637 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
638 }
639 finally
@@ -643,6 +668,8 @@ namespace Bootstrapper
668 BURN_REGISTRATION registration = { };
669 BURN_LOGGING logging = { };
670 BURN_PACKAGES packages = { };
671 + BURN_CACHE cache = { };
672 + BURN_ENGINE_COMMAND internalCommand = { };
673 BOOTSTRAPPER_RESUME_TYPE resumeType = BOOTSTRAPPER_RESUME_TYPE_NONE;
674 BYTE* pbBuffer = NULL;
675 SIZE_T cbBuffer = 0;
@@ -674,6 +701,9 @@ namespace Bootstrapper
701 // load XML document
702 LoadBundleXmlHelper(wzDocument, &pixeBundle);
703
704 + hr = CacheInitialize(&cache, &internalCommand);
705 + TestThrowOnFailure(hr, L"Failed initialize cache.");
706 +
707 hr = VariableInitialize(&variables);
708 TestThrowOnFailure(hr, L"Failed to initialize variables.");
709
@@ -683,7 +713,7 @@ namespace Bootstrapper
713 hr = UserExperienceParseFromXml(&userExperience, pixeBundle);
714 TestThrowOnFailure(hr, L"Failed to parse UX from XML.");
715
686 - hr = RegistrationParseFromXml(&registration, pixeBundle);
716 + hr = RegistrationParseFromXml(&registration, &cache, pixeBundle);
717 TestThrowOnFailure(hr, L"Failed to parse registration from XML.");
718
719 hr = PlanSetResumeCommand(&registration, BOOTSTRAPPER_ACTION_INSTALL, &command, &logging);
@@ -699,7 +729,7 @@ namespace Bootstrapper
729 Assert::Equal((int)BOOTSTRAPPER_RESUME_TYPE_NONE, (int)resumeType);
730
731 // begin session
702 - hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
732 + hr = RegistrationSessionBegin(sczCurrentProcess, &registration, &cache, &variables, BURN_REGISTRATION_ACTION_OPERATIONS_WRITE_REGISTRATION, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, 0, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
733 TestThrowOnFailure(hr, L"Failed to register bundle.");
734
735 VariableSetNumericHelper(&variables, L"MyBurnVariable1", 42);
@@ -738,7 +768,7 @@ namespace Bootstrapper
768 Assert::Equal((int)BOOTSTRAPPER_RESUME_TYPE_INTERRUPTED, (int)resumeType);
769
770 // suspend session
741 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_SUSPEND, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
771 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_SUSPEND, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_REGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_INPROGRESS);
772 TestThrowOnFailure(hr, L"Failed to suspend session.");
773
774 // verify that run key was removed
@@ -765,7 +795,7 @@ namespace Bootstrapper
795 Assert::NotEqual((Object^)nullptr, Registry::GetValue(gcnew String(TEST_RUN_KEY), gcnew String(TEST_BUNDLE_ID), nullptr));
796
797 // end session
768 - hr = RegistrationSessionEnd(&registration, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
798 + hr = RegistrationSessionEnd(&registration, &cache, &variables, &packages, BURN_RESUME_MODE_NONE, BOOTSTRAPPER_APPLY_RESTART_NONE, BURN_DEPENDENCY_REGISTRATION_ACTION_UNREGISTER, BOOTSTRAPPER_REGISTRATION_TYPE_NONE);
799 TestThrowOnFailure(hr, L"Failed to unregister bundle.");
800
801 // read resume type after session
src/burn/test/BurnUnitTest/precomp.h
+1 -1
@@ -56,8 +56,8 @@
56 #include "plan.h"
57 #include "pipe.h"
58 #include "logging.h"
59 -#include "core.h"
59 #include "cache.h"
60 +#include "core.h"
61 #include "apply.h"
62 #include "exeengine.h"
63 #include "msiengine.h"