FeatureAddItem Example

InstallShield 2014 ยป InstallScript Language Reference

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the FeatureAddItem function.

*

* In this script, FeatureAddItem is called to create a

* script-created feature set consisting of drives attached

* to the target system. These features are displayed in an

* SdAskOptionsList dialog so that the end user can select

* from among the drives.

*

\*--------------------------------------------------------------*/

 

LIST listDrives, listFeatures;

STRING szSaveMEDIAValue, svDrive;

LONG nResult;

BOOL bSelected;

 

#include "ifx.h"

 

function OnBegin()

begin

 

    // Create the list to store drive names.

    listDrives = ListCreate(STRINGLIST);

  

    // Add all fixed drives to the list.

    GetValidDrivesList(listDrives, FIXED_DRIVE, -1);

 

    // Save the value of the system variable MEDIA so it can

    // be restored for later calls to transfer data.

    szSaveMEDIAValue = MEDIA;

  

    // Specify a name for the script-created feature set.

    MEDIA = "Drives";

  

    // Put the drive names into the script-created feature set.  

    nResult = ListGetFirstString(listDrives, svDrive);

    while (nResult != END_OF_LIST)

        FeatureAddItem(MEDIA, svDrive, 0, FALSE);

        nResult = ListGetNextString(listDrives, svDrive);

    endwhile;

  

    // Display the list of drives.  Let user select one drive.

    SdAskOptionsList("Select a Drive" ,

    "Select one of the drives attached to your system." ,

    "" , EXCLUSIVE);

                    

    // Find the selected drive in the list.

   bSelected = FALSE;

   nResult = ListGetFirstString(listDrives, svDrive);

   bSelected = ComponentIsItemSelected (MEDIA , svDrive);

   while ((nResult != END_OF_LIST) && !bSelected);

        nResult = ListGetNextString(listDrives, svDrive);

        bSelected = ComponentIsItemSelected (MEDIA , svDrive);

    endwhile;

  

    // Release the list from memory.

    ListDestroy (listDrives);

    if bSelected then

        MessageBox("You selected drive " + svDrive + ".", INFORMATION);

    endif;

  

    // Restore MEDIA to its previous value for file transfer.

    MEDIA = szSaveMEDIAValue;

 

end;