winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 2006c662f6b55d3e64f02b61db3d6ae726877e6a
parent d386744e87217573a175b2b66023f8c14583e07a
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Fri, 11 Feb 2022 14:58:37 -0800

Add InstallerErrorCode to COM interface (#1926)


Diffstat:
Msrc/Microsoft.Management.Deployment/InstallResult.cpp | 9++++++++-
Msrc/Microsoft.Management.Deployment/InstallResult.h | 5++++-
Msrc/Microsoft.Management.Deployment/PackageManager.cpp | 17+++++++++++------
Msrc/Microsoft.Management.Deployment/PackageManager.idl | 9++++++++-
Mtools/SampleWinGetUWPCaller/AppInstallerCaller/GeneratedFromServer/Microsoft.Management.Deployment.winmd | 0
Mtools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp | 4+++-
Mtools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h | 2++
7 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/src/Microsoft.Management.Deployment/InstallResult.cpp b/src/Microsoft.Management.Deployment/InstallResult.cpp @@ -9,12 +9,14 @@ namespace winrt::Microsoft::Management::Deployment::implementation { void InstallResult::Initialize( winrt::Microsoft::Management::Deployment::InstallResultStatus status, - winrt::hresult extendedErrorCode, + winrt::hresult extendedErrorCode, + uint32_t installerErrorCode, hstring const& correlationData, bool rebootRequired) { m_status = status; m_extendedErrorCode = extendedErrorCode; + m_installerErrorCode = installerErrorCode; m_correlationData = correlationData; m_rebootRequired = rebootRequired; } @@ -34,4 +36,9 @@ namespace winrt::Microsoft::Management::Deployment::implementation { return m_extendedErrorCode; } + + uint32_t InstallResult::InstallerErrorCode() + { + return m_installerErrorCode; + } } diff --git a/src/Microsoft.Management.Deployment/InstallResult.h b/src/Microsoft.Management.Deployment/InstallResult.h @@ -12,7 +12,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation #if !defined(INCLUDE_ONLY_INTERFACE_METHODS) void Initialize( winrt::Microsoft::Management::Deployment::InstallResultStatus status, - winrt::hresult extendedErrorCode, + winrt::hresult extendedErrorCode, + uint32_t installerErrorCode, hstring const& correlationData, bool rebootRequired); #endif @@ -21,6 +22,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation bool RebootRequired(); winrt::Microsoft::Management::Deployment::InstallResultStatus Status(); winrt::hresult ExtendedErrorCode(); + uint32_t InstallerErrorCode(); #if !defined(INCLUDE_ONLY_INTERFACE_METHODS) private: @@ -28,6 +30,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation bool m_rebootRequired = false; winrt::Microsoft::Management::Deployment::InstallResultStatus m_status = winrt::Microsoft::Management::Deployment::InstallResultStatus::Ok; winrt::hresult m_extendedErrorCode = S_OK; + uint32_t m_installerErrorCode = 0; #endif }; } diff --git a/src/Microsoft.Management.Deployment/PackageManager.cpp b/src/Microsoft.Management.Deployment/PackageManager.cpp @@ -157,11 +157,11 @@ namespace winrt::Microsoft::Management::Deployment::implementation return *packageCatalogImpl; } - winrt::Microsoft::Management::Deployment::InstallResult GetInstallResult(::Workflow::ExecutionStage executionStage, winrt::hresult terminationHR, winrt::hstring correlationData, bool rebootRequired) + winrt::Microsoft::Management::Deployment::InstallResult GetInstallResult(::Workflow::ExecutionStage executionStage, winrt::hresult terminationHR, uint32_t installerError, winrt::hstring correlationData, bool rebootRequired) { winrt::Microsoft::Management::Deployment::InstallResultStatus installResultStatus = GetInstallResultStatus(executionStage, terminationHR); auto installResult = winrt::make_self<wil::details::module_count_wrapper<winrt::Microsoft::Management::Deployment::implementation::InstallResult>>(); - installResult->Initialize(installResultStatus, terminationHR, correlationData, rebootRequired); + installResult->Initialize(installResultStatus, terminationHR, installerError, correlationData, rebootRequired); return *installResult; } @@ -406,6 +406,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation bool isUpgrade = false) { winrt::hresult terminationHR = S_OK; + uint32_t installerError = 0; hstring correlationData = (options) ? options.CorrelationData() : L""; ::Workflow::ExecutionStage executionStage = ::Workflow::ExecutionStage::Initial; @@ -435,12 +436,12 @@ namespace winrt::Microsoft::Management::Deployment::implementation if (!(options.AllowUpgradeToUnknownVersion() && AppInstaller::Utility::ICUCaseInsensitiveEquals(installedVersion.GetChannel().ToString(), upgradeVersion.GetChannel().ToString()))) { - co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_UNKNOWN, correlationData, false); + co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_UNKNOWN, 0, correlationData, false); } } else if (!installedVersion.IsUpdatedBy(upgradeVersion)) { - co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_NOT_NEWER, correlationData, false); + co_return GetInstallResult(executionStage, APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_NOT_NEWER, 0, correlationData, false); } // Set upgrade flag @@ -537,12 +538,16 @@ namespace winrt::Microsoft::Management::Deployment::implementation // The install command has finished, check for success/failure and how far it got. terminationHR = queueItem->GetContext().GetTerminationHR(); executionStage = queueItem->GetContext().GetExecutionStage(); + if (queueItem->GetContext().Contains(Data::InstallerReturnCode)) + { + installerError = static_cast<uint32_t>(queueItem->GetContext().Get<Data::InstallerReturnCode>()); + } } } WINGET_CATCH_STORE(terminationHR, APPINSTALLER_CLI_ERROR_COMMAND_FAILED); // TODO - RebootRequired not yet populated, msi arguments not returned from Execute. - co_return GetInstallResult(executionStage, terminationHR, correlationData, false); + co_return GetInstallResult(executionStage, terminationHR, installerError, correlationData, false); } winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::InstallResult, winrt::Microsoft::Management::Deployment::InstallProgress> GetEmptyAsynchronousResultForInstallOperation( @@ -551,7 +556,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation { // If a function uses co_await or co_return (i.e. if it is a co_routine), it cannot use return directly. // This helper helps a function that is not a coroutine itself to return errors asynchronously. - co_return GetInstallResult(::Workflow::ExecutionStage::Initial, hr, correlationData, false); + co_return GetInstallResult(::Workflow::ExecutionStage::Initial, hr, 0, correlationData, false); } #define WINGET_RETURN_INSTALL_RESULT_HR_IF(hr, boolVal) { if(boolVal) { return GetEmptyAsynchronousResultForInstallOperation(hr, correlationData); }} diff --git a/src/Microsoft.Management.Deployment/PackageManager.idl b/src/Microsoft.Management.Deployment/PackageManager.idl @@ -76,8 +76,15 @@ namespace Microsoft.Management.Deployment /// Batched error code, example APPINSTALLER_CLI_ERROR_SHELLEXEC_INSTALL_FAILED InstallResultStatus Status{ get; }; - /// Specific error if known, from downloader or installer itself, example ERROR_INSTALL_PACKAGE_REJECTED + /// The error code of the overall operation. HRESULT ExtendedErrorCode{ get; }; + + [contract(Microsoft.Management.Deployment.WindowsPackageManagerContract, 4)] + { + /// The error code from the install attempt. Only valid if the Status is InstallError. + /// This value's meaning will require knowledge of the specific installer or install technology. + UInt32 InstallerErrorCode{ get; }; + } } /// IMPLEMENTATION NOTE: SourceOrigin from winget/RepositorySource.h diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/GeneratedFromServer/Microsoft.Management.Deployment.winmd b/tools/SampleWinGetUWPCaller/AppInstallerCaller/GeneratedFromServer/Microsoft.Management.Deployment.winmd Binary files differ. diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp b/tools/SampleWinGetUWPCaller/AppInstallerCaller/MainPage.cpp @@ -230,8 +230,10 @@ namespace winrt::AppInstallerCaller::implementation } else { + std::wostringstream failText; + failText << L"Install failed: " << installResult.ExtendedErrorCode() << L" [" << installResult.InstallerErrorCode() << L"]"; installButton.Content(box_value(L"Install")); - statusText.Text(L"Install failed."); + statusText.Text(failText.str()); } } diff --git a/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h b/tools/SampleWinGetUWPCaller/AppInstallerCaller/pch.h @@ -14,3 +14,5 @@ #include <winrt/Windows.UI.Xaml.Interop.h> #include <winrt/Windows.UI.Xaml.Markup.h> #include <winrt/Windows.UI.Xaml.Navigation.h> + +#include <sstream>