2

This code actually download me the files and it does not matter whether the selected component is "test" or not. I want those two files download, if you select a component, can do that? I use 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;
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
michal3210
  • 117
  • 1
  • 7

1 Answers1

4

Yes, that's possible. Your are looking for a little helper function called IsComponentSelected().

It's basically a boolean tester accepting a component name from the [components] and returning the checkbox value (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;

Comment by TLama:

In which event and where to enqueue the download files?

I would suggest to use the NextButtonClick event with a condition, that the current (CurPage) has to be the component selection screen (wpSelectComponents). In other words: when you are on the component selection screen and press next, only the selected components are added to the downloader.

The code could look like this:

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;

Sidenote: you might switch your download lib to https://code.google.com/p/inno-download-plugin/ This has better features, including decent https support and is actively maintained. InnoTools Download by SherlockSoftware is outdated (2008).

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • Though I agree with you in everything what you said, it's worth to mention in which event would you test and enqueue those files. – TLama Apr 04 '15 at 09:48
  • 1
    Good idea. I would suggest the `NextButtonClick` event with `CurPage = wpSelectedComponents` for adding the files to the downloader. I've updated my answer. – Jens A. Koch Apr 04 '15 at 10:47
  • And we can do to unpack the downloaded file in the location where the application is installed? – michal3210 Apr 04 '15 at 12:40
  • I'd recommend using `wpReady` rather than `wpSelectComponents`. A user can always return back to the "components" page and unselect the component, but the download will already be registered. Using `wpReady` is actually, what the `components2.iss` example of Inno Download Plugin shows. Though Inno Download Plugin actually has a simpler API for component-based downloads - `idpAddFileComp` - See [Downloading file with Inno Setup only when user chooses to](https://stackoverflow.com/q/56439471/850848). – Martin Prikryl Jun 04 '19 at 13:05