one
one

Reputation: 511

How to dynamically change the InfoAfterFile in InnoSetup

I have an InnoSetup project, i want to have the ability to set the InfoAfterFile according to the command line parameters sent to the setup exe. is there a way to do so? is there something like the "Check" paramter that will work in this case?

Upvotes: 1

Views: 798

Answers (1)

TLama
TLama

Reputation: 76713

You cannot assign a value for the InfoAfterFile directive at runtime. Its value specifies the file which is compiled into the output setup and so this directive value must be known at compilation time. However, you can load a file manually into the InfoAfterMemo control. The following example shows how to load a file specified by the command line parameter -iaf only if that parameter is present and the file exists:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
InfoAfterFile=c:\DefaultFileToBeDisplayed.txt

[Code]
const
  InfoAfterFileParam = '-iaf';

function TryGetInfoAfterFileParam(var FileName: string): Boolean;
var
  S: string;
  I: Integer;
  Index: Integer;
begin
  // initialize result
  Result := False;
  // iterate all the command line parameters
  for I := 1 to ParamCount do
  begin
    // store the current parameter to the local variable
    S := ParamStr(I);
    // try to find the position of the substring specified by the
    // InfoAfterFileParam constant; in this example we're looking
    // for the "-iaf" string in the current parameter
    Index := Pos(InfoAfterFileParam, S);
    // if the InfoAfterFileParam constant string was found in the
    // current parameter, then...
    if Index = 1 then
    begin
      // strip out the InfoAfterFileParam constant string from the
      // parameter string, so we get only file name
      Delete(S, Index, Length(InfoAfterFileParam));
      // now trim the spaces from rest of the string, which is the
      // file name
      S := Trim(S);
      // check if the file pointed by the file name we got exists;
      // if so, then return True for this function call and assign
      // the output file name to the output parameter
      if FileExists(S) then
      begin
        Result := True;
        FileName := S;
      end;
      // we've found the parameter starting with InfoAfterFileParam
      // constant string, so let's exit the function
      Exit;
    end;
  end;
end;

procedure InitializeWizard;
var
  FileName: string;
begin
  // when the parameter was found and the file to be loaded exists,
  // then load it to the InfoAfterMemo control
  if TryGetInfoAfterFileParam(FileName) then
    WizardForm.InfoAfterMemo.Lines.LoadFromFile(FileName);
end;

Please note, that you will have to specify the InfoAfterFile directive, otherwise the page won't be even shown. Also note, that I'm looking for the command line parameter starting with -iaf, so you'd need to modify this code in real if you expect to use e.g. -iafx parameter. Here is the sample call of such setup from command line:

Setup.exe -iaf"C:\SomeFolder\SomeFileToBeShownAsInfoAfter.txt"

Upvotes: 2

Related Questions