From b2ecce5076bfe366f589dfadf5bb07c50c076f62 Mon Sep 17 00:00:00 2001 From: Yao Sun Date: Thu, 24 Feb 2022 14:11:01 -0800 Subject: [PATCH] applicable installer --- src/AppInstallerCLICore/Workflows/WorkflowBase.cpp | 2 +- .../PackageManager.idl | 6 ++++++ .../PackageVersionInfo.cpp | 12 ++++++++++++ .../PackageVersionInfo.h | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp b/src/AppInstallerCLICore/Workflows/WorkflowBase.cpp index 75b0054fba..084ca69880 100644 --- 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()->GetMetadata(); diff --git a/src/Microsoft.Management.Deployment/PackageManager.idl b/src/Microsoft.Management.Deployment/PackageManager.idl index 4023837967..c9888a020e 100644 --- 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 index c38f56a951..a2e4812cc2 100644 --- 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 @@ -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 index d646498ce1..8d7c5e189f 100644 --- 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 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 };