| 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 | #include "BextBaseBootstrapperExtension.h" |
| 5 | |
| 6 | class CWixNetfxBootstrapperExtension : public CBextBaseBootstrapperExtension |
| 7 | { |
| 8 | public: // IBootstrapperExtension |
| 9 | virtual STDMETHODIMP Search( |
| 10 | __in LPCWSTR wzId, |
| 11 | __in LPCWSTR wzVariable |
| 12 | ) |
| 13 | { |
| 14 | HRESULT hr = S_OK; |
| 15 | |
| 16 | hr = NetfxSearchExecute(&m_searches, wzId, wzVariable, m_pEngine, m_sczBaseDirectory); |
| 17 | |
| 18 | return hr; |
| 19 | } |
| 20 | |
| 21 | public: //CBextBaseBootstrapperExtension |
| 22 | virtual STDMETHODIMP Initialize( |
| 23 | __in const BOOTSTRAPPER_EXTENSION_CREATE_ARGS* pCreateArgs |
| 24 | ) |
| 25 | { |
| 26 | HRESULT hr = S_OK; |
| 27 | LPWSTR sczModulePath = NULL; |
| 28 | IXMLDOMDocument* pixdManifest = NULL; |
| 29 | IXMLDOMNode* pixnBootstrapperExtension = NULL; |
| 30 | |
| 31 | hr = __super::Initialize(pCreateArgs); |
| 32 | BextExitOnFailure(hr, "CBextBaseBootstrapperExtension initialization failed."); |
| 33 | |
| 34 | hr = PathForCurrentProcess(&sczModulePath, m_hInstance); |
| 35 | BextExitOnFailure(hr, "Failed to get bundle extension path."); |
| 36 | |
| 37 | hr = PathGetDirectory(sczModulePath, &m_sczBaseDirectory); |
| 38 | BextExitOnFailure(hr, "Failed to get bundle extension base directory."); |
| 39 | |
| 40 | hr = XmlLoadDocumentFromFile(m_sczBootstrapperExtensionDataPath, &pixdManifest); |
| 41 | BextExitOnFailure(hr, "Failed to load bundle extension manifest from path: %ls", m_sczBootstrapperExtensionDataPath); |
| 42 | |
| 43 | hr = BextGetBootstrapperExtensionDataNode(pixdManifest, NETFX_BOOTSTRAPPER_EXTENSION_ID, &pixnBootstrapperExtension); |
| 44 | BextExitOnFailure(hr, "Failed to get BootstrapperExtension '%ls'", NETFX_BOOTSTRAPPER_EXTENSION_ID); |
| 45 | |
| 46 | hr = NetfxSearchParseFromXml(&m_searches, pixnBootstrapperExtension); |
| 47 | BextExitOnFailure(hr, "Failed to parse searches from bundle extension manifest."); |
| 48 | |
| 49 | LExit: |
| 50 | ReleaseObject(pixnBootstrapperExtension); |
| 51 | ReleaseObject(pixdManifest); |
| 52 | ReleaseStr(sczModulePath); |
| 53 | |
| 54 | return hr; |
| 55 | } |
| 56 | |
| 57 | public: |
| 58 | CWixNetfxBootstrapperExtension( |
| 59 | __in HINSTANCE hInstance, |
| 60 | __in IBootstrapperExtensionEngine* pEngine |
| 61 | ) : CBextBaseBootstrapperExtension(pEngine) |
| 62 | { |
| 63 | m_searches = { }; |
| 64 | m_hInstance = hInstance; |
| 65 | m_sczBaseDirectory = NULL; |
| 66 | } |
| 67 | |
| 68 | ~CWixNetfxBootstrapperExtension() |
| 69 | { |
| 70 | NetfxSearchUninitialize(&m_searches); |
| 71 | ReleaseStr(m_sczBaseDirectory); |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | NETFX_SEARCHES m_searches; |
| 76 | HINSTANCE m_hInstance; |
| 77 | LPWSTR m_sczBaseDirectory; |
| 78 | }; |
| 79 | |
| 80 | HRESULT NetfxBootstrapperExtensionCreate( |
| 81 | __in HINSTANCE hInstance, |
| 82 | __in IBootstrapperExtensionEngine* pEngine, |
| 83 | __in const BOOTSTRAPPER_EXTENSION_CREATE_ARGS* pArgs, |
| 84 | __out IBootstrapperExtension** ppBootstrapperExtension |
| 85 | ) |
| 86 | { |
| 87 | HRESULT hr = S_OK; |
| 88 | CWixNetfxBootstrapperExtension* pExtension = NULL; |
| 89 | |
| 90 | pExtension = new CWixNetfxBootstrapperExtension(hInstance, pEngine); |
| 91 | BextExitOnNull(pExtension, hr, E_OUTOFMEMORY, "Failed to create new CWixNetfxBootstrapperExtension."); |
| 92 | |
| 93 | hr = pExtension->Initialize(pArgs); |
| 94 | BextExitOnFailure(hr, "CWixNetfxBootstrapperExtension initialization failed."); |
| 95 | |
| 96 | *ppBootstrapperExtension = pExtension; |
| 97 | pExtension = NULL; |
| 98 | |
| 99 | LExit: |
| 100 | ReleaseObject(pExtension); |
| 101 | return hr; |
| 102 | } |