aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/pseudobundle.cpp
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-04-22 17:06:54 -0700
committerRob Mensching <rob@firegiant.com>2021-04-29 16:36:06 -0700
commitaf10c45d7b3a44af0b461a557847fe03263dcc10 (patch)
tree6a5c1532304782c36ffe4200b38f3afb76789a43 /src/burn/engine/pseudobundle.cpp
parent9c2aed97299fb96aeee3f1471ce40225437aaecf (diff)
downloadwix-af10c45d7b3a44af0b461a557847fe03263dcc10.tar.gz
wix-af10c45d7b3a44af0b461a557847fe03263dcc10.tar.bz2
wix-af10c45d7b3a44af0b461a557847fe03263dcc10.zip
Move burn into burn
Diffstat (limited to 'src/burn/engine/pseudobundle.cpp')
-rw-r--r--src/burn/engine/pseudobundle.cpp241
1 files changed, 241 insertions, 0 deletions
diff --git a/src/burn/engine/pseudobundle.cpp b/src/burn/engine/pseudobundle.cpp
new file mode 100644
index 00000000..180cc621
--- /dev/null
+++ b/src/burn/engine/pseudobundle.cpp
@@ -0,0 +1,241 @@
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
6extern "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 BOOL fCached,
14 __in_z LPCWSTR wzFilePath,
15 __in_z LPCWSTR wzLocalSource,
16 __in_z_opt LPCWSTR wzDownloadSource,
17 __in DWORD64 qwSize,
18 __in BOOL fVital,
19 __in_z_opt LPCWSTR wzInstallArguments,
20 __in_z_opt LPCWSTR wzRepairArguments,
21 __in_z_opt LPCWSTR wzUninstallArguments,
22 __in_opt BURN_DEPENDENCY_PROVIDER* pDependencyProvider,
23 __in_opt const BYTE* pbHash,
24 __in const DWORD cbHash
25 )
26{
27 HRESULT hr = S_OK;
28 LPWSTR sczRelationTypeCommandLineSwitch = NULL;
29 BURN_PAYLOAD* pPayload = NULL;
30
31 LPCWSTR wzRelationTypeCommandLine = CoreRelationTypeToCommandLineString(relationType);
32 if (wzRelationTypeCommandLine)
33 {
34 hr = StrAllocFormatted(&sczRelationTypeCommandLineSwitch, L" -%ls", wzRelationTypeCommandLine);
35 }
36
37 // Initialize the single payload, and fill out all the necessary fields
38 pPackage->payloads.rgItems = (BURN_PAYLOAD_GROUP_ITEM*)MemAlloc(sizeof(BURN_PAYLOAD_GROUP_ITEM), TRUE);
39 ExitOnNull(pPackage->payloads.rgItems, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload group inside of related bundle struct");
40 pPackage->payloads.cItems = 1;
41
42 pPayload = (BURN_PAYLOAD*)MemAlloc(sizeof(BURN_PAYLOAD), TRUE);
43 ExitOnNull(pPayload, hr, E_OUTOFMEMORY, "Failed to allocate space for burn payload inside of related bundle struct");
44 pPackage->payloads.rgItems[0].pPayload = pPayload;
45 pPayload->packaging = BURN_PAYLOAD_PACKAGING_EXTERNAL;
46 pPayload->qwFileSize = qwSize;
47
48 hr = StrAllocString(&pPayload->sczKey, wzId, 0);
49 ExitOnFailure(hr, "Failed to copy key for pseudo bundle payload.");
50
51 hr = StrAllocString(&pPayload->sczFilePath, wzFilePath, 0);
52 ExitOnFailure(hr, "Failed to copy filename for pseudo bundle.");
53
54 hr = StrAllocString(&pPayload->sczSourcePath, wzLocalSource, 0);
55 ExitOnFailure(hr, "Failed to copy local source path for pseudo bundle.");
56
57 if (wzDownloadSource && *wzDownloadSource)
58 {
59 hr = StrAllocString(&pPayload->downloadSource.sczUrl, wzDownloadSource, 0);
60 ExitOnFailure(hr, "Failed to copy download source for pseudo bundle.");
61 }
62
63 if (pbHash)
64 {
65 pPayload->pbHash = static_cast<BYTE*>(MemAlloc(cbHash, FALSE));
66 ExitOnNull(pPayload->pbHash, hr, E_OUTOFMEMORY, "Failed to allocate memory for pseudo bundle payload hash.");
67
68 pPayload->cbHash = cbHash;
69 memcpy_s(pPayload->pbHash, pPayload->cbHash, pbHash, cbHash);
70 }
71
72 pPackage->Exe.fPseudoBundle = TRUE;
73
74 pPackage->type = BURN_PACKAGE_TYPE_EXE;
75 pPackage->fPerMachine = fPerMachine;
76 pPackage->currentState = state;
77 pPackage->fCached = fCached;
78 pPackage->qwInstallSize = qwSize;
79 pPackage->qwSize = qwSize;
80 pPackage->fVital = fVital;
81
82 hr = StrAllocString(&pPackage->sczId, wzId, 0);
83 ExitOnFailure(hr, "Failed to copy key for pseudo bundle.");
84
85 hr = StrAllocString(&pPackage->sczCacheId, wzId, 0);
86 ExitOnFailure(hr, "Failed to copy cache id for pseudo bundle.");
87
88 // If we are a self updating bundle, we don't have to have Install arguments.
89 if (wzInstallArguments)
90 {
91 hr = StrAllocString(&pPackage->Exe.sczInstallArguments, wzInstallArguments, 0);
92 ExitOnFailure(hr, "Failed to copy install arguments for related bundle package");
93 }
94
95 if (sczRelationTypeCommandLineSwitch)
96 {
97 hr = StrAllocConcat(&pPackage->Exe.sczInstallArguments, sczRelationTypeCommandLineSwitch, 0);
98 ExitOnFailure(hr, "Failed to append relation type to install arguments for related bundle package");
99 }
100
101 if (wzRepairArguments)
102 {
103 hr = StrAllocString(&pPackage->Exe.sczRepairArguments, wzRepairArguments, 0);
104 ExitOnFailure(hr, "Failed to copy repair arguments for related bundle package");
105
106 if (sczRelationTypeCommandLineSwitch)
107 {
108 hr = StrAllocConcat(&pPackage->Exe.sczRepairArguments, sczRelationTypeCommandLineSwitch, 0);
109 ExitOnFailure(hr, "Failed to append relation type to repair arguments for related bundle package");
110 }
111
112 pPackage->Exe.fRepairable = TRUE;
113 }
114
115 if (wzUninstallArguments)
116 {
117 hr = StrAllocString(&pPackage->Exe.sczUninstallArguments, wzUninstallArguments, 0);
118 ExitOnFailure(hr, "Failed to copy uninstall arguments for related bundle package");
119
120 if (sczRelationTypeCommandLineSwitch)
121 {
122 hr = StrAllocConcat(&pPackage->Exe.sczUninstallArguments, sczRelationTypeCommandLineSwitch, 0);
123 ExitOnFailure(hr, "Failed to append relation type to uninstall arguments for related bundle package");
124 }
125
126 pPackage->fUninstallable = TRUE;
127 }
128
129 // 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).
130 pPackage->Exe.protocol = (FILEMAKEVERSION(3, 6, 2221, 0) <= qwEngineVersion && qwEngineVersion <= FILEMAKEVERSION(rmj, rmm, rup, rpr)) ? BURN_EXE_PROTOCOL_TYPE_BURN : BURN_EXE_PROTOCOL_TYPE_NONE;
131
132 // All versions of Burn past v3.9 RTM support suppressing ancestors.
133 pPackage->Exe.fSupportsAncestors = FILEMAKEVERSION(3, 9, 1006, 0) <= qwEngineVersion;
134
135 if (pDependencyProvider)
136 {
137 pPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE);
138 ExitOnNull(pPackage->rgDependencyProviders, hr, E_OUTOFMEMORY, "Failed to allocate memory for dependency providers.");
139 pPackage->cDependencyProviders = 1;
140
141 pPackage->rgDependencyProviders[0].fImported = pDependencyProvider->fImported;
142
143 hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczKey, pDependencyProvider->sczKey, 0);
144 ExitOnFailure(hr, "Failed to copy key for pseudo bundle.");
145
146 hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczVersion, pDependencyProvider->sczVersion, 0);
147 ExitOnFailure(hr, "Failed to copy version for pseudo bundle.");
148
149 hr = StrAllocString(&pPackage->rgDependencyProviders[0].sczDisplayName, pDependencyProvider->sczDisplayName, 0);
150 ExitOnFailure(hr, "Failed to copy display name for pseudo bundle.");
151 }
152
153LExit:
154 ReleaseStr(sczRelationTypeCommandLineSwitch);
155
156 return hr;
157}
158
159extern "C" HRESULT PseudoBundleInitializePassthrough(
160 __in BURN_PACKAGE* pPassthroughPackage,
161 __in BOOTSTRAPPER_COMMAND* pCommand,
162 __in_z_opt LPCWSTR wzAppendLogPath,
163 __in_z_opt LPCWSTR wzActiveParent,
164 __in_z_opt LPCWSTR wzAncestors,
165 __in BURN_PACKAGE* pPackage
166 )
167{
168 Assert(BURN_PACKAGE_TYPE_EXE == pPackage->type);
169
170 HRESULT hr = S_OK;
171 LPWSTR sczArguments = NULL;
172
173 // Initialize the payloads, and copy the necessary fields.
174 pPassthroughPackage->payloads.rgItems = (BURN_PAYLOAD_GROUP_ITEM*)MemAlloc(sizeof(BURN_PAYLOAD_GROUP_ITEM) * pPackage->payloads.cItems, TRUE);
175 ExitOnNull(pPassthroughPackage->payloads.rgItems, hr, E_OUTOFMEMORY, "Failed to allocate space for burn package payload inside of passthrough bundle.");
176 pPassthroughPackage->payloads.cItems = pPackage->payloads.cItems;
177
178 for (DWORD iPayload = 0; iPayload < pPackage->payloads.cItems; ++iPayload)
179 {
180 pPassthroughPackage->payloads.rgItems[iPayload].pPayload = pPackage->payloads.rgItems[iPayload].pPayload;
181 }
182
183 pPassthroughPackage->Exe.fPseudoBundle = TRUE;
184
185 pPassthroughPackage->fPerMachine = FALSE; // passthrough bundles are always launched per-user.
186 pPassthroughPackage->type = pPackage->type;
187 pPassthroughPackage->currentState = pPackage->currentState;
188 pPassthroughPackage->fCached = pPackage->fCached;
189 pPassthroughPackage->qwInstallSize = pPackage->qwInstallSize;
190 pPassthroughPackage->qwSize = pPackage->qwSize;
191 pPassthroughPackage->fVital = pPackage->fVital;
192
193 hr = StrAllocString(&pPassthroughPackage->sczId, pPackage->sczId, 0);
194 ExitOnFailure(hr, "Failed to copy key for passthrough pseudo bundle.");
195
196 hr = StrAllocString(&pPassthroughPackage->sczCacheId, pPackage->sczCacheId, 0);
197 ExitOnFailure(hr, "Failed to copy cache id for passthrough pseudo bundle.");
198
199 pPassthroughPackage->Exe.protocol = pPackage->Exe.protocol;
200
201 // No matter the operation, we're passing the same command-line. That's what makes
202 // this a passthrough bundle.
203 hr = CoreRecreateCommandLine(&sczArguments, pCommand->action, pCommand->display, pCommand->restart, pCommand->relationType, TRUE, wzActiveParent, wzAncestors, wzAppendLogPath, pCommand->wzCommandLine);
204 ExitOnFailure(hr, "Failed to recreate command-line arguments.");
205
206 hr = StrAllocString(&pPassthroughPackage->Exe.sczInstallArguments, sczArguments, 0);
207 ExitOnFailure(hr, "Failed to copy install arguments for passthrough bundle package");
208
209 hr = StrAllocString(&pPassthroughPackage->Exe.sczRepairArguments, sczArguments, 0);
210 ExitOnFailure(hr, "Failed to copy related arguments for passthrough bundle package");
211
212 pPassthroughPackage->Exe.fRepairable = TRUE;
213
214 hr = StrAllocString(&pPassthroughPackage->Exe.sczUninstallArguments, sczArguments, 0);
215 ExitOnFailure(hr, "Failed to copy uninstall arguments for passthrough bundle package");
216
217 pPassthroughPackage->fUninstallable = TRUE;
218
219 // TODO: consider bringing this back in the near future.
220 //if (pDependencyProvider)
221 //{
222 // pPassthroughPackage->rgDependencyProviders = (BURN_DEPENDENCY_PROVIDER*)MemAlloc(sizeof(BURN_DEPENDENCY_PROVIDER), TRUE);
223 // ExitOnNull(pPassthroughPackage->rgDependencyProviders, hr, E_OUTOFMEMORY, "Failed to allocate memory for dependency providers.");
224 // pPassthroughPackage->cDependencyProviders = 1;
225
226 // pPassthroughPackage->rgDependencyProviders[0].fImported = pDependencyProvider->fImported;
227
228 // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczKey, pDependencyProvider->sczKey, 0);
229 // ExitOnFailure(hr, "Failed to copy key for pseudo bundle.");
230
231 // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczVersion, pDependencyProvider->sczVersion, 0);
232 // ExitOnFailure(hr, "Failed to copy version for pseudo bundle.");
233
234 // hr = StrAllocString(&pPassthroughPackage->rgDependencyProviders[0].sczDisplayName, pDependencyProvider->sczDisplayName, 0);
235 // ExitOnFailure(hr, "Failed to copy display name for pseudo bundle.");
236 //}
237
238LExit:
239 ReleaseStr(sczArguments);
240 return hr;
241}