Skip to content

Commit

Permalink
Expose simple applicable installer check in Com api (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft authored Mar 1, 2022
1 parent 16de635 commit 84490b0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.Management.Deployment/PackageManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/Microsoft.Management.Deployment/PackageVersionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Microsoft.Management.Deployment/PackageVersionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit 84490b0

Please sign in to comment.