-
Notifications
You must be signed in to change notification settings - Fork 329
/
MsixDynamicDependency.cpp
197 lines (158 loc) · 7.01 KB
/
MsixDynamicDependency.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
#include "pch.h"
#include "msixdynamicdependency.h"
#include "MddDetourPackageGraph.h"
#include "PackageDependencyManager.h"
#include "PackageGraphManager.h"
#include "MddWin11.h"
STDAPI MddTryCreatePackageDependency(
PSID user,
_In_ PCWSTR packageFamilyName,
PACKAGE_VERSION minVersion,
MddPackageDependencyProcessorArchitectures packageDependencyProcessorArchitectures,
MddPackageDependencyLifetimeKind lifetimeKind,
PCWSTR lifetimeArtifact,
MddCreatePackageDependencyOptions options,
_Outptr_result_maybenull_ PWSTR* packageDependencyId) noexcept try
{
*packageDependencyId = nullptr;
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
RETURN_IF_FAILED(MddCore::Win11::TryCreatePackageDependency(user, packageFamilyName,
minVersion, packageDependencyProcessorArchitectures, lifetimeKind, lifetimeArtifact,
options, packageDependencyId));
return S_OK;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
MddCore::PackageDependencyManager::CreatePackageDependency(user, packageFamilyName, minVersion, packageDependencyProcessorArchitectures, lifetimeKind, lifetimeArtifact, options, packageDependencyId);
return S_OK;
}
CATCH_RETURN();
STDAPI_(void) MddDeletePackageDependency(
_In_ PCWSTR packageDependencyId) noexcept try
{
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
MddCore::Win11::DeletePackageDependency(packageDependencyId);
return;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
MddCore::PackageDependencyManager::DeletePackageDependency(packageDependencyId);
}
CATCH_LOG();
STDAPI MddAddPackageDependency(
_In_ PCWSTR packageDependencyId,
INT32 rank,
MddAddPackageDependencyOptions options,
_Out_ MDD_PACKAGEDEPENDENCY_CONTEXT* packageDependencyContext,
_Outptr_opt_result_maybenull_ PWSTR* packageFullName) noexcept try
{
*packageDependencyContext = nullptr;
if (packageFullName)
{
*packageFullName = nullptr;
}
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
RETURN_IF_FAILED(MddCore::Win11::AddPackageDependency(packageDependencyId, rank, options, packageDependencyContext, packageFullName));
return S_OK;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
RETURN_IF_FAILED(MddCore::PackageGraphManager::AddToPackageGraph(packageDependencyId, rank, options, packageDependencyContext, packageFullName));
return S_OK;
}
CATCH_RETURN();
STDAPI_(void) MddRemovePackageDependency(
_In_ MDD_PACKAGEDEPENDENCY_CONTEXT packageDependencyContext) noexcept try
{
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
MddCore::Win11::RemovePackageDependency(packageDependencyContext);
return;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
LOG_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
MddCore::PackageGraphManager::RemoveFromPackageGraph(packageDependencyContext);
}
CATCH_LOG();
STDAPI MddGetResolvedPackageFullNameForPackageDependency(
_In_ PCWSTR packageDependencyId,
_Outptr_result_maybenull_ PWSTR* packageFullName) noexcept try
{
*packageFullName = nullptr;
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
RETURN_IF_FAILED(MddCore::Win11::GetResolvedPackageFullNameForPackageDependency(packageDependencyId, packageFullName));
return S_OK;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
RETURN_HR_IF(E_INVALIDARG, !packageDependencyId || (packageDependencyId[0] == L'\0'));
wil::unique_process_heap_string fullName;
RETURN_IF_FAILED(MddCore::PackageGraphManager::GetResolvedPackageDependency(packageDependencyId, fullName));
*packageFullName = fullName.release();
return S_OK;
}
CATCH_RETURN();
STDAPI MddGetResolvedPackageFullNameForPackageDependency2(
_In_ PCWSTR packageDependencyId,
_Outptr_result_maybenull_ PWSTR* packageFullName) noexcept try
{
*packageFullName = nullptr;
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
RETURN_IF_FAILED(MddCore::Win11::GetResolvedPackageFullNameForPackageDependency2(packageDependencyId, packageFullName));
return S_OK;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
RETURN_HR_IF(E_INVALIDARG, !packageDependencyId || (packageDependencyId[0] == L'\0'));
wil::unique_process_heap_string fullName;
RETURN_IF_FAILED(MddCore::PackageGraphManager::GetResolvedPackageDependency2(packageDependencyId, fullName));
*packageFullName = fullName.release();
return S_OK;
}
CATCH_RETURN();
STDAPI MddGetIdForPackageDependencyContext(
_In_ MDD_PACKAGEDEPENDENCY_CONTEXT packageDependencyContext,
_Outptr_result_maybenull_ PWSTR* packageDependencyId) noexcept try
{
*packageDependencyId = nullptr;
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
RETURN_IF_FAILED(MddCore::Win11::GetIdForPackageDependencyContext(packageDependencyContext, packageDependencyId));
return S_OK;
}
// WinAppSDK's Dynamic Dependencies requires a non-packaged process
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED), AppModel::Identity::IsPackagedProcess());
RETURN_HR_IF(E_INVALIDARG, !packageDependencyContext);
wil::unique_process_heap_string id;
RETURN_IF_FAILED(MddCore::PackageGraphManager::GetPackageDependencyForContext(packageDependencyContext, id));
*packageDependencyId = id.release();
return S_OK;
}
CATCH_RETURN();
STDAPI_(UINT32) MddGetPackageGraphRevisionId() noexcept
{
// Use the Win11 APIs if available (instead of Detour'ing to our own implementation)
if (MddCore::Win11::IsSupported())
{
return MddCore::Win11::GetPackageGraphRevisionId();
}
return MddCore::PackageGraphManager::GetPackageGraphRevisionId();
}
STDAPI_(UINT32) MddGetGenerationId() noexcept
{
return MddGetPackageGraphRevisionId();
}