在InitializeSetup
event function中,检查是否存在预定义的目录集,并记住找到的目录集。然后使用DefaultDirName
directive中的scripted constant将默认安装路径设置为找到的安装路径。
您可能还想设置DisableDirPage=yes
和UsePreviousAppDir=no
。
[Setup]
DefaultDirName={code:GetDirName}
DisableDirPage=yes
UsePreviousAppDir=no
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
[Code]
var
DirName: string;
function TryPath(Path: string): Boolean;
begin
Result := DirExists(Path);
if Result then
begin
Log(Format('Path %s exists', [Path]))
DirName := Path;
end
else
begin
Log(Format('Path %s does not', [Path]))
end;
end;
function GetDirName(Param: string): string;
begin
Result := DirName;
end;
function InitializeSetup(): Boolean;
begin
Result :=
TryPath('C:\path1') or
TryPath('C:\path2') or
TryPath('C:\path3');
if Result then
begin
Log(Format('Destination %s selected', [DirName]))
end
else
begin
MsgBox('No destination found, aborting installation', mbError, MB_OK);
end;
end;
而不是使用DefaultDirName={code:GetDirName}
的,你也可以用在[Files]
部分的相应条目DestDir: "{code:GetDirName}"
,如果合适的话。
因此,您不希望允许用户在“选择目标位置”上选择目标文件夹?相反,您想要自动选择位置,具体取决于目标机器上已存在的位置,对吗? –
没有办法以某种方式选择正确的位置(如读取某个注册表项),而不是尝试一组硬编码的目录? –