aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-04-19 17:11:46 -0500
committerSean Hall <r.sean.hall@gmail.com>2021-04-19 23:12:55 -0500
commit61a8d39f689222faa677e4bd79475cd77795c57a (patch)
tree951c72ede571b23a1b1513136c861066ab8d3313
parent707e77212e105cd7fa8a74baca6efa3ae3e6d6b3 (diff)
downloadwix-61a8d39f689222faa677e4bd79475cd77795c57a.tar.gz
wix-61a8d39f689222faa677e4bd79475cd77795c57a.tar.bz2
wix-61a8d39f689222faa677e4bd79475cd77795c57a.zip
Allow setting source from OnCacheAcquireResolving.
-rw-r--r--src/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h18
-rw-r--r--src/engine/apply.cpp82
-rw-r--r--src/engine/cache.cpp11
-rw-r--r--src/engine/cache.h3
-rw-r--r--src/engine/userexperience.cpp17
-rw-r--r--src/engine/userexperience.h4
6 files changed, 92 insertions, 43 deletions
diff --git a/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h b/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h
index d8994c26..603df890 100644
--- a/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h
+++ b/src/WixToolset.BootstrapperCore.Native/inc/BootstrapperApplication.h
@@ -64,6 +64,20 @@ enum BOOTSTRAPPER_CACHE_OPERATION
64 BOOTSTRAPPER_CACHE_OPERATION_EXTRACT, 64 BOOTSTRAPPER_CACHE_OPERATION_EXTRACT,
65}; 65};
66 66
67enum BOOTSTRAPPER_CACHE_RESOLVE_OPERATION
68{
69 // There is no source available.
70 BOOTSTRAPPER_CACHE_RESOLVE_NONE,
71 // Copy the payload or container from the chosen local source.
72 BOOTSTRAPPER_CACHE_RESOLVE_LOCAL,
73 // Download the payload or container from the download URL.
74 BOOTSTRAPPER_CACHE_RESOLVE_DOWNLOAD,
75 // Extract the payload from the container.
76 BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER,
77 // Look again for the payload or container locally.
78 BOOTSTRAPPER_CACHE_RESOLVE_RETRY,
79};
80
67enum BOOTSTRAPPER_CACHE_VERIFY_STEP 81enum BOOTSTRAPPER_CACHE_VERIFY_STEP
68{ 82{
69 BOOTSTRAPPER_CACHE_VERIFY_STEP_STAGE, 83 BOOTSTRAPPER_CACHE_VERIFY_STEP_STAGE,
@@ -379,14 +393,14 @@ struct BA_ONCACHEACQUIRERESOLVING_ARGS
379 DWORD dwRecommendedSearchPath; 393 DWORD dwRecommendedSearchPath;
380 LPCWSTR wzDownloadUrl; 394 LPCWSTR wzDownloadUrl;
381 LPCWSTR wzPayloadContainerId; 395 LPCWSTR wzPayloadContainerId;
382 BOOTSTRAPPER_CACHE_OPERATION recommendation; 396 BOOTSTRAPPER_CACHE_RESOLVE_OPERATION recommendation;
383}; 397};
384 398
385struct BA_ONCACHEACQUIRERESOLVING_RESULTS 399struct BA_ONCACHEACQUIRERESOLVING_RESULTS
386{ 400{
387 DWORD cbSize; 401 DWORD cbSize;
388 DWORD dwChosenSearchPath; 402 DWORD dwChosenSearchPath;
389 BOOTSTRAPPER_CACHE_OPERATION action; 403 BOOTSTRAPPER_CACHE_RESOLVE_OPERATION action;
390 BOOL fCancel; 404 BOOL fCancel;
391}; 405};
392 406
diff --git a/src/engine/apply.cpp b/src/engine/apply.cpp
index 1bc01d44..9cba0483 100644
--- a/src/engine/apply.cpp
+++ b/src/engine/apply.cpp
@@ -1390,6 +1390,7 @@ static HRESULT AcquireContainerOrPayload(
1390 LPCWSTR wzRelativePath = pContainer ? pContainer->sczFilePath : pPayload->sczFilePath; 1390 LPCWSTR wzRelativePath = pContainer ? pContainer->sczFilePath : pPayload->sczFilePath;
1391 DWORD dwChosenSearchPath = 0; 1391 DWORD dwChosenSearchPath = 0;
1392 BOOTSTRAPPER_CACHE_OPERATION cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_NONE; 1392 BOOTSTRAPPER_CACHE_OPERATION cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_NONE;
1393 BOOTSTRAPPER_CACHE_RESOLVE_OPERATION resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_NONE;
1393 LPWSTR* pwzDownloadUrl = pContainer ? &pContainer->downloadSource.sczUrl : &pPayload->downloadSource.sczUrl; 1394 LPWSTR* pwzDownloadUrl = pContainer ? &pContainer->downloadSource.sczUrl : &pPayload->downloadSource.sczUrl;
1394 LPWSTR* pwzSourcePath = pContainer ? &pContainer->sczSourcePath : &pPayload->sczSourcePath; 1395 LPWSTR* pwzSourcePath = pContainer ? &pContainer->sczSourcePath : &pPayload->sczSourcePath;
1395 BOOL fFoundLocal = FALSE; 1396 BOOL fFoundLocal = FALSE;
@@ -1405,47 +1406,70 @@ static HRESULT AcquireContainerOrPayload(
1405 if (BOOTSTRAPPER_CACHE_OPERATION_DOWNLOAD != cacheOperation && 1406 if (BOOTSTRAPPER_CACHE_OPERATION_DOWNLOAD != cacheOperation &&
1406 BOOTSTRAPPER_CACHE_OPERATION_EXTRACT != cacheOperation) 1407 BOOTSTRAPPER_CACHE_OPERATION_EXTRACT != cacheOperation)
1407 { 1408 {
1408 hr = CacheGetLocalSourcePaths(wzRelativePath, *pwzSourcePath, wzDestinationPath, pContext->wzLayoutDirectory, pContext->pVariables, &pContext->rgSearchPaths, &pContext->cSearchPaths); 1409 do
1409 ExitOnFailure(hr, "Failed to search local source.");
1410
1411 for (DWORD i = 0; i < pContext->cSearchPaths; ++i)
1412 { 1410 {
1413 // If the file exists locally, choose it. 1411 fFoundLocal = FALSE;
1414 if (FileExistsEx(pContext->rgSearchPaths[i], NULL)) 1412 resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_NONE;
1415 { 1413 dwChosenSearchPath = 0;
1416 dwChosenSearchPath = i;
1417 1414
1418 fFoundLocal = TRUE; 1415 hr = CacheGetLocalSourcePaths(wzRelativePath, *pwzSourcePath, wzDestinationPath, pContext->wzLayoutDirectory, pContext->pVariables, &pContext->rgSearchPaths, &pContext->cSearchPaths, &dwChosenSearchPath);
1419 break; 1416 ExitOnFailure(hr, "Failed to search local source.");
1420 }
1421 }
1422 1417
1423 if (BOOTSTRAPPER_CACHE_OPERATION_COPY == cacheOperation) 1418 for (DWORD i = 0; i < pContext->cSearchPaths; ++i)
1424 {
1425 if (!fFoundLocal)
1426 { 1419 {
1427 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_NONE; 1420 // If the file exists locally, choose it.
1421 if (FileExistsEx(pContext->rgSearchPaths[i], NULL))
1422 {
1423 dwChosenSearchPath = i;
1424
1425 fFoundLocal = TRUE;
1426 break;
1427 }
1428 } 1428 }
1429 } 1429
1430 else 1430 if (BOOTSTRAPPER_CACHE_OPERATION_COPY == cacheOperation)
1431 {
1432 if (fFoundLocal) // the file exists locally, so copy it.
1433 { 1431 {
1434 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_COPY; 1432 if (fFoundLocal)
1433 {
1434 resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_LOCAL;
1435 }
1435 } 1436 }
1436 else if (wzPayloadContainerId) 1437 else
1437 { 1438 {
1438 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_EXTRACT; 1439 if (fFoundLocal) // the file exists locally, so copy it.
1440 {
1441 resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_LOCAL;
1442 }
1443 else if (wzPayloadContainerId)
1444 {
1445 resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER;
1446 }
1447 else if (*pwzDownloadUrl && **pwzDownloadUrl)
1448 {
1449 resolveOperation = BOOTSTRAPPER_CACHE_RESOLVE_DOWNLOAD;
1450 }
1439 } 1451 }
1440 else if (*pwzDownloadUrl && **pwzDownloadUrl) 1452
1453 // Let the BA have a chance to override the source.
1454 hr = UserExperienceOnCacheAcquireResolving(pContext->pUX, wzPackageOrContainerId, wzPayloadId, pContext->rgSearchPaths, pContext->cSearchPaths, fFoundLocal, &dwChosenSearchPath, pwzDownloadUrl, wzPayloadContainerId, &resolveOperation);
1455 ExitOnRootFailure(hr, "BA aborted cache acquire resolving.");
1456
1457 switch (resolveOperation)
1441 { 1458 {
1459 case BOOTSTRAPPER_CACHE_RESOLVE_LOCAL:
1460 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_COPY;
1461 break;
1462 case BOOTSTRAPPER_CACHE_RESOLVE_DOWNLOAD:
1442 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_DOWNLOAD; 1463 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_DOWNLOAD;
1464 break;
1465 case BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER:
1466 cacheOperation = BOOTSTRAPPER_CACHE_OPERATION_EXTRACT;
1467 break;
1468 case BOOTSTRAPPER_CACHE_RESOLVE_RETRY:
1469 pContext->cSearchPathsMax = max(pContext->cSearchPaths, pContext->cSearchPathsMax);
1470 break;
1443 } 1471 }
1444 } 1472 } while (BOOTSTRAPPER_CACHE_RESOLVE_RETRY == resolveOperation);
1445
1446 // Let the BA have a chance to override the action, but their chance to change the source is during begin or complete.
1447 hr = UserExperienceOnCacheAcquireResolving(pContext->pUX, wzPackageOrContainerId, wzPayloadId, pContext->rgSearchPaths, pContext->cSearchPaths, fFoundLocal, &dwChosenSearchPath, *pwzDownloadUrl, wzPayloadContainerId, &cacheOperation);
1448 ExitOnRootFailure(hr, "BA aborted cache acquire resolving.");
1449 } 1473 }
1450 1474
1451 switch (cacheOperation) 1475 switch (cacheOperation)
diff --git a/src/engine/cache.cpp b/src/engine/cache.cpp
index 16f2c1e5..764de065 100644
--- a/src/engine/cache.cpp
+++ b/src/engine/cache.cpp
@@ -440,7 +440,8 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
440 __in_z_opt LPCWSTR wzLayoutDirectory, 440 __in_z_opt LPCWSTR wzLayoutDirectory,
441 __in BURN_VARIABLES* pVariables, 441 __in BURN_VARIABLES* pVariables,
442 __inout LPWSTR** prgSearchPaths, 442 __inout LPWSTR** prgSearchPaths,
443 __out DWORD* pcSearchPaths 443 __out DWORD* pcSearchPaths,
444 __out DWORD* pdwLikelySearchPath
444 ) 445 )
445{ 446{
446 HRESULT hr = S_OK; 447 HRESULT hr = S_OK;
@@ -452,6 +453,7 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
452 BOOL fTryRelativePath = FALSE; 453 BOOL fTryRelativePath = FALSE;
453 BOOL fSourceIsAbsolute = FALSE; 454 BOOL fSourceIsAbsolute = FALSE;
454 DWORD cSearchPaths = 0; 455 DWORD cSearchPaths = 0;
456 DWORD dwLikelySearchPath = 0;
455 457
456 AssertSz(vfInitializedCache, "Cache wasn't initialized"); 458 AssertSz(vfInitializedCache, "Cache wasn't initialized");
457 459
@@ -473,6 +475,12 @@ extern "C" HRESULT CacheGetLocalSourcePaths(
473 hr = StrAllocString(psczPath, wzSourcePath, 0); 475 hr = StrAllocString(psczPath, wzSourcePath, 0);
474 ExitOnFailure(hr, "Failed to copy absolute source path."); 476 ExitOnFailure(hr, "Failed to copy absolute source path.");
475 } 477 }
478 else
479 {
480 // If none of the paths exist, then most BAs will want to prompt the user with a possible path.
481 // The destination path is a temporary location and so not really a possible path.
482 dwLikelySearchPath = 1;
483 }
476 484
477 // Try the destination path next. 485 // Try the destination path next.
478 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgSearchPaths), cSearchPaths + 1, sizeof(LPWSTR), BURN_CACHE_MAX_SEARCH_PATHS); 486 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(prgSearchPaths), cSearchPaths + 1, sizeof(LPWSTR), BURN_CACHE_MAX_SEARCH_PATHS);
@@ -593,6 +601,7 @@ LExit:
593 601
594 AssertSz(cSearchPaths <= BURN_CACHE_MAX_SEARCH_PATHS, "Got more than BURN_CACHE_MAX_SEARCH_PATHS search paths"); 602 AssertSz(cSearchPaths <= BURN_CACHE_MAX_SEARCH_PATHS, "Got more than BURN_CACHE_MAX_SEARCH_PATHS search paths");
595 *pcSearchPaths = cSearchPaths; 603 *pcSearchPaths = cSearchPaths;
604 *pdwLikelySearchPath = dwLikelySearchPath;
596 605
597 return hr; 606 return hr;
598} 607}
diff --git a/src/engine/cache.h b/src/engine/cache.h
index cd964649..afa18e47 100644
--- a/src/engine/cache.h
+++ b/src/engine/cache.h
@@ -101,7 +101,8 @@ HRESULT CacheGetLocalSourcePaths(
101 __in_z_opt LPCWSTR wzLayoutDirectory, 101 __in_z_opt LPCWSTR wzLayoutDirectory,
102 __in BURN_VARIABLES* pVariables, 102 __in BURN_VARIABLES* pVariables,
103 __inout LPWSTR** prgSearchPaths, 103 __inout LPWSTR** prgSearchPaths,
104 __out DWORD* pcSearchPaths 104 __out DWORD* pcSearchPaths,
105 __out DWORD* pdwLikelySearchPath
105 ); 106 );
106HRESULT CacheSetLastUsedSource( 107HRESULT CacheSetLastUsedSource(
107 __in BURN_VARIABLES* pVariables, 108 __in BURN_VARIABLES* pVariables,
diff --git a/src/engine/userexperience.cpp b/src/engine/userexperience.cpp
index 8c6f29f3..7e68d664 100644
--- a/src/engine/userexperience.cpp
+++ b/src/engine/userexperience.cpp
@@ -515,9 +515,9 @@ EXTERN_C BAAPI UserExperienceOnCacheAcquireResolving(
515 __in DWORD cSearchPaths, 515 __in DWORD cSearchPaths,
516 __in BOOL fFoundLocal, 516 __in BOOL fFoundLocal,
517 __in DWORD* pdwChosenSearchPath, 517 __in DWORD* pdwChosenSearchPath,
518 __in_z_opt LPCWSTR wzDownloadUrl, 518 __in_z_opt LPWSTR* pwzDownloadUrl,
519 __in_z_opt LPCWSTR wzPayloadContainerId, 519 __in_z_opt LPCWSTR wzPayloadContainerId,
520 __inout BOOTSTRAPPER_CACHE_OPERATION* pCacheOperation 520 __inout BOOTSTRAPPER_CACHE_RESOLVE_OPERATION* pCacheOperation
521 ) 521 )
522{ 522{
523 HRESULT hr = S_OK; 523 HRESULT hr = S_OK;
@@ -531,14 +531,14 @@ EXTERN_C BAAPI UserExperienceOnCacheAcquireResolving(
531 args.cSearchPaths = cSearchPaths; 531 args.cSearchPaths = cSearchPaths;
532 args.fFoundLocal = fFoundLocal; 532 args.fFoundLocal = fFoundLocal;
533 args.dwRecommendedSearchPath = *pdwChosenSearchPath; 533 args.dwRecommendedSearchPath = *pdwChosenSearchPath;
534 args.wzDownloadUrl = wzDownloadUrl; 534 args.wzDownloadUrl = *pwzDownloadUrl;
535 args.recommendation = *pCacheOperation; 535 args.recommendation = *pCacheOperation;
536 536
537 results.cbSize = sizeof(results); 537 results.cbSize = sizeof(results);
538 results.dwChosenSearchPath = *pdwChosenSearchPath; 538 results.dwChosenSearchPath = *pdwChosenSearchPath;
539 results.action = *pCacheOperation; 539 results.action = *pCacheOperation;
540 540
541 hr = SendBAMessage(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONCACHEACQUIRERESOLVING, &args, &results); 541 hr = SendBAMessageFromInactiveEngine(pUserExperience, BOOTSTRAPPER_APPLICATION_MESSAGE_ONCACHEACQUIRERESOLVING, &args, &results);
542 ExitOnFailure(hr, "BA OnCacheAcquireResolving failed."); 542 ExitOnFailure(hr, "BA OnCacheAcquireResolving failed.");
543 543
544 if (results.fCancel) 544 if (results.fCancel)
@@ -548,13 +548,14 @@ EXTERN_C BAAPI UserExperienceOnCacheAcquireResolving(
548 else 548 else
549 { 549 {
550 // Verify the BA requested an action that is possible. 550 // Verify the BA requested an action that is possible.
551 if (BOOTSTRAPPER_CACHE_OPERATION_DOWNLOAD == results.action && wzDownloadUrl && *wzDownloadUrl || 551 if (BOOTSTRAPPER_CACHE_RESOLVE_DOWNLOAD == results.action && *pwzDownloadUrl && **pwzDownloadUrl ||
552 BOOTSTRAPPER_CACHE_OPERATION_EXTRACT == results.action && wzPayloadContainerId || 552 BOOTSTRAPPER_CACHE_RESOLVE_CONTAINER == results.action && wzPayloadContainerId ||
553 BOOTSTRAPPER_CACHE_OPERATION_NONE == results.action) 553 BOOTSTRAPPER_CACHE_RESOLVE_RETRY == results.action ||
554 BOOTSTRAPPER_CACHE_RESOLVE_NONE == results.action)
554 { 555 {
555 *pCacheOperation = results.action; 556 *pCacheOperation = results.action;
556 } 557 }
557 else if (BOOTSTRAPPER_CACHE_OPERATION_COPY == results.action && results.dwChosenSearchPath < cSearchPaths) 558 else if (BOOTSTRAPPER_CACHE_RESOLVE_LOCAL == results.action && results.dwChosenSearchPath < cSearchPaths)
558 { 559 {
559 *pdwChosenSearchPath = results.dwChosenSearchPath; 560 *pdwChosenSearchPath = results.dwChosenSearchPath;
560 *pCacheOperation = results.action; 561 *pCacheOperation = results.action;
diff --git a/src/engine/userexperience.h b/src/engine/userexperience.h
index 58e0431e..e1041624 100644
--- a/src/engine/userexperience.h
+++ b/src/engine/userexperience.h
@@ -154,9 +154,9 @@ BAAPI UserExperienceOnCacheAcquireResolving(
154 __in DWORD cSearchPaths, 154 __in DWORD cSearchPaths,
155 __in BOOL fFoundLocal, 155 __in BOOL fFoundLocal,
156 __in DWORD* pdwChosenSearchPath, 156 __in DWORD* pdwChosenSearchPath,
157 __in_z_opt LPCWSTR wzDownloadUrl, 157 __in_z_opt LPWSTR* pwzDownloadUrl,
158 __in_z_opt LPCWSTR wzPayloadContainerId, 158 __in_z_opt LPCWSTR wzPayloadContainerId,
159 __inout BOOTSTRAPPER_CACHE_OPERATION* pCacheOperation 159 __inout BOOTSTRAPPER_CACHE_RESOLVE_OPERATION* pCacheOperation
160 ); 160 );
161BAAPI UserExperienceOnCacheBegin( 161BAAPI UserExperienceOnCacheBegin(
162 __in BURN_USER_EXPERIENCE* pUserExperience 162 __in BURN_USER_EXPERIENCE* pUserExperience