From a70157793de111752dca24a8518bb784443a5dc8 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Sat, 15 Jul 2017 22:47:08 -0700 Subject: [PATCH] Always show query version when registered Resolves issue #81 --- docker/Tests/vswhere.tests.ps1 | 20 +++++++++++++++++++- src/vswhere/Program.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/docker/Tests/vswhere.tests.ps1 b/docker/Tests/vswhere.tests.ps1 index e4afd9a..620fd4b 100644 --- a/docker/Tests/vswhere.tests.ps1 +++ b/docker/Tests/vswhere.tests.ps1 @@ -38,7 +38,7 @@ Describe 'vswhere' { } Context '(no arguments)' { - It 'header contains no query version' { + It 'header contains query version' { $output = C:\bin\vswhere.exe $output[0] | Should Match 'Visual Studio Locator version \d+\.\d+\.\d+' $output[0] | Should Match '\[query version \d+\.\d+.*\]' @@ -65,6 +65,24 @@ Describe 'vswhere' { } } + Context '-' { + It 'header contains query version' { + $output = C:\bin\vswhere.exe - + $output[0] | Should Match 'Visual Studio Locator version \d+\.\d+\.\d+' + $output[0] | Should Match '\[query version \d+\.\d+.*\]' + + $LASTEXITCODE | Should Be 87 + } + } + + Context '-help' { + It 'header contains query version' { + $output = C:\bin\vswhere.exe -help + $output[0] | Should Match 'Visual Studio Locator version \d+\.\d+\.\d+' + $output[0] | Should Match '\[query version \d+\.\d+.*\]' + } + } + Context '-all' { It 'returns 3 instances using "text"' { $instanceIds = C:\bin\vswhere.exe -all | Select-String 'instanceId: \w+' diff --git a/src/vswhere/Program.cpp b/src/vswhere/Program.cpp index 94a4ddb..94bc3c5 100644 --- a/src/vswhere/Program.cpp +++ b/src/vswhere/Program.cpp @@ -21,6 +21,20 @@ int wmain(_In_ int argc, _In_ LPCWSTR argv[]) { CoInitializer init; + // Create the query object early to print version in logo. + ISetupConfigurationPtr query; + auto hr = query.CreateInstance(__uuidof(SetupConfiguration)); + if (FAILED(hr)) + { + if (REGDB_E_CLASSNOTREG != hr) + { + throw win32_error(hr); + } + } + + // Try to get information about the query module for later. + queryModule.FromIUnknown(static_cast(query)); + args.Parse(argc, argv); if (args.get_Help()) { @@ -30,14 +44,9 @@ int wmain(_In_ int argc, _In_ LPCWSTR argv[]) return ERROR_SUCCESS; } - ISetupConfigurationPtr query; IEnumSetupInstancesPtr e; - GetEnumerator(args, query, e); - // Try to get information about the query module for later. - queryModule.FromIUnknown(static_cast(query)); - // Attempt to get the ISetupHelper. ISetupHelperPtr helper; if (query) @@ -94,15 +103,9 @@ int wmain(_In_ int argc, _In_ LPCWSTR argv[]) void GetEnumerator(_In_ const CommandArgs& args, _In_ ISetupConfigurationPtr& query, _In_ IEnumSetupInstancesPtr& e) { - auto hr = query.CreateInstance(__uuidof(SetupConfiguration)); - if (FAILED(hr)) + if (!query) { - if (REGDB_E_CLASSNOTREG == hr) - { - return; - } - - throw win32_error(hr); + return; } // If all instances are requested, try to get the proper enumerator; otherwise, fall back to original enumerator. @@ -110,7 +113,7 @@ void GetEnumerator(_In_ const CommandArgs& args, _In_ ISetupConfigurationPtr& qu { ISetupConfiguration2Ptr query2; - hr = query->QueryInterface(&query2); + auto hr = query->QueryInterface(&query2); if (SUCCEEDED(hr)) { hr = query2->EnumAllInstances(&e); @@ -123,7 +126,7 @@ void GetEnumerator(_In_ const CommandArgs& args, _In_ ISetupConfigurationPtr& qu if (!e) { - hr = query->EnumInstances(&e); + auto hr = query->EnumInstances(&e); if (FAILED(hr)) { throw win32_error(hr);