diff options
Diffstat (limited to 'src/engine/pseudobundle.cpp')
-rw-r--r-- | src/engine/pseudobundle.cpp | 271 |
1 files changed, 271 insertions, 0 deletions
diff --git a/src/engine/pseudobundle.cpp b/src/engine/pseudobundle.cpp new file mode 100644 index 00000000..ebdc040a --- /dev/null +++ b/src/engine/pseudobundle.cpp | |||
@@ -0,0 +1,271 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | |||
6 | extern "C" HRESULT PseudoBundleInitialize( | ||
7 | __in DWORD64 qwEngineVersion, | ||
8 | __in BURN_PACKAGE* pPackage, | ||
9 | __in BOOL fPerMachine, | ||
10 | __in_z LPCWSTR wzId, | ||
11 | __in BOOTSTRAPPER_RELATION_TYPE relationType, | ||
12 | __in BOOTSTRAPPER_PACKAGE_STATE state, | ||
13 | __in_z LPCWSTR wzFilePath, | ||
14 | __in_z LPCWSTR wzLocalSource, | ||
15 | __in_z_opt LPCWSTR wzDownloadSource, | ||
16 | __in DWORD64 qwSize, | ||
17 | __in BOOL fVital, | ||
18 | __in_z_opt LPCWSTR wzInstallArguments, | ||
19 | __in_z_opt LPCWSTR wzRepairArguments, | ||
20 | __in_z_opt LPCWSTR wzUninstallArguments, | ||
21 | __in_opt BURN_DEPENDENCY_PROVIDER* pDependencyProvider, | ||
22 | __in_opt BYTE* pbHash, | ||
23 | __in DWORD cbHash | ||
24 | ) | ||
25 | { | ||
26 | HRESULT hr = S_OK; | ||
27 | LPWSTR sczRelationTypeCommandLineSwitch = NULL; | ||
28 | |||
29 | LPCWSTR wzRelationTypeCommandLine = CoreRelationTypeToCommandLineString(relationType); | ||
30 | if (wzRelationTypeCommandLine) | ||
31 | { | ||
32 | hr = StrAllocFormatted(&sczRelationTypeCommandLineSwitch, L" -%ls", wzRelationTypeCommandLine); | ||
33 | } | ||
34 | |||
35 | // Initialize the single payload, and fill out all the necessary fields | ||
36 | pPackage->rgPayloads = (BURN_PACKAGE_PAYLOAD *)MemAlloc(sizeof(BURN_PACKAGE_PAYLOAD), TRUE); | ||
37 | ExitOnNull(pPackage->rgPayloads, hr, E_OUTOFMEMORY, "Failed to allocate space for burn package payload inside of related bundle struct"); | ||
38 | pPackage->cPayloads = 1; | ||
39 | |||
40 | pPackage->rgPayloads->pPayload = (BURN_PAYLOAD *)MemAlloc(sizeof(BURN_PAYLOAD), TRUE); | ||
41 | ExitOnNull(pPackage->rgPayloads, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload inside of related bundle struct"); | ||
42 | pPackage->rgPayloads->pPayload->packaging = BURN_PAYLOAD_PACKAGING_EXTERNAL; | ||
43 | pPackage->rgPayloads->pPayload->qwFileSize = qwSize; | ||
44 | |||
45 | hr = StrAllocString(&pPackage->rgPayloads->pPayload->sczKey, wzId, 0); | ||
46 | ExitOnFailure(hr, "Failed to copy key for pseudo bundle payload."); | ||
47 | |||
48 | hr = StrAllocString(&pPackage->rgPayloads->pPayload->sczFilePath, wzFilePath, 0); | ||
49 | ExitOnFailure(hr, "Failed to copy filename for pseudo bundle."); | ||
50 | |||
51 | hr = StrAllocString(&pPackage->rgPayloads->pPayload->sczSourcePath, wzLocalSource, 0); | ||
52 | ExitOnFailure(hr, "Failed to copy local source path for pseudo bundle."); | ||
53 | |||
54 | if (wzDownloadSource && *wzDownloadSource) | ||
55 | { | ||
56 | hr = StrAllocString(&pPackage->rgPayloads->pPayload->downloadSource.sczUrl, wzDownloadSource, 0); | ||
57 | ExitOnFailure(hr, "Failed to copy download source for pseudo bundle."); | ||
58 | } | ||
59 | |||
60 | if (pbHash) | ||
61 | { | ||
62 | pPackage->rgPayloads->pPayload->pbHash = static_cast<BYTE*>(MemAlloc(cbHash, FALSE)); | ||
63 | ExitOnNull(pPackage->rgPayloads->pPayload->pbHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for pseudo bundle payload hash."); | ||
64 | |||
65 | pPackage->rgPayloads->pPayload->cbHash = cbHash; | ||
66 | memcpy_s(pPackage->rgPayloads->pPayload->pbHash, pPackage->rgPayloads->pPayload->cbHash, pbHash, cbHash); | ||
67 | } | ||
68 | |||
69 | pPackage->rgPayloads->fCached = (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_CACHED == state); | ||
70 | |||
71 | pPackage->Exe.fPseudoBundle = TRUE; | ||
72 | |||
73 | pPackage->type = BURN_PACKAGE_TYPE_EXE; | ||
74 | pPackage->fPerMachine = fPerMachine; | ||
75 | pPackage->currentState = state; | ||
76 | pPackage->cache = (BOOTSTRAPPER_PACKAGE_STATE_PRESENT == state || BOOTSTRAPPER_PACKAGE_STATE_CACHED == state) ? BURN_CACHE_STATE_COMPLETE : BURN_CACHE_STATE_NONE; | ||
77 | pPackage->qwInstallSize = qwSize; | ||
78 | pPackage->qwSize = qwSize; | ||
79 | pPackage->fVital = fVital; | ||
80 | |||
81 | hr = StrAllocString(&pPackage->sczId, wzId, 0); | ||
82 | ExitOnFailure(hr, "Failed to copy key for pseudo bundle."); | ||
83 | |||
84 | hr = StrAllocString(&pPackage->sczCacheId, wzId, 0); | ||
85 | ExitOnFailure(hr, "Failed to copy cache id for pseudo bundle."); | ||
86 | |||
87 | // If we are a self updating bundle, we don't have to have Install arguments. | ||
88 | if (wzInstallArguments) | ||
89 | { | ||
90 | hr = StrAllocString(&pPackage->Exe.sczInstallArguments, wzInstallArguments, 0); | ||
91 | ExitOnFailure(hr, "Failed to copy install arguments for related bundle package"); | ||
92 | } | ||
93 | |||
94 | if (sczRelationTypeCommandLineSwitch) | ||
95 | { | ||
96 | hr = StrAllocConcat(&pPackage->Exe.sczInstallArguments, sczRelationTypeCommandLineSwitch, 0); | ||
97 | ExitOnFailure(hr, "Failed to append relation type to install arguments for related bundle package"); | ||
98 | } | ||
99 | |||
100 | if (wzRepairArguments) | ||
101 | { | ||
102 | hr = StrAllocString(&pPackage->Exe.sczRepairArguments, wzRepairArguments, 0); | ||
103 | ExitOnFailure(hr, "Failed to copy repair arguments for related bundle package"); | ||
104 | |||
105 | if (sczRelationTypeCommandLineSwitch) | ||
106 | { | ||
107 | hr = StrAllocConcat(&pPackage->Exe.sczRepairArguments, sczRelationTypeCommandLineSwitch, 0); | ||
108 | ExitOnFailure(hr, "Failed to append relation type to repair arguments for related bundle package"); | ||
109 | } | ||
110 | |||
111 | pPackage->Exe.fRepairable = TRUE; | ||
112 | } | ||
113 | |||
114 | if (wzUninstallArguments) | ||
115 | { | ||
116 | hr = StrAllocString(&pPackage->Exe.sczUninstallArguments, wzUninstallArguments, 0); | ||
117 | ExitOnFailure(hr, "Failed to copy uninstall arguments for related bundle package"); | ||
118 | |||
119 | if (sczRelationTypeCommandLineSwitch) | ||
120 | { | ||
121 | hr = StrAllocConcat(&pPackage->Exe.sczUninstallArguments, sczRelationTypeCommandLineSwitch, 0); | ||
122 | ExitOnFailure(hr, "Failed to append relation type to uninstall arguments for related bundle package"); | ||
123 | } | ||
124 | |||
125 | pPackage->fUninstallable = TRUE; | ||
126 | } | ||
127 | |||
128 | // Only support progress from engines that are compatible (aka: version greater than or equal to last protocol breaking change *and* versions that are older or the same as this engine). | ||
129 | pPackage->Exe.protocol = (FILEMAKEVERSION(3, 6, 2221, 0) <= qwEngineVersion && qwEngineVersion <= FILEMAKEVERSION(rmj, rmm, rup, 0)) ? BURN_EXE_PROTOCOL_TYPE_BURN : BURN_EXE_PROTOCOL_TYPE_NONE; | ||
130 | |||
131 | // All versions of Burn past v3.9 RTM support suppressing ancestors. | ||
132 | pPackage->Exe.fSupportsAncestors = FILEMAKEVERSION(3, 9, 1006, 0) <= qwEngineVersion; | ||
133 | |||
134 | if (pDependencyProvider) | ||
135 | { | ||
136 | pPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE); | ||
137 | ExitOnNull(pPackage->rgDependencyProviders, hr, E_OUTOFMEMORY, "Failed to allocate memory for dependency providers."); | ||
138 | pPackage->cDependencyProviders = 1; | ||
139 | |||
140 | pPackage->rgDependencyProviders[0].fImported = pDependencyProvider->fImported; | ||
141 | |||
142 | hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczKey, pDependencyProvider->sczKey, 0); | ||
143 | ExitOnFailure(hr, "Failed to copy key for pseudo bundle."); | ||
144 | |||
145 | hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczVersion, pDependencyProvider->sczVersion, 0); | ||
146 | ExitOnFailure(hr, "Failed to copy version for pseudo bundle."); | ||
147 | |||
148 | hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczDisplayName, pDependencyProvider->sczDisplayName, 0); | ||
149 | ExitOnFailure(hr, "Failed to copy display name for pseudo bundle."); | ||
150 | } | ||
151 | |||
152 | LExit: | ||
153 | ReleaseStr(sczRelationTypeCommandLineSwitch); | ||
154 | |||
155 | return hr; | ||
156 | } | ||
157 | |||
158 | extern "C" HRESULT PseudoBundleInitializePassthrough( | ||
159 | __in BURN_PACKAGE* pPassthroughPackage, | ||
160 | __in BOOTSTRAPPER_COMMAND* pCommand, | ||
161 | __in_z_opt LPCWSTR wzAppendLogPath, | ||
162 | __in_z_opt LPWSTR wzActiveParent, | ||
163 | __in_z_opt LPWSTR wzAncestors, | ||
164 | __in BURN_PACKAGE* pPackage | ||
165 | ) | ||
166 | { | ||
167 | Assert(BURN_PACKAGE_TYPE_EXE == pPackage->type); | ||
168 | |||
169 | HRESULT hr = S_OK; | ||
170 | LPWSTR sczArguments = NULL; | ||
171 | |||
172 | // Initialize the payloads, and copy the necessary fields. | ||
173 | pPassthroughPackage->rgPayloads = (BURN_PACKAGE_PAYLOAD *)MemAlloc(sizeof(BURN_PACKAGE_PAYLOAD) * pPackage->cPayloads, TRUE); | ||
174 | ExitOnNull(pPassthroughPackage->rgPayloads, hr, E_OUTOFMEMORY, "Failed to allocate space for burn package payload inside of passthrough bundle."); | ||
175 | pPassthroughPackage->cPayloads = pPackage->cPayloads; | ||
176 | |||
177 | for (DWORD iPayload = 0; iPayload < pPackage->cPayloads; ++iPayload) | ||
178 | { | ||
179 | BURN_PACKAGE_PAYLOAD* pPayload = pPackage->rgPayloads + iPayload; | ||
180 | |||
181 | pPassthroughPackage->rgPayloads[iPayload].pPayload = (BURN_PAYLOAD *)MemAlloc(sizeof(BURN_PAYLOAD), TRUE); | ||
182 | ExitOnNull(pPassthroughPackage->rgPayloads[iPayload].pPayload, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload inside of related bundle struct"); | ||
183 | pPassthroughPackage->rgPayloads[iPayload].pPayload->packaging = pPayload->pPayload->packaging; | ||
184 | pPassthroughPackage->rgPayloads[iPayload].pPayload->qwFileSize = pPayload->pPayload->qwFileSize; | ||
185 | |||
186 | hr = StrAllocString(&pPassthroughPackage->rgPayloads[iPayload].pPayload->sczKey, pPayload->pPayload->sczKey, 0); | ||
187 | ExitOnFailure(hr, "Failed to copy key for passthrough pseudo bundle payload."); | ||
188 | |||
189 | hr = StrAllocString(&pPassthroughPackage->rgPayloads[iPayload].pPayload->sczFilePath, pPayload->pPayload->sczFilePath, 0); | ||
190 | ExitOnFailure(hr, "Failed to copy filename for passthrough pseudo bundle."); | ||
191 | |||
192 | hr = StrAllocString(&pPassthroughPackage->rgPayloads[iPayload].pPayload->sczSourcePath, pPayload->pPayload->sczSourcePath, 0); | ||
193 | ExitOnFailure(hr, "Failed to copy local source path for passthrough pseudo bundle."); | ||
194 | |||
195 | if (pPayload->pPayload->downloadSource.sczUrl) | ||
196 | { | ||
197 | hr = StrAllocString(&pPassthroughPackage->rgPayloads[iPayload].pPayload->downloadSource.sczUrl, pPayload->pPayload->downloadSource.sczUrl, 0); | ||
198 | ExitOnFailure(hr, "Failed to copy download source for passthrough pseudo bundle."); | ||
199 | } | ||
200 | |||
201 | if (pPayload->pPayload->pbHash) | ||
202 | { | ||
203 | pPassthroughPackage->rgPayloads[iPayload].pPayload->pbHash = static_cast<BYTE*>(MemAlloc(pPayload->pPayload->cbHash, FALSE)); | ||
204 | ExitOnNull(pPassthroughPackage->rgPayloads[iPayload].pPayload->pbHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for pseudo bundle payload hash."); | ||
205 | |||
206 | pPassthroughPackage->rgPayloads[iPayload].pPayload->cbHash = pPayload->pPayload->cbHash; | ||
207 | memcpy_s(pPassthroughPackage->rgPayloads[iPayload].pPayload->pbHash, pPassthroughPackage->rgPayloads[iPayload].pPayload->cbHash, pPayload->pPayload->pbHash, pPayload->pPayload->cbHash); | ||
208 | } | ||
209 | |||
210 | pPassthroughPackage->rgPayloads[iPayload].fCached = pPayload->fCached; | ||
211 | } | ||
212 | |||
213 | pPassthroughPackage->Exe.fPseudoBundle = TRUE; | ||
214 | |||
215 | pPassthroughPackage->fPerMachine = FALSE; // passthrough bundles are always launched per-user. | ||
216 | pPassthroughPackage->type = pPackage->type; | ||
217 | pPassthroughPackage->currentState = pPackage->currentState; | ||
218 | pPassthroughPackage->cache = pPackage->cache; | ||
219 | pPassthroughPackage->qwInstallSize = pPackage->qwInstallSize; | ||
220 | pPassthroughPackage->qwSize = pPackage->qwSize; | ||
221 | pPassthroughPackage->fVital = pPackage->fVital; | ||
222 | |||
223 | hr = StrAllocString(&pPassthroughPackage->sczId, pPackage->sczId, 0); | ||
224 | ExitOnFailure(hr, "Failed to copy key for passthrough pseudo bundle."); | ||
225 | |||
226 | hr = StrAllocString(&pPassthroughPackage->sczCacheId, pPackage->sczCacheId, 0); | ||
227 | ExitOnFailure(hr, "Failed to copy cache id for passthrough pseudo bundle."); | ||
228 | |||
229 | pPassthroughPackage->Exe.protocol = pPackage->Exe.protocol; | ||
230 | |||
231 | // No matter the operation, we're passing the same command-line. That's what makes | ||
232 | // this a passthrough bundle. | ||
233 | hr = CoreRecreateCommandLine(&sczArguments, pCommand->action, pCommand->display, pCommand->restart, pCommand->relationType, TRUE, wzActiveParent, wzAncestors, wzAppendLogPath, pCommand->wzCommandLine); | ||
234 | ExitOnFailure(hr, "Failed to recreate command-line arguments."); | ||
235 | |||
236 | hr = StrAllocString(&pPassthroughPackage->Exe.sczInstallArguments, sczArguments, 0); | ||
237 | ExitOnFailure(hr, "Failed to copy install arguments for passthrough bundle package"); | ||
238 | |||
239 | hr = StrAllocString(&pPassthroughPackage->Exe.sczRepairArguments, sczArguments, 0); | ||
240 | ExitOnFailure(hr, "Failed to copy related arguments for passthrough bundle package"); | ||
241 | |||
242 | pPassthroughPackage->Exe.fRepairable = TRUE; | ||
243 | |||
244 | hr = StrAllocString(&pPassthroughPackage->Exe.sczUninstallArguments, sczArguments, 0); | ||
245 | ExitOnFailure(hr, "Failed to copy uninstall arguments for passthrough bundle package"); | ||
246 | |||
247 | pPassthroughPackage->fUninstallable = TRUE; | ||
248 | |||
249 | // TODO: consider bringing this back in the near future. | ||
250 | //if (pDependencyProvider) | ||
251 | //{ | ||
252 | // pPassthroughPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE); | ||
253 | // ExitOnNull(pPassthroughPackage->rgDependencyProviders, hr, E_OUTOFMEMORY, "Failed to allocate memory for dependency providers."); | ||
254 | // pPassthroughPackage->cDependencyProviders = 1; | ||
255 | |||
256 | // pPassthroughPackage->rgDependencyProviders[0].fImported = pDependencyProvider->fImported; | ||
257 | |||
258 | // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczKey, pDependencyProvider->sczKey, 0); | ||
259 | // ExitOnFailure(hr, "Failed to copy key for pseudo bundle."); | ||
260 | |||
261 | // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczVersion, pDependencyProvider->sczVersion, 0); | ||
262 | // ExitOnFailure(hr, "Failed to copy version for pseudo bundle."); | ||
263 | |||
264 | // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczDisplayName, pDependencyProvider->sczDisplayName, 0); | ||
265 | // ExitOnFailure(hr, "Failed to copy display name for pseudo bundle."); | ||
266 | //} | ||
267 | |||
268 | LExit: | ||
269 | ReleaseStr(sczArguments); | ||
270 | return hr; | ||
271 | } | ||