diff options
Diffstat (limited to 'src/engine/apply.cpp')
-rw-r--r-- | src/engine/apply.cpp | 232 |
1 files changed, 82 insertions, 150 deletions
diff --git a/src/engine/apply.cpp b/src/engine/apply.cpp index 9a0f64e1..909fb159 100644 --- a/src/engine/apply.cpp +++ b/src/engine/apply.cpp | |||
@@ -198,6 +198,19 @@ static HRESULT ExecuteCompatiblePackageAction( | |||
198 | __in BURN_ENGINE_STATE* pEngineState, | 198 | __in BURN_ENGINE_STATE* pEngineState, |
199 | __in BURN_EXECUTE_ACTION* pAction | 199 | __in BURN_EXECUTE_ACTION* pAction |
200 | ); | 200 | ); |
201 | static HRESULT ExecuteMsiBeginTransaction( | ||
202 | __in BURN_ENGINE_STATE* pEngineState, | ||
203 | __in LPCWSTR wzName, | ||
204 | __in BURN_EXECUTE_CONTEXT* pContext | ||
205 | ); | ||
206 | static HRESULT ExecuteMsiCommitTransaction( | ||
207 | __in BURN_ENGINE_STATE* pEngineState, | ||
208 | __in BURN_EXECUTE_CONTEXT* pContext | ||
209 | ); | ||
210 | static HRESULT ExecuteMsiRollbackTransaction( | ||
211 | __in BURN_ENGINE_STATE* pEngineState, | ||
212 | __in BURN_EXECUTE_CONTEXT* pContext | ||
213 | ); | ||
201 | static HRESULT CleanPackage( | 214 | static HRESULT CleanPackage( |
202 | __in HANDLE hElevatedPipe, | 215 | __in HANDLE hElevatedPipe, |
203 | __in BURN_PACKAGE* pPackage | 216 | __in BURN_PACKAGE* pPackage |
@@ -228,30 +241,6 @@ static HRESULT ExecutePackageComplete( | |||
228 | __out BOOL* pfSuspend | 241 | __out BOOL* pfSuspend |
229 | ); | 242 | ); |
230 | 243 | ||
231 | static HRESULT DoMsiBeginTransaction( | ||
232 | __in BURN_EXECUTE_CONTEXT *context | ||
233 | , __in BURN_ENGINE_STATE* pEngineState | ||
234 | ); | ||
235 | static HRESULT DoMsiCommitTransaction( | ||
236 | __in BURN_EXECUTE_CONTEXT *context | ||
237 | , __in BURN_ENGINE_STATE* pEngineState | ||
238 | ); | ||
239 | static HRESULT DoMsiRollbackTransaction( | ||
240 | __in BURN_EXECUTE_CONTEXT *context | ||
241 | , __in BURN_ENGINE_STATE* pEngineState | ||
242 | ); | ||
243 | static HRESULT ExecuteMsiBeginTransaction( | ||
244 | __in BURN_EXECUTE_CONTEXT* pContext | ||
245 | , __in BURN_ENGINE_STATE* pEngineState | ||
246 | ); | ||
247 | static HRESULT ExecuteMsiCommitTransaction( | ||
248 | __in BURN_EXECUTE_CONTEXT* pContext | ||
249 | , __in BURN_ENGINE_STATE* pEngineState | ||
250 | ); | ||
251 | static HRESULT ExecuteMsiRollbackTransaction( | ||
252 | __in BURN_EXECUTE_CONTEXT* pContext | ||
253 | , __in BURN_ENGINE_STATE* pEngineState | ||
254 | ); | ||
255 | 244 | ||
256 | // function definitions | 245 | // function definitions |
257 | 246 | ||
@@ -773,7 +762,7 @@ extern "C" HRESULT ApplyExecute( | |||
773 | if (fInTransaction) | 762 | if (fInTransaction) |
774 | { | 763 | { |
775 | LogString(REPORT_STANDARD, "Committing MSI transaction\n"); | 764 | LogString(REPORT_STANDARD, "Committing MSI transaction\n"); |
776 | hr = DoMsiCommitTransaction(&context, pEngineState); | 765 | hr = ExecuteMsiCommitTransaction(pEngineState, &context); |
777 | ExitOnFailure(hr, "Failed committing an MSI transaction"); | 766 | ExitOnFailure(hr, "Failed committing an MSI transaction"); |
778 | fInTransaction = FALSE; | 767 | fInTransaction = FALSE; |
779 | } | 768 | } |
@@ -789,7 +778,7 @@ extern "C" HRESULT ApplyExecute( | |||
789 | else | 778 | else |
790 | { | 779 | { |
791 | LogString(REPORT_STANDARD, "Starting a new MSI transaction\n"); | 780 | LogString(REPORT_STANDARD, "Starting a new MSI transaction\n"); |
792 | hr = DoMsiBeginTransaction(&context, pEngineState); | 781 | hr = ExecuteMsiBeginTransaction(pEngineState, pExecuteAction->rollbackBoundary.pRollbackBoundary->sczId, &context); |
793 | ExitOnFailure(hr, "Failed beginning an MSI transaction"); | 782 | ExitOnFailure(hr, "Failed beginning an MSI transaction"); |
794 | fInTransaction = TRUE; | 783 | fInTransaction = TRUE; |
795 | } | 784 | } |
@@ -855,7 +844,7 @@ extern "C" HRESULT ApplyExecute( | |||
855 | if (fInTransaction) | 844 | if (fInTransaction) |
856 | { | 845 | { |
857 | LogString(REPORT_STANDARD, "Committing an MSI transaction\n"); | 846 | LogString(REPORT_STANDARD, "Committing an MSI transaction\n"); |
858 | hr = DoMsiCommitTransaction(&context, pEngineState); | 847 | hr = ExecuteMsiCommitTransaction(pEngineState, &context); |
859 | ExitOnFailure(hr, "Failed committing an MSI transaction"); | 848 | ExitOnFailure(hr, "Failed committing an MSI transaction"); |
860 | fInTransaction = FALSE; | 849 | fInTransaction = FALSE; |
861 | } | 850 | } |
@@ -1658,127 +1647,6 @@ static void DoRollbackCache( | |||
1658 | } | 1647 | } |
1659 | } | 1648 | } |
1660 | 1649 | ||
1661 | /* MSI Transactions: | ||
1662 | * All MSI/MSP/MSU packages wrapped in MsiBeginTranasaction-MsiEndTransaction pair are installed or uninstalled together. | ||
1663 | */ | ||
1664 | static HRESULT ExecuteMsiBeginTransaction( | ||
1665 | __in BURN_EXECUTE_CONTEXT* pContext | ||
1666 | , __in BURN_ENGINE_STATE* pEngineState | ||
1667 | ) | ||
1668 | { | ||
1669 | HRESULT hr = S_OK; | ||
1670 | UINT uResult = ERROR_SUCCESS; | ||
1671 | |||
1672 | // Per user/machine context | ||
1673 | if (pEngineState->plan.fPerMachine) | ||
1674 | { | ||
1675 | hr = ElevationMsiBeginTransaction(pEngineState->companionConnection.hPipe, pEngineState->userExperience.hwndApply, pContext); | ||
1676 | ExitOnFailure(hr, "Failed to begin an MSI transaction."); | ||
1677 | } | ||
1678 | else | ||
1679 | { | ||
1680 | MSIHANDLE hMsiTrns = NULL; | ||
1681 | HANDLE hMsiTrnsEvent = NULL; | ||
1682 | uResult = MsiBeginTransaction(L"WiX", 0, &hMsiTrns, &hMsiTrnsEvent); | ||
1683 | ExitOnWin32Error(uResult, hr, "Failed beginning an MSI transaction"); | ||
1684 | } | ||
1685 | |||
1686 | LExit: | ||
1687 | return hr; | ||
1688 | } | ||
1689 | |||
1690 | static HRESULT ExecuteMsiCommitTransaction( | ||
1691 | __in BURN_EXECUTE_CONTEXT* pContext | ||
1692 | , __in BURN_ENGINE_STATE* pEngineState | ||
1693 | ) | ||
1694 | { | ||
1695 | HRESULT hr = S_OK; | ||
1696 | UINT uResult = ERROR_SUCCESS; | ||
1697 | |||
1698 | // Per user/machine context | ||
1699 | if (pEngineState->plan.fPerMachine) | ||
1700 | { | ||
1701 | hr = ElevationMsiCommitTransaction(pEngineState->companionConnection.hPipe, pEngineState->userExperience.hwndApply, pContext); | ||
1702 | ExitOnFailure(hr, "Failed to commit an MSI transaction."); | ||
1703 | } | ||
1704 | else | ||
1705 | { | ||
1706 | uResult = MsiEndTransaction(MSITRANSACTIONSTATE_COMMIT); | ||
1707 | ExitOnWin32Error(uResult, hr, "Failed beginning an MSI transaction"); | ||
1708 | } | ||
1709 | |||
1710 | LExit: | ||
1711 | return hr; | ||
1712 | } | ||
1713 | |||
1714 | static HRESULT ExecuteMsiRollbackTransaction( | ||
1715 | __in BURN_EXECUTE_CONTEXT* pContext | ||
1716 | , __in BURN_ENGINE_STATE* pEngineState | ||
1717 | ) | ||
1718 | { | ||
1719 | HRESULT hr = S_OK; | ||
1720 | UINT uResult = ERROR_SUCCESS; | ||
1721 | |||
1722 | // Per user/machine context | ||
1723 | if (pEngineState->plan.fPerMachine) | ||
1724 | { | ||
1725 | hr = ElevationMsiRollbackTransaction(pEngineState->companionConnection.hPipe, pEngineState->userExperience.hwndApply, pContext); | ||
1726 | ExitOnFailure(hr, "Failed to rollback an MSI transaction."); | ||
1727 | } | ||
1728 | else | ||
1729 | { | ||
1730 | uResult = MsiEndTransaction(MSITRANSACTIONSTATE_ROLLBACK); | ||
1731 | ExitOnWin32Error(uResult, hr, "Failed beginning an MSI transaction"); | ||
1732 | } | ||
1733 | |||
1734 | LExit: | ||
1735 | return hr; | ||
1736 | } | ||
1737 | |||
1738 | // Currently, supporting only elevated transactions. | ||
1739 | static HRESULT DoMsiBeginTransaction( | ||
1740 | __in BURN_EXECUTE_CONTEXT *pContext | ||
1741 | , __in BURN_ENGINE_STATE* pEngineState | ||
1742 | ) | ||
1743 | { | ||
1744 | HRESULT hr = S_OK; | ||
1745 | |||
1746 | hr = ExecuteMsiBeginTransaction(pContext, pEngineState); | ||
1747 | ExitOnFailure(hr, "Failed to execute EXE package."); | ||
1748 | |||
1749 | LExit: | ||
1750 | return hr; | ||
1751 | } | ||
1752 | |||
1753 | static HRESULT DoMsiCommitTransaction( | ||
1754 | __in BURN_EXECUTE_CONTEXT *pContext | ||
1755 | , __in BURN_ENGINE_STATE* pEngineState | ||
1756 | ) | ||
1757 | { | ||
1758 | HRESULT hr = S_OK; | ||
1759 | |||
1760 | hr = ExecuteMsiCommitTransaction(pContext, pEngineState); | ||
1761 | ExitOnFailure(hr, "Failed to execute EXE package."); | ||
1762 | |||
1763 | LExit: | ||
1764 | return hr; | ||
1765 | } | ||
1766 | |||
1767 | static HRESULT DoMsiRollbackTransaction( | ||
1768 | __in BURN_EXECUTE_CONTEXT *pContext | ||
1769 | , __in BURN_ENGINE_STATE* pEngineState | ||
1770 | ) | ||
1771 | { | ||
1772 | HRESULT hr = S_OK; | ||
1773 | |||
1774 | hr = ExecuteMsiRollbackTransaction(pContext, pEngineState); | ||
1775 | ExitOnFailure(hr, "Failed to execute EXE package."); | ||
1776 | |||
1777 | LExit: | ||
1778 | return hr; | ||
1779 | } | ||
1780 | |||
1781 | |||
1782 | static HRESULT DoExecuteAction( | 1650 | static HRESULT DoExecuteAction( |
1783 | __in BURN_ENGINE_STATE* pEngineState, | 1651 | __in BURN_ENGINE_STATE* pEngineState, |
1784 | __in BURN_EXECUTE_ACTION* pExecuteAction, | 1652 | __in BURN_EXECUTE_ACTION* pExecuteAction, |
@@ -1904,7 +1772,7 @@ static HRESULT DoRollbackActions( | |||
1904 | __in BOOL fInTransaction, | 1772 | __in BOOL fInTransaction, |
1905 | __out BOOL* pfKeepRegistration, | 1773 | __out BOOL* pfKeepRegistration, |
1906 | __out BOOTSTRAPPER_APPLY_RESTART* pRestart | 1774 | __out BOOTSTRAPPER_APPLY_RESTART* pRestart |
1907 | ) | 1775 | ) |
1908 | { | 1776 | { |
1909 | HRESULT hr = S_OK; | 1777 | HRESULT hr = S_OK; |
1910 | DWORD iCheckpoint = 0; | 1778 | DWORD iCheckpoint = 0; |
@@ -1916,7 +1784,7 @@ static HRESULT DoRollbackActions( | |||
1916 | // Rollback MSI transaction | 1784 | // Rollback MSI transaction |
1917 | if (fInTransaction) | 1785 | if (fInTransaction) |
1918 | { | 1786 | { |
1919 | hr = DoMsiRollbackTransaction(pContext, pEngineState); | 1787 | hr = ExecuteMsiRollbackTransaction(pEngineState, pContext); |
1920 | ExitOnFailure(hr, "Failed rolling back transaction"); | 1788 | ExitOnFailure(hr, "Failed rolling back transaction"); |
1921 | } | 1789 | } |
1922 | 1790 | ||
@@ -2364,6 +2232,70 @@ LExit: | |||
2364 | return hr; | 2232 | return hr; |
2365 | } | 2233 | } |
2366 | 2234 | ||
2235 | static HRESULT ExecuteMsiBeginTransaction( | ||
2236 | __in BURN_ENGINE_STATE* pEngineState, | ||
2237 | __in LPCWSTR wzName, | ||
2238 | __in BURN_EXECUTE_CONTEXT* /*pContext*/ | ||
2239 | ) | ||
2240 | { | ||
2241 | HRESULT hr = S_OK; | ||
2242 | |||
2243 | if (pEngineState->plan.fPerMachine) | ||
2244 | { | ||
2245 | hr = ElevationMsiBeginTransaction(pEngineState->companionConnection.hPipe, wzName); | ||
2246 | ExitOnFailure(hr, "Failed to begin an elevated MSI transaction."); | ||
2247 | } | ||
2248 | else | ||
2249 | { | ||
2250 | hr = MsiEngineBeginTransaction(wzName); | ||
2251 | } | ||
2252 | |||
2253 | LExit: | ||
2254 | return hr; | ||
2255 | } | ||
2256 | |||
2257 | static HRESULT ExecuteMsiCommitTransaction( | ||
2258 | __in BURN_ENGINE_STATE* pEngineState, | ||
2259 | __in BURN_EXECUTE_CONTEXT* /*pContext*/ | ||
2260 | ) | ||
2261 | { | ||
2262 | HRESULT hr = S_OK; | ||
2263 | |||
2264 | if (pEngineState->plan.fPerMachine) | ||
2265 | { | ||
2266 | hr = ElevationMsiCommitTransaction(pEngineState->companionConnection.hPipe); | ||
2267 | ExitOnFailure(hr, "Failed to commit an elevated MSI transaction."); | ||
2268 | } | ||
2269 | else | ||
2270 | { | ||
2271 | hr = MsiEngineCommitTransaction(); | ||
2272 | } | ||
2273 | |||
2274 | LExit: | ||
2275 | return hr; | ||
2276 | } | ||
2277 | |||
2278 | static HRESULT ExecuteMsiRollbackTransaction( | ||
2279 | __in BURN_ENGINE_STATE* pEngineState, | ||
2280 | __in BURN_EXECUTE_CONTEXT* /*pContext*/ | ||
2281 | ) | ||
2282 | { | ||
2283 | HRESULT hr = S_OK; | ||
2284 | |||
2285 | if (pEngineState->plan.fPerMachine) | ||
2286 | { | ||
2287 | hr = ElevationMsiRollbackTransaction(pEngineState->companionConnection.hPipe); | ||
2288 | ExitOnFailure(hr, "Failed to rollback an elevated MSI transaction."); | ||
2289 | } | ||
2290 | else | ||
2291 | { | ||
2292 | hr = MsiEngineRollbackTransaction(); | ||
2293 | } | ||
2294 | |||
2295 | LExit: | ||
2296 | return hr; | ||
2297 | } | ||
2298 | |||
2367 | static HRESULT CleanPackage( | 2299 | static HRESULT CleanPackage( |
2368 | __in HANDLE hElevatedPipe, | 2300 | __in HANDLE hElevatedPipe, |
2369 | __in BURN_PACKAGE* pPackage | 2301 | __in BURN_PACKAGE* pPackage |