Skip to content

Commit

Permalink
Always show query version when registered
Browse files Browse the repository at this point in the history
Resolves issue #81
  • Loading branch information
heaths committed Jul 16, 2017
1 parent edba012 commit a701577
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
20 changes: 19 additions & 1 deletion docker/Tests/vswhere.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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+.*\]'
Expand All @@ -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+'
Expand Down
33 changes: 18 additions & 15 deletions src/vswhere/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUnknown*>(query));

args.Parse(argc, argv);
if (args.get_Help())
{
Expand All @@ -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<IUnknown*>(query));

// Attempt to get the ISetupHelper.
ISetupHelperPtr helper;
if (query)
Expand Down Expand Up @@ -94,23 +103,17 @@ 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.
if (args.get_All())
{
ISetupConfiguration2Ptr query2;

hr = query->QueryInterface(&query2);
auto hr = query->QueryInterface(&query2);
if (SUCCEEDED(hr))
{
hr = query2->EnumAllInstances(&e);
Expand All @@ -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);
Expand Down

0 comments on commit a701577

Please sign in to comment.