我正在尝试使用Inno Setup分发另一个应用程序用作插件的文件。如果找不到插件的目标位置,它仍应将其自身安装到Program Files目录中,并向用户提供手动说明。
为了提供一些在类似问题中使用的代码而跳到Tlama:Inno Setup find subfolder。
Follow脚本列出了我希望实现的基本设置,并在脚本不完整的地方加了注释。我只是在我的头上。 :-)
如何将找到的目录传递回StampTargetDir
(当前只是一个MsgBox)
如何在指定目录名称(即'Stamps')下搜索所有子目录
如何将所有子目录(#2)的搜索限制为仅存在于{pf}
或{localappdata}
中的几个命名子目录(即“ Adobe”和“ Acrobat”)
在[Files]
下进行文件插件安装,条件是找到“邮票”目录。
P.S。我知道搜索有一些明显的缺点。但是,“邮票”目录不太可能在其他区域使用(请参阅#3)。
[Files]
; Install all the files in a user specified location.
Source: "C:\mydir\readme.pdf"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\mydir\stamp.pdf"; DestDir: "{app}"; Flags: ignoreversion
; If found, install the stamp file in the Adobe Acrobat or Reader Stamp directory.
Source: "C:\mydir\stamp.pdf"; DestDir: "{code:StampTargetDir}"; Flags: ignoreversion
[Tasks]
Name: pf; Description: "&All users on this computer."; GroupDescription: "Configure Acrobat stamp plug-in:"; Flags: exclusive
Name: local; Description: "&Only the current user (me)."; GroupDescription: "Configure Acrobat stamp plug-in:"; Flags: exclusive unchecked
Name: none; Description: "&Do not configure stamps (manual setup)."; GroupDescription: "Configure Acrobat stamp plug-in:"; Flags: exclusive unchecked
[Code]
function GetFirstMatchingSubfolder(const Path: string; out Folder: string): Boolean;
var
S: string;
FindRec: TFindRec;
begin
Result := False;
if FindFirst(ExpandConstant(AddBackslash(Path) + '*'), FindRec) then
try
repeat
// *** THIS DOES NOT SEARCH SUBDIRECTORIES ***
if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and
(FindRec.Name <> '.') and (FindRec.Name <> '..') and
(FindRec.Name = 'Stamps') then
begin
Result := True;
Folder := AddBackslash(Path) + FindRec.Name;
end;
until
not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
function StampTargetDir(Param: String): String;
begin
if IsTaskSelected('pf') then
// *** THIS NEEDS TO BE 'Stamps' DIRECTORY FOUND UNDER {pf}
Result := ExpandConstant('{app}') + '\pf'
else if IsTaskSelected('local') then
// *** THIS NEEDS TO BE 'Stamps' DIRECTORY FOUND UNDER {localappdata}
// Assuming {localappdata} is the user's Application Data Folder
// Typically C:\Documents and Settings\username\Application Data.
Result := ExpandConstant('{app}') + '\local'
else
Result := ExpandConstant('{app}') + '\none'
end;
// *** This procedure is just for testing. The results of
// GetFirstMatchingSubfolder should be used by StampTargetDir
procedure InitializeWizard;
var
S: string;
begin
// *** THIS DOES NOT LIMIT SEARCH TO {pf}\Adobe or {pf}\Acrobat *** if GetFirstMatchingSubfolder(ExpandConstant('{pf}'), S) then
MsgBox('An extra copy will go in here: ' + S, mbInformation, MB_OK);
end;
要将路径从InitializeWizard
传递到StampTargetDir
,请使用全局变量。尽管我建议您最好使用CurStepChanged(ssInstall)
而不是InitializeWizard
,除非您需要比实际安装更早的路径。
在GetFirstMatchingSubfolder
中使用递归。
最干净的解决方案是使用特定的根目录多次运行GetFirstMatchingSubfolder
(即,对于Adobe和Acrobat,两次运行)
代码可以像:
Check