任何人都可以推荐一种方法:
我有我的主应用程序,根据一些条件,客户可以选择安装与主应用程序相关的 7 个驱动程序的文件。问题是他们希望更新进度文本,例如:
如果选择功能 1,则添加文本“安装功能 1”
据我所知,我将如何实现这一目标的任何想法,我们只能为自定义操作设置进度文本..:(
任何人都可以推荐一种方法:
我有我的主应用程序,根据一些条件,客户可以选择安装与主应用程序相关的 7 个驱动程序的文件。问题是他们希望更新进度文本,例如:
如果选择功能 1,则添加文本“安装功能 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);
}