我试图通过 Pascal 代码访问文件夹中的所有文件。当我遍历一个空文件夹时,出现以下错误:
Exception: Internal error; An attempt was made to call the "CurrentFileName" function from outside a "Check", "BeforeInstall" or "AfterInstall" event function belonging to a "[Files]" entry
我使用的代码:
[Files]
Source: ".\3D_Dlls\*"; DestDir: {app}\3D_Dlls; \
Flags: ignoreversion recursesubdirs createallsubdirs skipifsourcedoesntexist; \
Check: FileBackup
[Code]
function FileBackup(): Boolean;
var FileName,Source,Target,TargetDir: String;
begin
Result := True;
Source := ExpandConstant(CurrentFileName);
end
比如说我的文件夹结构是这样的:
3D_Dlls
- Folder 1
- Folder 2 // Empty folder and it invokes the problem
- Folder 3
最佳答案
我相信这是 Inno Setup 中由 createallsubdirs
标志触发的错误。
当指定标志时,Inno Setup 会收集一个单独的空目录列表,这些空目录需要在安装期间显式创建。 “安装”空文件夹时,对 CurrentFileName
的调用会失败。
解决方法:
如果可能,删除 createallsubdirs
标志。
相反,您可以使用 [Dirs]
section 显式创建空目录.
捕获异常:
function FileBackup: Boolean;
begin
Result := True;
try
Source := ExpandConstant(CurrentFileName);
except
Log(GetExceptionMessage);
end;
end;
我已经在 Inno Setup 新闻组上报告了这一点,但此后新闻组已重置。
关于inno-setup - 安装空文件夹时访问 CurrentFileName 时出现 Inno Setup Runtime 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29112881/