如何在Inno Setup的InputDirPage中显示/使用用户选择的应用程序路径{app}?

发布于 2024-10-11 05:48:23 字数 750 浏览 3 评论 0原文

我正在使用 Inno Setup 创建一个安装程序。我必须从用户那里采取两条路径。一个用于程序可执行文件,另一个用于库。默认应用程序文件夹是 {pf}/companyname/applicationname

InitializeWizard 中,我创建了第二个页面,它从用户那里获取 lib 文件夹。

有什么方法可以将默认的 lib 文件夹更改为用户选择的文件夹 {app} 吗?

我已经尝试过WizardDirValue。它只是给出默认的 {app} 值,而不是用户在第一页中选择的路径。

[code]  
procedure InitializeWizard();  
begin  
  page2:= CreateInputDirPage(wpProgress,
    'Select Library Location', 'Where Library files should be stored?',
    'To continue, click Next. If you would like to select a different folder, click Browse.',
    False, 'Libs');    
  page2.Add('');  
  page2.Values[0] := WizardDirValue+'\libs';  
  LibDir := page2.Values[0];  
end

I'm creating an Installer using Inno Setup. I have to take two paths from user. One for program executables and another for libs. The default app folder is {pf}/companyname/applicationname

In the InitializeWizard I have created second page which takes the lib folder from the user.

Is there any way to change the default lib folder to the user selected folder {app}?

I have tried WizardDirValue. It just gives the default {app} value and NOT the path which user selected in first page.

[code]  
procedure InitializeWizard();  
begin  
  page2:= CreateInputDirPage(wpProgress,
    'Select Library Location', 'Where Library files should be stored?',
    'To continue, click Next. If you would like to select a different folder, click Browse.',
    False, 'Libs');    
  page2.Add('');  
  page2.Values[0] := WizardDirValue+'\libs';  
  LibDir := page2.Values[0];  
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄意 2024-10-18 05:48:23

正如名称 InitializeWizard() 所示,它是一个初始化函数,在显示向导之前仅调用一次。您可以通过在代码上设置断点来自行测试 - 它只会在开始时被命中一次。

因此,它是添加新向导页面并设置任何控件的默认值的正确位置,但不可能对其他向导页面的更改做出反应。您需要做的是在显示页面之前更新库路径。正确的方法是使用 NextButtonClick() 函数。以下是一些示例代码:

var
  LibPage: TInputDirWizardPage;

procedure InitializeWizard();
begin
  LibPage := CreateInputDirPage(wpSelectDir, 'Select Library Location',
    'Where should the library files be stored?',
    'To continue, click Next. If you would like to select a different folder, ' +
    'click Browse.', False, 'Libs');
  LibPage.Add('');
  LibPage.Values[0] := WizardDirValue + '\libs';
end;

这将在查询 {app} 目录的页面之后添加您的页面。由于用户可以单击“Prev”按钮多次更改 {app} 目录,因此您应该在页面即将显示时始终更新库路径:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpSelectDir then
    LibPage.Values[0] := WizardDirValue + '\libs';
end;

为了获得更好的可用性,您还可以检查库目录是默认值,否则不要更改其值。

As the name InitializeWizard() shows you it is an initialization function, called only once, before the wizard is shown. You can test this yourself by setting a breakpoint on your code - it will be hit only once, right at the start.

It's therefore the correct place to add a new wizard page and set the default value of any control, but it's impossible to react on changes to other wizard pages. What you need to do is to update the library path right before your page is shown. The correct way to do this is the NextButtonClick() function. Here is some sample code:

var
  LibPage: TInputDirWizardPage;

procedure InitializeWizard();
begin
  LibPage := CreateInputDirPage(wpSelectDir, 'Select Library Location',
    'Where should the library files be stored?',
    'To continue, click Next. If you would like to select a different folder, ' +
    'click Browse.', False, 'Libs');
  LibPage.Add('');
  LibPage.Values[0] := WizardDirValue + '\libs';
end;

This will add your page right after the page that queries the {app} directory. Since the user can click the "Prev" button to change the {app} directory multiple times you should always update the library path when your page is about to be shown:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpSelectDir then
    LibPage.Values[0] := WizardDirValue + '\libs';
end;

For better usability you could also check that the library directory is the default value, and otherwise don't change its value.

时光礼记 2024-10-18 05:48:23

您可以使用 ExpandConstant 函数。其中,所有 Inno Setup 常量都被替换为其实际值。例如,ExpandConstant('{app}\mydir') 应变为 C:\Program Files\\mydir。

You can use the ExpandConstant function. In it, all Inno Setup constants are replaced with their real values. For example, ExpandConstant('{app}\mydir') should become C:\Program Files\\mydir.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文