Use the primary functions and procedures

You can only use the primay function DwinsHs_ReadRemoteURL to download the files or access the web server. The DwinsHs_GetRemoteSize function, DwinsHs_Setproxy and DwinsHs_ProcessMessages procedures can be used too. Optional progress indicator can be created by yourself.

  1. Prepartory step:

    Copy the file dwinshs.iss to your installation script folder or a sub-folder in it.

  2. Include the "dwinshs.iss" file:

    Please include the dwinshs.iss file at the beginning of the "[Code]" section. If the file is placed in the sub-folder of your installation scripts folder, please add path of the sub-folder in order to locate it. For exampe:

    [Code]
    #include "dwinshs.iss"
    ......

    You can specify the size of read buffer by defining the macro DwinsHs_Data_Buffer_Length before including the dwinshs.iss file. By default, it's 4096 bytes. For example:

    [Code]
    #define DwinsHs_Data_Buffer_Length 8192
    #include "dwinshs.iss"
    ......

  3. Create a download progress indicator:

    Optional, you can create a download progress indicator in your Setup wizard page, and define the OnRead callback function for the DwinsHs_ReadRemoteURL function to update the indicator:

    var
      DownloadIndicator: TNewProgressBar;
    ...
    procedure InitializeWizard();
    begin
      ...
      // Create the download progress indicator
      DownloadIndicator := TNewProgressBar.Create(PageFromId(wpReady));
      DownloadIndicator.Left := ScaleX(20);
      DownloadIndicator.Top := ScaleY(200);
      DownloadIndicator.Width := ScaleX(200);
      DownloadIndicator.Height:= ScaleY(20);
      DownloadIndicator.Min := 0;
      DownloadIndicator.Parent := PageFromId(wpReady).Surface;
      ...
    end;
    ...
    // The callback function for DwinsHs_ReadRemoteURL
    function OnRead(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
      CurrentSize: {#BIG_INT}; var ReadStr: AnsiString): Boolean;
    begin
      if Index = 0 then DownloadIndicator.Max := 100;
      DownloadIndicator.Position := (ReadSize * 100) div TotalSize; // Update the download progress indicator
      Result := True; // Continue to download
    end;

  4. Specify the proxy settings:

    Optional, you can use the DwinsHs_Setproxy procedure to specify the proxy or direct configuration for downloading. The user Inetnet configuration specified in the control panel will be used if you don't specify them. For example:

    [Code]
    ...
    procedure InitializeWizard();
    begin
      ...
      // Specify the proxy or direct configuration
      DwinsHs_SetProxy(pmProxy, ppHttp, 'www.proxy_example.com', 8080, 'username', 'password');
      ...
    end;
    ...

  5. Start to download or access to your web script:

    Please call the DwinsHs_ReadRemoteURL function to start the downloading operation or visit your web server script. If the OnRead callback function is used, specify it in the OnRead parameter, specify nil in it othwise:

    procedure CurPageChanged(CurPageID: Integer);
    var
      Response: AnsiString;
      Size: {#BIG_INT};
    begin
      ...
      if (CurPageId = wpReady) then
      begin
        // Initialize download progress indicator
        DownloadIndicator.Position := 0;
        // Disbale to continue before download completes
        WizardForm.NextButton.Enabled := False;
        // Enable to continue after download successfully, save the remote file automatically
        WizardForm.NextButton.Enabled := DwinsHs_ReadRemoteURL('http://www.xxx.com/yyy/abc.zip',
          '', rmGet, Response, Size, ExpandConstant('{tmp}') + '\abc.zip', @OnRead) = READ_OK;
      end;
      ...
    end;

    Or

    procedure CurPageChanged(CurPageID: Integer);
    var
      Response: AnsiString;
      Size: {#BIG_INT};
    begin
      ...
      if (CurPageId = wpReady) then
      begin
        // Initialize download progress indicator
        DownloadIndicator.Position := 0;
        // Disbale to continue before download completes
        WizardForm.NextButton.Enabled := False;
        // Enable to continue after download successfully
        WizardForm.NextButton.Enabled := DwinsHs_ReadRemoteURL('http://www.xxx.com/yyy/...',
          '', rmGet, Response, Size, '', @OnRead) = READ_OK;
        // Save the remote file if download successfully
        if WizardForm.NextButton.Enabled then
          SaveStringToFile(ExpandConstant('{tmp}') + '\...', Response, False);
        // Or verify the remote response
        if Response = 'registered' then
        begin
          ...
        end;
      end;
      ...
    end;

  6. Catch event when user click on "Back" button:

    Optional, you can catch the event when user click on "Back" button, then stop downloading and move to previous wizard page. For example:

    var
      BackClicked: Boolean;
    ...
    // The callback function for DwinsHs_ReadRemoteURL
    function OnRead(URL, Agent: AnsiString; Method: TReadMethod; Index, TotalSize, ReadSize,
      CurrentSize: {#BIG_INT}; var ReadStr: AnsiString): Boolean;
    begin
      ...
      Result := not BackClicked; // Determine whether download was cancelled
      ...
    end;
    ...
    procedure CurPageChanged(CurPageID: Integer);
    var
      Response: AnsiString;
      Size: {#BIG_INT};
    begin
      if (CurPageId = wpReady) then
      begin
        // Allow to download
        BackClicked := False;
        // Disbale to continue before download completes
        WizardForm.NextButton.Enabled := False;
        // Enable to continue after download successfully
        WizardForm.NextButton.Enabled := DwinsHs_ReadRemoteURL('http://www.xxx.com/yyy/abc.zip',
          '', rmGet, Response, Size, ExpandConstant('{tmp}') + '\abc.zip', @OnRead) = READ_OK;
        ...
      end;
    end;
    ...
    function BackButtonClick(CurPageID: Integer): Boolean;
    begin
      // Stop to download
      BackClicked := True;
      Result := True;
    end;

    Or

    ...
    procedure CurPageChanged(CurPageID: Integer);
    var
      Response: AnsiString;
      Size: {#BIG_INT};
    begin
      if (CurPageId = wpReady) then
      begin
        // Allow to download
        DwinsHs_CancelDownload := cdNone;
        // Disbale to continue before download completes
        WizardForm.NextButton.Enabled := False;
        // Enable to continue after download successfully
        WizardForm.NextButton.Enabled := DwinsHs_ReadRemoteURL('http://www.xxx.com/yyy/abc.zip',
          '', rmGet, Response, Size, ExpandConstant('{tmp}') + '\abc.zip', nil) = READ_OK;
      end;
    end;
    ...
    function BackButtonClick(CurPageID: Integer): Boolean;
    begin
      // Stop to download
      DwinsHs_CancelDownload := cdBack;
      Result := True;
    end;

  7. Prevent re-download of already downloaded file:

    If you click on the "Back" button to move the Setup wizard to previous wizard page after the remote file was downloaded successfully, then click on the "Next" button to move it back to the wizard page which the download will be started, the download operation will be executed once again. Please use the following code to prevent the behavior:

    var
      Downloaded: Boolean;
    ...
    procedure InitializeWizard();
    begin
      ...
      Downloaded := False;
      ...
    end;
    ...
    procedure CurPageChanged(CurPageID: Integer);
    var
      Response: AnsiString;
      Size: {#BIG_INT};
    begin
      if (CurPageId = wpReady) and (not Downloaded) then
      begin
        // Disbale to continue before download completes
        WizardForm.NextButton.Enabled := False;
        // Enable to continue after download successfully
        WizardForm.NextButton.Enabled := DwinsHs_ReadRemoteURL('http://www.xxx.com/yyy/abc.zip',
          '', rmGet, Response, Size, ExpandConstant('{tmp}') + '\abc.zip', nil) = READ_OK;
        Downloaded := WizardForm.NextButton.Enabled;
      end;
    end;

  8. Congratulations!

    Compile your setup script and watch the download wizard page at work! If it doesn't work, please add a link to our website in your web page, then contact us and send your link page to us.