winget-cli

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

commit 84490b03d9dae7c815f5017848f56374fd3614d0
parent 16de635071b70d567f61e058f36278edff484a6e
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Mon, 28 Feb 2022 22:13:40 -0800

Expose simple applicable installer check in Com api (#1974)


Diffstat:
Msrc/AppInstallerCLICore/Workflows/WorkflowBase.cpp | 2+-
Msrc/Microsoft.Management.Deployment/PackageManager.idl | 6++++++
Msrc/Microsoft.Management.Deployment/PackageVersionInfo.cpp | 12++++++++++++
Msrc/Microsoft.Management.Deployment/PackageVersionInfo.h | 4+++-
4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp @@ -974,7 +974,7 @@ namespace AppInstaller::CLI::Workflow bool isUpdate = WI_IsFlagSet(context.GetFlags(), Execution::ContextFlag::InstallerExecutionUseUpdate); IPackageVersion::Metadata installationMetadata; - + if (isUpdate) { installationMetadata = context.Get<Execution::Data::InstalledPackageVersion>()->GetMetadata(); diff --git a/src/Microsoft.Management.Deployment/PackageManager.idl b/src/Microsoft.Management.Deployment/PackageManager.idl @@ -206,6 +206,12 @@ namespace Microsoft.Management.Deployment CompareResult CompareToVersion(String versionString); } + [contract(Microsoft.Management.Deployment.WindowsPackageManagerContract, 4)] + { + /// Checks if this package version has at least one applicable installer. + Boolean HasApplicableInstaller { get; }; + } + /// DESIGN NOTE: /// GetManifest from IPackageVersion in winget/RepositorySearch is not implemented in V1. That class has /// a lot of fields and no one requesting it. diff --git a/src/Microsoft.Management.Deployment/PackageVersionInfo.cpp b/src/Microsoft.Management.Deployment/PackageVersionInfo.cpp @@ -8,7 +8,10 @@ #include "PackageCatalogInfo.h" #include "PackageCatalog.h" #include "CatalogPackage.h" +#include "ComContext.h" #include "Workflows/WorkflowBase.h" +#include "Workflows/ManifestComparator.h" +#include "winget/RepositorySearch.h" #include "AppInstallerVersions.h" #include "Converters.h" #include <wil\cppwinrt_wrl.h> @@ -112,6 +115,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation return CompareResult::Equal; } } + bool PackageVersionInfo::HasApplicableInstaller() + { + AppInstaller::CLI::Execution::COMContext context; + AppInstaller::Repository::IPackageVersion::Metadata installationMetadata; + AppInstaller::CLI::Workflow::ManifestComparator manifestComparator{ context, installationMetadata }; + AppInstaller::Manifest::Manifest manifest = m_packageVersion->GetManifest(); + auto result = manifestComparator.GetPreferredInstaller(manifest); + return result.installer.has_value(); + } std::shared_ptr<::AppInstaller::Repository::IPackageVersion> PackageVersionInfo::GetRepositoryPackageVersion() { return m_packageVersion; diff --git a/src/Microsoft.Management.Deployment/PackageVersionInfo.h b/src/Microsoft.Management.Deployment/PackageVersionInfo.h @@ -23,7 +23,9 @@ namespace winrt::Microsoft::Management::Deployment::implementation winrt::Windows::Foundation::Collections::IVectorView<hstring> ProductCodes(); winrt::Microsoft::Management::Deployment::PackageCatalog PackageCatalog(); winrt::Microsoft::Management::Deployment::CompareResult CompareToVersion(hstring versionString); - + // Contract version 4 + bool HasApplicableInstaller(); + #if !defined(INCLUDE_ONLY_INTERFACE_METHODS) private: winrt::Microsoft::Management::Deployment::PackageCatalog m_packageCatalog{ nullptr };