Hi Chris,
The Feature conditions (stored in the "Condition" table inside the MSI database) are processed during the "CostFinalize" action. After this stage, any changes in the conditional expression evaluation do not affect the InstallLevel of the Features.
The serial validation DLL Custom Action is invoked
after the "CostFinalize" action (by a ControlEvent of the "Next" button from the "UserRegistrationDlg" dialog). Therefore, the InstallLevel of the Features is not affected anymore by the modification of any Property values.
I have used a different approach. Depending on the serial entered by the user, the Custom Action will set the state of certain Features (those that will be unavailable) to INSTALLSTATE_ABSENT (which means that those Features will not be installed). Furthermore, it is also necessary to hide those Features from the "SelectionTree" control in the "CustomizeDlg" dialog, such that the user cannot change their install state. This is accomplished by modifying the "Display" column of the in-memory "Feature" table. The function presented bellow performs all these operations, with one exception: it will FAIL for Features that have Sub-Features (see the code comments).
I have omitted error handling for clarity.
Code: Select all
#define QUERY_MAXLEN 300
/*---------------------------------------------------------------------------------------*
| This function sets the state for the specified Feature to INSTALLSTATE_ABSENT (which |
| means that the Feature will not be installed). |
| Then the specified Feature is hidden from the SelectionTree control in the |
| CustomizeDlg dialog by modifying the in-memory Feature table. |
| |
| Known issues: |
| - The function will FAIL for Features that have Sub-Features (see explanation bellow) |
| |
| @param hInstall Handle to the installation provided to a DLL custom action |
| @param lpszFeatureName A valid Feature identifier as it appears in the Feature table |
| @return 0 for success (no error handling is currently performed) |
*---------------------------------------------------------------------------------------*/
UINT __stdcall HideAndMakeFeatureAbsent(MSIHANDLE hInstall, LPCTSTR lpszFeatureName)
{
MSIHANDLE hDatabase;
PMSIHANDLE hViewFeature = 0;
PMSIHANDLE hRec = 0;
TCHAR szQuery[QUERY_MAXLEN];
UINT res;
// Causes a breakpoint exception - uncomment to attach the debugger
// DebugBreak();
// The Feature will not be installed
res = MsiSetFeatureState(hInstall, lpszFeatureName, INSTALLSTATE_ABSENT);
// We also need to hide the Feature in the SelectionTree control from the CustomizeDlg
// Create the query string that will select the appropriate row from the Feature table
wsprintf(szQuery, _T("SELECT * FROM `Feature` WHERE `Feature`.`Feature`='%s'"),
lpszFeatureName);
MessageBox(NULL, szQuery, "The SQL command", MB_OK | MB_ICONINFORMATION);
// Get the handle to the database
hDatabase = MsiGetActiveDatabase(hInstall);
// Create a view object
res = MsiDatabaseOpenView(hDatabase, szQuery, &hViewFeature);
// Execute the above query - the view object should contain a single record
// from the Feature table
res = MsiViewExecute(hViewFeature, 0);
// Get the record
res = MsiViewFetch(hViewFeature, &hRec);
/**
* Delete the record from the in-memory Feature table - this change is temporary.
* Note that if the Feature contains Sub-Features this call WILL FAIL (error code 1627)
* because the referential integrity of the Feature table will not be respected anymore
* (there will be Features that contain the deleted Feature's ID in the Feature_Parent
* column).
*/
res = MsiViewModify(hViewFeature, MSIMODIFY_DELETE, hRec);
// Set the Display (5th column) to 0 such that the Feature will be hidden
res = MsiRecordSetInteger(hRec, 5, 0);
// Insert the temporary record
res = MsiViewModify(hViewFeature, MSIMODIFY_INSERT_TEMPORARY, hRec);
// Close the database handle
MsiCloseHandle(hDatabase);
// Assume the function was successful
return 0;
}
When using this function in your code, you have to specify the Feature using its identifier. A simple method to determine this Feature ID is the following:
1. Switch to the Custom Actions page and add a new "Script Inline" CA.
2. Open the "Edit Condition" dialog by clicking the "..." button at the right of the Execution Condition -> "Expression" field.
3. Click the "Feature Action" (or "Feature State") button and select a Feature, then click OK. The Feature identifier will be inserted in the "Expression" text field from the "Edit Condition" dialog (for example, it could be "Feature_1" etc).
4. Delete the "Script Inline" Custom Action.
Then invoke the function in your code as follows:
Code: Select all
#define PIDKEY_LENGTH 100
BOOL __stdcall HideFeature(LPCTSTR lpszFeatureName, LPCTSTR lpszPidKey)
{
//...
}
UINT __stdcall ValidateSerial(MSIHANDLE hInstall)
{
TCHAR szPidKey[PIDKEY_LENGTH];
DWORD dwLen = sizeof(szPidKey) / sizeof(szPidKey[0]);
// retrieve the serial entered by the user
UINT res = MsiGetProperty(hInstall, _T("PIDKEY"), szPidKey, &dwLen);
//...
if ( HideFeature(_T("Feature_1"), szPidKey) )
{
res = HideAndMakeFeatureAbsent(hInstall, _T("Feature_1"));
}
//...
return 0;
}
I have not thoroughly tested this function, so please keep me informed of the results if you use this approach (or if you find another method). We also plan to add conditional Feature installation based on the serial entered by the user to the serial validation DLL that comes with AI.
Hope this helps.
Regards,
Ionut
FOLLOW US
Get the latest news in Application Packaging