main
cpp 66 lines 2.21 KB
Raw
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 int __cdecl wmain(int argc, LPWSTR argv[])
6 {
7 HRESULT hr = E_INVALIDARG;
8
9 ConsoleInitialize();
10
11 if (argc < 2)
12 {
13 ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Must specify a command");
14 }
15 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"smartcab", -1))
16 {
17 hr = SmartCabCommand(argc - 2, argv + 2);
18 }
19 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"extractcab", -1))
20 {
21 hr = ExtractCabCommand(argc - 2, argv + 2);
22 }
23 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"enumcab", -1))
24 {
25 hr = EnumCabCommand(argc - 2, argv + 2);
26 }
27 else if (CSTR_EQUAL == ::CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, argv[1], -1, L"certhashes", -1))
28 {
29 hr = CertificateHashesCommand(argc - 2, argv + 2);
30 }
31 else
32 {
33 ConsoleWriteError(hr, CONSOLE_COLOR_RED, "Unknown command: %ls", argv[1]);
34 }
35
36 ConsoleUninitialize();
37 return HRESULT_CODE(hr);
38 }
39
40 HRESULT WixNativeReadStdinPreamble()
41 {
42 HRESULT hr = S_OK;
43 LPWSTR sczLine = NULL;
44 size_t cchPreamble = 0;
45
46 // Read the first line to determine if a byte-order-mark was prepended to stdin.
47 // A byte-order-mark is not normally expected but has been seen in some CI/CD systems.
48 // The preable is a single line with ":".
49 hr = ConsoleReadW(&sczLine);
50 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "failed to read preamble from stdin");
51
52 hr = ::StringCchLengthW(sczLine, STRSAFE_MAX_CCH, &cchPreamble);
53 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "failed to get length of stdin preamble");
54
55 // Ensure the preamble ends with ":" and ignore anything before that (since it may be a BOM).
56 if (!cchPreamble || sczLine[cchPreamble - 1] != L':')
57 {
58 hr = E_INVALIDDATA;
59 ConsoleExitOnFailure(hr, CONSOLE_COLOR_RED, "expected ':' as preamble on first line of stdin");
60 }
61
62 LExit:
63 ReleaseStr(sczLine);
64
65 return hr;
66 }