Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum WixProductSearchType
Language,
State,
Assignment,
Exists,
}

public class WixProductSearchSymbol : IntermediateSymbol
Expand Down
13 changes: 13 additions & 0 deletions src/burn/engine/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ extern "C" HRESULT SearchesParseFromXml(
{
pSearch->MsiProductSearch.Type = BURN_MSI_PRODUCT_SEARCH_TYPE_ASSIGNMENT;
}
else if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"exists", -1))
{
pSearch->MsiProductSearch.Type = BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS;
}
else
{
ExitWithRootFailure(hr, E_INVALIDARG, "Invalid value for @Type: %ls", scz);
Expand Down Expand Up @@ -1144,6 +1148,7 @@ static HRESULT MsiProductSearch(
case BURN_MSI_PRODUCT_SEARCH_TYPE_LANGUAGE:
wzProperty = INSTALLPROPERTY_LANGUAGE;
break;
case BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS: __fallthrough;
case BURN_MSI_PRODUCT_SEARCH_TYPE_STATE:
wzProperty = INSTALLPROPERTY_PRODUCTSTATE;
break;
Expand Down Expand Up @@ -1218,6 +1223,7 @@ static HRESULT MsiProductSearch(
case BURN_MSI_PRODUCT_SEARCH_TYPE_LANGUAGE:
// is supposed to remain empty
break;
case BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS: __fallthrough;
case BURN_MSI_PRODUCT_SEARCH_TYPE_STATE:
value.Type = BURN_VARIANT_TYPE_NUMERIC;
value.llValue = INSTALLSTATE_ABSENT;
Expand All @@ -1237,6 +1243,7 @@ static HRESULT MsiProductSearch(
case BURN_MSI_PRODUCT_SEARCH_TYPE_LANGUAGE:
type = BURN_VARIANT_TYPE_STRING;
break;
case BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS: __fallthrough;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than fall through here and check the type again below (line 1255), we should just set the value appropriately in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is in this stage string format?

Copy link
Author

@metsma metsma Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to anything with this commit?
I am not using existing case because at this point the value is string and later converted to int.
hr = WiuGetProductInfo(sczGuid, wzProperty, &value.sczValue);
...
hr = BVariantChangeType(&value, type);
and then int value is compared
value.llValue = (value.llValue == INSTALLSTATE_ABSENT) ? 0 : 1;

case BURN_MSI_PRODUCT_SEARCH_TYPE_STATE: __fallthrough;
case BURN_MSI_PRODUCT_SEARCH_TYPE_ASSIGNMENT:
type = BURN_VARIANT_TYPE_NUMERIC;
Expand All @@ -1245,6 +1252,12 @@ static HRESULT MsiProductSearch(
hr = BVariantChangeType(&value, type);
ExitOnFailure(hr, "Failed to change value type.");

// Alter value here after value has changed to numberic type.
if (BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS == pSearch->MsiProductSearch.Type)
{
value.llValue = (value.llValue == INSTALLSTATE_ABSENT) ? 0 : 1;
}

// Set variable.
hr = VariableSetVariant(pVariables, pSearch->sczVariable, &value);
ExitOnFailure(hr, "Failed to set variable.");
Expand Down
1 change: 1 addition & 0 deletions src/burn/engine/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum BURN_MSI_PRODUCT_SEARCH_TYPE
BURN_MSI_PRODUCT_SEARCH_TYPE_LANGUAGE,
BURN_MSI_PRODUCT_SEARCH_TYPE_STATE,
BURN_MSI_PRODUCT_SEARCH_TYPE_ASSIGNMENT,
BURN_MSI_PRODUCT_SEARCH_TYPE_EXISTS,
};

enum BURN_MSI_PRODUCT_SEARCH_GUID_TYPE
Expand Down
4 changes: 4 additions & 0 deletions src/burn/test/BurnUnitTest/SearchTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ namespace Bootstrapper
L" <MsiProductSearch Id='Search4' Type='state' ProductCode='{600D0000-0000-0000-0000-000000000000}' Variable='Variable4' />"
L" <MsiProductSearch Id='Search5' Type='assignment' ProductCode='{600D0000-0000-0000-0000-000000000000}' Variable='Variable5' />"
L" <MsiProductSearch Id='Search6' Type='version' ProductCode='{600D0000-1000-0000-0000-000000000000}' Variable='Variable6' />"
L" <MsiProductSearch Id='Search7' Type='exists' ProductCode='{600D0000-0000-0000-0000-000000000000}' Variable='Variable7' />"
L" <MsiProductSearch Id='Search8' Type='exists' ProductCode='{BAD00000-0000-0000-0000-000000000000}' Variable='Variable8' />"
L"</Bundle>";

// load XML document
Expand All @@ -429,6 +431,8 @@ namespace Bootstrapper
Assert::Equal(5ll, VariableGetNumericHelper(&variables, L"Variable4"));
Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Variable5"));
Assert::Equal<String^>(gcnew String(L"1.0.0.0"), VariableGetVersionHelper(&variables, L"Variable6"));
Assert::Equal(1ll, VariableGetNumericHelper(&variables, L"Variable7"));
Assert::Equal(0ll, VariableGetNumericHelper(&variables, L"Variable8"));
}
finally
{
Expand Down
5 changes: 4 additions & 1 deletion src/ext/Util/wixext/UtilCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2736,8 +2736,11 @@ private void ParseProductSearchElement(Intermediate intermediate, IntermediateSe
case "assignment":
type = WixProductSearchType.Assignment;
break;
case "exists":
type = WixProductSearchType.Exists;
break;
default:
this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attrib.Parent.Name.LocalName, attrib.Name.LocalName, result, "version", "language", "state", "assignment"));
this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attrib.Parent.Name.LocalName, attrib.Name.LocalName, result, "version", "language", "state", "assignment", "exists"));
break;
}
break;
Expand Down
3 changes: 3 additions & 0 deletions src/wix/WixToolset.Core.Burn/Bind/LegacySearchFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ private void WriteProductSearchXml(XmlTextWriter writer, WixProductSearchSymbol
case WixProductSearchType.Assignment:
writer.WriteAttributeString("Type", "assignment");
break;
case WixProductSearchType.Exists:
writer.WriteAttributeString("Type", "exists");
break;
default:
throw new NotImplementedException();
}
Expand Down
5 changes: 5 additions & 0 deletions src/xsd/util.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,11 @@
<xs:documentation>Saves the version of a matching product if found; 0.0.0.0 otherwise. This is the default.</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="exists">
<xs:annotation>
<xs:documentation>Saves true if a matching product entry is found; false otherwise.</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
Expand Down