【发布时间】:2016-05-03 15:09:11
【问题描述】:
我想从 Internet 资源中读取包含版本号的文本文件。然后我需要在我的脚本中使用这个版本号。
如何在 InnoSetup 中做到这一点?
【问题讨论】:
标签: download inno-setup
我想从 Internet 资源中读取包含版本号的文本文件。然后我需要在我的脚本中使用这个版本号。
如何在 InnoSetup 中做到这一点?
【问题讨论】:
标签: download inno-setup
在 InnoSetup 中有很多方法可以从 Internet 获取文件。您可以使用外部库(例如 InnoTools Downloader)、编写自己的库或使用 Windows COM 对象之一。在下面的示例中,我使用了WinHttpRequest COM 对象来接收文件。
此脚本中的DownloadFile 函数在 WinHTTP 函数未引发任何异常时返回 True,否则返回 False。由AURL 参数指定的对URL 的HTTP GET 请求的响应内容然后被传递给声明的AResponse 参数。当脚本运行异常失败时,AResponse 参数将包含异常错误消息:
[Code]
function DownloadFile(const AURL: string; var AResponse: string): Boolean;
var
WinHttpRequest: Variant;
begin
Result := True;
try
WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpRequest.Open('GET', AURL, False);
WinHttpRequest.Send;
AResponse := WinHttpRequest.ResponseText;
except
Result := False;
AResponse := GetExceptionMessage;
end;
end;
procedure InitializeWizard;
var
S: string;
begin
if DownloadFile('http://www.example.com/versioninfo.txt', S) then
MsgBox(S, mbInformation, MB_OK)
else
MsgBox(S, mbError, MB_OK)
end;
【讨论】: