FileGrep Example

InstallShield 2016 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

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

*

* InstallShield Example Script

*

* Demonstrates the FileGrep function.

*

* FileGrep is called to search a file for the first line that

* contains the word "PATH".  The results are displayed in a

* message box.  Note that the FileGrep function is not case

* sensitive.

*

* Note: Before running this script, create a batch file

*       named ISExampl.bat in the root of drive C.  For

*       best effect, that file should include PATH command.

*

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

 

#define  SOURCE_DIR  "C:\\"

#define  SOURCE_FILE "ISExampl.bat"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_FileGrep(HWND);

 

function ExFn_FileGrep(hMSI)

    STRING  svLine, szNewString, svReturnLine, szMsg;

    NUMBER  nvLineNumber, nvResult;

begin

 

    // Find the search string in the source file.

    nvResult = FileGrep (SOURCE_DIR ^ SOURCE_FILE, "PATH", svReturnLine,

                                nvLineNumber, RESTART);

 

    switch(nvResult)

        case FILE_NOT_FOUND:

            // Report error; then abort.

            MessageBox( SOURCE_FILE + " not found.", WARNING);

            abort;

        case FILE_LINE_LENGTH:

            // Report error; then abort.

            MessageBox (SOURCE_FILE + "lines too long.", WARNING);

            abort;

        case OTHER_FAILURE:

            // Report error; then abort.

            MessageBox (SOURCE_FILE + "Unknown failure on call to FileGrep.",

                       WARNING);

            abort;

    endswitch;

 

    // Loop until end of file.

    while (nvResult != END_OF_FILE)

 

        // Set up message string for SprintfBox.

        szMsg = "'PATH' found in line %d of %s:\n\n'%s'";

        

        // Report matching line from file.

        SprintfBox (INFORMATION, "FileGrep", szMsg, nvLineNumber, SOURCE_FILE,

                   svReturnLine);

        

        // Search again.

        nvResult = FileGrep (SOURCE_DIR ^ SOURCE_FILE, "PATH", svReturnLine,

                            nvLineNumber, CONTINUE);

 

    endwhile;

 

end;