forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsixManifest.cpp
More file actions
111 lines (92 loc) · 3.84 KB
/
Copy pathMsixManifest.cpp
File metadata and controls
111 lines (92 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include <pch.h>
#include <AppInstallerMsixInfo.h>
#include <winget/MsixManifest.h>
using namespace Microsoft::WRL;
namespace AppInstaller::Msix
{
bool IsSupportedPlatform(MsixPackageManifestTargetDeviceFamily::Platform platform)
{
return platform == MsixPackageManifestTargetDeviceFamily::Platform::WindowsDesktop
|| platform == MsixPackageManifestTargetDeviceFamily::Platform::WindowsUniversal;
}
Utility::NormalizedString MsixPackageManifestIdentity::GetPackageFamilyName() const
{
wil::unique_cotaskmem_string familyName;
THROW_IF_FAILED(m_packageId->GetPackageFamilyName(&familyName));
return { familyName.get() };
}
PackageVersion MsixPackageManifestIdentity::GetVersion() const
{
UINT64 version = 0;
THROW_IF_FAILED(m_packageId->GetVersion(&version));
return PackageVersion{ version };
}
MsixPackageManifestIdentity MsixPackageManifest::GetIdentity() const
{
ComPtr<IAppxManifestPackageId> manifestPackageId;
THROW_IF_FAILED(m_manifestReader->GetPackageId(&manifestPackageId));
return MsixPackageManifestIdentity{ std::move(manifestPackageId) };
}
std::optional<OSVersion> MsixPackageManifest::GetMinimumOSVersionForSupportedPlatforms() const
{
std::optional<OSVersion> minOSVersion;
auto targetDeviceFamilies = GetTargetDeviceFamilies();
for (const auto& targetDeviceFamily : targetDeviceFamilies)
{
if (IsSupportedPlatform(targetDeviceFamily.GetPlatform()))
{
auto targetDeviceFamilyMinVersion = targetDeviceFamily.GetMinVersion();
if (!minOSVersion.has_value() || targetDeviceFamilyMinVersion < minOSVersion.value())
{
minOSVersion = targetDeviceFamilyMinVersion;
}
}
}
return minOSVersion;
}
std::vector<MsixPackageManifestTargetDeviceFamily> MsixPackageManifest::GetTargetDeviceFamilies() const
{
std::vector<MsixPackageManifestTargetDeviceFamily> targetDeviceFamilies;
ComPtr<IAppxManifestReader3> manifestReader3;
THROW_IF_FAILED(m_manifestReader.As(&manifestReader3));
ComPtr<IAppxManifestTargetDeviceFamiliesEnumerator> targetDeviceFamiliesIter;
THROW_IF_FAILED(manifestReader3->GetTargetDeviceFamilies(&targetDeviceFamiliesIter));
BOOL hasCurrent = FALSE;
THROW_IF_FAILED(targetDeviceFamiliesIter->GetHasCurrent(&hasCurrent));
while (hasCurrent)
{
ComPtr<IAppxManifestTargetDeviceFamily> targetDeviceFamily;
THROW_IF_FAILED(targetDeviceFamiliesIter->GetCurrent(&targetDeviceFamily));
targetDeviceFamilies.emplace_back(std::move(targetDeviceFamily));
THROW_IF_FAILED(targetDeviceFamiliesIter->MoveNext(&hasCurrent));
}
return targetDeviceFamilies;
}
std::string MsixPackageManifestTargetDeviceFamily::GetName() const
{
wil::unique_cotaskmem_string name;
THROW_IF_FAILED(m_targetDeviceFamily->GetName(&name));
return Utility::ConvertToUTF8(name.get());
}
OSVersion MsixPackageManifestTargetDeviceFamily::GetMinVersion() const
{
UINT64 minVersion = 0;
THROW_IF_FAILED(m_targetDeviceFamily->GetMinVersion(&minVersion));
return OSVersion{ minVersion };
}
MsixPackageManifestTargetDeviceFamily::Platform MsixPackageManifestTargetDeviceFamily::GetPlatform() const
{
auto name = GetName();
if (Utility::CaseInsensitiveEquals(name, WindowsDesktopName))
{
return WindowsDesktop;
}
if (Utility::CaseInsensitiveEquals(name, WindowsUniversalName))
{
return WindowsUniversal;
}
return Other;
}
}