在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}"
,如果合適的話。
因此,您不希望允許用戶在「選擇目標位置」上選擇目標文件夾?相反,您想要自動選擇位置,具體取決於目標機器上已存在的位置,對嗎? –
沒有辦法以某種方式選擇正確的位置(如讀取某個註冊表項),而不是嘗試一組硬編碼的目錄? –