如何在 InstallScript 代码中添加倒数计时器?

How to add count down timer in InstallScript code?

我创建了一个 Basic MSI 项目,并在其中编写了一个 InstallScript 自定义操作来从服务器下载文件。我为此使用了 CopyFile() 函数。在此下载过程中,我还显示了 sdShowMsg()。但是,当下载服务器没有响应时,sdShowMsg() 对话框将保持在屏幕上并在后台下载,不会发生。那么有没有什么办法可以添加一个倒计时定时器,只执行那段时间的下载操作,然后退出。或者有没有其他方法可以先检查下载服务器是否有响应?

SdShowMsg("Please Wait... Downloading file from our server...", TRUE);
CopyFile("https://<downloadURL>/sample.rtf", szEULAFile);
SdShowMsg("Please Wait... Downloading file from our server...", FALSE);

您可以使用外部命令替换 CopyFile 调用来下载文件,然后使用 LaunchApp() 函数,设置超时。 这是一个使用 powershell 的小伪示例(您也可以使用 curl.exe 和许多其他方法从命令行下载文件)

nOptions = LAAW_OPTION_WAIT | LAAW_OPTION_HIDDEN | LAAW_OPTION_FIXUP_PROGRAM | LAAW_OPTION_SHOW_HOURGLASS;
LAAW_PARAMETERS.nTimeOut = 30000;  // 30 seconds
SdShowMsg("Downloading, please wait...", TRUE);
nResult = LaunchAppAndWait( "powershell", "-Command \"Invoke-WebRequest -Uri https://example.com/sample.rtf -OutFile " + szEULAFile + "\"", nOptions); 
SdShowMsg("", FALSE);
if nResult < 0 then
  // failed to launch, notify the user
elseif (nResult == 5) || (nResult == 259) then
  // timeout reached, notify the user
endif;