FileCompare Example

InstallShield 2020 ยป 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 FileCompare function.

*

* This example script calls FileCompare three times:

*

* -- The first call compares the version of FILE_COMP1 in SDIR

*    to the version of FILE_COMP2 in TDIR.

*

* -- The second call checks if FILE_COMP1 was created earlier

*    than FILE_COMP2.

*

* -- The third call checks if FILE_COMP1 is smaller than

*    FILE_COMP2.

*

* Note: Before you run this script, set the preprocessor

*       constants so that they reference existing files in

*       existing directories on the target computer.

*

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

 

#define  SDIR        "C:\\"

#define  TDIR        "C:\\"

#define  FILE_COMP1  "Example1.dll"

#define  FILE_COMP2  "Example2.dll"

#define  MSG_TITLE   "FileCompare Example"

 

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

#include "Ifx.h"

 

export prototype ExFn_FileCompare(HWND);

 

function ExFn_FileCompare(hMSI)

    NUMBER nResult;

begin

 

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

     *

     * Compare the versions of the two files.

     *

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

 

    nResult = FileCompare (SDIR ^ FILE_COMP1, TDIR ^ FILE_COMP2,

                          COMPARE_VERSION);

 

    // Report an error and terminate if either file is not found.

    if (nResult = FILE_NOT_FOUND) then

        SprintfBox (INFORMATION, MSG_TITLE, "%s and/or %s not found.",

                        FILE_COMP1, FILE_COMP2);

        abort;

    endif;

 

    // Files are present so report the result of the comparison.

    switch (nResult)

        case EQUALS:

            SprintfBox (INFORMATION, MSG_TITLE, "%s is the same version as %s.",

                       FILE_COMP1, FILE_COMP2);

        case GREATER_THAN:

            SprintfBox (INFORMATION, MSG_TITLE, "%s is a newer version than %s.",

                       FILE_COMP1, FILE_COMP2);

        case LESS_THAN:

            SprintfBox (INFORMATION, MSG_TITLE, "%s is an older version than %s.",

                       FILE_COMP1, FILE_COMP2);

        case OTHER_FAILURE:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "Version information not available in %s and/or %s.",

                       FILE_COMP1, FILE_COMP2);

    endswitch;

 

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

     *

     * Compare the creation dates.

     *

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

 

    nResult = FileCompare (SDIR ^ FILE_COMP1, TDIR ^ FILE_COMP2,

                          COMPARE_DATE);

 

    switch (nResult)

        case LESS_THAN:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s was created earlier than %s.",

                       FILE_COMP1, FILE_COMP2);

        case GREATER_THAN:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s was created earlier than %s.",

                       FILE_COMP2, FILE_COMP1);

        case EQUALS:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s and %s have the same creation date and time.",

                       FILE_COMP1, FILE_COMP2);

        default:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "Unable to compare the creation date and time of %s and %s.",

                       FILE_COMP2, FILE_COMP1);

    endswitch;

 

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

     *

     * Compare the file sizes.

     *

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

 

    nResult = FileCompare (SDIR ^ FILE_COMP1, TDIR ^ FILE_COMP2,

        COMPARE_SIZE);

 

    switch (nResult)

        case LESS_THAN:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s is smaller than %s.",

                       FILE_COMP1, FILE_COMP2);

        case GREATER_THAN:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s is smaller than %s.",

                       FILE_COMP2, FILE_COMP1);

        case EQUALS:

            SprintfBox (INFORMATION, MSG_TITLE,

                       "%s and %s are the same size.",

                       FILE_COMP1, FILE_COMP2);

        default:

            SprintfBox(INFORMATION, MSG_TITLE,

                      "Unable to compare the size of %s and %s.",

                      FILE_COMP1, FILE_COMP2);

    endswitch;

 

end;