Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

c++ - How to install feature based on the property set in custom action?

I am trying to install one from two features based on the value that should be set inside of the custom action.
Firstly, I set the value of a property:

UINT __stdcall ConfigurationCheckAction(MSIHANDLE hInstall)
{
    HRESULT hr = S_OK;
    UINT er = ERROR_INSTALL_FAILURE;

    hr = WcaInitialize(hInstall, "ConfigurationCheckAction"); 
    if (condition) {
         MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("RED") );
    }
    else {
         MsiSetProperty( hInstall, TEXT("STREAM"), TEXT("BLUE") );
    } 
    return WcaFinalize(er);
}

Secondly, I make two conditions per two features:

<Feature Id='Complete' Level='1'>
     <Feature Id="Red" ConfigurableDirectory="TARGETDIR" Title="F1" Level="0">
     <Condition Level="1">STREAM</Condition>
     </Feature>
     <Feature Id="Blue" ConfigurableDirectory="TARGETDIR" Title="F2" Level="0">
     <Condition Level="1">NOT STREAM</Condition>
     </Feature>
</Feature>

Note that I don't define property inside of the wxs file previously, as I would like to set it from the custom action.

My custom action is called before InstallInitialize and Execute is immediate.

From the installation log I have confirmation that the property is set. However, my conditional installation does not work, as it seems like what is in the condition is always evaluated as false.

I tried evaluating conditions: STREAM, STREAM=RED, STREAM="RED", < ![CDATA[STREAM=RED]]>

I am running out of ideas what to do and would appreciate help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Too late to test all of this, but here goes with some information. I will check back tomorrow. Essentially I think the problem is your custom action sequencing. Try before Costing.

Some things to consider:

  • Custom action sequencing: you need to sequence your custom action right and it needs to be present in both silent and interactive installation modes.
    • Did you try to sequence the set property custom action before CostInitialize? You state you set it before InstallInitialize, but try it before CostInitialize instead (you might have tried).
    • And did you remember to insert this custom action in the InstallUISequence as well as the InstallExecuteSequence? You need to insert in both sequences in case the setup runs in silent mode. Before CostInitialize in both sequences I believe.
  • Feature Level: manipulating features via the feature level and INSTALLLEVEL is just one way to do feature control, you can also set features via the command line or using a custom action.
    • Setting a feature level to 0 should hide the feature from view in the setup's custom dialog.
    • Setting a feature level higher than the setup's INSTALLLEVEL will deselect the feature from installation.
    • And the other way around setting a feature level lower or equal to the setup's INSTALLLEVEL will select the feature for installation.
    • The conditional syntax allowed is quite flexible, and could provide the functionality you need outright - but I have never used them properly. Here is an example from the Installshield forum.
  • ADDLOCAL & REMOVE: you can manipulate the feature selection by changing the values of the ADDLOCAL and REMOVE properties from a custom action (technically also REINSTALL and ADVERTISE) - and these properties can be set via the command line as well.
  • Win32: you can also use the Win32 functions MsiGetFeatureState and MsiSetFeatureState - from a C++ custom action - to set feature selection.

Frankly it is a bit mad the whole thing. Also keep in mind that there are feature action states (what is going to happen to a feature) and feature installed states (what state it is in). The Win32 function documentation should explain.


Cross-linking for easy retrieval:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...