FeatureMoveData Example

InstallShield 2018 ยป InstallScript Language Reference

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

*

* InstallShield Example Script

*

* Demonstrates the functions SdSetupTypeEx, SdFeatureDialog,

* FeatureMoveData, FeatureError, and PlaceWindow.

*

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

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

*         and components (c):

*

*             (f) Program_Files

*                 (c) Program_DLLS

*                 (c) Program_EXEs

*             (f) Example_Files

*                 (sf) Small_Documents

*                      (c) Small_Document_Examples

*                 (sf) Books

*                      (c) Book_Examples

*                 (sf) Graphics

*                      (c) Graphic_Examples

*             (f) Help_Files

*                 (c) Help_Files

*             (f) Utilities

*                 (sf) Grammar_Checker

*                      (c) Grammar_Checker

*                 (sf) Art Studio

*                      (c) Art_Studio

*             (f) Evaluation_Copy

*                 (c) Evaluation_Copy

*                 (c) Help_Files

*

* Insert "dummy" files into the components.  Make sure you

* define the correct file name for the main EXE (MAIN_EXE,

* below) that you insert into the Program_EXEs component.

*

* This example script installs files, adds an icon to the

* Start Programs menu, and provides uninstallation

* functionality.

*

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

 

// Define strings. In a real installation, you would define these in the String Editor

// view and precede each string identifier in the script with the at symbol (@).

#define FEAT_SELECT_TITLE               "Select features"

#define FEAT_SELECT_MSG                 "Select features and subfeatures to install."

#define FEAT_PROGRAMFILES_DISPLAYNAME   "Program Files"

#define PASSWORD_PROMPT                 "Please enter the password."

#define PASSWORD_ERRMSG                 "Password incorrect. Please enter again."

#define TITLE_MAIN                      "Word Processor"

#define TITLE_CAPTIONBAR                "Word Processor Setup"

#define APPBASE_PATH                    "Your Company\\Word Processor"

#define COMPANY_NAME                    "Your Company"

#define PRODUCT_NAME                    "Word Processor"

#define PRODUCT_VERSION                 "1.0"

#define PRODUCT_KEY                     "Word Processor"

#define DEINSTALL_KEY                   "Word Processor"

#define UNINSTALL_NAME                  "Word Processor"

#define ADDINGICON                      "Adding program icon to the Start Programs menu..."

#define PROGRAMDIR                      "Program"

#define DEFAULT_FOLDER_NAME             ""

#define APP_NAME                        "Word Processor"

#define COMPLETE_MSG                    "Setup is complete. You can run Word Processor from the Start Programs menu."

#define MAIN_EXE                        "WRITE.EXE"

#define SETUPTYPE_TITLE                 "Setup Type Selection"

#define SETUPTYPE_MSG                   "Please select a setup type."

#define SETUPTYPE_CUSTOM                "Custom"

 

    // Global variable declarations.

 

    // Function declarations.

    prototype SetUpFileTransfer ();

    prototype HandleFeatureError (NUMBER);

    prototype FinishSetup ();

 

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

#include "Ifx.h"

 

export prototype ExFn_FeatureMoveData(HWND);

 

function ExFn_FeatureMoveData(hMSI)

    STRING  svData, svLogFile,  szProgram, szFeature;

    STRING svResult, svSetupType, svDir;

    BOOL    bInitStepsDone, bPwdValid;

    NUMBER  nvData, nvDisk, nResult;

