功能Wix的进度文本

时间:2012-12-13 10:52:09

标签: wix

任何人都可以推荐一种方法:

我有我的主应用程序,并且根据一些条件,客户可以选择安装与主应用程序相关的7个驱动程序的文件。问题是他们希望将进度文本更新为:

如果选择了功能1,则添加文本“安装功能1”

任何想法如何实现这一点,据我所知,我们只能设置自定义操作的进度文本.. :(

1 个答案:

答案 0 :(得分:1)

首先,我将ADDLOCAL属性设置为CustomActionData

 <CustomAction Id="SetAddLocalProperty" Return="check" Property="InstallDrivers" Value="[ADDLOCAL]"></CustomAction> 

然后,我在调用InstallDriver自定义操作之前安排了此自定义操作:

extern "C" UINT __stdcall InstallDrivers(MSIHANDLE hInstall)
{
    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;
    LPWSTR szValueBuf = NULL;
    char CustomActionData[MAX_PATH];
    const UINT iTickIncrement = 1000;
    const UINT iNumberItems = 3;
    const UINT iTotalTicks = iTickIncrement * iNumberItems;
    PMSIHANDLE hActionRec = MsiCreateRecord(10);
    PMSIHANDLE hProgressRec = MsiCreateRecord(3);

    hr = WcaInitialize(hInstall, "InstallDrivers");
    ExitOnFailure(hr, "Failed to initialize");

    WcaLog(LOGMSG_STANDARD, "Initialized.");

    hr = WcaGetProperty(L"CustomActionData",&szValueBuf);
    ExitOnFailure(hr, "failed to get CustomActionData");

    wcstombs(CustomActionData, szValueBuf, 260);

    char *token = strtok(CustomActionData, ",");

    while (token != NULL) 
    {
        MsiRecordSetString(hActionRec, 1, TEXT("MyCustomAction"));

        if (strcmp(token, "Driver1") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver1"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver2") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver2"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver3") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver3"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver4") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver4"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver5") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver5"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver6") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver6"));
            token = strtok (NULL, ",");
        }
        else if (strcmp(token, "Driver7") ==0)
        {
            MsiRecordSetString(hActionRec, 2, TEXT("Installing Driver7"));
            token = strtok (NULL, ",");
        }   
        else
        {
            MsiRecordSetString(hActionRec, 2, TEXT(""));
            token = strtok (NULL, ",");
        }

        MsiRecordSetString(hActionRec, 3, TEXT("Incrementing tick [1] of [2]"));

        UINT iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONSTART, hActionRec);
        if ((iResult == IDCANCEL))
            return ERROR_INSTALL_USEREXIT;


        MsiRecordSetInteger(hProgressRec, 1, 1);
        MsiRecordSetInteger(hProgressRec, 2, 1);
        MsiRecordSetInteger(hProgressRec, 3, 0);
        iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_PROGRESS, hProgressRec);
        if ((iResult == IDCANCEL))
            return ERROR_INSTALL_USEREXIT;

        MsiRecordSetInteger(hProgressRec, 1, 2);
        MsiRecordSetInteger(hProgressRec, 2, iTickIncrement);
        MsiRecordSetInteger(hProgressRec, 3, 0);

        MsiRecordSetInteger(hActionRec, 2, iTotalTicks);

        for( int i = 0; i < iTotalTicks; i+=iTickIncrement)
        {
            MsiRecordSetInteger(hActionRec, 1, i);

            iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hActionRec);
            if ((iResult == IDCANCEL))
                return ERROR_INSTALL_USEREXIT;

            iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_PROGRESS, hProgressRec);
            if ((iResult == IDCANCEL))
                return ERROR_INSTALL_USEREXIT;

            Sleep(1000);            
        }
    }

    LExit:
    er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
    return WcaFinalize(er);
}