Use Inno Setup UI as a self-extractor only - No installation

后端 未结 2 1973
一向
一向 2020-12-11 09:12

I use Inno Setup for many \"standard\" installers, but for this task I need to extract a bunch of temp files, run one of them, then remove them and exit the installer (witho

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 10:07

    It seems that ExtractTemporaryFiles() essentially locks up the UI until it's finished, so there's no way to get a progress bar (or Marquee) animated in here.

    Also getting a message on the screen at all while ExtractTemporaryFiles() is in progress was difficult. I solved it like this:

    const
      WM_SYSCOMMAND = 274;
      SC_MINIMIZE = $F020;
    //-------------------------------------------------------------------
    procedure MinimizeButtonClick();
    begin
      PostMessage(WizardForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0);
    end;
    //-------------------------------------------------------------------
    procedure CurPageChanged(CurPageID: Integer);
    var
      ResultCode: Integer;
    begin
      if CurPageID = wpPreparing then
      begin
        MinimizeButtonClick();
        Exec(ExpandConstant('{tmp}\MyScript.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
      end;
    end;
    //-------------------------------------------------------------------
    function NextButtonClick(CurPageID: Integer): Boolean;
    var
      ProgressPage: TOutputProgressWizardPage;
    begin
      if CurPageID = wpReady then
      begin
        ProgressPage := CreateOutputProgressPage('Preparing files...', '');
        ProgressPage.Show;
        try
          ProgressPage.Msg1Label.Caption := 'This process can take several minutes; please wait ...';
          ExtractTemporaryFiles('{tmp}\*');
        finally
          ProgressPage.Hide;
        end;
      end;
      Result := True;
    end;
    //-------------------------------------------------------------------
    procedure CurStepChanged(CurStep: TSetupStep);
    begin
      if CurStep = ssInstall then
      begin
        //MinimizeButtonClick() is called here as the Wizard flashes up for a second
        // and minimizing it makes that 1/2 a second instead...
        MinimizeButtonClick();
        Abort();
      end;
    end;
    

    I then changed the text on the "Ready" page to suit using the [Messages] section.

    The result is:

    • one wizard page asking the user if they want to continue
    • one wizard page telling the user "please wait..." while the temp files are extracted
    • once the files are extracted the wizard is hidden and MyScript.exe from the temp folder is run
    • once MyScript.exe finishes the wizard exits cleanly and deletes the temp files

提交回复
热议问题