zoukankan      html  css  js  c++  java
  • InstallShield学习笔记三:脚本(1)

    1.工程说明

    在实际应用中,有 InstallSrcipt MSI 和 InstallSrcipt 这两个工程最常用,基本上脚本是可以共用的,

    但是有个不同:

    在 InstallSrcipt MSI 中,安装路径可以使用 INSTALLDIR 和 TARGETDIR,

    而在 InstallSrcipt 中,只能使用TARGETDIR。

    这里 InstallSrcipt 说明,记录使用过程中遇到的问题。

    2.License选择

    在 OnFirstUIBefore中,已经为工程自定义了许可文件license页面,脚本代码如下::

    Dlg_SdLicense2:
        szTitle = "";
        szOpt1 = "";
        szOpt2 = "";
        //{{IS_SCRIPT_TAG(License_File_Path)
        szLicenseFile = SUPPORTDIR ^ "License.rtf";
        //}}IS_SCRIPT_TAG(License_File_Path)
        //{{IS_SCRIPT_TAG(Dlg_SdLicense2)
        nResult = SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE );
        //}}IS_SCRIPT_TAG(Dlg_SdLicense2)
        if (nResult = BACK) then
            goto Dlg_SdWelcome;
        else
            bLicenseAccepted = TRUE;
        endif;

    这里使用的是 SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, TRUE ),

    在实际应用过程中,用到许可文件是txt格式,在设置参数时,需要将最后一个参数设置为FlALSE,否则许可文件可能会显示不全。

    所以使用 SdLicense2Ex( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted, FALSE); (具体每个参数的含义可以查看帮组文档)

    3.选择安装路径

    在默认情况下,安装路径在选择安装模式之后。

    如果选择“全部”,则会安装在默认路径,即C:Program FilesXXX下

    如果选择“定制”,这会提示安装路径

    考虑看到这个体验不好,可以将路径选择提前,具体脚本代码如下:

    Dlg_SdAskDestPath2:
        szTitle = "";
        szMsg = "";
    //{{IS_SCRIPT_TAG(Dlg_SdAskDestPath2)    
        nResult = SdAskDestPath2( szTitle, szMsg, szDir );
        //}}IS_SCRIPT_TAG(Dlg_SdAskDestPath2)
        TARGETDIR = szDir;
    if (nResult = BACK) goto Dlg_SdRegisterUser; // 注意这里修改后,点击“上一步”时,应该跳转回输入用户信息页面
    
    Dlg_SetupType2:   
        szTitle = "";
        szMsg = "";
        nResult = CUSTOM;
        //{{IS_SCRIPT_TAG(Dlg_SetupType2)    
        nResult = SetupType2( szTitle, szMsg, "", nSetupType, 0 );
        //}}IS_SCRIPT_TAG(Dlg_SetupType2)
        if (nResult = BACK) then
            goto Dlg_SdAskDestPath2; // 在选择安装模式,点击“上一步”,应该跳回安装路径选择界面
        else
            nSetupType = nResult;
            if (nSetupType != CUSTOM) then
                szTargetPath = TARGETDIR;
                nSize = 0;
                FeatureCompareSizeRequired( MEDIA, szTargetPath, nSize );
                if (nSize != 0) then      
                    MessageBox( szSdStr_NotEnoughSpace, WARNING );
                    goto Dlg_SQLServer; // 选择的不是 CUSTOM  即定制,点击“下一步”, 跳转到安装数据库页面 
                endif;
            // 以下是新增部分,选择的是 CUSTOM  即定制,点击“下一步”, 需要跳转到选择组件页面  
             else
                goto Dlg_SdFeatureTree;
            endif;        
        endif;
    
    
    Dlg_SdFeatureTree: 
        if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2;
        szTitle = "";
        szMsg = "";
        szFeatures = "";
        nLevel = 2;
        if (nSetupType = CUSTOM) then
            //{{IS_SCRIPT_TAG(Dlg_SdFeatureTree)    
            nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel );
            //}}IS_SCRIPT_TAG(Dlg_SdFeatureTree)
            if (nResult = BACK) goto Dlg_SetupType2;  
        endif;

    注意:修改时要注意goto的路径,如果配置不会,会出现点击“上一步”或者“下一步”是页面错误。

    4.安装组件选择

    说明:InstallShiled 在自带有记忆功能。在当前页面选择参数后,如路径,组件等,在没有点击“下一步的”时候,这些参数不会被修改,

    此时点击“上一步”,在点击“下一步”后,还是会显示默认值。

    需求:选择安装组件时,当组件已经选择,在点击“上一步”查看前面的数据,再返回到当前页面,需要保证保证当前的组件还是选择状态。

    思路:在SdFeatureTree设置一个全局变量,用来标记组件选择状态。

    使用FeatureIsItemSelected ( szFeatureSource, szFeature );获取组件是否选上;

    使用FeatureSelectItem ( szFeatureSource, szFeature, bSelect );设置组件状态

    (1)在Setup.rul选择“Dailog Source”,选择SdFeatureTree,可以获取到选择组件代码。

    image

    (2)定义全局变量

    //===========================================================================
    //
    //  File Name:    Setup.rul
    //
    //  Description:  Blank setup main script file
    //
    //  Comments:     Blank setup is an empty setup project. If you want to
    //                  create a new project via. step-by step instructions use the
    //                  Project Assistant.
    //
    //===========================================================================
    
    // Included header files ----------------------------------------------------
    #include "ifx.h"
    
    // 全局变量
    BOOL bSelectFeature1, bSelectFeature2;

    (3)在SdFeatureTree(szTitle, szMsg, svDir, szComponents, nLevel)设置状态。

    case SD_TREE_COMPONENT: 条件下增加,因为当我们选择组件时,都会触发这个事件。

    加入一下两段代码

    bSelectFeature1 = FeatureIsItemSelected(MEDIA, "DefaultFeature\NewFeature1");

    bSelectFeature2 = FeatureIsItemSelected(MEDIA, "DefaultFeature\NewFeature2");

    注意:”DefaultFeature\NewFeature1”这里取得名称是新增Feature的名称,不是DisplayName。

    case SD_TREE_COMPONENT:
    
                nTNCode = CtrlGetNotificationCode(szDlg);
                NumToStr(sTN, nTNCode);
    
                if(nTNCode = -402) then //TVN_SELCHANGE
                    if(GetSelectedTreeComponent(nComponentView, strComp) = 0) then
                        ComponentGetData(MEDIA, strComp, COMPONENT_FIELD_DESCRIPTION, n, strDisplayName);
                        SetWindowText(CtrlGetDlgItem("", hwndDlg, SD_STA_MSG2), strDisplayName);
                    endif;
                endif;
    
                //set required size
                ISRT._ComponentGetTotalCostEx(__hContext, MEDIA, svDir, strReqSize, nUnitUsed);
                if ((nUnitUsed != KBYTES) && (nUnitUsed != MBYTES) && (nUnitUsed != GBYTES)) then
                    nUnitUsed = MBYTES;
                endif;
    
                if (StrLengthChars(strReqSize) = 0) then strReqSize = "0.00"; endif;
                strReqSize = strReqSize + " " + StrConvertSizeUnit( nUnitUsed );
                Sprintf(strTempCtrlTxt, strReqFormat, strReqSize,strDrive);
                SetWindowText( hwndReqCtrl, strTempCtrlTxt);
    
                //set Available size
                if(StrLength(svDir) >0 ) then
                    ISRT._GetDiskSpaceExEx(svDir,strAvailSize,nUnitUsed,TRUE,TRUE);
                    if (StrLengthChars(strAvailSize) = 0) then strAvailSize = "0.00"; endif;
                    strAvailSize = strAvailSize + " " + StrConvertSizeUnit( nUnitUsed );
                    Sprintf(strTempCtrlTxt, strAvailFormat, strAvailSize,strDrive);
                    SetWindowText(hwndAvailCtrl, strTempCtrlTxt);
                endif;
                
                // 设置选择状态
                bSelectFeature1 = FeatureIsItemSelected(MEDIA, "DefaultFeature\NewFeature1");
                bSelectFeature2 = FeatureIsItemSelected(MEDIA, "DefaultFeature\NewFeature2");
    
                bDone  = FALSE;

    (4)在Dlg_SdFeatureTree: 中对应增加配置:

    FeatureSelectItem(MEDIA, "DefaultFeature\NewFeature1", bSelectFeature1);

    FeatureSelectItem(MEDIA, "DefaultFeature\NewFeature2", bSelectFeature2);

    技巧:注意到”DefaultFeature\NewFeature1“和 ”DefaultFeature\NewFeature2“ 这两个第(3)步中的一样,可以定义全局的值,使用#define,

    #define FEATURE1    "DefaultFeature\NewFeature1"
    #define FEATURE2    "DefaultFeature\NewFeature2"

    代码:

    Dlg_SdFeatureTree: 
        if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SdAskDestPath2;
        szTitle = "";
        szMsg = "";
        szFeatures = "";
        nLevel = 2;
        if (nSetupType = CUSTOM) then
    
            FeatureSelectItem(MEDIA, "DefaultFeature\NewFeature1", bSelectFeature1);
            FeatureSelectItem(MEDIA, "DefaultFeature\NewFeature2", bSelectFeature2);
            
            //或者
             //FeatureSelectItem(MEDIA, FEATURE1, bSelectFeature1);
            //FeatureSelectItem(MEDIA, FEATURE2, bSelectFeature2);
            
            //{{IS_SCRIPT_TAG(Dlg_SdFeatureTree)    
            nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, szFeatures, nLevel );
            //}}IS_SCRIPT_TAG(Dlg_SdFeatureTree)
            if (nResult = BACK) goto Dlg_SetupType2;  
        endif;
  • 相关阅读:
    javascript页面刷新的几种方法
    Expo大作战(三十九)--expo sdk api之 DocumentPicker,Contacts(获取手机联系人信息),Branch
    Expo大作战(三十八)--expo sdk api之 FileSystem(文件操作系统)
    Expo大作战(三十七)--expo sdk api之 GLView,GestureHandler,Font,Fingerprint,DeviceMotion,Brightness
    Expo大作战(三十六)--expo sdk api之 ImagePicker,ImageManipulator,Camera
    Expo大作战(三十五)--expo sdk api之Location!
    一条SQL语句中算日销售额和月销售额
    绑定sql server数据库的用户与登录名
    牛腩代码生成器
    ASP.NET MVC做的微信WEBAPP中调用微信JSSDK扫一扫
  • 原文地址:https://www.cnblogs.com/winlrou/p/3959415.html
Copyright © 2011-2022 走看看