FeatureFileInfo Example

InstallShield 2015 ยป InstallScript Language Reference

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

*

* InstallShield Example Script

*

* Demonstrates the FeatureFileInfo function.

*

* This script calls FeatureFileInfo repeatedly to retrieve

* information about the file media. The information is stored

* in a list and then displayed.

*

* Note: To run this example script, create a project with the

*       following features (f), subfeatures (sf), and

*       components (c):

*

*       (f) Example_Files

*           (sf) Graphics

*                (c) Graphic_Examples

*

*       Be sure to assign at least one file to the Graphic_Examples

* component so there is something to enumerate.

*       Also, remember to specify the file name in the #define

*       FILE line.

*

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

 

#define FEAT         "Example Files"

#define SUBFEAT      "Graphics"

#define COMP      "Graphic Examples"

#define FILE         "comdlg32.dll"

#define SDSHOWTITLE  "ComponentFileInfo Results"

#define SDSHOWMSG    FILE + " information:"

 

prototype HandleFeatureError (NUMBER);

 

NUMBER nReturn, nvResult;

STRING svResult;

LIST   listID;

 

program

 

   // Create a list to store file media information.

   listID = ListCreate (STRINGLIST);

 

   // Get the original size of the specified file.

   nReturn = FeatureFileInfo (MEDIA, FEAT + "\\" + SUBFEAT,

                                COMP +  "\\" + FILE,

                                FEATURE_INFO_ORIGSIZE , nvResult, svResult);

 

   HandleFeatureError (nvResult);

 

   // Convert the original size to a string.

   Sprintf (svResult ,"%d", nvResult);

 

   // Add the string to the list.

   ListAddString (listID, "The Original size of the file is       " +

                  svResult, AFTER);

 

   // Get the attributes of the specified file.

   nReturn = FeatureFileInfo (MEDIA, FEAT + "\\" + SUBFEAT,

                                COMP +  "\\" + FILE,

                                FEATURE_INFO_ATTRIBUTE , nvResult, svResult);

 

   HandleFeatureError (nReturn);

 

   // If no attributes are set, indicate normal attributes.

   if (nvResult = FILE_ATTR_NORMAL) then

       svResult = "normal";

 

   // If attributes are set, concatenate them for display.

 

   else

      if (FILE_ATTR_ARCHIVED & nvResult) then

         svResult = "archived,";

      endif;

 

      if (FILE_ATTR_HIDDEN & nvResult) then

          svResult = svResult + "hidden,";

      endif;

 

      if (FILE_ATTR_READONLY & nvResult) then

          svResult = svResult + "read-only,";

      endif;

 

      if (FILE_ATTR_SYSTEM & nvResult) then

         svResult = svResult + "system,";

      endif;

 

      if (FILE_ATTR_DIRECTORY & nvResult) then

         svResult = svResult + "directory,";

 

      endif;

 

    endif;

 

    // Add the string of attributes to the list.

    ListAddString (listID, "The attribute for the file is          " +

                   svResult, AFTER);

 

    // Get the major file version of the specified file.

    nReturn = FeatureFileInfo (MEDIA, FEAT + "\\" + SUBFEAT,

                                 COMP +  "\\" + FILE,

                                 FEATURE_INFO_VERSIONMS , nvResult, svResult);

    HandleFeatureError (nReturn);

 

    // Add the major file version to the list.

    ListAddString (listID, "The upper 32-bit version value         " +

                   svResult, AFTER);

 

    // Get the minor file version of the specified file.

    nReturn = FeatureFileInfo (MEDIA, FEAT + "\\" + SUBFEAT,

                                 COMP +  "\\" + FILE,

                                 FEATURE_INFO_VERSIONLS , nvResult, svResult);

    HandleFeatureError (nReturn);

 

    // Add the minor file version to the list.

 

    ListAddString (listID, "The lower 32-bit version value is       " +

                  svResult, AFTER);

 

    // Get the complete file version of the specified file.

    nReturn = FeatureFileInfo (MEDIA, FEAT + "\\" + SUBFEAT,

                             COMP +  "\\" + FILE,

                             FEATURE_INFO_VERSIONSTR , nvResult, svResult);

 

    HandleFeatureError (nReturn);

 

// Add the complete file version to the list.

ListAddString (listID, "The version for the file is             " +

 

               svResult, AFTER);

 

// Display the list.

SdShowInfoList (SDSHOWTITLE, SDSHOWMSG, listID);

 

// Release the list from memory.

ListDestroy(listID);

 

endprogram

 

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

*

* Function:  HandleFeatureError

*

*  Purpose:  This function evaluates the value returned by a feature

*            function and if the value is less than zero, displays the error

*            number and aborts the setup.

*

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

function HandleFeatureError (nvResult)

 

   NUMBER  nvError;

   STRING  svFeatureSource, svFeature, svComponent, svFile;

 

begin

   if (nvResult < 0) then

      FeatureError(svFeatureSource, svFeature, svComponent, svFile, nvError);

      SprintfBox(INFORMATION, "Data Transfer Error Information",

                 "FeatureError returned the following data transfer error.\n" +

 

                 "Setup will now abort.\n\n" +

                 "Media Name: %s\nFeature: %s\nComponent: %s\n" +

                 "File: %s\nError Number: %ld",

                 svFeatureSource, svFeature, svComponent, svFile, nvError);

      abort;

   endif;

end;