0

我已经创建了一个基本 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);
4

1 回答 1

2

您可以将 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;
于 2018-05-29T06:00:25.503 回答