Andrew Truckle
Andrew Truckle

Reputation: 19157

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.

Upvotes: 2

Views: 286

Answers (2)

Andrew Truckle
Andrew Truckle

Reputation: 19157

I don't know if this was the best way, but at least it works.

Step 1

I added a new [Components] section like this:

[Components]
Name: downloadhelpcomponent; Description: "{cm:DownloadHelpTask}"

Step 2

I commented out the previous [Tasks] entry:

[Tasks]
;Name: "downloadhelp"; Description: "{cm:DownloadHelpTask}"; GroupDescription: "{cm:DownloadHelpGroup}"; Flags: unchecked

Step 3

I added the following to initializeWizard:

procedure InitializeWizard();
begin
    idpAddFileSizeComp('{#HelpDocSetupURL}', ExpandConstant('{tmp}\HelpDocSetup.exe'), {#HelpDocSetupFileSize}, 'downloadhelpcomponent');

    idpDownloadAfter(wpReady);

    { Make download wizard page resizeable }
    IDPForm.TotalProgressBar.Anchors := [akLeft, akTop, akRight];
    IDPForm.FileProgressBar.Anchors := [akLeft, akTop, akRight];
    IDPForm.TotalDownloaded.Anchors := [akTop, akRight];
    IDPForm.FileDownloaded.Anchors := [akTop, akRight];
    IDPForm.DetailsButton.Anchors := [akTop, akRight];
end;

When I run this installer the page looks like this:

Components

The main problem here is that it has decided this component is 56MB and that is wrong! The file is actually 7.28MB. Although I suppose the 56MB is the whole setup. Also, the various "Types" don't really make sense, but if I remove them I lose the check box choices.

Step 4

I adjusted the UpdateReadyMeno output like this:

function UpdateReadyMemo(Space, 
                         NewLine, 
                         MemoUserInfoInfo, 
                         MemoDirInfo, 
                         MemoTypeInfo, 
                         MemoComponentsInfo, 
                         MemoGroupInfo, 
                         MemoTasksInfo: String): String;
begin
    Result := '';
    if MemoUserInfoInfo <> '' then
        Result := Result + MemoUserInfoInfo + NewLine + NewLine;
    if MemoDirInfo <> '' then
        Result := Result + MemoDirInfo + NewLine + NewLine;
    if MemoComponentsInfo <> '' then
        Result := Result + MemoComponentsInfo + NewLine + NewLine;
    if MemoGroupInfo <> '' then
        Result := Result + MemoGroupInfo + NewLine + NewLine;
    if (MemoTasksInfo <> '') then
        Result := Result + MemoTasksInfo + NewLine + NewLine;

    { Only display the Auto Backup Settings info if it is a new install }
    if (not bIsUpgrading) then
        Result := Result + AutoBackupPage_MemoInfo(Space, NewLine);

    if ((FilesToDownload <> '') or WizardIsComponentSelected('downloadhelpcomponent')) then
    begin
        Result := Result + ExpandConstant('{cm:ReadyMemo_Download}') + NewLine;

        if(FilesToDownload <> '') then
            Result := Result + FilesToDownload;

        if(IsComponentSelected('downloadhelpcomponent')) then
            Result := Result + Space + 'HelpDocSetup.exe' + NewLine;
    end;
end;

So, if the component is selected my Ready page looks like this:

Ready memo

Step 5

Finally, I adjusted the [Run] entry:

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

This approach (which is documented in the IDP help files) seems to be the best way.

Upvotes: 1

Martin Prikryl
Martin Prikryl

Reputation: 202504

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.

Upvotes: 2

Related Questions