Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose simple applicable installer check in Com api #1974

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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