| 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 | HRESULT DetectNetCore( |
| 6 | __in NETFX_NET_CORE_PLATFORM platform, |
| 7 | __in NETFX_NET_CORE_RUNTIME_TYPE runtimeType, |
| 8 | __in LPCWSTR wzMajorVersion, |
| 9 | __in LPCWSTR wzBaseDirectory, |
| 10 | __inout LPWSTR* psczLatestVersion |
| 11 | ) |
| 12 | { |
| 13 | HRESULT hr = S_OK; |
| 14 | LPCWSTR wzRuntimeType = NULL; |
| 15 | LPWSTR sczArguments = NULL; |
| 16 | |
| 17 | switch (runtimeType) |
| 18 | { |
| 19 | case NETFX_NET_CORE_RUNTIME_TYPE_ASPNET: |
| 20 | wzRuntimeType = L"Microsoft.AspNetCore.App"; |
| 21 | break; |
| 22 | case NETFX_NET_CORE_RUNTIME_TYPE_CORE: |
| 23 | wzRuntimeType = L"Microsoft.NETCore.App"; |
| 24 | break; |
| 25 | case NETFX_NET_CORE_RUNTIME_TYPE_DESKTOP: |
| 26 | wzRuntimeType = L"Microsoft.WindowsDesktop.App"; |
| 27 | break; |
| 28 | default: |
| 29 | BextExitWithRootFailure(hr, E_INVALIDARG, "Unknown runtime type: %u", runtimeType); |
| 30 | break; |
| 31 | } |
| 32 | |
| 33 | hr = StrAllocFormatted(&sczArguments, L"runtime %ls %ls", wzMajorVersion, wzRuntimeType); |
| 34 | BextExitOnFailure(hr, "Failed to build runtime netcoresearch.exe arguments."); |
| 35 | |
| 36 | hr = RunNetCoreSearch(platform, wzBaseDirectory, sczArguments, psczLatestVersion); |
| 37 | BextExitOnFailure(hr, "Failed to run netcoresearch.exe for runtime."); |
| 38 | |
| 39 | LExit: |
| 40 | ReleaseStr(sczArguments); |
| 41 | |
| 42 | return hr; |
| 43 | } |
| 44 | |
| 45 | HRESULT NetfxPerformDetectNetCore( |
| 46 | __in LPCWSTR wzVariable, |
| 47 | __in NETFX_SEARCH* pSearch, |
| 48 | __in IBootstrapperExtensionEngine* pEngine, |
| 49 | __in LPCWSTR wzBaseDirectory |
| 50 | ) |
| 51 | { |
| 52 | HRESULT hr = S_OK; |
| 53 | LPWSTR sczLatestVersion = FALSE; |
| 54 | |
| 55 | hr = DetectNetCore(pSearch->NetCoreSearch.platform, pSearch->NetCoreSearch.runtimeType, pSearch->NetCoreSearch.sczMajorVersion, wzBaseDirectory, &sczLatestVersion); |
| 56 | BextExitOnFailure(hr, "DetectNetCore failed."); |
| 57 | |
| 58 | hr = pEngine->SetVariableVersion(wzVariable, sczLatestVersion); |
| 59 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); |
| 60 | |
| 61 | LExit: |
| 62 | ReleaseStr(sczLatestVersion); |
| 63 | |
| 64 | return hr; |
| 65 | } |