Inno Setup - 检查 {pf} 中文件是否存在

Inno Setup - Checking existence of file in {pf}

我想在 Inno Setup 配方中添加先决条件检查,以检查 C:\Program Files (x86)\XYZ 文件夹下是否存在文件。

显然,当调用 InitializeSetup 时,{pf} 等常量并未设置。

进行此类验证的正确方法是什么?

[Code]

function HasRequirements(): boolean;
begin
  result := FileExists('{pf}\XYZ\file.exe')
end;

function InitializeSetup(): Boolean;
begin
    MsgBox('{pf}', mbInformation, MB_OK);
    if not HasRequirements() then begin
        MsgBox('Please install XYZ first.', mbInformation, MB_OK);
        result := false;
    end else
        result := true;
end;

您需要使用 ExpandConstant 函数手动扩展字符串中的常量:

function HasRequirements(): boolean;
begin
  result := FileExists(ExpandConstant('{pf}\XYZ\file.exe'))
end;

function InitializeSetup(): Boolean;
begin
    MsgBox(ExpandConstant('{pf}'), mbInformation, MB_OK);
    if not HasRequirements() then begin
        MsgBox('Please install XYZ first.', mbInformation, MB_OK);
        result := false;
    end else
        result := true;
end;