Search code examples
inno-setuppascalscriptinno-download-plugin

Download based on the task selected with Inno Download Plugin?


I have been having a couple of problems trying to achieve what I want and I will discuss each issue separately. It concerns a help documentation setup file which I has asked about before. But now I am using IDP I need to change my logic and have it wrong.

Firstly, I have this task:

Name: "downloadhelp"; Description: "{cm:DownloadHelpTask}"; \
    GroupDescription: "{cm:DownloadHelpGroup}"; Flags: unchecked

Then I added this:

procedure CurPageChanged(CurPageID: Integer);
begin
    if CurPageID = wpReady then
    begin
        if (WizardIsTaskSelected('downloadhelp')) then
            AddFileForDownload('{#HelpDocSetupURL}', ExpandConstant('{tmp}\HelpDocSetup.exe'));
    end;

    WizardForm.CancelButton.Top := WizardForm.NextButton.Top;
end;

And this is in [Run] section:

Filename: "{app}\HelpDocSetup.exe"; \
    Parameters: "/SP- /VERYSILENT /InstallPath=""{app}"""; \
    WorkingDir: "{app}"; \
    Flags: waituntilterminated runhidden; \
    Description: "{cm:InstallingHelpDescription}"; \
    StatusMsg: "{cm:InstallingHelpStatusMessage}"; \
    Tasks: downloadhelp

But when I am on my "ready" page the file is not listed for download.

When exactly is is Ok to add a file to download based on the task being selected?

I realize now that wpReady means we have already filled the memo content. Previously I was using this line:

;Source: "{tmp}\HelpDocSetup.exe"; \
;    DestDir: "{app}"; \
;    Flags: external deleteafterinstall; \
;    Tasks: downloadhelp; \
;    Check: DwinsHs_Check( ExpandConstant('{tmp}\HelpDocSetup.exe'), '{#HelpDocSetupURL}', \
;            'My_Setup', 'Get', {#HelpDocSetupFileSize}, 0 )

The task is listed correctly:

enter image description here

But I need to add it if the task is selected. It is now obsolete. What do I do?

I see this question but it relates to components and not tasks.

The second answer here sounds possible solution.

Based on the linked answer I added:

function NextButtonClick(CurPageID: integer): boolean;
begin
    Result := True;

    if(CurPageID = wpSelectTasks) then
    begin
        if WizardIsTaskSelected('downloadhelp') then
            AddFileForDownload('{#HelpDocSetupURL}', ExpandConstant('{tmp}\HelpDocSetup.exe'));
    end;
end;

But this is flawed. If the user uses next / back it keeps adding the file multiple times to the list of files to download and my memo ready page lists all of them.

I tried changing it to use components and the "Download Help" listed there. Then I was able to simply use idpAddFileComp in InitializeWizard but then I end up with the former problem of listing the file as needing to be downloaded.


Solution

  • There's no really elegant way to solve this with IDP.

    One way is to call idpClearFiles in BackButtonClick(wpReady).

    For this to work, you will of course need to be adding all files in NextButtonClick(wpSelectTasks) – Even those that are added unconditionally.