仅在Inno设置中选择特定组件时显示自定义页面并将输入保存到文件中 [英] Display custom page and save inputs to a file only when specific component is selected in Inno setup

查看:52
本文介绍了仅在Inno设置中选择特定组件时显示自定义页面并将输入保存到文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用程序建立一个安装程序,该安装程序包含两部分:服务器和客户端.客户端部分需要具有用户输入的IP地址.我正在使用自定义页面来提示输入IP地址.但是,只有在用户选择客户端"组件时,我才需要显示自定义页面.

I'm trying to build a setup for my application , which contains two parts: server and client. The client part needs to have an IP address entered by the user. I'm using a custom page to prompt for the IP address. But I need to display the custom page, only if user selects "Client" component.

[Components]
Name: "Serveur"; Description: "Server installation"; Types: Serveur; Flags: exclusive; 
Name: "Client"; Description: "Client installation"; Types: Client; Flags: exclusive

[Types]
Name: "Serveur"; Description: "Server Installation"
Name: "Client"; Description: "Client Installation"

[Code]                                                                                                                                    
var
  Page: TInputQueryWizardPage;
  ip: String;

procedure InitializeWizard();
begin
  Page := CreateInputQueryPage(wpWelcome,
    'IP Adresse du serveur', 'par exemple : 192.168.1.120',
    'Veuillez introduire l''adresse IP du serveur :');

  Page.Add('IP :', False);

  Page.Values[0] := ExpandConstant('192.168.x.x');
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if (CurPageID = Page.ID) then
  begin
    ip := Page.Values[0];
    SaveStringToFile('C:\Program Files\AppClient\ipAddress.txt', ip, False);
  end;

  Result := True;
end;

推荐答案

  1. 您的自定义页面必须仅在选择组件"页面之后,因此您需要将 wpSelectComponents 传递给 CreateInputQueryPage :

var
  Page: TInputQueryWizardPage;

procedure InitializeWizard();
begin
  Page :=
    CreateInputQueryPage(
      wpSelectComponents, 'IP Adresse du serveur', 'par exemple : 192.168.1.120',
      'Veuillez introduire l''adresse IP du serveur :');
  Page.Add('IP :', False);
  Page.Values[0] := '192.168.x.x';
end;

(还要注意,对不包含任何常量的字符串文字调用 ExpandConstant 毫无意义).

(Also note that there's no point in calling ExpandConstant on a string literal that does not include any constants).

当未选择客户端"组件时,跳过自定义页面:

Skip the custom page, when the "Client" component is not selected:

function IsClient: Boolean;
begin
  Result := IsComponentSelected('Client');
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;
  if PageID = Page.ID then
  begin
    Result := not IsClient;
  end;
end;

另请参见跳过基于Inno Setup中可选组件的自定义页面.

行为良好的安装程序不应在用户最终确认安装之前对系统进行任何修改.因此,仅在真正开始安装后才进行任何更改,而在用户单击自定义页面上的下一步"时则无需进行任何更改.

Well behaving installer should not make any modifications to a system, before the user finally confirms the installation. So make any changes only, once installation really starts, not already when user click "Next" on the custom page.

此外,您不能使用 {app} 常量对文件的路径进行硬编码.

Also, you cannot hard-code a path to the file, use {app} constant.

procedure CurStepChanged(CurStep: TSetupStep);
var
  IP: string;
begin
  if (CurStep = ssInstall) and IsClient() then
  begin
    IP := Page.Values[0];
    SaveStringToFile(ExpandConstant('{app}\ipAddress.txt'), IP, False);
  end;
end;

这篇关于仅在Inno设置中选择特定组件时显示自定义页面并将输入保存到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