如何从 Code/Pascal 部分引用文件部分中的文件?

How to reference the files in the Files section from Code/Pascal section?

在我的代码部分,我需要修改现有的配置文件 (Apache httpd.conf) 以包含我在 Files 部分安装的文件之一。

我如何引用我的 .conf 文件,以便我可以像这样插入 httpd.conf 中:

Include "C:/Program Files (x86)/Apache Software Foundation/Apache2.4/conf/myinclude.conf"

我想我可以这样做:

 ExtractFilePath( {app} ) + '\conf\myinclude.conf' 

获取文件的完整路径。

然而,这意味着我必须在我的脚本代码中对部分路径进行硬编码。如果我们稍后更改路径,那么我必须在文件部分更改它,并记得在脚本代码中也更改它。

有没有办法仅通过名称引用文件并获取完整的安装路径?

第二个问题:
做这种事情(修改文件)的最佳位置是什么?

  1. 在我要修改的文件的 AfterInstall 中?
  2. NextButtonClickwpFinished?
  3. 其他?

使用 preprocessor constant/variable.

更新 httpd.conf 的最佳位置是 CurStepChanged(ssPostInstall)AfterInstall 也可以。

#define MyIncludeName "myinclude.conf"
#define MyIncludeRelPath "conf\" + MyIncludeName

[Files]
Source: "{#MyIncludeName}"; DestDir: "{app}\..\{#MyIncludeRelPath}"

[Code]

procedure CurStepChanged(CurStep: TSetupStep);
var
  Path: string;
begin
  if CurStep = ssPostInstall then
  begin
    Path := ExtractFilePath(ExpandConstant('{app}')) + '{#MyIncludeRelPath}';
    ...
  end;
end;