在我的Inno Setup项目中,我从服务器下载所有文件,还下载了一个有版本号的文件。现在我想从文件中读取版本,并将其分配给Code
部分中的[Setup]
部分AppVersion
。我的问题是,是否可以在Code
部分设置应用程序版本?
结合这两个问题:
- 如何从Inno Setup Pascal Script设置版本号
- Inno设置-HTTP请求-获取www/web内容
[Setup]
AppVersion={code:GetAppVersion}
[Code]
var
Version: string;
function GetAppVersion(Param: string): string;
var
WinHttpReq: Variant;
begin
if Version = '' then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('GET', 'https://www.example.com/version.txt', False);
WinHttpReq.Send('');
if WinHttpReq.Status <> 200 then
begin
Log('HTTP Error: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText);
MsgBox('Cannot obtain version', mbError, MB_OK);
Abort();
end
else
begin
Version := Trim(WinHttpReq.ResponseText);
Log('Version: ' + Version);
// you may want to validate that the value is meaningful here
end;
end;
Result := Version;
end;