inno-setuppascalscriptinno-tools-downloaderinno-download-plugin

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


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;

Solution

  • 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).