Search code examples
inno-setuppascalscript

Opening a document in wizard before install


My problem is that i would like to make an "hyperlink"(i know there is now such thing in inno) when you click label a document(rtf) with instructions will open.

The problem: i DON'T want to copy this program along with the setup, it should be inside the setup and after the installation it is no more needed, thus it should be deleted or thrown out.

cant use {tmp} folder since it is accesed only in [run] phase(that is installation if i am not mistaken) and i need it earlier.

Any suggestions?


Solution

  • The temporary folder is not explicitly reserved for [Run] section. It can be used whenever needed (it is widely used e.g. for DLL libraries). And there is no such thing as a hyperlink label in Inno Setup as far as I know. I've made an example of a link lable and extended it for opening files that are extracted from the setup archive into a temporary folder (a folder that is deleted when the installer terminates):

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    [Files]
    ; the dontcopy flag tells the installer that this file is not going to be copied to
    ; the target system
    Source: "File.txt"; Flags: dontcopy
    
    [Code]
    var
      LinkLabel: TLabel;
    
    procedure LinkLabelClick(Sender: TObject);
    var
      FileName: string;
      ErrorCode: Integer;
    begin
      FileName := ExpandConstant('{tmp}\File.txt');
      // if the file was not yet extracted into the temporary folder, do it now
      if not FileExists(FileName) then
        ExtractTemporaryFile('File.txt');
      // open the file from the temporary folder; if that fails, show the error message
      if not ShellExec('', FileName, '', '', SW_SHOW, ewNoWait, ErrorCode) then
        MsgBox(Format('File could not be opened. Code: %d', [ErrorCode]), mbError, MB_OK);
    end;
    
    procedure InitializeWizard;
    begin
      LinkLabel := TLabel.Create(WizardForm);
      LinkLabel.Parent := WizardForm;
      LinkLabel.Left := 8;
      LinkLabel.Top := WizardForm.ClientHeight - LinkLabel.ClientHeight - 8;
      LinkLabel.Cursor := crHand;
      LinkLabel.Font.Color := clBlue;
      LinkLabel.Font.Style := [fsUnderline];
      LinkLabel.Caption := 'Click me to read something important!';
      LinkLabel.OnClick := @LinkLabelClick;
    end;
    
    procedure CurPageChanged(CurPageID: Integer);
    begin
      LinkLabel.Visible := CurPageID <> wpLicense;
    end;