aboutsummaryrefslogtreecommitdiff
path: root/src/engine/catalog.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/engine/catalog.cpp180
1 files changed, 0 insertions, 180 deletions
diff --git a/src/engine/catalog.cpp b/src/engine/catalog.cpp
deleted file mode 100644
index da086545..00000000
--- a/src/engine/catalog.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
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// function definitions
7
8extern "C" HRESULT CatalogsParseFromXml(
9 __in BURN_CATALOGS* pCatalogs,
10 __in IXMLDOMNode* pixnBundle
11 )
12{
13 HRESULT hr = S_OK;
14 IXMLDOMNodeList* pixnNodes = NULL;
15 IXMLDOMNode* pixnNode = NULL;
16 DWORD cNodes = 0;
17 LPWSTR scz = NULL;
18
19 // select catalog nodes
20 hr = XmlSelectNodes(pixnBundle, L"Catalog", &pixnNodes);
21 ExitOnFailure(hr, "Failed to select catalog nodes.");
22
23 // get catalog node count
24 hr = pixnNodes->get_length((long*)&cNodes);
25 ExitOnFailure(hr, "Failed to get payload node count.");
26 if (!cNodes)
27 {
28 ExitFunction();
29 }
30
31 // allocate memory for catalogs
32 pCatalogs->rgCatalogs = (BURN_CATALOG*)MemAlloc(sizeof(BURN_CATALOG) * cNodes, TRUE);
33 ExitOnNull(pCatalogs->rgCatalogs, hr, E_OUTOFMEMORY, "Failed to allocate memory for payload structs.");
34
35 pCatalogs->cCatalogs = cNodes;
36
37 // parse catalog elements
38 for (DWORD i = 0; i < cNodes; ++i)
39 {
40 BURN_CATALOG* pCatalog = &pCatalogs->rgCatalogs[i];
41 pCatalog->hFile = INVALID_HANDLE_VALUE;
42
43 hr = XmlNextElement(pixnNodes, &pixnNode, NULL);
44 ExitOnFailure(hr, "Failed to get next node.");
45
46 // @Id
47 hr = XmlGetAttributeEx(pixnNode, L"Id", &pCatalog->sczKey);
48 ExitOnFailure(hr, "Failed to get @Id.");
49
50 // @Payload
51 hr = XmlGetAttributeEx(pixnNode, L"Payload", &pCatalog->sczPayload);
52 ExitOnFailure(hr, "Failed to get @Payload.");
53
54 // prepare next iteration
55 ReleaseNullObject(pixnNode);
56 }
57
58LExit:
59 ReleaseObject(pixnNodes);
60 ReleaseObject(pixnNode);
61 ReleaseStr(scz);
62
63 return hr;
64}
65
66extern "C" HRESULT CatalogFindById(
67 __in BURN_CATALOGS* pCatalogs,
68 __in_z LPCWSTR wzId,
69 __out BURN_CATALOG** ppCatalog
70 )
71{
72 HRESULT hr = S_OK;
73 BURN_CATALOG* pCatalog = NULL;
74
75 for (DWORD i = 0; i < pCatalogs->cCatalogs; ++i)
76 {
77 pCatalog = &pCatalogs->rgCatalogs[i];
78
79 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pCatalog->sczKey, -1, wzId, -1))
80 {
81 *ppCatalog = pCatalog;
82 ExitFunction1(hr = S_OK);
83 }
84 }
85
86 hr = E_NOTFOUND;
87
88LExit:
89 return hr;
90}
91
92extern "C" HRESULT CatalogLoadFromPayload(
93 __in BURN_CATALOGS* pCatalogs,
94 __in BURN_PAYLOADS* pPayloads
95 )
96{
97 HRESULT hr = S_OK;
98 BURN_CATALOG* pCatalog = NULL;
99 BURN_PAYLOAD* pPayload = NULL;
100
101 // go through each catalog file
102 for (DWORD i = 0; i < pCatalogs->cCatalogs; i++)
103 {
104 pCatalog = &pCatalogs->rgCatalogs[i];
105
106 // get the payload for this catalog file
107 hr = PayloadFindById(pPayloads, pCatalog->sczPayload, &pPayload);
108 ExitOnFailure(hr, "Failed to find payload for catalog file.");
109
110 // Get the local file name
111 hr = StrAllocString(&pCatalog->sczLocalFilePath, pPayload->sczLocalFilePath, 0);
112 ExitOnFailure(hr, "Failed to get catalog local file path");
113
114 // Get a handle to the file
115 pCatalog->hFile = ::CreateFileW(pCatalog->sczLocalFilePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
116 if (INVALID_HANDLE_VALUE == pCatalog->hFile)
117 {
118 ExitWithLastError(hr, "Failed to open catalog in working path: %ls", pCatalog->sczLocalFilePath);
119 }
120
121 // Verify the catalog file
122 hr = CacheVerifyPayloadSignature(pPayload, pCatalog->sczLocalFilePath, pCatalog->hFile);
123 ExitOnFailure(hr, "Failed to verify catalog signature: %ls", pCatalog->sczLocalFilePath);
124 }
125
126LExit:
127 return hr;
128}
129
130extern "C" HRESULT CatalogElevatedUpdateCatalogFile(
131 __in BURN_CATALOGS* pCatalogs,
132 __in_z LPCWSTR wzId,
133 __in_z LPCWSTR wzPath
134 )
135{
136 HRESULT hr = S_OK;
137 BURN_CATALOG* pCatalog = NULL;
138
139 // Find the catalog
140 hr = CatalogFindById(pCatalogs, wzId, &pCatalog);
141 ExitOnFailure(hr, "Failed to locate catalog information.");
142
143 if (NULL == pCatalog->sczLocalFilePath)
144 {
145 hr = StrAllocString(&pCatalog->sczLocalFilePath, wzPath, 0);
146 ExitOnFailure(hr, "Failed to allocated catalog path.");
147
148 // Get a handle to the file
149 pCatalog->hFile = ::CreateFileW(pCatalog->sczLocalFilePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
150 if (INVALID_HANDLE_VALUE == pCatalog->hFile)
151 {
152 ExitWithLastError(hr, "Failed to open catalog in working path: %ls", pCatalog->sczLocalFilePath);
153 }
154 }
155
156LExit:
157 return hr;
158}
159
160extern "C" void CatalogUninitialize(
161 __in BURN_CATALOGS* pCatalogs
162 )
163{
164 if (pCatalogs->rgCatalogs)
165 {
166 for (DWORD i = 0; i < pCatalogs->cCatalogs; ++i)
167 {
168 BURN_CATALOG* pCatalog = &pCatalogs->rgCatalogs[i];
169
170 ReleaseHandle(pCatalog->hFile);
171 ReleaseStr(pCatalog->sczKey);
172 ReleaseStr(pCatalog->sczLocalFilePath);
173 ReleaseStr(pCatalog->sczPayload);
174 }
175 MemFree(pCatalogs->rgCatalogs);
176 }
177
178 // clear struct
179 memset(pCatalogs, 0, sizeof(BURN_CATALOGS));
180}