aboutsummaryrefslogtreecommitdiff
path: root/src/burn/engine/manifest.cpp
blob: 7e16de13426cb51ae39dfdeebc61bcb7fc18ae46 (plain)
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
// 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.

#include "precomp.h"


static HRESULT ParseFromXml(
    __in IXMLDOMDocument* pixdDocument,
    __in BURN_ENGINE_STATE* pEngineState
    );

// function definitions

extern "C" HRESULT ManifestLoadXmlFromFile(
    __in LPCWSTR wzPath,
    __in BURN_ENGINE_STATE* pEngineState
    )
{
    HRESULT hr = S_OK;
    IXMLDOMDocument* pixdDocument = NULL;

    // load xml document
    hr = XmlLoadDocumentFromFile(wzPath, &pixdDocument);
    ExitOnFailure(hr, "Failed to load manifest as XML document.");

    hr = ParseFromXml(pixdDocument, pEngineState);

LExit:
    ReleaseObject(pixdDocument);

    return hr;
}

extern "C" HRESULT ManifestLoadXmlFromBuffer(
    __in_bcount(cbBuffer) BYTE* pbBuffer,
    __in SIZE_T cbBuffer,
    __in BURN_ENGINE_STATE* pEngineState
    )
{
    HRESULT hr = S_OK;
    IXMLDOMDocument* pixdDocument = NULL;

    // load xml document
    hr = XmlLoadDocumentFromBuffer(pbBuffer, cbBuffer, &pixdDocument);
    ExitOnFailure(hr, "Failed to load manifest as XML document.");

    hr = ParseFromXml(pixdDocument, pEngineState);

LExit:
    ReleaseObject(pixdDocument);

    return hr;
}

static HRESULT ParseFromXml(
    __in IXMLDOMDocument* pixdDocument,
    __in BURN_ENGINE_STATE* pEngineState
    )
{
    HRESULT hr = S_OK;
    IXMLDOMElement* pixeBundle = NULL;
    IXMLDOMNode* pixnLog = NULL;
    IXMLDOMNode* pixnChain = NULL;

    // get bundle element
    hr = pixdDocument->get_documentElement(&pixeBundle);
    ExitOnFailure(hr, "Failed to get bundle element.");

    // parse the log element, if present.
    hr = XmlSelectSingleNode(pixeBundle, L"Log", &pixnLog);
    ExitOnFailure(hr, "Failed to get Log element.");

    if (S_OK == hr)
    {
        hr = XmlGetAttributeEx(pixnLog, L"PathVariable", &pEngineState->log.sczPathVariable);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get Log/@PathVariable.");
        }

        hr = XmlGetAttributeEx(pixnLog, L"Prefix", &pEngineState->log.sczPrefix);
        ExitOnFailure(hr, "Failed to get Log/@Prefix attribute.");

        hr = XmlGetAttributeEx(pixnLog, L"Extension", &pEngineState->log.sczExtension);
        ExitOnFailure(hr, "Failed to get Log/@Extension attribute.");
    }

    // get the chain element
    hr = XmlSelectSingleNode(pixeBundle, L"Chain", &pixnChain);
    ExitOnFailure(hr, "Failed to get chain element.");

    if (S_OK == hr)
    {
        // parse disable rollback
        hr = XmlGetYesNoAttribute(pixnChain, L"DisableRollback", &pEngineState->fDisableRollback);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get Chain/@DisableRollback");
        }

        // parse disable system restore
        hr = XmlGetYesNoAttribute(pixnChain, L"DisableSystemRestore", &pEngineState->internalCommand.fDisableSystemRestore);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get Chain/@DisableSystemRestore");
        }

        // parse parallel cache
        hr = XmlGetYesNoAttribute(pixnChain, L"ParallelCache", &pEngineState->fParallelCacheAndExecute);
        if (E_NOTFOUND != hr)
        {
            ExitOnFailure(hr, "Failed to get Chain/@ParallelCache");
        }
    }

    // parse built-in condition 
    hr = ConditionGlobalParseFromXml(&pEngineState->condition, pixeBundle);
    ExitOnFailure(hr, "Failed to parse global condition.");

    // parse variables
    hr = VariablesParseFromXml(&pEngineState->variables, pixeBundle);
    ExitOnFailure(hr, "Failed to parse variables.");

    // parse user experience
    hr = UserExperienceParseFromXml(&pEngineState->userExperience, pixeBundle);
    ExitOnFailure(hr, "Failed to parse user experience.");

    // parse extensions
    hr = BurnExtensionParseFromXml(&pEngineState->extensions, &pEngineState->userExperience.payloads, pixeBundle);
    ExitOnFailure(hr, "Failed to parse extensions.");

    // parse searches
    hr = SearchesParseFromXml(&pEngineState->searches, &pEngineState->extensions, pixeBundle);
    ExitOnFailure(hr, "Failed to parse searches.");

    // parse registration
    hr = RegistrationParseFromXml(&pEngineState->registration, &pEngineState->cache, pixeBundle);
    ExitOnFailure(hr, "Failed to parse registration.");

    // parse update
    hr = UpdateParseFromXml(&pEngineState->update, pixeBundle);
    ExitOnFailure(hr, "Failed to parse update.");

    // parse containers
    hr = ContainersParseFromXml(&pEngineState->containers, pixeBundle);
    ExitOnFailure(hr, "Failed to parse containers.");

    // parse payloads
    hr = PayloadsParseFromXml(&pEngineState->payloads, &pEngineState->containers, &pEngineState->layoutPayloads, pixeBundle);
    ExitOnFailure(hr, "Failed to parse payloads.");

    // parse packages
    hr = PackagesParseFromXml(&pEngineState->packages, &pEngineState->payloads, pixeBundle);
    ExitOnFailure(hr, "Failed to parse packages.");

    // parse approved exes for elevation
    hr = ApprovedExesParseFromXml(&pEngineState->approvedExes, pixeBundle);
    ExitOnFailure(hr, "Failed to parse approved exes.");

LExit:
    ReleaseObject(pixnChain);
    ReleaseObject(pixnLog);
    ReleaseObject(pixeBundle);
    return hr;
}