diff options
Diffstat (limited to 'src/ext/NetFx/be/detectnetcore.cpp')
| -rw-r--r-- | src/ext/NetFx/be/detectnetcore.cpp | 91 |
1 files changed, 8 insertions, 83 deletions
diff --git a/src/ext/NetFx/be/detectnetcore.cpp b/src/ext/NetFx/be/detectnetcore.cpp index aeb04203..3ed26549 100644 --- a/src/ext/NetFx/be/detectnetcore.cpp +++ b/src/ext/NetFx/be/detectnetcore.cpp | |||
| @@ -12,18 +12,7 @@ HRESULT DetectNetCore( | |||
| 12 | { | 12 | { |
| 13 | HRESULT hr = S_OK; | 13 | HRESULT hr = S_OK; |
| 14 | LPCWSTR wzRuntimeType = NULL; | 14 | LPCWSTR wzRuntimeType = NULL; |
| 15 | LPCWSTR wzPlatformName = NULL; | 15 | LPWSTR sczArguments = NULL; |
| 16 | LPWSTR sczExePath = NULL; | ||
| 17 | LPWSTR sczCommandLine = NULL; | ||
| 18 | HANDLE hProcess = NULL; | ||
| 19 | HANDLE hStdOutErr = INVALID_HANDLE_VALUE; | ||
| 20 | BYTE* rgbOutput = NULL; | ||
| 21 | DWORD cbOutput = 0; | ||
| 22 | DWORD cbTotalRead = 0; | ||
| 23 | DWORD cbRead = 0; | ||
| 24 | DWORD dwExitCode = 0; | ||
| 25 | |||
| 26 | ReleaseNullStr(*psczLatestVersion); | ||
| 27 | 16 | ||
| 28 | switch (runtimeType) | 17 | switch (runtimeType) |
| 29 | { | 18 | { |
| @@ -41,80 +30,14 @@ HRESULT DetectNetCore( | |||
| 41 | break; | 30 | break; |
| 42 | } | 31 | } |
| 43 | 32 | ||
| 44 | switch (platform) | 33 | hr = StrAllocFormatted(&sczArguments, L"runtime %ls %ls", wzMajorVersion, wzRuntimeType); |
| 45 | { | 34 | BextExitOnFailure(hr, "Failed to build runtime netcoresearch.exe arguments."); |
| 46 | case NETFX_NET_CORE_PLATFORM_ARM64: | ||
| 47 | wzPlatformName = L"arm64"; | ||
| 48 | break; | ||
| 49 | case NETFX_NET_CORE_PLATFORM_X64: | ||
| 50 | wzPlatformName = L"x64"; | ||
| 51 | break; | ||
| 52 | case NETFX_NET_CORE_PLATFORM_X86: | ||
| 53 | wzPlatformName = L"x86"; | ||
| 54 | break; | ||
| 55 | default: | ||
| 56 | BextExitWithRootFailure(hr, E_INVALIDARG, "Unknown platform: %u", platform); | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | |||
| 60 | hr = StrAllocFormatted(&sczExePath, L"%ls%ls\\netcoresearch.exe", wzBaseDirectory, wzPlatformName); | ||
| 61 | BextExitOnFailure(hr, "Failed to build netcoresearch.exe path."); | ||
| 62 | |||
| 63 | hr = StrAllocFormatted(&sczCommandLine, L"\"%ls\" runtime %ls %ls", sczExePath, wzMajorVersion, wzRuntimeType); | ||
| 64 | BextExitOnFailure(hr, "Failed to build netcoresearch.exe command line."); | ||
| 65 | |||
| 66 | hr = ProcExecute(sczExePath, sczCommandLine, &hProcess, NULL, &hStdOutErr); | ||
| 67 | if (HRESULT_FROM_WIN32(ERROR_EXE_MACHINE_TYPE_MISMATCH) == hr) | ||
| 68 | { | ||
| 69 | ExitFunction1(hr = S_FALSE); | ||
| 70 | } | ||
| 71 | BextExitOnFailure(hr, "Failed to run: %ls", sczCommandLine); | ||
| 72 | |||
| 73 | cbOutput = 64; | ||
| 74 | 35 | ||
| 75 | rgbOutput = reinterpret_cast<BYTE*>(MemAlloc(cbOutput, TRUE)); | 36 | hr = RunNetCoreSearch(platform, wzBaseDirectory, sczArguments, psczLatestVersion); |
| 76 | BextExitOnNull(rgbOutput, hr, E_OUTOFMEMORY, "Failed to alloc output string."); | 37 | BextExitOnFailure(hr, "Failed to run netcoresearch.exe for runtime."); |
| 77 | |||
| 78 | while (::ReadFile(hStdOutErr, rgbOutput + cbTotalRead, cbOutput - cbTotalRead, &cbRead, NULL)) | ||
| 79 | { | ||
| 80 | cbTotalRead += cbRead; | ||
| 81 | |||
| 82 | if (cbTotalRead == cbOutput) | ||
| 83 | { | ||
| 84 | cbOutput *= 2; | ||
| 85 | |||
| 86 | LPVOID pvNew = MemReAlloc(rgbOutput, cbOutput, TRUE); | ||
| 87 | BextExitOnNull(pvNew, hr, E_OUTOFMEMORY, "Failed to realloc output string."); | ||
| 88 | |||
| 89 | rgbOutput = reinterpret_cast<BYTE*>(pvNew); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | if (ERROR_BROKEN_PIPE != ::GetLastError()) | ||
| 94 | { | ||
| 95 | BextExitWithLastError(hr, "Failed to read netcoresearch.exe output."); | ||
| 96 | } | ||
| 97 | |||
| 98 | hr = ProcWaitForCompletion(hProcess, INFINITE, &dwExitCode); | ||
| 99 | BextExitOnFailure(hr, "Failed to wait for netcoresearch.exe to exit."); | ||
| 100 | |||
| 101 | if (0 != dwExitCode) | ||
| 102 | { | ||
| 103 | BextExitWithRootFailure(hr, E_UNEXPECTED, "netcoresearch.exe failed with exit code: 0x%x\r\nOutput:\r\n%hs", dwExitCode, rgbOutput); | ||
| 104 | } | ||
| 105 | |||
| 106 | if (*rgbOutput) | ||
| 107 | { | ||
| 108 | hr = StrAllocStringAnsi(psczLatestVersion, reinterpret_cast<LPSTR>(rgbOutput), 0, CP_UTF8); | ||
| 109 | BextExitOnFailure(hr, "Failed to widen output string: %hs", rgbOutput); | ||
| 110 | } | ||
| 111 | 38 | ||
| 112 | LExit: | 39 | LExit: |
| 113 | ReleaseFileHandle(hStdOutErr); | 40 | ReleaseStr(sczArguments); |
| 114 | ReleaseHandle(hProcess); | ||
| 115 | ReleaseMem(rgbOutput); | ||
| 116 | ReleaseStr(sczCommandLine); | ||
| 117 | ReleaseStr(sczExePath); | ||
| 118 | 41 | ||
| 119 | return hr; | 42 | return hr; |
| 120 | } | 43 | } |
| @@ -136,5 +59,7 @@ HRESULT NetfxPerformDetectNetCore( | |||
| 136 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); | 59 | BextExitOnFailure(hr, "Failed to set variable '%ls' to '%ls'", wzVariable, sczLatestVersion); |
| 137 | 60 | ||
| 138 | LExit: | 61 | LExit: |
| 62 | ReleaseStr(sczLatestVersion); | ||
| 63 | |||
| 139 | return hr; | 64 | return hr; |
| 140 | } | 65 | } |
