InnoSetup网站上提供的
ispack就有此功能,其实现没有公布,但应该是采用了
isxdl(这是
ISTools的一部分,属于
InnoSetup的推荐扩展)。
isxdl以dll的方式提供,可以利用已有的窗口句柄显示其界面, InnoSetup的另一个推荐扩展 ISSI提供了对isxdl的一个封装实现:
#define ISSI_English
#define ISSI_Download_Title "Title Of Your Application"
#define ISSI_Download_URL "http://someserver/setup.exe"
#define ISSI_IncludePath "C:/ISSI"
#include ISSI_IncludePath+"/_issi.isi"
This #Include will make it easy to make a 'loader setup'. It will download another (Inno) setup.exe and installs it through the loader setup.
但实际使用中,这样的做法非常不灵活:
由于以上三个毛病,一般不推荐直接使用ISSI_Download_URL宏来实现下载功能。而是直接调用 isxdl。
下面是一个集成了下载的功能的inno setup脚本片段:
{ 从isxdl.dll中引入函数,这些函数声明可以从 isxdl 安装后目录中的isxdl.iss文件中找到 }
function isxdl_Download(hWnd: Integer; URL, Filename: PChar): Integer;
external 'isxdl_Download@files:isxdl.dll stdcall';
function isxdl_SetOption(Option, Value: PChar): Integer;
external 'isxdl_SetOption@files:isxdl.dll stdcall';
{ 响应NextButtonClick事件,动态显示下载对话框,
这里调用的NeedDownloadXXX是你自己写的函数,判断是否需要下载 }
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd : Integer;
nRet : Integer;
bRet : Boolean;
begin
Result := true;
if (CurPage = wpReady) And NeedDownloadXXX() then begin
{ wizardhwnd可以获得当前page的窗口句柄 }
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
isxdl_SetOption('label', '下载安装XXX');
isxdl_SetOption('description', '正在下载XXX,请稍候');
if isxdl_Download( hWnd,
'http://www.xxxx.com/setup.exe',
ExpandConstant('{tmp}/setup.exe')
) <> 0 then begin
bRet := Exec( ExpandConstant('{tmp}/setup.exe'),
'',
'',
SW_SHOW,
ewWaitUntilTerminated,
nRet );
if not bRet or (nRet <> 0) then begin
MsgBox( '安装xxx失败', mbInformation, MB_OK );
end;
end
else begin
MsgBox( '下载xxx失败', mbInformation, MB_OK );
end;
end;
end;
end;
最后,注意要在安装脚本的[Files]段中添加isxdl.dll(这个文件在ISSI的子目录Include/isxdl中)
Source: isxdl.dll; DestDir: {src}; Flags: ignoreversion dontcopy noencryption
isxdl以dll的方式提供,可以利用已有的窗口句柄显示其界面, InnoSetup的另一个推荐扩展 ISSI提供了对isxdl的一个封装实现:
#define ISSI_English
#define ISSI_Download_Title "Title Of Your Application"
#define ISSI_Download_URL "http://someserver/setup.exe"
#define ISSI_IncludePath "C:/ISSI"
#include ISSI_IncludePath+"/_issi.isi"
This #Include will make it easy to make a 'loader setup'. It will download another (Inno) setup.exe and installs it through the loader setup.
但实际使用中,这样的做法非常不灵活:
- 首先,一旦Include ISSI_IncludePath+"/_issi.isi",你原先定义的InitializeSetup等事件函数都将被替换,必须用更加别扭的语法才能使用。
- 其次,由于使用的是预处理宏,因此这个实现不能动态地判断是否需要下载,当然你可以修改_issi.isi文件来实现动态判断,但这实在有点过分了。
- 再其次,setup.exe下载完成后的执行命令竟然被写死在_issi.isi的代码中,还为其加上了两个命令行参数,某些安装程序就可能为了这两个不认识的命令行参数而报错。
由于以上三个毛病,一般不推荐直接使用ISSI_Download_URL宏来实现下载功能。而是直接调用 isxdl。
下面是一个集成了下载的功能的inno setup脚本片段:
{ 从isxdl.dll中引入函数,这些函数声明可以从 isxdl 安装后目录中的isxdl.iss文件中找到 }
function isxdl_Download(hWnd: Integer; URL, Filename: PChar): Integer;
external 'isxdl_Download@files:isxdl.dll stdcall';
function isxdl_SetOption(Option, Value: PChar): Integer;
external 'isxdl_SetOption@files:isxdl.dll stdcall';
{ 响应NextButtonClick事件,动态显示下载对话框,
这里调用的NeedDownloadXXX是你自己写的函数,判断是否需要下载 }
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd : Integer;
nRet : Integer;
bRet : Boolean;
begin
Result := true;
if (CurPage = wpReady) And NeedDownloadXXX() then begin
{ wizardhwnd可以获得当前page的窗口句柄 }
hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));
isxdl_SetOption('label', '下载安装XXX');
isxdl_SetOption('description', '正在下载XXX,请稍候');
if isxdl_Download( hWnd,
'http://www.xxxx.com/setup.exe',
ExpandConstant('{tmp}/setup.exe')
) <> 0 then begin
bRet := Exec( ExpandConstant('{tmp}/setup.exe'),
'',
'',
SW_SHOW,
ewWaitUntilTerminated,
nRet );
if not bRet or (nRet <> 0) then begin
MsgBox( '安装xxx失败', mbInformation, MB_OK );
end;
end
else begin
MsgBox( '下载xxx失败', mbInformation, MB_OK );
end;
end;
end;
end;
最后,注意要在安装脚本的[Files]段中添加isxdl.dll(这个文件在ISSI的子目录Include/isxdl中)
Source: isxdl.dll; DestDir: {src}; Flags: ignoreversion dontcopy noencryption