How to create two LicenseFile pages in Inno Setup

2019-04-09 18:56发布

I'm making an Inno setup for my application. I'm using this command:

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"; LicenseFile: "C:\Users\LocDaiLe\Desktop\license.txt"

to display a license agreement window, but I want two license agreement window right after each others. How can I archieve this - thank you

2条回答
别忘想泡老子
2楼-- · 2019-04-09 19:18

You have to code the second license page as a custom page.

You can start with the CreateOutputMsgMemoPage function, which creates a page with a memo. Then, you just add radio buttons for accepting the license.

[Files]
; Embed the second license files
; (the part after underscore must match the Name parameter from Languages section)
Source: "license2_english.txt"; Flags: dontcopy
Source: "license2_czech.txt"; Flags: dontcopy
; Other languages
...

[Code]

var
  SecondLicensePage: TOutputMsgMemoWizardPage;
  License2AcceptedRadio: TRadioButton;
  License2NotAcceptedRadio: TRadioButton;

procedure CheckLicense2Accepted(Sender: TObject);
begin
  { Update Next button when user (un)accepts the license }
  WizardForm.NextButton.Enabled := License2AcceptedRadio.Checked;
end;

function CloneLicenseRadioButton(Source: TRadioButton): TRadioButton;
begin
  Result := TRadioButton.Create(WizardForm);
  Result.Parent := SecondLicensePage.Surface;
  Result.Caption := Source.Caption;
  Result.Left := Source.Left;
  Result.Top := Source.Top;
  Result.Width := Source.Width;
  Result.Height := Source.Height;
  Result.OnClick := @CheckLicense2Accepted;
end;

procedure InitializeWizard();
var
  LicenseFileName: string;
  LicenseFilePath: string;
begin
  { Create second license page, with the same labels as the original license page }
  SecondLicensePage :=
    CreateOutputMsgMemoPage(
      wpLicense, SetupMessage(msgWizardLicense), SetupMessage(msgLicenseLabel),
      SetupMessage(msgLicenseLabel3), '');

  { Shrink license box to make space for radio buttons }
  SecondLicensePage.RichEditViewer.Height := WizardForm.LicenseMemo.Height;

  { Load license }
  { Loading ex-post, as Lines.LoadFromFile supports UTF-8, }
  { contrary to LoadStringFromFile. }
  LicenseFileName := 'license2_' + ActiveLanguage + '.txt';
  ExtractTemporaryFile(LicenseFileName);
  LicenseFilePath := ExpandConstant('{tmp}\' + LicenseFileName);
  SecondLicensePage.RichEditViewer.Lines.LoadFromFile(LicenseFilePath);
  DeleteFile(LicenseFilePath);

  { Clone accept/do not accept radio buttons for the second license }
  License2AcceptedRadio :=
    CloneLicenseRadioButton(WizardForm.LicenseAcceptedRadio);
  License2NotAcceptedRadio :=
    CloneLicenseRadioButton(WizardForm.LicenseNotAcceptedRadio);

  { Initially not accepted }
  License2NotAcceptedRadio.Checked := True;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  { Update Next button when user gets to second license page }
  if CurPageID = SecondLicensePage.ID then
  begin
    CheckLicense2Accepted(nil);
  end;
end;

Original (first) license page:

License 1

Coded (second) license page:

License 2

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-04-09 19:28

I also had to display two license files, but I did it by adding these two lines to the setup sectiony:

LicenseFile={#MyFileSource}License.rtf
InfoBeforeFile={#MyFileSource}License2.rtf

Works like a charm for me

查看更多
登录 后发表回答