2011-05-22 120 views
1

我正在使用Inno Setup Compiler(Pascal脚本)。 我的表单有一个图像对象(TBitmapImage),我想提供从网址获得的动态图像。是否可以在Inno Setup脚本中静默下载图像(或其他类型的文件)?Inno Setup图像下载

回答

0

Inno安装程序没有任何内置功能,但是,您可以使用为您执行工作的批处理文件执行此操作。

1)下载喜欢命令行URL资源下载 - http://www.chami.com/free/url2file_wincon.html

关于如何使用它的一些技巧 - http://www.chami.com/tips/windows/062598W.html

2)在您的安装

3包吧)创建批处理文件调用url2file.exe并将您的映像提取到应用程序目录中

4)在initialize setup命令中调用该批处理文件Inno Setup安装程序脚本

5)无论你想要的地方使用该图像!

ps - 如果您在设置中使用图像,请检查是否允许不同的图像加载..我不确定这一点。 让我知道如果您有任何其他疑问

3

我会写一个小的Win32程序,从Internet下载文件,如

program dwnld; 

uses 
    SysUtils, Windows, WinInet; 

const 
    PARAM_USER_AGENT = 1; 
    PARAM_URL = 2; 
    PARAM_FILE_NAME = 3; 

function DownloadFile(const UserAgent, URL, FileName: string): boolean; 
const 
    BUF_SIZE = 4096; 
var 
    hInet, hURL: HINTERNET; 
    f: file; 
    buf: PByte; 
    amtc: cardinal; 
    amti: integer; 
begin 
    result := false; 
    hInet := InternetOpen(PChar(UserAgent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
    try 
    hURL := InternetOpenUrl(hInet, PChar(URL), nil, 0, 0, 0); 
    try 
     GetMem(buf, BUF_SIZE); 
     try 
     FileMode := fmOpenWrite; 
     AssignFile(f, FileName); 
     try 
      Rewrite(f, 1); 
      repeat 
      InternetReadFile(hURL, buf, BUF_SIZE, amtc); 
      BlockWrite(f, buf^, amtc, amti); 
      until amtc = 0; 
      result := true; 
     finally 
      CloseFile(f); 
     end; 
     finally 
     FreeMem(buf); 
     end; 
    finally 
     InternetCloseHandle(hURL); 
    end; 
    finally 
    InternetCloseHandle(hInet); 
    end; 
end; 

begin 

    ExitCode := 0; 

    if ParamCount < 3 then 
    begin 
    MessageBox(0, 
     PChar(Format('%s: This program requires three command-line arguments.', 
     [ExtractFileName(ParamStr(0))])), 
     PChar(ExtractFileName(ParamStr(0))), 
     MB_ICONERROR); 
    Exit; 
    end; 

    if FileExists(ParamStr(PARAM_FILE_NAME)) then 
    DeleteFile(PChar(ParamStr(PARAM_FILE_NAME))); 

    if DownloadFile(ParamStr(PARAM_USER_AGENT), ParamStr(PARAM_URL), 
     ParamStr(PARAM_FILE_NAME)) then 
    ExitCode := 1; 

end. 

这个程序有三个命令行参数:用户代理,以发送到Web服务器(可以是任何内容,例如“MyApp Setup Utility”),Internet上文件的URL以及正在创建的文件的文件名。如果下载失败,程序的退出代码为0,如果下载成功,程序的退出代码为1

然后,在您的Inno Setup脚本中,您可以执行

[Files] 
Source: "dwnld.exe"; DestDir: "{app}"; Flags: dontcopy 

[Code] 

function InitializeSetup: boolean; 
var 
    ResultCode: integer; 
begin 
    ExtractTemporaryFile('dwnld.exe'); 
    if Exec(ExpandConstant('{tmp}\dwnld.exe'), 
     ExpandConstant('"{AppName} Setup Utility" "http://privat.rejbrand.se/sample.bmp" "{tmp}\bg.bmp"'), 
     '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then 
    if ResultCode = 1 then  
     (* Now you can do something with the file ExpandConstant('{tmp}\bg.bmp') *); 
end; 

然而不幸的是,我知道没有办法通过它可以在运行时改变了WizardImageFile ...