2011-05-22 118 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 ...