在这种情况下,我需要将文件安装到特定目录,但在不同的计算机上它可能位于不同的文件夹中,所以我需要检查哪个是正确的。
例如,我有一个文件,需要将其安装在A
文件夹或B
文件夹或C
文件夹,取决于计算机有A
or B
or C
。所以我需要先检查一下计算机是否有B
,然后将文件安装到B
文件夹等
我知道我可以在文件后使用检查DestDir
,如果该目录不存在,那么它不会安装任何东西,但我需要的是将该文件安装到其他目录。
提前致谢。
In the ,检查是否存在预定义的目录集并记住您找到的目录。然后使用 a 将默认安装路径设置为找到的路径脚本常量 https://jrsoftware.org/ishelp/index.php?topic=scriptconstants in the DefaultDirName指示 https://jrsoftware.org/ishelp/index.php?topic=setup_defaultdirname.
您可能还想设置DisableDirPage=yes https://jrsoftware.org/ishelp/index.php?topic=setup_disabledirpage和UsePreviousAppDir=no https://jrsoftware.org/ishelp/index.php?topic=setup_usepreviousappdir.
[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}
,您还可以使用DestDir: "{code:GetDirName}"
在相应的条目中[Files]
部分(如果适用)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)