/// Win32 MSI APIs:
/// MsiGetFeatureInfo,
/// MsiSetFeatureAttributes
///
/// Since the lpAttributes paramter of
/// MsiGetFeatureInfo
/// does not contain an equivalent flag for , this flag will
/// not be retrieved.
///
/// Since the dwAttributes parameter of
/// MsiSetFeatureAttributes
/// does not contain an equivalent flag for , the presence
/// of this flag will be ignored.
///
public FeatureAttributes Attributes
{
get
{
FeatureAttributes attributes;
uint titleBufSize = 0;
uint descBufSize = 0;
uint attr;
uint ret = NativeMethods.MsiGetFeatureInfo(
(int) this.session.Handle,
this.name,
out attr,
null,
ref titleBufSize,
null,
ref descBufSize);
if (ret != 0)
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
// Values for attributes that MsiGetFeatureInfo returns are
// double the values in the Attributes column of the Feature Table.
attributes = (FeatureAttributes) (attr >> 1);
// MsiGetFeatureInfo MSDN documentation indicates
// NOUNSUPPORTEDADVERTISE is 32. Conversion above changes this to 16
// which is UIDisallowAbsent. MsiGetFeatureInfo isn't documented to
// return an attribute for 'UIDisallowAbsent', so if UIDisallowAbsent
// is set, change it to NoUnsupportedAdvertise which then maps correctly
// to NOUNSUPPORTEDADVERTISE.
if ((attributes & FeatureAttributes.UIDisallowAbsent) == FeatureAttributes.UIDisallowAbsent)
{
attributes &= ~FeatureAttributes.UIDisallowAbsent;
attributes |= FeatureAttributes.NoUnsupportedAdvertise;
}
return attributes;
}
set
{
// MsiSetFeatureAttributes doesn't indicate UIDisallowAbsent is valid
// so remove it.
FeatureAttributes attributes = value;
attributes &= ~FeatureAttributes.UIDisallowAbsent;
// Values for attributes that MsiSetFeatureAttributes uses are
// double the values in the Attributes column of the Feature Table.
uint attr = ((uint) attributes) << 1;
// MsiSetFeatureAttributes MSDN documentation indicates
// NOUNSUPPORTEDADVERTISE is 32. Conversion above changes this to 64
// which is undefined. Change this back to 32.
uint noUnsupportedAdvertiseDbl = ((uint)FeatureAttributes.NoUnsupportedAdvertise) << 1;
if ((attr & noUnsupportedAdvertiseDbl) == noUnsupportedAdvertiseDbl)
{
attr &= ~noUnsupportedAdvertiseDbl;
attr |= (uint) FeatureAttributes.NoUnsupportedAdvertise;
}
uint ret = RemotableNativeMethods.MsiSetFeatureAttributes((int) this.session.Handle, this.name, attr);
if (ret != (uint)NativeMethods.Error.SUCCESS)
{
if (ret == (uint)NativeMethods.Error.UNKNOWN_FEATURE)
{
throw InstallerException.ExceptionFromReturnCode(ret, this.name);
}
else
{
throw InstallerException.ExceptionFromReturnCode(ret);
}
}
}
}
///