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

后端 未结 2 1953
一向
一向 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
    0 讨论(0)
  • 2020-12-11 10:16
    • "Install" the files to {tmp}, instead of using ExtractTemporaryFiles;
    • Execute the files extracted to {tmp} from Run section (or use AfterInstall parameter or CurStepChanged to trigger Pascal Script code after files are installed);
    • Set Uninstallable to no;
    • Set CreateAppDir to no;
    • Use [Messages] section to edit the wizard texts that are too installer-centric for your needs.
    [Setup]
    Uninstallable=no
    CreateAppDir=no
    
    [Files]
    Source: "dist\*"; DestDir: {tmp}; Flags: recursesubdirs
    
    [Run]
    FileName: "{tmp}\MyScript.exe"
    

    Notes:

    • The {tmp} folder gets automatically deleted, when the "installer" is closing;
    • No need for ignoreversion flag, when installing to new empty folder.

    For an answer your literal question, see Inno setup: ExtractTemporaryFile causes wizard freeze. Or a more generic question on the topic: Inno Setup: How to modify long running script so it will not freeze GUI?

    0 讨论(0)
提交回复
热议问题