Skip to content

Commit

Permalink
Treat missing product as non-fatal
Browse files Browse the repository at this point in the history
Fixes #116
  • Loading branch information
heaths committed Oct 30, 2017
1 parent 683800a commit 0bd658f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/vswhere.lib/Formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ HRESULT Formatter::GetProductId(_In_ ISetupInstance* pInstance, _Out_ VARIANT* p
ISetupPackageReferencePtr reference;

hr = instance->GetProduct(&reference);
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && !!reference)
{
variant_t vt;

Expand All @@ -437,7 +437,7 @@ HRESULT Formatter::GetProductPath(_In_ ISetupInstance* pInstance, _Out_ VARIANT*
bstr_t bstrProductPath;

hr = instance->GetProductPath(bstrProductPath.GetAddress());
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && !!bstrProductPath)
{
variant_t vt;

Expand Down
2 changes: 1 addition & 1 deletion src/vswhere.lib/InstanceSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ bool InstanceSelector::IsProductMatch(_In_ ISetupInstance2* pInstance) const
ISetupPackageReferencePtr product;

auto hr = pInstance->GetProduct(&product);
if (FAILED(hr))
if (FAILED(hr) || !product)
{
// Should always have a product so no match.
return false;
Expand Down
20 changes: 10 additions & 10 deletions test/vswhere.test/TestInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,15 @@ class TestInstance :
_Outptr_result_maybenull_ ISetupPackageReference** ppPackage
)
{
if (m_product)
{
*ppPackage = m_product;
return S_OK;
}

return E_NOTFOUND;
*ppPackage = m_product;
return S_OK;
}

STDMETHODIMP GetProductPath(
_Outptr_result_maybenull_ BSTR* pbstrProductPath
)
{
return TryGetBSTR(L"ProductPath", pbstrProductPath);
return TryGetBSTR(L"ProductPath", pbstrProductPath, TRUE);
}

STDMETHODIMP GetErrors(
Expand Down Expand Up @@ -297,7 +292,7 @@ class TestInstance :
_Outptr_result_maybenull_ BSTR* pbstrEnginePath
)
{
return TryGetBSTR(L"EnginePath", pbstrEnginePath);
return TryGetBSTR(L"EnginePath", pbstrEnginePath, TRUE);
}

// ISetupInstanceCatalog
Expand Down Expand Up @@ -372,7 +367,7 @@ class TestInstance :
return E_NOTFOUND;
}

STDMETHODIMP TryGetBSTR(_In_ LPCWSTR wszName, _Out_ BSTR* pbstrValue)
STDMETHODIMP TryGetBSTR(_In_ LPCWSTR wszName, _Out_ BSTR* pbstrValue, _In_opt_ BOOL fAllowNull = FALSE)
{
if (!pbstrValue)
{
Expand All @@ -390,6 +385,11 @@ class TestInstance :
return E_OUTOFMEMORY;
}
}
else if (fAllowNull && E_NOTFOUND == hr)
{
*pbstrValue = NULL;
return S_OK;
}

return hr;
}
Expand Down

0 comments on commit 0bd658f

Please sign in to comment.