Robert Wigley
Robert Wigley

Reputation: 1957

Inno Setup change the CreateInputFilePage behaviour from Open to Save

I am using the CreateInputFilePage function to create a page with an input field and a Browse button that allows selection of a path and file. The problem is that I don't want to select a file to open, I want to specify a file to save to. The default behaviour when specifying a path and file that doesn't exist is to prompt

File not found. Check the file name and try again.

Unfortunately, this isn't the behaviour required if specifying a file to save to. In this scenario it needs to prompt

File does not exist. Create the file?

or something similar and allow selection of the chosen path and file.

Ideally, the Open button in the Browse dialog should also be changed to read "Save".

Is it possible to modify this behaviour as described and change the button text? If so, how could this be done?

Upvotes: 3

Views: 843

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202272

Use TInputFileWizardPage.IsSaveButton property.

To implement the confirmation, handle TWizardPage.OnNextButtonClick event.

var
  FileIndex: Integer;

function InputFileCheck(Page: TWizardPage): Boolean;
var
  Path: string;
begin
  Result := True;
  Path := Trim(TInputFileWizardPage(Page).Values[FileIndex]);
  if Length(Path) = 0 then
  begin
    MsgBox('No file specified.', mbError, MB_OK);
    Result := False;
  end
    else
  if not FileExists(Path) then
  begin
    Result :=
      MsgBox('File does not exist. Create the file?', mbConfirmation, MB_YESNO) = IDYES;
  end;
end;

procedure InitializeWizard;
var
  Page: TInputFileWizardPage;
begin
  Page := CreateInputFilePage('...', '...', '...', '...');
  Page.OnNextButtonClick := @InputFileCheck;

  FileIndex := Page.Add('...', '...', '...');
  Page.IsSaveButton[FileIndex] := True;
  ...
end;

Upvotes: 3

Related Questions