如果已选择该组件,则通过 Internet 下载文件(使用 Inno Tools Downloader)

downloading files over the internet, if the component has been selected (WITH Inno Tools Downloader)

此代码实际上是为我下载文件,selected 组件是否 "test" 并不重要。我要下载这两个文件,如果你 select 一个组件,可以吗? 我使用 Inno Inno Setup 5 + Tools Downloader)

[Components]
Name: Dictionaries; Description: "test"; Types: Full; ExtraDiskSpaceRequired: 50;

[Languages]
Name: english; MessagesFile: compiler:Default.isl

    #include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');

[Code]
    procedure InitializeWizard();
    begin
     itd_init;


     itd_addfile('http://www.sherlocksoftware.org/petz/files/dogz5.zip',expandconstant('{tmp}\dogz5.zip'));
     itd_addfile('http://www.sherlocksoftware.org/petz/files/petz4.zip',expandconstant('{tmp}\petz4.zip'));


     itd_downloadafter(wpReady);
    end;

    procedure CurStepChanged(CurStep: TSetupStep);
    begin
     if CurStep=ssInstall then begin 
      filecopy(expandconstant('{tmp}\dogz5.zip'),expandconstant('{app}\dogz5.zip'),false);
      filecopy(expandconstant('{tmp}\petz4.zip'),expandconstant('{app}\petz4.zip'),false);
     end;
    end;

是的,这是可能的。您正在寻找一个名为 IsComponentSelected()

它基本上是一个布尔测试器,它从 [components] 中接受组件 name 并返回复选框值 (selected=true)。

// for a single component
if IsComponentSelected('NameOfTheComponent') then idpAddFile(URL, ...);`

// multiple components with one selection
if IsComponentSelected('dictionaries') then
begin
   idpAddFile(URL1, ...);
   idpAddFile(URL2, ...);
end;

TLama 的评论:

In which event and where to enqueue the download files?

我建议使用带有条件的 NextButtonClick 事件,即当前 (CurPage) 必须是组件选择屏幕 (wpSelectComponents)。 换句话说:当您在组件选择屏幕上并按下一步时,只会将所选组件添加到下载器。

代码可能如下所示:

function NextButtonClick(CurPage: Integer): Boolean;
(*
    Called when the user clicks the Next button.
    If you return True, the wizard will move to the next page.
    If you return False, it will remain on the current page (specified by CurPageID).
*)
begin
  if CurPage = wpSelectComponents then
  begin
    if IsComponentSelected('NameOfTheComponent') then idpAddFile(URL, ...);

  end; // of wpSelectComponents

  Result := True;
end;

旁注:您可以将下载库切换到 https://code.google.com/p/inno-download-plugin/ 这具有更好的功能,包括不错的 https 支持,并且得到积极维护。 SherlockSoftware 下载的 InnoTools 已过时 (2008)。