begin

 

    SetUpFileTransfer ();

 

    // Disable the Back button in installation dialogs.

    Disable (BACKBUTTON);

 

    // Get the setup type.

    svDir = INSTALLDIR;

 

    SdSetupTypeEx (SETUPTYPE_TITLE, SETUPTYPE_MSG, "", svSetupType, 0);

 

    // If user selected Custom setup type, display feature selection dialog.

    if (svSetupType = SETUPTYPE_CUSTOM) then

        SdFeatureDialog (FEAT_SELECT_TITLE, FEAT_SELECT_MSG, svDir, "");

    endif;

 

    // Enable the Back button in installation dialogs.

    Enable (BACKBUTTON);

 

    // Set up the progress indicator, including locations for

    // progress indicator, information gauges, and billboards.

    PlaceWindow (FEEDBACK, LOWER_LEFT, LOWER_LEFT, LOWER_LEFT);

 

    PlaceWindow (STATUSDLG, CENTERED, LOWER_RIGHT, LOWER_RIGHT);

 

    PlaceWindow (BILLBOARD, CENTERED, CENTERED, CENTERED);

 

    Enable (STATUSDLG);

 

    Enable (INDVFILESTATUS);

 

    // Indicate the final percentage the progress bar is to show when the

    // following file transfer operation is complete.

    StatusUpdate (ON, 95);

    

    // Transfer files to the target system.  FeatureMoveData prompts

    // for next disk in a floppy disk installation.

    nResult=FeatureMoveData (MEDIA, nvDisk, 0);

 

    // See the FeatureError function in action.

    HandleFeatureError (nResult);

    

    FinishSetup();

 

end;

 

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

*

* Function:  SetupFileTransfer()

*

*  Purpose:  This function sets up file transfer. The main reason for

*            abstracting this process into this function is to make it

*            easy to see the function calls this sample script demonstrates.

*

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

function SetUpFileTransfer()

 

begin

  // Set up the installation screen.

  Enable (FULLWINDOWMODE);

  SdProductName ( PRODUCT_NAME );

  SetTitle (TITLE_MAIN, 24, WHITE);

  SetTitle (TITLE_CAPTIONBAR, 0, BACKGROUNDCAPTION);

  Enable (BACKGROUND);

 

  // Welcome the user, check that the system meets minimum requirements,

  // and verify the destination location.

  bInitStepsDone = FALSE;

 

  while (!bInitStepsDone)

    Disable (BACKBUTTON);

    Welcome ("", 0);

    Enable (BACKBUTTON);

    INSTALLDIR = PROGRAMFILES ^ APPBASE_PATH;

    if (AskDestPath ("", "", INSTALLDIR, 0) != BACK) then

      bInitStepsDone = TRUE;

    endif;

  endwhile;

 

  // Set installation information required for registry entries and for

  // the following call to DeinstallStart.

  InstallationInfo (COMPANY_NAME, PRODUCT_NAME,

                   PRODUCT_VERSION, PRODUCT_KEY);

 

  // Initialize the uninstallation log file, including registry entry.

  svLogFile = "Uninst.isu";

 

  DeinstallStart (INSTALLDIR, svLogFile, DEINSTALL_KEY, 0);

 

  RegDBSetItem (REGDB_UNINSTALL_NAME, UNINSTALL_NAME);

end;

 

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

*

* 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 installation.

*

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

function HandleFeatureError (nResult)

  NUMBER  nvError;

  STRING  svFeatureSource, svFeature, svComponent, svFile;

begin

  if (nResult < 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;

 

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

*

* Function:  FinishSetup()

*

*  Purpose:  This function finishes the installation. The main reason for

*            abstracting this process into this function is to make it

*            easy to see the function calls this sample script demonstrates.

*

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

function FinishSetup()

begin

  // Indicate the final percentage the progress bar is to show when the

  // following file transfer operation is complete.

  StatusUpdate(ON, 99);

 

  // Increment progress bar to 99% for creation of Start Programs menu icon.

  SetStatusWindow (96 , ADDINGICON);

 

  // Add the APP_NAME icon to the DEFAULT_FOLDER_NAME folder.

  szProgram = INSTALLDIR ^ PROGRAMDIR ^ MAIN_EXE;

 

  LongPathToQuote (szProgram, TRUE);

  AddFolderIcon (DEFAULT_FOLDER_NAME, APP_NAME, szProgram,

                INSTALLDIR ^ PROGRAMDIR, "", 0, "", REPLACE);

 

  Delay (1);

 

  // Disable the progress indicator and its settings.

  Disable  (INDVFILESTATUS);

  Disable (STATUSDLG);  

 

  // Announce installation complete and offer to view Readme file.

  MessageBox (COMPLETE_MSG, INFORMATION);

 

end;