SdConfirmNewDir Example

InstallShield 2015 » InstallScript Language Reference

Project: This information applies to the following project types:

InstallScript
InstallScript MSI

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

*

* InstallShield Example Script

*

* Demonstrates the SdConfirmNewDir function.

*

* This example script first calls SdAskDestPath to get the

* destination folder from the user.  If the folder does not

* exist, SdConfirmNewDir is then called to ask if the user

* wants to create the folder.

*

* Note: This script creates directories on the local hard disk.

*

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

 

#define DEFAULT_TARGET_FOLDER "C:\\NONEXIST\\DIR";

#define TITLE_TEXT "SdConfirmNewDir Example"

 

#include "ifx.h"

 

function OnBegin()

    NUMBER nResult;

    STRING szMsg, svDir;

begin    

 

    // Disable the Back button in setup dialogs.

    Disable (BACKBUTTON);

 

start:

    // Set up parameters for call to SdAskDestPath.

    szMsg = "Select destination folder:";

    svDir = DEFAULT_TARGET_FOLDER

 

    // Retrieve destination folder from user.

    nResult = SdAskDestPath (TITLE_TEXT, szMsg, svDir, 0);

 

    // Check if the selected folder exists.

    if (ExistsDir (svDir) = EXISTS) then

        // Inform user that the specified folder already exists.

        szMsg = "folder '%s' already exists.\n\nIn order for this example to " +

                "run properly, please specify a nonexisting folder.";

        SprintfBox (INFORMATION, TITLE_TEXT, szMsg, svDir);

 

        // Start over.

        goto start;

    else

        // The specified folder does not exist. Request user

        // confirmation to create it.

        nResult = SdConfirmNewDir (TITLE_TEXT, svDir, 0);

 

        if (nResult = NO) then

            // The user did not want it created select.

            MessageBox ("Selected folder was not created.", INFORMATION);

 

            // Start over.

            goto start;

        elseif (nResult = YES) then

            // The user wants to create the folder.

            SprintfBox (INFORMATION, TITLE_TEXT, "%s created.", svDir);

        elseif (nResult < 0) then

            // Report the error; then terminate.

            MessageBox ("SdConfirmNewDir failed.", SEVERE);

            abort;

        endif;

    endif;

 

end;